ingo@1022: /* ingo@1022: * Copyright (c) 2010 by Intevation GmbH ingo@1022: * ingo@1022: * This program is free software under the LGPL (>=v2.1) ingo@1022: * Read the file LGPL.txt coming with the software for details ingo@1022: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@1022: */ ingo@1022: tim@4: package de.intevation.gnv.action; tim@4: tim@4: import javax.servlet.http.HttpServletRequest; tim@4: import javax.servlet.http.HttpServletResponse; ingo@991: import javax.servlet.http.HttpSession; tim@4: tim@4: import org.apache.log4j.Logger; tim@4: import org.apache.struts.action.Action; tim@4: import org.apache.struts.action.ActionForm; tim@4: import org.apache.struts.action.ActionForward; tim@4: import org.apache.struts.action.ActionMapping; tim@4: tim@4: /** tim@963: * Basicimplemantation for all Actions which should serv request for tim@963: * the GNV. sascha@684: * @author Tim Englich sascha@681: * tim@4: */ tim@4: public class ArtifactDatabaseActionBase extends Action { tim@4: tim@963: /** tim@963: * The id of the action which should used if the execution tim@963: * of the action was successful. tim@963: */ tim@8: protected final static String SUCCSESS_FORWARD_ID = "success"; tim@963: tim@963: /** tim@963: * The id of the action which should be used if an exception has occurred tim@963: * during the execution. tim@963: */ tim@34: protected final static String EXCEPTION_FORWARD_ID = "success"; tim@36: tim@4: /** tim@4: * the logger, used to log exceptions and additonaly information tim@4: */ tim@36: private static Logger log = Logger tim@36: .getLogger(ArtifactDatabaseActionBase.class); tim@36: tim@4: /** tim@4: * Constructor tim@4: */ tim@4: public ArtifactDatabaseActionBase() { tim@4: super(); tim@4: } tim@4: tim@4: @Override tim@4: public ActionForward execute(ActionMapping mapping, ActionForm form, tim@38: HttpServletRequest request, tim@38: HttpServletResponse response) throws Exception { tim@8: log.debug("ArtifactDatabaseActionBase.execute"); tim@34: ActionForward forward = mapping.findForward(SUCCSESS_FORWARD_ID); tim@34: return forward; tim@34: } tim@36: tim@963: /** tim@963: * Returns the Action that should be used if an exception has occurred. tim@963: * @param mapping the mapping which holds all available Actions tim@963: * @return the Action that should be used. tim@963: */ tim@36: protected ActionForward getExceptionForward(ActionMapping mapping) { tim@34: log.debug("ArtifactDatabaseActionBase.getExceptionForward"); tim@34: ActionForward lForward = mapping.findForward(EXCEPTION_FORWARD_ID); tim@8: return lForward; tim@4: } ingo@705: tim@963: /** tim@963: * Encodes the String to prevent cross-site-scripting tim@963: * @param s the string that should be encoded tim@963: * @return the encoded string tim@963: */ ingo@705: protected String encode(String s) { ingo@705: log.debug("String to encode: " + s); ingo@705: s = s.replaceAll("<", "<"); ingo@705: s = s.replaceAll(">", ">"); ingo@705: s = s.replaceAll("\"", """); ingo@705: s = s.replaceAll("&", "&"); ingo@705: ingo@705: log.debug("Encoded string: " + s); ingo@705: return s; ingo@705: } ingo@705: tim@963: /** tim@963: * Encodes the StringArray to prevent cross-site-scripting tim@963: * @param s the stringarray that should be encoded tim@963: * @return the encoded stringarray tim@963: */ ingo@705: protected String[] encode(String[] s) { ingo@705: if (s == null) ingo@705: return null; ingo@705: ingo@705: String[] good = new String[s.length]; ingo@705: for (int i = 0; i < good.length; i++) { ingo@705: good[i] = encode(s[i]); ingo@705: } ingo@705: ingo@705: return good; ingo@705: } ingo@991: ingo@991: ingo@991: protected boolean isSessionExhausted(HttpServletRequest request) { ingo@991: HttpSession session = request.getSession(); ingo@991: return session.isNew(); ingo@991: } ingo@991: ingo@991: ingo@991: protected ActionForward sessionExhaustedForward( ingo@991: ActionMapping mapping, ActionForm form, ingo@991: HttpServletRequest request, HttpServletResponse response) ingo@991: throws Exception ingo@991: { ingo@991: request.setAttribute( ingo@991: CommunicationKeys.REQUEST_EXCEPTION_SESSION_ID, ingo@991: "SessionTimeout has occured"); ingo@991: ingo@991: log.warn("Session timed out."); ingo@991: ingo@991: return new FetchArtifactFactoriesAction().execute( ingo@991: mapping, form, request, response); ingo@991: } tim@4: } sascha@700: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :