javax.xml.transform.Transformer.setOutputProperties()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中javax.xml.transform.Transformer.setOutputProperties()方法的一些代码示例,展示了Transformer.setOutputProperties()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transformer.setOutputProperties()方法的具体详情如下:
包路径:javax.xml.transform.Transformer
类名称:Transformer
方法名:setOutputProperties

Transformer.setOutputProperties介绍

[英]Set the output properties for the transformation. These properties will override properties set in the Templates with xsl:output.

If argument to this function is null, any properties previously set are removed, and the value will revert to the value defined in the templates object.

Pass a qualified property key name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the local name. If the name has a null URL, the String only contain the local name. An application can safely check for a non-null URI by testing to see if the first character of the name is a '{' character.

For example, if a URI and local name were obtained from an element defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that no prefix is used.
An IllegalArgumentException is thrown if any of the argument keys are not recognized and are not namespace qualified.
[中]设置转换的输出属性。这些属性将使用xsl:output覆盖模板中设置的属性。
如果此函数的参数为null,则会删除以前设置的所有属性,并且该值将恢复为templates对象中定义的值。
以两部分字符串形式传递一个限定的属性键名称,名称空间URI用大括号({})括起来,后跟本地名称。如果名称的URL为空,则字符串仅包含本地名称。应用程序可以通过测试名称的第一个字符是否为“{”字符来安全地检查非空URI。
例如,如果从使用<xyz:foo xmlns:xyz=”定义的元素中获取URI和本地名称http://xyz.foo.com/yada/baz.html“/>,则限定名为”{http://xyz.foo.com/yada/baz.html}注意,没有使用前缀。
如果任何参数键未被识别且未限定命名空间,则会抛出IllegalArgumentException

代码示例

代码示例来源:origin: apache/nifi

props.setProperty(OutputKeys.INDENT, "no");
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperties(props);

代码示例来源:origin: apache/nifi

void writeformattedItem(XdmItem item, ProcessContext context, OutputStream out)
    throws TransformerFactoryConfigurationError, TransformerException, IOException {
  if (item.isAtomicValue()) {
    out.write(item.getStringValue().getBytes(UTF8));
  } else { // item is an XdmNode
    XdmNode node = (XdmNode) item;
    switch (node.getNodeKind()) {
      case DOCUMENT:
      case ELEMENT:
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        final Properties props = getTransformerProperties(context);
        transformer.setOutputProperties(props);
        transformer.transform(node.asSource(), new StreamResult(out));
        break;
      default:
        out.write(node.getStringValue().getBytes(UTF8));
    }
  }
}

代码示例来源:origin: xalan/xalan

stylesheet.getOutputProperties();
serializer.setOutputProperties(serializationProps);

代码示例来源:origin: pentaho/pentaho-kettle

xformer.setOutputProperties( outputProperties );

代码示例来源:origin: spring-projects/spring-integration

private Transformer getNewTransformer() throws TransformerConfigurationException {
  Transformer transformer;
  synchronized (this.transformerFactory) {
    transformer = this.transformerFactory.newTransformer();
  }
  if (this.outputProperties != null) {
    transformer.setOutputProperties(this.outputProperties);
  }
  return transformer;
}

代码示例来源:origin: pentaho/pentaho-kettle

transformer.setOutputProperties( data.outputProperties );

代码示例来源:origin: spring-projects/spring-integration

transformer.setOutputProperties(this.outputProperties);

代码示例来源:origin: geotools/geotools

throw new IOException(e);
xmls.getTransformer().setOutputProperties(outputProps);
xmls.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml");
xmls.setResult(new StreamResult(out));

代码示例来源:origin: errai/errai

public XmlParserImpl(final File xmlFile, final Properties xmlProperties, final DocumentBuilder docBuilder,
    final Transformer transformer) {
 this.xmlFile = xmlFile;
 this.docBuilder = docBuilder;
 this.transformer = transformer;
 
 transformer.setOutputProperties(xmlProperties);
}

代码示例来源:origin: geotools/geotools

xmls.getTransformer().setOutputProperties(outputProps);
xmls.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml");
xmls.setResult(new StreamResult(out));

代码示例来源:origin: org.zkoss.common/zcommon

/** Set the output properties for the transformation.
 */
public final void setOutputProperties(Properties props) {
  _tfmr.setOutputProperties(props);
}

代码示例来源:origin: org.custommonkey.xmlunit/com.springsource.org.custommonkey.xmlunit

/**
 * Override output properties specified in the transformation stylesheet
 * @param outputProperties
 * @see Transformer#setOutputProperties(java.util.Properties)
 */
public void setOutputProperties(Properties outputProperties) {
  transformer.setOutputProperties(outputProperties);
}

代码示例来源:origin: org.ikasan/ikasan-filetransfer-common

/**
 * Sets the output properties for the transformation.
 *
 * @param outputProps - the set of output properties that will be used to
 *                      override any of the same properties in affect
 *                      for the transformation.
 */
public void setOutputProperties(Properties outputProps)
{
  if (outputProps == null || outputProps.isEmpty()) return;
  this.transformer.setOutputProperties(outputProps);
}

代码示例来源:origin: org.ikasan/ikasan-common

/**
 * Sets the output properties for the transformation.
 *
 * @param outputProps - the set of output properties that will be used to
 *                      override any of the same properties in affect
 *                      for the transformation.
 */
public void setOutputProperties(Properties outputProps)
{
  if (outputProps == null || outputProps.isEmpty()) return;
  this.transformer.setOutputProperties(outputProps);
}

代码示例来源:origin: apache/activemq-artemis

public void write(File output, Properties outputProperties) throws TransformerException {
 Transformer transformer = TransformerFactory.newInstance().newTransformer();
 transformer.setOutputProperties(outputProperties);
 StreamResult streamResult = new StreamResult(output);
 transformer.transform(new DOMSource(document), streamResult);
}

代码示例来源:origin: org.apache.activemq/artemis-tools

public void write(File output, Properties outputProperties) throws TransformerException {
 Transformer transformer = TransformerFactory.newInstance().newTransformer();
 transformer.setOutputProperties(outputProperties);
 StreamResult streamResult = new StreamResult(output);
 transformer.transform(new DOMSource(document), streamResult);
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public void setOutputProperties(java.util.Properties properties)
  throws java.lang.IllegalArgumentException {
  try {
    materialize();
    m_realTransformer.setOutputProperties(properties);
  } catch (TransformerException e) {
    // will be caught later
  }
}

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

public static String toString(Source source, Properties props) throws TransformerException, IOException {
  StringWriter bos = new StringWriter();
  StreamResult sr = new StreamResult(bos);
  Transformer trans = newTransformer();
  if (props == null) {
    props = new Properties();
    props.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
  }
  trans.setOutputProperties(props);
  trans.transform(source, sr);
  bos.close();
  return bos.toString();
}

代码示例来源:origin: org.apache.cxf/cxf-api

public static String toString(Source source, Properties props) throws TransformerException, IOException {
  StringWriter bos = new StringWriter();
  StreamResult sr = new StreamResult(bos);
  Transformer trans = newTransformer();
  if (props == null) {
    props = new Properties();
    props.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
  }
  trans.setOutputProperties(props);
  trans.transform(source, sr);
  bos.close();
  return bos.toString();
}

代码示例来源:origin: apache/cxf

private static String source2String(Source source) throws Exception {
    final java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
    final StreamResult sr = new StreamResult(bos);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
    Transformer transformer = transformerFactory.newTransformer();
    final java.util.Properties oprops = new java.util.Properties();
    oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
    transformer.setOutputProperties(oprops);
    transformer.transform(source, sr);
    return bos.toString();
  }
}

相关文章