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

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

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

Transformer.getOutputProperty介绍

[英]Get an output property that is in effect for the transformer. The property specified may be a property that was set with setOutputProperty, or it may be a property specified in the stylesheet.
[中]获取对转换器有效的输出属性。指定的属性可能是使用setOutputProperty设置的属性,也可能是样式表中指定的属性。

代码示例

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

/**
 * Configure the supplied {@link HttpServletResponse}.
 * <p>The default implementation of this method sets the
 * {@link HttpServletResponse#setContentType content type} and
 * {@link HttpServletResponse#setCharacterEncoding encoding}
 * from the "media-type" and "encoding" output properties
 * specified in the {@link Transformer}.
 * @param model merged output Map (never {@code null})
 * @param response current HTTP response
 * @param transformer the target transformer
 */
protected void configureResponse(Map<String, Object> model, HttpServletResponse response, Transformer transformer) {
  String contentType = getContentType();
  String mediaType = transformer.getOutputProperty(OutputKeys.MEDIA_TYPE);
  String encoding = transformer.getOutputProperty(OutputKeys.ENCODING);
  if (StringUtils.hasText(mediaType)) {
    contentType = mediaType;
  }
  if (StringUtils.hasText(encoding)) {
    // Only apply encoding if content type is specified but does not contain charset clause already.
    if (contentType != null && !contentType.toLowerCase().contains(WebUtils.CONTENT_TYPE_CHARSET_PREFIX)) {
      contentType = contentType + WebUtils.CONTENT_TYPE_CHARSET_PREFIX + encoding;
    }
  }
  response.setContentType(contentType);
}

代码示例来源:origin: org.springframework/spring-webmvc

/**
 * Configure the supplied {@link HttpServletResponse}.
 * <p>The default implementation of this method sets the
 * {@link HttpServletResponse#setContentType content type} and
 * {@link HttpServletResponse#setCharacterEncoding encoding}
 * from the "media-type" and "encoding" output properties
 * specified in the {@link Transformer}.
 * @param model merged output Map (never {@code null})
 * @param response current HTTP response
 * @param transformer the target transformer
 */
protected void configureResponse(Map<String, Object> model, HttpServletResponse response, Transformer transformer) {
  String contentType = getContentType();
  String mediaType = transformer.getOutputProperty(OutputKeys.MEDIA_TYPE);
  String encoding = transformer.getOutputProperty(OutputKeys.ENCODING);
  if (StringUtils.hasText(mediaType)) {
    contentType = mediaType;
  }
  if (StringUtils.hasText(encoding)) {
    // Only apply encoding if content type is specified but does not contain charset clause already.
    if (contentType != null && !contentType.toLowerCase().contains(WebUtils.CONTENT_TYPE_CHARSET_PREFIX)) {
      contentType = contentType + WebUtils.CONTENT_TYPE_CHARSET_PREFIX + encoding;
    }
  }
  response.setContentType(contentType);
}

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

@Test
public void enableIndentingSunnyDay() throws Exception {
  Transformer transformer = new StubTransformer();
  TransformerUtils.enableIndenting(transformer);
  String indent = transformer.getOutputProperty(OutputKeys.INDENT);
  assertNotNull(indent);
  assertEquals("yes", indent);
  String indentAmount = transformer.getOutputProperty("{http://xml.apache.org/xslt}indent-amount");
  assertNotNull(indentAmount);
  assertEquals(String.valueOf(TransformerUtils.DEFAULT_INDENT_AMOUNT), indentAmount);
}

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

@Test
public void enableIndentingSunnyDayWithCustomKosherIndentAmount() throws Exception {
  final String indentAmountProperty = "10";
  Transformer transformer = new StubTransformer();
  TransformerUtils.enableIndenting(transformer, Integer.valueOf(indentAmountProperty));
  String indent = transformer.getOutputProperty(OutputKeys.INDENT);
  assertNotNull(indent);
  assertEquals("yes", indent);
  String indentAmount = transformer.getOutputProperty("{http://xml.apache.org/xslt}indent-amount");
  assertNotNull(indentAmount);
  assertEquals(indentAmountProperty, indentAmount);
}

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

