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/standard/src/org/apache/taglibs/standard/tei ImportTEI.java XmlParseTEI.java
Date Mon, 04 Feb 2002 02:56:24 GMT
shawn       02/02/03 18:56:24

  Modified:    standard/conf c-rt.tld c.tld
  Added:       standard/conf permittedTaglibs.tld
               standard/src/javax/servlet/jsp/jstl/tlv
                        PermittedTaglibsTLV.java
               standard/src/org/apache/taglibs/standard/tag/common/core
                        ParamParent.java
               standard/src/org/apache/taglibs/standard/tei ImportTEI.java
                        XmlParseTEI.java
  Log:
  Stragglers :)
  
  Revision  Changes    Path
  1.4       +1 -0      jakarta-taglibs/standard/conf/c-rt.tld
  
  Index: c-rt.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/conf/c-rt.tld,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- c-rt.tld	4 Feb 2002 02:39:49 -0000	1.3
  +++ c-rt.tld	4 Feb 2002 02:56:24 -0000	1.4
  @@ -60,6 +60,7 @@
     <tag>
       <name>import</name>
       <tag-class>org.apache.taglibs.standard.tag.rt.core.ImportTag</tag-class>
  +    <tei-class>org.apache.taglibs.standard.tei.ImportTEI</tei-class>
       <body-content>JSP</body-content>
       <description>
           Retrieves an absolute or relative URL and exposes its contents
  
  
  
  1.4       +1 -0      jakarta-taglibs/standard/conf/c.tld
  
  Index: c.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/standard/conf/c.tld,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- c.tld	4 Feb 2002 02:39:49 -0000	1.3
  +++ c.tld	4 Feb 2002 02:56:24 -0000	1.4
  @@ -135,6 +135,7 @@
     <tag>
       <name>import</name>
       <tag-class>org.apache.taglibs.standard.tag.el.core.ImportTag</tag-class>
  +    <tei-class>org.apache.taglibs.standard.tei.ImportTEI</tei-class>
       <body-content>JSP</body-content>
       <description>
   	Retrieves an absolute or relative URL and exposes its contents
  
  
  
  1.1                  jakarta-taglibs/standard/conf/permittedTaglibs.tld
  
  Index: permittedTaglibs.tld
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1" ?>
  <!DOCTYPE taglib
          PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
          "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_2.dtd">
  <taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>permittedTaglibs</short-name>
    <uri>http://jakarta.apache.org/taglibs/standard/permittedTaglibs</uri>
    <description>
      Validates JSP pages to restrict 'taglib' directives
    </description>
  
    <validator>
      <validator-class>
  	javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV
      </validator-class>
      <init-param>
        <param-name>permittedTaglibs</param-name>
        <param-value>
  	http://java.sun.com/jstl/ea/core
  	http://java.sun.com/jstl/ea/fmt
  	http://java.sun.com/jstl/ea/sql
  	http://java.sun.com/jstl/ea/xml
        </param-value>
        <description>
          Whitespace-separated list of taglib URIs to permit.  This example
  	TLD for the Standard Taglib allows only JSTL 'el' taglibs to be
  	imported.
        </description>
      </init-param>
    </validator>
  
    <!-- Every TLD needs at least one 'tag' element.  We happily oblige. -->
  
    <tag>
      <name>noop</name>
      <tag-class>javax.servlet.jsp.tagext.TagSupport</tag-class>
      <body-content>empty</body-content>
      <description>Does nothing.</description>
    </tag>
  </taglib>
  
  
  
  1.1                  jakarta-taglibs/standard/src/javax/servlet/jsp/jstl/tlv/PermittedTaglibsTLV.java
  
  Index: PermittedTaglibsTLV.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 javax.servlet.jsp.jstl.tlv;
  
  import java.io.*;
  import java.util.*;
  import javax.servlet.jsp.*;
  import javax.servlet.jsp.tagext.*;
  import javax.xml.parsers.*;
  import org.xml.sax.*;
  import org.xml.sax.helpers.*;
  
  /**
   * <p>A TagLibraryValidator class to allow a TLD to restrict what
   * taglibs (in addition to itself) may be imported on a page where it's
   * used.</p>
   *
   * @author Shawn Bayern
   */
  public class PermittedTaglibsTLV extends TagLibraryValidator {
  
      //*********************************************************************
      // Constants
  
      // parameter names
      private final String PERMITTED_TAGLIBS_PARAM = "permittedTaglibs";
  
      // URI for "<jsp:root>" element
      private final String JSP_ROOT_URI = "http://java.sun.com/JSP/Page";
  
      // local name of "<jsp:root>" element
      private final String JSP_ROOT_NAME = "root";
  
      // QName for "<jsp:root>" element
      private final String JSP_ROOT_QN = "jsp:root";
  
  
      //*********************************************************************
      // Validation and configuration state (protected)
  
      private Set permittedTaglibs;		// what URIs are allowed?
      private boolean failed;			// did the page fail?
      private String uri;				// our taglib's URI
  
      //*********************************************************************
      // Constructor and lifecycle management
  
      public PermittedTaglibsTLV() {
  	super();
  	init();
      }
  
      private void init() {
  	permittedTaglibs = null;
      }
  
      public void release() {
  	super.release();
  	init();
      }
      
  
      //*********************************************************************
      // Validation entry point
  
      public synchronized ValidationMessage[] validate(
  	    String prefix, String uri, PageData page) {
  	try {
  
  	    // initialize
  	    this.uri = uri;
  	    permittedTaglibs = readConfiguration();
  
  	    // get a handler
  	    DefaultHandler h = new PermittedTaglibsHandler();
  
  	    // parse the page
  	    SAXParserFactory f = SAXParserFactory.newInstance();
  	    f.setValidating(true);
  	    SAXParser p = f.newSAXParser();
  	    p.parse(page.getInputStream(), h);
  
  	    if (failed)
  		return vmFromString(
  		    "taglib " + prefix + " (" + uri + ") allows only the "
  		    + "following taglibs to be imported: " + permittedTaglibs);
  	    else
  		return null;
  
  	} catch (SAXException ex) {
  	    return vmFromString(ex.toString());
  	} catch (ParserConfigurationException ex) {
  	    return vmFromString(ex.toString());
  	} catch (IOException ex) {
  	    return vmFromString(ex.toString());
  	}
      }
  
  
      //*********************************************************************
      // Utility functions
  
      /** Returns Set of permitted taglibs, based on configuration data. */
      private Set readConfiguration() {
  
  	// initialize the Set
  	Set s = new HashSet();
  
  	// get the space-separated list of taglibs
  	String uris = (String) getInitParameters().get(PERMITTED_TAGLIBS_PARAM);
  
          // separate the list into individual uris and store them
          StringTokenizer st = new StringTokenizer(uris);
          while (st.hasMoreTokens())
  	    s.add(st.nextToken());
  
  	// return the new Set
  	return s;
  
      }
  
      // constructs a ValidationMessage[] from a single String and no ID
      private ValidationMessage[] vmFromString(String message) {
  	return new ValidationMessage[] {
  	    new ValidationMessage(null, message)
  	};
      }
  
  
      //*********************************************************************
      // SAX handler
  
      /** The handler that provides the base of our implementation. */
      private class PermittedTaglibsHandler extends DefaultHandler {
  
          // if the element is <jsp:root>, check its "xmlns:" attributes
          public void startElement(
                  String ns, String ln, String qn, Attributes a) {
  
  	    // ignore all but <jsp:root>
  	    if (!qn.equals(JSP_ROOT_QN) &&
  	            (!ns.equals(JSP_ROOT_URI) || !ln.equals(JSP_ROOT_NAME)))
  		return;
  
  	    // for <jsp:root>, check the attributes
  	    for (int i = 0; i < a.getLength(); i++) {
  		String name = a.getQName(i);
  
  		// ignore non-namespace attributes, and xmlns:jsp
  		if (!name.startsWith("xmlns:") || name.equals("xmlns:jsp"))
  		    continue;
  
  		String value = a.getValue(i);
  		// ignore our own namespace declaration
  		if (value.equals(uri))
  		    continue;
  
  		// otherwise, ensure that 'value' is in 'permittedTaglibs' set
  		if (!permittedTaglibs.contains(value))
  		    failed = true;
  	    }
  	}
      }
  
  }
  
  
  
  1.1                  jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/core/ParamParent.java
  
  Index: ParamParent.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.standard.tag.common.core;
  
  /**
   * <p>Interface for tag handlers implementing valid parent tags for
   * &lt;c:param&gt;.</p>
   *
   * @author Shawn Bayern
   */
  
  public interface ParamParent {
  
      /**
       * 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.
       *
       * @see ParamSupport
       */
      void addParameter(String name, String value);
  
  }
  
  
  
  1.1                  jakarta-taglibs/standard/src/org/apache/taglibs/standard/tei/ImportTEI.java
  
  Index: ImportTEI.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.standard.tei;
  
  import javax.servlet.jsp.tagext.*;
  
  /**
   * <p>An implementation of TagExtraInfo that implements validation for
   * &lt;c:import&gt;'s attributes</p>
   *
   * @author Shawn Bayern
   */
  public class ImportTEI extends TagExtraInfo {
  
      final private static String VAR = "var";
      final private static String VAR_READER = "varReader";
  
      public boolean isValid(TagData us) {
  	// don't allow both VAR and VAR_READER, together
  	if (Util.isSpecified(us, VAR) && Util.isSpecified(us, VAR_READER))
  	    return false;
  
          return true;
      }
  
  }
  
  
  
  1.1                  jakarta-taglibs/standard/src/org/apache/taglibs/standard/tei/XmlParseTEI.java
  
  Index: XmlParseTEI.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.standard.tei;
  
  import javax.servlet.jsp.tagext.*;
  
  /**
   * <p>An implementation of TagExtraInfo that implements validation for
   * <x:parse>'s attributes</p>
   *
   * @author Shawn Bayern
   */
  public class XmlParseTEI extends TagExtraInfo {
  
      final private static String XML_TEXT = "xmlText";
      final private static String XML_URL = "xmlUrl";
      final private static String VAR = "var";
      final private static String VAR_DOM = "varDom";
      final private static String SCOPE = "scope";
      final private static String SCOPE_DOM = "scopeDom";
  
      public boolean isValid(TagData us) {
  	// must have no more than one of XML_TEXT and XML_URL ...
  	if (Util.isSpecified(us, XML_TEXT) && Util.isSpecified(us, XML_URL))
  	    return false;
  
  	// must have no more than one of VAR and VAR_DOM ...
  	if (Util.isSpecified(us, VAR) && Util.isSpecified(us, VAR_DOM))
  	    return false;
  
  	// ... and must have no less than one of VAR and VAR_DOM
  	if (!(Util.isSpecified(us, VAR) || Util.isSpecified(us, VAR_DOM)))
  	    return false;
  
  	// When either 'scope' is specified, its 'var' must be specified
  	if (Util.isSpecified(us, SCOPE) && !Util.isSpecified(us, VAR))
  	    return false;
  	if (Util.isSpecified(us, SCOPE_DOM) && !Util.isSpecified(us, VAR_DOM))
  	    return false;
  
          return true;
      }
  
  }
  
  
  

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


Mime
View raw message