Examples of XPipeline


Examples of com.xmlcalabash.runtime.XPipeline

                tree.startContent();
                tree.addText(port);
                tree.addEndElement();
            }
        } else {
            XPipeline xpipeline = pipeconfig.pipeline;
            DeclareStep pipeline = xpipeline.getDeclareStep();

            for (String port : pipeconfig.inputPorts) {
                tree.addStartElement(pr_input);
                if (port.equals(pipeconfig.definput)) {
                    tree.addAttribute(_primary, "true");
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

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

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

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

        try {
            if (MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), true)) {
                processMultipartForm(pipeconfig, entity, variant);
            } else {
                if (pipeconfig.definput == null) {
                    return badRequest(Status.CLIENT_ERROR_BAD_REQUEST, "No primary input port", variant.getMediaType());
                }
                if (pipeconfig.documentCount(pipeconfig.definput) == 0) {
                    xpipeline.clearInputs(pipeconfig.definput);
                }
                pipeconfig.writeTo(pipeconfig.definput);

                XdmNode doc = null;

                if (isXml(entity.getMediaType())) {
                    doc = runtime.parse(new InputSource(entity.getStream()));
                    logger.debug("Posting XML document to " + pipeconfig.definput + " for " + id);
                } else {
                    ReadablePipe pipe = null;
                    pipe = new ReadableData(runtime, XProcConstants.c_data, entity.getStream(), entity.getMediaType().toString());
                    doc = pipe.read();
                    logger.debug("Posting non-XML document to " + pipeconfig.definput + " for " + id);
                }

                xpipeline.writeTo(pipeconfig.definput, doc);

                HashMap<String, String> nsBindings = bindingsFromForm(getQuery());
                HashMap<String, String> options = convertFormStrings(getQuery());

                DeclareStep pipeline = xpipeline.getDeclareStep();
                for (String fieldName : options.keySet()) {
                    RuntimeValue value = new RuntimeValue(options.get(fieldName));

                    if (fieldName.startsWith("-p")) {
                        fieldName = fieldName.substring(2);

                        String port= null;
                        Matcher matcher = portRE.matcher(fieldName);
                        if (matcher.matches()) {
                            port = matcher.group(1);
                            fieldName = matcher.group(2);
                        }

                        if (port == null) {
                            // Figure out the default parameter port
                            for (String iport : xpipeline.getInputs()) {
                                com.xmlcalabash.model.Input input = pipeline.getInput(iport);
                                if (input.getParameterInput() && input.getPrimary()) {
                                    port = iport;
                                }
                            }
                        }

                        if (port == null) {
                            throw new XProcException("No primary parameter input port.");
                        }

                        logger.debug("Parameter " + fieldName + "=" + value.getString() + " for " + id);

                        QName qname = qnameFromForm(fieldName, nsBindings);
                        xpipeline.setParameter(port, qname, value);
                        pipeconfig.setParameter(qname, value.getString());
                    } else {
                        logger.debug("Option " + fieldName + "=" + value.getString() + " for " + id);

                        QName qname = qnameFromForm(fieldName, nsBindings);
                        xpipeline.passOption(qname, value);
                        pipeconfig.setGVOption(qname);
                    }
                }
            }
        } catch (Exception e) {
            pipeconfig.reset();
            xpipeline.reset();
            return badRequest(Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage(), variant.getMediaType());
        }

        return runPipeline(id);
    }
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

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

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

        pipeconfig.reset();
        xpipeline.reset();

        return okResponse("Pipeline reset", variant.getMediaType());
    }
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

            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());
            }

            while (pipe.moreDocuments()) {
                XdmNode doc = pipe.read();
                nodes.add(doc);
            }
        } catch (Exception e) {
            throw new XProcException(e);
        }

        String message = "Parameter added: " + qname.toString();

        RuntimeValue value = new RuntimeValue(null, nodes, null, null);
        xpipeline.setParameter(port, qname, value);
        pipeconfig.setGVParameter(qname);

        return okResponse(message, variant.getMediaType(), Status.SUCCESS_ACCEPTED);
    }
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

        }

        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();
            }
            xpipeline.writeTo(port, doc);
        } catch (Exception e) {
            throw new XProcException(e);
        }

        return okResponse("Added document to the '" + port + "' port.", variant.getMediaType(), Status.SUCCESS_ACCEPTED);
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

        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