@Test
public void disableIndentingSunnyDay() throws Exception {
  Transformer transformer = new StubTransformer();
  TransformerUtils.disableIndenting(transformer);
  String indent = transformer.getOutputProperty(OutputKeys.INDENT);
  assertNotNull(indent);
  assertEquals("no", indent);
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

ByteArrayOutputStreamEx baos = new ByteArrayOutputStreamEx();
Transformer tr = xs.getIdentityTransformer();
String defaultEncoding = tr.getOutputProperty(OutputKeys.ENCODING);
tr.setOutputProperty(OutputKeys.ENCODING, charset);                        
tr.transform(v, new StreamResult(new OutputStreamWriter(baos,charset)));

代码示例来源:origin: org.glassfish.jaxb/jaxb-runtime

ByteArrayOutputStreamEx baos = new ByteArrayOutputStreamEx();
Transformer tr = xs.getIdentityTransformer();
String defaultEncoding = tr.getOutputProperty(OutputKeys.ENCODING);
tr.setOutputProperty(OutputKeys.ENCODING, charset);                        
tr.transform(v, new StreamResult(new OutputStreamWriter(baos,charset)));

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

/** Get an output property that is in effect for the transformation.
 */
public final String getOutputProperty(String name) {
  return _tfmr.getOutputProperty(name);
}

代码示例来源:origin: toplink.essentials/toplink-essentials

public String getEncoding() {
  return transformer.getOutputProperty(OutputKeys.ENCODING);
}

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

public String getEncoding() {
  return transformer.getOutputProperty(OutputKeys.ENCODING);
}

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

public String getVersion() {
  return transformer.getOutputProperty(OutputKeys.VERSION);
}

代码示例来源:origin: toplink.essentials/toplink-essentials

public String getVersion() {
  return transformer.getOutputProperty(OutputKeys.VERSION);
}

代码示例来源:origin: org.eclipse.persistence/com.springsource.org.eclipse.persistence

public boolean isFormattedOutput() {
  return transformer.getOutputProperty(OutputKeys.INDENT).equals(YES);
}

代码示例来源:origin: toplink.essentials/toplink-essentials

public boolean isFormattedOutput() {
  return transformer.getOutputProperty(OutputKeys.INDENT).equals(YES);
}

代码示例来源:origin: apache/uima-uimaj

CharacterValidatingContentHandler(boolean xml11, ContentHandler serializerHandler) {
 mHandler = serializerHandler;  
 mXml11 = xml11;
 String indentDeltaString = mTransformer.getOutputProperty("{http://xml.apache.org/xslt}indent-amount");
 if (null != indentDeltaString) {
  try {
   indentDelta = Integer.parseInt(indentDeltaString);
  } catch (NumberFormatException e) {
   indentDelta = 0;
  }
 }
 mLastOutputNode.add(null);
}

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

public ContentHandler getContentHandler() {
 String xmlVer = mTransformer.getOutputProperty( OutputKeys.VERSION );
 boolean xml10 = xmlVer == null || "1.0".equals( xmlVer );
 return new CharacterValidatingContentHandler( !xml10, mHandler );
}

代码示例来源:origin: org.apache.ctakes/ctakes-core

public ContentHandler getContentHandler() {
 String xmlVer = mTransformer.getOutputProperty( OutputKeys.VERSION );
 boolean xml10 = xmlVer == null || "1.0".equals( xmlVer );
 return new CharacterValidatingContentHandler( !xml10, mHandler );
}

代码示例来源:origin: apache/uima-uimaj

public ContentHandler getContentHandler() {
 String xmlVer = mTransformer.getOutputProperty(OutputKeys.VERSION);
 boolean xml10 = xmlVer == null || "1.0".equals(xmlVer);
 return new CharacterValidatingContentHandler(!xml10, mHandler);
}

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

@Override
public String getOutputProperty(String str)
  throws java.lang.IllegalArgumentException {
  try {
    materialize();
    return m_realTransformer.getOutputProperty(str);
  } catch (TransformerException e) {
    // will be caught later
  }
  return null;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.help

public String writeString(Element element, boolean xmlDecl) throws TransformerException, TransformerConfigurationException {
  byte[] bytes = writeBytes(element, xmlDecl);
  String encoding = transformer.getOutputProperty(OutputKeys.ENCODING);
  if (encoding == null) {
    encoding = "UTF-8"; //$NON-NLS-1$
  }
  try {
    return new String(bytes, encoding);
  }
  catch (UnsupportedEncodingException e) {
    return new String(bytes);
  }
}

相关文章