dmkarr      2002/10/25 21:33:17

  Modified:    contrib/struts-el/doc/userGuide struts-bean-el.xml
               contrib/struts-el/web/exercise-taglib bean-include.jsp
                        index.jsp
  Added:       contrib/struts-el/src/share/org/apache/strutsel/taglib/bean
                        ELIncludeTag.java ELIncludeTagBeanInfo.java
  Log:
  Bug 13788; Added bean-el:include to get access to forward functionality
  
  Revision  Changes    Path
  1.1                  
jakarta-struts/contrib/struts-el/src/share/org/apache/strutsel/taglib/bean/ELIncludeTag.java
  
  Index: ELIncludeTag.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-struts/contrib/struts-el/src/share/org/apache/strutsel/taglib/bean/ELIncludeTag.java,v
 1.1 2002/10/26 04:33:17 dmkarr Exp $
   * $Revision: 1.1 $
   * $Date: 2002/10/26 04:33:17 $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 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 acknowledgement:
   *       "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.strutsel.taglib.bean;
  
  import org.apache.struts.taglib.bean.IncludeTag;
  import javax.servlet.jsp.JspException;
  import org.apache.strutsel.taglib.utils.EvalHelper;
  import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
  
  /**
   * Generate a URL-encoded include to the specified URI.
   *<p>
   * This class is a subclass of the class
   * <code>org.apache.struts.taglib.bean.IncludeTag</code> which
   * provides most of the described functionality.  This subclass allows all
   * attribute values to be specified as expressions utilizing the JavaServer
   * Pages Standard Library expression language.
   *
   * @author David M. Karr
   * @version $Revision: 1.1 $
   */
  public class ELIncludeTag extends IncludeTag {
  
      /**
       * String value of the "transaction" attribute.
       */
      private String   transactionExpr;
  
      /**
       * Returns the string value of the "transaction" attribute.
       */
      public  String   getTransactionExpr() { return (transactionExpr); }
  
      /**
       * Sets the string value of the "transaction" attribute.  This attribute is
       * mapped to this method by the <code>ELIncludeTagBeanInfo</code> class.
       */
      public  void     setTransactionExpr(String transactionExpr)
      { this.transactionExpr  = transactionExpr; }
  
      /**
       * Resets attribute values for tag reuse.
       */
      public void release()
      {
          super.release();
          setTransactionExpr(null);
      }
  
      /**
       * Process the start tag.
       *
       * @exception JspException if a JSP exception has occurred
       */
      public int doStartTag() throws JspException {
          evaluateExpressions();
          return (super.doStartTag());
      }
  
      /**
       * Evaluates and returns a single attribute value, given the attribute
       * name, attribute value, and attribute type.  It uses the
       * <code>EvalHelper</code> class to interface to
       * <code>ExpressionUtil.evalNotNull</code> to do the actual evaluation, and
       * it passes to this the name of the current tag, the <code>this</code>
       * pointer, and the current pageContext.
       *
       * @param attrName attribute name being evaluated
       * @param attrValue String value of attribute to be evaluated using EL
       * @param attrType Required resulting type of attribute value
       * @exception NullAttributeException if either the <code>attrValue</code>
       * was null, or the resulting evaluated value was null.
       * @return Resulting attribute value
       */
      private Object   evalAttr(String   attrName,
                                String   attrValue,
                                Class    attrType)
          throws JspException, NullAttributeException
      {
          return (EvalHelper.eval("include", attrName, attrValue, attrType,
                                  this, pageContext));
      }
      
      /**
       * Processes all attribute values which use the JSTL expression evaluation
       * engine to determine their values.  If any evaluation fails with a
       * <code>NullAttributeException</code> it will just use <code>null</code>
       * as the value.
       *
       * @exception JspException if a JSP exception has occurred
       */
      private void evaluateExpressions() throws JspException {
          try {
              setAnchor((String) evalAttr("anchor", getAnchor(), String.class));
          } catch (NullAttributeException ex) {
              setAnchor(null);
          }
  
          try {
              setForward((String) evalAttr("forward", getForward(),
                                           String.class));
          } catch (NullAttributeException ex) {
              setForward(null);
          }
  
          try {
              setHref((String) evalAttr("href", getHref(), String.class));
          } catch (NullAttributeException ex) {
              setHref(null);
          }
  
          try {
              setId((String) evalAttr("id", getId(), String.class));
          } catch (NullAttributeException ex) {
              setId(null);
          }
  
          //  The "name" attribute is deprecated.  The base class has a
          //  "setName()" method, which sets the "page" attribute, but it does
          //  not have a "getName()" attribute, so just use "getPage()".
          try {
              setName((String) evalAttr("name", getPage(), String.class));
          } catch (NullAttributeException ex) {
              setName(null);
          }
  
          try {
              setPage((String) evalAttr("page", getPage(), String.class));
          } catch (NullAttributeException ex) {
              setPage(null);
          }
  
          try {
              setTransaction(((Boolean) evalAttr("transaction",
                                                 getTransactionExpr(),
                                                 Boolean.class)).
                             booleanValue());
          } catch (NullAttributeException ex) {
              setTransaction(false);
          }
      }
  }
  
  
  
  1.1                  
jakarta-struts/contrib/struts-el/src/share/org/apache/strutsel/taglib/bean/ELIncludeTagBeanInfo.java
  
  Index: ELIncludeTagBeanInfo.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-struts/contrib/struts-el/src/share/org/apache/strutsel/taglib/bean/ELIncludeTagBeanInfo.java,v
 1.1 2002/10/26 04:33:17 dmkarr Exp $
   * $Revision: 1.1 $
   * $Date: 2002/10/26 04:33:17 $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 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 acknowledgement:
   *       "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.strutsel.taglib.bean;
  
  import java.beans.PropertyDescriptor;
  import java.beans.IntrospectionException;
  import java.beans.SimpleBeanInfo;
  
  /**
   * This is the <code>BeanInfo</code> descriptor for the
   * <code>org.apache.strutsel.taglib.bean.ELIncludeTag</code> class.  It is
   * needed to override the default mapping of custom tag attribute names to
   * class attribute names.
   *<p>
   * This is necessary because the base class,
   * <code>org.apache.struts.taglib.bean.IncludeTag</code> defines some
   * attributes whose type is not <code>java.lang.String</code>, so the subclass
   * needs to define setter methods of a different name, which this class maps
   * to.
   *<p>
   * Unfortunately, if a <code>BeanInfo</code> class needs to be provided to
   * change the mapping of one attribute, it has to specify the mappings of ALL
   * attributes, even if all the others use the expected mappings of "name" to
   * "method".
   */
  public class ELIncludeTagBeanInfo extends SimpleBeanInfo
  {
      public  PropertyDescriptor[] getPropertyDescriptors()
      {
          PropertyDescriptor[]  result   = new PropertyDescriptor[7];
  
          try {
              result[0] = new PropertyDescriptor("anchor", ELIncludeTag.class,
                                                 null, "setAnchor");
              result[1] = new PropertyDescriptor("forward", ELIncludeTag.class,
                                                 null, "setForward");
              result[2] = new PropertyDescriptor("href", ELIncludeTag.class,
                                                 null, "setHref");
              result[3] = new PropertyDescriptor("id", ELIncludeTag.class,
                                                 null, "setId");
              result[4] = new PropertyDescriptor("name", ELIncludeTag.class,
                                                 null, "setName");
              result[5] = new PropertyDescriptor("page", ELIncludeTag.class,
                                                  null, "setPage");
              result[6] = new PropertyDescriptor("transaction",
                                                 ELIncludeTag.class,
                                                 null, "setTransactionExpr");
          }
          catch (IntrospectionException ex) {
              ex.printStackTrace();
          }
          
          return (result);
      }
  }
  
  
  
  1.2       +127 -5    