Examples of com.xmlcalabash.runtime.XPipeline

                    if (touts.size() > 0) {
                        XdmNode tdoc = touts.remove(0);
                        XdmNode pdoc = pipe.read();

                        if (t.ignoreWS) {
                            XPipeline pppipe = runtime.use(prettyPrint);
                            pppipe.writeTo("source", tdoc);
                            pppipe.run();
                            ReadablePipe rpipe = pppipe.readFrom("result");
                            tdoc = rpipe.read();

                            pppipe.reset();
                            pppipe.writeTo("source", pdoc);
                            pppipe.run();
                            rpipe = pppipe.readFrom("result");
                            pdoc = rpipe.read();
                        }

                        pres.add(pdoc);
                        pexp.add(tdoc);
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

                                                   Hashtable<String, Vector<XdmNode>> inputs,
                                                   Hashtable<String, Vector<XdmNode>> outputs,
                                                   Hashtable<QName, String> parameters,
                                                   Hashtable<QName, String> options) throws SaxonApiException {

        XPipeline xpipeline = runtime.use(pipeline);

        if (inputs != null) {
            for (String port : inputs.keySet()) {
                if (!xpipeline.getInputs().contains(port)) {
                    throw new UnsupportedOperationException("Error: Test sets input port that doesn't exist: " + port);
                }
                xpipeline.clearInputs(port);
                for (XdmNode node : inputs.get(port)) {
                    xpipeline.writeTo(port, node);
                }
            }
        }

        if (parameters != null) {
            for (QName name : parameters.keySet()) {
                xpipeline.setParameter(name, new RuntimeValue(parameters.get(name)));
            }
        }

        if (options != null) {
            for (QName name : options.keySet()) {

                // HACK HACK HACK!
                RuntimeValue v;
                if (_path.equals(name)) {
                    v = new RuntimeValue("file:///home/www/tests.xproc.org/tests/required/" + options.get(name));
                } else {
                    v = new RuntimeValue(options.get(name));
                }

                xpipeline.passOption(name, v);
            }
        }

        try {
            xpipeline.run();
        } catch (XProcException e) {
            logger.debug(e.getMessage(), e);
            throw e;
        } catch (Throwable e) {
            logger.debug(e.getMessage(), e);
            throw new XProcException(e);
        }

        Hashtable<String, ReadablePipe> pipeoutputs = new Hashtable<String, ReadablePipe> ();

        Set<String> pipeouts = xpipeline.getOutputs();
        for (String port : pipeouts) {
            if (!port.startsWith("!")) {
                ReadablePipe rpipe = xpipeline.readFrom(port);
                rpipe.canReadSequence(true);
                pipeoutputs.put(port, rpipe);
            }
        }
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

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

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

        String port = (String) getRequest().getAttributes().get("port");
        if (port == null) {
            // Figure out the default parameter port
            DeclareStep pipeline = xpipeline.getDeclareStep();
            for (String iport : xpipeline.getInputs()) {
                com.xmlcalabash.model.Input input = pipeline.getInput(iport);
                if (input.getParameterInput() && input.getPrimary()) {
                    port = iport;
                }
            }
        }

        if (port == null) {
            return badRequest(Status.CLIENT_ERROR_BAD_REQUEST, "No primary parameter input port", variant.getMediaType());
        }

        String message = "Parameters added: ";
        boolean first = true;

        HashMap<QName,String> params = convertForm(getQuery());

        for (QName name : params.keySet()) {
            RuntimeValue value = new RuntimeValue(params.get(name), null, null);
            xpipeline.setParameter(port, name, value);
            pipeconfig.setParameter(name, params.get(name));
            if (!first) {
                message += ", ";
            }
            message += name;
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

            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());
            }

            while (pipe.moreDocuments()) {
                XdmNode doc = pipe.read();
                nodes.add(doc);
            }
        } catch (Exception e) {
            throw new XProcException(e);
        }

        String message = "Option added: " + qname.toString();

        RuntimeValue value = new RuntimeValue(null, nodes, null, null);
        xpipeline.passOption(qname, value);
        pipeconfig.setGVOption(qname);

        return okResponse(message, variant.getMediaType(), Status.SUCCESS_ACCEPTED);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.