Java Examples for javax.xml.transform.dom.DOMResult

The following java examples will help you to understand the usage of javax.xml.transform.dom.DOMResult. These source code samples are taken from different open source projects.

Example 1
Project: metafacture-core-master  File: DomLoader.java View source code
public static Document parse(String schemaFile, InputSource input) {
    final Document document = createEmptyDocument();
    final XMLReader pipeline = createXmlFilterPipeline(schemaFile, document);
    process(new SAXSource(pipeline, input), new DOMResult(document));
    // Xerces does not use the XSD schema for deciding whether
    // whitespace is ignorable (it requires a DTD for this).
    // Since we do not use a DTD we have to use a different
    // method to remove ignorable whitespace.
    //
    // Note that this method does not only remove ignorable
    // whitespace but all text nodes containing only whitespace.
    removeEmptyTextNodes(document);
    return document;
}
Example 2
Project: JDK-master  File: DOMResultBuilder.java View source code
/*
     * DOMDocumentHandler methods
     */
public void setDOMResult(DOMResult result) {
    fCurrentNode = null;
    fFragmentRoot = null;
    fIgnoreChars = false;
    fTargetChildren.clear();
    if (result != null) {
        fTarget = result.getNode();
        fNextSibling = result.getNextSibling();
        fDocument = (fTarget.getNodeType() == Node.DOCUMENT_NODE) ? (Document) fTarget : fTarget.getOwnerDocument();
        fDocumentImpl = (fDocument instanceof CoreDocumentImpl) ? (CoreDocumentImpl) fDocument : null;
        fStorePSVI = (fDocument instanceof PSVIDocumentImpl);
        return;
    }
    fTarget = null;
    fNextSibling = null;
    fDocument = null;
    fDocumentImpl = null;
    fStorePSVI = false;
}
Example 3
Project: classlib6-master  File: DOMResultBuilder.java View source code
/*
     * DOMDocumentHandler methods
     */
public void setDOMResult(DOMResult result) {
    fCurrentNode = null;
    fFragmentRoot = null;
    fIgnoreChars = false;
    fTargetChildren.clear();
    if (result != null) {
        fTarget = result.getNode();
        fNextSibling = result.getNextSibling();
        fDocument = (fTarget.getNodeType() == Node.DOCUMENT_NODE) ? (Document) fTarget : fTarget.getOwnerDocument();
        fDocumentImpl = (fDocument instanceof CoreDocumentImpl) ? (CoreDocumentImpl) fDocument : null;
        fStorePSVI = (fDocument instanceof PSVIDocumentImpl);
        return;
    }
    fTarget = null;
    fNextSibling = null;
    fDocument = null;
    fDocumentImpl = null;
    fStorePSVI = false;
}
Example 4
Project: ikvm-openjdk-master  File: DOMResultBuilder.java View source code
/*
     * DOMDocumentHandler methods
     */
public void setDOMResult(DOMResult result) {
    fCurrentNode = null;
    fFragmentRoot = null;
    fIgnoreChars = false;
    fTargetChildren.clear();
    if (result != null) {
        fTarget = result.getNode();
        fNextSibling = result.getNextSibling();
        fDocument = (fTarget.getNodeType() == Node.DOCUMENT_NODE) ? (Document) fTarget : fTarget.getOwnerDocument();
        fDocumentImpl = (fDocument instanceof CoreDocumentImpl) ? (CoreDocumentImpl) fDocument : null;
        fStorePSVI = (fDocument instanceof PSVIDocumentImpl);
        return;
    }
    fTarget = null;
    fNextSibling = null;
    fDocument = null;
    fDocumentImpl = null;
    fStorePSVI = false;
}
Example 5
Project: jlibs-master  File: DOMUtil.java View source code
public static void main(String[] args) throws Exception {
    String file = "/Volumes/Backup/projects/office/trunk/fountainhead/gateway/testsuites/newregression/messagevalidation/resources/anothergsearch.wsdl";
    Document doc = newDocumentBuilder(true, false, false, false).parse(file);
    SAXDelegate delegate = new SAXDelegate();
    TransformerHandler handler = TransformerUtil.newTransformerHandler(null, true, 0, null);
    delegate.setHandler(handler);
    DOMResult result = new DOMResult();
    handler.setResult(result);
    Node node = doc;
    node = doc.getDocumentElement().getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/", "binding").item(0);
    toSAX(node, delegate);
    node = result.getNode();
    TransformerUtil.newTransformer(null, true, 0, null).transform(new DOMSource(node), new StreamResult(System.out));
}
Example 6
Project: kabeja-master  File: AbstractSAXSerializer.java View source code
/*
     * (non-Javadoc)
     *
     * @see org.xml.sax.ContentHandler#startDocument()
     */
