dgraham 2003/07/13 17:10:49 Modified: src/share/org/apache/struts/taglib/bean HeaderTag.java Log: Refactored doStartTag() into smaller methods. Revision Changes Path 1.11 +40 -24 jakarta-struts/src/share/org/apache/struts/taglib/bean/HeaderTag.java Index: HeaderTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/HeaderTag.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- HeaderTag.java 14 Jul 2003 00:04:44 -0000 1.10 +++ HeaderTag.java 14 Jul 2003 00:10:49 -0000 1.11 @@ -151,26 +151,21 @@ */ public int doStartTag() throws JspException { - // Deal with a single header value - if (multiple == null) { - String value = - ((HttpServletRequest) pageContext.getRequest()).getHeader(name); - - if ((value == null) && (this.value != null)) { - value = this.value; - } - - if (value == null) { - JspException e = - new JspException(messages.getMessage("header.get", name)); - RequestUtils.saveException(pageContext, e); - throw e; - } - pageContext.setAttribute(id, value); - return (SKIP_BODY); + if (this.multiple == null) { + this.handleSingleHeader(); + } else { + this.handleMultipleHeaders(); } - // Deal with multiple header values + return SKIP_BODY; + } + + /** + * Expose an array of header values. + * @throws JspException + * @since Struts 1.2 + */ + protected void handleMultipleHeaders() throws JspException { ArrayList values = new ArrayList(); Enumeration items = ((HttpServletRequest) pageContext.getRequest()).getHeaders(name); @@ -179,7 +174,7 @@ values.add(items.nextElement()); } - if ((values.size() == 0) && (this.value != null)){ + if (values.isEmpty() && (this.value != null)){ values.add(this.value); } @@ -192,8 +187,29 @@ } pageContext.setAttribute(id, (String[]) values.toArray(headers)); - return (SKIP_BODY); + } + + /** + * Expose a single header value. + * @throws JspException + * @since Struts 1.2 + */ + protected void handleSingleHeader() throws JspException { + String value = + ((HttpServletRequest) pageContext.getRequest()).getHeader(name); + if ((value == null) && (this.value != null)) { + value = this.value; + } + + if (value == null) { + JspException e = + new JspException(messages.getMessage("header.get", name)); + RequestUtils.saveException(pageContext, e); + throw e; + } + + pageContext.setAttribute(id, value); } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]