jakarta-struts/contrib/struts-el/doc/userGuide/struts-bean-el.xml
  
  Index: struts-bean-el.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/struts-el/doc/userGuide/struts-bean-el.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- struts-bean-el.xml        26 Sep 2002 04:54:38 -0000      1.1
  +++ struts-bean-el.xml        26 Oct 2002 04:33:17 -0000      1.2
  @@ -43,6 +43,128 @@
   
     <tag>
   
  +    <name>include</name>
  +    <summary>
  +    Load the response from a dynamic application request and make it available
  +    as a bean.
  +    </summary>
  +    <tagclass>org.apache.strutsel.taglib.bean.ELIncludeTag</tagclass>
  +    <bodycontent>empty</bodycontent>
  +    <info>
  +
  +    <p>Perform an internal dispatch to the specified application component (or
  +    external URL) and make the response data from that request available as a
  +    scoped variable of type <code>String</code>.  This tag has a function
  +    similar to that of the standard <code>&lt;jsp:include&gt;</code> tag,
  +    except that the response data is stored in a page scope attribute instead
  +    of being written to the output stream.  If the current request is part of a
  +    session, the generated request for the include will also include the
  +    session identifier (and thus be part of the same session).</p>
  +
  +    <p>The URL used to access the specified application component is
  +    calculated based on which of the following attributes you specify
  +    (you must specify exactly one of them):</p>
  +    <ul>
  +    <li><em>forward</em> - Use the value of this attribute as the name
  +        of a global <code>ActionForward</code> to be looked up, and
  +        use the application-relative or context-relative URI found there.</li>
  +    <li><em>href</em> - Use the value of this attribute unchanged (since
  +        this might link to a resource external to the application, the
  +        session identifier is <strong>not</strong> included.</li>
  +    <li><em>page</em> - Use the value of this attribute as an
  +        application-relative URI to the desired resource.</li>
  +    </ul>
  +    </info>
  +
  +    <p><strong>WARNING</strong> - Accessing resources protected by security
  +    constraints, or resources under the <code>/WEB-INF</code> subdirectory,
  +     with this tag is not supported.  Consider using the
  +    <code>&lt;jsp:include ... flush="false"&gt;</code> tag on a JSP 1.2
  +    or later container, or the
  +    <code>&lt;c:import&gt;</code> tag from the JSP Standard Tag Library
  +    to accomplish this.</p>
  +
  +    <attribute>
  +      <name>anchor</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +      <info>
  +      <p>Optional anchor tag ("#xxx") to be added to the generated
  +      hyperlink.  Specify this value <strong>without</strong> any
  +      "#" character.</p>
  +      </info>
  +    </attribute>
  +
  +    <attribute>
  +      <name>forward</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +      <info>
  +      <p>Logical name of a global <code>ActionForward</code> that contains
  +      the actual content-relative URI of the resource to be included.</p>
  +      </info>
  +    </attribute>
  +
  +    <attribute>
  +      <name>href</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +      <info>
  +      <p>Absolute URL (including the appropriate protocol prefix such as
  +      "http:") of the resource to be included.  Because this URL could be
  +      external to the current web application, the session identifier will
  +      <strong>not</strong> be included in the request.</p>
  +      </info>
  +    </attribute>
  +
  +    <attribute>
  +      <name>id</name>
  +      <required>true</required>
  +      <rtexprvalue>false</rtexprvalue>
  +      <info>
  +      <p>Specifies the name of the associated page scope attribute that will be
  +      made available with the value of the specified web application
  +      resource.</p>
  +      </info>
  +    </attribute>
  +
  +    <attribute>
  +      <name>name</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +      <info>
  +      <p>Application-relative name (starting with a '/') of the web application
  +      resource to be dispatched, and whose response data is to be made
  +      available as a bean.  <strong>DEPRECATED - Use the "page" attribute
  +      instead</strong>.</p>
  +      </info>
  +    </attribute>
  +
  +    <attribute>
  +      <name>page</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +      <info>
  +      <p>Application-relative URI (starting with a '/') of the web application
  +      resource to be included.</p>
  +      </info>
  +    </attribute>
  +
  +    <attribute>
  +      <name>transaction</name>
  +      <required>false</required>
  +      <rtexprvalue>false</rtexprvalue>
  +      <info>
  +        <p>Set to <code>true</code> if you want the current
  +        transaction control token included in the generated
  +        URL for this include.</p>
  +      </info>
  +    </attribute>
  +
  +  </tag>
  +
  +  <tag>
  +
       <name>message</name>
       <summary>
       Render an internationalized message string to the response.
  @@ -243,16 +365,16 @@
         <required>true</required>
         <rtexprvalue>false</rtexprvalue>
         <info>
  -      <p>Specifies the name of the scripting variable (and associated page
  -      scope attribute) that will be made available with the value of the
  -      specified web application resource.</p>
  +      <p>Specifies the name of the associated page scope attribute that will be
  +      made available with the value of the specified web application
  +      resource.</p>
         </info>
       </attribute>
   
       <attribute>
         <name>input</name>
         <required>false</required>
  -      <rtexprvalue>true</rtexprvalue>
  +      <rtexprvalue>false</rtexprvalue>
         <info>
         <p>If any arbitrary value for this attribute is specified, the resource
         will be made available as an <code>InputStream</code>.  If this
  @@ -264,7 +386,7 @@
       <attribute>
         <name>name</name>
         <required>true</required>
  -      <rtexprvalue>true</rtexprvalue>
  +      <rtexprvalue>false</rtexprvalue>
         <info>
         <p>Application-relative name (starting with a '/') of the web application
         resource to be loaded and made available.</p>
  
  
  
  1.2       +21 -4     
jakarta-struts/contrib/struts-el/web/exercise-taglib/bean-include.jsp
  
  Index: bean-include.jsp
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/struts-el/web/exercise-taglib/bean-include.jsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- bean-include.jsp  26 Sep 2002 04:54:41 -0000      1.1
  +++ bean-include.jsp  26 Oct 2002 04:33:17 -0000      1.2
  @@ -5,18 +5,19 @@
   <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
   <html-el:html>
   <head>
  -<title>Test Replacements for struts-bean:include Tag</title>
  +<title>Test bean-el:include Tag and Replacements</title>
   </head>
   <body bgcolor="white">
   
   <div align="center">
  -<h1>Test Replacements for struts-bean:include Tag</h1>
  +<h1>Test bean-el:include Tag and Replacements</h1>
   </div>
   
   <c:import url="/index.jsp" var="index"/>
  +<bean-el:include id="index2" page="/index.jsp"/>
   
   <p>Display the contents returned by invoking <code>/index.jsp</code>
  -directly, with no filtering.</p>
  +using <code>&lt;c:import&gt;</code>, with no filtering.</p>
   <hr>
   <pre>
   <c:out value="${index}" escapeXml="false"/>
  @@ -24,10 +25,26 @@
   <hr>
   
   <p>Display the contents returned by invoking <code>/index.jsp</code>
  -directly, with filtering.</p>
  +using <code>&lt;c:import&gt;</code>, with filtering.</p>
   <hr>
   <pre>
   <c:out value="${index}" escapeXml="true"/>
  +</pre>
  +<hr>
  +
  +<p>Display the contents returned by invoking <code>/index.jsp</code>
  +using <code>&lt;bean-el:include&gt;</code>, with no filtering.</p>
  +<hr>
  +<pre>
  +<c:out value="${index2}" escapeXml="false"/>
  +</pre>
  +<hr>
  +
  +<p>Display the contents returned by invoking <code>/index.jsp</code>
  +using <code>&lt;bean-el:include&gt;</code>, with filtering.</p>
  +<hr>
  +<pre>
  +<c:out value="${index2}" escapeXml="true"/>
   </pre>
   <hr>
   
  
  
  
  1.5       +1 -1      jakarta-struts/contrib/struts-el/web/exercise-taglib/index.jsp
  
  Index: index.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/contrib/struts-el/web/exercise-taglib/index.jsp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- index.jsp 25 Oct 2002 04:45:01 -0000      1.4
  +++ index.jsp 26 Oct 2002 04:33:17 -0000      1.5
  @@ -11,6 +11,7 @@
   
   <h3>BEAN Tags</h3>
   <ul>
  +<li><a href="bean-include.jsp">&lt;bean:include&gt;</a>[<a 
href="showSource.jsp?path=/bean-include.jsp">Source</a>]</li>
   <li><a href="bean-resource.jsp">&lt;bean:resource&gt;</a>[<a 
href="showSource.jsp?path=/bean-resource.jsp">Source</a>]</li>
   <li><a href="bean-size.jsp">&lt;bean:size&gt;</a>[<a 
href="showSource.jsp?path=/bean-size.jsp">Source</a>]</li>
   </ul>
  @@ -42,7 +43,6 @@
   <li><a href="bean-cookie.jsp">&lt;bean:cookie&gt;</a>[<a 
href="showSource.jsp?path=/bean-cookie.jsp">Source</a>]</li>
   <li><a href="bean-define.jsp">&lt;bean:define&gt;</a>[<a 
href="showSource.jsp?path=/bean-define.jsp">Source</a>]</li>
   <li><a href="bean-header.jsp">&lt;bean:header&gt;</a>[<a 
href="showSource.jsp?path=/bean-header.jsp">Source</a>]</li>
  -<li><a href="bean-include.jsp">&lt;bean:include&gt;</a>[<a 
href="showSource.jsp?path=/bean-include.jsp">Source</a>]</li>
   <li><a 
href="bean-parameter.jsp?param1=value1&param2=value2">&lt;bean:parameter&gt;</a>[<a 
href="showSource.jsp?path=/bean-parameter.jsp">Source</a>]</li>
   <li><a href="bean-write.jsp">&lt;bean:write&gt;</a>[<a 
href="showSource.jsp?path=/bean-write.jsp">Source</a>]</li>
   </ul>
  
  
  

--
To unsubscribe, e-mail:   <mailto:struts-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-dev-help@;jakarta.apache.org>

Reply via email to