All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.anotheria.anosite.gen.assitedata.action.MultiOpDialogPageTemplatesAction Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
/**
 ********************************************************************************
 *** MultiOpDialogPageTemplatesAction.java                                    ***
 *** generated by AnoSiteGenerator (ASG), Version: 2.6.3                      ***
 *** Copyright (C) 2005 - 2010 Anotheria.net, www.anotheria.net               ***
 *** All Rights Reserved.                                                     ***
 ********************************************************************************
 *** Don't edit this code, if you aren't sure                                 ***
 *** that you do exactly know what you are doing!                             ***
 *** It's better to invest time in the generator, as into the generated code. ***
 ********************************************************************************
 */

package net.anotheria.anosite.gen.assitedata.action;

import net.anotheria.util.NumberUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.anotheria.maf.action.ActionForward;
import net.anotheria.maf.action.ActionMapping;
import net.anotheria.maf.bean.FormBean;
import java.util.List;
import java.util.ArrayList;
import net.anotheria.anosite.gen.assitedata.data.PageTemplateFactory;
import net.anotheria.anosite.gen.assitedata.data.PageTemplate;
import net.anotheria.anosite.gen.assitedata.bean.EditPageTemplateFB;
import net.anotheria.asg.data.LockableObject;
import net.anotheria.asg.util.locking.helper.DocumentLockingHelper;
import net.anotheria.maf.bean.annotations.Form;


public class MultiOpDialogPageTemplatesAction extends BasePageTemplateAction{

	// Generated by: class net.anotheria.asg.generator.view.action.ModuleActionsGenerator.generateMultiOpDialogAction


	@Override
	public ActionForward execute(ActionMapping mapping, @Form(EditPageTemplateFB.class) FormBean formBean, HttpServletRequest req, HttpServletResponse res) throws Exception{
		return super.execute(mapping, formBean, req, res);
	} //execute

	public ActionForward anoDocExecute(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
		String path = stripPath(mapping.getPath());
		if (path.equals("assitedataPageTemplateDelete"))
			return assitedataPageTemplateDelete(mapping, af, req, res);
		if (path.equals("assitedataPageTemplateDuplicate"))
			return assitedataPageTemplateDuplicate(mapping, af, req, res);
		if (path.equals("assitedataPageTemplateUpdate"))
			return assitedataPageTemplateUpdate(mapping, af, req, res);
		if (path.equals("assitedataPageTemplateClose"))
			return assitedataPageTemplateClose(mapping, af, req, res);
		if (path.equals("assitedataPageTemplateLock"))
			return assitedataPageTemplateLock(mapping, af, req, res);
		if (path.equals("assitedataPageTemplateUnLock"))
			return assitedataPageTemplateUnLock(mapping, af, req, res);
		throw new IllegalArgumentException("Unknown path: "+path);
	}

	public ActionForward assitedataPageTemplateDelete(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
		String[] iDs = req.getParameterValues(PARAM_ID);
		if (iDs == null){
		throw new RuntimeException("Parameter " + PARAM_ID + " is not set.");
	}
	for (String id : iDs){
		PageTemplate pagetemplateCurr = getASSiteDataService().getPageTemplate(id);
		if (pagetemplateCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)pagetemplateCurr;
		DocumentLockingHelper.delete.checkExecutionPermission(lockable, false, getUserId(req));
		}
		getASSiteDataService().deletePageTemplate(id);
	}
	res.sendRedirect("assitedataPageTemplateShow?ts="+System.currentTimeMillis());
	return null;
}

public ActionForward assitedataPageTemplateDuplicate(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	PageTemplate pagetemplateSrc = getASSiteDataService().getPageTemplate(id);
	PageTemplate pagetemplateDest = PageTemplateFactory.createPageTemplate(pagetemplateSrc);














	PageTemplate pagetemplateCreated = getASSiteDataService().createPageTemplate(pagetemplateDest);
	res.sendRedirect("assitedataPageTemplateEdit?ts="+System.currentTimeMillis()+"&"+PARAM_ID+"="+pagetemplateCreated.getId());

	return null;
}

// Generated by: class net.anotheria.asg.generator.view.action.ModuleActionsGenerator.generateUpdateActionMethod

