Java Code Examples for javax.xml.transform.dom.DOMSource#getNode()
The following examples show how to use
javax.xml.transform.dom.DOMSource#getNode() .
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: DispatchXMLClientServerTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testDOMSourcePAYLOAD() throws Exception { URL wsdl = getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl"); assertNotNull(wsdl); XMLService service = new XMLService(wsdl, SERVICE_NAME); assertNotNull(service); InputStream is = getClass().getResourceAsStream("/messages/XML_GreetMeDocLiteralReq.xml"); Document doc = StaxUtils.read(is); DOMSource reqMsg = new DOMSource(doc); assertNotNull(reqMsg); Dispatch<DOMSource> disp = service.createDispatch(PORT_NAME, DOMSource.class, Service.Mode.PAYLOAD); disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + port + "/XMLService/XMLDispatchPort"); DOMSource result = disp.invoke(reqMsg); assertNotNull(result); Node respDoc = result.getNode(); assertEquals("greetMeResponse", respDoc.getFirstChild().getLocalName()); assertEquals("Hello tli", respDoc.getFirstChild().getTextContent()); }
Example 2
Source File: SimpleBatchSTSClient.java From cxf with Apache License 2.0 | 5 votes |
protected Element getDocumentElement(DOMSource ds) { Node nd = ds.getNode(); if (nd instanceof Document) { nd = ((Document)nd).getDocumentElement(); } return (Element)nd; }
Example 3
Source File: DOMValidatorHelper.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Sets up handler for <code>DOMResult</code>. */ private void setupDOMResultHandler(DOMSource source, DOMResult result) throws SAXException { // If there's no DOMResult, unset the validator handler if (result == null) { fDOMValidatorHandler = null; fSchemaValidator.setDocumentHandler(null); return; } final Node nodeResult = result.getNode(); // If the source node and result node are the same use the DOMResultAugmentor. // Otherwise use the DOMResultBuilder. if (source.getNode() == nodeResult) { fDOMValidatorHandler = fDOMResultAugmentor; fDOMResultAugmentor.setDOMResult(result); fSchemaValidator.setDocumentHandler(fDOMResultAugmentor); return; } if (result.getNode() == null) { try { DocumentBuilderFactory factory = fComponentManager.getFeature(Constants.ORACLE_FEATURE_SERVICE_MECHANISM) ? DocumentBuilderFactory.newInstance() : new DocumentBuilderFactoryImpl(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); result.setNode(builder.newDocument()); } catch (ParserConfigurationException e) { throw new SAXException(e); } } fDOMValidatorHandler = fDOMResultBuilder; fDOMResultBuilder.setDOMResult(result); fSchemaValidator.setDocumentHandler(fDOMResultBuilder); }
Example 4
Source File: AbstractSTSClient.java From steady with Apache License 2.0 | 5 votes |
protected Element getDocumentElement(DOMSource ds) { Node nd = ds.getNode(); if (nd instanceof Document) { nd = ((Document)nd).getDocumentElement(); } return (Element)nd; }
Example 5
Source File: SAXImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Construct a SAXImpl object using the given block size. */ public SAXImpl(XSLTCDTMManager mgr, Source source, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing, int blocksize, boolean buildIdIndex, boolean newNameTable) { super(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory, doIndexing, blocksize, false, buildIdIndex, newNameTable); _dtmManager = mgr; _size = blocksize; // Use a smaller size for the space stack if the blocksize is small _xmlSpaceStack = new int[blocksize <= 64 ? 4 : 64]; /* From DOMBuilder */ _xmlSpaceStack[0] = DTMDefaultBase.ROOTNODE; // If the input source is DOMSource, set the _document field and // create the node2Ids table. if (source instanceof DOMSource) { _hasDOMSource = true; DOMSource domsrc = (DOMSource)source; Node node = domsrc.getNode(); if (node instanceof Document) { _document = (Document)node; } else { _document = node.getOwnerDocument(); } _node2Ids = new HashMap<>(); } }
Example 6
Source File: SourceHttpMessageConverterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void readDOMSourceExternal() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(bodyExternal.getBytes("UTF-8")); inputMessage.getHeaders().setContentType(new MediaType("application", "xml")); converter.setSupportDtd(true); DOMSource result = (DOMSource) converter.read(DOMSource.class, inputMessage); Document document = (Document) result.getNode(); assertEquals("Invalid result", "root", document.getDocumentElement().getLocalName()); assertNotEquals("Invalid result", "Foo Bar", document.getDocumentElement().getTextContent()); }
Example 7
Source File: SourceHttpMessageConverterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void readDOMSource() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes("UTF-8")); inputMessage.getHeaders().setContentType(new MediaType("application", "xml")); DOMSource result = (DOMSource) converter.read(DOMSource.class, inputMessage); Document document = (Document) result.getNode(); assertEquals("Invalid result", "root", document.getDocumentElement().getLocalName()); }
Example 8
Source File: SourceHttpMessageConverterTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void readDOMSource() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes("UTF-8")); inputMessage.getHeaders().setContentType(new MediaType("application", "xml")); DOMSource result = (DOMSource) converter.read(DOMSource.class, inputMessage); Document document = (Document) result.getNode(); assertEquals("Invalid result", "root", document.getDocumentElement().getLocalName()); }
Example 9
Source File: DOMValidatorHelper.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Sets up handler for <code>DOMResult</code>. */ private void setupDOMResultHandler(DOMSource source, DOMResult result) throws SAXException { // If there's no DOMResult, unset the validator handler if (result == null) { fDOMValidatorHandler = null; fSchemaValidator.setDocumentHandler(null); return; } final Node nodeResult = result.getNode(); // If the source node and result node are the same use the DOMResultAugmentor. // Otherwise use the DOMResultBuilder. if (source.getNode() == nodeResult) { fDOMValidatorHandler = fDOMResultAugmentor; fDOMResultAugmentor.setDOMResult(result); fSchemaValidator.setDocumentHandler(fDOMResultAugmentor); return; } if (result.getNode() == null) { try { DocumentBuilderFactory factory = JdkXmlUtils.getDOMFactory( fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER)); DocumentBuilder builder = factory.newDocumentBuilder(); result.setNode(builder.newDocument()); } catch (ParserConfigurationException e) { throw new SAXException(e); } } fDOMValidatorHandler = fDOMResultBuilder; fDOMResultBuilder.setDOMResult(result); fSchemaValidator.setDocumentHandler(fDOMResultBuilder); }
Example 10
Source File: SAXImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Construct a SAXImpl object using the given block size. */ public SAXImpl(XSLTCDTMManager mgr, Source source, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing, int blocksize, boolean buildIdIndex, boolean newNameTable) { super(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory, doIndexing, blocksize, false, buildIdIndex, newNameTable); _dtmManager = mgr; _size = blocksize; // Use a smaller size for the space stack if the blocksize is small _xmlSpaceStack = new int[blocksize <= 64 ? 4 : 64]; /* From DOMBuilder */ _xmlSpaceStack[0] = DTMDefaultBase.ROOTNODE; // If the input source is DOMSource, set the _document field and // create the node2Ids table. if (source instanceof DOMSource) { _hasDOMSource = true; DOMSource domsrc = (DOMSource)source; Node node = domsrc.getNode(); if (node instanceof Document) { _document = (Document)node; } else { _document = node.getOwnerDocument(); } _node2Ids = new HashMap<>(); } }
Example 11
Source File: Convert.java From xmlunit with Apache License 2.0 | 5 votes |
private static Node tryExtractNodeFromDOMSource(Source s) { if (s instanceof DOMSource) { @SuppressWarnings("unchecked") DOMSource ds = (DOMSource) s; return ds.getNode(); } return null; }
Example 12
Source File: SAXImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Construct a SAXImpl object using the given block size. */ public SAXImpl(XSLTCDTMManager mgr, Source source, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing, int blocksize, boolean buildIdIndex, boolean newNameTable) { super(mgr, source, dtmIdentity, whiteSpaceFilter, xstringfactory, doIndexing, blocksize, false, buildIdIndex, newNameTable); _dtmManager = mgr; _size = blocksize; // Use a smaller size for the space stack if the blocksize is small _xmlSpaceStack = new int[blocksize <= 64 ? 4 : 64]; /* From DOMBuilder */ _xmlSpaceStack[0] = DTMDefaultBase.ROOTNODE; // If the input source is DOMSource, set the _document field and // create the node2Ids table. if (source instanceof DOMSource) { _hasDOMSource = true; DOMSource domsrc = (DOMSource)source; Node node = domsrc.getNode(); if (node instanceof Document) { _document = (Document)node; } else { _document = node.getOwnerDocument(); } _node2Ids = new HashMap<>(); } }
Example 13
Source File: DOMValidatorHelper.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Sets up handler for <code>DOMResult</code>. */ private void setupDOMResultHandler(DOMSource source, DOMResult result) throws SAXException { // If there's no DOMResult, unset the validator handler if (result == null) { fDOMValidatorHandler = null; fSchemaValidator.setDocumentHandler(null); return; } final Node nodeResult = result.getNode(); // If the source node and result node are the same use the DOMResultAugmentor. // Otherwise use the DOMResultBuilder. if (source.getNode() == nodeResult) { fDOMValidatorHandler = fDOMResultAugmentor; fDOMResultAugmentor.setDOMResult(result); fSchemaValidator.setDocumentHandler(fDOMResultAugmentor); return; } if (result.getNode() == null) { try { DocumentBuilderFactory factory = JdkXmlUtils.getDOMFactory( fComponentManager.getFeature(JdkXmlUtils.OVERRIDE_PARSER)); DocumentBuilder builder = factory.newDocumentBuilder(); result.setNode(builder.newDocument()); } catch (ParserConfigurationException e) { throw new SAXException(e); } } fDOMValidatorHandler = fDOMResultBuilder; fDOMResultBuilder.setDOMResult(result); fSchemaValidator.setDocumentHandler(fDOMResultBuilder); }
Example 14
Source File: SourceHttpMessageConverterTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void readDOMSourceExternal() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(bodyExternal.getBytes("UTF-8")); inputMessage.getHeaders().setContentType(new MediaType("application", "xml")); converter.setSupportDtd(true); DOMSource result = (DOMSource) converter.read(DOMSource.class, inputMessage); Document document = (Document) result.getNode(); assertEquals("Invalid result", "root", document.getDocumentElement().getLocalName()); assertNotEquals("Invalid result", "Foo Bar", document.getDocumentElement().getTextContent()); }
Example 15
Source File: AbstractSchemaValidationTube.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private String getTargetNamespace(DOMSource src) { Element elem = (Element)src.getNode(); return elem.getAttribute("targetNamespace"); }
Example 16
Source File: AbstractSchemaValidationTube.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private String getTargetNamespace(DOMSource src) { Element elem = (Element)src.getNode(); return elem.getAttribute("targetNamespace"); }
Example 17
Source File: Diff.java From xmlunit with Apache License 2.0 | 4 votes |
private static Document toDocument(DOMSource d) { Node n = d.getNode(); return n instanceof Document ? (Document) n : n.getOwnerDocument(); }
Example 18
Source File: DOM2DTM.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Construct a DOM2DTM object from a DOM node. * * @param mgr The DTMManager who owns this DTM. * @param domSource the DOM source that this DTM will wrap. * @param dtmIdentity The DTM identity ID for this DTM. * @param whiteSpaceFilter The white space filter for this DTM, which may * be null. * @param xstringfactory XMLString factory for creating character content. * @param doIndexing true if the caller considers it worth it to use * indexing schemes. */ public DOM2DTM(DTMManager mgr, DOMSource domSource, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing) { super(mgr, domSource, dtmIdentity, whiteSpaceFilter, xstringfactory, doIndexing); // Initialize DOM navigation m_pos=m_root = domSource.getNode(); // Initialize DTM navigation m_last_parent=m_last_kid=NULL; m_last_kid=addNode(m_root, m_last_parent,m_last_kid, NULL); // Apparently the domSource root may not actually be the // Document node. If it's an Element node, we need to immediately // add its attributes. Adapted from nextNode(). // %REVIEW% Move this logic into addNode and recurse? Cleaner! // // (If it's an EntityReference node, we're probably scrod. For now // I'm just hoping nobody is ever quite that foolish... %REVIEW%) // // %ISSUE% What about inherited namespaces in this case? // Do we need to special-case initialize them into the DTM model? if(ELEMENT_NODE == m_root.getNodeType()) { NamedNodeMap attrs=m_root.getAttributes(); int attrsize=(attrs==null) ? 0 : attrs.getLength(); if(attrsize>0) { int attrIndex=NULL; // start with no previous sib for(int i=0;i<attrsize;++i) { // No need to force nodetype in this case; // addNode() will take care of switching it from // Attr to Namespace if necessary. attrIndex=addNode(attrs.item(i),0,attrIndex,NULL); m_firstch.setElementAt(DTM.NULL,attrIndex); } // Terminate list of attrs, and make sure they aren't // considered children of the element m_nextsib.setElementAt(DTM.NULL,attrIndex); // IMPORTANT: This does NOT change m_last_parent or m_last_kid! } // if attrs exist } //if(ELEMENT_NODE) // Initialize DTM-completed status m_nodesAreProcessed = false; }
Example 19
Source File: AbstractSchemaValidationTube.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private String getTargetNamespace(DOMSource src) { Element elem = (Element)src.getNode(); return elem.getAttribute("targetNamespace"); }
Example 20
Source File: DOM2DTM.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Construct a DOM2DTM object from a DOM node. * * @param mgr The DTMManager who owns this DTM. * @param domSource the DOM source that this DTM will wrap. * @param dtmIdentity The DTM identity ID for this DTM. * @param whiteSpaceFilter The white space filter for this DTM, which may * be null. * @param xstringfactory XMLString factory for creating character content. * @param doIndexing true if the caller considers it worth it to use * indexing schemes. */ public DOM2DTM(DTMManager mgr, DOMSource domSource, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing) { super(mgr, domSource, dtmIdentity, whiteSpaceFilter, xstringfactory, doIndexing); // Initialize DOM navigation m_pos=m_root = domSource.getNode(); // Initialize DTM navigation m_last_parent=m_last_kid=NULL; m_last_kid=addNode(m_root, m_last_parent,m_last_kid, NULL); // Apparently the domSource root may not actually be the // Document node. If it's an Element node, we need to immediately // add its attributes. Adapted from nextNode(). // %REVIEW% Move this logic into addNode and recurse? Cleaner! // // (If it's an EntityReference node, we're probably scrod. For now // I'm just hoping nobody is ever quite that foolish... %REVIEW%) // // %ISSUE% What about inherited namespaces in this case? // Do we need to special-case initialize them into the DTM model? if(ELEMENT_NODE == m_root.getNodeType()) { NamedNodeMap attrs=m_root.getAttributes(); int attrsize=(attrs==null) ? 0 : attrs.getLength(); if(attrsize>0) { int attrIndex=NULL; // start with no previous sib for(int i=0;i<attrsize;++i) { // No need to force nodetype in this case; // addNode() will take care of switching it from // Attr to Namespace if necessary. attrIndex=addNode(attrs.item(i),0,attrIndex,NULL); m_firstch.setElementAt(DTM.NULL,attrIndex); } // Terminate list of attrs, and make sure they aren't // considered children of the element m_nextsib.setElementAt(DTM.NULL,attrIndex); // IMPORTANT: This does NOT change m_last_parent or m_last_kid! } // if attrs exist } //if(ELEMENT_NODE) // Initialize DTM-completed status m_nodesAreProcessed = false; }