Java 8 TransformerHandler - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 TransformerHandler class.

This code example shows how to use the following methods:getTransformer, setResult
        DicomObject attrs = load("sr/511/sr_511_ct.dcm");
        File ofile = new File("target/test-out/sr_511_ct-1.xml");
        ofile.getParentFile().mkdirs();
        SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
        TransformerHandler th = tf.newTransformerHandler();
        th.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
        th.setResult(new StreamResult(ofile));
        new SAXWriter(th, th).write(attrs);
    } 
 
    public final void testReadValue() throws IOException, 
            TransformerConfigurationException, 
            TransformerFactoryConfigurationError { 
        File ofile = new File("target/test-out/sr_511_ct-2.xml");
        ofile.getParentFile().mkdirs();
        SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory
                .newInstance();
        TransformerHandler th = tf.newTransformerHandler();
        th.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
        th.setResult(new StreamResult(ofile));
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setResult
 
	@Override 
	public Node readXML(String uri) throws Exception {
		TransformerHandler handler = saxFactory.newTransformerHandler();
		DOMResult result = new DOMResult();
		handler.setResult(result);
		parser.setContentHandler(handler);
		parser.parse(getInputSource(uri));
		return result.getNode();
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getTransformer, setResult, startDocument
		try { 
			StreamResult streamResult = new StreamResult(out);
			SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
			// SAX2.0 ContentHandler. 
			hd = tf.newTransformerHandler();
			Transformer serializer = hd.getTransformer();
			serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
			// serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"users.dtd"); 
			serializer.setOutputProperty(OutputKeys.INDENT, "yes");
			hd.setResult(streamResult);
			hd.startDocument();
		} catch (Exception e) {
			throw new SAXException("Unexpected error in XML initialization", e);
		} 
	} 
 
	public void close() throws SAXException {
		hd.endDocument();
	} 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getTransformer, setResult
        } 
        catch (TransformerConfigurationException error)
        { 
            throw new RuntimeException("Unable to create TransformerHandler.", error);
        } 
        final Transformer t = xmlOut.getTransformer();
        try 
        { 
            t.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2");
        } 
        catch (final IllegalArgumentException e)
        { 
            // It was worth a try 
        } 
        t.setOutputProperty(OutputKeys.INDENT, "yes");
     
        writer = new StringWriter();
        xmlOut.setResult(new StreamResult(writer));
         
        transformer = new DbObjectXMLTransformer(xmlOut);        

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:endDocument, startDocument
        } 
    } 
     
    private void attemptTransformation() throws SAXException 
    { 
        xmlOut.startDocument();
        DbObjectXMLTransformer dboTransformer = new DbObjectXMLTransformer(xmlOut);
        dboTransformer.output(schema);
        xmlOut.endDocument();
    } 
   
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getTransformer, setResult
        // Check the HTML version 
        StringWriter sw = new StringWriter();
        SAXTransformerFactory factory = (SAXTransformerFactory)
                 SAXTransformerFactory.newInstance();
        TransformerHandler handler = factory.newTransformerHandler();
        handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml");
        handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
        handler.setResult(new StreamResult(sw));
 
        InputStream stream = OutlookParserTest.class.getResourceAsStream(
               "/test-documents/testMSG_chinese.msg"); 
        try { 
           parser.parse(stream, handler, metadata, new ParseContext());
        } finally { 
           stream.close();
        } 
          
        // As the HTML version should have been processed, ensure 
        //  we got some of the links 
        String content = sw.toString();
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getTransformer, setResult, startDocument
			throws TransformerConfigurationException, SAXException { 
		StreamResult streamResult = new StreamResult(out);
		SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory
				.newInstance();
		transformerHandler = tf.newTransformerHandler();
		Transformer serializer = transformerHandler.getTransformer();
		serializer.setOutputProperty(OutputKeys.ENCODING, encoding);
		serializer.setOutputProperty(OutputKeys.INDENT, "yes");
		serializer.setOutputProperty(OutputKeys.METHOD, "xml");
		transformerHandler.setResult(streamResult);
		startedElementStack = new Stack<String>();
		transformerHandler.startDocument();
		elementAttributes = new AttributesImpl();
		Pattern p = Pattern.compile("\\p{Cntrl}");
		controlMatcher = p.matcher("");
 
	} 
 
	public void textNode(Object data) throws SAXException {
		if (data == null)
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getClass, setResult, setDocumentLocator, startDocument, startElement
     */ 
    public void startElement(String namespaceURI, String localName, String qName,
        Attributes atts) throws SAXExceptionthis.initContentHandler();
        contentHandler.startElement(namespaceURI, localName, qName, atts);
    } 
 
    /** 
     * Replaces the default transformer handler with the given one. 
     */ 
    private void setTransformerHandler(TransformerHandler fallbackHandler)
        throws SAXException
    { 
        if (contentHandler != null)
        { 
            throw new SAXException(
                "Some input has been already processed. Cannot change the handler anymore. " 
                    + "Place xml-stylesheet " 
                    + "directive immediately at the top of the XML file."); 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setResult
 
        // Prepare a SAX content handler 
        SAXTransformerFactory factory = ((SAXTransformerFactory) TransformerFactory
                .newInstance());
        TransformerHandler transform = factory.newTransformerHandler();
        transform.setResult(new StreamResult(System.out));
 
        // Analyze the RTF representation 
        TikaRepresentation tr = new TikaRepresentation(rtfSample);
        tr.setTikaParser(new RTFParser());
        tr.parse(transform);
    } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:startDocument, startPrefixMapping
            this.jp = jsonFactory.createJsonParser(jsonIn);
            this.out = out;
        } 
 
        private void startDocument() throws SAXException {
            handler.startDocument();
            handler.startPrefixMapping(JSON_PREFIX, JSON_URI);
            handler.startPrefixMapping(XSD_PREFIX, XSD_URI);
        } 
 
        private void endDocument() throws SAXException {
            try { 
                handler.endPrefixMapping(XSD_PREFIX);
            } catch (Exception ex) {
                LOG.warn("Unable to end prefix mapping: " + XSD_PREFIX, ex);
            } 
            try { 
                handler.endPrefixMapping(JSON_PREFIX);
            } catch (Exception ex) {
                LOG.warn("Unable to end prefix mapping: " + JSON_PREFIX, ex);
6
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 TransformerHandler Methods: