Save This Page
Home » glassfish-v2ur2-b04-src » javax » servlet » jsp » tagext » [javadoc | source]
    1   /*
    2    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    3    * 
    4    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    5    * 
    6    * Portions Copyright Apache Software Foundation.
    7    * 
    8    * The contents of this file are subject to the terms of either the GNU
    9    * General Public License Version 2 only ("GPL") or the Common Development
   10    * and Distribution License("CDDL") (collectively, the "License").  You
   11    * may not use this file except in compliance with the License. You can obtain
   12    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   13    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   14    * language governing permissions and limitations under the License.
   15    * 
   16    * When distributing the software, include this License Header Notice in each
   17    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   18    * Sun designates this particular file as subject to the "Classpath" exception
   19    * as provided by Sun in the GPL Version 2 section of the License file that
   20    * accompanied this code.  If applicable, add the following below the License
   21    * Header, with the fields enclosed by brackets [] replaced by your own
   22    * identifying information: "Portions Copyrighted [year]
   23    * [name of copyright owner]"
   24    * 
   25    * Contributor(s):
   26    * 
   27    * If you wish your version of this file to be governed by only the CDDL or
   28    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   29    * elects to include this software in this distribution under the [CDDL or GPL
   30    * Version 2] license."  If you don't indicate a single choice of license, a
   31    * recipient has the option to distribute your version of this file under
   32    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   33    * its licensees as provided above.  However, if you add GPL Version 2 code
   34    * and therefore, elected the GPL Version 2 license, then the option applies
   35    * only if the new code is made subject to such option by the copyright
   36    * holder.
   37    */
   38   
   39   package javax.servlet.jsp.tagext;
   40   
   41   import java.util.Map;
   42   
   43   /**
   44    * Translation-time validator class for a JSP page. 
   45    * A validator operates on the XML view associated with the JSP page.
   46    *
   47    * <p>
   48    * The TLD file associates a TagLibraryValidator class and some init
   49    * arguments with a tag library.
   50    *
   51    * <p>
   52    * The JSP container is reponsible for locating an appropriate
   53    * instance of the appropriate subclass by
   54    *
   55    * <ul>
   56    * <li> new a fresh instance, or reuse an available one
   57    * <li> invoke the setInitParams(Map) method on the instance
   58    * </ul>
   59    *
   60    * once initialized, the validate(String, String, PageData) method will
   61    * be invoked, where the first two arguments are the prefix
   62    * and uri for this tag library in the XML View.  The prefix is intended
   63    * to make it easier to produce an error message.  However, it is not
   64    * always accurate.  In the case where a single URI is mapped to more 
   65    * than one prefix in the XML view, the prefix of the first URI is provided.
   66    * Therefore, to provide high quality error messages in cases where the 
   67    * tag elements themselves are checked, the prefix parameter should be 
   68    * ignored and the actual prefix of the element should be used instead.  
   69    * TagLibraryValidators should always use the uri to identify elements 
   70    * as beloning to the tag library, not the prefix.
   71    *
   72    * <p>
   73    * A TagLibraryValidator instance
   74    * may create auxiliary objects internally to perform
   75    * the validation (e.g. an XSchema validator) and may reuse it for all
   76    * the pages in a given translation run.
   77    *
   78    * <p>
   79    * The JSP container is not guaranteed to serialize invocations of
   80    * validate() method, and TagLibraryValidators should perform any
   81    * synchronization they may require.
   82    *
   83    * <p>
   84    * As of JSP 2.0, a JSP container must provide a jsp:id attribute to
   85    * provide higher quality validation errors.
   86    * The container will track the JSP pages
   87    * as passed to the container, and will assign to each element
   88    * a unique "id", which is passed as the value of the jsp:id
   89    * attribute.  Each XML element in the XML view available will
   90    * be extended with this attribute.  The TagLibraryValidator
   91    * can then use the attribute in one or more ValidationMessage
   92    * objects.  The container then, in turn, can use these
   93    * values to provide more precise information on the location
   94    * of an error.
   95    *
   96    * <p>
   97    * The actual prefix of the <code>id</code> attribute may or may not be 
   98    * <code>jsp</code> but it will always map to the namespace
   99    * <code>http://java.sun.com/JSP/Page</code>.  A TagLibraryValidator
  100    * implementation must rely on the uri, not the prefix, of the <code>id</code>
  101    * attribute.
  102    */
  103   
  104   abstract public class TagLibraryValidator {
  105   
  106       /**
  107        * Sole constructor. (For invocation by subclass constructors, 
  108        * typically implicit.)
  109        */
  110       public TagLibraryValidator() {
  111       }
  112       
  113       /**
  114        * Set the init data in the TLD for this validator.
  115        * Parameter names are keys, and parameter values are the values.
  116        *
  117        * @param map A Map describing the init parameters
  118        */
  119       public void setInitParameters(Map map) {
  120   	initParameters = map;
  121       }
  122   
  123   
  124       /**
  125        * Get the init parameters data as an immutable Map.
  126        * Parameter names are keys, and parameter values are the values.
  127        *
  128        * @return The init parameters as an immutable map.
  129        */
  130       public Map getInitParameters() {
  131   	return initParameters;
  132       }
  133   
  134       /**
  135        * Validate a JSP page.
  136        * This will get invoked once per unique tag library URI in the
  137        * XML view.  This method will return null if the page is valid; otherwise
  138        * the method should return an array of ValidationMessage objects.
  139        * An array of length zero is also interpreted as no errors.
  140        *
  141        * @param prefix the first prefix with which the tag library is 
  142        *     associated, in the XML view.  Note that some tags may use 
  143        *     a different prefix if the namespace is redefined.
  144        * @param uri the tag library's unique identifier
  145        * @param page the JspData page object
  146        * @return A null object, or zero length array if no errors, an array
  147        * of ValidationMessages otherwise.
  148        */
  149       public ValidationMessage[] validate(String prefix, String uri, 
  150           PageData page) 
  151       {
  152   	return null;
  153       }
  154   
  155       /**
  156        * Release any data kept by this instance for validation purposes.
  157        */
  158       public void release() {
  159   	initParameters = null;
  160       }
  161   
  162       // Private data
  163       private Map initParameters;
  164   
  165   }

Save This Page
Home » glassfish-v2ur2-b04-src » javax » servlet » jsp » tagext » [javadoc | source]