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

net.anotheria.anosite.gen.asresourcedata.action.MultiOpDialogImagesAction Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
/**
 ********************************************************************************
 *** MultiOpDialogImagesAction.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.asresourcedata.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.asresourcedata.data.ImageFactory;
import net.anotheria.anosite.gen.asresourcedata.data.Image;
import net.anotheria.anosite.gen.asresourcedata.bean.EditImageFB;
import net.anotheria.asg.data.LockableObject;
import net.anotheria.asg.util.locking.helper.DocumentLockingHelper;
import net.anotheria.asg.data.MultilingualObject;
import net.anotheria.webutils.filehandling.actions.FileStorage;
import net.anotheria.webutils.filehandling.beans.TemporaryFileHolder;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import net.anotheria.util.StringUtils;
import org.apache.commons.lang.WordUtils;
import net.anotheria.maf.bean.annotations.Form;


public class MultiOpDialogImagesAction extends BaseImageAction{

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


	@Override
	public ActionForward execute(ActionMapping mapping, @Form(EditImageFB.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("asresourcedataImageDelete"))
			return asresourcedataImageDelete(mapping, af, req, res);
		if (path.equals("asresourcedataImageDuplicate"))
			return asresourcedataImageDuplicate(mapping, af, req, res);
		if (path.equals("asresourcedataImageUpdate"))
			return asresourcedataImageUpdate(mapping, af, req, res);
		if (path.equals("asresourcedataImageClose"))
			return asresourcedataImageClose(mapping, af, req, res);
		if (path.equals("asresourcedataImageCopyLang"))
			return asresourcedataImageCopyLang(mapping, af, req, res);
		if (path.equals("asresourcedataImageSwitchMultilang"))
			return asresourcedataImageSwitchMultilang(mapping, af, req, res);
		if (path.equals("asresourcedataImageLock"))
			return asresourcedataImageLock(mapping, af, req, res);
		if (path.equals("asresourcedataImageUnLock"))
			return asresourcedataImageUnLock(mapping, af, req, res);
		throw new IllegalArgumentException("Unknown path: "+path);
	}

	public ActionForward asresourcedataImageDelete(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){
		Image imageCurr = getASResourceDataService().getImage(id);
		if (imageCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)imageCurr;
		DocumentLockingHelper.delete.checkExecutionPermission(lockable, false, getUserId(req));
		}
		getASResourceDataService().deleteImage(id);
		FileStorage.removeFilePermanently( imageCurr.getImage() );
	}
	res.sendRedirect("asresourcedataImageShow?ts="+System.currentTimeMillis());
	return null;
}

public ActionForward asresourcedataImageDuplicate(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	Image imageSrc = getASResourceDataService().getImage(id);
	Image imageDest = ImageFactory.createImage(imageSrc);

	imageDest.setImage(FileStorage.cloneFilePermanently( imageDest.getImage() ));

	Image imageCreated = getASResourceDataService().createImage(imageDest);
	res.sendRedirect("asresourcedataImageEdit?ts="+System.currentTimeMillis()+"&"+PARAM_ID+"="+imageCreated.getId());

	return null;
}

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

public ActionForward asresourcedataImageUpdate(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	EditImageFB form = (EditImageFB) af;
	boolean create = false;
	Image image = null;
	if (form.getId()==null) {
	res.sendRedirect("asresourcedataLocalizationBundleShow?ts="+System.currentTimeMillis());
	return null;
}
if (form.getId().length()>0){
	image = (Image)getASResourceDataService().getImage(form.getId()).clone();
}else{
	image = ImageFactory.createImage();
	create = true;
}

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

//skipped id because it's readonly.
image.setName(form.getName());
image.setTitle(form.getTitle());
image.setAliasEN(form.getAliasEN());
image.setAliasDE(form.getAliasDE());
image.setAltEN(form.getAltEN());
image.setAltDE(form.getAltDE());
//handle image
TemporaryFileHolder holder_image = FileStorage.getTemporaryFile(req,"image");
if (holder_image!=null && holder_image.getData()!=null){
	FileStorage.removeFilePermanently( image.getImage() );
	FileStorage.storeFilePermanently(req, holder_image.getFileName(),"image");
	image.setImage(holder_image.getFileName());
	FileStorage.removeTemporaryFile(req,"image");
}

// delete image method start
String fieldName = req.getParameter("fieldName");
String fileName = req.getParameter("fileName");

if (!StringUtils.isEmpty(fieldName) && !StringUtils.isEmpty(fileName)) {
	String setMethodName = "set"+WordUtils.capitalize(fieldName);
	Class c = image.getClass();
	try{
		Method m = c.getDeclaredMethod(setMethodName, new Class[]{String.class});
		m.invoke(image, new Object[]{""});
		FileStorage.removeFilePermanently(fileName);
	}catch (NoSuchMethodException e){
		e.printStackTrace();
	}catch (InvocationTargetException ignored) {
		ignored.printStackTrace();
	}
}
// delete image method end


Image updatedCopy = null;
if (create){
	updatedCopy = getASResourceDataService().createImage(image);
}else{
	canUpdateImages(image, req);
	checkImages(image, req);
	updatedCopy = getASResourceDataService().updateImage(image);
}
if (nextAction.equalsIgnoreCase("stay")){
	res.sendRedirect("asresourcedataImageEdit?ts="+System.currentTimeMillis()+"&pId="+updatedCopy.getId());
}else{
	unlockAfterUpdate(image, req);
	res.sendRedirect("asresourcedataImageShow?ts="+System.currentTimeMillis());
}
return null;
}
/**
 * Simply unlocks document after updation.
 */
