Package net.sf.saxon.s9api

Examples of net.sf.saxon.s9api.QName


                XdmSequenceIterator attriter = node.axisIterator(Axis.ATTRIBUTE);
                while (attriter.hasNext()) {
                    XdmNode attr = (XdmNode) attriter.next();
                    String attrns = attr.getNodeName().getNamespaceURI();
                    if (excludeNS.contains(attrns)) {
                        tree.addAttribute(new QName(attr.getNodeName().getLocalName()), attr.getStringValue());
                    } else {
                        tree.addAttribute(attr);
                    }
                }
            } else {
View Full Code Here


        }

        String version = null;
        if (getOption(_version) == null) {
            XdmNode ssroot = S9apiUtils.getDocumentElement(stylesheet);
            version = ssroot.getAttributeValue(new QName("","version"));
            if (version == null) {
                version = ssroot.getAttributeValue(new QName("http://www.w3.org/1999/XSL/Transform","version"));
            }
            if (version == null) {
                version = "2.0"; // WTF?
            }
        } else {
            version = getOption(_version).getString();
        }
       
        if ("3.0".equals(version) && Configuration.softwareEdition.toLowerCase().equals("he")) {
            throw XProcException.stepError(38, "XSLT version '" + version + "' is not supported (Saxon PE or EE processor required).");
        }
       
        // We used to check if the XSLT version was supported, but I've removed that check.
        // If it's not supported by Saxon, we'll get an error from Saxon. Otherwise, we'll
        // get the results we get.

        if ("1.0".equals(version) && defaultCollection.size() > 1) {
            throw XProcException.stepError(39);
        }
       
        if ("1.0".equals(version) && runtime.getUseXslt10Processor()) {
            run10(stylesheet, document);
            return;
        }

        QName initialMode = null;
        QName templateName = null;
        String outputBaseURI = null;

        RuntimeValue opt = getOption(_initial_mode);
        if (opt != null) {
            initialMode = opt.getQName();
View Full Code Here

        XdmNode piperoot = S9apiUtils.getDocumentElement(pipedoc);

        XProcRuntime innerRuntime = new XProcRuntime(runtime);
        innerRuntime.resetExtensionFunctions();

        QName stepName = getOption(_step, (QName) null);
        XPipeline pipeline = null;
        if (XProcConstants.p_pipeline.equals(piperoot.getNodeName())
                || XProcConstants.p_declare_step.equals(piperoot.getNodeName())) {
            if (stepName != null) {
                throw new XProcException(step.getNode(), "Step option can only be used when loading a p:library");
            }
            pipeline = innerRuntime.use(pipedoc);
        } else if (XProcConstants.p_library.equals(piperoot.getNodeName())) {
            XLibrary library = innerRuntime.useLibrary(piperoot);
            if (stepName == null) {
                pipeline = library.getFirstPipeline();
            } else {
                pipeline = library.getPipeline(stepName);
            }
        }

        Set<String> inputports = pipeline.getInputs();
        Set<String> outputports = pipeline.getOutputs();

        int inputCount = 0;
        for (String port : inputports) {
            XInput input = pipeline.getInput(port);
            if (input.getParameters()) {
                // nop; it's ok for these to be unbound
            } else {
                inputCount++;
            }
        }

        boolean detailed = getOption(_detailed, false);

        if (!detailed && (inputCount > 1 || outputports.size() > 1)) {
            throw new XProcException(step.getNode(), "You must specify detailed='true' to eval pipelines with multiple inputs or outputs");
        }

        DeclareStep decl = pipeline.getDeclareStep();
        String primaryin = null;
        Iterator<String> portiter = inputports.iterator();
        while (portiter.hasNext()) {
            String port = portiter.next();
            Input input = decl.getInput(port);
            if (!input.getParameterInput() && ((inputports.size() == 1 && !input.getPrimarySet()) || input.getPrimary())) {
                primaryin = port;
            }
        }

        Hashtable<String,Vector<XdmNode>> inputs = new Hashtable<String,Vector<XdmNode>> ();
        for (ReadablePipe pipe : sources) {
            while (pipe.moreDocuments()) {
                String port = primaryin;
                XdmNode doc = pipe.read();
                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");
                }

                if (!inputs.containsKey(port)) {
                    inputs.put(port, new Vector<XdmNode> ());
                }

                inputs.get(port).add(doc);
            }
        }

        for (String port : inputs.keySet()) {
            if (inputports.contains(port)) {
                pipeline.clearInputs(port);
                for (XdmNode node : inputs.get(port)) {
                    pipeline.writeTo(port, node);
                }
            } else {
                throw new XProcException(step.getNode(), "Eval pipeline has no input port named '" + port + "'");
            }
        }

        if (params != null) {
            for (QName name : params.keySet()) {
                pipeline.setParameter(name, params.get(name));
            }
        }

        for (ReadablePipe pipe : options) {
            while (pipe.moreDocuments()) {
                XdmNode doc = pipe.read();
                XdmNode root = S9apiUtils.getDocumentElement(doc);

                if (!cx_options.equals(root.getNodeName())) {
                    throw new XProcException(step.getNode(), "Options port must be a cx:options document.");
                }

               
                for (XdmNode opt : new AxisNodes(runtime, root, Axis.CHILD, AxisNodes.SIGNIFICANT)) {
                    if (opt.getNodeKind() != XdmNodeKind.ELEMENT || !cx_option.equals(opt.getNodeName())) {
                        throw new XProcException(step.getNode(), "A cx:options document must only contain cx:option elements");
                    }

                    String name = opt.getAttributeValue(_name);
                    QName qname = new QName(name, opt);

                    String value = opt.getAttributeValue(_value);

                    if (name == null || value == null) {
                        throw new XProcException(step.getNode(), "A cx:option element must have name and value attributes");
View Full Code Here

                } else {
                    treeWriter.startContent();
                    XdmSequenceIterator iter = xdmvalue.iterator();
                    while (iter.hasNext()) {
                        XdmItem next = iter.next();
                        QName type = next.isAtomicValue() ? ((XdmAtomicValue) next).getPrimitiveTypeName() : null;

                        treeWriter.addStartElement(cx_item);

                        if (type != null) {
                            if ("http://www.w3.org/2001/XMLSchema".equals(type.getNamespaceURI())) {
                                treeWriter.addAttribute(_type, type.getLocalName());
                            } else {
                                treeWriter.addAttribute(_type, type.getClarkName());
                            }
                        }

                        if (next.isAtomicValue()) {
                            treeWriter.addAttribute(_value, next.getStringValue());
View Full Code Here

        if (wns != null && wrapperNameStr.contains(":")) {
            throw XProcException.dynamicError(34, "You can't specify a namespace if the wrapper name contains a colon");
        }

        QName wrapper = null;
        if (wrapperNameStr.contains(":")) {
            wrapper = new QName(wrapperNameStr, wrapperNameValue.getNode());
        } else {
            wrapper = new QName(wpfx == null ? "" : wpfx, wns, wrapperNameStr);
        }

        while (source.moreDocuments() || alternate.moreDocuments()) {
            XdmNode sdoc = null;
            XdmNode adoc = null;
View Full Code Here

    public void run() throws SaxonApiException {
        super.run();

        String value = getOption(_value).getString();
        QName algorithm = getOption(_algorithm).getQName();

        String version = null;
        if (getOption(_version) != null) {
            version = getOption(_version).getString();
        }
View Full Code Here

        String host = getOption(_host, "");
        int port = getOption(_port, 0);
        String user = getOption(_user, "");
        String password = getOption(_password, "");
        String contentBase = getOption(_contentBase, "");
        QName wrapper = XProcConstants.c_result;

        if (getOption(_wrapper) != null) {
            wrapper = getOption(_wrapper).getQName();
        }

        XdmNode queryDocument = source.read();
        String queryString = queryDocument.getStringValue();

        ContentSource contentSource;

        try {
            if ("".equals(contentBase)) {
                contentSource = ContentSourceFactory.newContentSource(host, port, user, password);
            } else {
                contentSource = ContentSourceFactory.newContentSource(host, port, user, password, contentBase);
            }
        } catch (Exception e) {
            throw new XProcException(e);
        }

        if ("basic".equals(getOption(_auth_method, ""))) {
            contentSource.setAuthenticationPreemptive(true);
        }

        Session session;

        try {
            session = contentSource.newSession ();
            Request request = session.newAdhocQuery (queryString);

            for (QName name : params.keySet()) {
                XSString value = ValueFactory.newXSString (params.get(name));
                XName xname = new XName(name.getNamespaceURI(), name.getLocalName());
                XdmVariable myVariable = ValueFactory.newVariable (xname, value);
                request.setVariable (myVariable);
            }

            ResultSequence rs = session.submitRequest (request);

            while (rs.hasNext()) {
                ResultItem rsItem = rs.next();
                XdmItem item = rsItem.getItem();

                // FIXME: This needs work...
                if (item instanceof XdmDocument || item instanceof XdmElement) {
                    XdmNode xccXML = parseString(item.asString());
                    result.write(xccXML);
                } else if (item instanceof XdmBinary) {
                    String base64 = Base64.encodeBytes(((XdmBinary) item).asBinaryData());
                    TreeWriter treeWriter = new TreeWriter(runtime);
                    treeWriter.startDocument(step.getNode().getBaseURI());
                    treeWriter.addStartElement(wrapper);

                    if (XProcConstants.NS_XPROC_STEP.equals(wrapper.getNamespaceURI())) {
                        treeWriter.addAttribute(_encoding, "base64");
                    } else {
                        treeWriter.addAttribute(c_encoding, "base64");
                    }
View Full Code Here

        }
    }

    public static QName staticError(int errno) {
        String localName = String.format("XS%04d", errno);
        return new QName("err", NS_XPROC_ERROR, localName);
    }
View Full Code Here

        return new QName("err", NS_XPROC_ERROR, localName);
    }

    public static QName dynamicError(int errno) {
        String localName = String.format("XD%04d", errno);
        return new QName("err", NS_XPROC_ERROR, localName);

    }
View Full Code Here

    }

    public static QName stepError(int errno) {
        String localName = String.format("XC%04d", errno);
        return new QName("err", NS_XPROC_ERROR, localName);
    }
View Full Code Here

TOP

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

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.