| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
package net.smartlab.web; |
| 25 |
|
|
| 26 |
|
import java.lang.reflect.InvocationTargetException; |
| 27 |
|
import java.lang.reflect.Method; |
| 28 |
|
import java.util.Arrays; |
| 29 |
|
import java.util.HashMap; |
| 30 |
|
import java.util.Iterator; |
| 31 |
|
import java.util.Locale; |
| 32 |
|
import java.util.Map; |
| 33 |
|
|
| 34 |
|
import javax.servlet.http.HttpServletRequest; |
| 35 |
|
import javax.servlet.http.HttpServletResponse; |
| 36 |
|
|
| 37 |
|
import org.apache.commons.collections.FastHashMap; |
| 38 |
|
import org.apache.struts.Globals; |
| 39 |
|
import org.apache.struts.action.ActionForm; |
| 40 |
|
import org.apache.struts.action.ActionForward; |
| 41 |
|
import org.apache.struts.action.ActionMapping; |
| 42 |
|
import org.apache.struts.config.MessageResourcesConfig; |
| 43 |
|
import org.apache.struts.config.ModuleConfig; |
| 44 |
|
import org.apache.struts.util.MessageResources; |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
@author |
| 50 |
|
|
|
|
|
| 0% |
Uncovered Elements: 74 (74) |
Complexity: 19 |
Complexity Density: 0,42 |
|
| 51 |
|
public abstract class DynaAction extends Action { |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
private final static Class[] PARAMETERS = new Class[] {ActionForm.class, HttpServletRequest.class, HttpServletResponse.class, ActionMapping.class}; |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
private final Map methods = new FastHashMap(); |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
private final Map locales = new HashMap(); |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0,6 |
|
| 71 |
0
|
public DynaAction() {... |
| 72 |
0
|
Method[] methods = this.getClass().getMethods(); |
| 73 |
0
|
for (int i = 0; i < methods.length; i++) { |
| 74 |
0
|
if (Arrays.equals(methods[i].getParameterTypes(), PARAMETERS)) { |
| 75 |
0
|
this.methods.put(methods[i].getName(), methods[i]); |
| 76 |
|
} |
| 77 |
|
} |
| 78 |
0
|
((FastHashMap)this.methods).setFast(true); |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
@see |
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
|
|
|
| 0% |
Uncovered Elements: 61 (61) |
Complexity: 15 |
Complexity Density: 0,38 |
|
| 86 |
0
|
protected ActionForward execute(ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws Exception {... |
| 87 |
0
|
if (logger.isDebugEnabled()) { |
| 88 |
0
|
logger.debug("execute(" + mapping.getPath() + ") - start"); |
| 89 |
|
} |
| 90 |
0
|
String method = mapping.getParameter(); |
| 91 |
0
|
if (mapping == null) { |
| 92 |
0
|
throw new ActionException("action.parameter.null"); |
| 93 |
|
} |
| 94 |
0
|
if (method.startsWith("@")) { |
| 95 |
|
|
| 96 |
0
|
method = method.substring(1); |
| 97 |
|
|
| 98 |
0
|
method = request.getParameter(method); |
| 99 |
0
|
if (!methods.containsKey(method)) { |
| 100 |
|
|
| 101 |
|
|
| 102 |
0
|
Map lookup = null; |
| 103 |
0
|
Locale locale = request.getLocale(); |
| 104 |
0
|
boolean exists = true; |
| 105 |
0
|
synchronized (locales) { |
| 106 |
0
|
lookup = (Map)this.locales.get(locale); |
| 107 |
0
|
if (lookup == null) { |
| 108 |
0
|
exists = false; |
| 109 |
0
|
lookup = new HashMap(); |
| 110 |
0
|
locales.put(locale, lookup); |
| 111 |
|
} |
| 112 |
|
} |
| 113 |
0
|
if (!exists) { |
| 114 |
0
|
synchronized (lookup) { |
| 115 |
0
|
method = mapping.getParameter().substring(1); |
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
0
|
ModuleConfig module = (ModuleConfig)request.getAttribute(Globals.MODULE_KEY); |
| 123 |
0
|
MessageResourcesConfig[] messages = module.findMessageResourcesConfigs(); |
| 124 |
|
|
| 125 |
0
|
for (int i = 0; i < messages.length; i++) { |
| 126 |
0
|
MessageResources resources = this.getResources(request, messages[i].getKey()); |
| 127 |
|
|
| 128 |
0
|
Iterator names = this.methods.keySet().iterator(); |
| 129 |
0
|
while (names.hasNext()) { |
| 130 |
0
|
String name = (String)names.next(); |
| 131 |
0
|
String message = resources.getMessage(locale, method + '.' + name); |
| 132 |
0
|
if ((message != null) && !lookup.containsKey(message)) { |
| 133 |
|
|
| 134 |
|
|
| 135 |
0
|
lookup.put(message, name); |
| 136 |
|
} |
| 137 |
|
} |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
|
} |
| 141 |
|
|
| 142 |
0
|
method = (String)lookup.get(method); |
| 143 |
|
} |
| 144 |
|
} |
| 145 |
|
|
| 146 |
0
|
if (logger.isTraceEnabled()) { |
| 147 |
0
|
logger.trace(" method = " + method); |
| 148 |
|
} |
| 149 |
0
|
try { |
| 150 |
0
|
Object forward = ((Method)methods.get(method)).invoke(this, new Object[] {form, request, response, mapping}); |
| 151 |
0
|
if (forward instanceof String) { |
| 152 |
0
|
return mapping.findForward((String)forward); |
| 153 |
|
} else { |
| 154 |
0
|
return (ActionForward)forward; |
| 155 |
|
} |
| 156 |
|
} catch (InvocationTargetException ite) { |
| 157 |
|
Throwable cause = ite.getTargetException(); |
| 158 |
|
if (cause instanceof Exception) { |
| 159 |
|
throw (Exception)cause; |
| 160 |
|
} else { |
| 161 |
|
logger.error("execute( " + mapping.getPath() + ") - error", cause); |
| 162 |
|
throw new ActionException("action.method.exception", cause); |
| 163 |
|
} |
| 164 |
|
} catch (Exception e) { |
| 165 |
|
logger.error("execute( " + mapping.getPath() + ") - error", e); |
| 166 |
|
throw new ActionException("action.method.unknown", method); |
| 167 |
|
} |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
|
@param |
| 174 |
|
@param |
| 175 |
|
@param |
| 176 |
|
@param |
| 177 |
|
@return |
| 178 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 179 |
0
|
public final String forward(ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) {... |
| 180 |
0
|
return "success"; |
| 181 |
|
} |
| 182 |
|
} |