jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject cvs commit: jakarta-taglibs/jsptl/src/org/apache/taglibs/jsptl/tag/jx ExpressionUtil.java ImportTag.java
Date Thu, 25 Oct 2001 04:31:36 GMT
shawn       01/10/24 21:31:36

  Modified:    jsptl/conf jr.tld jx.tld
               jsptl/src/org/apache/taglibs/jsptl/tag/common
                        NullAttributeException.java
  Added:       jsptl/examples/web/import Absolute.jsp ContextRelative.jsp
                        ExposeString.jsp ExposeStringRelative.jsp
                        LocalSample.jsp Relative.jsp
               jsptl/src/org/apache/taglibs/jsptl/tag/common
                        ImportSupport.java
               jsptl/src/org/apache/taglibs/jsptl/tag/jr ImportTag.java
               jsptl/src/org/apache/taglibs/jsptl/tag/jx
                        ExpressionUtil.java ImportTag.java
  Log:
  Initial version of <import> tag for 'jr' and 'jx', including TLD modifications,
  and several examples.  Some other related changes and minor typo fixes too.
  Not yet thoroughly tested.
  
  Revision  Changes    Path
  1.2       +35 -0     jakarta-taglibs/jsptl/conf/jr.tld
  
  Index: jr.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/jsptl/conf/jr.tld,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- jr.tld	2001/07/08 16:27:34	1.1
  +++ jr.tld	2001/10/25 04:31:35	1.2
  @@ -76,6 +76,41 @@
     </tag>
   
     <tag>
  +    <name>import</name>
  +    <tag-class>org.apache.taglibs.jsptl.tag.jr.ImportTag</tag-class>
  +    <body-content>JSP</body-content>
  +    <description>
  +        Retrieves an absolute or relative URL and exposes its contents
  +        to either the page, a String in 'var', or a Reader in 'varReader'.
  +    </description>
  +    <attribute>
  +        <name>url</name>
  +        <required>true</required>
  +        <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>var</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>varReader</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>context</name>
  +        <required>false</required>
  +        <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>charEncoding</name>
  +        <required>false</required>
  +        <rtexprvalue>true</rtexprvalue>
  +    </attribute>
  +  </tag>
  +
  +  <tag>
       <name>forEach</name>
       <tag-class>org.apache.taglibs.jsptl.tag.jr.ForEachTag</tag-class>
       <tei-class>org.apache.taglibs.jsptl.tei.ForEachTEI</tei-class>
  
  
  
  1.2       +35 -0     jakarta-taglibs/jsptl/conf/jx.tld
  
  Index: jx.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/jsptl/conf/jx.tld,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- jx.tld	2001/07/08 16:27:34	1.1
  +++ jx.tld	2001/10/25 04:31:35	1.2
  @@ -145,6 +145,41 @@
     </tag>
   
     <tag>
  +    <name>import</name>
  +    <tag-class>org.apache.taglibs.jsptl.tag.jx.ImportTag</tag-class>
  +    <body-content>JSP</body-content>
  +    <description>
  +	Retrieves an absolute or relative URL and exposes its contents
  +	to either the page, a String in 'var', or a Reader in 'varReader'.
  +    </description>
  +    <attribute>
  +        <name>url</name>
  +        <required>true</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>var</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>varReader</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>context</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +    <attribute>
  +        <name>charEncoding</name>
  +        <required>false</required>
  +        <rtexprvalue>false</rtexprvalue>
  +    </attribute>
  +  </tag>
  +
  +  <tag>
       <name>forEach</name>
       <tag-class>org.apache.taglibs.jsptl.tag.jx.ForEachTag</tag-class>
       <tei-class>org.apache.taglibs.jsptl.tei.ForEachTEI</tei-class>
  
  
  
  1.1                  jakarta-taglibs/jsptl/examples/web/import/Absolute.jsp
  
  Index: Absolute.jsp
  ===================================================================
  <%@ taglib prefix="jx" uri="http://java.sun.com/jsptl/ea/jx" %>
  
  <html>
  <head>
    <title>JSPTL: I/O Support -- Absolute URL Example</title>
  </head>
  <body bgcolor="#FFFFFF">
  <h3>Absolute URL</h3>
  
  <h4>CNN's RSS XML feed:</h4>
  <blockquote>
   <pre>
    <jx:import url="http://www.cnn.com/cnn.rss"/>
   </pre>
  </blockquote>
  
  </body>
  </html>
  
  
  
  1.1                  jakarta-taglibs/jsptl/examples/web/import/ContextRelative.jsp
  
  Index: ContextRelative.jsp
  ===================================================================
  <%@ taglib prefix="jx" uri="http://java.sun.com/jsptl/ea/jx" %>
  
  <html>
  <head>
    <title>JSPTL: I/O Support -- Context-relative URL example</title>
  </head>
  <body bgcolor="#FFFFFF">
  Assuming you have the "examples" webapp installed, here's a file from it...
  
  <blockquote>
   <pre>
    <jx:import url="/jsp/simpletag/foo.jsp" context="/examples"/>
   </pre>
  </blockquote>
  
  </body>
  </html>
  
  
  
  1.1                  jakarta-taglibs/jsptl/examples/web/import/ExposeString.jsp
  
  Index: ExposeString.jsp
  ===================================================================
  <%@ taglib prefix="jx" uri="http://java.sun.com/jsptl/ea/jx" %>
  
  <html>
  <head>
    <title>JSPTL: I/O Support -- String exposure</title>
  </head>
  <body bgcolor="#FFFFFF">
  <h3>String exposure</h3>
  
  <jx:import var="cnn" url="http://www.cnn.com/cnn.rss"/>
  
  <h4>CNN's RSS XML feed:</h4>
  <blockquote>
   <pre>
    <jx:expr value="$cnn"/>
   </pre>
  </blockquote>
  
  </body>
  </html>
  
  
  
  1.1                  jakarta-taglibs/jsptl/examples/web/import/ExposeStringRelative.jsp
  
  Index: ExposeStringRelative.jsp
  ===================================================================
  <%@ taglib prefix="jx" uri="http://java.sun.com/jsptl/ea/jx" %>
  
  <html>
  <head>
    <title>JSPTL: I/O Support -- String exposure for relative URL</title>
  </head>
  <body bgcolor="#FFFFFF">
  <h3>String exposure for relative URL</h3>
  
  <jx:import var="cnn" url="LocalSample.jsp"/>
  
  <jx:expr value="$cnn"/>
  
  </body>
  </html>
  
  
  
  1.1                  jakarta-taglibs/jsptl/examples/web/import/LocalSample.jsp
  
  Index: LocalSample.jsp
  ===================================================================
  <%@ taglib prefix="jx" uri="http://java.sun.com/jsptl/ea/jx" %>
  
  <html>
  <head>
    <title>JSPTL: I/O Support -- Simple static example to be included
     in other pages</title>
  </head>
  <body bgcolor="#FFFFFF">
  <h3>Local example target page</h3>
  
  <h4>&#149; This output comes from LocalSample.jsp &#149; </h4>
  
  </body>
  </html>
  
  
  
  1.1                  jakarta-taglibs/jsptl/examples/web/import/Relative.jsp
  
  Index: Relative.jsp
  ===================================================================
  <%@ taglib prefix="jx" uri="http://java.sun.com/jsptl/ea/jx" %>
  
  <html>
  <head>
    <title>JSPTL: I/O Support -- Relative URL Example</title>
  </head>
  <body bgcolor="#FFFFFF">
  <h3>Relative URL</h3>
  
  <h4>Import from current directory:</h4>
  <blockquote>
   <pre>
    <jx:import url="LocalSample.jsp"/>
   </pre>
  </blockquote>
  
  </body>
  </html>
  
  
  
  1.2       +1 -1      jakarta-taglibs/jsptl/src/org/apache/taglibs/jsptl/tag/common/NullAttributeException.java
  
  Index: NullAttributeException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/jsptl/src/org/apache/taglibs/jsptl/tag/common/NullAttributeException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NullAttributeException.java	2001/07/08 16:27:12	1.1
  +++ NullAttributeException.java	2001/10/25 04:31:35	1.2
  @@ -68,7 +68,7 @@
   public class NullAttributeException extends JspTagException {
   
       /**
  -     * Constructs a ExpressionException with appropriate information.
  +     * Constructs a NullAttributeException with appropriate information.
        *
        * @param tag The name of the tag in which the error occurred.
        * @param att The attribute value for which the error occurred.
  
  
  
  1.1                  jakarta-taglibs/jsptl/src/org/apache/taglibs/jsptl/tag/common/ImportSupport.java
  
  Index: ImportSupport.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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", "Tomcat", 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 apache@apache.org.
   *
   * 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.taglibs.jsptl.tag.common;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  
  /**
   * <p>Support for tag handlers for &lt;import&gt;, the general-purpose
   * text-importing mechanism for JSPTL 1.0.  The rtexprvalue and expression-
   * evaluating libraries each have handlers that extend this class.</p>
   *
   * @author Shawn Bayern
   */
  
  public abstract class ImportSupport extends BodyTagSupport 
          implements TryCatchFinally {
  
      //*********************************************************************
      // Public constants
      
      /** <p>Valid characters in a scheme.</p>
       *  <p>RFC 1738 says the following:</p>
       *  <blockquote>
       *   Scheme names consist of a sequence of characters. The lower
       *   case letters "a"--"z", digits, and the characters plus ("+"),
       *   period ("."), and hyphen ("-") are allowed. For resiliency,
       *   programs interpreting URLs should treat upper case letters as
       *   equivalent to lower case in scheme names (e.g., allow "HTTP" as
       *   well as "http").
       *  </blockquote>
       * <p>We treat as absolute any URL that begins with such a scheme name,
       * followed by a colon.</p>
       */
      public static final String VALID_SCHEME_CHARS =
  	"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+.-";
  
      /** Default character encoding for response. */
      public static final String DEFAULT_ENCODING = "ISO-8859-1";
  
      //*********************************************************************
      // Protected state
  
      protected String url;                         // 'url' attribute
      protected String var;                         // 'var' attribute
      protected String varReader;                   // 'varReader' attribute
      protected String context;			  // 'context' attribute
      protected String charEncoding;                // 'charEncoding' attrib.
  
      //*********************************************************************
      // Private state (implementation details)
  
      Reader r;				// exposed reader, if relevant
      Object oldVarReader;		// overwritten attribute
      boolean isAbsoluteUrl;		// is our URL absolute?
  
      //*********************************************************************
      // Constructor and initialization
  
      public ImportSupport() {
  	super();
  	init();
      }
  
      private void init() {
  	url = var = varReader = context = charEncoding = null;
      }
  
  
      //*********************************************************************
      // Tag logic
  
      // determines what kind of import and variable exposure to perform 
      public int doStartTag() throws JspException {
  	// Sanity check
  	if (context != null
  	        && (!context.startsWith("/") || !url.startsWith("/"))) {
  	    throw new JspException(
  		"In &lt;import&gt;, when 'context' attribute is specified, "
  		+ "values of both 'context' and 'url' must start with '/'.");
  	}
  
  	// Record whether our URL is absolute or relative
  	isAbsoluteUrl = isAbsoluteUrl();
  
  	try {
  	   // If we need to expose a Reader, we've got to do it right away
  	    if  (varReader != null) {
  	        r = acquireReader();
  	        Object oldVarReader = pageContext.getAttribute(varReader);
  	        pageContext.setAttribute(varReader, r);
  	    }
  	} catch (IOException ex) {
  	    throw new JspException(ex.getMessage());
  	} catch (ServletException ex) {
  	    throw new JspException(ex.getMessage());
  	}
  
  	return EVAL_BODY_INCLUDE;
      }
  
      // manages connections as necessary (creating or destroying)
      public int doEndTag() throws JspException {
          try {
  	    // If we didn't expose a Reader earlier...
  	    if (varReader == null) {
  	        // ... store it in 'var', if available ...
  	        if (var != null)
  	            pageContext.setAttribute(var, acquireString());	
                  // ... or simply output it, if we have nowhere to expose it
  	        else
  	            pageContext.getOut().print(acquireString());
  	    }
  	    return EVAL_PAGE;
          } catch (IOException ex) {
  	    throw new JspException(ex.getMessage());
          } catch (ServletException ex) {
  	    throw new JspException(ex.getMessage());
          }
      }
  
      // simply rethrows its exception
      public void doCatch(Throwable t) throws Throwable {
  	throw t;
      }
  
      // cleans up if appropriate
      public void doFinally() { 
          try {
  	    // If we exposed a Reader in doStartTag(), close it.
  	    if (varReader != null) {
  	        r.close();
  	        pageContext.setAttribute(varReader, oldVarReader);
  	    }
          } catch (IOException ex) {
  	    // ignore it; close() failed, but there's nothing more we can do
          }
      }
  
      // Releases any resources we may have (or inherit)
      public void release() {
  	init();
          super.release();
      }
  
      //*********************************************************************
      // Tag attributes known at translation time
  
      public void setVar(String var) {
  	this.var = var;
      }
  
      public void setVarReader(String varReader) {
  	this.varReader = varReader;
      }
  
      //*********************************************************************
      // Collaboration with subtags
  
      /**
       * Adds a parameter to this tag's URL.  The intent is that the
       * &lt;param&gt; subtag will call this to register URL parameters.
       * Assumes that 'name' and 'value' are appropriately encoded and do
       * not contain any meaningful metacharacters; in order words, escaping
       * is the responsibility of the caller.
       */
      public void addParameter(String name, String value) {
  	// append a '?' or '&' as appropriate, followed by name=value
  	boolean firstParameter = url.indexOf('?') == -1;
  	if (firstParameter)
  	    url += "?" + name + "=" + value;
  	else
  	    url += "&" + name + "=" + value;
      }
  
      //*********************************************************************
      // Actual URL importation logic
  
      /*
       * Overall strategy:  we have two entry points, acquireString() and
       * acquireReader().  The latter passes data through unbuffered if
       * possible (but note that it is not always possible -- specifically
       * for cases where we must use the RequestDispatcher.  The remaining
       * methods handle the common logic of loading either a URL or a local
       * resource.
       *
       * We consider the 'natural' form of absolute URLs to be Readers and
       * relative URLs to be Strings.  Thus, to avoid doing extra work,
       * acquireString() and acquireReader() delegate to one another as
       * appropriate.  (Perhaps I could have spelled things out more clearly,
       * but I thought this implementation was instructive, not to mention
       * somewhat cute...)
       */
  
      private String acquireString() throws IOException, ServletException {
  	if (isAbsoluteUrl) {
  	    // for absolute URLs, delegate to our peer
  	    BufferedReader r = new BufferedReader(acquireReader());
  	    StringBuffer sb = new StringBuffer();
  	    int i;
  
  	    // under JIT, testing seems to show this simple loop is as fast
  	    // as any of the alternatives
  	    while ((i = r.read()) != -1)
  	        sb.append((char)i);
  
  	    return sb.toString();
  	} else { 
  	    // handle relative URLs ourselves
  
  	    // retrieve an appropriate ServletContext
  	    ServletContext c = null;
  	    String targetUrl = null;
  	    if (context != null) {
  	        c = pageContext.getServletContext().getContext(context);
  
  		// accept the URL wholesale; we know it starts with '/'
  		targetUrl = url;
  		
  	    } else {
  	        c = pageContext.getServletContext();
  
  		// normalize the URL if we have an HttpServletRequest
  		if (pageContext.getRequest() instanceof HttpServletRequest
  			&& !url.startsWith("/")) {
  		    String sp = ((HttpServletRequest) 
  			pageContext.getRequest()).getServletPath();
  		    targetUrl = sp.substring(0, sp.lastIndexOf('/'))
  			+ '/' + url;
  		}
  	    }
  
  	    // from this context, get a dispatcher
  	    RequestDispatcher rd = c.getRequestDispatcher(targetUrl);
  
  	    // include the resource, using our custom wrapper
  	    ImportResponseWrapper irw = 
  		new ImportResponseWrapper(
  		    (HttpServletResponse) pageContext.getResponse());
  	    rd.include(pageContext.getRequest(), irw);
  
  	    // recover the response String from our wrapper
  	    return irw.toString();
  	}
      }
  
      private Reader acquireReader() throws IOException, ServletException {
  	if (!isAbsoluteUrl) {
  	    // for relative URLs, delegate to our peer
  	    return new StringReader(acquireString());
  	} else {
  	    // handle absolute URLs ourselves, using java.net.URL
  	    URL u = new URL(url);
              URLConnection uc = u.openConnection();
              InputStream i = uc.getInputStream();
  
  	    // okay, we've got a stream; encode it appropriately
  	    Reader r = null;
  	    if (charEncoding != null)
  		r = new InputStreamReader(i, charEncoding);
  	    else {
  		String responseAdvisoryEncoding = uc.getContentEncoding();
  		if (responseAdvisoryEncoding != null)
  		    r = new InputStreamReader(i, responseAdvisoryEncoding);
  		else
  		    r = new InputStreamReader(i, DEFAULT_ENCODING);
  	    }
  	    return r;
  	}
      }
  
      /** Wraps responses to allow us to retrieve results as Strings. */
      private static class ImportResponseWrapper
  	    extends HttpServletResponseWrapper {
  
  	//************************************************************
  	// Data
  
  	/** The Writer we convey. */
  	private StringWriter s = new StringWriter();
  
  	/** A ServletOutputStream we convey, tied to this Writer. */
  	private ServletOutputStream sos = new ServletOutputStream() {
  	    public void write(int b) throws IOException {
  		s.write(b);
  	    }
  	};
  	
  	//************************************************************
  	// Constructor and methods
  
  	/** Constructs a new ImportResponseWrapper. */
  	public ImportResponseWrapper(HttpServletResponse response) {
  	    super(response);
  	}
  	
  	/** Returns a Writer designed to buffer the output. */
  	public PrintWriter getWriter() {
  	    return new PrintWriter(s);
  	}
  	
  	/** Returns a ServletOutputStream designed to buffer the output. */
  	public ServletOutputStream getOutputStream() {
  	    return sos;
  	}
  
  	/** Retrieves the buffered output. */
  	public String toString() {
  	    return s.toString();
  	}
      }
  
      /** Returns <tt>true</tt> if our current URL is absolute,
       *  <tt>false</tt> otherwise.
       */
      private boolean isAbsoluteUrl() {
  	// do a fast, simple check first
  	int colonPos;
  	if ((colonPos = url.indexOf(":")) == -1)
  	    return false;
  
  	// if we DO have a colon, make sure that every character
  	// leading up to it is a valid scheme character
  	for (int i = 0; i < colonPos; i++)
  	    if (VALID_SCHEME_CHARS.indexOf(url.charAt(i)) == -1)
  		return false;
  
  	// otherwise, we've got ourselves an absolute url
  	return true;
      }
  }
  
  
  
  
  1.1                  jakarta-taglibs/jsptl/src/org/apache/taglibs/jsptl/tag/jr/ImportTag.java
  
  Index: ImportTag.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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", "Tomcat", 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 apache@apache.org.
   *
   * 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.taglibs.jsptl.tag.jr;
  
  import java.util.*;
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import org.apache.taglibs.jsptl.tag.common.*;
  
  /**
   * <p>A handler for &lt;import&gt; that supports rtexprvalue-based
   * attributes.</p>
   *
   * @author Shawn Bayern
   */
  
  public class ImportTag extends ImportSupport {
  
      //*********************************************************************
      // Accessor methods
  
      // for tag attribute
      public void setUrl(String url) throws JspTagException {
          this.url = url;
      }
  
      // for tag attribute
      public void setContext(String context) throws JspTagException {
          this.url = url;
      }
  
      // for tag attribute
      public void setCharEncoding(String charEncoding) throws JspTagException {
          this.url = url;
      }
  
  }
  
  
  
  1.1                  jakarta-taglibs/jsptl/src/org/apache/taglibs/jsptl/tag/jx/ExpressionUtil.java
  
  Index: ExpressionUtil.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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", "Tomcat", 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 apache@apache.org.
   *
   * 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.taglibs.jsptl.tag.jx;
  
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import javax.servlet.jsptl.ConditionalTagSupport;
  import org.apache.taglibs.jsptl.tag.common.*;
  import org.apache.taglibs.jsptl.lang.support.ExpressionEvaluatorManager;
  
  /**
   * <p>Contains some static utilities to facilitate common forms of
   * expression evaluation.</p>
   *
   * @author Shawn Bayern
   */
  
  public class ExpressionUtil {
  
      /** Evaluates an expression if present, but does not allow the expression
       *  to evaluate to 'null', throwing a NullAttributeException if it
       *  does.  The function <b>can</b> return null, however, if the
       *  expression itself is null.
       */
      public static Object evalNotNull(String tagName,
  				     String attributeName,
  	                             String expression,
  				     Class expectedType,
  				     Tag tag,
  	                             PageContext pageContext)
  	        throws JspException {
          if (expression != null) {
              Object r = ExpressionEvaluatorManager.evaluate(
                  attributeName, expression, expectedType, tag, pageContext);
              if (r == null)
                  throw new NullAttributeException(tagName, attributeName);
  	    return r;
          } else
  	    return null;
      }
  }
  
  
  
  1.1                  jakarta-taglibs/jsptl/src/org/apache/taglibs/jsptl/tag/jx/ImportTag.java
  
  Index: ImportTag.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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", "Tomcat", 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 apache@apache.org.
   *
   * 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.taglibs.jsptl.tag.jx;
  
  import java.util.*;
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import org.apache.taglibs.jsptl.tag.common.*;
  
  /**
   * <p>A handler for &lt;import&gt; that accepts attributes as Strings
   * and evaluates them as expressions at runtime.</p>
   *
   * @author Shawn Bayern
   */
  
  public class ImportTag extends ImportSupport {
  
      //*********************************************************************
      // 'Private' state (implementation details)
  
      private String context_;                    // stores EL-based property
      private String charEncoding_;		// stores EL-based property
      private String url_;			// stores EL-based property
  
  
      //*********************************************************************
      // Constructor
  
      /**
       * Constructs a new ImportTag.  As with TagSupport, subclasses
       * should not provide other constructors and are expected to call
       * the superclass constructor
       */
      public ImportTag() {
          super();
          init();
      }
  
  
      //*********************************************************************
      // Tag logic
  
      // evaluates expression and chains to parent
      public int doStartTag() throws JspException {
  
          // evaluate any expressions we were passed, once per invocation
          evaluateExpressions();
  
  	// chain to the parent implementation
  	return super.doStartTag();
      }
  
  
      // Releases any resources we may have (or inherit)
      public void release() {
          super.release();
          init();
      }
  
  
      //*********************************************************************
      // Accessor methods
  
      // for EL-based attribute
      public void setUrl(String url_) {
          this.url_ = url_;
      }
  
      public void setContext(String context_) {
          this.context_ = context_;
      }
  
      public void setCharEncoding(String charEncoding_) {
          this.charEncoding_ = charEncoding_;
      }
  
      //*********************************************************************
      // Private (utility) methods
  
      // (re)initializes state (during release() or construction)
      private void init() {
          // null implies "no expression"
  	url_ = context_ = charEncoding_ = null;
      }
  
      /* Evaluates expressions as necessary */
      private void evaluateExpressions() throws JspException {
          /* 
           * Note: we don't check for type mismatches here; we assume
           * the expression evaluator will return the expected type
           * (by virtue of knowledge we give it about what that type is).
           * A ClassCastException here is truly unexpected, so we let it
           * propagate up.
           */
  
  	url = (String) ExpressionUtil.evalNotNull(
  	    "import", "url", url_, String.class, this, pageContext);
  	context = (String) ExpressionUtil.evalNotNull(
  	    "import", "context", context_, String.class, this, pageContext);
  	charEncoding = (String) ExpressionUtil.evalNotNull(
  	    "import", "charEncoding", charEncoding_, String.class, this,
  	    pageContext);
      }
  }
  
  
  

Mime
View raw message