Most visited

Recently visited

Added in API level 8

TransformerFactory

public abstract class TransformerFactory
extends Object

java.lang.Object
   ↳ javax.xml.transform.TransformerFactory
Known Direct Subclasses


TransformerFactory实例可用于创建 TransformerTemplates对象。

确定要创建哪个Factory实现的系统属性被命名为"javax.xml.transform.TransformerFactory" 该属性命名TransformerFactory抽象类的具体子类。 如果该属性未定义,则使用平台默认值。

Summary

Protected constructors

TransformerFactory()

默认的构造函数是有意保护的。

Public methods

abstract Source getAssociatedStylesheet(Source source, String media, String title, String charset)

通过符合给定条件的 xml-stylesheet processing instruction获取与XML Source文档关联的样式表规范。

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)

返回 TransformerFactory的命名实现的 TransformerFactory

static TransformerFactory newInstance()

返回Android的实现 TransformerFactory

abstract Templates newTemplates(Source source)

将源处理为模板对象,该对象是源的编译表示。

abstract Transformer newTransformer(Source source)

SourceTransformer Object

abstract Transformer newTransformer()

创建一个新的 Transformer ,将 Source的副本执行到 Result

abstract void setAttribute(String name, Object value)

允许用户在底层实现上设置特定的属性。

abstract void setErrorListener(ErrorListener listener)

为TransformerFactory设置错误事件侦听器,该事件侦听器用于处理转换指令,而不是转换本身。

abstract void setFeature(String name, boolean value)

设置此工厂创建的 TransformerFactoryTransformerTemplate的功能。

abstract void setURIResolver(URIResolver resolver)

设置转换过程中默认使用的对象,以解析document(),xsl:import或xsl:include中使用的URI。

Inherited methods

From class java.lang.Object

Protected constructors

TransformerFactory

Added in API level 8
TransformerFactory ()

默认的构造函数是有意保护的。

Public methods

getAssociatedStylesheet

Added in API level 8
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.

也可以看看:

getAttribute

Added in API level 8
Object getAttribute (String name)

允许用户检索底层实现的特定属性。 如果底层实现无法识别该属性,则会引发IllegalArgumentException

Parameters
name String: The name of the attribute.
Returns
Object value The value of the attribute.

getErrorListener

Added in API level 8
ErrorListener getErrorListener ()

获取TransformerFactory的错误事件处理程序。

Returns
ErrorListener The current error handler, which should never be null.

getFeature

Added in API level 8
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.

getURIResolver

Added in API level 8
URIResolver getURIResolver ()

获取转换过程中默认使用的对象,以解析document(),xsl:import或xsl:include中使用的URI。

Returns
URIResolver The URIResolver that was set with setURIResolver.

newInstance

Added in API level 9
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.

newInstance

Added in API level 8
TransformerFactory newInstance ()

返回Android的实现TransformerFactory 与其他Java实现不同,此方法不涉及系统属性,属性文件或服务API。

Returns
TransformerFactory
Throws
TransformerFactoryConfigurationError never. Included for API compatibility with other Java implementations.

newTemplates

Added in API level 8
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.

newTransformer

Added in API level 8
Transformer newTransformer (Source source)

SourceTransformer 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.

也可以看看:

newTransformer

Added in API level 8
Transformer newTransformer ()

创建一个新的Transformer ,执行SourceResult 即“ 身份转换 ”。

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.

setAttribute

Added in API level 8
void setAttribute (String name, 
                Object value)

允许用户在底层实现上设置特定的属性。 此上下文中的属性被定义为实现提供的选项。 如果底层实现无法识别该属性,则会引发IllegalArgumentException

Parameters
name String: The name of the attribute.
value Object: The value of the attribute.

setErrorListener

Added in API level 8
void setErrorListener (ErrorListener listener)

为TransformerFactory设置错误事件侦听器,该事件侦听器用于处理转换指令,而不是转换本身。 一个IllegalArgumentException如果抛出ErrorListener监听器是null

Parameters
listener ErrorListener: The new error listener.

setFeature

Added in API level 8
void setFeature (String name, 
                boolean value)

为此工厂创建的 TransformerFactoryTransformerTemplate设置功能。

功能名称完全限定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.

setURIResolver

Added in API level 8
void setURIResolver (URIResolver resolver)

设置转换过程中默认使用的对象,以解析document(),xsl:import或xsl:include中使用的URI。

Parameters
resolver URIResolver: An object that implements the URIResolver interface, or null.

Hooray!