dgraham     2003/07/26 11:58:37

  Modified:    src/share/org/apache/struts/taglib/html ErrorsTag.java
               src/share/org/apache/struts/util RequestUtils.java
               src/share/org/apache/struts/taglib TagUtils.java
  Log:
  Moved present() and message() to TagUtils.
  
  Revision  Changes    Path
  1.24      +8 -8      
jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java
  
  Index: ErrorsTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- ErrorsTag.java    26 Jul 2003 01:00:01 -0000      1.23
  +++ ErrorsTag.java    26 Jul 2003 18:58:36 -0000      1.24
  @@ -196,16 +196,16 @@
           }
   
           boolean headerPresent =
  -            RequestUtils.present(pageContext, bundle, locale, "errors.header");
  +            TagUtils.getInstance().present(pageContext, bundle, locale, 
"errors.header");
   
           boolean footerPresent =
  -            RequestUtils.present(pageContext, bundle, locale, "errors.footer");
  +        TagUtils.getInstance().present(pageContext, bundle, locale, 
"errors.footer");
   
           boolean prefixPresent =
  -            RequestUtils.present(pageContext, bundle, locale, "errors.prefix");
  +        TagUtils.getInstance().present(pageContext, bundle, locale, 
"errors.prefix");
   
           boolean suffixPresent =
  -            RequestUtils.present(pageContext, bundle, locale, "errors.suffix");
  +        TagUtils.getInstance().present(pageContext, bundle, locale, 
"errors.suffix");
   
           // Render the error messages appropriately
           StringBuffer results = new StringBuffer();
  
  
  
  1.125     +15 -75    
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.124
  retrieving revision 1.125
  diff -u -r1.124 -r1.125
  --- RequestUtils.java 26 Jul 2003 18:51:37 -0000      1.124
  +++ RequestUtils.java 26 Jul 2003 18:58:36 -0000      1.125
  @@ -845,6 +845,8 @@
        * @return message string
        * @exception JspException if a lookup error occurs (will have been
        *  saved in the request already)
  +     * @deprecated Use TagUtils.message() instead.  This will be removed after
  +     * Struts 1.2.
        */
       public static String message(
           PageContext pageContext,
  @@ -854,71 +856,12 @@
           Object args[])
           throws JspException {
   
  -        MessageResources resources =
  -            retrieveMessageResources(pageContext, bundle, false);
  -
  -        Locale userLocale = retrieveUserLocale(pageContext, locale);
  -        
  -        if (args == null) {
  -            return (resources.getMessage(userLocale, key));
  -        } else {
  -            return (resources.getMessage(userLocale, key, args));
  -        }
  -
  -    }
  -
  -    /**
  -     * Returns the appropriate MessageResources object for the current module and 
  -     * the given bundle.
  -     * 
  -     * @param pageContext Search the context's scopes for the resources.
  -     * @param bundle The bundle name to look for.  If this is <code>null</code>, 
the 
  -     * default bundle name is used.
  -     * @return MessageResources The bundle's resources stored in some scope. 
  -     * @throws JspException if the MessageResources object could not be found.
  -     */
  -    private static MessageResources retrieveMessageResources(
  -        PageContext pageContext,
  -        String bundle,
  -        boolean checkPageScope)
  -        throws JspException {
  -            
  -        MessageResources resources = null;
  -
  -        if (bundle == null) {
  -            bundle = Globals.MESSAGES_KEY;
  -        }
  -
  -        if (checkPageScope) {
  -            resources =
  -                (MessageResources) pageContext.getAttribute(
  -                    bundle,
  -                    PageContext.PAGE_SCOPE);
  -        }
  -
  -        if (resources == null) {
  -            resources =
  -                (MessageResources) pageContext.getAttribute(
  -                    bundle,
  -                    PageContext.REQUEST_SCOPE);
  -        }
  -
  -        if (resources == null) {
  -            ModuleConfig config = getModuleConfig(pageContext);
  -            resources =
  -                (MessageResources) pageContext.getAttribute(
  -                    bundle + config.getPrefix(),
  -                    PageContext.APPLICATION_SCOPE);
  -        }
  -
  -        if (resources == null) {
  -            JspException e =
  -                new JspException(messages.getMessage("message.bundle", bundle));
  -            saveException(pageContext, e);
  -            throw e;
  -        }
  -
  -        return resources;
  +        return TagUtils.getInstance().message(
  +            pageContext,
  +            bundle,
  +            locale,
  +            key,
  +            args);
       }
   
       /**
  @@ -1209,6 +1152,8 @@
        * @return true if a message string for message key exists
        * @exception JspException if a lookup error occurs (will have been
        *  saved in the request already)
  +     * @deprecated Use TagUtils.present() instead.  This will be removed after
  +     * Struts 1.2.
        */
       public static boolean present(
           PageContext pageContext,
  @@ -1217,12 +1162,7 @@
           String key)
           throws JspException {
   
  -        MessageResources resources =
  -            retrieveMessageResources(pageContext, bundle, true);
  -
  -        Locale userLocale = retrieveUserLocale(pageContext, locale);
  -
  -        return (resources.isPresent(userLocale, key));
  +        return TagUtils.getInstance().present(pageContext, bundle, locale, key);
       }
   
       /**
  
  
  
  1.11      +120 -4    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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TagUtils.java     26 Jul 2003 18:51:37 -0000      1.10
  +++ TagUtils.java     26 Jul 2003 18:58:37 -0000      1.11
  @@ -573,6 +573,122 @@
           }
   
       }
  +    
  +    /**
  +     * Look up and return a message string, based on the specified parameters.
  +     *
  +     * @param pageContext The PageContext associated with this request
  +     * @param bundle Name of the servlet context attribute for our
  +     *  message resources bundle
  +     * @param locale Name of the session attribute for our user's Locale
  +     * @param key Message key to be looked up and returned
  +     * @param args Replacement parameters for this message
  +     * @return message string
  +     * @exception JspException if a lookup error occurs (will have been
  +     *  saved in the request already)
  +     */
  +    public String message(
  +        PageContext pageContext,
  +        String bundle,
  +        String locale,
  +        String key,
  +        Object args[])
  +        throws JspException {
  +
  +        MessageResources resources =
  +            retrieveMessageResources(pageContext, bundle, false);
  +
  +        Locale userLocale = getUserLocale(pageContext, locale);
  +        
  +        if (args == null) {
  +            return (resources.getMessage(userLocale, key));
  +        } else {
  +            return (resources.getMessage(userLocale, key, args));
  +        }
  +
  +    }
  +    
  +    /**
  +     * Return true if a message string for the specified message key
  +     * is present for the specified Locale.
  +     *
  +     * @param pageContext The PageContext associated with this request
  +     * @param bundle Name of the servlet context attribute for our
  +     *  message resources bundle
  +     * @param locale Name of the session attribute for our user's Locale
  +     * @param key Message key to be looked up and returned
  +     * @return true if a message string for message key exists
  +     * @exception JspException if a lookup error occurs (will have been
  +     *  saved in the request already)
  +     */
  +    public boolean present(
  +        PageContext pageContext,
  +        String bundle,
  +        String locale,
  +        String key)
  +        throws JspException {
  +
  +        MessageResources resources =
  +            retrieveMessageResources(pageContext, bundle, true);
  +
  +        Locale userLocale = getUserLocale(pageContext, locale);
  +
  +        return (resources.isPresent(userLocale, key));
  +    }
  +    
  +    /**
  +     * Returns the appropriate MessageResources object for the current module and 
  +     * the given bundle.
  +     * 
  +     * @param pageContext Search the context's scopes for the resources.
  +     * @param bundle The bundle name to look for.  If this is <code>null</code>, 
the 
  +     * default bundle name is used.
  +     * @return MessageResources The bundle's resources stored in some scope. 
  +     * @throws JspException if the MessageResources object could not be found.
  +     */
  +    private MessageResources retrieveMessageResources(
  +        PageContext pageContext,
  +        String bundle,
  +        boolean checkPageScope)
  +        throws JspException {
  +            
  +        MessageResources resources = null;
  +
  +        if (bundle == null) {
  +            bundle = Globals.MESSAGES_KEY;
  +        }
  +
  +        if (checkPageScope) {
  +            resources =
  +                (MessageResources) pageContext.getAttribute(
  +                    bundle,
  +                    PageContext.PAGE_SCOPE);
  +        }
  +
  +        if (resources == null) {
  +            resources =
  +                (MessageResources) pageContext.getAttribute(
  +                    bundle,
  +                    PageContext.REQUEST_SCOPE);
  +        }
  +
  +        if (resources == null) {
  +            ModuleConfig config = getModuleConfig(pageContext);
  +            resources =
  +                (MessageResources) pageContext.getAttribute(
  +                    bundle + config.getPrefix(),
  +                    PageContext.APPLICATION_SCOPE);
  +        }
  +
  +        if (resources == null) {
  +            JspException e =
  +                new JspException(messages.getMessage("message.bundle", bundle));
  +            saveException(pageContext, e);
  +            throw e;
  +        }
  +
  +        return resources;
  +    }
   
       /**
        * Save the specified exception as a request attribute for later use.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to