private void unlockAfterUpdate(Image image, HttpServletRequest req) throws Exception{
	if(((LockableObject)image).isLocked())
		unLockImages(image, req, false);
}

public ActionForward asresourcedataImageCopyLang(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String sourceLanguage = req.getParameter("pSrcLang");
	if (sourceLanguage==null || sourceLanguage.length()==0)
		throw new RuntimeException("No source language");

	String destLanguage = req.getParameter("pDestLang");
	if (destLanguage==null || destLanguage.length()==0)
		throw new RuntimeException("No destination language");

	String id = getStringParameter(req, PARAM_ID);
	Image image = getASResourceDataService().getImage(id);
	canUpdateImages(image, req);
	checkImages(image, req);
	image.copyLANG2LANG(sourceLanguage, destLanguage);
	getASResourceDataService().updateImage(image);
	res.sendRedirect("asresourcedataImageEdit?ts="+System.currentTimeMillis()+"&pId="+id);
	return null;
}

public ActionForward asresourcedataImageSwitchMultilang(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	String value = getStringParameter(req, "value");
	Image image = getASResourceDataService().getImage(id);
	canUpdateImages(image, req);
	checkImages(image, req);
	((MultilingualObject)image).setMultilingualDisabledInstance(Boolean.valueOf(value));
	getASResourceDataService().updateImage(image);
	res.sendRedirect("asresourcedataImageEdit?ts="+System.currentTimeMillis()+"&pId="+id);
	return null;
}

public ActionForward asresourcedataImageLock(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	Image imageCurr = id != null && !id.equals("") ? getASResourceDataService().getImage(id) : null;
	if(imageCurr != null && imageCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)imageCurr;
		DocumentLockingHelper.lock.checkExecutionPermission(lockable,false,getUserId(req));
		lockImages(imageCurr, req);
	}
	res.sendRedirect(getRedirectUrl(req, imageCurr));
	return null;
}

public ActionForward asresourcedataImageUnLock(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	Image imageCurr = id != null && !id.equals("") ? getASResourceDataService().getImage(id) : null;
	if(imageCurr != null && imageCurr instanceof LockableObject){ 
		LockableObject lockable = (LockableObject)imageCurr;
		DocumentLockingHelper.unLock.checkExecutionPermission(lockable,isUserInRole(req, "admin"),getUserId(req));
		unLockImages(imageCurr, req, false);
	}
	res.sendRedirect(getRedirectUrl(req, imageCurr));
	return null;
}

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

public ActionForward asresourcedataImageClose(ActionMapping mapping, FormBean af, HttpServletRequest req, HttpServletResponse res) throws Exception{
	String id = getStringParameter(req, PARAM_ID);
	Image imageCurr = id != null && !id.equals("") ? getASResourceDataService().getImage(id) : null;
	if(imageCurr != null && imageCurr instanceof LockableObject && ((LockableObject)imageCurr).isLocked()) 
		unLockImages(imageCurr, req, false);
	res.sendRedirect("asresourcedataImageShow?ts="+System.currentTimeMillis());
	return null;
}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy