Package com.xmlcalabash.core

Examples of com.xmlcalabash.core.XProcRuntime


        if (!getPipelines().containsKey(id)) {
            return badRequest(Status.CLIENT_ERROR_NOT_FOUND, "no pipeline: " + pipelineUri(id), variant.getMediaType());
        }

        PipelineConfiguration pipeconfig = getPipelines().get(id);
        XProcRuntime runtime = pipeconfig.runtime;
        XPipeline xpipeline = pipeconfig.pipeline;

        String port = (String) getRequest().getAttributes().get("port");
        String name = (String) getRequest().getAttributes().get("param");

        QName qname = qnameFromForm(name, getQuery());

        Vector<XdmItem> nodes = new Vector<XdmItem>();

        try {
            ReadablePipe pipe = null;

            if (isXml(entity.getMediaType())) {
                XdmNode doc = runtime.parse(new InputSource(entity.getStream()));
                pipe = new ReadableDocument(runtime, doc, null, null, null);
            } else {
                pipe = new ReadableData(runtime, XProcConstants.c_data, entity.getStream(), entity.getMediaType().toString());
            }
View Full Code Here


        String port = (String) getRequest().getAttributes().get("port");

        PipelineConfiguration pipeconfig = getPipelines().get(id);
        XPipeline xpipeline = pipeconfig.pipeline;
        XProcRuntime runtime = pipeconfig.runtime;

        if (pipeconfig.ran) {
            pipeconfig.reset();
            xpipeline.reset();
        }

        if (pipeconfig.documentCount(port) == 0) {
            xpipeline.clearInputs(port);
        }
        pipeconfig.writeTo(port);

        try {
            XdmNode doc = null;

            if (isXml(entity.getMediaType())) {
                doc = runtime.parse(new InputSource(entity.getStream()));
            } else {
                ReadablePipe pipe = null;
                pipe = new ReadableData(runtime, XProcConstants.c_data, entity.getStream(), entity.getMediaType().toString());
                doc = pipe.read();
            }
View Full Code Here

        public IterationSizeCall(XProcExtensionFunctionDefinition def) {
            xdef = def;
        }

        public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
            XProcRuntime runtime = registry.getRuntime(xdef);
            XStep step = runtime.getXProcData().getStep();
            // FIXME: this can't be the best way to do this...
            // step == null in use-when
            if (step != null && !(step instanceof XCompoundStep)) {
                throw XProcException.dynamicError(23);
            }
            return new Int64Value(runtime.getXProcData().getIterationSize());
        }
View Full Code Here

            expires.setTimeInMillis(extime);
        } else {
            expires.setTimeInMillis(Long.MAX_VALUE);
        }

        XProcRuntime runtime = new XProcRuntime(getConfiguration());

        try {
            XdmNode doc = runtime.parse(uri, runtime.getStaticBaseURI().toASCIIString());
            XPipeline pipeline = runtime.use(doc);
            getPipelines().put(id, new PipelineConfiguration(runtime, pipeline, expires));
        } catch (Exception e) {
            throw new XProcException(e);
        }
    }
