husted 2004/02/07 07:55:02 Modified: src/share/org/apache/struts/taglib TagUtils.java src/share/org/apache/struts/taglib/bean IncludeTag.java src/share/org/apache/struts/taglib/html ImgTag.java LinkTag.java RewriteTag.java src/share/org/apache/struts/taglib/logic RedirectTag.java src/share/org/apache/struts/util ModuleUtils.java RequestUtils.java Log: Apply #24235 " html:link tag, plus module support" submitted by Gary Ashley. Revision Changes Path 1.31 +39 -12 jakarta-struts/src/share/org/apache/struts/taglib/TagUtils.java Index: TagUtils.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/TagUtils.java,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- TagUtils.java 19 Jan 2004 04:43:10 -0000 1.30 +++ TagUtils.java 7 Feb 2004 15:55:02 -0000 1.31 @@ -311,6 +311,7 @@ String href, String page, String action, + String module, Map params, String anchor, boolean redirect) @@ -321,6 +322,7 @@ href, page, action, + module, params, anchor, redirect, @@ -358,6 +360,7 @@ String href, String page, String action, + String module, Map params, String anchor, boolean redirect, @@ -370,6 +373,7 @@ href, page, action, + module, params, anchor, redirect, @@ -383,6 +387,7 @@ String href, String page, String action, + String module, Map params, String anchor, boolean redirect, @@ -394,6 +399,7 @@ href, page, action, + module, params, anchor, redirect, @@ -439,6 +445,7 @@ String href, String page, String action, + String module, Map params, String anchor, boolean redirect, @@ -471,7 +478,7 @@ } // Look up the module configuration for this request - ModuleConfig config = instance.getModuleConfig(pageContext); + ModuleConfig config = instance.getModuleConfig(module, pageContext); // Calculate the appropriate URL StringBuffer url = new StringBuffer(); @@ -493,7 +500,7 @@ } else if (href != null) { url.append(href); } else if (action != null) { - url.append(instance.getActionMappingURL(action, pageContext)); + url.append(instance.getActionMappingURL(action, module, pageContext, false)); } else /* if (page != null) */ { url.append(request.getContextPath()); @@ -778,18 +785,18 @@ * Return the form action converted into a server-relative URL. */ public String getActionMappingURL(String action, PageContext pageContext) { - return getActionMappingURL(action,pageContext,false); + return getActionMappingURL(action,null,pageContext,false); } /** * Return the form action converted into a server-relative URL. */ - public String getActionMappingURL(String action, PageContext pageContext, boolean contextRelative) { + public String getActionMappingURL(String action, String module, PageContext pageContext, boolean contextRelative) { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); StringBuffer value = new StringBuffer(request.getContextPath()); - ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(request); + ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(module, request, pageContext.getServletContext()); if ((config != null) && (!contextRelative)) { value.append(config.getPrefix()); @@ -903,11 +910,24 @@ * @return the ModuleConfig object */ public ModuleConfig getModuleConfig(PageContext pageContext) { - return ModuleUtils.getInstance().getModuleConfig( - (HttpServletRequest) pageContext.getRequest(), - pageContext.getServletContext()); + return getModuleConfig( + null, + pageContext); } + /** + * Return the ModuleConfig object for the given prefix if it exists, null if otherwise. + * @param module The module prefix + * @param pageContext The page context. + * @return the ModuleConfig object + */ + public ModuleConfig getModuleConfig(String module, PageContext pageContext) { + return ModuleUtils.getInstance().getModuleConfig( + module, + (HttpServletRequest) pageContext.getRequest(), + pageContext.getServletContext()); + } + /** * Converts the scope name into its corresponding PageContext constant value. * @param scopeName Can be "page", "request", "session", or "application" in any @@ -1242,6 +1262,13 @@ (MessageResources) pageContext.getAttribute( bundle + config.getPrefix(), PageContext.APPLICATION_SCOPE); + } + + if (resources == null) { + resources = + (MessageResources) pageContext.getAttribute( + bundle, + PageContext.APPLICATION_SCOPE); } if (resources == null) { 1.29 +5 -5 jakarta-struts/src/share/org/apache/struts/taglib/bean/IncludeTag.java Index: IncludeTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/IncludeTag.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- IncludeTag.java 13 Jan 2004 12:48:46 -0000 1.28 +++ IncludeTag.java 7 Feb 2004 15:55:02 -0000 1.29 @@ -232,7 +232,7 @@ URL url = null; try { urlString = - TagUtils.getInstance().computeURLWithCharEncoding(pageContext, forward, href, page, null,params, anchor, false, useLocalEncoding); + TagUtils.getInstance().computeURLWithCharEncoding(pageContext, forward, href, page, null,null, params, anchor, false, useLocalEncoding); if (urlString.indexOf(':') < 0) { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); url = new URL(RequestUtils.requestURL(request), urlString); 1.38 +18 -5 jakarta-struts/src/share/org/apache/struts/taglib/html/ImgTag.java Index: ImgTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ImgTag.java,v retrieving revision 1.37 retrieving revision 1.38 diff -u -r1.37 -r1.38 --- ImgTag.java 22 Jan 2004 04:54:13 -0000 1.37 +++ ImgTag.java 7 Feb 2004 15:55:02 -0000 1.38 @@ -273,6 +273,19 @@ this.action = action; } + /** + * The module prefix (beginning with a slash) which will be + * used to find the action for this link. + */ + protected String module = null; + + public String getModule() { + return (this.module); + } + + public void setModule(String module) { + this.module = module; + } /** * In situations where an image is dynamically generated (such as to create @@ -631,7 +644,7 @@ if ((this.src != null) || (this.srcKey != null)) { throwImgTagSrcException(); } - return TagUtils.getInstance().getActionMappingURL(action, pageContext, isContextRelativeSet()); + return TagUtils.getInstance().getActionMappingURL(action, module, pageContext, isContextRelativeSet()); } // Deal with an absolute source that has been specified 1.35 +31 -16 jakarta-struts/src/share/org/apache/struts/taglib/html/LinkTag.java Index: LinkTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/LinkTag.java,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- LinkTag.java 13 Jan 2004 12:48:47 -0000 1.34 +++ LinkTag.java 7 Feb 2004 15:55:02 -0000 1.35 @@ -183,19 +183,34 @@ } - /** - * The module-relative action (beginning with a slash) which will be - * called by this link - */ - protected String action = null; + /** + * The module-relative action (beginning with a slash) which will be + * called by this link + */ + protected String action = null; - public String getAction() { - return (this.action); - } + public String getAction() { + return (this.action); + } - public void setAction(String action) { - this.action = action; - } + public void setAction(String action) { + this.action = action; + } + + + /** + * The module prefix (beginning with a slash) which will be + * used to find the action for this link. + */ + protected String module = null; + + public String getModule() { + return (this.module); + } + + public void setModule(String module) { + this.module = module; + } /** @@ -497,7 +512,7 @@ String url = null; try { url = TagUtils.getInstance().computeURLWithCharEncoding(pageContext, forward, href, - page, action, params, anchor, false, useLocalEncoding); + page, action, module, params, anchor, false, useLocalEncoding); } catch (MalformedURLException e) { TagUtils.getInstance().saveException(pageContext, e); throw new JspException 1.19 +5 -4 jakarta-struts/src/share/org/apache/struts/taglib/html/RewriteTag.java Index: RewriteTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/RewriteTag.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- RewriteTag.java 13 Jan 2004 12:48:47 -0000 1.18 +++ RewriteTag.java 7 Feb 2004 15:55:02 -0000 1.19 @@ -102,6 +102,7 @@ href, page, action, + module, params, anchor, false, 1.23 +20 -4 jakarta-struts/src/share/org/apache/struts/taglib/logic/RedirectTag.java Index: RedirectTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/RedirectTag.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- RedirectTag.java 16 Jan 2004 04:55:00 -0000 1.22 +++ RedirectTag.java 7 Feb 2004 15:55:02 -0000 1.23 @@ -168,6 +168,21 @@ this.action = action; } + + /** + * The module prefix (beginning with a slash) which will be + * used to find the action for this link. + */ + protected String module = null; + + public String getModule() { + return (this.module); + } + + public void setModule(String module) { + this.module = module; + } + /** * The single-parameter request parameter name to generate. */ @@ -326,6 +341,7 @@ href, page, action, + module, params, anchor, true, 1.7 +65 -27 jakarta-struts/src/share/org/apache/struts/util/ModuleUtils.java Index: ModuleUtils.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/ModuleUtils.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ModuleUtils.java 13 Jan 2004 12:48:52 -0000 1.6 +++ ModuleUtils.java 7 Feb 2004 15:55:02 -0000 1.7 @@ -108,21 +108,59 @@ super(); } - /** - * Return the current ModuleConfig object stored in request, if it exists, - * null otherwise. - * This method can be used by plugin to retrieve the current module config - * object. If no moduleConfig is found, this means that the request haven't - * hit the server throught the struts servlet. The appropriate module config - * can be set and found with - * <code>[EMAIL PROTECTED] RequestUtils#selectModule(HttpServletRequest, ServletContext)} </code>. - * @param request The servlet request we are processing - * @return the ModuleConfig object from request, or null if none is set in - * the request. - */ - public ModuleConfig getModuleConfig(HttpServletRequest request) { - return (ModuleConfig) request.getAttribute(Globals.MODULE_KEY); - } + /** + * Return the current ModuleConfig object stored in request, if it exists, + * null otherwise. + * This method can be used by plugin to retrieve the current module config + * object. If no moduleConfig is found, this means that the request haven't + * hit the server throught the struts servlet. The appropriate module config + * can be set and found with + * <code>[EMAIL PROTECTED] RequestUtils#selectModule(HttpServletRequest, ServletContext)} </code>. + * @param request The servlet request we are processing + * @return the ModuleConfig object from request, or null if none is set in + * the request. + */ + public ModuleConfig getModuleConfig(HttpServletRequest request) { + return (ModuleConfig) request.getAttribute(Globals.MODULE_KEY); + } + + /** + * Return the desired ModuleConfig object stored in context, if it exists, + * null otherwise. + * + * @param prefix The module prefix of the desired module + * @param context The ServletContext for this web application + * @return the ModuleConfig object specified, or null if not found in + * the context. + */ + public ModuleConfig getModuleConfig(String prefix, ServletContext context) { + return (ModuleConfig) context.getAttribute(Globals.MODULE_KEY + prefix); + } + + /** + * Return the desired ModuleConfig object stored in context, if it exists, + * otherwise return the current ModuleConfig + * + * @param prefix The module prefix of the desired module + * @param request The servlet request we are processing + * @param context The ServletContext for this web application + * @return the ModuleConfig object specified, or null if not found in + * the context. + */ + public ModuleConfig getModuleConfig(String prefix, HttpServletRequest request, ServletContext context) { + ModuleConfig moduleConfig = null; + + + if(prefix != null) { + //lookup module stored with the given prefix. + moduleConfig = this.getModuleConfig(prefix, context); + } + else { + //return the current module if no prefix was supplied. + moduleConfig = this.getModuleConfig(request, context); + } + return moduleConfig; + } /** * Return the ModuleConfig object is it exists, null otherwise. @@ -134,16 +172,17 @@ HttpServletRequest request, ServletContext context) { - ModuleConfig moduleConfig = this.getModuleConfig(request); + ModuleConfig moduleConfig = this.getModuleConfig(request); - if (moduleConfig == null) { - moduleConfig = (ModuleConfig) context.getAttribute(Globals.MODULE_KEY); - request.setAttribute(Globals.MODULE_KEY, moduleConfig); - } + if (moduleConfig == null) { + moduleConfig = this.getModuleConfig("", context); + request.setAttribute(Globals.MODULE_KEY, moduleConfig); + } - return moduleConfig; + return moduleConfig; } + /** * Get the module name to which the specified request belong. * @param request The servlet request we are processing @@ -246,8 +285,7 @@ ServletContext context) { // Expose the resources for this module - ModuleConfig config = - (ModuleConfig) context.getAttribute(Globals.MODULE_KEY + prefix); + ModuleConfig config = getModuleConfig(prefix, context); if (config != null) { request.setAttribute(Globals.MODULE_KEY, config); 1.145 +7 -5 jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java Index: RequestUtils.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v retrieving revision 1.144 retrieving revision 1.145 diff -u -r1.144 -r1.145 --- RequestUtils.java 27 Jan 2004 01:09:32 -0000 1.144 +++ RequestUtils.java 7 Feb 2004 15:55:02 -0000 1.145 @@ -1216,7 +1216,7 @@ // :TODO: Remove after Struts 1.2 return (TagUtils.getInstance().computeURLWithCharEncoding( - pageContext, forward, href, page, null, params, anchor, redirect, false)); + pageContext, forward, href, page, null, null, params, anchor, redirect, false)); } @@ -1263,6 +1263,7 @@ href, page, action, + null, params, anchor, redirect); @@ -1317,6 +1318,7 @@ href, page, action, + null, params, anchor, redirect,
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]