public ActionForward assitedataPageTemplateUpdate(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	EditPageTemplateFB form = (EditPageTemplateFB) af;
	boolean create = false;
	PageTemplate pagetemplate = null;
	if (form.getId()==null) {
	res.sendRedirect("asresourcedataLocalizationBundleShow?ts="+System.currentTimeMillis());
	return null;
}
if (form.getId().length()>0){
	pagetemplate = (PageTemplate)getASSiteDataService().getPageTemplate(form.getId()).clone();
}else{
	pagetemplate = PageTemplateFactory.createPageTemplate();
	create = true;
}

String nextAction = req.getParameter("nextAction");
if (nextAction == null || nextAction.length() == 0)
	nextAction = "close";

//skipped id because it's readonly.
pagetemplate.setName(form.getName());
pagetemplate.setLayout(form.getLayout());
pagetemplate.setSite(form.getSite());
// skipped container mediaLinks
// skipped container scripts
// skipped container localizations
// skipped container c1first
// skipped container c2first
// skipped container c3first
// skipped container c1last
// skipped container c2last
// skipped container c3last
// skipped container meta
// skipped container header
// skipped container footer
pagetemplate.setDescription(form.getDescription());

PageTemplate updatedCopy = null;
if (create){
	updatedCopy = getASSiteDataService().createPageTemplate(pagetemplate);
}else{
	canUpdatePageTemplates(pagetemplate, req);
	checkPageTemplates(pagetemplate, req);
	updatedCopy = getASSiteDataService().updatePageTemplate(pagetemplate);
}
if (nextAction.equalsIgnoreCase("stay")){
	res.sendRedirect("assitedataPageTemplateEdit?ts="+System.currentTimeMillis()+"&pId="+updatedCopy.getId());
}else{
	unlockAfterUpdate(pagetemplate, req);
	res.sendRedirect("assitedataPageTemplateShow?ts="+System.currentTimeMillis());
}
return null;
}
/**
 * Simply unlocks document after updation.
 */
private void unlockAfterUpdate(PageTemplate pagetemplate, HttpServletRequest req) throws Exception{
	if(((LockableObject)pagetemplate).isLocked())
		unLockPageTemplates(pagetemplate, req, false);
}

public ActionForward assitedataPageTemplateLock(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	PageTemplate pagetemplateCurr = id != null && !id.equals("") ? getASSiteDataService().getPageTemplate(id) : null;
	if(pagetemplateCurr != null && pagetemplateCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)pagetemplateCurr;
		DocumentLockingHelper.lock.checkExecutionPermission(lockable,false,getUserId(req));
		lockPageTemplates(pagetemplateCurr, req);
	}
	res.sendRedirect(getRedirectUrl(req, pagetemplateCurr));
	return null;
}

public ActionForward assitedataPageTemplateUnLock(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	PageTemplate pagetemplateCurr = id != null && !id.equals("") ? getASSiteDataService().getPageTemplate(id) : null;
	if(pagetemplateCurr != null && pagetemplateCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)pagetemplateCurr;
		DocumentLockingHelper.unLock.checkExecutionPermission(lockable,isUserInRole(req, "admin"),getUserId(req));
		unLockPageTemplates(pagetemplateCurr, req, false);
	}
	res.sendRedirect(getRedirectUrl(req, pagetemplateCurr));
	return null;
}

/**
 * Simplest method for redirect url creation. nextAction == showEdit - going to 'editView', to 'listView' otherwise. 
 */
private String getRedirectUrl(HttpServletRequest req, PageTemplate item){
	String nextAction = req.getParameter("nextAction");
	if (item==null || nextAction == null || nextAction.length() == 0)
		return "assitedataPageTemplateShow?ts="+System.currentTimeMillis();
	else
		return nextAction.equals("showEdit") ? "assitedataPageTemplateEdit?ts="+System.currentTimeMillis()+"&pId="+item.getId()
		       : "assitedataPageTemplateShow?ts="+System.currentTimeMillis();
}

public ActionForward assitedataPageTemplateClose(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	PageTemplate pagetemplateCurr = id != null && !id.equals("") ? getASSiteDataService().getPageTemplate(id) : null;
	if(pagetemplateCurr != null && pagetemplateCurr instanceof LockableObject && ((LockableObject)pagetemplateCurr).isLocked()) 
		unLockPageTemplates(pagetemplateCurr, req, false);
	res.sendRedirect("assitedataPageTemplateShow?ts="+System.currentTimeMillis());
	return null;
}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy