first commit
This commit is contained in:
169
hrmsEjb/org/apache/struts/action/Action.java
Normal file
169
hrmsEjb/org/apache/struts/action/Action.java
Normal file
@@ -0,0 +1,169 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.sql.DataSource;
|
||||
import org.apache.struts.config.ModuleConfig;
|
||||
import org.apache.struts.util.MessageResources;
|
||||
import org.apache.struts.util.RequestUtils;
|
||||
import org.apache.struts.util.TokenProcessor;
|
||||
|
||||
public class Action {
|
||||
public static final String ACTION_SERVLET_KEY = "org.apache.struts.action.ACTION_SERVLET";
|
||||
|
||||
public static final String APPLICATION_KEY = "org.apache.struts.action.MODULE";
|
||||
|
||||
public static final String DATA_SOURCE_KEY = "org.apache.struts.action.DATA_SOURCE";
|
||||
|
||||
public static final String ERROR_KEY = "org.apache.struts.action.ERROR";
|
||||
|
||||
public static final String EXCEPTION_KEY = "org.apache.struts.action.EXCEPTION";
|
||||
|
||||
public static final String FORM_BEANS_KEY = "org.apache.struts.action.FORM_BEANS";
|
||||
|
||||
public static final String FORWARDS_KEY = "org.apache.struts.action.FORWARDS";
|
||||
|
||||
public static final String LOCALE_KEY = "org.apache.struts.action.LOCALE";
|
||||
|
||||
public static final String MAPPING_KEY = "org.apache.struts.action.mapping.instance";
|
||||
|
||||
public static final String MAPPINGS_KEY = "org.apache.struts.action.MAPPINGS";
|
||||
|
||||
public static final String MESSAGE_KEY = "org.apache.struts.action.ACTION_MESSAGE";
|
||||
|
||||
public static final String MESSAGES_KEY = "org.apache.struts.action.MESSAGE";
|
||||
|
||||
public static final String MULTIPART_KEY = "org.apache.struts.action.mapping.multipartclass";
|
||||
|
||||
public static final String PLUG_INS_KEY = "org.apache.struts.action.PLUG_INS";
|
||||
|
||||
public static final String REQUEST_PROCESSOR_KEY = "org.apache.struts.action.REQUEST_PROCESSOR";
|
||||
|
||||
public static final String SERVLET_KEY = "org.apache.struts.action.SERVLET_MAPPING";
|
||||
|
||||
public static final String TRANSACTION_TOKEN_KEY = "org.apache.struts.action.TOKEN";
|
||||
|
||||
private static TokenProcessor token = TokenProcessor.getInstance();
|
||||
|
||||
protected static Locale defaultLocale = Locale.getDefault();
|
||||
|
||||
protected ActionServlet servlet = null;
|
||||
|
||||
public ActionServlet getServlet() {
|
||||
return this.servlet;
|
||||
}
|
||||
|
||||
public void setServlet(ActionServlet servlet) {
|
||||
this.servlet = servlet;
|
||||
}
|
||||
|
||||
public ActionForward execute(ActionMapping mapping, ActionForm form, ServletRequest request, ServletResponse response) throws Exception {
|
||||
return perform(mapping, form, request, response);
|
||||
}
|
||||
|
||||
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
return perform(mapping, form, request, response);
|
||||
}
|
||||
|
||||
public ActionForward perform(ActionMapping mapping, ActionForm form, ServletRequest request, ServletResponse response) throws IOException, ServletException {
|
||||
try {
|
||||
return perform(mapping, form, (HttpServletRequest)request, (HttpServletResponse)response);
|
||||
} catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String generateToken(HttpServletRequest request) {
|
||||
return token.generateToken(request);
|
||||
}
|
||||
|
||||
protected DataSource getDataSource(HttpServletRequest request) {
|
||||
return getDataSource(request, "org.apache.struts.action.DATA_SOURCE");
|
||||
}
|
||||
|
||||
protected DataSource getDataSource(HttpServletRequest request, String key) {
|
||||
ServletContext context = getServlet().getServletContext();
|
||||
ModuleConfig moduleConfig = RequestUtils.getModuleConfig(request, context);
|
||||
return (DataSource)context.getAttribute(key + moduleConfig.getPrefix());
|
||||
}
|
||||
|
||||
protected Locale getLocale(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession();
|
||||
Locale locale = (Locale)session.getAttribute("org.apache.struts.action.LOCALE");
|
||||
if (locale == null)
|
||||
locale = defaultLocale;
|
||||
return locale;
|
||||
}
|
||||
|
||||
protected MessageResources getResources() {
|
||||
return (MessageResources)this.servlet.getServletContext().getAttribute("org.apache.struts.action.MESSAGE");
|
||||
}
|
||||
|
||||
protected MessageResources getResources(HttpServletRequest request) {
|
||||
return (MessageResources)request.getAttribute("org.apache.struts.action.MESSAGE");
|
||||
}
|
||||
|
||||
protected MessageResources getResources(HttpServletRequest request, String key) {
|
||||
ServletContext context = getServlet().getServletContext();
|
||||
ModuleConfig moduleConfig = RequestUtils.getModuleConfig(request, context);
|
||||
return (MessageResources)context.getAttribute(key + moduleConfig.getPrefix());
|
||||
}
|
||||
|
||||
protected boolean isCancelled(HttpServletRequest request) {
|
||||
return (request.getAttribute("org.apache.struts.action.CANCEL") != null);
|
||||
}
|
||||
|
||||
protected boolean isTokenValid(HttpServletRequest request) {
|
||||
return token.isTokenValid(request, false);
|
||||
}
|
||||
|
||||
protected boolean isTokenValid(HttpServletRequest request, boolean reset) {
|
||||
return token.isTokenValid(request, reset);
|
||||
}
|
||||
|
||||
protected void resetToken(HttpServletRequest request) {
|
||||
token.resetToken(request);
|
||||
}
|
||||
|
||||
protected void saveErrors(HttpServletRequest request, ActionErrors errors) {
|
||||
if (errors == null || errors.isEmpty()) {
|
||||
request.removeAttribute("org.apache.struts.action.ERROR");
|
||||
return;
|
||||
}
|
||||
request.setAttribute("org.apache.struts.action.ERROR", errors);
|
||||
}
|
||||
|
||||
protected void saveMessages(HttpServletRequest request, ActionMessages messages) {
|
||||
if (messages == null || messages.isEmpty()) {
|
||||
request.removeAttribute("org.apache.struts.action.ACTION_MESSAGE");
|
||||
return;
|
||||
}
|
||||
request.setAttribute("org.apache.struts.action.ACTION_MESSAGE", messages);
|
||||
}
|
||||
|
||||
protected void saveToken(HttpServletRequest request) {
|
||||
token.saveToken(request);
|
||||
}
|
||||
|
||||
protected void setLocale(HttpServletRequest request, Locale locale) {
|
||||
HttpSession session = request.getSession();
|
||||
if (locale == null)
|
||||
locale = defaultLocale;
|
||||
session.setAttribute("org.apache.struts.action.LOCALE", locale);
|
||||
}
|
||||
|
||||
protected String toHex(byte[] buffer) {
|
||||
return token.toHex(buffer);
|
||||
}
|
||||
}
|
29
hrmsEjb/org/apache/struts/action/ActionError.java
Normal file
29
hrmsEjb/org/apache/struts/action/ActionError.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ActionError extends ActionMessage implements Serializable {
|
||||
public ActionError(String key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
public ActionError(String key, Object value0) {
|
||||
super(key, value0);
|
||||
}
|
||||
|
||||
public ActionError(String key, Object value0, Object value1) {
|
||||
super(key, value0, value1);
|
||||
}
|
||||
|
||||
public ActionError(String key, Object value0, Object value1, Object value2) {
|
||||
super(key, value0, value1, value2);
|
||||
}
|
||||
|
||||
public ActionError(String key, Object value0, Object value1, Object value2, Object value3) {
|
||||
super(key, value0, value1, value2, value3);
|
||||
}
|
||||
|
||||
public ActionError(String key, Object[] values) {
|
||||
super(key, values);
|
||||
}
|
||||
}
|
17
hrmsEjb/org/apache/struts/action/ActionErrors.java
Normal file
17
hrmsEjb/org/apache/struts/action/ActionErrors.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ActionErrors extends ActionMessages implements Serializable {
|
||||
public static final String GLOBAL_ERROR = "org.apache.struts.action.GLOBAL_ERROR";
|
||||
|
||||
public ActionErrors() {}
|
||||
|
||||
public ActionErrors(ActionErrors messages) {
|
||||
super(messages);
|
||||
}
|
||||
|
||||
public void add(String property, ActionError error) {
|
||||
add(property, error);
|
||||
}
|
||||
}
|
52
hrmsEjb/org/apache/struts/action/ActionForm.java
Normal file
52
hrmsEjb/org/apache/struts/action/ActionForm.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.struts.upload.MultipartRequestHandler;
|
||||
|
||||
public abstract class ActionForm implements Serializable {
|
||||
protected transient ActionServlet servlet = null;
|
||||
|
||||
protected transient MultipartRequestHandler multipartRequestHandler;
|
||||
|
||||
protected ActionServlet getServlet() {
|
||||
return this.servlet;
|
||||
}
|
||||
|
||||
public ActionServletWrapper getServletWrapper() {
|
||||
return new ActionServletWrapper(getServlet());
|
||||
}
|
||||
|
||||
public MultipartRequestHandler getMultipartRequestHandler() {
|
||||
return this.multipartRequestHandler;
|
||||
}
|
||||
|
||||
public void setServlet(ActionServlet servlet) {
|
||||
this.servlet = servlet;
|
||||
}
|
||||
|
||||
public void setMultipartRequestHandler(MultipartRequestHandler multipartRequestHandler) {
|
||||
this.multipartRequestHandler = multipartRequestHandler;
|
||||
}
|
||||
|
||||
public void reset(ActionMapping mapping, ServletRequest request) {
|
||||
try {
|
||||
reset(mapping, (HttpServletRequest)request);
|
||||
} catch (ClassCastException e) {}
|
||||
}
|
||||
|
||||
public void reset(ActionMapping mapping, HttpServletRequest request) {}
|
||||
|
||||
public ActionErrors validate(ActionMapping mapping, ServletRequest request) {
|
||||
try {
|
||||
return validate(mapping, (HttpServletRequest)request);
|
||||
} catch (ClassCastException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
|
||||
return null;
|
||||
}
|
||||
}
|
12
hrmsEjb/org/apache/struts/action/ActionFormBean.java
Normal file
12
hrmsEjb/org/apache/struts/action/ActionFormBean.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import org.apache.struts.config.FormBeanConfig;
|
||||
|
||||
public class ActionFormBean extends FormBeanConfig {
|
||||
public ActionFormBean() {}
|
||||
|
||||
public ActionFormBean(String name, String type) {
|
||||
setName(name);
|
||||
setType(type);
|
||||
}
|
||||
}
|
32
hrmsEjb/org/apache/struts/action/ActionFormBeans.java
Normal file
32
hrmsEjb/org/apache/struts/action/ActionFormBeans.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.apache.commons.collections.FastHashMap;
|
||||
|
||||
public class ActionFormBeans implements Serializable {
|
||||
protected FastHashMap formBeans = new FastHashMap();
|
||||
|
||||
public boolean getFast() {
|
||||
return this.formBeans.getFast();
|
||||
}
|
||||
|
||||
public void setFast(boolean fast) {
|
||||
this.formBeans.setFast(fast);
|
||||
}
|
||||
|
||||
public void addFormBean(ActionFormBean formBean) {
|
||||
this.formBeans.put(formBean.getName(), formBean);
|
||||
}
|
||||
|
||||
public ActionFormBean findFormBean(String name) {
|
||||
return (ActionFormBean)this.formBeans.get(name);
|
||||
}
|
||||
|
||||
public String[] findFormBeans() {
|
||||
return (String[])this.formBeans.keySet().toArray((Object[])new String[this.formBeans.size()]);
|
||||
}
|
||||
|
||||
public void removeFormBean(ActionFormBean formBean) {
|
||||
this.formBeans.remove(formBean.getName());
|
||||
}
|
||||
}
|
32
hrmsEjb/org/apache/struts/action/ActionForward.java
Normal file
32
hrmsEjb/org/apache/struts/action/ActionForward.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import org.apache.struts.config.ForwardConfig;
|
||||
|
||||
public class ActionForward extends ForwardConfig {
|
||||
public ActionForward() {
|
||||
this((String)null, false);
|
||||
}
|
||||
|
||||
public ActionForward(String path) {
|
||||
this(path, false);
|
||||
}
|
||||
|
||||
public ActionForward(String path, boolean redirect) {
|
||||
setName(null);
|
||||
setPath(path);
|
||||
setRedirect(redirect);
|
||||
}
|
||||
|
||||
public ActionForward(String name, String path, boolean redirect) {
|
||||
setName(name);
|
||||
setPath(path);
|
||||
setRedirect(redirect);
|
||||
}
|
||||
|
||||
public ActionForward(String name, String path, boolean redirect, boolean contextRelative) {
|
||||
setName(name);
|
||||
setPath(path);
|
||||
setRedirect(redirect);
|
||||
setContextRelative(contextRelative);
|
||||
}
|
||||
}
|
32
hrmsEjb/org/apache/struts/action/ActionForwards.java
Normal file
32
hrmsEjb/org/apache/struts/action/ActionForwards.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.apache.commons.collections.FastHashMap;
|
||||
|
||||
public class ActionForwards implements Serializable {
|
||||
private FastHashMap forwards = new FastHashMap();
|
||||
|
||||
public boolean getFast() {
|
||||
return this.forwards.getFast();
|
||||
}
|
||||
|
||||
public void setFast(boolean fast) {
|
||||
this.forwards.setFast(fast);
|
||||
}
|
||||
|
||||
public void addForward(ActionForward forward) {
|
||||
this.forwards.put(forward.getName(), forward);
|
||||
}
|
||||
|
||||
public ActionForward findForward(String name) {
|
||||
return (ActionForward)this.forwards.get(name);
|
||||
}
|
||||
|
||||
public String[] findForwards() {
|
||||
return (String[])this.forwards.keySet().toArray((Object[])new String[this.forwards.size()]);
|
||||
}
|
||||
|
||||
public void removeForward(ActionForward forward) {
|
||||
this.forwards.remove(forward.getName());
|
||||
}
|
||||
}
|
44
hrmsEjb/org/apache/struts/action/ActionMapping.java
Normal file
44
hrmsEjb/org/apache/struts/action/ActionMapping.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.apache.struts.config.ActionConfig;
|
||||
import org.apache.struts.config.ExceptionConfig;
|
||||
import org.apache.struts.config.ForwardConfig;
|
||||
|
||||
public class ActionMapping extends ActionConfig {
|
||||
public ExceptionConfig findException(Class type) {
|
||||
ExceptionConfig config = null;
|
||||
do {
|
||||
String name = type.getName();
|
||||
config = findExceptionConfig(name);
|
||||
if (config != null)
|
||||
return config;
|
||||
config = getModuleConfig().findExceptionConfig(name);
|
||||
if (config != null)
|
||||
return config;
|
||||
type = type.getSuperclass();
|
||||
} while (type != null);
|
||||
return null;
|
||||
}
|
||||
|
||||
public ActionForward findForward(String name) {
|
||||
ForwardConfig config = findForwardConfig(name);
|
||||
if (config == null)
|
||||
config = getModuleConfig().findForwardConfig(name);
|
||||
return (ActionForward)config;
|
||||
}
|
||||
|
||||
public String[] findForwards() {
|
||||
ArrayList results = new ArrayList();
|
||||
ForwardConfig[] fcs = findForwardConfigs();
|
||||
for (int i = 0; i < fcs.length; i++)
|
||||
results.add(fcs[i].getName());
|
||||
return results.<String>toArray(new String[results.size()]);
|
||||
}
|
||||
|
||||
public ActionForward getInputForward() {
|
||||
if (getModuleConfig().getControllerConfig().getInputForward())
|
||||
return findForward(getInput());
|
||||
return new ActionForward(getInput());
|
||||
}
|
||||
}
|
64
hrmsEjb/org/apache/struts/action/ActionMappings.java
Normal file
64
hrmsEjb/org/apache/struts/action/ActionMappings.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.commons.collections.FastHashMap;
|
||||
|
||||
public class ActionMappings implements Serializable {
|
||||
protected FastHashMap mappings = new FastHashMap();
|
||||
|
||||
protected transient ActionServlet servlet = null;
|
||||
|
||||
protected ActionMapping unknown = null;
|
||||
|
||||
public boolean getFast() {
|
||||
return this.mappings.getFast();
|
||||
}
|
||||
|
||||
public void setFast(boolean fast) {
|
||||
this.mappings.setFast(fast);
|
||||
}
|
||||
|
||||
public ActionMapping getUnknown(ServletRequest request) {
|
||||
return getUnknown((HttpServletRequest)request);
|
||||
}
|
||||
|
||||
public ActionMapping getUnknown(HttpServletRequest request) {
|
||||
if (this.unknown != null)
|
||||
return this.unknown;
|
||||
String[] paths = findMappings();
|
||||
for (int i = 0; i < paths.length; i++) {
|
||||
ActionMapping mapping = findMapping(paths[i]);
|
||||
if (mapping.getUnknown()) {
|
||||
this.unknown = mapping;
|
||||
return mapping;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ActionServlet getServlet() {
|
||||
return this.servlet;
|
||||
}
|
||||
|
||||
public void setServlet(ActionServlet servlet) {
|
||||
this.servlet = servlet;
|
||||
}
|
||||
|
||||
public void addMapping(ActionMapping mapping) {
|
||||
this.mappings.put(mapping.getPath(), mapping);
|
||||
}
|
||||
|
||||
public ActionMapping findMapping(String path) {
|
||||
return (ActionMapping)this.mappings.get(path);
|
||||
}
|
||||
|
||||
public String[] findMappings() {
|
||||
return (String[])this.mappings.keySet().toArray((Object[])new String[this.mappings.size()]);
|
||||
}
|
||||
|
||||
public void removeMapping(ActionMapping mapping) {
|
||||
this.mappings.remove(mapping.getPath());
|
||||
}
|
||||
}
|
59
hrmsEjb/org/apache/struts/action/ActionMessage.java
Normal file
59
hrmsEjb/org/apache/struts/action/ActionMessage.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ActionMessage implements Serializable {
|
||||
protected String key;
|
||||
|
||||
protected Object[] values;
|
||||
|
||||
public ActionMessage(String key) {
|
||||
this.key = null;
|
||||
this.values = null;
|
||||
this.key = key;
|
||||
this.values = null;
|
||||
}
|
||||
|
||||
public ActionMessage(String key, Object value0) {
|
||||
this.key = null;
|
||||
this.values = null;
|
||||
this.key = key;
|
||||
this.values = new Object[] { value0 };
|
||||
}
|
||||
|
||||
public ActionMessage(String key, Object value0, Object value1) {
|
||||
this.key = null;
|
||||
this.values = null;
|
||||
this.key = key;
|
||||
this.values = new Object[] { value0, value1 };
|
||||
}
|
||||
|
||||
public ActionMessage(String key, Object value0, Object value1, Object value2) {
|
||||
this.key = null;
|
||||
this.values = null;
|
||||
this.key = key;
|
||||
this.values = new Object[] { value0, value1, value2 };
|
||||
}
|
||||
|
||||
public ActionMessage(String key, Object value0, Object value1, Object value2, Object value3) {
|
||||
this.key = null;
|
||||
this.values = null;
|
||||
this.key = key;
|
||||
this.values = new Object[] { value0, value1, value2, value3 };
|
||||
}
|
||||
|
||||
public ActionMessage(String key, Object[] values) {
|
||||
this.key = null;
|
||||
this.values = null;
|
||||
this.key = key;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public Object[] getValues() {
|
||||
return this.values;
|
||||
}
|
||||
}
|
143
hrmsEjb/org/apache/struts/action/ActionMessages.java
Normal file
143
hrmsEjb/org/apache/struts/action/ActionMessages.java
Normal file
@@ -0,0 +1,143 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ActionMessages implements Serializable {
|
||||
public static final String GLOBAL_MESSAGE = "org.apache.struts.action.GLOBAL_MESSAGE";
|
||||
|
||||
protected HashMap messages = new HashMap();
|
||||
|
||||
protected int iCount = 0;
|
||||
|
||||
public ActionMessages() {}
|
||||
|
||||
public ActionMessages(ActionMessages messages) {
|
||||
add(messages);
|
||||
}
|
||||
|
||||
public void add(String property, ActionMessage message) {
|
||||
ActionMessageItem item = (ActionMessageItem)this.messages.get(property);
|
||||
List list = null;
|
||||
if (item == null) {
|
||||
list = new ArrayList();
|
||||
item = new ActionMessageItem(this, list, this.iCount++);
|
||||
this.messages.put(property, item);
|
||||
} else {
|
||||
list = item.getList();
|
||||
}
|
||||
list.add(message);
|
||||
}
|
||||
|
||||
public void add(ActionMessages messages) {
|
||||
if (messages == null)
|
||||
return;
|
||||
Iterator props = messages.properties();
|
||||
while (props.hasNext()) {
|
||||
String property = props.next();
|
||||
Iterator msgs = messages.get(property);
|
||||
while (msgs.hasNext()) {
|
||||
ActionMessage msg = msgs.next();
|
||||
add(property, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.messages.clear();
|
||||
}
|
||||
|
||||
public boolean empty() {
|
||||
return isEmpty();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.messages.isEmpty();
|
||||
}
|
||||
|
||||
public Iterator get() {
|
||||
if (this.messages.isEmpty())
|
||||
return Collections.EMPTY_LIST.iterator();
|
||||
ArrayList results = new ArrayList();
|
||||
ArrayList actionItems = new ArrayList();
|
||||
for (Iterator i = this.messages.values().iterator(); i.hasNext();)
|
||||
actionItems.add(i.next());
|
||||
Collections.sort(actionItems, new Comparator(this) {
|
||||
private final ActionMessages this$0;
|
||||
|
||||
public int compare(Object o1, Object o2) {
|
||||
return ((ActionMessages.ActionMessageItem)o1).getOrder() - ((ActionMessages.ActionMessageItem)o2).getOrder();
|
||||
}
|
||||
});
|
||||
for (Iterator iterator = actionItems.iterator(); iterator.hasNext(); ) {
|
||||
ActionMessageItem ami = (ActionMessageItem)iterator.next();
|
||||
for (Iterator messages = ami.getList().iterator(); messages.hasNext();)
|
||||
results.add(messages.next());
|
||||
}
|
||||
return results.iterator();
|
||||
}
|
||||
|
||||
public Iterator get(String property) {
|
||||
ActionMessageItem item = (ActionMessageItem)this.messages.get(property);
|
||||
if (item == null)
|
||||
return Collections.EMPTY_LIST.iterator();
|
||||
return item.getList().iterator();
|
||||
}
|
||||
|
||||
public Iterator properties() {
|
||||
return this.messages.keySet().iterator();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
int total = 0;
|
||||
for (Iterator i = this.messages.values().iterator(); i.hasNext(); ) {
|
||||
ActionMessageItem ami = i.next();
|
||||
total += ami.getList().size();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public int size(String property) {
|
||||
ActionMessageItem ami = (ActionMessageItem)this.messages.get(property);
|
||||
if (ami == null)
|
||||
return 0;
|
||||
return ami.getList().size();
|
||||
}
|
||||
|
||||
protected class ActionMessageItem implements Serializable {
|
||||
protected List list;
|
||||
|
||||
protected int iOrder;
|
||||
|
||||
private final ActionMessages this$0;
|
||||
|
||||
public ActionMessageItem(ActionMessages this$0, List list, int iOrder) {
|
||||
this.this$0 = this$0;
|
||||
this.list = null;
|
||||
this.iOrder = 0;
|
||||
this.list = list;
|
||||
this.iOrder = iOrder;
|
||||
}
|
||||
|
||||
public List getList() {
|
||||
return this.list;
|
||||
}
|
||||
|
||||
public void setList(List list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return this.iOrder;
|
||||
}
|
||||
|
||||
public void setOrder(int iOrder) {
|
||||
this.iOrder = iOrder;
|
||||
}
|
||||
}
|
||||
}
|
646
hrmsEjb/org/apache/struts/action/ActionServlet.java
Normal file
646
hrmsEjb/org/apache/struts/action/ActionServlet.java
Normal file
@@ -0,0 +1,646 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.MissingResourceException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.UnavailableException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.sql.DataSource;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
import org.apache.commons.beanutils.Converter;
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.apache.commons.beanutils.converters.BigDecimalConverter;
|
||||
import org.apache.commons.beanutils.converters.BigIntegerConverter;
|
||||
import org.apache.commons.beanutils.converters.BooleanConverter;
|
||||
import org.apache.commons.beanutils.converters.ByteConverter;
|
||||
import org.apache.commons.beanutils.converters.CharacterConverter;
|
||||
import org.apache.commons.beanutils.converters.DoubleConverter;
|
||||
import org.apache.commons.beanutils.converters.FloatConverter;
|
||||
import org.apache.commons.beanutils.converters.IntegerConverter;
|
||||
import org.apache.commons.beanutils.converters.LongConverter;
|
||||
import org.apache.commons.beanutils.converters.ShortConverter;
|
||||
import org.apache.commons.collections.FastHashMap;
|
||||
import org.apache.commons.digester.Digester;
|
||||
import org.apache.commons.digester.RuleSet;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.struts.config.ActionConfig;
|
||||
import org.apache.struts.config.ApplicationConfig;
|
||||
import org.apache.struts.config.ConfigRuleSet;
|
||||
import org.apache.struts.config.ControllerConfig;
|
||||
import org.apache.struts.config.DataSourceConfig;
|
||||
import org.apache.struts.config.FormBeanConfig;
|
||||
import org.apache.struts.config.ForwardConfig;
|
||||
import org.apache.struts.config.MessageResourcesConfig;
|
||||
import org.apache.struts.config.ModuleConfig;
|
||||
import org.apache.struts.config.ModuleConfigFactory;
|
||||
import org.apache.struts.config.PlugInConfig;
|
||||
import org.apache.struts.config.impl.ModuleConfigImpl;
|
||||
import org.apache.struts.util.GenericDataSource;
|
||||
import org.apache.struts.util.MessageResources;
|
||||
import org.apache.struts.util.MessageResourcesFactory;
|
||||
import org.apache.struts.util.RequestUtils;
|
||||
import org.apache.struts.util.ServletContextWriter;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class ActionServlet extends HttpServlet {
|
||||
protected String config = "/WEB-INF/struts-config.xml";
|
||||
|
||||
protected Digester configDigester = null;
|
||||
|
||||
protected boolean convertNull = false;
|
||||
|
||||
protected FastHashMap dataSources = new FastHashMap();
|
||||
|
||||
protected int debug = 0;
|
||||
|
||||
protected MessageResources internal = null;
|
||||
|
||||
protected String internalName = "org.apache.struts.action.ActionResources";
|
||||
|
||||
protected static Log log = LogFactory.getLog(ActionServlet.class);
|
||||
|
||||
protected RequestProcessor processor = null;
|
||||
|
||||
protected String[] registrations = new String[] { "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN", "/org/apache/struts/resources/struts-config_1_0.dtd", "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN", "/org/apache/struts/resources/struts-config_1_1.dtd", "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", "/org/apache/struts/resources/web-app_2_2.dtd", "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", "/org/apache/struts/resources/web-app_2_3.dtd" };
|
||||
|
||||
protected String servletMapping = null;
|
||||
|
||||
protected String servletName = null;
|
||||
|
||||
public void destroy() {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(this.internal.getMessage("finalizing"));
|
||||
destroyModules();
|
||||
destroyDataSources();
|
||||
destroyInternal();
|
||||
getServletContext().removeAttribute("org.apache.struts.action.ACTION_SERVLET");
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null)
|
||||
classLoader = ActionServlet.class.getClassLoader();
|
||||
try {
|
||||
LogFactory.release(classLoader);
|
||||
} catch (Throwable t) {}
|
||||
}
|
||||
|
||||
public void init() throws ServletException {
|
||||
initInternal();
|
||||
initOther();
|
||||
initServlet();
|
||||
getServletContext().setAttribute("org.apache.struts.action.ACTION_SERVLET", this);
|
||||
ModuleConfig moduleConfig = initModuleConfig("", this.config);
|
||||
initModuleMessageResources(moduleConfig);
|
||||
initModuleDataSources(moduleConfig);
|
||||
initModulePlugIns(moduleConfig);
|
||||
moduleConfig.freeze();
|
||||
Enumeration names = getServletConfig().getInitParameterNames();
|
||||
while (names.hasMoreElements()) {
|
||||
String name = names.nextElement();
|
||||
if (!name.startsWith("config/"))
|
||||
continue;
|
||||
String prefix = name.substring(6);
|
||||
moduleConfig = initModuleConfig(prefix, getServletConfig().getInitParameter(name));
|
||||
initModuleMessageResources(moduleConfig);
|
||||
initModuleDataSources(moduleConfig);
|
||||
initModulePlugIns(moduleConfig);
|
||||
moduleConfig.freeze();
|
||||
}
|
||||
destroyConfigDigester();
|
||||
}
|
||||
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
process(request, response);
|
||||
}
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
process(request, response);
|
||||
}
|
||||
|
||||
public void addServletMapping(String servletName, String urlPattern) {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Process servletName=" + servletName + ", urlPattern=" + urlPattern);
|
||||
if (servletName == null)
|
||||
return;
|
||||
if (servletName.equals(this.servletName))
|
||||
this.servletMapping = urlPattern;
|
||||
}
|
||||
|
||||
public DataSource findDataSource(String key) {
|
||||
if (key == null)
|
||||
return (DataSource)this.dataSources.get("org.apache.struts.action.DATA_SOURCE");
|
||||
return (DataSource)this.dataSources.get(key);
|
||||
}
|
||||
|
||||
public ActionFormBean findFormBean(String name) {
|
||||
ActionFormBeans afb = (ActionFormBeans)getServletContext().getAttribute("org.apache.struts.action.FORM_BEANS");
|
||||
if (afb == null)
|
||||
return null;
|
||||
return afb.findFormBean(name);
|
||||
}
|
||||
|
||||
public ActionForward findForward(String name) {
|
||||
ActionForwards af = (ActionForwards)getServletContext().getAttribute("org.apache.struts.action.FORWARDS");
|
||||
if (af == null)
|
||||
return null;
|
||||
return af.findForward(name);
|
||||
}
|
||||
|
||||
public ActionMapping findMapping(String path) {
|
||||
ActionMappings am = (ActionMappings)getServletContext().getAttribute("org.apache.struts.action.MAPPINGS");
|
||||
if (am == null)
|
||||
return null;
|
||||
return am.findMapping(path);
|
||||
}
|
||||
|
||||
public int getDebug() {
|
||||
return this.debug;
|
||||
}
|
||||
|
||||
public MessageResources getInternal() {
|
||||
return this.internal;
|
||||
}
|
||||
|
||||
public MessageResources getResources() {
|
||||
return (MessageResources)getServletContext().getAttribute("org.apache.struts.action.MESSAGE");
|
||||
}
|
||||
|
||||
public void log(String message, int level) {
|
||||
if (this.debug >= level)
|
||||
log(message);
|
||||
}
|
||||
|
||||
protected void destroyApplications() {
|
||||
destroyModules();
|
||||
}
|
||||
|
||||
protected void destroyModules() {
|
||||
ArrayList values = new ArrayList();
|
||||
Enumeration names = getServletContext().getAttributeNames();
|
||||
while (names.hasMoreElements())
|
||||
values.add(names.nextElement());
|
||||
Iterator keys = values.iterator();
|
||||
while (keys.hasNext()) {
|
||||
String name = keys.next();
|
||||
Object value = getServletContext().getAttribute(name);
|
||||
if (value instanceof ModuleConfig) {
|
||||
ModuleConfig config = (ModuleConfig)value;
|
||||
try {
|
||||
getRequestProcessor(config).destroy();
|
||||
} catch (ServletException e) {
|
||||
log.error(e);
|
||||
}
|
||||
getServletContext().removeAttribute(name);
|
||||
PlugIn[] plugIns = (PlugIn[])getServletContext().getAttribute("org.apache.struts.action.PLUG_INS" + config.getPrefix());
|
||||
if (plugIns != null) {
|
||||
for (int i = 0; i < plugIns.length; i++) {
|
||||
int j = plugIns.length - i + 1;
|
||||
plugIns[j].destroy();
|
||||
}
|
||||
getServletContext().removeAttribute("org.apache.struts.action.PLUG_INS" + config.getPrefix());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void destroyConfigDigester() {
|
||||
this.configDigester = null;
|
||||
}
|
||||
|
||||
protected void destroyDataSources() {
|
||||
synchronized (this.dataSources) {
|
||||
Iterator keys = this.dataSources.keySet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
getServletContext().removeAttribute(key);
|
||||
DataSource dataSource = findDataSource(key);
|
||||
if (dataSource instanceof GenericDataSource) {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(this.internal.getMessage("dataSource.destroy", key));
|
||||
try {
|
||||
((GenericDataSource)dataSource).close();
|
||||
} catch (SQLException e) {
|
||||
log.error(this.internal.getMessage("destroyDataSource", key), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.dataSources.clear();
|
||||
}
|
||||
}
|
||||
|
||||
protected void destroyInternal() {
|
||||
this.internal = null;
|
||||
}
|
||||
|
||||
protected ApplicationConfig getApplicationConfig(HttpServletRequest request) {
|
||||
return new ApplicationConfig((ModuleConfigImpl)getModuleConfig(request));
|
||||
}
|
||||
|
||||
protected ModuleConfig getModuleConfig(HttpServletRequest request) {
|
||||
ModuleConfig config = (ModuleConfig)request.getAttribute("org.apache.struts.action.MODULE");
|
||||
if (config == null)
|
||||
config = (ModuleConfig)getServletContext().getAttribute("org.apache.struts.action.MODULE");
|
||||
return config;
|
||||
}
|
||||
|
||||
protected synchronized RequestProcessor getRequestProcessor(ModuleConfig config) throws ServletException {
|
||||
String key = "org.apache.struts.action.REQUEST_PROCESSOR" + config.getPrefix();
|
||||
RequestProcessor processor = (RequestProcessor)getServletContext().getAttribute(key);
|
||||
if (processor == null) {
|
||||
try {
|
||||
processor = (RequestProcessor)RequestUtils.applicationInstance(config.getControllerConfig().getProcessorClass());
|
||||
} catch (Exception e) {
|
||||
throw new UnavailableException("Cannot initialize RequestProcessor of class " + config.getControllerConfig().getProcessorClass() + ": " + e);
|
||||
}
|
||||
processor.init(this, config);
|
||||
getServletContext().setAttribute(key, processor);
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
|
||||
protected ApplicationConfig initApplicationConfig(String prefix, String path) throws ServletException {
|
||||
return new ApplicationConfig((ModuleConfigImpl)initModuleConfig(prefix, path));
|
||||
}
|
||||
|
||||
protected ModuleConfig initModuleConfig(String prefix, String paths) throws ServletException {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Initializing module path '" + prefix + "' configuration from '" + paths + "'");
|
||||
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
|
||||
ModuleConfig config = factoryObject.createModuleConfig(prefix);
|
||||
String mapping = getServletConfig().getInitParameter("mapping");
|
||||
if (mapping != null)
|
||||
config.setActionMappingClass(mapping);
|
||||
Digester digester = initConfigDigester();
|
||||
while (paths.length() > 0) {
|
||||
digester.push(config);
|
||||
String path = null;
|
||||
int comma = paths.indexOf(',');
|
||||
if (comma >= 0) {
|
||||
path = paths.substring(0, comma).trim();
|
||||
paths = paths.substring(comma + 1);
|
||||
} else {
|
||||
path = paths.trim();
|
||||
paths = "";
|
||||
}
|
||||
if (path.length() < 1)
|
||||
break;
|
||||
parseModuleConfigFile(prefix, paths, config, digester, path);
|
||||
}
|
||||
FormBeanConfig[] fbs = config.findFormBeanConfigs();
|
||||
for (int i = 0; i < fbs.length; i++) {
|
||||
if (fbs[i].getDynamic())
|
||||
DynaActionFormClass.createDynaActionFormClass(fbs[i]);
|
||||
}
|
||||
if (prefix.length() < 1) {
|
||||
defaultControllerConfig(config);
|
||||
defaultMessageResourcesConfig(config);
|
||||
defaultFormBeansConfig(config);
|
||||
defaultForwardsConfig(config);
|
||||
defaultMappingsConfig(config);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
private void parseModuleConfigFile(String prefix, String paths, ModuleConfig config, Digester digester, String path) throws UnavailableException {
|
||||
InputStream input = null;
|
||||
try {
|
||||
URL url = getServletContext().getResource(path);
|
||||
InputSource is = new InputSource(url.toExternalForm());
|
||||
input = getServletContext().getResourceAsStream(path);
|
||||
is.setByteStream(input);
|
||||
digester.parse(is);
|
||||
getServletContext().setAttribute("org.apache.struts.action.MODULE" + prefix, config);
|
||||
} catch (MalformedURLException e) {
|
||||
handleConfigException(paths, e);
|
||||
} catch (IOException e) {
|
||||
handleConfigException(paths, e);
|
||||
} catch (SAXException e) {
|
||||
handleConfigException(paths, e);
|
||||
} finally {
|
||||
if (input != null)
|
||||
try {
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
throw new UnavailableException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleConfigException(String paths, Exception e) throws UnavailableException {
|
||||
log.error(this.internal.getMessage("configParse", paths), e);
|
||||
throw new UnavailableException(this.internal.getMessage("configParse", paths));
|
||||
}
|
||||
|
||||
protected void initApplicationDataSources(ModuleConfig config) throws ServletException {
|
||||
initModuleDataSources(config);
|
||||
}
|
||||
|
||||
protected void initModuleDataSources(ModuleConfig config) throws ServletException {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Initializing module path '" + config.getPrefix() + "' data sources");
|
||||
ServletContextWriter scw = new ServletContextWriter(getServletContext());
|
||||
DataSourceConfig[] dscs = config.findDataSourceConfigs();
|
||||
if (dscs == null)
|
||||
dscs = new DataSourceConfig[0];
|
||||
this.dataSources.setFast(false);
|
||||
for (int i = 0; i < dscs.length; i++) {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Initializing module path '" + config.getPrefix() + "' data source '" + dscs[i].getKey() + "'");
|
||||
DataSource ds = null;
|
||||
try {
|
||||
ds = (DataSource)RequestUtils.applicationInstance(dscs[i].getType());
|
||||
BeanUtils.populate(ds, dscs[i].getProperties());
|
||||
if (ds instanceof GenericDataSource)
|
||||
((GenericDataSource)ds).open();
|
||||
ds.setLogWriter((PrintWriter)scw);
|
||||
} catch (Exception e) {
|
||||
log.error(this.internal.getMessage("dataSource.init", dscs[i].getKey()), e);
|
||||
throw new UnavailableException(this.internal.getMessage("dataSource.init", dscs[i].getKey()));
|
||||
}
|
||||
getServletContext().setAttribute(dscs[i].getKey() + config.getPrefix(), ds);
|
||||
this.dataSources.put(dscs[i].getKey(), ds);
|
||||
}
|
||||
this.dataSources.setFast(true);
|
||||
if ("".equals(config.getPrefix()))
|
||||
initDataSources();
|
||||
}
|
||||
|
||||
protected void initApplicationPlugIns(ModuleConfig config) throws ServletException {
|
||||
initModulePlugIns(config);
|
||||
}
|
||||
|
||||
protected void initModulePlugIns(ModuleConfig config) throws ServletException {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Initializing module path '" + config.getPrefix() + "' plug ins");
|
||||
PlugInConfig[] plugInConfigs = config.findPlugInConfigs();
|
||||
PlugIn[] plugIns = new PlugIn[plugInConfigs.length];
|
||||
getServletContext().setAttribute("org.apache.struts.action.PLUG_INS" + config.getPrefix(), plugIns);
|
||||
for (int i = 0; i < plugIns.length; i++) {
|
||||
try {
|
||||
plugIns[i] = (PlugIn)RequestUtils.applicationInstance(plugInConfigs[i].getClassName());
|
||||
BeanUtils.populate(plugIns[i], plugInConfigs[i].getProperties());
|
||||
try {
|
||||
PropertyUtils.setProperty(plugIns[i], "currentPlugInConfigObject", plugInConfigs[i]);
|
||||
} catch (Exception e) {}
|
||||
plugIns[i].init(this, config);
|
||||
} catch (ServletException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
String errMsg = this.internal.getMessage("plugIn.init", plugInConfigs[i].getClassName());
|
||||
log(errMsg, e);
|
||||
throw new UnavailableException(errMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void initApplicationMessageResources(ModuleConfig config) throws ServletException {
|
||||
initModuleMessageResources(config);
|
||||
}
|
||||
|
||||
protected void initModuleMessageResources(ModuleConfig config) throws ServletException {
|
||||
MessageResourcesConfig[] mrcs = config.findMessageResourcesConfigs();
|
||||
for (int i = 0; i < mrcs.length; i++) {
|
||||
if (mrcs[i].getFactory() != null && mrcs[i].getParameter() != null) {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Initializing module path '" + config.getPrefix() + "' message resources from '" + mrcs[i].getParameter() + "'");
|
||||
String factory = mrcs[i].getFactory();
|
||||
MessageResourcesFactory.setFactoryClass(factory);
|
||||
MessageResourcesFactory factoryObject = MessageResourcesFactory.createFactory();
|
||||
MessageResources resources = factoryObject.createResources(mrcs[i].getParameter());
|
||||
resources.setReturnNull(mrcs[i].getNull());
|
||||
getServletContext().setAttribute(mrcs[i].getKey() + config.getPrefix(), resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Digester initConfigDigester() throws ServletException {
|
||||
if (this.configDigester != null)
|
||||
return this.configDigester;
|
||||
boolean validating = true;
|
||||
String value = getServletConfig().getInitParameter("validating");
|
||||
if ("false".equalsIgnoreCase(value) || "no".equalsIgnoreCase(value) || "n".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value))
|
||||
validating = false;
|
||||
this.configDigester = new Digester();
|
||||
this.configDigester.setNamespaceAware(true);
|
||||
this.configDigester.setValidating(validating);
|
||||
this.configDigester.setUseContextClassLoader(true);
|
||||
this.configDigester.addRuleSet((RuleSet)new ConfigRuleSet());
|
||||
for (int i = 0; i < this.registrations.length; i += 2) {
|
||||
URL url = getClass().getResource(this.registrations[i + 1]);
|
||||
if (url != null)
|
||||
this.configDigester.register(this.registrations[i], url.toString());
|
||||
}
|
||||
String rulesets = getServletConfig().getInitParameter("rulesets");
|
||||
if (rulesets == null)
|
||||
rulesets = "";
|
||||
rulesets = rulesets.trim();
|
||||
String ruleset = null;
|
||||
while (rulesets.length() > 0) {
|
||||
int comma = rulesets.indexOf(",");
|
||||
if (comma < 0) {
|
||||
ruleset = rulesets.trim();
|
||||
rulesets = "";
|
||||
} else {
|
||||
ruleset = rulesets.substring(0, comma).trim();
|
||||
rulesets = rulesets.substring(comma + 1).trim();
|
||||
}
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Configuring custom Digester Ruleset of type " + ruleset);
|
||||
try {
|
||||
RuleSet instance = (RuleSet)RequestUtils.applicationInstance(ruleset);
|
||||
this.configDigester.addRuleSet(instance);
|
||||
} catch (Exception e) {
|
||||
log.error("Exception configuring custom Digester RuleSet", e);
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
return this.configDigester;
|
||||
}
|
||||
|
||||
protected void initDataSources() throws ServletException {}
|
||||
|
||||
protected void initInternal() throws ServletException {
|
||||
try {
|
||||
this.internal = MessageResources.getMessageResources(this.internalName);
|
||||
} catch (MissingResourceException e) {
|
||||
log.error("Cannot load internal resources from '" + this.internalName + "'", e);
|
||||
throw new UnavailableException("Cannot load internal resources from '" + this.internalName + "'");
|
||||
}
|
||||
}
|
||||
|
||||
protected void initOther() throws ServletException {
|
||||
String value = null;
|
||||
value = getServletConfig().getInitParameter("config");
|
||||
if (value != null)
|
||||
this.config = value;
|
||||
value = getServletConfig().getInitParameter("debug");
|
||||
if (value != null)
|
||||
try {
|
||||
this.debug = Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
this.debug = 0;
|
||||
}
|
||||
value = getServletConfig().getInitParameter("convertNull");
|
||||
if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value) || "on".equalsIgnoreCase(value) || "y".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value))
|
||||
this.convertNull = true;
|
||||
if (this.convertNull) {
|
||||
ConvertUtils.deregister();
|
||||
ConvertUtils.register((Converter)new BigDecimalConverter(null), BigDecimal.class);
|
||||
ConvertUtils.register((Converter)new BigIntegerConverter(null), BigInteger.class);
|
||||
ConvertUtils.register((Converter)new BooleanConverter(null), Boolean.class);
|
||||
ConvertUtils.register((Converter)new ByteConverter(null), Byte.class);
|
||||
ConvertUtils.register((Converter)new CharacterConverter(null), Character.class);
|
||||
ConvertUtils.register((Converter)new DoubleConverter(null), Double.class);
|
||||
ConvertUtils.register((Converter)new FloatConverter(null), Float.class);
|
||||
ConvertUtils.register((Converter)new IntegerConverter(null), Integer.class);
|
||||
ConvertUtils.register((Converter)new LongConverter(null), Long.class);
|
||||
ConvertUtils.register((Converter)new ShortConverter(null), Short.class);
|
||||
}
|
||||
}
|
||||
|
||||
protected void initServlet() throws ServletException {
|
||||
this.servletName = getServletConfig().getServletName();
|
||||
Digester digester = new Digester();
|
||||
digester.push(this);
|
||||
digester.setNamespaceAware(true);
|
||||
digester.setValidating(false);
|
||||
for (int i = 0; i < this.registrations.length; i += 2) {
|
||||
URL url = getClass().getResource(this.registrations[i + 1]);
|
||||
if (url != null)
|
||||
digester.register(this.registrations[i], url.toString());
|
||||
}
|
||||
digester.addCallMethod("web-app/servlet-mapping", "addServletMapping", 2);
|
||||
digester.addCallParam("web-app/servlet-mapping/servlet-name", 0);
|
||||
digester.addCallParam("web-app/servlet-mapping/url-pattern", 1);
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Scanning web.xml for controller servlet mapping");
|
||||
InputStream input = getServletContext().getResourceAsStream("/WEB-INF/web.xml");
|
||||
try {
|
||||
digester.parse(input);
|
||||
} catch (IOException e) {
|
||||
log.error(this.internal.getMessage("configWebXml"), e);
|
||||
throw new ServletException(e);
|
||||
} catch (SAXException e) {
|
||||
log.error(this.internal.getMessage("configWebXml"), e);
|
||||
throw new ServletException(e);
|
||||
} finally {
|
||||
if (input != null)
|
||||
try {
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
log.error(this.internal.getMessage("configWebXml"), e);
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Mapping for servlet '" + this.servletName + "' = '" + this.servletMapping + "'");
|
||||
if (this.servletMapping != null)
|
||||
getServletContext().setAttribute("org.apache.struts.action.SERVLET_MAPPING", this.servletMapping);
|
||||
}
|
||||
|
||||
protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
RequestUtils.selectModule(request, getServletContext());
|
||||
getRequestProcessor(getModuleConfig(request)).process(request, response);
|
||||
}
|
||||
|
||||
private void defaultControllerConfig(ModuleConfig config) {
|
||||
String value = null;
|
||||
ControllerConfig cc = config.getControllerConfig();
|
||||
value = getServletConfig().getInitParameter("bufferSize");
|
||||
if (value != null)
|
||||
cc.setBufferSize(Integer.parseInt(value));
|
||||
value = getServletConfig().getInitParameter("content");
|
||||
if (value != null)
|
||||
cc.setContentType(value);
|
||||
value = getServletConfig().getInitParameter("locale");
|
||||
if (value != null)
|
||||
if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value)) {
|
||||
cc.setLocale(true);
|
||||
} else {
|
||||
cc.setLocale(false);
|
||||
}
|
||||
value = getServletConfig().getInitParameter("maxFileSize");
|
||||
if (value != null)
|
||||
cc.setMaxFileSize(value);
|
||||
value = getServletConfig().getInitParameter("nocache");
|
||||
if (value != null)
|
||||
if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value)) {
|
||||
cc.setNocache(true);
|
||||
} else {
|
||||
cc.setNocache(false);
|
||||
}
|
||||
value = getServletConfig().getInitParameter("multipartClass");
|
||||
if (value != null)
|
||||
cc.setMultipartClass(value);
|
||||
value = getServletConfig().getInitParameter("tempDir");
|
||||
if (value != null)
|
||||
cc.setTempDir(value);
|
||||
}
|
||||
|
||||
private void defaultFormBeansConfig(ModuleConfig config) {
|
||||
FormBeanConfig[] fbcs = config.findFormBeanConfigs();
|
||||
ActionFormBeans afb = new ActionFormBeans();
|
||||
afb.setFast(false);
|
||||
for (int i = 0; i < fbcs.length; i++)
|
||||
afb.addFormBean((ActionFormBean)fbcs[i]);
|
||||
afb.setFast(true);
|
||||
getServletContext().setAttribute("org.apache.struts.action.FORM_BEANS", afb);
|
||||
}
|
||||
|
||||
private void defaultForwardsConfig(ModuleConfig config) {
|
||||
ForwardConfig[] fcs = config.findForwardConfigs();
|
||||
ActionForwards af = new ActionForwards();
|
||||
af.setFast(false);
|
||||
for (int i = 0; i < fcs.length; i++)
|
||||
af.addForward((ActionForward)fcs[i]);
|
||||
af.setFast(true);
|
||||
getServletContext().setAttribute("org.apache.struts.action.FORWARDS", af);
|
||||
}
|
||||
|
||||
private void defaultMappingsConfig(ModuleConfig config) {
|
||||
ActionConfig[] acs = config.findActionConfigs();
|
||||
ActionMappings am = new ActionMappings();
|
||||
am.setServlet(this);
|
||||
am.setFast(false);
|
||||
for (int i = 0; i < acs.length; i++)
|
||||
am.addMapping((ActionMapping)acs[i]);
|
||||
am.setFast(true);
|
||||
getServletContext().setAttribute("org.apache.struts.action.MAPPINGS", am);
|
||||
}
|
||||
|
||||
private void defaultMessageResourcesConfig(ModuleConfig config) {
|
||||
String value = null;
|
||||
MessageResourcesConfig mrc = config.findMessageResourcesConfig("org.apache.struts.action.MESSAGE");
|
||||
if (mrc == null) {
|
||||
mrc = new MessageResourcesConfig();
|
||||
mrc.setKey("org.apache.struts.action.MESSAGE");
|
||||
config.addMessageResourcesConfig(mrc);
|
||||
}
|
||||
value = getServletConfig().getInitParameter("application");
|
||||
if (value != null)
|
||||
mrc.setParameter(value);
|
||||
value = getServletConfig().getInitParameter("factory");
|
||||
if (value != null)
|
||||
mrc.setFactory(value);
|
||||
value = getServletConfig().getInitParameter("null");
|
||||
if (value != null)
|
||||
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes")) {
|
||||
mrc.setNull(true);
|
||||
} else {
|
||||
mrc.setNull(false);
|
||||
}
|
||||
}
|
||||
}
|
23
hrmsEjb/org/apache/struts/action/ActionServletWrapper.java
Normal file
23
hrmsEjb/org/apache/struts/action/ActionServletWrapper.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import org.apache.struts.upload.MultipartRequestHandler;
|
||||
|
||||
public class ActionServletWrapper {
|
||||
protected transient ActionServlet servlet = null;
|
||||
|
||||
public void log(String message, int level) {
|
||||
this.servlet.log(message, level);
|
||||
}
|
||||
|
||||
public void log(String message) {
|
||||
this.servlet.log(message);
|
||||
}
|
||||
|
||||
public void setServletFor(MultipartRequestHandler object) {
|
||||
object.setServlet(this.servlet);
|
||||
}
|
||||
|
||||
public ActionServletWrapper(ActionServlet servlet) {
|
||||
this.servlet = servlet;
|
||||
}
|
||||
}
|
228
hrmsEjb/org/apache/struts/action/DynaActionForm.java
Normal file
228
hrmsEjb/org/apache/struts/action/DynaActionForm.java
Normal file
@@ -0,0 +1,228 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
import org.apache.commons.beanutils.DynaBean;
|
||||
import org.apache.commons.beanutils.DynaClass;
|
||||
import org.apache.commons.beanutils.DynaProperty;
|
||||
import org.apache.struts.config.FormBeanConfig;
|
||||
import org.apache.struts.config.FormPropertyConfig;
|
||||
|
||||
public class DynaActionForm extends ActionForm implements DynaBean {
|
||||
protected DynaActionFormClass dynaClass = null;
|
||||
|
||||
protected HashMap dynaValues = new HashMap();
|
||||
|
||||
public void initialize(ActionMapping mapping) {
|
||||
String name = mapping.getName();
|
||||
if (name == null)
|
||||
return;
|
||||
FormBeanConfig config = mapping.getModuleConfig().findFormBeanConfig(name);
|
||||
if (config == null)
|
||||
return;
|
||||
FormPropertyConfig[] props = config.findFormPropertyConfigs();
|
||||
for (int i = 0; i < props.length; i++)
|
||||
set(props[i].getName(), props[i].initial());
|
||||
}
|
||||
|
||||
public void reset(ActionMapping mapping, ServletRequest request) {
|
||||
try {
|
||||
reset(mapping, (HttpServletRequest)request);
|
||||
} catch (ClassCastException e) {}
|
||||
}
|
||||
|
||||
public void reset(ActionMapping mapping, HttpServletRequest request) {}
|
||||
|
||||
public boolean contains(String name, String key) {
|
||||
Object value = this.dynaValues.get(name);
|
||||
if (value == null)
|
||||
throw new NullPointerException("No mapped value for '" + name + "(" + key + ")'");
|
||||
if (value instanceof Map)
|
||||
return ((Map)value).containsKey(key);
|
||||
throw new IllegalArgumentException("Non-mapped property for '" + name + "(" + key + ")'");
|
||||
}
|
||||
|
||||
public Object get(String name) {
|
||||
Object value = this.dynaValues.get(name);
|
||||
if (value != null)
|
||||
return value;
|
||||
Class type = getDynaProperty(name).getType();
|
||||
if (type == null)
|
||||
throw new NullPointerException("The type for property " + name + " is invalid");
|
||||
if (!type.isPrimitive())
|
||||
return value;
|
||||
if (type == boolean.class)
|
||||
return Boolean.FALSE;
|
||||
if (type == byte.class)
|
||||
return new Byte((byte)0);
|
||||
if (type == char.class)
|
||||
return new Character(false);
|
||||
if (type == double.class)
|
||||
return new Double(0.0D);
|
||||
if (type == float.class)
|
||||
return new Float(0.0F);
|
||||
if (type == int.class)
|
||||
return new Integer(0);
|
||||
if (type == long.class)
|
||||
return new Long(0L);
|
||||
if (type == short.class)
|
||||
return new Short((short)0);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object get(String name, int index) {
|
||||
Object value = this.dynaValues.get(name);
|
||||
if (value == null)
|
||||
throw new NullPointerException("No indexed value for '" + name + "[" + index + "]'");
|
||||
if (value.getClass().isArray())
|
||||
return Array.get(value, index);
|
||||
if (value instanceof List)
|
||||
return ((List)value).get(index);
|
||||
throw new IllegalArgumentException("Non-indexed property for '" + name + "[" + index + "]'");
|
||||
}
|
||||
|
||||
public Object get(String name, String key) {
|
||||
Object value = this.dynaValues.get(name);
|
||||
if (value == null)
|
||||
throw new NullPointerException("No mapped value for '" + name + "(" + key + ")'");
|
||||
if (value instanceof Map)
|
||||
return ((Map)value).get(key);
|
||||
throw new IllegalArgumentException("Non-mapped property for '" + name + "(" + key + ")'");
|
||||
}
|
||||
|
||||
public DynaClass getDynaClass() {
|
||||
return this.dynaClass;
|
||||
}
|
||||
|
||||
public Map getMap() {
|
||||
return this.dynaValues;
|
||||
}
|
||||
|
||||
public void remove(String name, String key) {
|
||||
Object value = this.dynaValues.get(name);
|
||||
if (value == null)
|
||||
throw new NullPointerException("No mapped value for '" + name + "(" + key + ")'");
|
||||
if (value instanceof Map) {
|
||||
((Map)value).remove(key);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Non-mapped property for '" + name + "(" + key + ")'");
|
||||
}
|
||||
}
|
||||
|
||||
public void set(String name, Object value) {
|
||||
DynaProperty descriptor = getDynaProperty(name);
|
||||
if (descriptor.getType() == null)
|
||||
throw new NullPointerException("The type for property " + name + " is invalid");
|
||||
if (value == null) {
|
||||
if (descriptor.getType().isPrimitive())
|
||||
throw new NullPointerException("Primitive value for '" + name + "'");
|
||||
} else if (!isDynaAssignable(descriptor.getType(), value.getClass())) {
|
||||
throw new ConversionException("Cannot assign value of type '" + value.getClass().getName() + "' to property '" + name + "' of type '" + descriptor.getType().getName() + "'");
|
||||
}
|
||||
this.dynaValues.put(name, value);
|
||||
}
|
||||
|
||||
public void set(String name, int index, Object value) {
|
||||
Object prop = this.dynaValues.get(name);
|
||||
if (prop == null)
|
||||
throw new NullPointerException("No indexed value for '" + name + "[" + index + "]'");
|
||||
if (prop.getClass().isArray()) {
|
||||
Array.set(prop, index, value);
|
||||
} else if (prop instanceof List) {
|
||||
try {
|
||||
((List)prop).set(index, value);
|
||||
} catch (ClassCastException e) {
|
||||
throw new ConversionException(e.getMessage());
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Non-indexed property for '" + name + "[" + index + "]'");
|
||||
}
|
||||
}
|
||||
|
||||
public void set(String name, String key, Object value) {
|
||||
Object prop = this.dynaValues.get(name);
|
||||
if (prop == null)
|
||||
throw new NullPointerException("No mapped value for '" + name + "(" + key + ")'");
|
||||
if (prop instanceof Map) {
|
||||
((Map)prop).put(key, value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Non-mapped property for '" + name + "(" + key + ")'");
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("DynaActionForm[dynaClass=");
|
||||
sb.append(getDynaClass().getName());
|
||||
DynaProperty[] props = getDynaClass().getDynaProperties();
|
||||
if (props == null)
|
||||
props = new DynaProperty[0];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
sb.append(',');
|
||||
sb.append(props[i].getName());
|
||||
sb.append('=');
|
||||
Object value = get(props[i].getName());
|
||||
if (value == null) {
|
||||
sb.append("<NULL>");
|
||||
} else if (value.getClass().isArray()) {
|
||||
int n = Array.getLength(value);
|
||||
sb.append("{");
|
||||
for (int j = 0; j < n; j++) {
|
||||
if (j > 0)
|
||||
sb.append(',');
|
||||
sb.append(Array.get(value, j));
|
||||
}
|
||||
sb.append("}");
|
||||
} else if (value instanceof List) {
|
||||
int n = ((List)value).size();
|
||||
sb.append("{");
|
||||
for (int j = 0; j < n; j++) {
|
||||
if (j > 0)
|
||||
sb.append(',');
|
||||
sb.append(((List)value).get(j));
|
||||
}
|
||||
sb.append("}");
|
||||
} else if (value instanceof Map) {
|
||||
int n = 0;
|
||||
Iterator keys = ((Map)value).keySet().iterator();
|
||||
sb.append("{");
|
||||
while (keys.hasNext()) {
|
||||
if (n > 0)
|
||||
sb.append(',');
|
||||
n++;
|
||||
String key = keys.next();
|
||||
sb.append(key);
|
||||
sb.append('=');
|
||||
sb.append(((Map)value).get(key));
|
||||
}
|
||||
sb.append("}");
|
||||
} else {
|
||||
sb.append(value);
|
||||
}
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
void setDynaActionFormClass(DynaActionFormClass dynaClass) {
|
||||
this.dynaClass = dynaClass;
|
||||
}
|
||||
|
||||
protected DynaProperty getDynaProperty(String name) {
|
||||
DynaProperty descriptor = getDynaClass().getDynaProperty(name);
|
||||
if (descriptor == null)
|
||||
throw new IllegalArgumentException("Invalid property name '" + name + "'");
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
protected boolean isDynaAssignable(Class dest, Class source) {
|
||||
if (dest.isAssignableFrom(source) || (dest == boolean.class && source == Boolean.class) || (dest == byte.class && source == Byte.class) || (dest == char.class && source == Character.class) || (dest == double.class && source == Double.class) || (dest == float.class && source == Float.class) || (dest == int.class && source == Integer.class) || (dest == long.class && source == Long.class) || (dest == short.class && source == Short.class))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
126
hrmsEjb/org/apache/struts/action/DynaActionFormClass.java
Normal file
126
hrmsEjb/org/apache/struts/action/DynaActionFormClass.java
Normal file
@@ -0,0 +1,126 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import org.apache.commons.beanutils.DynaBean;
|
||||
import org.apache.commons.beanutils.DynaClass;
|
||||
import org.apache.commons.beanutils.DynaProperty;
|
||||
import org.apache.struts.config.FormBeanConfig;
|
||||
import org.apache.struts.config.FormPropertyConfig;
|
||||
import org.apache.struts.config.ModuleConfig;
|
||||
import org.apache.struts.util.RequestUtils;
|
||||
|
||||
public class DynaActionFormClass implements DynaClass, Serializable {
|
||||
protected transient Class beanClass;
|
||||
|
||||
protected FormBeanConfig config;
|
||||
|
||||
protected String name;
|
||||
|
||||
protected DynaProperty[] properties;
|
||||
|
||||
protected HashMap propertiesMap;
|
||||
|
||||
private DynaActionFormClass(FormBeanConfig config) {
|
||||
this.beanClass = null;
|
||||
this.config = null;
|
||||
this.name = null;
|
||||
this.properties = null;
|
||||
this.propertiesMap = new HashMap();
|
||||
introspect(config);
|
||||
}
|
||||
|
||||
protected static transient HashMap dynaClasses = new HashMap();
|
||||
|
||||
protected static String lock = "";
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public DynaProperty getDynaProperty(String name) {
|
||||
if (name == null)
|
||||
throw new IllegalArgumentException("No property name specified");
|
||||
return (DynaProperty)this.propertiesMap.get(name);
|
||||
}
|
||||
|
||||
public DynaProperty[] getDynaProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public DynaBean newInstance() throws IllegalAccessException, InstantiationException {
|
||||
DynaActionForm dynaBean = getBeanClass().newInstance();
|
||||
dynaBean.setDynaActionFormClass(this);
|
||||
FormPropertyConfig[] props = this.config.findFormPropertyConfigs();
|
||||
for (int i = 0; i < props.length; i++)
|
||||
dynaBean.set(props[i].getName(), props[i].initial());
|
||||
return dynaBean;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("DynaActionFormBean[name=");
|
||||
sb.append(this.name);
|
||||
DynaProperty[] props = getDynaProperties();
|
||||
if (props == null)
|
||||
props = new DynaProperty[0];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
sb.append(',');
|
||||
sb.append(props[i].getName());
|
||||
sb.append('/');
|
||||
sb.append(props[i].getType());
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
synchronized (lock) {
|
||||
if (dynaClasses == null)
|
||||
dynaClasses = new HashMap();
|
||||
dynaClasses.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static DynaActionFormClass createDynaActionFormClass(FormBeanConfig config) {
|
||||
synchronized (lock) {
|
||||
if (dynaClasses == null)
|
||||
dynaClasses = new HashMap();
|
||||
ModuleConfig moduleConfig = config.getModuleConfig();
|
||||
String key = config.getName();
|
||||
if (moduleConfig != null)
|
||||
key = key + moduleConfig.getPrefix();
|
||||
DynaActionFormClass dynaClass = (DynaActionFormClass)dynaClasses.get(key);
|
||||
if (dynaClass == null) {
|
||||
dynaClass = new DynaActionFormClass(config);
|
||||
dynaClasses.put(key, dynaClass);
|
||||
}
|
||||
return dynaClass;
|
||||
}
|
||||
}
|
||||
|
||||
protected Class getBeanClass() {
|
||||
if (this.beanClass == null)
|
||||
introspect(this.config);
|
||||
return this.beanClass;
|
||||
}
|
||||
|
||||
protected void introspect(FormBeanConfig config) {
|
||||
this.config = config;
|
||||
try {
|
||||
this.beanClass = RequestUtils.applicationClass(config.getType());
|
||||
} catch (Throwable t) {
|
||||
throw new IllegalArgumentException("Cannot instantiate ActionFormBean class '" + config.getType() + "': " + t);
|
||||
}
|
||||
if (!DynaActionForm.class.isAssignableFrom(this.beanClass))
|
||||
throw new IllegalArgumentException("Class '" + config.getType() + "' is not a subclass of " + "'org.apache.struts.action.DynaActionForm'");
|
||||
this.name = config.getName();
|
||||
FormPropertyConfig[] descriptors = config.findFormPropertyConfigs();
|
||||
if (descriptors == null)
|
||||
descriptors = new FormPropertyConfig[0];
|
||||
this.properties = new DynaProperty[descriptors.length];
|
||||
for (int i = 0; i < descriptors.length; i++) {
|
||||
this.properties[i] = new DynaProperty(descriptors[i].getName(), descriptors[i].getTypeClass());
|
||||
this.propertiesMap.put(this.properties[i].getName(), this.properties[i]);
|
||||
}
|
||||
}
|
||||
}
|
40
hrmsEjb/org/apache/struts/action/ExceptionHandler.java
Normal file
40
hrmsEjb/org/apache/struts/action/ExceptionHandler.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.struts.config.ExceptionConfig;
|
||||
import org.apache.struts.util.ModuleException;
|
||||
|
||||
public class ExceptionHandler {
|
||||
public ActionForward execute(Exception ex, ExceptionConfig ae, ActionMapping mapping, ActionForm formInstance, HttpServletRequest request, HttpServletResponse response) throws ServletException {
|
||||
ActionForward forward = null;
|
||||
ActionError error = null;
|
||||
String property = null;
|
||||
if (ae.getPath() != null) {
|
||||
forward = new ActionForward(ae.getPath());
|
||||
} else {
|
||||
forward = mapping.getInputForward();
|
||||
}
|
||||
if (ex instanceof ModuleException) {
|
||||
error = ((ModuleException)ex).getError();
|
||||
property = ((ModuleException)ex).getProperty();
|
||||
} else {
|
||||
error = new ActionError(ae.getKey(), ex.getMessage());
|
||||
property = error.getKey();
|
||||
}
|
||||
request.setAttribute("org.apache.struts.action.EXCEPTION", ex);
|
||||
storeException(request, property, error, forward, ae.getScope());
|
||||
return forward;
|
||||
}
|
||||
|
||||
protected void storeException(HttpServletRequest request, String property, ActionError error, ActionForward forward, String scope) {
|
||||
ActionErrors errors = new ActionErrors();
|
||||
errors.add(property, error);
|
||||
if ("request".equals(scope)) {
|
||||
request.setAttribute("org.apache.struts.action.ERROR", errors);
|
||||
} else {
|
||||
request.getSession().setAttribute("org.apache.struts.action.ERROR", errors);
|
||||
}
|
||||
}
|
||||
}
|
10
hrmsEjb/org/apache/struts/action/PlugIn.java
Normal file
10
hrmsEjb/org/apache/struts/action/PlugIn.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import org.apache.struts.config.ModuleConfig;
|
||||
|
||||
public interface PlugIn {
|
||||
void destroy();
|
||||
|
||||
void init(ActionServlet paramActionServlet, ModuleConfig paramModuleConfig) throws ServletException;
|
||||
}
|
414
hrmsEjb/org/apache/struts/action/RequestProcessor.java
Normal file
414
hrmsEjb/org/apache/struts/action/RequestProcessor.java
Normal file
@@ -0,0 +1,414 @@
|
||||
package org.apache.struts.action;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.struts.config.ActionConfig;
|
||||
import org.apache.struts.config.ExceptionConfig;
|
||||
import org.apache.struts.config.ForwardConfig;
|
||||
import org.apache.struts.config.ModuleConfig;
|
||||
import org.apache.struts.upload.MultipartRequestWrapper;
|
||||
import org.apache.struts.util.MessageResources;
|
||||
import org.apache.struts.util.RequestUtils;
|
||||
|
||||
public class RequestProcessor {
|
||||
public static final String INCLUDE_PATH_INFO = "javax.servlet.include.path_info";
|
||||
|
||||
public static final String INCLUDE_SERVLET_PATH = "javax.servlet.include.servlet_path";
|
||||
|
||||
protected HashMap actions = new HashMap();
|
||||
|
||||
protected ModuleConfig appConfig = null;
|
||||
|
||||
protected ModuleConfig moduleConfig = null;
|
||||
|
||||
protected static Log log = LogFactory.getLog(RequestProcessor.class);
|
||||
|
||||
protected ActionServlet servlet = null;
|
||||
|
||||
public void destroy() {
|
||||
synchronized (this.actions) {
|
||||
Iterator actions = this.actions.values().iterator();
|
||||
while (actions.hasNext()) {
|
||||
Action action = actions.next();
|
||||
action.setServlet(null);
|
||||
}
|
||||
this.actions.clear();
|
||||
}
|
||||
this.servlet = null;
|
||||
}
|
||||
|
||||
public void init(ActionServlet servlet, ModuleConfig moduleConfig) throws ServletException {
|
||||
synchronized (this.actions) {
|
||||
this.actions.clear();
|
||||
}
|
||||
this.servlet = servlet;
|
||||
this.appConfig = moduleConfig;
|
||||
this.moduleConfig = moduleConfig;
|
||||
}
|
||||
|
||||
public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
request = processMultipart(request);
|
||||
String path = processPath(request, response);
|
||||
if (path == null)
|
||||
return;
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Processing a '" + request.getMethod() + "' for path '" + path + "'");
|
||||
processLocale(request, response);
|
||||
processContent(request, response);
|
||||
processNoCache(request, response);
|
||||
if (!processPreprocess(request, response))
|
||||
return;
|
||||
ActionMapping mapping = processMapping(request, response, path);
|
||||
if (mapping == null)
|
||||
return;
|
||||
if (!processRoles(request, response, mapping))
|
||||
return;
|
||||
ActionForm form = processActionForm(request, response, mapping);
|
||||
processPopulate(request, response, form, mapping);
|
||||
if (!processValidate(request, response, form, mapping))
|
||||
return;
|
||||
if (!processForward(request, response, mapping))
|
||||
return;
|
||||
if (!processInclude(request, response, mapping))
|
||||
return;
|
||||
Action action = processActionCreate(request, response, mapping);
|
||||
if (action == null)
|
||||
return;
|
||||
ActionForward forward = processActionPerform(request, response, action, form, mapping);
|
||||
processForwardConfig(request, response, forward);
|
||||
}
|
||||
|
||||
protected Action processActionCreate(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws IOException {
|
||||
String className = mapping.getType();
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(" Looking for Action instance for class " + className);
|
||||
Action instance = null;
|
||||
synchronized (this.actions) {
|
||||
instance = (Action)this.actions.get(className);
|
||||
if (instance != null) {
|
||||
if (log.isTraceEnabled())
|
||||
log.trace(" Returning existing Action instance");
|
||||
return instance;
|
||||
}
|
||||
if (log.isTraceEnabled())
|
||||
log.trace(" Creating new Action instance");
|
||||
try {
|
||||
instance = (Action)RequestUtils.applicationInstance(className);
|
||||
} catch (Exception e) {
|
||||
log.error(getInternal().getMessage("actionCreate", mapping.getPath()), e);
|
||||
response.sendError(500, getInternal().getMessage("actionCreate", mapping.getPath()));
|
||||
return null;
|
||||
}
|
||||
instance.setServlet(this.servlet);
|
||||
this.actions.put(className, instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
protected ActionForm processActionForm(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) {
|
||||
ActionForm instance = RequestUtils.createActionForm(request, mapping, this.moduleConfig, this.servlet);
|
||||
if (instance == null)
|
||||
return null;
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(" Storing ActionForm bean instance in scope '" + mapping.getScope() + "' under attribute key '" + mapping.getAttribute() + "'");
|
||||
if ("request".equals(mapping.getScope())) {
|
||||
request.setAttribute(mapping.getAttribute(), instance);
|
||||
} else {
|
||||
HttpSession session = request.getSession();
|
||||
session.setAttribute(mapping.getAttribute(), instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
protected void processActionForward(HttpServletRequest request, HttpServletResponse response, ActionForward forward) throws IOException, ServletException {
|
||||
processForwardConfig(request, response, forward);
|
||||
}
|
||||
|
||||
protected void processForwardConfig(HttpServletRequest request, HttpServletResponse response, ForwardConfig forward) throws IOException, ServletException {
|
||||
if (forward == null)
|
||||
return;
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("processForwardConfig(" + forward + ")");
|
||||
String forwardPath = forward.getPath();
|
||||
String uri = null;
|
||||
if (forwardPath.startsWith("/")) {
|
||||
uri = RequestUtils.forwardURL(request, forward);
|
||||
} else {
|
||||
uri = forwardPath;
|
||||
}
|
||||
if (forward.getRedirect()) {
|
||||
if (uri.startsWith("/"))
|
||||
uri = request.getContextPath() + uri;
|
||||
response.sendRedirect(response.encodeRedirectURL(uri));
|
||||
} else {
|
||||
doForward(uri, request, response);
|
||||
}
|
||||
}
|
||||
|
||||
protected ActionForward processActionPerform(HttpServletRequest request, HttpServletResponse response, Action action, ActionForm form, ActionMapping mapping) throws IOException, ServletException {
|
||||
try {
|
||||
return action.execute(mapping, form, request, response);
|
||||
} catch (Exception e) {
|
||||
return processException(request, response, e, form, mapping);
|
||||
}
|
||||
}
|
||||
|
||||
protected void processContent(HttpServletRequest request, HttpServletResponse response) {
|
||||
String contentType = this.moduleConfig.getControllerConfig().getContentType();
|
||||
if (contentType != null)
|
||||
response.setContentType(contentType);
|
||||
}
|
||||
|
||||
protected ActionForward processException(HttpServletRequest request, HttpServletResponse response, Exception exception, ActionForm form, ActionMapping mapping) throws IOException, ServletException {
|
||||
ExceptionConfig config = mapping.findException(exception.getClass());
|
||||
if (config == null) {
|
||||
log.warn(getInternal().getMessage("unhandledException", exception.getClass()));
|
||||
if (exception instanceof IOException)
|
||||
throw (IOException)exception;
|
||||
if (exception instanceof ServletException)
|
||||
throw (ServletException)exception;
|
||||
throw new ServletException(exception);
|
||||
}
|
||||
try {
|
||||
ExceptionHandler handler = (ExceptionHandler)RequestUtils.applicationInstance(config.getHandler());
|
||||
return handler.execute(exception, config, mapping, form, request, response);
|
||||
} catch (Exception e) {
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean processForward(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws IOException, ServletException {
|
||||
String forward = mapping.getForward();
|
||||
if (forward == null)
|
||||
return true;
|
||||
internalModuleRelativeForward(forward, request, response);
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean processInclude(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws IOException, ServletException {
|
||||
String include = mapping.getInclude();
|
||||
if (include == null)
|
||||
return true;
|
||||
internalModuleRelativeInclude(include, request, response);
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void processLocale(HttpServletRequest request, HttpServletResponse response) {
|
||||
if (!this.moduleConfig.getControllerConfig().getLocale())
|
||||
return;
|
||||
HttpSession session = request.getSession();
|
||||
if (session.getAttribute("org.apache.struts.action.LOCALE") != null)
|
||||
return;
|
||||
Locale locale = request.getLocale();
|
||||
if (locale != null) {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(" Setting user locale '" + locale + "'");
|
||||
session.setAttribute("org.apache.struts.action.LOCALE", locale);
|
||||
}
|
||||
}
|
||||
|
||||
protected ActionMapping processMapping(HttpServletRequest request, HttpServletResponse response, String path) throws IOException {
|
||||
ActionMapping mapping = (ActionMapping)this.moduleConfig.findActionConfig(path);
|
||||
if (mapping != null) {
|
||||
request.setAttribute("org.apache.struts.action.mapping.instance", mapping);
|
||||
return mapping;
|
||||
}
|
||||
ActionConfig[] configs = this.moduleConfig.findActionConfigs();
|
||||
for (int i = 0; i < configs.length; i++) {
|
||||
if (configs[i].getUnknown()) {
|
||||
mapping = (ActionMapping)configs[i];
|
||||
request.setAttribute("org.apache.struts.action.mapping.instance", mapping);
|
||||
return mapping;
|
||||
}
|
||||
}
|
||||
log.error(getInternal().getMessage("processInvalid", path));
|
||||
response.sendError(400, getInternal().getMessage("processInvalid", path));
|
||||
return null;
|
||||
}
|
||||
|
||||
protected HttpServletRequest processMultipart(HttpServletRequest request) {
|
||||
if (!"POST".equalsIgnoreCase(request.getMethod()))
|
||||
return request;
|
||||
String contentType = request.getContentType();
|
||||
if (contentType != null && contentType.startsWith("multipart/form-data"))
|
||||
return (HttpServletRequest)new MultipartRequestWrapper(request);
|
||||
return request;
|
||||
}
|
||||
|
||||
protected void processNoCache(HttpServletRequest request, HttpServletResponse response) {
|
||||
if (this.moduleConfig.getControllerConfig().getNocache()) {
|
||||
response.setHeader("Pragma", "No-cache");
|
||||
response.setHeader("Cache-Control", "no-cache");
|
||||
response.setDateHeader("Expires", 1L);
|
||||
}
|
||||
}
|
||||
|
||||
protected String processPath(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
String path = null;
|
||||
path = (String)request.getAttribute("javax.servlet.include.path_info");
|
||||
if (path == null)
|
||||
path = request.getPathInfo();
|
||||
if (path != null && path.length() > 0)
|
||||
return path;
|
||||
path = (String)request.getAttribute("javax.servlet.include.servlet_path");
|
||||
if (path == null)
|
||||
path = request.getServletPath();
|
||||
String prefix = this.moduleConfig.getPrefix();
|
||||
if (!path.startsWith(prefix)) {
|
||||
log.error(getInternal().getMessage("processPath", request.getRequestURI()));
|
||||
response.sendError(400, getInternal().getMessage("processPath", request.getRequestURI()));
|
||||
return null;
|
||||
}
|
||||
path = path.substring(prefix.length());
|
||||
int slash = path.lastIndexOf("/");
|
||||
int period = path.lastIndexOf(".");
|
||||
if (period >= 0 && period > slash)
|
||||
path = path.substring(0, period);
|
||||
return path;
|
||||
}
|
||||
|
||||
protected void processPopulate(HttpServletRequest request, HttpServletResponse response, ActionForm form, ActionMapping mapping) throws ServletException {
|
||||
if (form == null)
|
||||
return;
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(" Populating bean properties from this request");
|
||||
form.setServlet(this.servlet);
|
||||
form.reset(mapping, request);
|
||||
if (mapping.getMultipartClass() != null)
|
||||
request.setAttribute("org.apache.struts.action.mapping.multipartclass", mapping.getMultipartClass());
|
||||
RequestUtils.populate(form, mapping.getPrefix(), mapping.getSuffix(), request);
|
||||
if (request.getParameter("org.apache.struts.taglib.html.CANCEL") != null || request.getParameter("org.apache.struts.taglib.html.CANCEL.x") != null)
|
||||
request.setAttribute("org.apache.struts.action.CANCEL", Boolean.TRUE);
|
||||
}
|
||||
|
||||
protected boolean processPreprocess(HttpServletRequest request, HttpServletResponse response) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean processRoles(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws IOException, ServletException {
|
||||
String[] roles = mapping.getRoleNames();
|
||||
if (roles == null || roles.length < 1)
|
||||
return true;
|
||||
for (int i = 0; i < roles.length; i++) {
|
||||
if (request.isUserInRole(roles[i])) {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(" User '" + request.getRemoteUser() + "' has role '" + roles[i] + "', granting access");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(" User '" + request.getRemoteUser() + "' does not have any required role, denying access");
|
||||
response.sendError(400, getInternal().getMessage("notAuthorized", mapping.getPath()));
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean processValidate(HttpServletRequest request, HttpServletResponse response, ActionForm form, ActionMapping mapping) throws IOException, ServletException {
|
||||
if (form == null)
|
||||
return true;
|
||||
if (request.getAttribute("org.apache.struts.action.CANCEL") != null) {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(" Cancelled transaction, skipping validation");
|
||||
return true;
|
||||
}
|
||||
if (!mapping.getValidate())
|
||||
return true;
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(" Validating input form properties");
|
||||
ActionErrors errors = form.validate(mapping, request);
|
||||
if (errors == null || errors.isEmpty()) {
|
||||
if (log.isTraceEnabled())
|
||||
log.trace(" No errors detected, accepting input");
|
||||
return true;
|
||||
}
|
||||
if (form.getMultipartRequestHandler() != null) {
|
||||
if (log.isTraceEnabled())
|
||||
log.trace(" Rolling back multipart request");
|
||||
form.getMultipartRequestHandler().rollback();
|
||||
}
|
||||
String input = mapping.getInput();
|
||||
if (input == null) {
|
||||
if (log.isTraceEnabled())
|
||||
log.trace(" Validation failed but no input form available");
|
||||
response.sendError(500, getInternal().getMessage("noInput", mapping.getPath()));
|
||||
return false;
|
||||
}
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(" Validation failed, returning to '" + input + "'");
|
||||
request.setAttribute("org.apache.struts.action.ERROR", errors);
|
||||
if (this.moduleConfig.getControllerConfig().getInputForward()) {
|
||||
ForwardConfig forward = mapping.findForward(input);
|
||||
processForwardConfig(request, response, forward);
|
||||
} else {
|
||||
internalModuleRelativeForward(input, request, response);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void internalModuleRelativeForward(String uri, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
uri = this.moduleConfig.getPrefix() + uri;
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(" Delegating via forward to '" + uri + "'");
|
||||
doForward(uri, request, response);
|
||||
}
|
||||
|
||||
protected void internalModuleRelativeInclude(String uri, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
uri = this.moduleConfig.getPrefix() + uri;
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(" Delegating via include to '" + uri + "'");
|
||||
doInclude(uri, request, response);
|
||||
}
|
||||
|
||||
protected void doForward(String uri, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
if (request instanceof MultipartRequestWrapper)
|
||||
request = ((MultipartRequestWrapper)request).getRequest();
|
||||
RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
|
||||
if (rd == null) {
|
||||
response.sendError(500, getInternal().getMessage("requestDispatcher", uri));
|
||||
return;
|
||||
}
|
||||
rd.forward((ServletRequest)request, (ServletResponse)response);
|
||||
}
|
||||
|
||||
protected void doInclude(String uri, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
if (request instanceof MultipartRequestWrapper)
|
||||
request = ((MultipartRequestWrapper)request).getRequest();
|
||||
RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
|
||||
if (rd == null) {
|
||||
response.sendError(500, getInternal().getMessage("requestDispatcher", uri));
|
||||
return;
|
||||
}
|
||||
rd.include((ServletRequest)request, (ServletResponse)response);
|
||||
}
|
||||
|
||||
public int getDebug() {
|
||||
return this.servlet.getDebug();
|
||||
}
|
||||
|
||||
protected MessageResources getInternal() {
|
||||
return this.servlet.getInternal();
|
||||
}
|
||||
|
||||
protected ServletContext getServletContext() {
|
||||
return this.servlet.getServletContext();
|
||||
}
|
||||
|
||||
protected void log(String message) {
|
||||
this.servlet.log(message);
|
||||
}
|
||||
|
||||
protected void log(String message, Throwable exception) {
|
||||
this.servlet.log(message, exception);
|
||||
}
|
||||
}
|
344
hrmsEjb/org/apache/struts/config/ActionConfig.java
Normal file
344
hrmsEjb/org/apache/struts/config/ActionConfig.java
Normal file
@@ -0,0 +1,344 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ActionConfig implements Serializable {
|
||||
protected boolean configured = false;
|
||||
|
||||
protected HashMap exceptions = new HashMap();
|
||||
|
||||
protected HashMap forwards = new HashMap();
|
||||
|
||||
protected ModuleConfig moduleConfig = null;
|
||||
|
||||
public ModuleConfig getApplicationConfig() {
|
||||
return getModuleConfig();
|
||||
}
|
||||
|
||||
public ModuleConfig getModuleConfig() {
|
||||
return this.moduleConfig;
|
||||
}
|
||||
|
||||
public void setApplicationConfig(ModuleConfig moduleConfig) {
|
||||
setModuleConfig(moduleConfig);
|
||||
}
|
||||
|
||||
public void setModuleConfig(ModuleConfig moduleConfig) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.moduleConfig = moduleConfig;
|
||||
}
|
||||
|
||||
protected String attribute = null;
|
||||
|
||||
public String getAttribute() {
|
||||
if (this.attribute == null)
|
||||
return this.name;
|
||||
return this.attribute;
|
||||
}
|
||||
|
||||
public void setAttribute(String attribute) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.attribute = attribute;
|
||||
}
|
||||
|
||||
protected String forward = null;
|
||||
|
||||
public String getForward() {
|
||||
return this.forward;
|
||||
}
|
||||
|
||||
public void setForward(String forward) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.forward = forward;
|
||||
}
|
||||
|
||||
protected String include = null;
|
||||
|
||||
public String getInclude() {
|
||||
return this.include;
|
||||
}
|
||||
|
||||
public void setInclude(String include) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.include = include;
|
||||
}
|
||||
|
||||
protected String input = null;
|
||||
|
||||
public String getInput() {
|
||||
return this.input;
|
||||
}
|
||||
|
||||
public void setInput(String input) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
protected String multipartClass = null;
|
||||
|
||||
public String getMultipartClass() {
|
||||
return this.multipartClass;
|
||||
}
|
||||
|
||||
public void setMultipartClass(String multipartClass) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.multipartClass = multipartClass;
|
||||
}
|
||||
|
||||
protected String name = null;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected String parameter = null;
|
||||
|
||||
public String getParameter() {
|
||||
return this.parameter;
|
||||
}
|
||||
|
||||
public void setParameter(String parameter) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
protected String path = null;
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
protected String prefix = null;
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
protected String roles = null;
|
||||
|
||||
public String getRoles() {
|
||||
return this.roles;
|
||||
}
|
||||
|
||||
public void setRoles(String roles) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.roles = roles;
|
||||
if (roles == null) {
|
||||
this.roleNames = new String[0];
|
||||
return;
|
||||
}
|
||||
ArrayList list = new ArrayList();
|
||||
while (true) {
|
||||
int comma = roles.indexOf(',');
|
||||
if (comma < 0)
|
||||
break;
|
||||
list.add(roles.substring(0, comma).trim());
|
||||
roles = roles.substring(comma + 1);
|
||||
}
|
||||
roles = roles.trim();
|
||||
if (roles.length() > 0)
|
||||
list.add(roles);
|
||||
this.roleNames = list.<String>toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
protected String[] roleNames = new String[0];
|
||||
|
||||
public String[] getRoleNames() {
|
||||
return this.roleNames;
|
||||
}
|
||||
|
||||
protected String scope = "session";
|
||||
|
||||
public String getScope() {
|
||||
return this.scope;
|
||||
}
|
||||
|
||||
public void setScope(String scope) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
protected String suffix = null;
|
||||
|
||||
public String getSuffix() {
|
||||
return this.suffix;
|
||||
}
|
||||
|
||||
public void setSuffix(String suffix) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
protected String type = null;
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
protected boolean unknown = false;
|
||||
|
||||
public boolean getUnknown() {
|
||||
return this.unknown;
|
||||
}
|
||||
|
||||
public void setUnknown(boolean unknown) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.unknown = unknown;
|
||||
}
|
||||
|
||||
protected boolean validate = true;
|
||||
|
||||
public boolean getValidate() {
|
||||
return this.validate;
|
||||
}
|
||||
|
||||
public void setValidate(boolean validate) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.validate = validate;
|
||||
}
|
||||
|
||||
public void addExceptionConfig(ExceptionConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.exceptions.put(config.getType(), config);
|
||||
}
|
||||
|
||||
public void addForwardConfig(ForwardConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.forwards.put(config.getName(), config);
|
||||
}
|
||||
|
||||
public ExceptionConfig findExceptionConfig(String type) {
|
||||
return (ExceptionConfig)this.exceptions.get(type);
|
||||
}
|
||||
|
||||
public ExceptionConfig[] findExceptionConfigs() {
|
||||
ExceptionConfig[] results = new ExceptionConfig[this.exceptions.size()];
|
||||
return (ExceptionConfig[])this.exceptions.values().toArray((Object[])results);
|
||||
}
|
||||
|
||||
public ForwardConfig findForwardConfig(String name) {
|
||||
return (ForwardConfig)this.forwards.get(name);
|
||||
}
|
||||
|
||||
public ForwardConfig[] findForwardConfigs() {
|
||||
ForwardConfig[] results = new ForwardConfig[this.forwards.size()];
|
||||
return (ForwardConfig[])this.forwards.values().toArray((Object[])results);
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
this.configured = true;
|
||||
ExceptionConfig[] econfigs = findExceptionConfigs();
|
||||
for (int i = 0; i < econfigs.length; i++)
|
||||
econfigs[i].freeze();
|
||||
ForwardConfig[] fconfigs = findForwardConfigs();
|
||||
for (int j = 0; j < fconfigs.length; j++)
|
||||
fconfigs[j].freeze();
|
||||
}
|
||||
|
||||
public void removeExceptionConfig(ExceptionConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.exceptions.remove(config.getType());
|
||||
}
|
||||
|
||||
public void removeForwardConfig(ForwardConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.forwards.remove(config.getName());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("ActionConfig[");
|
||||
sb.append("path=");
|
||||
sb.append(this.path);
|
||||
if (this.attribute != null) {
|
||||
sb.append(",attribute=");
|
||||
sb.append(this.attribute);
|
||||
}
|
||||
if (this.forward != null) {
|
||||
sb.append(",forward=");
|
||||
sb.append(this.forward);
|
||||
}
|
||||
if (this.include != null) {
|
||||
sb.append(",include=");
|
||||
sb.append(this.include);
|
||||
}
|
||||
if (this.input != null) {
|
||||
sb.append(",input=");
|
||||
sb.append(this.input);
|
||||
}
|
||||
if (this.multipartClass != null) {
|
||||
sb.append(",multipartClass=");
|
||||
sb.append(this.multipartClass);
|
||||
}
|
||||
if (this.name != null) {
|
||||
sb.append(",name=");
|
||||
sb.append(this.name);
|
||||
}
|
||||
if (this.parameter != null) {
|
||||
sb.append(",parameter=");
|
||||
sb.append(this.parameter);
|
||||
}
|
||||
if (this.prefix != null) {
|
||||
sb.append(",prefix=");
|
||||
sb.append(this.prefix);
|
||||
}
|
||||
if (this.roles != null) {
|
||||
sb.append(",roles=");
|
||||
sb.append(this.roles);
|
||||
}
|
||||
if (this.scope != null) {
|
||||
sb.append(",scope=");
|
||||
sb.append(this.scope);
|
||||
}
|
||||
if (this.suffix != null) {
|
||||
sb.append(",suffix=");
|
||||
sb.append(this.suffix);
|
||||
}
|
||||
if (this.type != null) {
|
||||
sb.append(",type=");
|
||||
sb.append(this.type);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
22
hrmsEjb/org/apache/struts/config/ActionMappingFactory.java
Normal file
22
hrmsEjb/org/apache/struts/config/ActionMappingFactory.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import org.apache.commons.digester.AbstractObjectCreationFactory;
|
||||
import org.apache.struts.util.RequestUtils;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
final class ActionMappingFactory extends AbstractObjectCreationFactory {
|
||||
public Object createObject(Attributes attributes) {
|
||||
String className = attributes.getValue("className");
|
||||
if (className == null) {
|
||||
ModuleConfig mc = (ModuleConfig)this.digester.peek();
|
||||
className = mc.getActionMappingClass();
|
||||
}
|
||||
Object actionMapping = null;
|
||||
try {
|
||||
actionMapping = RequestUtils.applicationInstance(className);
|
||||
} catch (Exception e) {
|
||||
this.digester.getLogger().error("ActionMappingFactory.createObject: ", e);
|
||||
}
|
||||
return actionMapping;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import org.apache.commons.digester.Rule;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
final class AddDataSourcePropertyRule extends Rule {
|
||||
public void begin(Attributes attributes) throws Exception {
|
||||
DataSourceConfig dsc = (DataSourceConfig)this.digester.peek();
|
||||
dsc.addProperty(attributes.getValue("property"), attributes.getValue("value"));
|
||||
}
|
||||
}
|
14
hrmsEjb/org/apache/struts/config/ApplicationConfig.java
Normal file
14
hrmsEjb/org/apache/struts/config/ApplicationConfig.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import org.apache.struts.config.impl.ModuleConfigImpl;
|
||||
|
||||
public class ApplicationConfig extends ModuleConfigImpl {
|
||||
public ApplicationConfig(String prefix) {
|
||||
super(prefix);
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public ApplicationConfig(ModuleConfigImpl moduleConfig) {
|
||||
super(moduleConfig);
|
||||
}
|
||||
}
|
55
hrmsEjb/org/apache/struts/config/ConfigRuleSet.java
Normal file
55
hrmsEjb/org/apache/struts/config/ConfigRuleSet.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import org.apache.commons.digester.Digester;
|
||||
import org.apache.commons.digester.ObjectCreationFactory;
|
||||
import org.apache.commons.digester.RuleSetBase;
|
||||
|
||||
public class ConfigRuleSet extends RuleSetBase {
|
||||
public void addRuleInstances(Digester digester) {
|
||||
digester.addObjectCreate("struts-config/data-sources/data-source", "org.apache.struts.config.DataSourceConfig", "className");
|
||||
digester.addSetProperties("struts-config/data-sources/data-source");
|
||||
digester.addSetNext("struts-config/data-sources/data-source", "addDataSourceConfig", "org.apache.struts.config.DataSourceConfig");
|
||||
digester.addRule("struts-config/data-sources/data-source/set-property", new AddDataSourcePropertyRule());
|
||||
digester.addRule("struts-config/action-mappings", new SetActionMappingClassRule());
|
||||
digester.addFactoryCreate("struts-config/action-mappings/action", (ObjectCreationFactory)new ActionMappingFactory());
|
||||
digester.addSetProperties("struts-config/action-mappings/action");
|
||||
digester.addSetNext("struts-config/action-mappings/action", "addActionConfig", "org.apache.struts.config.ActionConfig");
|
||||
digester.addSetProperty("struts-config/action-mappings/action/set-property", "property", "value");
|
||||
digester.addObjectCreate("struts-config/action-mappings/action/exception", "org.apache.struts.config.ExceptionConfig", "className");
|
||||
digester.addSetProperties("struts-config/action-mappings/action/exception");
|
||||
digester.addSetNext("struts-config/action-mappings/action/exception", "addExceptionConfig", "org.apache.struts.config.ExceptionConfig");
|
||||
digester.addSetProperty("struts-config/action-mappings/action/exception/set-property", "property", "value");
|
||||
digester.addObjectCreate("struts-config/action-mappings/action/forward", "org.apache.struts.action.ActionForward", "className");
|
||||
digester.addSetProperties("struts-config/action-mappings/action/forward");
|
||||
digester.addSetNext("struts-config/action-mappings/action/forward", "addForwardConfig", "org.apache.struts.config.ForwardConfig");
|
||||
digester.addSetProperty("struts-config/action-mappings/action/forward/set-property", "property", "value");
|
||||
digester.addObjectCreate("struts-config/controller", "org.apache.struts.config.ControllerConfig", "className");
|
||||
digester.addSetProperties("struts-config/controller");
|
||||
digester.addSetNext("struts-config/controller", "setControllerConfig", "org.apache.struts.config.ControllerConfig");
|
||||
digester.addSetProperty("struts-config/controller/set-property", "property", "value");
|
||||
digester.addObjectCreate("struts-config/form-beans/form-bean", "org.apache.struts.action.ActionFormBean", "className");
|
||||
digester.addSetProperties("struts-config/form-beans/form-bean");
|
||||
digester.addSetNext("struts-config/form-beans/form-bean", "addFormBeanConfig", "org.apache.struts.config.FormBeanConfig");
|
||||
digester.addObjectCreate("struts-config/form-beans/form-bean/form-property", "org.apache.struts.config.FormPropertyConfig", "className");
|
||||
digester.addSetProperties("struts-config/form-beans/form-bean/form-property");
|
||||
digester.addSetNext("struts-config/form-beans/form-bean/form-property", "addFormPropertyConfig", "org.apache.struts.config.FormPropertyConfig");
|
||||
digester.addSetProperty("struts-config/form-beans/form-bean/form-property/set-property", "property", "value");
|
||||
digester.addSetProperty("struts-config/form-beans/form-bean/set-property", "property", "value");
|
||||
digester.addObjectCreate("struts-config/global-exceptions/exception", "org.apache.struts.config.ExceptionConfig", "className");
|
||||
digester.addSetProperties("struts-config/global-exceptions/exception");
|
||||
digester.addSetNext("struts-config/global-exceptions/exception", "addExceptionConfig", "org.apache.struts.config.ExceptionConfig");
|
||||
digester.addSetProperty("struts-config/global-exceptions/exception/set-property", "property", "value");
|
||||
digester.addObjectCreate("struts-config/global-forwards/forward", "org.apache.struts.action.ActionForward", "className");
|
||||
digester.addSetProperties("struts-config/global-forwards/forward");
|
||||
digester.addSetNext("struts-config/global-forwards/forward", "addForwardConfig", "org.apache.struts.config.ForwardConfig");
|
||||
digester.addSetProperty("struts-config/global-forwards/forward/set-property", "property", "value");
|
||||
digester.addObjectCreate("struts-config/message-resources", "org.apache.struts.config.MessageResourcesConfig", "className");
|
||||
digester.addSetProperties("struts-config/message-resources");
|
||||
digester.addSetNext("struts-config/message-resources", "addMessageResourcesConfig", "org.apache.struts.config.MessageResourcesConfig");
|
||||
digester.addSetProperty("struts-config/message-resources/set-property", "property", "value");
|
||||
digester.addObjectCreate("struts-config/plug-in", "org.apache.struts.config.PlugInConfig");
|
||||
digester.addSetProperties("struts-config/plug-in");
|
||||
digester.addSetNext("struts-config/plug-in", "addPlugInConfig", "org.apache.struts.config.PlugInConfig");
|
||||
digester.addRule("struts-config/plug-in/set-property", new PlugInSetPropertyRule());
|
||||
}
|
||||
}
|
203
hrmsEjb/org/apache/struts/config/ControllerConfig.java
Normal file
203
hrmsEjb/org/apache/struts/config/ControllerConfig.java
Normal file
@@ -0,0 +1,203 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ControllerConfig implements Serializable {
|
||||
protected boolean configured = false;
|
||||
|
||||
protected int bufferSize = 4096;
|
||||
|
||||
public int getBufferSize() {
|
||||
return this.bufferSize;
|
||||
}
|
||||
|
||||
public void setBufferSize(int bufferSize) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
protected String contentType = "text/html";
|
||||
|
||||
public String getContentType() {
|
||||
return this.contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
protected int debug = 0;
|
||||
|
||||
public int getDebug() {
|
||||
return this.debug;
|
||||
}
|
||||
|
||||
public void setDebug(int debug) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
protected String forwardPattern = null;
|
||||
|
||||
public String getForwardPattern() {
|
||||
return this.forwardPattern;
|
||||
}
|
||||
|
||||
public void setForwardPattern(String forwardPattern) {
|
||||
this.forwardPattern = forwardPattern;
|
||||
}
|
||||
|
||||
protected boolean inputForward = false;
|
||||
|
||||
public boolean getInputForward() {
|
||||
return this.inputForward;
|
||||
}
|
||||
|
||||
public void setInputForward(boolean inputForward) {
|
||||
this.inputForward = inputForward;
|
||||
}
|
||||
|
||||
protected boolean locale = true;
|
||||
|
||||
public boolean getLocale() {
|
||||
return this.locale;
|
||||
}
|
||||
|
||||
public void setLocale(boolean locale) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
protected String maxFileSize = "250M";
|
||||
|
||||
public String getMaxFileSize() {
|
||||
return this.maxFileSize;
|
||||
}
|
||||
|
||||
public void setMaxFileSize(String maxFileSize) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.maxFileSize = maxFileSize;
|
||||
}
|
||||
|
||||
protected String memFileSize = "256K";
|
||||
|
||||
public String getMemFileSize() {
|
||||
return this.memFileSize;
|
||||
}
|
||||
|
||||
public void setMemFileSize(String memFileSize) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.memFileSize = memFileSize;
|
||||
}
|
||||
|
||||
protected String multipartClass = "org.apache.struts.upload.CommonsMultipartRequestHandler";
|
||||
|
||||
public String getMultipartClass() {
|
||||
return this.multipartClass;
|
||||
}
|
||||
|
||||
public void setMultipartClass(String multipartClass) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.multipartClass = multipartClass;
|
||||
}
|
||||
|
||||
protected boolean nocache = false;
|
||||
|
||||
public boolean getNocache() {
|
||||
return this.nocache;
|
||||
}
|
||||
|
||||
public void setNocache(boolean nocache) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.nocache = nocache;
|
||||
}
|
||||
|
||||
protected String pagePattern = null;
|
||||
|
||||
public String getPagePattern() {
|
||||
return this.pagePattern;
|
||||
}
|
||||
|
||||
public void setPagePattern(String pagePattern) {
|
||||
this.pagePattern = pagePattern;
|
||||
}
|
||||
|
||||
protected String processorClass = "org.apache.struts.action.RequestProcessor";
|
||||
|
||||
public String getProcessorClass() {
|
||||
return this.processorClass;
|
||||
}
|
||||
|
||||
public void setProcessorClass(String processorClass) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.processorClass = processorClass;
|
||||
}
|
||||
|
||||
protected String tempDir = null;
|
||||
|
||||
public String getTempDir() {
|
||||
return this.tempDir;
|
||||
}
|
||||
|
||||
public void setTempDir(String tempDir) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.tempDir = tempDir;
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
this.configured = true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("ControllerConfig[");
|
||||
sb.append("bufferSize=");
|
||||
sb.append(this.bufferSize);
|
||||
if (this.contentType != null) {
|
||||
sb.append(",contentType=");
|
||||
sb.append(this.contentType);
|
||||
}
|
||||
if (this.forwardPattern != null) {
|
||||
sb.append(",forwardPattern=");
|
||||
sb.append(this.forwardPattern);
|
||||
}
|
||||
sb.append(",inputForward=");
|
||||
sb.append(this.inputForward);
|
||||
sb.append(",locale=");
|
||||
sb.append(this.locale);
|
||||
if (this.maxFileSize != null) {
|
||||
sb.append(",maxFileSize=");
|
||||
sb.append(this.maxFileSize);
|
||||
}
|
||||
if (this.memFileSize != null) {
|
||||
sb.append(",memFileSize=");
|
||||
sb.append(this.memFileSize);
|
||||
}
|
||||
sb.append(",multipartClass=");
|
||||
sb.append(this.multipartClass);
|
||||
sb.append(",nocache=");
|
||||
sb.append(this.nocache);
|
||||
if (this.pagePattern != null) {
|
||||
sb.append(",pagePattern=");
|
||||
sb.append(this.pagePattern);
|
||||
}
|
||||
sb.append(",processorClass=");
|
||||
sb.append(this.processorClass);
|
||||
if (this.tempDir != null) {
|
||||
sb.append(",tempDir=");
|
||||
sb.append(this.tempDir);
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
69
hrmsEjb/org/apache/struts/config/DataSourceConfig.java
Normal file
69
hrmsEjb/org/apache/struts/config/DataSourceConfig.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class DataSourceConfig implements Serializable {
|
||||
protected boolean configured = false;
|
||||
|
||||
protected String key = "org.apache.struts.action.DATA_SOURCE";
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
protected HashMap properties = new HashMap();
|
||||
|
||||
public Map getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
protected String type = "org.apache.struts.util.GenericDataSource";
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void addProperty(String name, String value) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.properties.put(name, value);
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
this.configured = true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("DataSourceConfig[");
|
||||
sb.append("key=");
|
||||
sb.append(this.key);
|
||||
sb.append(",type=");
|
||||
sb.append(this.type);
|
||||
Iterator names = this.properties.keySet().iterator();
|
||||
while (names.hasNext()) {
|
||||
String name = names.next();
|
||||
String value = (String)this.properties.get(name);
|
||||
sb.append(',');
|
||||
sb.append(name);
|
||||
sb.append('=');
|
||||
sb.append(value);
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
101
hrmsEjb/org/apache/struts/config/ExceptionConfig.java
Normal file
101
hrmsEjb/org/apache/struts/config/ExceptionConfig.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ExceptionConfig implements Serializable {
|
||||
protected boolean configured = false;
|
||||
|
||||
protected String bundle = null;
|
||||
|
||||
public String getBundle() {
|
||||
return this.bundle;
|
||||
}
|
||||
|
||||
public void setBundle(String bundle) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.bundle = bundle;
|
||||
}
|
||||
|
||||
protected String handler = "org.apache.struts.action.ExceptionHandler";
|
||||
|
||||
public String getHandler() {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
public void setHandler(String handler) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
protected String key = null;
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
protected String path = null;
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
protected String scope = "request";
|
||||
|
||||
public String getScope() {
|
||||
return this.scope;
|
||||
}
|
||||
|
||||
public void setScope(String scope) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
protected String type = null;
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
this.configured = true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("ExceptionConfig[");
|
||||
sb.append("type=");
|
||||
sb.append(this.type);
|
||||
if (this.bundle != null) {
|
||||
sb.append(",bundle=");
|
||||
sb.append(this.bundle);
|
||||
}
|
||||
sb.append(",key=");
|
||||
sb.append(this.key);
|
||||
sb.append(",path=");
|
||||
sb.append(this.path);
|
||||
sb.append(",scope=");
|
||||
sb.append(this.scope);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
120
hrmsEjb/org/apache/struts/config/FormBeanConfig.java
Normal file
120
hrmsEjb/org/apache/struts/config/FormBeanConfig.java
Normal file
@@ -0,0 +1,120 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import org.apache.struts.action.DynaActionForm;
|
||||
|
||||
public class FormBeanConfig implements Serializable {
|
||||
protected boolean configured = false;
|
||||
|
||||
protected HashMap formProperties = new HashMap();
|
||||
|
||||
protected boolean dynamic = false;
|
||||
|
||||
public boolean getDynamic() {
|
||||
return this.dynamic;
|
||||
}
|
||||
|
||||
public void setDynamic(boolean dynamic) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
}
|
||||
|
||||
protected ModuleConfig moduleConfig = null;
|
||||
|
||||
public ModuleConfig getModuleConfig() {
|
||||
return this.moduleConfig;
|
||||
}
|
||||
|
||||
public void setModuleConfig(ModuleConfig moduleConfig) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.moduleConfig = moduleConfig;
|
||||
}
|
||||
|
||||
protected String name = null;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected String type = null;
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.type = type;
|
||||
Class dynaBeanClass = DynaActionForm.class;
|
||||
Class formBeanClass = formBeanClass();
|
||||
if (formBeanClass != null) {
|
||||
if (dynaBeanClass.isAssignableFrom(formBeanClass)) {
|
||||
this.dynamic = true;
|
||||
} else {
|
||||
this.dynamic = false;
|
||||
}
|
||||
} else {
|
||||
this.dynamic = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void addFormPropertyConfig(FormPropertyConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
if (this.formProperties.containsKey(config.getName()))
|
||||
throw new IllegalArgumentException("Property " + config.getName() + " already defined");
|
||||
this.formProperties.put(config.getName(), config);
|
||||
}
|
||||
|
||||
public FormPropertyConfig findFormPropertyConfig(String name) {
|
||||
return (FormPropertyConfig)this.formProperties.get(name);
|
||||
}
|
||||
|
||||
public FormPropertyConfig[] findFormPropertyConfigs() {
|
||||
FormPropertyConfig[] results = new FormPropertyConfig[this.formProperties.size()];
|
||||
return (FormPropertyConfig[])this.formProperties.values().toArray((Object[])results);
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
this.configured = true;
|
||||
FormPropertyConfig[] fpconfigs = findFormPropertyConfigs();
|
||||
for (int i = 0; i < fpconfigs.length; i++)
|
||||
fpconfigs[i].freeze();
|
||||
}
|
||||
|
||||
public void removeFormPropertyConfig(FormPropertyConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.formProperties.remove(config.getName());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("FormBeanConfig[");
|
||||
sb.append("name=");
|
||||
sb.append(this.name);
|
||||
sb.append(",type=");
|
||||
sb.append(this.type);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected Class formBeanClass() {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null)
|
||||
classLoader = getClass().getClassLoader();
|
||||
try {
|
||||
return classLoader.loadClass(getType());
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
153
hrmsEjb/org/apache/struts/config/FormPropertyConfig.java
Normal file
153
hrmsEjb/org/apache/struts/config/FormPropertyConfig.java
Normal file
@@ -0,0 +1,153 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Array;
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
|
||||
public class FormPropertyConfig implements Serializable {
|
||||
public FormPropertyConfig() {}
|
||||
|
||||
public FormPropertyConfig(String name, String type, String initial) {
|
||||
this(name, type, initial, 0);
|
||||
}
|
||||
|
||||
public FormPropertyConfig(String name, String type, String initial, int size) {
|
||||
setName(name);
|
||||
setType(type);
|
||||
setInitial(initial);
|
||||
setSize(size);
|
||||
}
|
||||
|
||||
protected boolean configured = false;
|
||||
|
||||
protected String initial = null;
|
||||
|
||||
public String getInitial() {
|
||||
return this.initial;
|
||||
}
|
||||
|
||||
public void setInitial(String initial) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.initial = initial;
|
||||
}
|
||||
|
||||
protected String name = null;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected int size = 0;
|
||||
|
||||
public int getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public void setSize(int size) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
if (size < 0)
|
||||
throw new IllegalArgumentException("size < 0");
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
protected String type = null;
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Class getTypeClass() {
|
||||
String baseType = getType();
|
||||
boolean indexed = false;
|
||||
if (baseType.endsWith("[]")) {
|
||||
baseType = baseType.substring(0, baseType.length() - 2);
|
||||
indexed = true;
|
||||
}
|
||||
Class baseClass = null;
|
||||
if ("boolean".equals(baseType)) {
|
||||
baseClass = boolean.class;
|
||||
} else if ("byte".equals(baseType)) {
|
||||
Class clazz = byte.class;
|
||||
} else if ("char".equals(baseType)) {
|
||||
Class clazz = char.class;
|
||||
} else if ("double".equals(baseType)) {
|
||||
Class clazz = double.class;
|
||||
} else if ("float".equals(baseType)) {
|
||||
Class clazz = float.class;
|
||||
} else if ("int".equals(baseType)) {
|
||||
Class clazz = int.class;
|
||||
} else if ("long".equals(baseType)) {
|
||||
Class clazz = long.class;
|
||||
} else if ("short".equals(baseType)) {
|
||||
Class clazz = short.class;
|
||||
} else {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null)
|
||||
classLoader = getClass().getClassLoader();
|
||||
try {
|
||||
baseClass = (Class)classLoader.loadClass(baseType);
|
||||
} catch (Throwable t) {
|
||||
baseClass = null;
|
||||
}
|
||||
}
|
||||
if (indexed)
|
||||
return Array.newInstance(baseClass, 0).getClass();
|
||||
return baseClass;
|
||||
}
|
||||
|
||||
public Object initial() {
|
||||
Object initialValue = null;
|
||||
try {
|
||||
Class clazz = getTypeClass();
|
||||
if (clazz.isArray()) {
|
||||
if (this.initial != null) {
|
||||
initialValue = ConvertUtils.convert(this.initial, clazz);
|
||||
} else {
|
||||
initialValue = Array.newInstance(clazz.getComponentType(), this.size);
|
||||
for (int i = 0; i < this.size; i++) {
|
||||
try {
|
||||
Array.set(initialValue, i, clazz.getComponentType().newInstance());
|
||||
} catch (Throwable t) {}
|
||||
}
|
||||
}
|
||||
} else if (this.initial != null) {
|
||||
initialValue = ConvertUtils.convert(this.initial, clazz);
|
||||
} else {
|
||||
initialValue = clazz.newInstance();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
initialValue = null;
|
||||
}
|
||||
return initialValue;
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
this.configured = true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("FormPropertyConfig[");
|
||||
sb.append("name=");
|
||||
sb.append(this.name);
|
||||
sb.append(",type=");
|
||||
sb.append(this.type);
|
||||
sb.append(",initial=");
|
||||
sb.append(this.initial);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
88
hrmsEjb/org/apache/struts/config/ForwardConfig.java
Normal file
88
hrmsEjb/org/apache/struts/config/ForwardConfig.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ForwardConfig implements Serializable {
|
||||
public ForwardConfig() {}
|
||||
|
||||
public ForwardConfig(String name, String path, boolean redirect) {
|
||||
setName(name);
|
||||
setPath(path);
|
||||
setRedirect(redirect);
|
||||
}
|
||||
|
||||
public ForwardConfig(String name, String path, boolean redirect, boolean contextRelative) {
|
||||
setName(name);
|
||||
setPath(path);
|
||||
setRedirect(redirect);
|
||||
setContextRelative(contextRelative);
|
||||
}
|
||||
|
||||
protected boolean configured = false;
|
||||
|
||||
protected boolean contextRelative = false;
|
||||
|
||||
public boolean getContextRelative() {
|
||||
return this.contextRelative;
|
||||
}
|
||||
|
||||
public void setContextRelative(boolean contextRelative) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.contextRelative = contextRelative;
|
||||
}
|
||||
|
||||
protected String name = null;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected String path = null;
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
protected boolean redirect = false;
|
||||
|
||||
public boolean getRedirect() {
|
||||
return this.redirect;
|
||||
}
|
||||
|
||||
public void setRedirect(boolean redirect) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.redirect = redirect;
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
this.configured = true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("ForwardConfig[");
|
||||
sb.append("name=");
|
||||
sb.append(this.name);
|
||||
sb.append(",path=");
|
||||
sb.append(this.path);
|
||||
sb.append(",redirect=");
|
||||
sb.append(this.redirect);
|
||||
sb.append(",contextRelative=");
|
||||
sb.append(this.contextRelative);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
71
hrmsEjb/org/apache/struts/config/MessageResourcesConfig.java
Normal file
71
hrmsEjb/org/apache/struts/config/MessageResourcesConfig.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class MessageResourcesConfig implements Serializable {
|
||||
protected boolean configured = false;
|
||||
|
||||
protected String factory = "org.apache.struts.util.PropertyMessageResourcesFactory";
|
||||
|
||||
public String getFactory() {
|
||||
return this.factory;
|
||||
}
|
||||
|
||||
public void setFactory(String factory) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
protected String key = "org.apache.struts.action.MESSAGE";
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
protected boolean nullValue = true;
|
||||
|
||||
public boolean getNull() {
|
||||
return this.nullValue;
|
||||
}
|
||||
|
||||
public void setNull(boolean nullValue) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.nullValue = nullValue;
|
||||
}
|
||||
|
||||
protected String parameter = null;
|
||||
|
||||
public String getParameter() {
|
||||
return this.parameter;
|
||||
}
|
||||
|
||||
public void setParameter(String parameter) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
this.configured = true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer("MessageResourcesConfig[");
|
||||
sb.append("factory=");
|
||||
sb.append(this.factory);
|
||||
sb.append(",null=");
|
||||
sb.append(this.nullValue);
|
||||
sb.append(",parameter=");
|
||||
sb.append(this.parameter);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
71
hrmsEjb/org/apache/struts/config/ModuleConfig.java
Normal file
71
hrmsEjb/org/apache/struts/config/ModuleConfig.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
public interface ModuleConfig {
|
||||
boolean getConfigured();
|
||||
|
||||
ControllerConfig getControllerConfig();
|
||||
|
||||
void setControllerConfig(ControllerConfig paramControllerConfig);
|
||||
|
||||
String getPrefix();
|
||||
|
||||
void setPrefix(String paramString);
|
||||
|
||||
String getActionMappingClass();
|
||||
|
||||
void setActionMappingClass(String paramString);
|
||||
|
||||
void addActionConfig(ActionConfig paramActionConfig);
|
||||
|
||||
void addDataSourceConfig(DataSourceConfig paramDataSourceConfig);
|
||||
|
||||
void addExceptionConfig(ExceptionConfig paramExceptionConfig);
|
||||
|
||||
void addFormBeanConfig(FormBeanConfig paramFormBeanConfig);
|
||||
|
||||
void addForwardConfig(ForwardConfig paramForwardConfig);
|
||||
|
||||
void addMessageResourcesConfig(MessageResourcesConfig paramMessageResourcesConfig);
|
||||
|
||||
void addPlugInConfig(PlugInConfig paramPlugInConfig);
|
||||
|
||||
ActionConfig findActionConfig(String paramString);
|
||||
|
||||
ActionConfig[] findActionConfigs();
|
||||
|
||||
DataSourceConfig findDataSourceConfig(String paramString);
|
||||
|
||||
DataSourceConfig[] findDataSourceConfigs();
|
||||
|
||||
ExceptionConfig findExceptionConfig(String paramString);
|
||||
|
||||
ExceptionConfig[] findExceptionConfigs();
|
||||
|
||||
FormBeanConfig findFormBeanConfig(String paramString);
|
||||
|
||||
FormBeanConfig[] findFormBeanConfigs();
|
||||
|
||||
ForwardConfig findForwardConfig(String paramString);
|
||||
|
||||
ForwardConfig[] findForwardConfigs();
|
||||
|
||||
MessageResourcesConfig findMessageResourcesConfig(String paramString);
|
||||
|
||||
MessageResourcesConfig[] findMessageResourcesConfigs();
|
||||
|
||||
PlugInConfig[] findPlugInConfigs();
|
||||
|
||||
void freeze();
|
||||
|
||||
void removeActionConfig(ActionConfig paramActionConfig);
|
||||
|
||||
void removeExceptionConfig(ExceptionConfig paramExceptionConfig);
|
||||
|
||||
void removeDataSourceConfig(DataSourceConfig paramDataSourceConfig);
|
||||
|
||||
void removeFormBeanConfig(FormBeanConfig paramFormBeanConfig);
|
||||
|
||||
void removeForwardConfig(ForwardConfig paramForwardConfig);
|
||||
|
||||
void removeMessageResourcesConfig(MessageResourcesConfig paramMessageResourcesConfig);
|
||||
}
|
36
hrmsEjb/org/apache/struts/config/ModuleConfigFactory.java
Normal file
36
hrmsEjb/org/apache/struts/config/ModuleConfigFactory.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.struts.util.RequestUtils;
|
||||
|
||||
public abstract class ModuleConfigFactory {
|
||||
public abstract ModuleConfig createModuleConfig(String paramString);
|
||||
|
||||
public static String getFactoryClass() {
|
||||
return factoryClass;
|
||||
}
|
||||
|
||||
public static void setFactoryClass(String factoryClass) {
|
||||
ModuleConfigFactory.factoryClass = factoryClass;
|
||||
clazz = null;
|
||||
}
|
||||
|
||||
public static ModuleConfigFactory createFactory() {
|
||||
try {
|
||||
if (clazz == null)
|
||||
clazz = RequestUtils.applicationClass(factoryClass);
|
||||
ModuleConfigFactory factory = clazz.newInstance();
|
||||
return factory;
|
||||
} catch (Throwable t) {
|
||||
LOG.error("ModuleConfigFactory.createFactory", t);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static Class clazz = null;
|
||||
|
||||
private static Log LOG = LogFactory.getLog(ModuleConfigFactory.class);
|
||||
|
||||
protected static String factoryClass = "org.apache.struts.config.impl.DefaultModuleConfigFactory";
|
||||
}
|
35
hrmsEjb/org/apache/struts/config/PlugInConfig.java
Normal file
35
hrmsEjb/org/apache/struts/config/PlugInConfig.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlugInConfig implements Serializable {
|
||||
protected boolean configured = false;
|
||||
|
||||
protected Map properties = new HashMap();
|
||||
|
||||
protected String className = null;
|
||||
|
||||
public String getClassName() {
|
||||
return this.className;
|
||||
}
|
||||
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public void addProperty(String name, String value) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.properties.put(name, value);
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
this.configured = true;
|
||||
}
|
||||
|
||||
public Map getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
}
|
11
hrmsEjb/org/apache/struts/config/PlugInSetPropertyRule.java
Normal file
11
hrmsEjb/org/apache/struts/config/PlugInSetPropertyRule.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import org.apache.commons.digester.Rule;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
final class PlugInSetPropertyRule extends Rule {
|
||||
public void begin(Attributes attributes) throws Exception {
|
||||
PlugInConfig plugInConfig = (PlugInConfig)this.digester.peek();
|
||||
plugInConfig.addProperty(attributes.getValue("property"), attributes.getValue("value"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package org.apache.struts.config;
|
||||
|
||||
import org.apache.commons.digester.Rule;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
final class SetActionMappingClassRule extends Rule {
|
||||
public void begin(Attributes attributes) throws Exception {
|
||||
String className = attributes.getValue("type");
|
||||
if (className != null) {
|
||||
ModuleConfig mc = (ModuleConfig)this.digester.peek();
|
||||
mc.setActionMappingClass(className);
|
||||
}
|
||||
}
|
||||
}
|
289
hrmsEjb/org/apache/struts/config/impl/ModuleConfigImpl.java
Normal file
289
hrmsEjb/org/apache/struts/config/impl/ModuleConfigImpl.java
Normal file
@@ -0,0 +1,289 @@
|
||||
package org.apache.struts.config.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.apache.struts.config.ActionConfig;
|
||||
import org.apache.struts.config.ControllerConfig;
|
||||
import org.apache.struts.config.DataSourceConfig;
|
||||
import org.apache.struts.config.ExceptionConfig;
|
||||
import org.apache.struts.config.FormBeanConfig;
|
||||
import org.apache.struts.config.ForwardConfig;
|
||||
import org.apache.struts.config.MessageResourcesConfig;
|
||||
import org.apache.struts.config.ModuleConfig;
|
||||
import org.apache.struts.config.PlugInConfig;
|
||||
|
||||
public class ModuleConfigImpl implements Serializable, ModuleConfig {
|
||||
protected HashMap actionConfigs;
|
||||
|
||||
protected HashMap dataSources;
|
||||
|
||||
protected HashMap exceptions;
|
||||
|
||||
protected HashMap formBeans;
|
||||
|
||||
protected HashMap forwards;
|
||||
|
||||
protected HashMap messageResources;
|
||||
|
||||
protected ArrayList plugIns;
|
||||
|
||||
protected boolean configured;
|
||||
|
||||
protected ControllerConfig controllerConfig;
|
||||
|
||||
protected String prefix;
|
||||
|
||||
protected String actionMappingClass;
|
||||
|
||||
public ModuleConfigImpl(String prefix) {
|
||||
this.actionConfigs = null;
|
||||
this.dataSources = null;
|
||||
this.exceptions = null;
|
||||
this.formBeans = null;
|
||||
this.forwards = null;
|
||||
this.messageResources = null;
|
||||
this.plugIns = null;
|
||||
this.configured = false;
|
||||
this.controllerConfig = null;
|
||||
this.prefix = null;
|
||||
this.actionMappingClass = "org.apache.struts.action.ActionMapping";
|
||||
this.prefix = prefix;
|
||||
this.actionConfigs = new HashMap();
|
||||
this.actionMappingClass = "org.apache.struts.action.ActionMapping";
|
||||
this.configured = false;
|
||||
this.controllerConfig = null;
|
||||
this.dataSources = new HashMap();
|
||||
this.exceptions = new HashMap();
|
||||
this.formBeans = new HashMap();
|
||||
this.forwards = new HashMap();
|
||||
this.messageResources = new HashMap();
|
||||
this.plugIns = new ArrayList();
|
||||
}
|
||||
|
||||
public ModuleConfigImpl(ModuleConfigImpl moduleConfig) {
|
||||
this.actionConfigs = null;
|
||||
this.dataSources = null;
|
||||
this.exceptions = null;
|
||||
this.formBeans = null;
|
||||
this.forwards = null;
|
||||
this.messageResources = null;
|
||||
this.plugIns = null;
|
||||
this.configured = false;
|
||||
this.controllerConfig = null;
|
||||
this.prefix = null;
|
||||
this.actionMappingClass = "org.apache.struts.action.ActionMapping";
|
||||
this.actionConfigs = moduleConfig.actionConfigs;
|
||||
this.actionMappingClass = moduleConfig.actionMappingClass;
|
||||
this.configured = moduleConfig.configured;
|
||||
this.controllerConfig = moduleConfig.controllerConfig;
|
||||
this.dataSources = moduleConfig.dataSources;
|
||||
this.exceptions = moduleConfig.exceptions;
|
||||
this.formBeans = moduleConfig.formBeans;
|
||||
this.forwards = moduleConfig.forwards;
|
||||
this.messageResources = moduleConfig.messageResources;
|
||||
this.plugIns = moduleConfig.plugIns;
|
||||
this.prefix = moduleConfig.prefix;
|
||||
}
|
||||
|
||||
public boolean getConfigured() {
|
||||
return this.configured;
|
||||
}
|
||||
|
||||
public ControllerConfig getControllerConfig() {
|
||||
if (this.controllerConfig == null)
|
||||
this.controllerConfig = new ControllerConfig();
|
||||
return this.controllerConfig;
|
||||
}
|
||||
|
||||
public void setControllerConfig(ControllerConfig cc) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.controllerConfig = cc;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public String getActionMappingClass() {
|
||||
return this.actionMappingClass;
|
||||
}
|
||||
|
||||
public void setActionMappingClass(String actionMappingClass) {
|
||||
this.actionMappingClass = actionMappingClass;
|
||||
}
|
||||
|
||||
public void addActionConfig(ActionConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
config.setModuleConfig(this);
|
||||
this.actionConfigs.put(config.getPath(), config);
|
||||
}
|
||||
|
||||
public void addDataSourceConfig(DataSourceConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.dataSources.put(config.getKey(), config);
|
||||
}
|
||||
|
||||
public void addExceptionConfig(ExceptionConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.exceptions.put(config.getType(), config);
|
||||
}
|
||||
|
||||
public void addFormBeanConfig(FormBeanConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
config.setModuleConfig(this);
|
||||
this.formBeans.put(config.getName(), config);
|
||||
}
|
||||
|
||||
public void addForwardConfig(ForwardConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.forwards.put(config.getName(), config);
|
||||
}
|
||||
|
||||
public void addMessageResourcesConfig(MessageResourcesConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.messageResources.put(config.getKey(), config);
|
||||
}
|
||||
|
||||
public void addPlugInConfig(PlugInConfig plugInConfig) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.plugIns.add(plugInConfig);
|
||||
}
|
||||
|
||||
public ActionConfig findActionConfig(String path) {
|
||||
return (ActionConfig)this.actionConfigs.get(path);
|
||||
}
|
||||
|
||||
public ActionConfig[] findActionConfigs() {
|
||||
ActionConfig[] results = new ActionConfig[this.actionConfigs.size()];
|
||||
return (ActionConfig[])this.actionConfigs.values().toArray((Object[])results);
|
||||
}
|
||||
|
||||
public DataSourceConfig findDataSourceConfig(String key) {
|
||||
return (DataSourceConfig)this.dataSources.get(key);
|
||||
}
|
||||
|
||||
public DataSourceConfig[] findDataSourceConfigs() {
|
||||
DataSourceConfig[] results = new DataSourceConfig[this.dataSources.size()];
|
||||
return (DataSourceConfig[])this.dataSources.values().toArray((Object[])results);
|
||||
}
|
||||
|
||||
public ExceptionConfig findExceptionConfig(String type) {
|
||||
return (ExceptionConfig)this.exceptions.get(type);
|
||||
}
|
||||
|
||||
public ExceptionConfig[] findExceptionConfigs() {
|
||||
ExceptionConfig[] results = new ExceptionConfig[this.exceptions.size()];
|
||||
return (ExceptionConfig[])this.exceptions.values().toArray((Object[])results);
|
||||
}
|
||||
|
||||
public FormBeanConfig findFormBeanConfig(String name) {
|
||||
return (FormBeanConfig)this.formBeans.get(name);
|
||||
}
|
||||
|
||||
public FormBeanConfig[] findFormBeanConfigs() {
|
||||
FormBeanConfig[] results = new FormBeanConfig[this.formBeans.size()];
|
||||
return (FormBeanConfig[])this.formBeans.values().toArray((Object[])results);
|
||||
}
|
||||
|
||||
public ForwardConfig findForwardConfig(String name) {
|
||||
return (ForwardConfig)this.forwards.get(name);
|
||||
}
|
||||
|
||||
public ForwardConfig[] findForwardConfigs() {
|
||||
ForwardConfig[] results = new ForwardConfig[this.forwards.size()];
|
||||
return (ForwardConfig[])this.forwards.values().toArray((Object[])results);
|
||||
}
|
||||
|
||||
public MessageResourcesConfig findMessageResourcesConfig(String key) {
|
||||
return (MessageResourcesConfig)this.messageResources.get(key);
|
||||
}
|
||||
|
||||
public MessageResourcesConfig[] findMessageResourcesConfigs() {
|
||||
MessageResourcesConfig[] results = new MessageResourcesConfig[this.messageResources.size()];
|
||||
return (MessageResourcesConfig[])this.messageResources.values().toArray((Object[])results);
|
||||
}
|
||||
|
||||
public PlugInConfig[] findPlugInConfigs() {
|
||||
PlugInConfig[] results = new PlugInConfig[this.plugIns.size()];
|
||||
return (PlugInConfig[])this.plugIns.toArray((Object[])results);
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
this.configured = true;
|
||||
ActionConfig[] aconfigs = findActionConfigs();
|
||||
for (int i = 0; i < aconfigs.length; i++)
|
||||
aconfigs[i].freeze();
|
||||
getControllerConfig().freeze();
|
||||
DataSourceConfig[] dsconfigs = findDataSourceConfigs();
|
||||
for (int j = 0; j < dsconfigs.length; j++)
|
||||
dsconfigs[j].freeze();
|
||||
ExceptionConfig[] econfigs = findExceptionConfigs();
|
||||
for (int k = 0; k < econfigs.length; k++)
|
||||
econfigs[k].freeze();
|
||||
FormBeanConfig[] fbconfigs = findFormBeanConfigs();
|
||||
for (int m = 0; m < fbconfigs.length; m++)
|
||||
fbconfigs[m].freeze();
|
||||
ForwardConfig[] fconfigs = findForwardConfigs();
|
||||
for (int n = 0; n < fconfigs.length; n++)
|
||||
fconfigs[n].freeze();
|
||||
MessageResourcesConfig[] mrconfigs = findMessageResourcesConfigs();
|
||||
for (int i1 = 0; i1 < mrconfigs.length; i1++)
|
||||
mrconfigs[i1].freeze();
|
||||
PlugInConfig[] piconfigs = findPlugInConfigs();
|
||||
for (int i2 = 0; i2 < piconfigs.length; i2++)
|
||||
piconfigs[i2].freeze();
|
||||
}
|
||||
|
||||
public void removeActionConfig(ActionConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
config.setModuleConfig(null);
|
||||
this.actionConfigs.remove(config.getPath());
|
||||
}
|
||||
|
||||
public void removeExceptionConfig(ExceptionConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.exceptions.remove(config.getType());
|
||||
}
|
||||
|
||||
public void removeDataSourceConfig(DataSourceConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.dataSources.remove(config.getKey());
|
||||
}
|
||||
|
||||
public void removeFormBeanConfig(FormBeanConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
config.setModuleConfig(null);
|
||||
this.formBeans.remove(config.getName());
|
||||
}
|
||||
|
||||
public void removeForwardConfig(ForwardConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.forwards.remove(config.getName());
|
||||
}
|
||||
|
||||
public void removeMessageResourcesConfig(MessageResourcesConfig config) {
|
||||
if (this.configured)
|
||||
throw new IllegalStateException("Configuration is frozen");
|
||||
this.messageResources.remove(config.getKey());
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package org.apache.struts.upload;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.struts.action.ActionMapping;
|
||||
import org.apache.struts.action.ActionServlet;
|
||||
|
||||
public interface MultipartRequestHandler {
|
||||
public static final String ATTRIBUTE_MAX_LENGTH_EXCEEDED = "org.apache.struts.upload.MaxLengthExceeded";
|
||||
|
||||
void setServlet(ActionServlet paramActionServlet);
|
||||
|
||||
void setMapping(ActionMapping paramActionMapping);
|
||||
|
||||
ActionServlet getServlet();
|
||||
|
||||
ActionMapping getMapping();
|
||||
|
||||
void handleRequest(HttpServletRequest paramHttpServletRequest) throws ServletException;
|
||||
|
||||
Hashtable getTextElements();
|
||||
|
||||
Hashtable getFileElements();
|
||||
|
||||
Hashtable getAllElements();
|
||||
|
||||
void rollback();
|
||||
|
||||
void finish();
|
||||
}
|
258
hrmsEjb/org/apache/struts/upload/MultipartRequestWrapper.java
Normal file
258
hrmsEjb/org/apache/struts/upload/MultipartRequestWrapper.java
Normal file
@@ -0,0 +1,258 @@
|
||||
package org.apache.struts.upload;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.security.Principal;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
public class MultipartRequestWrapper implements HttpServletRequest {
|
||||
protected Map parameters;
|
||||
|
||||
protected HttpServletRequest request;
|
||||
|
||||
public MultipartRequestWrapper(HttpServletRequest request) {
|
||||
this.request = request;
|
||||
this.parameters = new HashMap();
|
||||
}
|
||||
|
||||
public void setParameter(String name, String value) {
|
||||
String[] mValue = (String[])this.parameters.get(name);
|
||||
if (mValue == null)
|
||||
mValue = new String[0];
|
||||
String[] newValue = new String[mValue.length + 1];
|
||||
System.arraycopy(mValue, 0, newValue, 0, mValue.length);
|
||||
newValue[mValue.length] = value;
|
||||
this.parameters.put(name, newValue);
|
||||
}
|
||||
|
||||
public String getParameter(String name) {
|
||||
String value = this.request.getParameter(name);
|
||||
if (value == null) {
|
||||
String[] mValue = (String[])this.parameters.get(name);
|
||||
if (mValue != null && mValue.length > 0)
|
||||
value = mValue[0];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public Enumeration getParameterNames() {
|
||||
Enumeration baseParams = this.request.getParameterNames();
|
||||
Vector list = new Vector();
|
||||
while (baseParams.hasMoreElements())
|
||||
list.add(baseParams.nextElement());
|
||||
Collection multipartParams = this.parameters.keySet();
|
||||
Iterator iterator = multipartParams.iterator();
|
||||
while (iterator.hasNext())
|
||||
list.add(iterator.next());
|
||||
return Collections.enumeration(list);
|
||||
}
|
||||
|
||||
public String[] getParameterValues(String name) {
|
||||
String[] value = this.request.getParameterValues(name);
|
||||
if (value == null)
|
||||
value = (String[])this.parameters.get(name);
|
||||
return value;
|
||||
}
|
||||
|
||||
public HttpServletRequest getRequest() {
|
||||
return this.request;
|
||||
}
|
||||
|
||||
public Object getAttribute(String name) {
|
||||
return this.request.getAttribute(name);
|
||||
}
|
||||
|
||||
public Enumeration getAttributeNames() {
|
||||
return this.request.getAttributeNames();
|
||||
}
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return this.request.getCharacterEncoding();
|
||||
}
|
||||
|
||||
public int getContentLength() {
|
||||
return this.request.getContentLength();
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return this.request.getContentType();
|
||||
}
|
||||
|
||||
public ServletInputStream getInputStream() throws IOException {
|
||||
return this.request.getInputStream();
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return this.request.getProtocol();
|
||||
}
|
||||
|
||||
public String getScheme() {
|
||||
return this.request.getScheme();
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return this.request.getServerName();
|
||||
}
|
||||
|
||||
public int getServerPort() {
|
||||
return this.request.getServerPort();
|
||||
}
|
||||
|
||||
public BufferedReader getReader() throws IOException {
|
||||
return this.request.getReader();
|
||||
}
|
||||
|
||||
public String getRemoteAddr() {
|
||||
return this.request.getRemoteAddr();
|
||||
}
|
||||
|
||||
public String getRemoteHost() {
|
||||
return this.request.getRemoteHost();
|
||||
}
|
||||
|
||||
public void setAttribute(String name, Object o) {
|
||||
this.request.setAttribute(name, o);
|
||||
}
|
||||
|
||||
public void removeAttribute(String name) {
|
||||
this.request.removeAttribute(name);
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return this.request.getLocale();
|
||||
}
|
||||
|
||||
public Enumeration getLocales() {
|
||||
return this.request.getLocales();
|
||||
}
|
||||
|
||||
public boolean isSecure() {
|
||||
return this.request.isSecure();
|
||||
}
|
||||
|
||||
public RequestDispatcher getRequestDispatcher(String path) {
|
||||
return this.request.getRequestDispatcher(path);
|
||||
}
|
||||
|
||||
public String getRealPath(String path) {
|
||||
return this.request.getRealPath(path);
|
||||
}
|
||||
|
||||
public String getAuthType() {
|
||||
return this.request.getAuthType();
|
||||
}
|
||||
|
||||
public Cookie[] getCookies() {
|
||||
return this.request.getCookies();
|
||||
}
|
||||
|
||||
public long getDateHeader(String name) {
|
||||
return this.request.getDateHeader(name);
|
||||
}
|
||||
|
||||
public String getHeader(String name) {
|
||||
return this.request.getHeader(name);
|
||||
}
|
||||
|
||||
public Enumeration getHeaders(String name) {
|
||||
return this.request.getHeaders(name);
|
||||
}
|
||||
|
||||
public Enumeration getHeaderNames() {
|
||||
return this.request.getHeaderNames();
|
||||
}
|
||||
|
||||
public int getIntHeader(String name) {
|
||||
return this.request.getIntHeader(name);
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return this.request.getMethod();
|
||||
}
|
||||
|
||||
public String getPathInfo() {
|
||||
return this.request.getPathInfo();
|
||||
}
|
||||
|
||||
public String getPathTranslated() {
|
||||
return this.request.getPathTranslated();
|
||||
}
|
||||
|
||||
public String getContextPath() {
|
||||
return this.request.getContextPath();
|
||||
}
|
||||
|
||||
public String getQueryString() {
|
||||
return this.request.getQueryString();
|
||||
}
|
||||
|
||||
public String getRemoteUser() {
|
||||
return this.request.getRemoteUser();
|
||||
}
|
||||
|
||||
public boolean isUserInRole(String user) {
|
||||
return this.request.isUserInRole(user);
|
||||
}
|
||||
|
||||
public Principal getUserPrincipal() {
|
||||
return this.request.getUserPrincipal();
|
||||
}
|
||||
|
||||
public String getRequestedSessionId() {
|
||||
return this.request.getRequestedSessionId();
|
||||
}
|
||||
|
||||
public String getRequestURI() {
|
||||
return this.request.getRequestURI();
|
||||
}
|
||||
|
||||
public String getServletPath() {
|
||||
return this.request.getServletPath();
|
||||
}
|
||||
|
||||
public HttpSession getSession(boolean create) {
|
||||
return this.request.getSession(create);
|
||||
}
|
||||
|
||||
public HttpSession getSession() {
|
||||
return this.request.getSession();
|
||||
}
|
||||
|
||||
public boolean isRequestedSessionIdValid() {
|
||||
return this.request.isRequestedSessionIdValid();
|
||||
}
|
||||
|
||||
public boolean isRequestedSessionIdFromURL() {
|
||||
return this.request.isRequestedSessionIdFromURL();
|
||||
}
|
||||
|
||||
public boolean isRequestedSessionIdFromUrl() {
|
||||
return this.request.isRequestedSessionIdFromUrl();
|
||||
}
|
||||
|
||||
public Map getParameterMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setCharacterEncoding(String encoding) {}
|
||||
|
||||
public StringBuffer getRequestURL() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isRequestedSessionIdFromCookie() {
|
||||
return false;
|
||||
}
|
||||
}
|
28
hrmsEjb/org/apache/struts/util/ErrorMessages.java
Normal file
28
hrmsEjb/org/apache/struts/util/ErrorMessages.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package org.apache.struts.util;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class ErrorMessages {
|
||||
private Vector errors = new Vector();
|
||||
|
||||
public void addError(String key) {
|
||||
this.errors.addElement(key);
|
||||
}
|
||||
|
||||
public String getError(int index) {
|
||||
return this.errors.elementAt(index);
|
||||
}
|
||||
|
||||
public String[] getErrors() {
|
||||
if (this.errors.size() > 0) {
|
||||
String[] array = new String[this.errors.size()];
|
||||
this.errors.copyInto((Object[])array);
|
||||
return array;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.errors.size();
|
||||
}
|
||||
}
|
5
hrmsEjb/org/apache/struts/util/GenericDataSource.java
Normal file
5
hrmsEjb/org/apache/struts/util/GenericDataSource.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package org.apache.struts.util;
|
||||
|
||||
import org.apache.struts.legacy.GenericDataSource;
|
||||
|
||||
public class GenericDataSource extends GenericDataSource {}
|
182
hrmsEjb/org/apache/struts/util/MessageResources.java
Normal file
182
hrmsEjb/org/apache/struts/util/MessageResources.java
Normal file
@@ -0,0 +1,182 @@
|
||||
package org.apache.struts.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public abstract class MessageResources implements Serializable {
|
||||
protected static Log log = LogFactory.getLog(MessageResources.class);
|
||||
|
||||
protected String config = null;
|
||||
|
||||
public String getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
protected Locale defaultLocale = Locale.getDefault();
|
||||
|
||||
protected MessageResourcesFactory factory = null;
|
||||
|
||||
public MessageResourcesFactory getFactory() {
|
||||
return this.factory;
|
||||
}
|
||||
|
||||
protected HashMap formats = new HashMap();
|
||||
|
||||
protected boolean returnNull = false;
|
||||
|
||||
public boolean getReturnNull() {
|
||||
return this.returnNull;
|
||||
}
|
||||
|
||||
public void setReturnNull(boolean returnNull) {
|
||||
this.returnNull = returnNull;
|
||||
}
|
||||
|
||||
public MessageResources(MessageResourcesFactory factory, String config) {
|
||||
this(factory, config, false);
|
||||
}
|
||||
|
||||
public MessageResources(MessageResourcesFactory factory, String config, boolean returnNull) {
|
||||
this.factory = factory;
|
||||
this.config = config;
|
||||
this.returnNull = returnNull;
|
||||
}
|
||||
|
||||
public String getMessage(String key) {
|
||||
return getMessage((Locale)null, key);
|
||||
}
|
||||
|
||||
public String getMessage(String key, Object[] args) {
|
||||
return getMessage((Locale)null, key, args);
|
||||
}
|
||||
|
||||
public String getMessage(String key, Object arg0) {
|
||||
return getMessage((Locale)null, key, arg0);
|
||||
}
|
||||
|
||||
public String getMessage(String key, Object arg0, Object arg1) {
|
||||
return getMessage((Locale)null, key, arg0, arg1);
|
||||
}
|
||||
|
||||
public String getMessage(String key, Object arg0, Object arg1, Object arg2) {
|
||||
return getMessage((Locale)null, key, arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
public String getMessage(String key, Object arg0, Object arg1, Object arg2, Object arg3) {
|
||||
return getMessage((Locale)null, key, arg0, arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
public String getMessage(Locale locale, String key, Object[] args) {
|
||||
if (locale == null)
|
||||
locale = this.defaultLocale;
|
||||
MessageFormat format = null;
|
||||
String formatKey = messageKey(locale, key);
|
||||
synchronized (this.formats) {
|
||||
format = (MessageFormat)this.formats.get(formatKey);
|
||||
if (format == null) {
|
||||
String formatString = getMessage(locale, key);
|
||||
if (formatString == null) {
|
||||
if (this.returnNull)
|
||||
return null;
|
||||
return "???" + formatKey + "???";
|
||||
}
|
||||
format = new MessageFormat(escape(formatString));
|
||||
this.formats.put(formatKey, format);
|
||||
}
|
||||
}
|
||||
return format.format(args);
|
||||
}
|
||||
|
||||
public String getMessage(Locale locale, String key, Object arg0) {
|
||||
Object[] args = new Object[1];
|
||||
args[0] = arg0;
|
||||
return getMessage(locale, key, args);
|
||||
}
|
||||
|
||||
public String getMessage(Locale locale, String key, Object arg0, Object arg1) {
|
||||
Object[] args = new Object[2];
|
||||
args[0] = arg0;
|
||||
args[1] = arg1;
|
||||
return getMessage(locale, key, args);
|
||||
}
|
||||
|
||||
public String getMessage(Locale locale, String key, Object arg0, Object arg1, Object arg2) {
|
||||
Object[] args = new Object[3];
|
||||
args[0] = arg0;
|
||||
args[1] = arg1;
|
||||
args[2] = arg2;
|
||||
return getMessage(locale, key, args);
|
||||
}
|
||||
|
||||
public String getMessage(Locale locale, String key, Object arg0, Object arg1, Object arg2, Object arg3) {
|
||||
Object[] args = new Object[4];
|
||||
args[0] = arg0;
|
||||
args[1] = arg1;
|
||||
args[2] = arg2;
|
||||
args[3] = arg3;
|
||||
return getMessage(locale, key, args);
|
||||
}
|
||||
|
||||
public boolean isPresent(String key) {
|
||||
return isPresent(null, key);
|
||||
}
|
||||
|
||||
public boolean isPresent(Locale locale, String key) {
|
||||
String message = getMessage(locale, key);
|
||||
if (message == null)
|
||||
return false;
|
||||
if (message.startsWith("???") && message.endsWith("???"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected String escape(String string) {
|
||||
if (string == null || string.indexOf('\'') < 0)
|
||||
return string;
|
||||
int n = string.length();
|
||||
StringBuffer sb = new StringBuffer(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
char ch = string.charAt(i);
|
||||
if (ch == '\'')
|
||||
sb.append('\'');
|
||||
sb.append(ch);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected String localeKey(Locale locale) {
|
||||
if (locale == null)
|
||||
return "";
|
||||
return locale.toString();
|
||||
}
|
||||
|
||||
protected String messageKey(Locale locale, String key) {
|
||||
return localeKey(locale) + "." + key;
|
||||
}
|
||||
|
||||
protected String messageKey(String localeKey, String key) {
|
||||
return localeKey + "." + key;
|
||||
}
|
||||
|
||||
protected static MessageResourcesFactory defaultFactory = null;
|
||||
|
||||
public static synchronized MessageResources getMessageResources(String config) {
|
||||
if (defaultFactory == null)
|
||||
defaultFactory = MessageResourcesFactory.createFactory();
|
||||
return defaultFactory.createResources(config);
|
||||
}
|
||||
|
||||
public void log(String message) {
|
||||
log.debug(message);
|
||||
}
|
||||
|
||||
public void log(String message, Throwable throwable) {
|
||||
log.debug(message, throwable);
|
||||
}
|
||||
|
||||
public abstract String getMessage(Locale paramLocale, String paramString);
|
||||
}
|
46
hrmsEjb/org/apache/struts/util/MessageResourcesFactory.java
Normal file
46
hrmsEjb/org/apache/struts/util/MessageResourcesFactory.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package org.apache.struts.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public abstract class MessageResourcesFactory implements Serializable {
|
||||
protected boolean returnNull = true;
|
||||
|
||||
public boolean getReturnNull() {
|
||||
return this.returnNull;
|
||||
}
|
||||
|
||||
public void setReturnNull(boolean returnNull) {
|
||||
this.returnNull = returnNull;
|
||||
}
|
||||
|
||||
protected static transient Class clazz = null;
|
||||
|
||||
private static Log LOG = LogFactory.getLog(MessageResourcesFactory.class);
|
||||
|
||||
protected static String factoryClass = "org.apache.struts.util.PropertyMessageResourcesFactory";
|
||||
|
||||
public static String getFactoryClass() {
|
||||
return factoryClass;
|
||||
}
|
||||
|
||||
public static void setFactoryClass(String factoryClass) {
|
||||
MessageResourcesFactory.factoryClass = factoryClass;
|
||||
clazz = null;
|
||||
}
|
||||
|
||||
public static MessageResourcesFactory createFactory() {
|
||||
try {
|
||||
if (clazz == null)
|
||||
clazz = RequestUtils.applicationClass(factoryClass);
|
||||
MessageResourcesFactory factory = clazz.newInstance();
|
||||
return factory;
|
||||
} catch (Throwable t) {
|
||||
LOG.error("MessageResourcesFactory.createFactory", t);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract MessageResources createResources(String paramString);
|
||||
}
|
50
hrmsEjb/org/apache/struts/util/ModuleException.java
Normal file
50
hrmsEjb/org/apache/struts/util/ModuleException.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package org.apache.struts.util;
|
||||
|
||||
import org.apache.struts.action.ActionError;
|
||||
|
||||
public class ModuleException extends Exception {
|
||||
protected String property = null;
|
||||
|
||||
protected ActionError error = null;
|
||||
|
||||
public ModuleException(String key) {
|
||||
super(key);
|
||||
this.error = new ActionError(key);
|
||||
}
|
||||
|
||||
public ModuleException(String key, Object value) {
|
||||
super(key);
|
||||
this.error = new ActionError(key, value);
|
||||
}
|
||||
|
||||
public ModuleException(String key, Object value0, Object value1) {
|
||||
super(key);
|
||||
this.error = new ActionError(key, value0, value1);
|
||||
}
|
||||
|
||||
public ModuleException(String key, Object value0, Object value1, Object value2) {
|
||||
super(key);
|
||||
this.error = new ActionError(key, value0, value1, value2);
|
||||
}
|
||||
|
||||
public ModuleException(String key, Object value0, Object value1, Object value2, Object value3) {
|
||||
super(key);
|
||||
this.error = new ActionError(key, value0, value1, value2, value3);
|
||||
}
|
||||
|
||||
public ModuleException(String key, Object[] values) {
|
||||
this.error = new ActionError(key, values);
|
||||
}
|
||||
|
||||
public String getProperty() {
|
||||
return (this.property != null) ? this.property : this.error.getKey();
|
||||
}
|
||||
|
||||
public void setProperty(String property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public ActionError getError() {
|
||||
return this.error;
|
||||
}
|
||||
}
|
930
hrmsEjb/org/apache/struts/util/RequestUtils.java
Normal file
930
hrmsEjb/org/apache/struts/util/RequestUtils.java
Normal file
@@ -0,0 +1,930 @@
|
||||
package org.apache.struts.util;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.PageContext;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.commons.beanutils.DynaBean;
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.struts.action.ActionError;
|
||||
import org.apache.struts.action.ActionErrors;
|
||||
import org.apache.struts.action.ActionForm;
|
||||
import org.apache.struts.action.ActionMapping;
|
||||
import org.apache.struts.action.ActionMessage;
|
||||
import org.apache.struts.action.ActionMessages;
|
||||
import org.apache.struts.action.ActionServlet;
|
||||
import org.apache.struts.action.ActionServletWrapper;
|
||||
import org.apache.struts.action.DynaActionForm;
|
||||
import org.apache.struts.action.DynaActionFormClass;
|
||||
import org.apache.struts.config.ActionConfig;
|
||||
import org.apache.struts.config.FormBeanConfig;
|
||||
import org.apache.struts.config.ForwardConfig;
|
||||
import org.apache.struts.config.ModuleConfig;
|
||||
import org.apache.struts.upload.MultipartRequestHandler;
|
||||
import org.apache.struts.upload.MultipartRequestWrapper;
|
||||
|
||||
public class RequestUtils {
|
||||
protected static Log log = LogFactory.getLog(RequestUtils.class);
|
||||
|
||||
private static MessageResources messages = MessageResources.getMessageResources("org.apache.struts.util.LocalStrings");
|
||||
|
||||
private static final String PREFIXES_KEY = "org.apache.struts.util.PREFIXES";
|
||||
|
||||
private static Method encode = null;
|
||||
|
||||
private static Map scopes = new HashMap();
|
||||
|
||||
static {
|
||||
try {
|
||||
Class[] args = { String.class, String.class };
|
||||
encode = URLEncoder.class.getMethod("encode", args);
|
||||
} catch (NoSuchMethodException e) {
|
||||
log.debug("Could not find Java 1.4 encode method. Using deprecated version.", e);
|
||||
}
|
||||
scopes.put("page", new Integer(1));
|
||||
scopes.put("request", new Integer(2));
|
||||
scopes.put("session", new Integer(3));
|
||||
scopes.put("application", new Integer(4));
|
||||
}
|
||||
|
||||
public static URL absoluteURL(HttpServletRequest request, String path) throws MalformedURLException {
|
||||
return new URL(serverURL(request), request.getContextPath() + path);
|
||||
}
|
||||
|
||||
public static Class applicationClass(String className) throws ClassNotFoundException {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null)
|
||||
classLoader = RequestUtils.class.getClassLoader();
|
||||
return classLoader.loadClass(className);
|
||||
}
|
||||
|
||||
public static Object applicationInstance(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
|
||||
return applicationClass(className).newInstance();
|
||||
}
|
||||
|
||||
public static Map computeParameters(PageContext pageContext, String paramId, String paramName, String paramProperty, String paramScope, String name, String property, String scope, boolean transaction) throws JspException {
|
||||
if (paramId == null && name == null && !transaction)
|
||||
return null;
|
||||
Map map = null;
|
||||
try {
|
||||
if (name != null)
|
||||
map = (Map)lookup(pageContext, name, property, scope);
|
||||
} catch (ClassCastException e) {
|
||||
saveException(pageContext, e);
|
||||
throw new JspException(messages.getMessage("parameters.multi", name, property, scope));
|
||||
} catch (JspException e) {
|
||||
saveException(pageContext, (Throwable)e);
|
||||
throw e;
|
||||
}
|
||||
Map results = null;
|
||||
if (map != null) {
|
||||
results = new HashMap(map);
|
||||
} else {
|
||||
results = new HashMap();
|
||||
}
|
||||
if (paramId != null && paramName != null) {
|
||||
Object paramValue = null;
|
||||
try {
|
||||
paramValue = lookup(pageContext, paramName, paramProperty, paramScope);
|
||||
} catch (JspException e) {
|
||||
saveException(pageContext, (Throwable)e);
|
||||
throw e;
|
||||
}
|
||||
if (paramValue != null) {
|
||||
String paramString = null;
|
||||
if (paramValue instanceof String) {
|
||||
paramString = (String)paramValue;
|
||||
} else {
|
||||
paramString = paramValue.toString();
|
||||
}
|
||||
Object mapValue = results.get(paramId);
|
||||
if (mapValue == null) {
|
||||
results.put(paramId, paramString);
|
||||
} else if (mapValue instanceof String) {
|
||||
String[] newValues = new String[2];
|
||||
newValues[0] = (String)mapValue;
|
||||
newValues[1] = paramString;
|
||||
results.put(paramId, newValues);
|
||||
} else {
|
||||
String[] oldValues = (String[])mapValue;
|
||||
String[] newValues = new String[oldValues.length + 1];
|
||||
System.arraycopy(oldValues, 0, newValues, 0, oldValues.length);
|
||||
newValues[oldValues.length] = paramString;
|
||||
results.put(paramId, newValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (transaction) {
|
||||
HttpSession session = pageContext.getSession();
|
||||
String token = null;
|
||||
if (session != null)
|
||||
token = (String)session.getAttribute("org.apache.struts.action.TOKEN");
|
||||
if (token != null)
|
||||
results.put("org.apache.struts.taglib.html.TOKEN", token);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public static String computeURL(PageContext pageContext, String forward, String href, String page, Map params, String anchor, boolean redirect) throws MalformedURLException {
|
||||
return computeURL(pageContext, forward, href, page, null, params, anchor, redirect);
|
||||
}
|
||||
|
||||
public static String computeURL(PageContext pageContext, String forward, String href, String page, String action, Map params, String anchor, boolean redirect) throws MalformedURLException {
|
||||
return computeURL(pageContext, forward, href, page, action, params, anchor, redirect, true);
|
||||
}
|
||||
|
||||
public static String computeURL(PageContext pageContext, String forward, String href, String page, String action, Map params, String anchor, boolean redirect, boolean encodeSeparator) throws MalformedURLException {
|
||||
int n = 0;
|
||||
if (forward != null)
|
||||
n++;
|
||||
if (href != null)
|
||||
n++;
|
||||
if (page != null)
|
||||
n++;
|
||||
if (action != null)
|
||||
n++;
|
||||
if (n != 1)
|
||||
throw new MalformedURLException(messages.getMessage("computeURL.specifier"));
|
||||
ModuleConfig config = (ModuleConfig)pageContext.getRequest().getAttribute("org.apache.struts.action.MODULE");
|
||||
if (config == null) {
|
||||
config = (ModuleConfig)pageContext.getServletContext().getAttribute("org.apache.struts.action.MODULE");
|
||||
pageContext.getRequest().setAttribute("org.apache.struts.action.MODULE", config);
|
||||
}
|
||||
StringBuffer url = new StringBuffer();
|
||||
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
|
||||
if (forward != null) {
|
||||
ForwardConfig fc = config.findForwardConfig(forward);
|
||||
if (fc == null)
|
||||
throw new MalformedURLException(messages.getMessage("computeURL.forward", forward));
|
||||
if (fc.getRedirect())
|
||||
redirect = true;
|
||||
if (fc.getPath().startsWith("/")) {
|
||||
url.append(request.getContextPath());
|
||||
url.append(forwardURL(request, fc));
|
||||
} else {
|
||||
url.append(fc.getPath());
|
||||
}
|
||||
} else if (href != null) {
|
||||
url.append(href);
|
||||
} else if (action != null) {
|
||||
url.append(getActionMappingURL(action, pageContext));
|
||||
} else {
|
||||
url.append(request.getContextPath());
|
||||
url.append(pageURL(request, page));
|
||||
}
|
||||
if (anchor != null) {
|
||||
String temp = url.toString();
|
||||
int hash = temp.indexOf('#');
|
||||
if (hash >= 0)
|
||||
url.setLength(hash);
|
||||
url.append('#');
|
||||
url.append(encodeURL(anchor));
|
||||
}
|
||||
if (params != null && params.size() > 0) {
|
||||
String temp = url.toString();
|
||||
int hash = temp.indexOf('#');
|
||||
if (hash >= 0) {
|
||||
anchor = temp.substring(hash + 1);
|
||||
url.setLength(hash);
|
||||
temp = url.toString();
|
||||
} else {
|
||||
anchor = null;
|
||||
}
|
||||
String separator = null;
|
||||
if (redirect) {
|
||||
separator = "&";
|
||||
} else if (encodeSeparator) {
|
||||
separator = "&";
|
||||
} else {
|
||||
separator = "&";
|
||||
}
|
||||
boolean question = (temp.indexOf('?') >= 0);
|
||||
Iterator keys = params.keySet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
String key = keys.next();
|
||||
Object value = params.get(key);
|
||||
if (value == null) {
|
||||
if (!question) {
|
||||
url.append('?');
|
||||
question = true;
|
||||
} else {
|
||||
url.append(separator);
|
||||
}
|
||||
url.append(encodeURL(key));
|
||||
url.append('=');
|
||||
continue;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
if (!question) {
|
||||
url.append('?');
|
||||
question = true;
|
||||
} else {
|
||||
url.append(separator);
|
||||
}
|
||||
url.append(encodeURL(key));
|
||||
url.append('=');
|
||||
url.append(encodeURL((String)value));
|
||||
continue;
|
||||
}
|
||||
if (value instanceof String[]) {
|
||||
String[] values = (String[])value;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (!question) {
|
||||
url.append('?');
|
||||
question = true;
|
||||
} else {
|
||||
url.append(separator);
|
||||
}
|
||||
url.append(encodeURL(key));
|
||||
url.append('=');
|
||||
url.append(encodeURL(values[i]));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!question) {
|
||||
url.append('?');
|
||||
question = true;
|
||||
} else {
|
||||
url.append(separator);
|
||||
}
|
||||
url.append(encodeURL(key));
|
||||
url.append('=');
|
||||
url.append(encodeURL(value.toString()));
|
||||
}
|
||||
if (anchor != null) {
|
||||
url.append('#');
|
||||
url.append(encodeURL(anchor));
|
||||
}
|
||||
}
|
||||
if (pageContext.getSession() != null) {
|
||||
HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
|
||||
if (redirect)
|
||||
return response.encodeRedirectURL(url.toString());
|
||||
return response.encodeURL(url.toString());
|
||||
}
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
public static String getActionMappingName(String action) {
|
||||
String value = action;
|
||||
int question = action.indexOf("?");
|
||||
if (question >= 0)
|
||||
value = value.substring(0, question);
|
||||
int slash = value.lastIndexOf("/");
|
||||
int period = value.lastIndexOf(".");
|
||||
if (period >= 0 && period > slash)
|
||||
value = value.substring(0, period);
|
||||
if (value.startsWith("/"))
|
||||
return value;
|
||||
return "/" + value;
|
||||
}
|
||||
|
||||
public static String getActionMappingURL(String action, PageContext pageContext) {
|
||||
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
|
||||
StringBuffer value = new StringBuffer(request.getContextPath());
|
||||
ModuleConfig config = (ModuleConfig)pageContext.getRequest().getAttribute("org.apache.struts.action.MODULE");
|
||||
if (config != null)
|
||||
value.append(config.getPrefix());
|
||||
String servletMapping = (String)pageContext.getAttribute("org.apache.struts.action.SERVLET_MAPPING", 4);
|
||||
if (servletMapping != null) {
|
||||
String queryString = null;
|
||||
int question = action.indexOf("?");
|
||||
if (question >= 0)
|
||||
queryString = action.substring(question);
|
||||
String actionMapping = getActionMappingName(action);
|
||||
if (servletMapping.startsWith("*.")) {
|
||||
value.append(actionMapping);
|
||||
value.append(servletMapping.substring(1));
|
||||
} else if (servletMapping.endsWith("/*")) {
|
||||
value.append(servletMapping.substring(0, servletMapping.length() - 2));
|
||||
value.append(actionMapping);
|
||||
} else if (servletMapping.equals("/")) {
|
||||
value.append(actionMapping);
|
||||
}
|
||||
if (queryString != null)
|
||||
value.append(queryString);
|
||||
} else {
|
||||
if (!action.startsWith("/"))
|
||||
value.append("/");
|
||||
value.append(action);
|
||||
}
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
public static ActionForm createActionForm(HttpServletRequest request, ActionMapping mapping, ModuleConfig moduleConfig, ActionServlet servlet) {
|
||||
String attribute = mapping.getAttribute();
|
||||
if (attribute == null)
|
||||
return null;
|
||||
String name = mapping.getName();
|
||||
FormBeanConfig config = moduleConfig.findFormBeanConfig(name);
|
||||
if (config == null)
|
||||
return null;
|
||||
if (log.isDebugEnabled())
|
||||
log.debug(" Looking for ActionForm bean instance in scope '" + mapping.getScope() + "' under attribute key '" + attribute + "'");
|
||||
ActionForm instance = null;
|
||||
HttpSession session = null;
|
||||
if ("request".equals(mapping.getScope())) {
|
||||
instance = (ActionForm)request.getAttribute(attribute);
|
||||
} else {
|
||||
session = request.getSession();
|
||||
instance = (ActionForm)session.getAttribute(attribute);
|
||||
}
|
||||
if (instance != null)
|
||||
if (config.getDynamic()) {
|
||||
String className = ((DynaBean)instance).getDynaClass().getName();
|
||||
if (className.equals(config.getName())) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(" Recycling existing DynaActionForm instance of type '" + className + "'");
|
||||
log.trace(" --> " + instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Class configClass = applicationClass(config.getType());
|
||||
if (configClass.isAssignableFrom(instance.getClass())) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(" Recycling existing ActionForm instance of class '" + instance.getClass().getName() + "'");
|
||||
log.trace(" --> " + instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
log.error(servlet.getInternal().getMessage("formBean", config.getType()), t);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (config.getDynamic()) {
|
||||
try {
|
||||
DynaActionFormClass dynaClass = DynaActionFormClass.createDynaActionFormClass(config);
|
||||
instance = (ActionForm)dynaClass.newInstance();
|
||||
((DynaActionForm)instance).initialize(mapping);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(" Creating new DynaActionForm instance of type '" + config.getType() + "'");
|
||||
log.trace(" --> " + instance);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
log.error(servlet.getInternal().getMessage("formBean", config.getType()), t);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
instance = (ActionForm)applicationInstance(config.getType());
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(" Creating new ActionForm instance of type '" + config.getType() + "'");
|
||||
log.trace(" --> " + instance);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
log.error(servlet.getInternal().getMessage("formBean", config.getType()), t);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
instance.setServlet(servlet);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static Object lookup(PageContext pageContext, String name, String scopeName) throws JspException {
|
||||
if (scopeName == null)
|
||||
return pageContext.findAttribute(name);
|
||||
try {
|
||||
return pageContext.getAttribute(name, getScope(scopeName));
|
||||
} catch (JspException e) {
|
||||
saveException(pageContext, (Throwable)e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getScope(String scopeName) throws JspException {
|
||||
Integer scope = (Integer)scopes.get(scopeName.toLowerCase());
|
||||
if (scope == null)
|
||||
throw new JspException(messages.getMessage("lookup.scope", scope));
|
||||
return scope.intValue();
|
||||
}
|
||||
|
||||
public static Object lookup(PageContext pageContext, String name, String property, String scope) throws JspException {
|
||||
Object bean = lookup(pageContext, name, scope);
|
||||
if (bean == null) {
|
||||
JspException e = null;
|
||||
if (scope == null) {
|
||||
e = new JspException(messages.getMessage("lookup.bean.any", name));
|
||||
} else {
|
||||
e = new JspException(messages.getMessage("lookup.bean", name, scope));
|
||||
}
|
||||
saveException(pageContext, (Throwable)e);
|
||||
throw e;
|
||||
}
|
||||
if (property == null)
|
||||
return bean;
|
||||
try {
|
||||
return PropertyUtils.getProperty(bean, property);
|
||||
} catch (IllegalAccessException e) {
|
||||
saveException(pageContext, e);
|
||||
throw new JspException(messages.getMessage("lookup.access", property, name));
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable t = e.getTargetException();
|
||||
if (t == null)
|
||||
t = e;
|
||||
saveException(pageContext, t);
|
||||
throw new JspException(messages.getMessage("lookup.target", property, name));
|
||||
} catch (NoSuchMethodException e) {
|
||||
saveException(pageContext, e);
|
||||
throw new JspException(messages.getMessage("lookup.method", property, name));
|
||||
}
|
||||
}
|
||||
|
||||
public static Locale retrieveUserLocale(PageContext pageContext, String locale) {
|
||||
Locale userLocale = null;
|
||||
HttpSession session = pageContext.getSession();
|
||||
if (locale == null)
|
||||
locale = "org.apache.struts.action.LOCALE";
|
||||
if (session != null)
|
||||
userLocale = (Locale)session.getAttribute(locale);
|
||||
if (userLocale == null)
|
||||
userLocale = pageContext.getRequest().getLocale();
|
||||
return userLocale;
|
||||
}
|
||||
|
||||
public static String message(PageContext pageContext, String bundle, String locale, String key) throws JspException {
|
||||
return message(pageContext, bundle, locale, key, null);
|
||||
}
|
||||
|
||||
public static String message(PageContext pageContext, String bundle, String locale, String key, Object[] args) throws JspException {
|
||||
MessageResources resources = retrieveMessageResources(pageContext, bundle, false);
|
||||
Locale userLocale = retrieveUserLocale(pageContext, locale);
|
||||
if (args == null)
|
||||
return resources.getMessage(userLocale, key);
|
||||
return resources.getMessage(userLocale, key, args);
|
||||
}
|
||||
|
||||
private static MessageResources retrieveMessageResources(PageContext pageContext, String bundle, boolean checkPageScope) throws JspException {
|
||||
MessageResources resources = null;
|
||||
if (bundle == null)
|
||||
bundle = "org.apache.struts.action.MESSAGE";
|
||||
if (checkPageScope)
|
||||
resources = (MessageResources)pageContext.getAttribute(bundle, 1);
|
||||
if (resources == null)
|
||||
resources = (MessageResources)pageContext.getAttribute(bundle, 2);
|
||||
if (resources == null)
|
||||
resources = (MessageResources)pageContext.getAttribute(bundle, 4);
|
||||
if (resources == null) {
|
||||
JspException e = new JspException(messages.getMessage("message.bundle", bundle));
|
||||
saveException(pageContext, (Throwable)e);
|
||||
throw e;
|
||||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
public static void populate(Object bean, HttpServletRequest request) throws ServletException {
|
||||
populate(bean, null, null, request);
|
||||
}
|
||||
|
||||
public static void populate(Object bean, String prefix, String suffix, HttpServletRequest request) throws ServletException {
|
||||
HashMap properties = new HashMap();
|
||||
Enumeration names = null;
|
||||
Map multipartParameters = null;
|
||||
String contentType = request.getContentType();
|
||||
String method = request.getMethod();
|
||||
boolean isMultipart = false;
|
||||
if (contentType != null && contentType.startsWith("multipart/form-data") && method.equalsIgnoreCase("POST")) {
|
||||
ActionServletWrapper servlet;
|
||||
if (bean instanceof ActionForm) {
|
||||
servlet = ((ActionForm)bean).getServletWrapper();
|
||||
} else {
|
||||
throw new ServletException("bean that's supposed to be populated from a multipart request is not of type \"org.apache.struts.action.ActionForm\", but type \"" + bean.getClass().getName() + "\"");
|
||||
}
|
||||
MultipartRequestHandler multipartHandler = getMultipartHandler(request);
|
||||
((ActionForm)bean).setMultipartRequestHandler(multipartHandler);
|
||||
if (multipartHandler != null) {
|
||||
isMultipart = true;
|
||||
servlet.setServletFor(multipartHandler);
|
||||
multipartHandler.setMapping((ActionMapping)request.getAttribute("org.apache.struts.action.mapping.instance"));
|
||||
multipartHandler.handleRequest(request);
|
||||
Boolean maxLengthExceeded = (Boolean)request.getAttribute("org.apache.struts.upload.MaxLengthExceeded");
|
||||
if (maxLengthExceeded != null && maxLengthExceeded.booleanValue())
|
||||
return;
|
||||
multipartParameters = getAllParametersForMultipartRequest(request, multipartHandler);
|
||||
names = Collections.enumeration(multipartParameters.keySet());
|
||||
}
|
||||
}
|
||||
if (!isMultipart)
|
||||
names = request.getParameterNames();
|
||||
while (names.hasMoreElements()) {
|
||||
String name = (String)names.nextElement();
|
||||
String stripped = name;
|
||||
if (prefix != null) {
|
||||
if (!stripped.startsWith(prefix))
|
||||
continue;
|
||||
stripped = stripped.substring(prefix.length());
|
||||
}
|
||||
if (suffix != null) {
|
||||
if (!stripped.endsWith(suffix))
|
||||
continue;
|
||||
stripped = stripped.substring(0, stripped.length() - suffix.length());
|
||||
}
|
||||
if (isMultipart) {
|
||||
properties.put(stripped, multipartParameters.get(name));
|
||||
continue;
|
||||
}
|
||||
properties.put(stripped, request.getParameterValues(name));
|
||||
}
|
||||
try {
|
||||
BeanUtils.populate(bean, properties);
|
||||
} catch (Exception e) {
|
||||
throw new ServletException("BeanUtils.populate", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static MultipartRequestHandler getMultipartHandler(HttpServletRequest request) throws ServletException {
|
||||
MultipartRequestHandler multipartHandler = null;
|
||||
String multipartClass = (String)request.getAttribute("org.apache.struts.action.mapping.multipartclass");
|
||||
request.removeAttribute("org.apache.struts.action.mapping.multipartclass");
|
||||
if (multipartClass != null) {
|
||||
try {
|
||||
multipartHandler = (MultipartRequestHandler)applicationInstance(multipartClass);
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
log.error("MultipartRequestHandler class \"" + multipartClass + "\" in mapping class not found, " + "defaulting to global multipart class");
|
||||
} catch (InstantiationException ie) {
|
||||
log.error("InstantiaionException when instantiating MultipartRequestHandler \"" + multipartClass + "\", " + "defaulting to global multipart class, exception: " + ie.getMessage());
|
||||
} catch (IllegalAccessException iae) {
|
||||
log.error("IllegalAccessException when instantiating MultipartRequestHandler \"" + multipartClass + "\", " + "defaulting to global multipart class, exception: " + iae.getMessage());
|
||||
}
|
||||
if (multipartHandler != null)
|
||||
return multipartHandler;
|
||||
}
|
||||
ModuleConfig moduleConfig = (ModuleConfig)request.getAttribute("org.apache.struts.action.MODULE");
|
||||
multipartClass = moduleConfig.getControllerConfig().getMultipartClass();
|
||||
if (multipartClass != null) {
|
||||
try {
|
||||
multipartHandler = (MultipartRequestHandler)applicationInstance(multipartClass);
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
throw new ServletException("Cannot find multipart class \"" + multipartClass + "\"" + ", exception: " + cnfe.getMessage());
|
||||
} catch (InstantiationException ie) {
|
||||
throw new ServletException("InstantiaionException when instantiating multipart class \"" + multipartClass + "\", exception: " + ie.getMessage());
|
||||
} catch (IllegalAccessException iae) {
|
||||
throw new ServletException("IllegalAccessException when instantiating multipart class \"" + multipartClass + "\", exception: " + iae.getMessage());
|
||||
}
|
||||
if (multipartHandler != null)
|
||||
return multipartHandler;
|
||||
}
|
||||
return multipartHandler;
|
||||
}
|
||||
|
||||
private static Map getAllParametersForMultipartRequest(HttpServletRequest request, MultipartRequestHandler multipartHandler) {
|
||||
Map parameters = new HashMap();
|
||||
Hashtable elements = multipartHandler.getAllElements();
|
||||
Enumeration enum = elements.keys();
|
||||
while (enum.hasMoreElements()) {
|
||||
String key = enum.nextElement();
|
||||
parameters.put(key, elements.get(key));
|
||||
}
|
||||
if (request instanceof MultipartRequestWrapper) {
|
||||
request = ((MultipartRequestWrapper)request).getRequest();
|
||||
enum = request.getParameterNames();
|
||||
while (enum.hasMoreElements()) {
|
||||
String key = enum.nextElement();
|
||||
parameters.put(key, request.getParameterValues(key));
|
||||
}
|
||||
} else {
|
||||
log.debug("Gathering multipart parameters for unwrapped request");
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public static boolean present(PageContext pageContext, String bundle, String locale, String key) throws JspException {
|
||||
MessageResources resources = retrieveMessageResources(pageContext, bundle, true);
|
||||
Locale userLocale = retrieveUserLocale(pageContext, locale);
|
||||
return resources.isPresent(userLocale, key);
|
||||
}
|
||||
|
||||
public static String printableURL(URL url) {
|
||||
if (url.getHost() != null)
|
||||
return url.toString();
|
||||
String file = url.getFile();
|
||||
String ref = url.getRef();
|
||||
if (ref == null)
|
||||
return file;
|
||||
StringBuffer sb = new StringBuffer(file);
|
||||
sb.append('#');
|
||||
sb.append(ref);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String actionURL(HttpServletRequest request, ActionConfig action, String pattern) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (pattern.endsWith("/*")) {
|
||||
sb.append(pattern.substring(0, pattern.length() - 2));
|
||||
sb.append(action.getPath());
|
||||
} else if (pattern.startsWith("*.")) {
|
||||
ModuleConfig appConfig = (ModuleConfig)request.getAttribute("org.apache.struts.action.MODULE");
|
||||
sb.append(appConfig.getPrefix());
|
||||
sb.append(action.getPath());
|
||||
sb.append(pattern.substring(1));
|
||||
} else {
|
||||
throw new IllegalArgumentException(pattern);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String forwardURL(HttpServletRequest request, ForwardConfig forward) {
|
||||
String path = forward.getPath();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (forward.getContextRelative()) {
|
||||
if (!path.startsWith("/"))
|
||||
sb.append("/");
|
||||
sb.append(path);
|
||||
return sb.toString();
|
||||
}
|
||||
ModuleConfig moduleConfig = (ModuleConfig)request.getAttribute("org.apache.struts.action.MODULE");
|
||||
String forwardPattern = moduleConfig.getControllerConfig().getForwardPattern();
|
||||
if (forwardPattern == null) {
|
||||
sb.append(moduleConfig.getPrefix());
|
||||
if (!path.startsWith("/"))
|
||||
sb.append("/");
|
||||
sb.append(path);
|
||||
} else {
|
||||
boolean dollar = false;
|
||||
for (int i = 0; i < forwardPattern.length(); i++) {
|
||||
char ch = forwardPattern.charAt(i);
|
||||
if (dollar) {
|
||||
switch (ch) {
|
||||
case 'M':
|
||||
sb.append(moduleConfig.getPrefix());
|
||||
break;
|
||||
case 'P':
|
||||
if (!path.startsWith("/"))
|
||||
sb.append("/");
|
||||
sb.append(path);
|
||||
break;
|
||||
case '$':
|
||||
sb.append('$');
|
||||
break;
|
||||
}
|
||||
dollar = false;
|
||||
} else if (ch == '$') {
|
||||
dollar = true;
|
||||
} else {
|
||||
sb.append(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String pageURL(HttpServletRequest request, String page) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
ModuleConfig moduleConfig = (ModuleConfig)request.getAttribute("org.apache.struts.action.MODULE");
|
||||
String pagePattern = moduleConfig.getControllerConfig().getPagePattern();
|
||||
if (pagePattern == null) {
|
||||
sb.append(moduleConfig.getPrefix());
|
||||
sb.append(page);
|
||||
} else {
|
||||
boolean dollar = false;
|
||||
for (int i = 0; i < pagePattern.length(); i++) {
|
||||
char ch = pagePattern.charAt(i);
|
||||
if (dollar) {
|
||||
switch (ch) {
|
||||
case 'M':
|
||||
sb.append(moduleConfig.getPrefix());
|
||||
break;
|
||||
case 'P':
|
||||
sb.append(page);
|
||||
break;
|
||||
case '$':
|
||||
sb.append('$');
|
||||
break;
|
||||
}
|
||||
dollar = false;
|
||||
} else if (ch == '$') {
|
||||
dollar = true;
|
||||
} else {
|
||||
sb.append(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static URL requestURL(HttpServletRequest request) throws MalformedURLException {
|
||||
StringBuffer url = new StringBuffer();
|
||||
String scheme = request.getScheme();
|
||||
int port = request.getServerPort();
|
||||
if (port < 0)
|
||||
port = 80;
|
||||
url.append(scheme);
|
||||
url.append("://");
|
||||
url.append(request.getServerName());
|
||||
if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) {
|
||||
url.append(':');
|
||||
url.append(port);
|
||||
}
|
||||
url.append(request.getRequestURI());
|
||||
return new URL(url.toString());
|
||||
}
|
||||
|
||||
public static URL serverURL(HttpServletRequest request) throws MalformedURLException {
|
||||
StringBuffer url = new StringBuffer();
|
||||
String scheme = request.getScheme();
|
||||
int port = request.getServerPort();
|
||||
if (port < 0)
|
||||
port = 80;
|
||||
url.append(scheme);
|
||||
url.append("://");
|
||||
url.append(request.getServerName());
|
||||
if ((scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) {
|
||||
url.append(':');
|
||||
url.append(port);
|
||||
}
|
||||
return new URL(url.toString());
|
||||
}
|
||||
|
||||
public static void saveException(PageContext pageContext, Throwable exception) {
|
||||
pageContext.setAttribute("org.apache.struts.action.EXCEPTION", exception, 2);
|
||||
}
|
||||
|
||||
public static void selectApplication(String prefix, HttpServletRequest request, ServletContext context) {
|
||||
selectModule(prefix, request, context);
|
||||
}
|
||||
|
||||
public static void selectModule(String prefix, HttpServletRequest request, ServletContext context) {
|
||||
ModuleConfig config = (ModuleConfig)context.getAttribute("org.apache.struts.action.MODULE" + prefix);
|
||||
if (config != null) {
|
||||
request.setAttribute("org.apache.struts.action.MODULE", config);
|
||||
} else {
|
||||
request.removeAttribute("org.apache.struts.action.MODULE");
|
||||
}
|
||||
MessageResources resources = (MessageResources)context.getAttribute("org.apache.struts.action.MESSAGE" + prefix);
|
||||
if (resources != null) {
|
||||
request.setAttribute("org.apache.struts.action.MESSAGE", resources);
|
||||
} else {
|
||||
request.removeAttribute("org.apache.struts.action.MESSAGE");
|
||||
}
|
||||
}
|
||||
|
||||
public static void selectApplication(HttpServletRequest request, ServletContext context) {
|
||||
selectModule(request, context);
|
||||
}
|
||||
|
||||
public static void selectModule(HttpServletRequest request, ServletContext context) {
|
||||
String prefix = getModuleName(request, context);
|
||||
selectModule(prefix, request, context);
|
||||
}
|
||||
|
||||
public static String getModuleName(HttpServletRequest request, ServletContext context) {
|
||||
String matchPath = (String)request.getAttribute("javax.servlet.include.servlet_path");
|
||||
if (matchPath == null)
|
||||
matchPath = request.getServletPath();
|
||||
return getModuleName(matchPath, context);
|
||||
}
|
||||
|
||||
public static String getModuleName(String matchPath, ServletContext context) {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Get module name for path " + matchPath);
|
||||
String prefix = "";
|
||||
String[] prefixes = getModulePrefixes(context);
|
||||
int lastSlash = 0;
|
||||
while (prefix.equals("") && (lastSlash = matchPath.lastIndexOf("/")) > 0) {
|
||||
matchPath = matchPath.substring(0, lastSlash);
|
||||
for (int i = 0; i < prefixes.length; i++) {
|
||||
if (matchPath.equals(prefixes[i])) {
|
||||
prefix = prefixes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Module name found: " + (prefix.equals("") ? "default" : prefix));
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public static ModuleConfig getRequestModuleConfig(HttpServletRequest request) {
|
||||
return (ModuleConfig)request.getAttribute("org.apache.struts.action.MODULE");
|
||||
}
|
||||
|
||||
public static ModuleConfig getModuleConfig(HttpServletRequest request, ServletContext context) {
|
||||
ModuleConfig moduleConfig = (ModuleConfig)request.getAttribute("org.apache.struts.action.MODULE");
|
||||
if (moduleConfig == null)
|
||||
moduleConfig = (ModuleConfig)context.getAttribute("org.apache.struts.action.MODULE");
|
||||
return moduleConfig;
|
||||
}
|
||||
|
||||
public static ModuleConfig getModuleConfig(PageContext pageContext) {
|
||||
return getModuleConfig((HttpServletRequest)pageContext.getRequest(), pageContext.getServletContext());
|
||||
}
|
||||
|
||||
public static String[] getApplicationPrefixes(ServletContext context) {
|
||||
return getModulePrefixes(context);
|
||||
}
|
||||
|
||||
public static synchronized String[] getModulePrefixes(ServletContext context) {
|
||||
String[] prefixes = (String[])context.getAttribute("org.apache.struts.util.PREFIXES");
|
||||
if (prefixes != null)
|
||||
return prefixes;
|
||||
ArrayList list = new ArrayList();
|
||||
Enumeration names = context.getAttributeNames();
|
||||
while (names.hasMoreElements()) {
|
||||
String name = names.nextElement();
|
||||
if (!name.startsWith("org.apache.struts.action.MODULE"))
|
||||
continue;
|
||||
String prefix = name.substring("org.apache.struts.action.MODULE".length());
|
||||
if (prefix.length() > 0)
|
||||
list.add(prefix);
|
||||
}
|
||||
prefixes = list.<String>toArray(new String[list.size()]);
|
||||
context.setAttribute("org.apache.struts.util.PREFIXES", prefixes);
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
public static ActionMessages getActionMessages(PageContext pageContext, String paramName) throws JspException {
|
||||
ActionMessages am = new ActionMessages();
|
||||
Object value = pageContext.findAttribute(paramName);
|
||||
try {
|
||||
if (value != null)
|
||||
if (value instanceof String) {
|
||||
am.add("org.apache.struts.action.GLOBAL_MESSAGE", new ActionMessage((String)value));
|
||||
} else if (value instanceof String[]) {
|
||||
String[] keys = (String[])value;
|
||||
for (int i = 0; i < keys.length; i++)
|
||||
am.add("org.apache.struts.action.GLOBAL_MESSAGE", new ActionMessage(keys[i]));
|
||||
} else if (value instanceof ErrorMessages) {
|
||||
String[] keys = ((ErrorMessages)value).getErrors();
|
||||
if (keys == null)
|
||||
keys = new String[0];
|
||||
for (int i = 0; i < keys.length; i++)
|
||||
am.add("org.apache.struts.action.GLOBAL_ERROR", (ActionMessage)new ActionError(keys[i]));
|
||||
} else if (value instanceof ActionMessages) {
|
||||
am = (ActionMessages)value;
|
||||
} else {
|
||||
throw new JspException(messages.getMessage("actionMessages.errors", value.getClass().getName()));
|
||||
}
|
||||
} catch (JspException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {}
|
||||
return am;
|
||||
}
|
||||
|
||||
public static ActionErrors getActionErrors(PageContext pageContext, String paramName) throws JspException {
|
||||
ActionErrors errors = new ActionErrors();
|
||||
Object value = pageContext.findAttribute(paramName);
|
||||
try {
|
||||
if (value != null)
|
||||
if (value instanceof String) {
|
||||
errors.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError((String)value));
|
||||
} else if (value instanceof String[]) {
|
||||
String[] keys = (String[])value;
|
||||
for (int i = 0; i < keys.length; i++)
|
||||
errors.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError(keys[i]));
|
||||
} else if (value instanceof ErrorMessages) {
|
||||
String[] keys = ((ErrorMessages)value).getErrors();
|
||||
if (keys == null)
|
||||
keys = new String[0];
|
||||
for (int i = 0; i < keys.length; i++)
|
||||
errors.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError(keys[i]));
|
||||
} else if (value instanceof ActionErrors) {
|
||||
errors = (ActionErrors)value;
|
||||
} else {
|
||||
throw new JspException(messages.getMessage("actionErrors.errors", value.getClass().getName()));
|
||||
}
|
||||
} catch (JspException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.debug(e, e);
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
public static String encodeURL(String url) {
|
||||
try {
|
||||
if (encode != null)
|
||||
return (String)encode.invoke(null, new Object[] { url, "UTF-8" });
|
||||
} catch (IllegalAccessException e) {
|
||||
log.debug("Could not find Java 1.4 encode method. Using deprecated version.", e);
|
||||
} catch (InvocationTargetException e) {
|
||||
log.debug("Could not find Java 1.4 encode method. Using deprecated version.", e);
|
||||
}
|
||||
return URLEncoder.encode(url);
|
||||
}
|
||||
|
||||
public static boolean isXhtml(PageContext pageContext) {
|
||||
String xhtml = (String)pageContext.getAttribute("org.apache.struts.globals.XHTML", 1);
|
||||
return "true".equalsIgnoreCase(xhtml);
|
||||
}
|
||||
}
|
64
hrmsEjb/org/apache/struts/util/ResponseUtils.java
Normal file
64
hrmsEjb/org/apache/struts/util/ResponseUtils.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package org.apache.struts.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.JspWriter;
|
||||
import javax.servlet.jsp.PageContext;
|
||||
import javax.servlet.jsp.tagext.BodyContent;
|
||||
|
||||
public class ResponseUtils {
|
||||
protected static MessageResources messages = MessageResources.getMessageResources("org.apache.struts.util.LocalStrings");
|
||||
|
||||
public static String filter(String value) {
|
||||
if (value == null)
|
||||
return null;
|
||||
char[] content = new char[value.length()];
|
||||
value.getChars(0, value.length(), content, 0);
|
||||
StringBuffer result = new StringBuffer(content.length + 50);
|
||||
for (int i = 0; i < content.length; i++) {
|
||||
switch (content[i]) {
|
||||
case '<':
|
||||
result.append("<");
|
||||
break;
|
||||
case '>':
|
||||
result.append(">");
|
||||
break;
|
||||
case '&':
|
||||
result.append("&");
|
||||
break;
|
||||
case '"':
|
||||
result.append(""");
|
||||
break;
|
||||
case '\'':
|
||||
result.append("'");
|
||||
break;
|
||||
default:
|
||||
result.append(content[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static void write(PageContext pageContext, String text) throws JspException {
|
||||
JspWriter writer = pageContext.getOut();
|
||||
try {
|
||||
writer.print(text);
|
||||
} catch (IOException e) {
|
||||
RequestUtils.saveException(pageContext, e);
|
||||
throw new JspException(messages.getMessage("write.io", e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void writePrevious(PageContext pageContext, String text) throws JspException {
|
||||
JspWriter writer = pageContext.getOut();
|
||||
if (writer instanceof BodyContent)
|
||||
writer = ((BodyContent)writer).getEnclosingWriter();
|
||||
try {
|
||||
writer.print(text);
|
||||
} catch (IOException e) {
|
||||
RequestUtils.saveException(pageContext, e);
|
||||
throw new JspException(messages.getMessage("write.io", e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
159
hrmsEjb/org/apache/struts/util/ServletContextWriter.java
Normal file
159
hrmsEjb/org/apache/struts/util/ServletContextWriter.java
Normal file
@@ -0,0 +1,159 @@
|
||||
package org.apache.struts.util;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
public class ServletContextWriter extends PrintWriter {
|
||||
protected StringBuffer buffer;
|
||||
|
||||
protected ServletContext context;
|
||||
|
||||
protected boolean error;
|
||||
|
||||
public ServletContextWriter(ServletContext context) {
|
||||
super(new StringWriter());
|
||||
this.buffer = new StringBuffer();
|
||||
this.context = null;
|
||||
this.error = false;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public boolean checkError() {
|
||||
flush();
|
||||
return this.error;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
flush();
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
if (this.buffer.length() > 0) {
|
||||
this.context.log(this.buffer.toString());
|
||||
this.buffer.setLength(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void print(boolean b) {
|
||||
write(String.valueOf(b));
|
||||
}
|
||||
|
||||
public void print(char c) {
|
||||
write(c);
|
||||
}
|
||||
|
||||
public void print(char[] c) {
|
||||
for (int i = 0; i < c.length; i++)
|
||||
write(c[i]);
|
||||
}
|
||||
|
||||
public void print(double d) {
|
||||
write(String.valueOf(d));
|
||||
}
|
||||
|
||||
public void print(float f) {
|
||||
write(String.valueOf(f));
|
||||
}
|
||||
|
||||
public void print(int i) {
|
||||
write(String.valueOf(i));
|
||||
}
|
||||
|
||||
public void print(long l) {
|
||||
write(String.valueOf(l));
|
||||
}
|
||||
|
||||
public void print(Object o) {
|
||||
write(o.toString());
|
||||
}
|
||||
|
||||
public void print(String s) {
|
||||
int len = s.length();
|
||||
for (int i = 0; i < len; i++)
|
||||
write(s.charAt(i));
|
||||
}
|
||||
|
||||
public void println() {
|
||||
flush();
|
||||
}
|
||||
|
||||
public void println(boolean b) {
|
||||
println(String.valueOf(b));
|
||||
}
|
||||
|
||||
public void println(char c) {
|
||||
write(c);
|
||||
println();
|
||||
}
|
||||
|
||||
public void println(char[] c) {
|
||||
for (int i = 0; i < c.length; i++)
|
||||
print(c[i]);
|
||||
println();
|
||||
}
|
||||
|
||||
public void println(double d) {
|
||||
println(String.valueOf(d));
|
||||
}
|
||||
|
||||
public void println(float f) {
|
||||
println(String.valueOf(f));
|
||||
}
|
||||
|
||||
public void println(int i) {
|
||||
println(String.valueOf(i));
|
||||
}
|
||||
|
||||
public void println(long l) {
|
||||
println(String.valueOf(l));
|
||||
}
|
||||
|
||||
public void println(Object o) {
|
||||
println(o.toString());
|
||||
}
|
||||
|
||||
public void println(String s) {
|
||||
int len = s.length();
|
||||
for (int i = 0; i < len; i++)
|
||||
print(s.charAt(i));
|
||||
println();
|
||||
}
|
||||
|
||||
public void setError() {
|
||||
this.error = true;
|
||||
}
|
||||
|
||||
public void write(char c) {
|
||||
if (c == '\n') {
|
||||
flush();
|
||||
} else if (c != '\r') {
|
||||
this.buffer.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(int c) {
|
||||
write((char)c);
|
||||
}
|
||||
|
||||
public void write(char[] buf) {
|
||||
for (int i = 0; i < buf.length; i++)
|
||||
write(buf[i]);
|
||||
}
|
||||
|
||||
public void write(char[] buf, int off, int len) {
|
||||
for (int i = off; i < len; i++)
|
||||
write(buf[i]);
|
||||
}
|
||||
|
||||
public void write(String s) {
|
||||
int len = s.length();
|
||||
for (int i = 0; i < len; i++)
|
||||
write(s.charAt(i));
|
||||
}
|
||||
|
||||
public void write(String s, int off, int len) {
|
||||
for (int i = off; i < len; i++)
|
||||
write(s.charAt(i));
|
||||
}
|
||||
}
|
75
hrmsEjb/org/apache/struts/util/TokenProcessor.java
Normal file
75
hrmsEjb/org/apache/struts/util/TokenProcessor.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package org.apache.struts.util;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
public class TokenProcessor {
|
||||
private static TokenProcessor instance = new TokenProcessor();
|
||||
|
||||
public static TokenProcessor getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public synchronized boolean isTokenValid(HttpServletRequest request) {
|
||||
return isTokenValid(request, false);
|
||||
}
|
||||
|
||||
public synchronized boolean isTokenValid(HttpServletRequest request, boolean reset) {
|
||||
HttpSession session = request.getSession(false);
|
||||
if (session == null)
|
||||
return false;
|
||||
String saved = (String)session.getAttribute("org.apache.struts.action.TOKEN");
|
||||
if (saved == null)
|
||||
return false;
|
||||
if (reset)
|
||||
resetToken(request);
|
||||
String token = request.getParameter("org.apache.struts.taglib.html.TOKEN");
|
||||
if (token == null)
|
||||
return false;
|
||||
return saved.equals(token);
|
||||
}
|
||||
|
||||
public synchronized void resetToken(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession(false);
|
||||
if (session == null)
|
||||
return;
|
||||
session.removeAttribute("org.apache.struts.action.TOKEN");
|
||||
}
|
||||
|
||||
public synchronized void saveToken(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession();
|
||||
String token = generateToken(request);
|
||||
if (token != null)
|
||||
session.setAttribute("org.apache.struts.action.TOKEN", token);
|
||||
}
|
||||
|
||||
public String generateToken(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession();
|
||||
try {
|
||||
byte[] id = session.getId().getBytes();
|
||||
byte[] now = (new Long(System.currentTimeMillis())).toString().getBytes();
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(id);
|
||||
md.update(now);
|
||||
return toHex(md.digest());
|
||||
} catch (IllegalStateException e) {
|
||||
return null;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String toHex(byte[] buffer) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String s = null;
|
||||
for (int i = 0; i < buffer.length; i++) {
|
||||
s = Integer.toHexString(buffer[i] & 0xFF);
|
||||
if (s.length() < 2)
|
||||
sb.append('0');
|
||||
sb.append(s);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user