當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。