/** * Create a new input source with a DOM node, and with the * system ID also passed in as the base URI. * * @param node The DOM node that will contain the Source tree. * @param systemID Specifies the base URI associated with node. */ public DOMSource(Node node, String systemID) { setNode(node); setSystemId(systemID); }
/** * Create a new input source with a DOM node. The operation * will be applied to the subtree rooted at this node. In XSLT, * a "/" pattern still means the root of the tree (not the subtree), * and the evaluation of global variables and parameters is done * from the root node also. * * @param n The DOM node that will contain the Source tree. */ public DOMSource(Node n) { setNode(n); }
public Source marshal(Element element, ValidationEventHandler errorHandler) { return new DOMSource(element); } }
/** * Template method for handling {@code DOMResult}s. * <p>This implementation delegates to {@code marshalDomNode}. * @param graph the root of the object graph to marshal * @param domResult the {@code DOMResult} * @throws XmlMappingException if the given object cannot be marshalled to the result * @throws IllegalArgumentException if the {@code domResult} is empty * @see #marshalDomNode(Object, org.w3c.dom.Node) */ protected void marshalDomResult(Object graph, DOMResult domResult) throws XmlMappingException { if (domResult.getNode() == null) { domResult.setNode(buildDocument()); } marshalDomNode(graph, domResult.getNode()); }
/** * Creates an appropriate post-init action object. */ final Runnable createPostInitAction(Result result) { if (result instanceof DOMResult) { Node node = ((DOMResult) result).getNode(); return new DomPostInitAction(node,serializer); } return null; }
/** * Template method for handling {@code DOMSource}s. * <p>This implementation delegates to {@code unmarshalDomNode}. * If the given source is empty, an empty source {@code Document} * will be created as a placeholder. * @param domSource the {@code DOMSource} * @return the object graph * @throws XmlMappingException if the given source cannot be mapped to an object * @throws IllegalArgumentException if the {@code domSource} is empty * @see #unmarshalDomNode(org.w3c.dom.Node) */ protected Object unmarshalDomSource(DOMSource domSource) throws XmlMappingException { if (domSource.getNode() == null) { domSource.setNode(buildDocument()); } try { return unmarshalDomNode(domSource.getNode()); } catch (NullPointerException ex) { if (!isSupportDtd()) { throw new UnmarshallingFailureException("NPE while unmarshalling. " + "This can happen on JDK 1.6 due to the presence of DTD " + "declarations, which are disabled.", ex); } throw ex; } }
/** * <p>Zero-argument default constructor.</p> * * <p><code>node</code>, * <code>siblingNode</code> and * <code>systemId</code> * will be set to <code>null</code>.</p> */ public DOMResult() { setNode(null); setNextSibling(null); setSystemId(null); }
@Override protected void provideXml(SQLXML xmlObject) throws SQLException, IOException { xmlObject.setResult(DOMResult.class).setNode(document); } };
/** * Parse the content as {@link DOMSource} and apply a {@link Matcher}. * @see <a href="https://github.com/davidehringer/xml-matchers">xml-matchers</a> */ public void assertSource(String content, Matcher<? super Source> matcher) throws Exception { Document document = parseXmlString(content); assertThat("Body content", new DOMSource(document), matcher); }
@Override protected void marshalDomNode(Object graph, Node node) throws XmlMappingException { try { // JiBX does not support DOM natively, so we write to a buffer first, and transform that to the Node Result result = new DOMResult(node); transformAndMarshal(graph, result); } catch (IOException ex) { throw new MarshallingFailureException("JiBX marshalling exception", ex); } }
/** * <p>Use a DOM node to create a new output target with the specified System ID.<p> * * <p>In practice, the node should be * a {@link org.w3c.dom.Document} node, * a {@link org.w3c.dom.DocumentFragment} node, or * a {@link org.w3c.dom.Element} node. * In other words, a node that accepts children.</p> * * <p><code>siblingNode</code> will be set to <code>null</code>.</p> * * @param node The DOM node that will contain the result tree. * @param systemId The system identifier which may be used in association with this node. */ public DOMResult(Node node, String systemId) { setNode(node); setNextSibling(null); setSystemId(systemId); }
/** * Write a pretty version of the Element to the OutputStream. * * @param element the Element to serialize * @param os the OutputStream to write to */ public static void serialize(Element element, OutputStream os) { Source source = new DOMSource(element); serialize(source, os); }
public final void marshal( Object obj, org.w3c.dom.Node node ) throws JAXBException { checkNotNull( obj, "obj", node, "node" ); marshal( obj, new DOMResult(node) ); }
/** * Write a pretty version of the Element to the Writer. * * @param element the Element to serialize * @param w the Writer to write to */ public static void serialize(Element element, Writer w) { Source source = new DOMSource(element); serialize(source, w); }
@Test public void isStaxResultInvalid() throws Exception { assertFalse("A StAX Result", StaxUtils.isStaxResult(new DOMResult())); assertFalse("A StAX Result", StaxUtils.isStaxResult(new SAXResult())); assertFalse("A StAX Result", StaxUtils.isStaxResult(new StreamResult())); }
@Override protected Object unmarshalDomNode(Node node) throws XmlMappingException { try { return transformAndUnmarshal(new DOMSource(node), null); } catch (IOException ex) { throw new UnmarshallingFailureException("JiBX unmarshalling exception", ex); } }
/** * Output a DOM node to stdout. * * @param input * input * @throws TransformerException * TransformerException * @see #output(Source) */ public void output(Node input) throws TransformerException { output(new DOMSource(input)); }
/** * Output a DOM node to stdout. * * @param input * input * @throws TransformerException * TransformerException * @see #output(Source) */ public void output(Node input) throws TransformerException { output(new DOMSource(input)); }
@Test public void isStaxSourceInvalid() throws Exception { assertFalse("A StAX Source", StaxUtils.isStaxSource(new DOMSource())); assertFalse("A StAX Source", StaxUtils.isStaxSource(new SAXSource())); assertFalse("A StAX Source", StaxUtils.isStaxSource(new StreamSource())); }