1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A Class that implements administrative methods
|
4
|
* Copyright: 2008 Regents of the University of California and the
|
5
|
* National Center for Ecological Analysis and Synthesis
|
6
|
* Authors: Michael Daigle
|
7
|
*
|
8
|
* '$Author: daigle $'
|
9
|
* '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
|
10
|
* '$Revision: 4080 $'
|
11
|
*
|
12
|
* This program is free software; you can redistribute it and/or modify
|
13
|
* it under the terms of the GNU General Public License as published by
|
14
|
* the Free Software Foundation; either version 2 of the License, or
|
15
|
* (at your option) any later version.
|
16
|
*
|
17
|
* This program is distributed in the hope that it will be useful,
|
18
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
* GNU General Public License for more details.
|
21
|
*
|
22
|
* You should have received a copy of the GNU General Public License
|
23
|
* along with this program; if not, write to the Free Software
|
24
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
25
|
*/
|
26
|
|
27
|
package edu.ucsb.nceas.metacat.util;
|
28
|
|
29
|
import java.io.IOException;
|
30
|
import java.util.Vector;
|
31
|
|
32
|
import javax.servlet.ServletContext;
|
33
|
import javax.servlet.ServletException;
|
34
|
import javax.servlet.http.HttpServletRequest;
|
35
|
import javax.servlet.http.HttpServletResponse;
|
36
|
|
37
|
import org.apache.log4j.Logger;
|
38
|
|
39
|
public class RequestUtil {
|
40
|
|
41
|
private static Logger logMetacat = Logger.getLogger(RequestUtil.class);
|
42
|
|
43
|
/**
|
44
|
* private constructor - all methods are static so there is no
|
45
|
* no need to instantiate.
|
46
|
*/
|
47
|
private RequestUtil() {}
|
48
|
|
49
|
/**
|
50
|
* Forward a request that was received by this servlet on to another JSP
|
51
|
* page or servlet to continue handling the request.
|
52
|
*
|
53
|
* @param request
|
54
|
* to be forwarded
|
55
|
* @param response
|
56
|
* that can be used for writing output to the client
|
57
|
* @param destination
|
58
|
* the context-relative URL to which the request is forwarded
|
59
|
*/
|
60
|
public static void forwardRequest(HttpServletRequest request,
|
61
|
HttpServletResponse response, String destination)
|
62
|
throws IOException, ServletException {
|
63
|
|
64
|
logMetacat.debug("Forwarding request to " + destination);
|
65
|
ServletContext servletContext = request.getSession()
|
66
|
.getServletContext();
|
67
|
|
68
|
servletContext.getRequestDispatcher(destination).forward(request,
|
69
|
response);
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* Add a list of errors to the request. The pages will pick up the errors
|
74
|
* and display them where appropriate.
|
75
|
*
|
76
|
* @param request
|
77
|
* the request that will get forwarded
|
78
|
* @param errorVector
|
79
|
* a list of error strings
|
80
|
*/
|
81
|
public static void setRequestErrors(HttpServletRequest request,
|
82
|
Vector<String> errorVector) {
|
83
|
request.setAttribute("formErrors", "true");
|
84
|
request.setAttribute("processingErrors", errorVector);
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* Add a list of form errors to the request. The pages will pick up the
|
89
|
* errors and display them where appropriate.
|
90
|
*
|
91
|
* @param request
|
92
|
* the request that will get forwarded
|
93
|
* @param errorVector
|
94
|
* a list of form error strings
|
95
|
*/
|
96
|
public static void setRequestFormErrors(HttpServletRequest request,
|
97
|
Vector<String> errorVector) {
|
98
|
request.setAttribute("formErrors", "true");
|
99
|
request.setAttribute("formFieldErrors", errorVector);
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* Add a list of success messages to the request. The pages will pick up the
|
104
|
* messages and display them where appropriate.
|
105
|
*
|
106
|
* @param request
|
107
|
* the request that will get forwarded
|
108
|
* @param errorVector
|
109
|
* a list of success message strings
|
110
|
*/
|
111
|
public static void setRequestSuccess(HttpServletRequest request,
|
112
|
Vector<String> successVector) {
|
113
|
request.setAttribute("formSuccess", "true");
|
114
|
request.setAttribute("processingSuccess", successVector);
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* Add a list of general messages to the request. The pages will pick up the
|
119
|
* messages and display them where appropriate.
|
120
|
*
|
121
|
* @param request
|
122
|
* the request that will get forwarded
|
123
|
* @param errorVector
|
124
|
* a list of general message strings
|
125
|
*/
|
126
|
public static void setRequestMessage(HttpServletRequest request,
|
127
|
Vector<String> messageVector) {
|
128
|
request.setAttribute("formMessage", "true");
|
129
|
request.setAttribute("processingMessage", messageVector);
|
130
|
}
|
131
|
|
132
|
/**
|
133
|
* Add a list of general messages to the request. The pages will pick up the
|
134
|
* messages and display them where appropriate.
|
135
|
*
|
136
|
* @param request
|
137
|
* the request that will get forwarded
|
138
|
* @param errorVector
|
139
|
* a list of general message strings
|
140
|
*/
|
141
|
public static void clearRequestMessages(HttpServletRequest request) {
|
142
|
request.setAttribute("formMessage", null);
|
143
|
request.setAttribute("formSuccess", null);
|
144
|
request.setAttribute("formErrors", null);
|
145
|
request.setAttribute("processingMessage", null);
|
146
|
request.setAttribute("processingSuccess", null);
|
147
|
request.setAttribute("formFieldErrors", null);
|
148
|
request.setAttribute("processingErrors", null);
|
149
|
}
|
150
|
|
151
|
/**
|
152
|
* Add the user's login id to the session on this request
|
153
|
*
|
154
|
* @param request
|
155
|
* the request that will get forwarded
|
156
|
* @param userId
|
157
|
* the user's login id
|
158
|
*/
|
159
|
public static void setUserId(HttpServletRequest request, String userId) {
|
160
|
request.getSession().setAttribute("userId", userId);
|
161
|
}
|
162
|
}
|