TagLibraryValidator (Java EE 5)

Java EE API


javax.servlet.jsp.tagext Class TagLibraryValidator

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagLibraryValidator

public abstract class TagLibraryValidator
extends Object


JSP 页面的转换期间验证器类。验证器在与 JSP 页面关联的 XML 视图上进行操作。

TLD 文件将 TagLibraryValidator 类和一些 init 参数与标记库相关联。

JSP 容器负责定位适当子类的适当实例,方法是

  • 新建一个新的实例,或者重用可用的实例
  • 对实例调用 setInitParams(Map) 方法
一旦完成初始化,则将调用 validate(String, String, PageData) 方法,其中前两个参数是 XML 视图中此标记库的前缀和 uri。前缀用于使生成错误消息变得更容易。不过,它并不总是很准确。在单个 URI 被映射到 XML 视图中的多个前缀的情况下,提供第一个 URI 的前缀。因此,要在检查标记元素自身的情况下提供高质量的错误消息,就应该忽略前缀参数,而使用元素的实际前缀。TagLibraryValidator 应该总是使用 uri 来标识属于标记库的元素,而不是使用前缀来标识。

TagLibraryValidator 实例可以内部创建辅助对象来执行验证(例如,XSchema 验证器),并且可将该对象重用于给定转换运行中的所有页面。

JSP 容器不保证会序列化 validate() 方法的调用,并且 TagLibraryValidator 应该执行它们可能需要的任何同步。

从 JSP 2.0 起,JSP 容器必须提供 jsp:id 属性,以提供更高质量的验证错误。容器将跟踪传递给容器的 JSP 页面,将给每个元素分配唯一的 "id",该 id 作为 jsp:id 属性的值传递。XML 视图中每个可用的 XML 元素都将使用此属性扩展。然后,TagLibraryValidator 可以在一个或多个 ValidationMessage 对象中使用该属性。然后,容器可以依次使用这些值提供有关错误位置的更准确信息。

id 属性的实际前缀不一定是 jsp,但它总是映射到名称空间 http://java.sun.com/JSP/Page。TagLibraryValidator 实现必须依赖 id 属性的 uri 而不是前缀。

英文文档:

Translation-time validator class for a JSP page. A validator operates on the XML view associated with the JSP page.

The TLD file associates a TagLibraryValidator class and some init arguments with a tag library.

The JSP container is reponsible for locating an appropriate instance of the appropriate subclass by

  • new a fresh instance, or reuse an available one
  • invoke the setInitParams(Map) method on the instance
once initialized, the validate(String, String, PageData) method will be invoked, where the first two arguments are the prefix and uri for this tag library in the XML View. The prefix is intended to make it easier to produce an error message. However, it is not always accurate. In the case where a single URI is mapped to more than one prefix in the XML view, the prefix of the first URI is provided. Therefore, to provide high quality error messages in cases where the tag elements themselves are checked, the prefix parameter should be ignored and the actual prefix of the element should be used instead. TagLibraryValidators should always use the uri to identify elements as beloning to the tag library, not the prefix.

A TagLibraryValidator instance may create auxiliary objects internally to perform the validation (e.g. an XSchema validator) and may reuse it for all the pages in a given translation run.

The JSP container is not guaranteed to serialize invocations of validate() method, and TagLibraryValidators should perform any synchronization they may require.

As of JSP 2.0, a JSP container must provide a jsp:id attribute to provide higher quality validation errors. The container will track the JSP pages as passed to the container, and will assign to each element a unique "id", which is passed as the value of the jsp:id attribute. Each XML element in the XML view available will be extended with this attribute. The TagLibraryValidator can then use the attribute in one or more ValidationMessage objects. The container then, in turn, can use these values to provide more precise information on the location of an error.

The actual prefix of the id attribute may or may not be jsp but it will always map to the namespace http://java.sun.com/JSP/Page. A TagLibraryValidator implementation must rely on the uri, not the prefix, of the id attribute.


Constructor Summary
 
Method Summary
 Map<String,Object>
 void
 void
 ValidationMessage[]
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public TagLibraryValidator()
唯一的构造方法。(由子类构造方法调用,通常是隐式的)。
英文文档:

TagLibraryValidator

public TagLibraryValidator()
Sole constructor. (For invocation by subclass constructors, typically implicit.)

Method Detail

public void setInitParameters(java.util.Map<K, V> map)
设置此验证器的 TLD 中的 init 数据。参数名称是键,参数值是值。
map 描述 init 参数的 Map
英文文档:

setInitParameters

public void setInitParameters(Map<String,Object> map)
Set the init data in the TLD for this validator. Parameter names are keys, and parameter values are the values.

Parameters:
map - A Map describing the init parameters

public java.util.Map<K, V> getInitParameters()
获取不可变 Map 形式的 init 参数数据。参数名称是键,参数值是值。
return 不可变映射形式的 init 参数。
英文文档:

getInitParameters

public Map<String,Object> getInitParameters()
Get the init parameters data as an immutable Map. Parameter names are keys, and parameter values are the values.

Returns:
The init parameters as an immutable map.

public ValidationMessage[] validate(String prefix, String uri, PageData page)
验证 JSP 页面。此方法将对 XML 视图中的每个唯一标记库 URI 调用一次。如果页面有效,则此方法将返回 null;否则该方法应该返回 ValidationMessage 对象的数组。长度为 0 的数组也将被解释为没有错误。
prefix XML 视图中与标记库关联的第一个前缀。注意,如果重新定义名称空间,那么某些标记可能使用不同的前缀。
uri 标记库的唯一标识符
page JspData 页面对象
return 如果没有错误,则返回一个 null 对象,或长度为 0 的数组,否则返回 ValidationMessage 的数组。
英文文档:

validate

public ValidationMessage[] validate(String prefix,
                                    String uri,
                                    PageData page)
Validate a JSP page. This will get invoked once per unique tag library URI in the XML view. This method will return null if the page is valid; otherwise the method should return an array of ValidationMessage objects. An array of length zero is also interpreted as no errors.

Parameters:
prefix - the first prefix with which the tag library is associated, in the XML view. Note that some tags may use a different prefix if the namespace is redefined.
uri - the tag library's unique identifier
page - the JspData page object
Returns:
A null object, or zero length array if no errors, an array of ValidationMessages otherwise.

public void release()
释放此实例为了进行验证保存的所有数据。
英文文档:

release

public void release()
Release any data kept by this instance for validation purposes.



Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!