本文整理了Java中javax.xml.transform.Transformer.reset()
方法的一些代码示例,展示了Transformer.reset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transformer.reset()
方法的具体详情如下:
包路径:javax.xml.transform.Transformer
类名称:Transformer
方法名:reset
[英]Reset this Transformer
to its original configuration.
Transformer
is reset to the same state as when it was created with TransformerFactory#newTransformer(), TransformerFactory#newTransformer(Source source) or Templates#newTransformer(). reset()
is designed to allow the reuse of existing Transformer
s thus saving resources associated with the creation of new Transformer
s.
The reset Transformer
is not guaranteed to have the same URIResolveror ErrorListener Object
s, e.g. Object#equals(Object obj). It is guaranteed to have a functionally equal URIResolver
and ErrorListener
.
[中]将此Transformer
重置为其原始配置。Transformer
重置为与TransformerFactory#newTransformer()、TransformerFactory#newTransformer(源)或Templates#newTransformer()创建时相同的状态。reset()
旨在允许重用现有Transformer
s,从而节省与创建新Transformer
s相关的资源。
重置Transformer
不保证具有相同的URIResolveror ErrorListenerObject
s,例如Object#equals(Object obj)。它保证有一个功能上相等的URIResolver
和ErrorListener
。
代码示例来源:origin: org.apache.tuscany.sca/tuscany-common-xml
@Override
protected void resetInstance(Transformer obj) {
obj.reset();
}
};
代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime
@Override
protected void resetInstance(Transformer obj) {
obj.reset();
}
};
代码示例来源:origin: com.ebmwebsourcing.easycommons/easycommons-util
@Override
public void onRelease(Transformer transformer) {
transformer.reset();
}
代码示例来源:origin: dsukhoroslov/bagri
@Override
public Transformer get() {
Transformer result = super.get();
result.reset();
return result;
}
};
代码示例来源:origin: apache/karaf
public static void transform(Source xmlSource, Result outputTarget) throws TransformerException {
Transformer t = transformer();
try {
t.transform(xmlSource, outputTarget);
} finally {
t.reset();
}
}
代码示例来源:origin: apache/karaf
public static void transform(Source xsltSource, Source xmlSource, Result outputTarget) throws TransformerException {
Transformer t = transformer(xsltSource);
try {
t.transform(xmlSource, outputTarget);
} finally {
t.reset();
}
}
代码示例来源:origin: org.ow2.easycommons/easycommons-util
@Override
public void onRelease(Transformer transformer) {
transformer.reset();
// See https://issues.apache.org/jira/browse/XALANJ-2605
if (transformer instanceof com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl) {
try {
ReflectionHelper.setFieldValue(com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.class,
transformer, "_properties", new Properties(), false);
} catch (final Exception e) {
// do nothing if we can't...
}
}
}
代码示例来源:origin: org.carrot2/carrot2-core
/**
* This method should be invoked to cleanup after processing is done.
*/
public final void cleanup()
{
if (this.defaultHandler != null)
{
/*
* Reset the default handler's transformer.
*/
this.defaultHandler.getTransformer().reset();
}
}
代码示例来源:origin: org.osgl/osgl-tool
public static void print(Document document, boolean pretty, OutputStream os) {
Transformer t = transformer.get();
t.setOutputProperty(OutputKeys.METHOD, "xml");
t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
if (pretty) {
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
}
try {
t.transform(new DOMSource(document), new StreamResult(os));
} catch (TransformerException e) {
throw E.unexpected(e);
} finally {
t.reset();
}
}
代码示例来源:origin: osglworks/java-tool
public static void print(Document document, boolean pretty, OutputStream os) {
Transformer t = transformer.get();
t.setOutputProperty(OutputKeys.METHOD, "xml");
t.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
if (pretty) {
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
}
try {
t.transform(new DOMSource(document), new StreamResult(os));
} catch (TransformerException e) {
throw E.unexpected(e);
} finally {
t.reset();
}
}
代码示例来源:origin: org.ow2.petals/petals-kernel
/**
* Create the String format of the given XML Source.
*
* @param source
*
* @return the String format
* @throws TransformerException
*/
private static final String createStringFromSource(final Source source)
throws TransformerException {
final StringWriter buffer = new StringWriter();
final Result sresult = new StreamResult(buffer);
final Transformer transformer = Transformers.getDefaultTransformer();
try {
transformer.transform(source, sresult);
} finally {
transformer.reset();
}
return buffer.toString();
}
代码示例来源:origin: org.ow2.petals/petals-kernel
/**
* Write a document to an output stream. The output stream and the document
* must not be null.
*
* @param document
* @param outputFile
*/
public static void writeDocument(final Document document, final OutputStream outputStream)
throws Exception {
if (document != null && outputStream != null) {
final Transformer transformer = Transformers.getXmlWithDeclarationTransformer();
try {
transformer.transform(new DOMSource(document), new StreamResult(outputStream));
} finally {
transformer.reset();
}
} else {
throw new Exception("Can not write document to output stream");
}
}
}
代码示例来源:origin: org.ow2.petals/petals-kernel
public static final void serializeContent(Source content, ObjectOutputStream outStream,
boolean compress) throws Exception {
if (content == null) {
// set a flag which indicate that the source is null
outStream.writeBoolean(false);
} else {
outStream.writeBoolean(true);
synchronized (content) {
// Compress content if specified
StreamResult sresult = null;
GZIPOutputStream gz = null;
if (compress) {
gz = new GZIPOutputStream(outStream);
sresult = new StreamResult(gz);
} else {
sresult = new StreamResult(outStream);
}
final Transformer transform = Transformers.getDefaultTransformer();
try {
transform.transform(content, sresult);
} finally {
transform.reset();
}
if (compress) {
gz.finish();
}
}
}
}
代码示例来源:origin: org.mule.modules/mule-module-xml
@Override
public void passivateObject(Object object) throws Exception
{
javax.xml.transform.Transformer transformer = (javax.xml.transform.Transformer) object;
// Clear transformation parameters before returning transformer to the pool
transformer.clearParameters();
// Clean up transformer before return it to the pool
transformer.reset();
super.passivateObject(transformer);
}
}
代码示例来源:origin: org.ow2.petals/petals-kernel
/**
* Transform an XML {@link Node} into a String
*
* @param node
* the XML {@link Node} to parse
* @return the resulting String, null if node is null
* @throws TransformerException
* if errors occured during transformation
*/
public static String parseToString(final Node node) throws TransformerException {
String result = null;
if (node != null) {
node.normalize();
final Transformer transformer = Transformers.getDefaultTransformer();
StringWriter stringWriter = new StringWriter();
try {
transformer.transform(new DOMSource(node), new StreamResult(stringWriter));
} finally {
transformer.reset();
}
StringBuffer buffer = stringWriter.getBuffer();
result = buffer.toString();
}
return result;
}
代码示例来源:origin: com.qualinsight.mojo.cobertura/qualinsight-mojo-cobertura-conversion
private void reset() {
this.coberturaToSonarqubeTransformer.clearParameters();
this.coberturaToSonarqubeTransformer.reset();
this.builder.reset();
}
}
代码示例来源:origin: org.fcrepo/fcrepo-server
transformer.reset();
代码示例来源:origin: org.ow2.petals/petals-kernel
/**
* Create a String result from a DOM Node
*
* @param node
* the DOM Node. Must not be null
* @return a String representation of the DOM Document
* @throws TransformerException
*/
public static String createStringFromDOMNode(final Node node, final boolean omitDeclaration)
throws TransformerException {
node.normalize();
Source source = new DOMSource(node);
StringWriter out = new StringWriter();
Result resultStream = new StreamResult(out);
final Transformer transformer;
if (omitDeclaration) {
transformer = Transformers.getWithoutDeclarationTransformer();
} else {
transformer = Transformers.getDefaultTransformer();
}
try {
transformer.transform(source, resultStream);
} finally {
transformer.reset();
}
return out.toString();
}
代码示例来源:origin: dragome/dragome-sdk
transformer.reset();
if (xsltParams != null)
代码示例来源:origin: dragome/dragome-sdk
transformer.reset();
if (xsltParams != null)
内容来源于网络,如有侵权,请联系作者删除!