public void startDocument() throws SAXException {
    try {
        SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
        TransformerHandler f = factory.newTransformerHandler();
        this.document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        // put the the transformer in the chain
        f.setResult(new DOMResult(document));
        super.setContentHandler(f);
    } catch (TransformerConfigurationException e) {
        throw new SAXException(e);
    } catch (IllegalArgumentException e) {
        throw new SAXException(e);
    } catch (TransformerFactoryConfigurationError e) {
        throw new SAXException(e.getException());
    } catch (ParserConfigurationException e) {
        throw new SAXException(e);
    }
    super.startDocument();
}
Example 7
Project: geotoolkit-master  File: StaxStreamWriterTest.java View source code
@Test
public void testWritingToDom() throws Exception {
    //this test requiere and advanced Stax library, here we use WoodStox stream reader.
    final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
    final DocumentBuilder constructeur = fabrique.newDocumentBuilder();
    final Document document = constructeur.newDocument();
    final File file = new File("src/test/resources/org/geotoolkit/xml/sampleOutput.xml");
    if (file.exists())
        file.delete();
    final Result res = new DOMResult(document);
    final MockWriter instance = new MockWriter();
    instance.setOutput(res);
    instance.write();
    instance.dispose();
    //check by reading it back
    final Source src = new DOMSource(document);
    final XMLInputFactory XMLfactory = new WstxInputFactory();
    final XMLStreamReader reader = XMLfactory.createXMLStreamReader(src);
    final MockReader mr = new MockReader();
    mr.setInput(reader);
    StaxStreamReaderTest.validate(mr.read());
    mr.dispose();
}
Example 8
Project: JBossAS51-master  File: XSLSubDeployer.java View source code
public void init(DeploymentInfo di) throws DeploymentException {
    if (di.document == null)
        findDd(di);
    try {
        Transformer trans = templates.newTransformer();
        String urlStr = di.url.toString();
        String shortURL = ServerConfigUtil.shortUrlFromServerHome(urlStr);
        trans.setErrorListener(new JBossErrorHandler(shortURL, null));
        Source s = new DOMSource(di.document);
        DOMResult r = new DOMResult();
        setParameters(trans);
        trans.transform(s, r);
        di.document = (Document) r.getNode();
        if (log.isDebugEnabled()) {
            log.debug("transformed into doc: " + di.document);
            String docStr = DOMWriter.printNode(di.document, true);
            int index = docStr.toLowerCase().indexOf("password");
            if (index != -1) {
                docStr = maskPasswords(docStr, index);
            }
            log.debug("transformed into doc: " + docStr);
        }
    } catch (TransformerException ce) {
        throw new DeploymentException("Problem with xsl transformation", ce);
    }
    delegate.init(di);
}
Example 9
Project: JBossAS_5_1_EDG-master  File: XSLSubDeployer.java View source code
public void init(DeploymentInfo di) throws DeploymentException {
    if (di.document == null)
        findDd(di);
    try {
        Transformer trans = templates.newTransformer();
        String urlStr = di.url.toString();
        String shortURL = ServerConfigUtil.shortUrlFromServerHome(urlStr);
        trans.setErrorListener(new JBossErrorHandler(shortURL, null));
        Source s = new DOMSource(di.document);
        DOMResult r = new DOMResult();
        setParameters(trans);
        trans.transform(s, r);
        di.document = (Document) r.getNode();
        if (log.isDebugEnabled()) {
            log.debug("transformed into doc: " + di.document);
            String docStr = DOMWriter.printNode(di.document, true);
            int index = docStr.toLowerCase().indexOf("password");
            if (index != -1) {
                docStr = maskPasswords(docStr, index);
            }
            log.debug("transformed into doc: " + docStr);
        }
    } catch (TransformerException ce) {
        throw new DeploymentException("Problem with xsl transformation", ce);
    }
    delegate.init(di);
}
Example 10
Project: JFugue-for-Android-master  File: SmartTransformerFactoryImpl.java View source code
/**
     * javax.xml.transform.sax.TransformerFactory implementation.
     * Look up the value of a feature (to see if it is supported).
     * This method must be updated as the various methods and features of this
     * class are implemented.
     *
     * @param name The feature name
     * @return 'true' if feature is supported, 'false' if not
     */
public boolean getFeature(String name) {
    // All supported features should be listed here
    String[] features = { DOMSource.FEATURE, DOMResult.FEATURE, SAXSource.FEATURE, SAXResult.FEATURE, StreamSource.FEATURE, StreamResult.FEATURE };
    // feature name cannot be null
    if (name == null) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME);
        throw new NullPointerException(err.toString());
    }
    // Inefficient, but it really does not matter in a function like this
    for (int i = 0; i < features.length; i++) {
        if (name.equals(features[i]))
            return true;
    }
    // secure processing?
    if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) {
        return featureSecureProcessing;
    }
    // unknown feature
    return false;
}