Package net.sf.saxon.s9api

Examples of net.sf.saxon.s9api.XdmDestination


    //} catch (SaxonApiException e) {
      // TODO Auto-generated catch block
    //  e.printStackTrace();
    //}
      trans.setInitialContextNode(source);
      XdmDestination pipeDoc = new XdmDestination();
      trans.setDestination(pipeDoc);
      XPipeline pipeline = null;
    //try {
            trans.transform();
      pipeline = runtime.use(pipeDoc.getXdmNode());
      pipeline.run();
    //} catch (SaxonApiException e) {
      // TODO Auto-generated catch block
    //  e.printStackTrace();
    //}
View Full Code Here


                XdmNode root = S9apiUtils.getDocumentElement(doc);
                if (detailed && cx_document.equals(root.getNodeName())) {
                    port = root.getAttributeValue(_port);
                    // FIXME: support exclude-inline-prefixes
                    boolean seenelem = false;
                    XdmDestination dest = new XdmDestination();
                    Vector<XdmValue> nodes = new Vector<XdmValue> ();
                    XdmSequenceIterator iter = root.axisIterator(Axis.CHILD);
                    while (iter.hasNext()) {
                        XdmNode child = (XdmNode) iter.next();
                        if (child.getNodeKind() == XdmNodeKind.ELEMENT) {
                            if (seenelem) {
                                throw new IllegalArgumentException("Not a well-formed inline document");
                            }
                            seenelem = true;
                        }
                        nodes.add(child);
                    }

                    S9apiUtils.writeXdmValue(runtime, nodes, dest, root.getBaseURI());
                    doc = dest.getXdmNode();
                }

                if (port == null) {
                    throw new XProcException(step.getNode(), "You must use cx:document for pipelines with no primary input port");
                }
View Full Code Here

        UnparsedTextURIResolver unparsedTextURIResolver = runtime.getResolver();

        config.setOutputURIResolver(new OutputResolver());
        config.setCollectionURIResolver(new CollectionResolver(runtime, defaultCollection, collectionResolver));

        XdmDestination result = null;
        try {
            XsltCompiler compiler = runtime.getProcessor().newXsltCompiler();
            compiler.setSchemaAware(processor.isSchemaAware());
            XsltExecutable exec = compiler.compile(stylesheet.asSource());
            XsltTransformer transformer = exec.load();

            for (QName name : params.keySet()) {
                RuntimeValue v = params.get(name);
                if (runtime.getAllowGeneralExpressions()) {
                    transformer.setParameter(name, v.getValue());
                } else {
                    transformer.setParameter(name, new XdmAtomicValue(v.getString()));
                }
            }

            if (document != null) {
                transformer.setInitialContextNode(document);
            }
            transformer.setMessageListener(new CatchMessages());
            result = new XdmDestination();
            transformer.setDestination(result);

            if (initialMode != null) {
                transformer.setInitialMode(initialMode);
            }

            if (templateName != null) {
                transformer.setInitialTemplate(templateName);
            }

            if (outputBaseURI != null) {
                transformer.setBaseOutputURI(outputBaseURI);
                // The following hack works around https://saxonica.plan.io/issues/1724
                try {
                    result.setBaseURI(new URI(outputBaseURI));
                } catch (URISyntaxException use) {
                    // whatever
                }
            }

            transformer.setSchemaValidationMode(ValidationMode.DEFAULT);
            transformer.getUnderlyingController().setUnparsedTextURIResolver(unparsedTextURIResolver);
            transformer.transform();
        } finally {
            config.setOutputURIResolver(uriResolver);
            config.setCollectionURIResolver(collectionResolver);
        }

        XdmNode xformed = result.getXdmNode();

        // Can be null when nothing is written to the principle result tree...
        if (xformed != null) {
            if (document != null
                && (xformed.getBaseURI() == null
View Full Code Here

            }

            logger.trace(MessageFormatter.nodeMessage(step.getNode(), "XSLT secondary result document: " + baseURI));

            try {
                XdmDestination xdmResult = new XdmDestination();
                secondaryResults.put(baseURI.toASCIIString(), xdmResult);
                Receiver receiver = xdmResult.getReceiver(runtime.getProcessor().getUnderlyingConfiguration());
                receiver.setSystemId(baseURI.toASCIIString());
                return receiver;
            } catch (SaxonApiException sae) {
                throw new XProcException(sae);
            }
View Full Code Here

            }
        }

        public void close(Result result) throws TransformerException {
            String href = result.getSystemId();
            XdmDestination xdmResult = secondaryResults.get(href);
            XdmNode doc = xdmResult.getXdmNode();
            secondaryPipe.write(doc);
        }
