public abstract class TransformerFactory
extends Object
| java.lang.Object | |
| javax.xml.transform.TransformerFactory | |
| |
TransformerFactory实例可用于创建 Transformer和 Templates对象。
确定要创建哪个Factory实现的系统属性被命名为"javax.xml.transform.TransformerFactory" 。 该属性命名TransformerFactory抽象类的具体子类。 如果该属性未定义,则使用平台默认值。
Protected constructors |
|
|---|---|
TransformerFactory() 默认的构造函数是有意保护的。 |
|
公共方法(Public methods) |
|
|---|---|
abstract Source |
getAssociatedStylesheet(Source source, String media, String title, String charset) 通过符合给定条件的 xml-stylesheet processing instruction获取与XML |
abstract Object |
getAttribute(String name) 允许用户检索底层实现的特定属性。 |
abstract ErrorListener |
getErrorListener() 获取TransformerFactory的错误事件处理程序。 |
abstract boolean |
getFeature(String name) 查找功能的值。 |
abstract URIResolver |
getURIResolver() 获取转换过程中默认使用的对象,以解析document(),xsl:import或xsl:include中使用的URI。 |
static TransformerFactory |
newInstance(String factoryClassName, ClassLoader classLoader) 返回 |
static TransformerFactory |
newInstance() 返回Android的实现 |
abstract Templates |
newTemplates(Source source) 将源处理为模板对象,该对象是源的编译表示。 |
abstract Transformer |
newTransformer(Source source) 将 |
abstract Transformer |
newTransformer() 创建一个新的 |
abstract void |
setAttribute(String name, Object value) 允许用户在底层实现上设置特定的属性。 |
abstract void |
setErrorListener(ErrorListener listener) 为TransformerFactory设置错误事件侦听器,该事件侦听器用于处理转换指令,而不是转换本身。 |
abstract void |
setFeature(String name, boolean value) 设置此工厂创建的 |
abstract void |
setURIResolver(URIResolver resolver) 设置转换过程中默认使用的对象,以解析document(),xsl:import或xsl:include中使用的URI。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
Source getAssociatedStylesheet (Source source, String media, String title, String charset)
通过符合给定条件的xml-stylesheet processing instruction获取与XML Source文档相关联的样式表规范。 请注意,可以返回多个样式表,在这种情况下,它们就像在单个样式表中的进口或级联列表一样应用。
| 参数(Parameters) | |
|---|---|
source |
Source: The XML source document. |
media |
String: The media attribute to be matched. May be null, in which case the preferred templates will be used (i.e. alternate = no). |
title |
String: The value of the title attribute to match. May be null. |
charset |
String: The value of the charset attribute to match. May be null. |
| 返回(Returns) | |
|---|---|
Source |
A Source Object suitable for passing to the TransformerFactory. |
| 抛出异常(Throws) | |
|---|---|
TransformerConfigurationException |
An 异常 is thrown if an error occurs during parsing of the source. |
Object getAttribute (String name)
允许用户检索底层实现的特定属性。 如果底层实现无法识别该属性,则会引发IllegalArgumentException 。
| 参数(Parameters) | |
|---|---|
name |
String: The name of the attribute. |
| 返回(Returns) | |
|---|---|
Object |
value The value of the attribute. |
ErrorListener getErrorListener ()
获取TransformerFactory的错误事件处理程序。
| 返回(Returns) | |
|---|---|
ErrorListener |
The current error handler, which should never be null. |
boolean getFeature (String name)
查找功能的值。
功能名称完全限定为URI s。 实现可以定义它们自己的特征。 false返回如果TransformerFactory或者Transformer S或Template的IT创建不支持该功能。 TransformerFactory可能公开某个特征值,但无法更改其状态。
| 参数(Parameters) | |
|---|---|
name |
String: Feature name. |
| 返回(Returns) | |
|---|---|
boolean |
The current state of the feature, true or false. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
If the name parameter is null. |
URIResolver getURIResolver ()
获取转换过程中默认使用的对象,以解析document(),xsl:import或xsl:include中使用的URI。
| 返回(Returns) | |
|---|---|
URIResolver |
The URIResolver that was set with setURIResolver. |
TransformerFactory newInstance (String factoryClassName, ClassLoader classLoader)
返回 TransformerFactory的指定实现的 TransformerFactory 。
| 参数(Parameters) | |
|---|---|
factoryClassName |
String
|
classLoader |
ClassLoader
|
| 返回(Returns) | |
|---|---|
TransformerFactory |
|
| 抛出异常(Throws) | |
|---|---|
TransformerFactoryConfigurationError |
if factoryClassName is not available or cannot be instantiated. |
TransformerFactory newInstance ()
返回Android的实现TransformerFactory 。 与其他Java实现不同,此方法不涉及系统属性,属性文件或服务API。
| 返回(Returns) | |
|---|---|
TransformerFactory |
|
| 抛出异常(Throws) | |
|---|---|
TransformerFactoryConfigurationError |
never. Included for API compatibility with other Java implementations. |
Templates newTemplates (Source source)
将源处理为模板对象,该对象是源的编译表示。 这个模板对象可以在多个线程中同时使用。 创建模板对象允许TransformerFactory对转换指令进行详细的性能优化,而不会影响运行时转换。
| 参数(Parameters) | |
|---|---|
source |
Source: An object that holds a URL, input stream, etc. |
| 返回(Returns) | |
|---|---|
Templates |
A Templates object capable of being used for transformation purposes, never null. |
| 抛出异常(Throws) | |
|---|---|
TransformerConfigurationException |
May throw this during the parse when it is constructing the Templates object and fails. |
Transformer newTransformer (Source source)
将Source为Transformer Object 。 Source是符合XSL Transformations (XSLT) Version 1.0的XSLT文档。 必须小心不要在同时运行的多个Thread使用此Transformer 。 不同的TransformerFactories可以由不同的Thread同时使用。
| 参数(Parameters) | |
|---|---|
source |
Source: Source of XSLT document used to create Transformer. Examples of XML Sources include StreamSource, SAXSource and DOMSource. |
| 返回(Returns) | |
|---|---|
Transformer |
A Transformer object that may be used to perform a transformation in a single Thread, never null. |
| 抛出异常(Throws) | |
|---|---|
TransformerConfigurationException |
Thrown if there are errors when parsing the Source or it is not possible to create a Transformer instance. |
Transformer newTransformer ()
创建一个新的Transformer ,执行Source到Result 。 即“ 身份转换 ”。
| 返回(Returns) | |
|---|---|
Transformer |
A Transformer object that may be used to perform a transformation in a single thread, never null. |
| 抛出异常(Throws) | |
|---|---|
TransformerConfigurationException |
Thrown if it is not possible to create a Transformer instance. |
void setAttribute (String name, Object value)
允许用户在底层实现上设置特定的属性。 此上下文中的属性被定义为实现提供的选项。 如果底层实现无法识别该属性,则会引发IllegalArgumentException 。
| 参数(Parameters) | |
|---|---|
name |
String: The name of the attribute. |
value |
Object: The value of the attribute. |
void setErrorListener (ErrorListener listener)
为TransformerFactory设置错误事件侦听器,该事件侦听器用于处理转换指令,而不是转换本身。 一个IllegalArgumentException如果抛出ErrorListener监听器是null 。
| 参数(Parameters) | |
|---|---|
listener |
ErrorListener: The new error listener. |
void setFeature (String name, boolean value)
为此工厂创建的 TransformerFactory和 Transformer或 Template设置功能。
功能名称完全限定URI s。 实现可以定义它们自己的特征。 一个TransformerConfigurationException如果这是抛出TransformerFactory或者Transformer S或Template的IT创建不支持该功能。 TransformerFactory可能公开某个特征值,但无法更改其状态。
所有实现都需要支持FEATURE_SECURE_PROCESSING功能。 当功能是:
true: the implementation will limit XML processing to conform to implementation limits and behave in a secure fashion as defined by the implementation. Examples include resolving user defined style sheets and functions. If XML processing is limited for security reasons, it will be reported via a call to the registered fatalError(TransformerException). See setErrorListener(ErrorListener). false: the implementation will processing XML according to the XML specifications without regard to possible implementation limits. | 参数(Parameters) | |
|---|---|
name |
String: Feature name. |
value |
boolean: Is feature state true or false. |
| 抛出异常(Throws) | |
|---|---|
TransformerConfigurationException |
if this TransformerFactory or the Transformers or Templates it creates cannot support this feature. |
NullPointerException |
If the name parameter is null. |
void setURIResolver (URIResolver resolver)
设置转换过程中默认使用的对象,以解析document(),xsl:import或xsl:include中使用的URI。
| 参数(Parameters) | |
|---|---|
resolver |
URIResolver: An object that implements the URIResolver interface, or null. |