当前位置: 首页>>代码示例>>Java>>正文


Java Transformer.getOutputProperties方法代码示例

本文整理汇总了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;
}
 
开发者ID:funtl,项目名称:framework,代码行数:28,代码来源:XmlUtils.java

示例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;
}
 
开发者ID:funtl,项目名称:framework,代码行数:29,代码来源:XmlUtils.java

示例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;
}
 
开发者ID:funtl,项目名称:framework,代码行数:31,代码来源:XmlUtils.java

示例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;  
}
 
开发者ID:m18507308080,项目名称:bohemia,代码行数:28,代码来源:XmlUtils.java

示例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;  
}
 
开发者ID:m18507308080,项目名称:bohemia,代码行数:29,代码来源:XmlUtils.java

示例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;  
}
 
开发者ID:m18507308080,项目名称:bohemia,代码行数:33,代码来源:XmlUtils.java

示例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());
	}
}
 
开发者ID:DataAgg,项目名称:DAFramework,代码行数:22,代码来源:DomXmlUtils.java

示例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();
	}
}
 
开发者ID:inspingcc,项目名称:LibraSock,代码行数:21,代码来源:XmlUtils.java

示例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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:TransformerTest.java

示例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;
}
 
开发者ID:wendal,项目名称:alipay-sdk,代码行数:28,代码来源:XmlUtils.java

示例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;
}
 
开发者ID:wendal,项目名称:alipay-sdk,代码行数:29,代码来源:XmlUtils.java

示例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;
   }
 
开发者ID:wendal,项目名称:alipay-sdk,代码行数:33,代码来源:XmlUtils.java

示例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;
}
 
开发者ID:1991wangliang,项目名称:pay,代码行数:28,代码来源:XmlUtils.java

示例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;
}
 
开发者ID:1991wangliang,项目名称:pay,代码行数:29,代码来源:XmlUtils.java

示例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;
   }
 
开发者ID:1991wangliang,项目名称:pay,代码行数:33,代码来源:XmlUtils.java


注:本文中的javax.xml.transform.Transformer.getOutputProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。