View Full Code Here

        // No resolver, there isn't one here.
        DocumentBuilder builder = processor.newDocumentBuilder();
        SAXSource document = new SAXSource(new InputSource(new StringReader(textXML)));
        XdmNode context = builder.build(document);
        transformer.setInitialContextNode(context);
        XdmDestination result = new XdmDestination();
        transformer.setDestination(result);
        transformer.transform();

        XdmNode xformed = result.getXdmNode();
        System.err.println("Document base: " + xformed.getBaseURI());

        XdmSequenceIterator nodes = xformed.axisIterator(Axis.CHILD);
        XdmNode docNode = (XdmNode) nodes.next();
View Full Code Here

        source = new SAXSource(new InputSource("http://tests.xproc.org/tests/doc/document.xsd"));
        XdmNode schema = builder.build(source);
        manager.load(schema.asSource());

        XdmDestination destination = new XdmDestination();
        Controller controller = new Controller(processor.getUnderlyingConfiguration());
        Receiver receiver = destination.getReceiver(controller.getConfiguration());
        PipelineConfiguration pipe = controller.makePipelineConfiguration();
        pipe.setRecoverFromValidationErrors(false);
        receiver.setPipelineConfiguration(pipe);

        SchemaValidator validator = manager.newSchemaValidator();
        validator.setDestination(destination);

        dumpTree(document, "Input");

        validator.validate(document.asSource());

        XdmNode valid = destination.getXdmNode();

        dumpTree(valid, "Output");
    }
View Full Code Here

                        }

                        nodes.add(gchild);
                    }

                    XdmDestination dest = new XdmDestination();

                    try {
                        if (baseURI == null) {
                            baseURI = new URI("http://example.com/"); // FIXME: do I need this?
                        }
                        S9apiUtils.writeXdmValue(runtime.getProcessor(), nodes, dest, baseURI);
                        XdmNode doc = dest.getXdmNode();
                        stringValue += doc.getStringValue();
                        items.add(doc);
                    } catch (URISyntaxException use) {
                        throw new XProcException(use);
                    } catch (SaxonApiException sae) {
View Full Code Here

                    XdmNode node = (XdmNode) item;
                    if (node.getNodeKind() == XdmNodeKind.ATTRIBUTE
                            || node.getNodeKind() == XdmNodeKind.NAMESPACE) {
                        value += node.getStringValue();
                    } else {
                        XdmDestination dest = new XdmDestination();
                        S9apiUtils.writeXdmValue(runtime,item,dest,null);
                        value += dest.getXdmNode().getStringValue();
                    }
                }
            }
        } catch (SaxonApiUncheckedException saue) {
            Throwable sae = saue.getCause();
View Full Code Here

            schemaSource.setSystemId(schemaNode.getBaseURI().toASCIIString());
            SAXSource source = new SAXSource(schemaSource);
            manager.load(source);
        }

        XdmDestination destination = new XdmDestination();
        Controller controller = new Controller(config);
        Receiver receiver = destination.getReceiver(controller.getConfiguration());
        PipelineConfiguration pipe = controller.makePipelineConfiguration();
        pipe.setRecoverFromValidationErrors(!getOption(_assert_valid,false));
        receiver.setPipelineConfiguration(pipe);

        SchemaValidator validator = manager.newSchemaValidator();
        validator.setDestination(destination);
        validator.setErrorListener(new XSDErrorHandler());

        String mode = getOption(_mode, "strict");
        validator.setLax("lax".equals(mode));

        boolean useHints = getOption(_use_location_hints, false);
        validator.setUseXsiSchemaLocation(useHints);
       
        try {
            logger.trace(MessageFormatter.nodeMessage(step.getNode(),
                    "Validating: " + doc.getBaseURI().toASCIIString()));

            validator.validate(doc.asSource());
            if (validationException != null) {
                throw (SaxonApiException) validationException;
            }
        } catch (SaxonApiException sae) {
            if (getOption(_assert_valid,false)) {
                throw new XProcException(XProcConstants.stepError(53), sae);
            }
        }
       
        XdmNode valid = destination.getXdmNode();
        result.write(valid);
    }
View Full Code Here

TOP

Related Classes of net.sf.saxon.s9api.XdmDestination

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.