dgraham 2003/07/25 18:00:01 Modified: src/share/org/apache/struts/taglib/html ErrorsTag.java src/share/org/apache/struts/taglib/logic MessagesPresentTag.java Added: src/share/org/apache/struts/taglib TagUtils.java Log: Added TagUtils class for taglibs to use instead of RequestUtils. We should migrate any method in RequestUtils that takes a PageContext parameter and/or throws JspException. A clean separation will help keep RequestUtils smaller and allow the taglibs to be easily split off of the core Struts distro. Revision Changes Path 1.23 +6 -5 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.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- ErrorsTag.java 2 Jul 2003 02:24:12 -0000 1.22 +++ ErrorsTag.java 26 Jul 2003 01:00:01 -0000 1.23 @@ -70,6 +70,7 @@ import org.apache.struts.Globals; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; +import org.apache.struts.taglib.TagUtils; import org.apache.struts.util.MessageResources; import org.apache.struts.util.RequestUtils; import org.apache.struts.util.ResponseUtils; @@ -184,7 +185,7 @@ // Were any error messages specified? ActionErrors errors = null; try { - errors = RequestUtils.getActionErrors(pageContext, name); + errors = TagUtils.getInstance().getActionErrors(pageContext, name); } catch (JspException e) { RequestUtils.saveException(pageContext, e); throw e; 1.8 +3 -2 jakarta-struts/src/share/org/apache/struts/taglib/logic/MessagesPresentTag.java Index: MessagesPresentTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/MessagesPresentTag.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- MessagesPresentTag.java 13 Jul 2003 23:20:16 -0000 1.7 +++ MessagesPresentTag.java 26 Jul 2003 01:00:01 -0000 1.8 @@ -61,6 +61,7 @@ import org.apache.struts.Globals; import org.apache.struts.action.ActionMessages; +import org.apache.struts.taglib.TagUtils; import org.apache.struts.util.RequestUtils; /** @@ -129,7 +130,7 @@ try { // Definitely know it should be an error so use method to retrieve errors. if (Globals.ERROR_KEY.equals(name)) { - am = RequestUtils.getActionErrors(pageContext, name); + am = TagUtils.getInstance().getActionErrors(pageContext, name); } else { am = RequestUtils.getActionMessages(pageContext, name); } 1.1 jakarta-struts/src/share/org/apache/struts/taglib/TagUtils.java Index: TagUtils.java =================================================================== /* * $Header$ * $Revision$ * $Date$ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Struts", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.struts.taglib; import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.util.MessageResources; /** * Provides helper methods for JSP tags. * * @author Craig R. McClanahan * @author Ted Husted * @author James Turner * @author David Graham * @version $Revision$ */ public class TagUtils { /** * The Singleton instance. */ private static final TagUtils instance = new TagUtils(); /** * Commons logging instance. */ private static final Log log = LogFactory.getLog(TagUtils.class); /** * The message resources for this package. */ private static final MessageResources messages = MessageResources.getMessageResources("org.apache.struts.util.LocalStrings"); /** * Constructor for TagUtils. */ protected TagUtils() { super(); } /** * Returns the Singleton instance of TagUtils. */ public static TagUtils getInstance() { return instance; } /** * Retrieves the value from request scope and if it isn't already an * <code>ErrorMessages</code> some classes are converted to one. * * @param pageContext The PageContext for the current page * @param paramName Key for parameter value * @return ActionErrors from request scope * @exception JspException */ public ActionErrors getActionErrors(PageContext pageContext, String paramName) throws JspException { ActionErrors errors = new ActionErrors(); Object value = pageContext.findAttribute(paramName); try { if (value == null) { ; } else if (value instanceof String) { errors.add( ActionErrors.GLOBAL_ERROR, new ActionError((String) value)); } else if (value instanceof String[]) { String keys[] = (String[]) value; for (int i = 0; i < keys.length; i++) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(keys[i])); } } else if (value instanceof ActionErrors) { errors = (ActionErrors) value; } else { throw new JspException( messages.getMessage( "actionErrors.errors", value.getClass().getName())); } } catch (JspException e) { throw e; } catch (Exception e) { log.debug(e, e); } return errors; } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]