/** * Send the contents of a Source to a Receiver. * @param source the source to be copied * @param receiver the destination to which it is to be copied */ public void send(Source source, Receiver receiver) throws XPathException { send(source, receiver, false); }
/** * Send the contents of a Source to a Receiver. Note that if the Source * identifies an element node rather than a document node, only the subtree * rooted at that element will be copied. * @param source the document or element to be copied * @param receiver the destination to which it is to be copied */ public void send(Source source, Receiver receiver) throws XPathException { send(source, receiver, false); }
/** * Test whether this object model recognizes a particular kind of JAXP Source object, * and if it does, send the contents of the document to a supplied Receiver, and return true. * Otherwise, return false. * <p>This implementation returns true only if the source is a DOMSource whose contained node is a * a "NodeOverNodeInfo".</p> */ public boolean sendSource(Source source, Receiver receiver) throws XPathException { if (source instanceof DOMSource) { Node startNode = ((DOMSource) source).getNode(); if (startNode instanceof NodeOverNodeInfo) { NodeInfo base = ((NodeOverNodeInfo) startNode).getUnderlyingNodeInfo(); Sender.send(base, receiver, null); return true; } } return false; }
/** * Test whether this object model recognizes a particular kind of JAXP Source object, * and if it does, send the contents of the document to a supplied Receiver, and return true. * Otherwise, return false. * <p>This implementation returns true only if the source is a DOMSource whose contained node is a * a "NodeOverNodeInfo".</p> */ public boolean sendSource(Source source, Receiver receiver) throws XPathException { if (source instanceof DOMSource) { Node startNode = ((DOMSource) source).getNode(); if (startNode instanceof NodeOverNodeInfo) { NodeInfo base = ((NodeOverNodeInfo) startNode).getUnderlyingNodeInfo(); Sender.send(base, receiver, null); return true; } } return false; }
/** * Test whether this object model recognizes a particular kind of JAXP Source object, * and if it does, send the contents of the document to a supplied Receiver, and return true. * Otherwise, return false. * <p> * This implementation returns true only if the source is a DOMSource whose contained node is a * a "NodeOverNodeInfo". */ public boolean sendSource(Source source, Receiver receiver, PipelineConfiguration pipe) throws XPathException { if (source instanceof DOMSource) { Node startNode = ((DOMSource)source).getNode(); if (startNode instanceof NodeOverNodeInfo) { NodeInfo base = ((NodeOverNodeInfo)startNode).getUnderlyingNodeInfo(); Sender driver = new Sender(pipe); driver.send(base, receiver); return true; } } return false; }
public static PackageDetails getPackageDetails(File top, Configuration config) { PackageInspector inspector = new PackageInspector(config.makePipelineConfiguration()); try { Sender.send(new StreamSource(top), inspector, new ParseOptions()); } catch (XPathException e) { // early exit is expected } VersionedPackageName vp = inspector.getNameAndVersion(); if (vp == null) { return null; } else { PackageDetails details = new PackageDetails(); details.nameAndVersion = vp; details.sourceLocation = new StreamSource(top); return details; } } }
public static PackageDetails getPackageDetails(File top, Configuration config) { PackageInspector inspector = new PackageInspector(config.makePipelineConfiguration()); try { Sender.send(new StreamSource(top), inspector, new ParseOptions()); } catch (XPathException e) { // early exit is expected } VersionedPackageName vp = inspector.getNameAndVersion(); if (vp == null) { return null; } else { PackageDetails details = new PackageDetails(); details.nameAndVersion = vp; details.sourceLocation = new StreamSource(top); return details; } } }
/** * Copy a DOM node to create a node in a different tree model * * @param node the DOM node to be copied * @param model the target tree model * @param config the Saxon Configuration * @return the copied node * @throws net.sf.saxon.trans.XPathException * if the operation fails * @since 9.2 */ public NodeInfo copy(Node node, TreeModel model, Configuration config) throws XPathException { PipelineConfiguration pipe = config.makePipelineConfiguration(); Builder builder = model.makeBuilder(pipe); builder.open(); Sender.send(new DOMSource(node), builder, null); NodeInfo result = builder.getCurrentRoot(); builder.close(); return result; }
/** * Copy a DOM node to create a node in a different tree model * * @param node the DOM node to be copied * @param model the target tree model * @param config the Saxon Configuration * @return the copied node * @throws net.sf.saxon.trans.XPathException * if the operation fails * @since 9.2 */ public NodeInfo copy(Node node, TreeModel model, Configuration config) throws XPathException { PipelineConfiguration pipe = config.makePipelineConfiguration(); Builder builder = model.makeBuilder(pipe); builder.open(); Sender.send(new DOMSource(node), builder, null); NodeInfo result = builder.getCurrentRoot(); builder.close(); return result; }
private static NodeInfo sourceToNode(Source src, Configuration cfg) throws XPathException { // Saxon extension to the XQJ specification PipelineConfiguration pipe = cfg.makePipelineConfiguration(); TinyBuilder b = new TinyBuilder(pipe); b.setStatistics(Statistics.SOURCE_DOCUMENT_STATISTICS); Sender.send(src, b, null); NodeInfo node = b.getCurrentRoot(); b.reset(); return node; }
/** * Validate an instance document supplied as a Source object * @param source the instance document to be validated. The call getSystemId() applied to * this source object must return the base URI used for dereferencing any xsi:schemaLocation * or xsi:noNamespaceSchemaLocation attributes * @throws SaxonApiException if the source document is found to be invalid */ public void validate(Source source) throws SaxonApiException { Receiver receiver = getReceiver(config, source.getSystemId()); PipelineConfiguration pipe = receiver.getPipelineConfiguration(); try { new Sender(pipe).send(source, receiver, true); } catch (XPathException e) { throw new SaxonApiException(e); } }
SAXSource source = new SAXSource(in); source.setSystemId(in.getSystemId()); Sender.send(source, builder, parseOptions); TinyDocumentImpl doc = (TinyDocumentImpl) builder.getCurrentRoot(); builder.reset();
/** * Evaluate in a general context */ public Item evaluateItem(XPathContext c) throws XPathException { Controller controller = c.getController(); AtomicValue content = (AtomicValue)argument[0].evaluateItem(c); StringReader sr = new StringReader(content.getStringValue()); InputSource is = new InputSource(sr); is.setSystemId(baseURI); Source source = new SAXSource(is); source.setSystemId(baseURI); Builder b = controller.makeBuilder(); Receiver s = b; source = AugmentedSource.makeAugmentedSource(source); ((AugmentedSource)source).setStripSpace(Whitespace.XSLT); if (controller.getExecutable().stripsInputTypeAnnotations()) { s = controller.getConfiguration().getAnnotationStripper(s); } try { new Sender(controller.makePipelineConfiguration()).send(source, s); return b.getCurrentRoot(); } catch (XPathException err) { throw new XPathException(err); } }
/** * Evaluate in a general context */ public Item evaluateItem(XPathContext c) throws XPathException { Controller controller = c.getController(); AtomicValue content = (AtomicValue)argument[0].evaluateItem(c); StringReader sr = new StringReader(content.getStringValue()); InputSource is = new InputSource(sr); is.setSystemId(baseURI); Source source = new SAXSource(is); source.setSystemId(baseURI); Builder b = controller.makeBuilder(); Receiver s = b; source = AugmentedSource.makeAugmentedSource(source); ((AugmentedSource)source).setStripSpace(Whitespace.XSLT); if (controller.getExecutable().stripsInputTypeAnnotations()) { s = controller.getConfiguration().getAnnotationStripper(s); } try { new Sender(controller.makePipelineConfiguration()).send(source, s); return b.getCurrentRoot(); } catch (XPathException err) { throw new XPathException(err); } }
/** * Evaluate in a general context */ public Item evaluateItem(XPathContext c) throws XPathException { Controller controller = c.getController(); AtomicValue content = (AtomicValue)argument[0].evaluateItem(c); StringReader sr = new StringReader(content.getStringValue()); InputSource is = new InputSource(sr); is.setSystemId(baseURI); Source source = new SAXSource(is); source.setSystemId(baseURI); Builder b = controller.makeBuilder(); Receiver s = b; source = AugmentedSource.makeAugmentedSource(source); ((AugmentedSource)source).setStripSpace(Whitespace.XSLT); if (controller.getExecutable().stripsInputTypeAnnotations()) { s = controller.getConfiguration().getAnnotationStripper(s); } try { new Sender(controller.makePipelineConfiguration()).send(source, s); NodeInfo node = b.getCurrentRoot(); b.reset(); return node; } catch (XPathException err) { throw new XPathException(err); } }
Sender.send(source, b, options); newdoc = b.getCurrentRoot().getTreeInfo(); b.reset();
/** * Perform identify transformation from Source to Result */ public void transform(Source source, Result result) throws TransformerException { try { SerializerFactory sf = getConfiguration().getSerializerFactory(); Receiver receiver = sf.getReceiver(result, new SerializationProperties(getOutputProperties())); ParseOptions options = receiver.getPipelineConfiguration().getParseOptions(); options.setContinueAfterValidationErrors(true); Sender.send(source, receiver, options); } catch (XPathException err) { Throwable cause = err.getException(); if (cause instanceof SAXParseException) { // This generally means the error was already reported. // But if a RuntimeException occurs in Saxon during a callback from // the Crimson parser, Crimson wraps this in a SAXParseException without // reporting it further. SAXParseException spe = (SAXParseException) cause; cause = spe.getException(); if (cause instanceof RuntimeException) { reportFatalError(err); } } else { reportFatalError(err); } throw err; } }
NamespaceReducer reducer = new NamespaceReducer(); reducer.setUnderlyingReceiver(receiver); new Sender(pipe).send(source, reducer, true); } catch (XPathException err) { Throwable cause = err.getException();
/** * Perform identify transformation from Source to Result */ public void transform(Source source, Result result) throws TransformerException { try { SerializerFactory sf = getConfiguration().getSerializerFactory(); Receiver receiver = sf.getReceiver(result, new SerializationProperties(getOutputProperties())); ParseOptions options = receiver.getPipelineConfiguration().getParseOptions(); options.setContinueAfterValidationErrors(true); Sender.send(source, receiver, options); } catch (XPathException err) { Throwable cause = err.getException(); if (cause instanceof SAXParseException) { // This generally means the error was already reported. // But if a RuntimeException occurs in Saxon during a callback from // the Crimson parser, Crimson wraps this in a SAXParseException without // reporting it further. SAXParseException spe = (SAXParseException) cause; cause = spe.getException(); if (cause instanceof RuntimeException) { reportFatalError(err); } } else { reportFatalError(err); } throw err; } }
NamespaceReducer reducer = new NamespaceReducer(); reducer.setUnderlyingReceiver(receiver); new Sender(pipe).send(source, reducer, true); } catch (XPathException err) { Throwable cause = err.getException();