rleland 2002/10/11 15:17:51 Modified: src/share/org/apache/struts/taglib/html JavascriptValidatorTag.java src/share/org/apache/struts/util RequestUtils.java StrutsValidatorUtil.java src/share/org/apache/struts/validator ValidatorPlugIn.java Log: Buzilla 10348 - based on Patch by Eddie Bush Allow Ranges for Floating point numbers Eddie I didn't place your name in RequestUtils.java, since that patch didn't make sense. However I did placed it in StrutsValidatorUtil which met the 10 lines rule of thumb. Revision Changes Path 1.5 +8 -3 jakarta-struts/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java Index: JavascriptValidatorTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- JavascriptValidatorTag.java 9 Jul 2002 23:58:52 -0000 1.4 +++ JavascriptValidatorTag.java 11 Oct 2002 22:17:50 -0000 1.5 @@ -68,6 +68,7 @@ import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.BodyTagSupport; + import org.apache.commons.validator.Field; import org.apache.commons.validator.Form; import org.apache.commons.validator.ValidatorAction; @@ -78,6 +79,9 @@ import org.apache.struts.validator.ValidatorPlugIn; import org.apache.struts.util.MessageResources; import org.apache.struts.util.StrutsValidatorUtil; +import org.apache.struts.util.RequestUtils; +import org.apache.struts.Globals; +import org.apache.struts.config.ApplicationConfig; /** @@ -254,9 +258,10 @@ public int doStartTag() throws JspException { StringBuffer results = new StringBuffer(); + ApplicationConfig config = RequestUtils.getApplicationConfig(pageContext); ValidatorResources resources = (ValidatorResources) - pageContext.getAttribute(ValidatorPlugIn.VALIDATOR_KEY, PageContext.APPLICATION_SCOPE); - + pageContext.getAttribute(ValidatorPlugIn.VALIDATOR_KEY + + config.getPrefix(),PageContext.APPLICATION_SCOPE); Locale locale = null; try { locale = (Locale) pageContext.getAttribute(Action.LOCALE_KEY, PageContext.SESSION_SCOPE); 1.55 +18 -11 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.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- RequestUtils.java 8 Oct 2002 06:16:41 -0000 1.54 +++ RequestUtils.java 11 Oct 2002 22:17:51 -0000 1.55 @@ -90,7 +90,6 @@ import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; -import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; @@ -103,7 +102,6 @@ import org.apache.struts.config.FormBeanConfig; import org.apache.struts.config.ForwardConfig; import org.apache.struts.taglib.html.Constants; -import org.apache.struts.upload.FormFile; import org.apache.struts.upload.MultipartRequestHandler; @@ -1190,9 +1188,6 @@ * * @param request The servlet request we are processing * @param forward ForwardConfig to be evaluated - * @param slashPrefixed If true, method takes care to prefix the forward path - * URL with a '/' if needed. If false, the '/' is added only if forward - * path is used after another prefix. * @since Struts 1.1b2 */ public static String forwardURL(HttpServletRequest request, @@ -1452,6 +1447,20 @@ } + /** + * Return the ApplicationConfig object is it exists, null otherwise. + * @param pageContext The page context. + * @return the ApplicationConfig object + */ + public static ApplicationConfig getApplicationConfig(PageContext pageContext) { + ApplicationConfig appConfig = (ApplicationConfig) + pageContext.getRequest().getAttribute(Action.APPLICATION_KEY); + if (appConfig == null) { // Backwards compatibility hack + appConfig = (ApplicationConfig) + pageContext.getServletContext().getAttribute(Action.APPLICATION_KEY); + } + return appConfig; + } /** * Return the list of module prefixes that are defined for @@ -1474,8 +1483,6 @@ if (!name.startsWith(Action.APPLICATION_KEY)) { continue; } - ApplicationConfig config = (ApplicationConfig) - context.getAttribute(name); String prefix = name.substring(Action.APPLICATION_KEY.length()); if (prefix.length() > 0) { list.add(prefix); 1.5 +20 -7 jakarta-struts/src/share/org/apache/struts/util/StrutsValidatorUtil.java Index: StrutsValidatorUtil.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/StrutsValidatorUtil.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- StrutsValidatorUtil.java 10 Jul 2002 00:00:19 -0000 1.4 +++ StrutsValidatorUtil.java 11 Oct 2002 22:17:51 -0000 1.5 @@ -68,14 +68,14 @@ import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.util.MessageResources; -import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.validator.Arg; import org.apache.commons.validator.Field; import org.apache.commons.validator.Validator; import org.apache.commons.validator.ValidatorAction; import org.apache.commons.validator.ValidatorResources; -import org.apache.commons.validator.ValidatorUtil; import org.apache.struts.validator.ValidatorPlugIn; +import org.apache.struts.config.ApplicationConfig; +import org.apache.struts.Globals; /** @@ -83,6 +83,7 @@ * from different scopes of the application.</p> * * @author David Winterfeldt + * @author Eddie Bush * @version $Revision$ $Date$ * @since Struts 1.1 */ @@ -107,11 +108,23 @@ /** * Retrieve <code>ValidatorResources</code> for the module. + * + * @deprecated This method can only return the resources for the default + * module. Use getValidatorResources(HttpServletRequest, ServletContext) + * to get the resources for the current application module. */ public static ValidatorResources getValidatorResources(ServletContext application) { return (ValidatorResources)application.getAttribute(ValidatorPlugIn.VALIDATOR_KEY); } + /** + * Retrieve <code>ValidatorResources</code> for the current module. + */ + public static ValidatorResources getValidatorResources(ServletContext application,HttpServletRequest request) { + return (ValidatorResources) application.getAttribute(ValidatorPlugIn.VALIDATOR_KEY + + ((ApplicationConfig)request.getAttribute(Globals.APPLICATION_KEY)).getPrefix()); + } + /** * Retrieve <code>MessageResources</code> for the application module. * @@ -291,7 +304,7 @@ ServletContext application, HttpServletRequest request, ActionErrors errors, int page) { - ValidatorResources resources = StrutsValidatorUtil.getValidatorResources(application); + ValidatorResources resources = StrutsValidatorUtil.getValidatorResources(application,request); Locale locale = StrutsValidatorUtil.getLocale(request); Validator validator = new Validator(resources, key); 1.7 +5 -5 jakarta-struts/src/share/org/apache/struts/validator/ValidatorPlugIn.java Index: ValidatorPlugIn.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/validator/ValidatorPlugIn.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ValidatorPlugIn.java 10 Jul 2002 00:00:27 -0000 1.6 +++ ValidatorPlugIn.java 11 Oct 2002 22:17:51 -0000 1.7 @@ -165,7 +165,7 @@ // Load our database from persistent storage try { initResources(); - servlet.getServletContext().setAttribute(VALIDATOR_KEY, resources); + servlet.getServletContext().setAttribute(VALIDATOR_KEY + config.getPrefix(), resources); } catch (Exception e) { log.error(e.getMessage(), e); throw new UnavailableException
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>