List of usage examples for javax.xml.transform Result getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler.java
/** {@inheritDoc} */ public void setResult(Result result) throws IFException { if (result instanceof StreamResult) { StreamResult streamResult = (StreamResult) result; OutputStream out = streamResult.getOutputStream(); if (out == null) { if (streamResult.getWriter() != null) { throw new IllegalArgumentException("FOP cannot use a Writer. Please supply an OutputStream!"); }//from ww w . ja v a2 s . co m try { URL url = new URL(streamResult.getSystemId()); File f = FileUtils.toFile(url); if (f != null) { out = new java.io.FileOutputStream(f); } else { out = url.openConnection().getOutputStream(); } } catch (IOException ioe) { throw new IFException("I/O error while opening output stream", ioe); } out = new java.io.BufferedOutputStream(out); this.ownOutputStream = true; } if (out == null) { throw new IllegalArgumentException("Need a StreamResult with an OutputStream"); } this.outputStream = out; } else { throw new UnsupportedOperationException("Unsupported Result subclass: " + result.getClass().getName()); } }
From source file:org.dhatim.delivery.dom.SmooksDOMFilter.java
protected void doFilter(Source source, Result result) { if (!(source instanceof StreamSource) && !(source instanceof DOMSource) && !(source instanceof JavaSource)) { throw new IllegalArgumentException( source.getClass().getName() + " Source types not yet supported by the DOM Filter."); }/*from w w w .j a va2s. co m*/ if (!(result instanceof FilterResult)) { if (result != null && !(result instanceof StreamResult) && !(result instanceof DOMResult)) { throw new IllegalArgumentException( result.getClass().getName() + " Result types not yet supported by the DOM Filter."); } } try { Node resultNode; // Filter the Source.... if (source instanceof DOMSource) { Node node = ((DOMSource) source).getNode(); if ((node instanceof Document)) { resultNode = filter((Document) node); } else if ((node instanceof Element)) { resultNode = filter((Element) node); } else { throw new IllegalArgumentException( "DOMSource Source types must contain a Document or Element node."); } } else { resultNode = filter(source); } // Populate the Result if (result instanceof StreamResult) { StreamResult streamResult = ((StreamResult) result); Writer writer = getWriter(streamResult, executionContext); try { serialize(resultNode, writer); writer.flush(); } catch (IOException e) { logger.debug("Error writing result to output stream.", e); } } else if (result instanceof DOMResult) { ((DOMResult) result).setNode(resultNode); } } finally { if (closeSource) { close(source); } if (closeResult) { close(result); } } }
From source file:org.dhatim.delivery.sax.SmooksSAXFilter.java
protected void doFilter(Source source, Result result) { if (source instanceof DOMSource) { String serializedDOM = XmlUtil.serialize(((DOMSource) source).getNode(), false); source = new StringSource(serializedDOM); if (logger.isDebugEnabled()) { logger.debug("DOMSource converted to a StringSource."); }/*from w w w . j av a2s . co m*/ } if (!(source instanceof StreamSource) && !(source instanceof JavaSource)) { throw new IllegalArgumentException(source.getClass().getName() + " Source types not yet supported by the SAX Filter. Only supports StreamSource and JavaSource at present."); } if (!(result instanceof FilterResult)) { if (!(result instanceof StreamResult) && result != null) { throw new IllegalArgumentException(result.getClass().getName() + " Result types not yet supported by the SAX Filter. Only supports StreamResult at present."); } } try { Writer writer = parser.parse(source, result, executionContext); writer.flush(); } catch (TerminateException e) { if (logger.isDebugEnabled()) { if (e.isTerminateBefore()) { logger.debug("Terminated filtering on visitBefore of element '" + SAXUtil.getXPath(e.getElement()) + "'."); } else { logger.debug("Terminated filtering on visitAfter of element '" + SAXUtil.getXPath(e.getElement()) + "'."); } } } catch (Exception e) { throw new SmooksException("Failed to filter source.", e); } finally { if (closeSource) { close(source); } if (closeResult) { close(result); } } }
From source file:org.springframework.batch.item.xml.StaxUtils.java
public static XMLEventWriter getXmlEventWriter(Result r) throws Exception { Method m = r.getClass().getDeclaredMethod("getXMLEventWriter", new Class[] {}); boolean accessible = m.isAccessible(); m.setAccessible(true);// ww w.j a va 2s.c om Object result = m.invoke(r); m.setAccessible(accessible); return (XMLEventWriter) result; }
From source file:org.springframework.integration.xml.transformer.XsltPayloadTransformer.java
private Document transformDocument(Document documentPayload, Transformer transformer) throws TransformerException { Source source;//from w w w . j a v a2 s.c om if (this.alwaysUseSourceFactory) { source = this.sourceFactory.createSource(documentPayload); } else { source = new DOMSource(documentPayload); } Result result = this.resultFactory.createResult(documentPayload); if (!DOMResult.class.isAssignableFrom(result.getClass())) { throw new MessagingException( "Document to Document conversion requires a DOMResult-producing ResultFactory implementation."); } DOMResult domResult = (DOMResult) result; transformer.transform(source, domResult); return (Document) domResult.getNode(); }
From source file:org.springframework.oxm.support.AbstractMarshaller.java
/** * Marshals the object graph with the given root into the provided {@code javax.xml.transform.Result}. * <p>This implementation inspects the given result, and calls {@code marshalDomResult}, * {@code marshalSaxResult}, or {@code marshalStreamResult}. * @param graph the root of the object graph to marshal * @param result the result to marshal to * @throws IOException if an I/O exception occurs * @throws XmlMappingException if the given object cannot be marshalled to the result * @throws IllegalArgumentException if {@code result} if neither a {@code DOMResult}, * a {@code SAXResult}, nor a {@code StreamResult} * @see #marshalDomResult(Object, javax.xml.transform.dom.DOMResult) * @see #marshalSaxResult(Object, javax.xml.transform.sax.SAXResult) * @see #marshalStreamResult(Object, javax.xml.transform.stream.StreamResult) *//* ww w .jav a 2 s . c o m*/ @Override public final void marshal(Object graph, Result result) throws IOException, XmlMappingException { if (result instanceof DOMResult) { marshalDomResult(graph, (DOMResult) result); } else if (StaxUtils.isStaxResult(result)) { marshalStaxResult(graph, result); } else if (result instanceof SAXResult) { marshalSaxResult(graph, (SAXResult) result); } else if (result instanceof StreamResult) { marshalStreamResult(graph, (StreamResult) result); } else { throw new IllegalArgumentException("Unknown Result type: " + result.getClass()); } }