本文整理汇总了Java中javax.xml.transform.Transformer.getOutputProperties方法的典型用法代码示例。如果您正苦于以下问题:Java Transformer.getOutputProperties方法的具体用法?Java Transformer.getOutputProperties怎么用?Java Transformer.getOutputProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.transform.Transformer
的用法示例。
在下文中一共展示了Transformer.getOutputProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: childNodeToString
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* Converts the Node/Element instance to XML payload.
*
* @param node the node/element instance to convert
* @return the XML payload representing the node/element
* @throws AlipayApiException problem converting XML to string
*/
public static String childNodeToString(Node node) throws AlipayApiException {
String payload = null;
try {
Transformer tf = TransformerFactory.newInstance().newTransformer();
Properties props = tf.getOutputProperties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, LOGIC_YES);
tf.setOutputProperties(props);
StringWriter writer = new StringWriter();
tf.transform(new DOMSource(node), new StreamResult(writer));
payload = writer.toString();
payload = payload.replaceAll(REG_INVALID_CHARS, " ");
} catch (TransformerException e) {
throw new AlipayApiException("XML_TRANSFORM_ERROR", e);
}
return payload;
}
示例2: nodeToString
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* Converts the Node/Document/Element instance to XML payload.
*
* @param node the node/document/element instance to convert
* @return the XML payload representing the node/document/element
* @throws AlipayApiException problem converting XML to string
*/
public static String nodeToString(Node node) throws AlipayApiException {
String payload = null;
try {
Transformer tf = TransformerFactory.newInstance().newTransformer();
Properties props = tf.getOutputProperties();
props.setProperty(OutputKeys.INDENT, LOGIC_YES);
props.setProperty(OutputKeys.ENCODING, DEFAULT_ENCODE);
tf.setOutputProperties(props);
StringWriter writer = new StringWriter();
tf.transform(new DOMSource(node), new StreamResult(writer));
payload = writer.toString();
payload = payload.replaceAll(REG_INVALID_CHARS, " ");
} catch (TransformerException e) {
throw new AlipayApiException("XML_TRANSFORM_ERROR", e);
}
return payload;
}
示例3: xmlToHtml
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* Transforms the XML content to XHTML/HTML format string with the XSL.
*
* @param payload the XML payload to convert
* @param xsltFile the XML stylesheet file
* @return the transformed XHTML/HTML format string
* @throws AlipayApiException problem converting XML to HTML
*/
public static String xmlToHtml(String payload, File xsltFile) throws AlipayApiException {
String result = null;
try {
Source template = new StreamSource(xsltFile);
Transformer transformer = TransformerFactory.newInstance().newTransformer(template);
Properties props = transformer.getOutputProperties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, LOGIC_YES);
transformer.setOutputProperties(props);
StreamSource source = new StreamSource(new StringReader(payload));
StreamResult sr = new StreamResult(new StringWriter());
transformer.transform(source, sr);
result = sr.getWriter().toString();
} catch (TransformerException e) {
throw new AlipayApiException("XML_TRANSFORM_ERROR", e);
}
return result;
}
示例4: childNodeToString
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* Converts the Node/Element instance to XML payload.
*
* @param node the node/element instance to convert
* @return the XML payload representing the node/element
* @throws XmlException problem converting XML to string
*/
public static String childNodeToString(Node node) throws XmlException {
String payload = null;
try {
Transformer tf = TransformerFactory.newInstance().newTransformer();
Properties props = tf.getOutputProperties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, LOGIC_YES);
tf.setOutputProperties(props);
StringWriter writer = new StringWriter();
tf.transform(new DOMSource(node), new StreamResult(writer));
payload = writer.toString();
payload = payload.replaceAll(REG_INVALID_CHARS, " ");
} catch (TransformerException e) {
throw new XmlException(XmlException.XML_TRANSFORM_ERROR, e);
}
return payload;
}
示例5: nodeToString
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* Converts the Node/Document/Element instance to XML payload.
*
* @param node the node/document/element instance to convert
* @return the XML payload representing the node/document/element
* @throws XmlException problem converting XML to string
*/
public static String nodeToString(Node node) throws XmlException {
String payload = null;
try {
Transformer tf = TransformerFactory.newInstance().newTransformer();
Properties props = tf.getOutputProperties();
props.setProperty(OutputKeys.INDENT, LOGIC_YES);
props.setProperty(OutputKeys.ENCODING, DEFAULT_ENCODE);
tf.setOutputProperties(props);
StringWriter writer = new StringWriter();
tf.transform(new DOMSource(node), new StreamResult(writer));
payload = writer.toString();
payload = payload.replaceAll(REG_INVALID_CHARS, " ");
} catch (TransformerException e) {
throw new XmlException(XmlException.XML_TRANSFORM_ERROR, e);
}
return payload;
}
示例6: xmlToHtml
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* Transforms the XML content to XHTML/HTML format string with the XSL.
*
* @param payload the XML payload to convert
* @param xsltFile the XML stylesheet file
* @return the transformed XHTML/HTML format string
* @throws XmlException problem converting XML to HTML
*/
public static String xmlToHtml(String payload, File xsltFile)
throws XmlException {
String result = null;
try {
Source template = new StreamSource(xsltFile);
Transformer transformer = TransformerFactory.newInstance()
.newTransformer(template);
Properties props = transformer.getOutputProperties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, LOGIC_YES);
transformer.setOutputProperties(props);
StreamSource source = new StreamSource(new StringReader(payload));
StreamResult sr = new StreamResult(new StringWriter());
transformer.transform(source, sr);
result = sr.getWriter().toString();
} catch (TransformerException e) {
throw new XmlException(XmlException.XML_TRANSFORM_ERROR, e);
}
return result;
}
示例7: newTransformer
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* 获取一个Transformer对象,由于使用时都做相同的初始化,所以提取出来作为公共方法。
*
* @return a Transformer encoding gb2312
*/
public static Transformer newTransformer() {
try {
Transformer transformer = TransformerFactory.newInstance()
.newTransformer();
Properties properties = transformer.getOutputProperties();
properties.setProperty(OutputKeys.ENCODING, "gb2312");
properties.setProperty(OutputKeys.METHOD, "xml");
properties.setProperty(OutputKeys.VERSION, "1.0");
properties.setProperty(OutputKeys.INDENT, "no");
transformer.setOutputProperties(properties);
return transformer;
} catch (TransformerConfigurationException tce) {
throw new RuntimeException(tce.getMessage());
}
}
示例8: save
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
public static void save(String paramString, Document paramDocument) throws Exception {
DOMSource localDOMSource = new DOMSource(paramDocument);
File localFile1 = new File(paramString);
File localFile2 = localFile1.getParentFile();
localFile2.mkdirs();
StreamResult localStreamResult = new StreamResult(localFile1);
try {
TransformerFactory localTransformerFactory = TransformerFactory.newInstance();
Transformer localTransformer = localTransformerFactory.newTransformer();
Properties localProperties = localTransformer.getOutputProperties();
localProperties.setProperty("encoding", "UTF-8");
localProperties.setProperty("indent", "yes");
localTransformer.setOutputProperties(localProperties);
localTransformer.transform(localDOMSource, localStreamResult);
} catch (TransformerConfigurationException localTransformerConfigurationException) {
localTransformerConfigurationException.printStackTrace();
} catch (TransformerException localTransformerException) {
localTransformerException.printStackTrace();
}
}
示例9: transformer05
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* This tests getOutputProperties() method of Transformer.
*
* @throws Exception If any errors occur.
*/
@Test
public void transformer05() throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new File(TEST_XSL));
DOMSource domSource = new DOMSource(document);
Transformer transformer = TransformerFactory.newInstance().
newTransformer(domSource);
Properties prop = transformer.getOutputProperties();
assertEquals(prop.getProperty("indent"), "yes");
assertEquals(prop.getProperty("method"), "xml");
assertEquals(prop.getProperty("encoding"), "UTF-8");
assertEquals(prop.getProperty("standalone"), "no");
assertEquals(prop.getProperty("version"), "1.0");
assertEquals(prop.getProperty("omit-xml-declaration"), "no");
}
示例10: childNodeToString
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* Converts the Node/Element instance to XML payload.
*
* @param node the node/element instance to convert
* @return the XML payload representing the node/element
* @throws ApiException problem converting XML to string
*/
public static String childNodeToString(Node node) throws AlipayApiException {
String payload = null;
try {
Transformer tf = TransformerFactory.newInstance().newTransformer();
Properties props = tf.getOutputProperties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, LOGIC_YES);
tf.setOutputProperties(props);
StringWriter writer = new StringWriter();
tf.transform(new DOMSource(node), new StreamResult(writer));
payload = writer.toString();
payload = payload.replaceAll(REG_INVALID_CHARS, " ");
} catch (TransformerException e) {
throw new AlipayApiException("XML_TRANSFORM_ERROR", e);
}
return payload;
}
示例11: nodeToString
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* Converts the Node/Document/Element instance to XML payload.
*
* @param node the node/document/element instance to convert
* @return the XML payload representing the node/document/element
* @throws ApiException problem converting XML to string
*/
public static String nodeToString(Node node) throws AlipayApiException {
String payload = null;
try {
Transformer tf = TransformerFactory.newInstance().newTransformer();
Properties props = tf.getOutputProperties();
props.setProperty(OutputKeys.INDENT, LOGIC_YES);
props.setProperty(OutputKeys.ENCODING, DEFAULT_ENCODE);
tf.setOutputProperties(props);
StringWriter writer = new StringWriter();
tf.transform(new DOMSource(node), new StreamResult(writer));
payload = writer.toString();
payload = payload.replaceAll(REG_INVALID_CHARS, " ");
} catch (TransformerException e) {
throw new AlipayApiException("XML_TRANSFORM_ERROR", e);
}
return payload;
}
示例12: xmlToHtml
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* Transforms the XML content to XHTML/HTML format string with the XSL.
*
* @param payload the XML payload to convert
* @param xsltFile the XML stylesheet file
* @return the transformed XHTML/HTML format string
* @throws ApiException problem converting XML to HTML
*/
public static String xmlToHtml(String payload, File xsltFile)
throws AlipayApiException {
String result = null;
try {
Source template = new StreamSource(xsltFile);
Transformer transformer = TransformerFactory.newInstance()
.newTransformer(template);
Properties props = transformer.getOutputProperties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, LOGIC_YES);
transformer.setOutputProperties(props);
StreamSource source = new StreamSource(new StringReader(payload));
StreamResult sr = new StreamResult(new StringWriter());
transformer.transform(source, sr);
result = sr.getWriter().toString();
} catch (TransformerException e) {
throw new AlipayApiException("XML_TRANSFORM_ERROR", e);
}
return result;
}
示例13: childNodeToString
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* Converts the Node/Element instance to XML payload.
*
* @param node the node/element instance to convert
* @return the XML payload representing the node/element
* @throws AlipayApiException problem converting XML to string
*/
public static String childNodeToString(Node node) throws AlipayApiException {
String payload = null;
try {
Transformer tf = TransformerFactory.newInstance().newTransformer();
Properties props = tf.getOutputProperties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, LOGIC_YES);
tf.setOutputProperties(props);
StringWriter writer = new StringWriter();
tf.transform(new DOMSource(node), new StreamResult(writer));
payload = writer.toString();
payload = payload.replaceAll(REG_INVALID_CHARS, " ");
} catch (TransformerException e) {
throw new AlipayApiException("XML_TRANSFORM_ERROR", e);
}
return payload;
}
示例14: nodeToString
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* Converts the Node/Document/Element instance to XML payload.
*
* @param node the node/document/element instance to convert
* @return the XML payload representing the node/document/element
* @throws AlipayApiException problem converting XML to string
*/
public static String nodeToString(Node node) throws AlipayApiException {
String payload = null;
try {
Transformer tf = TransformerFactory.newInstance().newTransformer();
Properties props = tf.getOutputProperties();
props.setProperty(OutputKeys.INDENT, LOGIC_YES);
props.setProperty(OutputKeys.ENCODING, DEFAULT_ENCODE);
tf.setOutputProperties(props);
StringWriter writer = new StringWriter();
tf.transform(new DOMSource(node), new StreamResult(writer));
payload = writer.toString();
payload = payload.replaceAll(REG_INVALID_CHARS, " ");
} catch (TransformerException e) {
throw new AlipayApiException("XML_TRANSFORM_ERROR", e);
}
return payload;
}
示例15: xmlToHtml
import javax.xml.transform.Transformer; //导入方法依赖的package包/类
/**
* Transforms the XML content to XHTML/HTML format string with the XSL.
*
* @param payload the XML payload to convert
* @param xsltFile the XML stylesheet file
* @return the transformed XHTML/HTML format string
* @throws AlipayApiException problem converting XML to HTML
*/
public static String xmlToHtml(String payload, File xsltFile)
throws AlipayApiException {
String result = null;
try {
Source template = new StreamSource(xsltFile);
Transformer transformer = TransformerFactory.newInstance()
.newTransformer(template);
Properties props = transformer.getOutputProperties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, LOGIC_YES);
transformer.setOutputProperties(props);
StreamSource source = new StreamSource(new StringReader(payload));
StreamResult sr = new StreamResult(new StringWriter());
transformer.transform(source, sr);
result = sr.getWriter().toString();
} catch (TransformerException e) {
throw new AlipayApiException("XML_TRANSFORM_ERROR", e);
}
return result;
}