Java Code Examples for javax.xml.transform.sax.SAXTransformerFactory#newTransformer()

The following examples show how to use javax.xml.transform.sax.SAXTransformerFactory#newTransformer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bug5072946.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test3() throws Exception {
    SAXTransformerFactory sf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    Transformer t = sf.newTransformer();

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder parser = dbf.newDocumentBuilder();
    Document dom = parser.parse(Bug5072946.class.getResourceAsStream("Bug5072946.xml"));

    DOMResult r = new DOMResult();

    t.transform(new DOMSource(dom), r);
    Assert.assertNotNull(r.getNode());

    Node n = r.getNode().getFirstChild();
    r.setNode(n);
    t.transform(new DOMSource(dom), r);
    Assert.assertNotNull(r.getNode());
    Assert.assertSame(r.getNode(), n);

    r.setNextSibling(r.getNode().getFirstChild());
    t.transform(new DOMSource(dom), r);
    Assert.assertNotNull(r.getNode());
    Assert.assertSame(r.getNode(), n);
}
 
Example 2
Source File: JAXBContextImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new identity transformer.
 */
static Transformer createTransformer(boolean disableSecureProcessing) {
    try {
        SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
        return tf.newTransformer();
    } catch (TransformerConfigurationException e) {
        throw new Error(e); // impossible
    }
}
 
Example 3
Source File: JAXBContextImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new identity transformer.
 */
static Transformer createTransformer(boolean disableSecureProcessing) {
    try {
        SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
        return tf.newTransformer();
    } catch (TransformerConfigurationException e) {
        throw new Error(e); // impossible
    }
}
 
Example 4
Source File: JAXBContextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new identity transformer.
 */
static Transformer createTransformer(boolean disableSecureProcessing) {
    try {
        SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
        return tf.newTransformer();
    } catch (TransformerConfigurationException e) {
        throw new Error(e); // impossible
    }
}
 
Example 5
Source File: JAXBContextImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new identity transformer.
 */
static Transformer createTransformer(boolean disableSecureProcessing) {
    try {
        SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
        return tf.newTransformer();
    } catch (TransformerConfigurationException e) {
        throw new Error(e); // impossible
    }
}
 
Example 6
Source File: JAXBContextImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new identity transformer.
 */
static Transformer createTransformer(boolean disableSecureProcessing) {
    try {
        SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
        return tf.newTransformer();
    } catch (TransformerConfigurationException e) {
        throw new Error(e); // impossible
    }
}
 
Example 7
Source File: JAXBContextImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new identity transformer.
 */
static Transformer createTransformer(boolean disableSecureProcessing) {
    try {
        SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
        return tf.newTransformer();
    } catch (TransformerConfigurationException e) {
        throw new Error(e); // impossible
    }
}
 
Example 8
Source File: OBRXMLWriter.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public static ContentHandler newHandler(OutputStream out, String encoding, boolean indent)
        throws TransformerConfigurationException {
    SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    TransformerHandler hd = tf.newTransformerHandler();
    Transformer serializer = tf.newTransformer();
    StreamResult stream = new StreamResult(out);
    serializer.setOutputProperty(OutputKeys.ENCODING, encoding);
    serializer.setOutputProperty(OutputKeys.INDENT, indent ? "yes" : "no");
    hd.setResult(stream);
    return hd;
}
 
Example 9
Source File: sqlxmlExample.java    From PracticeCode with Apache License 2.0 4 votes vote down vote up
private static void showTransformer(Connection con) {

      try {
          // Create and execute an SQL statement that returns a
          // set of data.       
          String SQL = "SELECT * FROM TestTable1";
          Statement stmt = con.createStatement();
          ResultSet rs = stmt.executeQuery(SQL);
	       
          rs.next();
	        
          // Get the value of the source SQLXML object from the database.
          SQLXML xmlSource = rs.getSQLXML("Col3");
	        
          // Get a Source to read the XML data. 
          SAXSource sxSource =  xmlSource.getSource(SAXSource.class);
	        
         // Create a destination SQLXML object without any data.
         SQLXML xmlDest = con.createSQLXML();

         // Get a Result to write the XML data.
         SAXResult sxResult = xmlDest.setResult(SAXResult.class);
	        
         // Transform the Source to a Result by using the identity transform.
         SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactory.newInstance();
         Transformer identity = stf.newTransformer();
         identity.transform(sxSource, sxResult);

         // Insert the destination SQLXML object into the database.
         PreparedStatement psmt = 
           con.prepareStatement(
              "INSERT INTO TestTable2" + " (Col2, Col3, Col4, Col5) VALUES (?, ?, ?, ?)");
         psmt.setString(1, "A");
         psmt.setString(2, "Test data");
         psmt.setInt(3, 123);
         psmt.setSQLXML(4, xmlDest);
         psmt.execute();
	        
         // Execute the query and display the data.	
         SQL = "SELECT * FROM TestTable2";
         stmt = con.createStatement();
         rs = stmt.executeQuery(SQL);

         System.out.println("showTransformer method : Display data in TestTable2 => ");
         while (rs.next()) {
            System.out.println(rs.getString("Col1") + " : " + rs.getString("Col2"));
            System.out.println(rs.getString("Col3") + " : " + rs.getInt("Col4"));
	          
            SQLXML xml = rs.getSQLXML("Col5");              
            System.out.println("XML column : " + xml.getString());
         }
     } catch (Exception e) {
        e.printStackTrace();
     }
   }