1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 1999 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. *
  54. */
  55. package javax.servlet.jsp.tagext;
  56. import java.util.Map;
  57. /**
  58. * Translation-time validator class for a JSP page.
  59. * A validator operates on the XML document associated with the JSP page.
  60. *
  61. * <p>
  62. * The TLD file associates a TagLibraryValidator class and some init
  63. * arguments with a tag library.
  64. *
  65. * <p>
  66. * The JSP container is reponsible for locating an appropriate
  67. * instance of the appropriate subclass by
  68. *
  69. * <ul>
  70. * <li> new a fresh instance, or reuse an available one
  71. * <li> invoke the setInitParams(Map) method on the instance
  72. * </ul>
  73. *
  74. * once initialized, the validate(String, String, PageData) method will
  75. * be invoked, where the first two arguments are the prefix
  76. * and uri arguments used in the taglib directive.
  77. *
  78. * <p>
  79. * A TagLibraryValidator instance
  80. * may create auxiliary objects internally to perform
  81. * the validation (e.g. an XSchema validator) and may reuse it for all
  82. * the pages in a given translation run.
  83. *
  84. * <p>
  85. * The JSP container is not guaranteed to serialize invocations of
  86. * validate() method, and TagLibraryValidators should perform any
  87. * synchronization they may require.
  88. *
  89. * <p>
  90. * A JSP container may optionally support a jsp:id attribute to
  91. * provide higher quality validation errors.
  92. * When supported, the container will track the JSP pages
  93. * as passed to the container, and will assign to each element
  94. * a unique "id", which is passed as the value of the jsp:id
  95. * attribute. Each XML element in the XML view available will
  96. * be extended with this attribute. The TagLibraryValidator
  97. * can then use the attribute in one or more ValidationMessage
  98. * objects. The container then, in turn, can use these
  99. * values to provide more precise information on the location
  100. * of an error.
  101. */
  102. abstract public class TagLibraryValidator {
  103. /**
  104. * Set the init data in the TLD for this validator.
  105. * Parameter names are keys, and parameter values are the values.
  106. *
  107. * @param initMap A Map describing the init parameters
  108. */
  109. public void setInitParameters(Map map) {
  110. initParameters = map;
  111. }
  112. /**
  113. * Get the init parameters data as an immutable Map.
  114. * Parameter names are keys, and parameter values are the values.
  115. *
  116. * @return The init parameters as an immutable map.
  117. */
  118. public Map getInitParameters() {
  119. return initParameters;
  120. }
  121. /**
  122. * Validate a JSP page.
  123. * This will get invoked once per directive in the JSP page.
  124. * This method will return null if the page is valid; otherwise
  125. * the method should return an array of ValidationMessage objects.
  126. * An array of length zero is also interpreted as no errors.
  127. *
  128. * @param prefix the value of the prefix argument in the directive
  129. * @param uri the value of the uri argument in the directive
  130. * @param thePage the JspData page object
  131. * @return A null object, or zero length array if no errors, an array
  132. * of ValidationMessages otherwise.
  133. */
  134. public ValidationMessage[] validate(String prefix, String uri, PageData page) {
  135. return null;
  136. }
  137. /**
  138. * Release any data kept by this instance for validation purposes
  139. */
  140. public void release() {
  141. initParameters = null;
  142. };
  143. // Private data
  144. private Map initParameters;
  145. }