View Full Code Here

        }

        public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
            String relativeURI = sequences[0].head().getStringValue();

            XProcRuntime runtime = registry.getRuntime(xdef);
            XStep step = runtime.getXProcData().getStep();
            // FIXME: this can't be the best way to do this...
            // step == null in use-when
            if (step != null && !(step instanceof XCompoundStep)) {
                throw XProcException.dynamicError(23);
            }

            String baseURI = null;
            if (sequences.length > 1) {
                baseURI = sequences[1].head().getStringValue();
            } else {
                baseURI = runtime.getStaticBaseURI().toASCIIString();
                try {
                    // FIXME: TinyDocumentImpl? Surely we can do better than that!
                    Item item = xPathContext.getContextItem();
                    baseURI = ((TinyDocumentImpl) item).getBaseURI();
                } catch (Exception e) {
View Full Code Here

        public XPathVersionAvailableCall(XProcExtensionFunctionDefinition def) {
            xdef = def;
        }

        public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
            XProcRuntime runtime = registry.getRuntime(xdef);
            XStep step = runtime.getXProcData().getStep();
            // FIXME: this can't be the best way to do this...
            // step == null in use-when
            if (step != null && !(step instanceof XCompoundStep)) {
                throw XProcException.dynamicError(23);
            }
View Full Code Here

        public CwdCall(XProcExtensionFunctionDefinition def) {
            xdef = def;
        }

        public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
            XProcRuntime runtime = registry.getRuntime(xdef);
            XStep step = runtime.getXProcData().getStep();
            // FIXME: this can't be the best way to do this...
            // step == null in use-when
            if (step != null && !(step instanceof XCompoundStep)) {
                throw XProcException.dynamicError(23);
            }

            // In 0.9.20, I removed the trailing slash from cwd().
            // The community didn't like that, so I put it back.
            String cwd = runtime.getStaticBaseURI().toASCIIString();
            return new AnyURIValue(cwd);
        }
View Full Code Here

         }

        public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
             StructuredQName propertyName = null;

             XProcRuntime runtime = registry.getRuntime(xdef);
             XStep step = runtime.getXProcData().getStep();
             // FIXME: this can't be the best way to do this...
             // FIXME: And what, exactly, is this even supposed to be doing!?
             if (step != null && !(step instanceof XCompoundStep)) {
                 throw XProcException.dynamicError(23);
             }

             try {
                 String lexicalQName = sequences[0].head().getStringValue();
                 propertyName = StructuredQName.fromLexicalQName(
                      lexicalQName,
                      false,
                      false,
                      xPathContext.getConfiguration().getNameChecker(),
                      staticContext.getNamespaceResolver());
             } catch (XPathException e) {
                 if (e.getErrorCodeLocalPart()==null || e.getErrorCodeLocalPart().equals("FOCA0002")
                         || e.getErrorCodeLocalPart().equals("FONS0004")) {
                     e.setErrorCode("XTDE1390");
                 }
                 throw e;
             }

             String uri = propertyName.getURI();
             String local = propertyName.getLocalPart();
             String value = "";

             if (uri.equals(XProcConstants.NS_XPROC)) {
                 if ("episode".equals(local)) {
                     value = runtime.getEpisode();
                 } else if ("language".equals(local)) {
                     value = runtime.getLanguage();
                 } else if ("product-name".equals(local)) {
                     value = runtime.getProductName();
                 } else if ("product-version".equals(local)) {
                     value = runtime.getProductVersion();
                 } else if ("vendor".equals(local)) {
                     value = runtime.getVendor();
                 } else if ("vendor-uri".equals(local)) {
                     value = runtime.getVendorURI();
                 } else if ("version".equals(local)) {
                     value = runtime.getXProcVersion();
                 } else if ("xpath-version".equals(local)) {
                     value = runtime.getXPathVersion();
                 } else if ("psvi-supported".equals(local)) {
                     value = runtime.getPSVISupported() ? "true" : "false";
                 }
             } else if (uri.equals(XProcConstants.NS_CALABASH_EX)) {
                 if ("transparent-json".equals(local)) {
                     value = runtime.transparentJSON() ? "true" : "false";
                 } else if ("json-flavor".equals(local)) {
                     value = runtime.jsonFlavor();
                 } else if ("general-values".equals(local)) {
                     value = runtime.getAllowGeneralExpressions() ? "true" : "false";
                 } else if ("xpointer-on-text".equals(local)) {
                     value = runtime.getAllowXPointerOnText() ? "true" : "false";
                 } else if ("use-xslt-1.0".equals(local) || "use-xslt-10".equals(local)) {
                     value = runtime.getUseXslt10Processor() ? "true" : "false";
                 } else if ("html-serializer".equals(local)) {
                     value = runtime.getHtmlSerializer() ? "true" : "false";
                 } else if ("saxon-version".equals(local)) {
                     value = runtime.getConfiguration().getProcessor().getSaxonProductVersion();
                 } else if ("saxon-edition".equals(local)) {
                     value = runtime.getConfiguration().saxonProcessor;
                 }
             }

             return new StringValue(value);
         }
View Full Code Here

        if (!getPipelines().containsKey(id)) {
            return badRequest(Status.CLIENT_ERROR_NOT_FOUND, "no pipeline: " + pipelineUri(id), variant.getMediaType());
        }

        PipelineConfiguration pipeconfig = getPipelines().get(id);
        XProcRuntime runtime = pipeconfig.runtime;
        XPipeline xpipeline = pipeconfig.pipeline;

        String name = (String) getRequest().getAttributes().get("option");
        QName qname = qnameFromForm(name, getQuery());

        Vector<XdmItem> nodes = new Vector<XdmItem>();

        try {
            ReadablePipe pipe = null;

            if (isXml(entity.getMediaType())) {
                XdmNode doc = runtime.parse(new InputSource(entity.getStream()));
                pipe = new ReadableDocument(runtime, doc, null, null, null);
            } else {
                pipe = new ReadableData(runtime, XProcConstants.c_data, entity.getStream(), entity.getMediaType().toString());
            }
View Full Code Here

        return converted;
    }

    protected String serialize(XdmNode doc, MediaType type) {
        XProcRuntime runtime = getGlobalRuntime();
        String format = "text";

        if (MediaType.TEXT_HTML.equals(type)) {
            format = "html";
        } else if (MediaType.APPLICATION_XML.equals(type)) {
            format = "xml";
        } else if (MediaType.APPLICATION_JSON.equals(type)) {
            format = "json";
        }

        if (xsl() != null) {
            XdmDestination result = null;
            try {
                XsltCompiler compiler = runtime.getProcessor().newXsltCompiler();
                XsltExecutable exec = compiler.compile(xsl().asSource());
                XsltTransformer transformer = exec.load();
                transformer.setParameter(_format, new XdmAtomicValue(format));
                transformer.setInitialContextNode(doc);
                result = new XdmDestination();
View Full Code Here

TOP

Related Classes of com.xmlcalabash.core.XProcRuntime

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.