public ActionMapping getMapping(HttpServletRequest request) { ActionMapping mapping = new ActionMapping(); String uri = getUri(request); parseNameAndNamespace(uri, mapping); handleSpecialParameters(request, mapping); if (mapping.getName() == null) { return null; } // handle "name!method" convention. String name = mapping.getName(); int exclamation = name.lastIndexOf("!"); if (exclamation != -1) { mapping.setName(name.substring(0, exclamation)); mapping.setMethod(name.substring(exclamation + 1)); } return mapping; }
/** * Returns null if no extension is specified. */ static String getDefaultExtension() { List extensions = getExtensions(); if (extensions == null) { return null; } else { return (String) extensions.get(0); } }
protected void parseNameAndNamespace(String uri, ActionMapping mapping) { String namespace, name; int lastSlash = uri.lastIndexOf("/"); if (lastSlash == -1) { namespace = ""; name = uri; } else if (lastSlash == 0) { // ww-1046, assume it is the root namespace, it will fallback to default // namespace anyway if not found in root namespace. namespace = "/"; name = uri.substring(lastSlash + 1); } else { namespace = uri.substring(0, lastSlash); name = uri.substring(lastSlash + 1); } mapping.setNamespace(namespace); mapping.setName(dropExtension(name)); }
/** * Renders an action URL by consulting the {@link com.opensymphony.webwork.dispatcher.mapper.ActionMapper}. * @param action the action * @param namespace the namespace * @param method the method * @param req HTTP request * @param res HTTP response * @param parameters parameters * @param scheme http or https * @param includeContext should the context path be included or not * @param encodeResult should the url be encoded * @return the action url. */ protected String determineActionURL(String action, String namespace, String method, HttpServletRequest req, HttpServletResponse res, Map parameters, String scheme, boolean includeContext, boolean encodeResult, boolean escapeXml) { String finalAction = findString(action); String finalNamespace = determineNamespace(namespace, getStack(), req); ActionMapping mapping = new ActionMapping(finalAction, finalNamespace, method, parameters); ActionMapper mapper = ActionMapperFactory.getMapper(); String uri = mapper.getUriFromActionMapping(mapping); return UrlHelper.buildUrl(uri, req, res, parameters, scheme, includeContext, encodeResult, false, escapeXml); }
ActionMapping mapping = new ActionMapping(); mapping.setName(getActionName(fullPath.toString())); mapping.setNamespace(getNamespace(fullPath.toString())); actionMap.put(portletMode, mapping);
String namespace = mapping.getNamespace(); String name = mapping.getName(); String method = mapping.getMethod(); if (mapping.getResult() != null) { Result result = mapping.getResult(); result.execute(proxy.getInvocation()); } else {
public String getUriFromActionMapping(ActionMapping mapping) { StringBuffer uri = new StringBuffer(); uri.append(mapping.getNamespace()); if(!"/".equals(mapping.getNamespace())) { uri.append("/"); } String name = mapping.getName(); String params = ""; if ( name.indexOf('?') != -1) { params = name.substring(name.indexOf('?')); name = name.substring(0, name.indexOf('?')); } uri.append(name); if (null != mapping.getMethod() && !"".equals(mapping.getMethod())) { uri.append("!").append(mapping.getMethod()); } String extension = getDefaultExtension(); if ( extension != null && uri.indexOf( '.' + extension) == -1 ) { uri.append(".").append(extension); if ( params.length() > 0) { uri.append(params); } } return uri.toString(); }
String namespace = ActionMapperFactory.getMapper().getMapping(request).getNamespace();
public String getUriFromActionMapping(ActionMapping mapping) { String base = mapping.getNamespace() + mapping.getName(); for (Iterator iterator = mapping.getParams().entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); String name = (String) entry.getKey(); if (name.equals(mapping.getName() + "Id")) { base = base + "/" + entry.getValue(); break; } } return base; } }
/** * */ protected ActionMapping getActionMapping(ActionDefinition actionDefinition, Map<String, String> params) { ActionMapping actionMapping = new ActionMapping(actionDefinition.getAction(), actionDefinition.getNamespace(), actionDefinition.getMethod(), params); return actionMapping; }
ActionMapping mapping = ActionMapperFactory.getMapper().getMapping(request); if (mapping == null) { try {
/** * Extension hook, that handle special parameters, namely those with prefix * eg. * <ul> * <li>action:someAction</li> * <li>method:someMethod</li> * <li>redirect:http://www.google.com</li> * <li>redirect-action:someRedirectAction</li> * </ul> * @param request * @param mapping */ protected void handleSpecialParameters(HttpServletRequest request, ActionMapping mapping) { // handle special parameter prefixes. Map parameterMap = request.getParameterMap(); for (Iterator iterator = parameterMap.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); ParameterAction parameterAction = (ParameterAction) prefixTrie.get(key); if (parameterAction != null) { parameterAction.execute(key, mapping); break; } } }
public Map createContextMap(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping, ServletContext context) { // request map wrapping the http request objects Map requestMap = new RequestMap(request); // parameters map wrapping the http paraneters. Map params = null; if (mapping != null) { params = mapping.getParams(); } Map requestParams = new HashMap(request.getParameterMap()); if (params != null) { params.putAll(requestParams); } else { params = requestParams; } // session map wrapping the http session Map session = new SessionMap(request); // application map wrapping the ServletContext Map application = new ApplicationMap(context); return createContextMap(requestMap, params, session, application, request, response, context); }
ActionMapper mapper = ActionMapperFactory.getMapper(); StringBuffer tmpLocation = new StringBuffer(mapper.getUriFromActionMapping(new ActionMapping(actionName, namespace, method, null))); UrlHelper.buildParametersString(requestParameters, tmpLocation, "&");
ActionMapping mapping = new ActionMapping(); if (resetAction(request)) { mapping = (ActionMapping) actionMap.get(request.getPortletMode()); action = actionPath.substring(idx + 1); mapping.setName(action); mapping.setNamespace(namespace);
public static String buildNamespace(OgnlValueStack stack, HttpServletRequest request) { ActionContext context = new ActionContext(stack.getContext()); ActionInvocation invocation = context.getActionInvocation(); if (invocation == null) { ActionMapper mapper = ActionMapperFactory.getMapper(); ActionMapping mapping = mapper.getMapping(request); if (mapping != null) { return mapping.getNamespace(); } else { // well, if the ActionMapper can't tell us, and there is no existing action invocation, // let's just go with a default guess that the namespace is the last the path minus the // last part (/foo/bar/baz.xyz -> /foo/bar) String path = RequestUtils.getServletPath(request); return path.substring(0, path.lastIndexOf("/")); } } else { return invocation.getProxy().getNamespace(); } } }
return new ActionMapping(actionName, "", "", parameters);
ActionMapper mapper = ActionMapperFactory.getMapper(); ActionMapping mapping = mapper.getMapping(request);
String dropExtension(String name) { List extensions = getExtensions(); if (extensions == null) { return name; } Iterator it = extensions.iterator(); while (it.hasNext()) { String extension = "." + (String) it.next(); if ( name.endsWith(extension)) { name = name.substring(0, name.length() - extension.length()); return name; } } return null; }
if (actionConfig != null) { ActionMapping mapping = new ActionMapping(action, namespace, actionMethod, parameters); String result = UrlHelper.buildUrl(ActionMapperFactory.getMapper().getUriFromActionMapping(mapping), request, response, null); addParameter("action", result);