annotate gnv/src/main/java/de/intevation/gnv/action/ArtifactDatabaseActionBase.java @ 1022:28a0628b11b0

Added license file and license header. gnv/trunk@1258 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 02 Nov 2010 17:15:08 +0000
parents 33198e55371c
children
rev   line source
1022
28a0628b11b0 Added license file and license header.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 991
diff changeset
1 /*
28a0628b11b0 Added license file and license header.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 991
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
28a0628b11b0 Added license file and license header.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 991
diff changeset
3 *
28a0628b11b0 Added license file and license header.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 991
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
28a0628b11b0 Added license file and license header.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 991
diff changeset
5 * Read the file LGPL.txt coming with the software for details
28a0628b11b0 Added license file and license header.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 991
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
28a0628b11b0 Added license file and license header.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 991
diff changeset
7 */
28a0628b11b0 Added license file and license header.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 991
diff changeset
8
4
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
9 package de.intevation.gnv.action;
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
10
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
11 import javax.servlet.http.HttpServletRequest;
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
12 import javax.servlet.http.HttpServletResponse;
991
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
13 import javax.servlet.http.HttpSession;
4
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
14
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
15 import org.apache.log4j.Logger;
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
16 import org.apache.struts.action.Action;
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
17 import org.apache.struts.action.ActionForm;
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
18 import org.apache.struts.action.ActionForward;
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
19 import org.apache.struts.action.ActionMapping;
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
20
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
21 /**
963
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
22 * Basicimplemantation for all Actions which should serv request for
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
23 * the GNV.
684
57fa8019fbdc Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 683
diff changeset
24 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
681
15ac78a91d1b Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 409
diff changeset
25 *
4
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
26 */
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
27 public class ArtifactDatabaseActionBase extends Action {
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
28
963
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
29 /**
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
30 * The id of the action which should used if the execution
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
31 * of the action was successful.
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
32 */
8
65ff6fcfee0c Some Basic Stuff for WebProjects
Tim Englich <tim.englich@intevation.de>
parents: 4
diff changeset
33 protected final static String SUCCSESS_FORWARD_ID = "success";
963
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
34
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
35 /**
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
36 * The id of the action which should be used if an exception has occurred
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
37 * during the execution.
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
38 */
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 8
diff changeset
39 protected final static String EXCEPTION_FORWARD_ID = "success";
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 34
diff changeset
40
4
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
41 /**
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
42 * the logger, used to log exceptions and additonaly information
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
43 */
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 34
diff changeset
44 private static Logger log = Logger
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 34
diff changeset
45 .getLogger(ArtifactDatabaseActionBase.class);
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 34
diff changeset
46
4
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
47 /**
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
48 * Constructor
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
49 */
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
50 public ArtifactDatabaseActionBase() {
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
51 super();
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
52 }
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
53
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
54 @Override
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
55 public ActionForward execute(ActionMapping mapping, ActionForm form,
38
fccf90761825 Format Code to max 80 Chars per Row better Formatter choosen
Tim Englich <tim.englich@intevation.de>
parents: 36
diff changeset
56 HttpServletRequest request,
fccf90761825 Format Code to max 80 Chars per Row better Formatter choosen
Tim Englich <tim.englich@intevation.de>
parents: 36
diff changeset
57 HttpServletResponse response) throws Exception {
8
65ff6fcfee0c Some Basic Stuff for WebProjects
Tim Englich <tim.englich@intevation.de>
parents: 4
diff changeset
58 log.debug("ArtifactDatabaseActionBase.execute");
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 8
diff changeset
59 ActionForward forward = mapping.findForward(SUCCSESS_FORWARD_ID);
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 8
diff changeset
60 return forward;
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 8
diff changeset
61 }
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 34
diff changeset
62
963
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
63 /**
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
64 * Returns the Action that should be used if an exception has occurred.
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
65 * @param mapping the mapping which holds all available Actions
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
66 * @return the Action that should be used.
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
67 */
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 34
diff changeset
68 protected ActionForward getExceptionForward(ActionMapping mapping) {
34
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 8
diff changeset
69 log.debug("ArtifactDatabaseActionBase.getExceptionForward");
25fdec8b4c69 Added Global Errorhandling to the GNV-Client
Tim Englich <tim.englich@intevation.de>
parents: 8
diff changeset
70 ActionForward lForward = mapping.findForward(EXCEPTION_FORWARD_ID);
8
65ff6fcfee0c Some Basic Stuff for WebProjects
Tim Englich <tim.englich@intevation.de>
parents: 4
diff changeset
71 return lForward;
4
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
72 }
705
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
73
963
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
74 /**
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
75 * Encodes the <code>String</code> to prevent cross-site-scripting
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
76 * @param s the string that should be encoded
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
77 * @return the encoded string
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
78 */
705
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
79 protected String encode(String s) {
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
80 log.debug("String to encode: " + s);
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
81 s = s.replaceAll("<", "&lt;");
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
82 s = s.replaceAll(">", "&gt;");
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
83 s = s.replaceAll("\"", "&quot;");
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
84 s = s.replaceAll("&", "&amp;");
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
85
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
86 log.debug("Encoded string: " + s);
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
87 return s;
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
88 }
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
89
963
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
90 /**
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
91 * Encodes the <code>StringArray</code> to prevent cross-site-scripting
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
92 * @param s the stringarray that should be encoded
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
93 * @return the encoded stringarray
0441e78cd900 Add more Javadocs
Tim Englich <tim.englich@intevation.de>
parents: 705
diff changeset
94 */
705
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
95 protected String[] encode(String[] s) {
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
96 if (s == null)
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
97 return null;
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
98
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
99 String[] good = new String[s.length];
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
100 for (int i = 0; i < good.length; i++) {
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
101 good[i] = encode(s[i]);
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
102 }
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
103
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
104 return good;
f550bd27a3f1 Html characters in strings inserted by the user are quoted (issue221).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 700
diff changeset
105 }
991
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
106
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
107
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
108 protected boolean isSessionExhausted(HttpServletRequest request) {
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
109 HttpSession session = request.getSession();
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
110 return session.isNew();
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
111 }
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
112
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
113
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
114 protected ActionForward sessionExhaustedForward(
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
115 ActionMapping mapping, ActionForm form,
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
116 HttpServletRequest request, HttpServletResponse response)
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
117 throws Exception
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
118 {
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
119 request.setAttribute(
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
120 CommunicationKeys.REQUEST_EXCEPTION_SESSION_ID,
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
121 "SessionTimeout has occured");
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
122
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
123 log.warn("Session timed out.");
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
124
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
125 return new FetchArtifactFactoriesAction().execute(
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
126 mapping, form, request, response);
33198e55371c Improved session handling in the gui. If a session has timed out, the user gets to the start point - the fis selection.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 963
diff changeset
127 }
4
72951b955f00 Basic Struts-Infrastructur Added
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
128 }
700
89ade245ca7a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 690
diff changeset
129 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org