Examples of XPipeline


Examples of com.xmlcalabash.runtime.XPipeline

        return new StringRepresentation(serialize(tree.getResult(), type), type);
    }

    protected Representation runPipeline(String id) {
        PipelineConfiguration pipeconfig = getPipelines().get(id);
        XPipeline pipeline = pipeconfig.pipeline;

        try {
            pipeline.run();
            pipeconfig.ran = true;

            for (String port : pipeline.getOutputs()) {
                Vector<XdmNode> nodes = new Vector<XdmNode> ();
                ReadablePipe rpipe = pipeline.readFrom(port);
                while (rpipe.moreDocuments()) {
                    nodes.add(rpipe.read());
                }
                pipeconfig.outputs.put(port, nodes);
            }
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

        }
    }

    protected Representation getOutput(PipelineConfiguration pipeconfig, String port) {
        XProcConfiguration config = getConfiguration();
        XPipeline pipeline = pipeconfig.pipeline;
        XProcRuntime runtime = pipeconfig.runtime;
        Serialization serial = pipeline.getSerialization(port);

        if (serial == null) {
            // Use the configuration options
            // FIXME: should each of these be considered separately?
            // FIXME: should there be command-line options to override these settings?
            serial = new Serialization(runtime, pipeline.getNode()); // The node's a hack
            for (String name : config.serializationOptions.keySet()) {
                String value = config.serializationOptions.get(name);

                if ("byte-order-mark".equals(name)) serial.setByteOrderMark("true".equals(value));
                if ("escape-uri-attributes".equals(name)) serial.setEscapeURIAttributes("true".equals(value));
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

    }

    protected Representation processMultipartForm(PipelineConfiguration pipeconfig, Representation entity, Variant variant) {
        String id = (String) getRequest().getAttributes().get("id");

        XPipeline xpipeline = pipeconfig.pipeline;
        XProcRuntime runtime = pipeconfig.runtime;

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

        String message = "";

        HashMap<String,String> nameValuePairs = new HashMap<String,String> ();
        HashMap<String,String> nsBindings = new HashMap<String,String> ();

        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setSizeThreshold(100240);

        RestletFileUpload upload = new RestletFileUpload(factory);
        List<FileItem> items;
        try {
            items = upload.parseRequest(getRequest());

            File file = null;
            String filename = null;

            for (final Iterator<FileItem> it = items.iterator(); it.hasNext(); ) {
                FileItem fi = it.next();
                String fieldName = fi.getFieldName();
                String name = fi.getName();

                if (name == null) {
                    Matcher matcher = xmlnsRE.matcher(fieldName);
                    if (matcher.matches()) {
                        nsBindings.put(matcher.group(1), new String(fi.get(), "utf-8"));
                    } else {
                        nameValuePairs.put(fieldName, new String(fi.get(), "utf-8"));
                    }
                } else {
                    String port = fieldName;

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

                    try {
                        XdmNode doc = null;
                        MediaType m = new MediaType(fi.getContentType());

                        if (isXml(m)) {
                            doc = runtime.parse(new InputSource(fi.getInputStream()));
                            logger.debug("Posting XML document to " + port + " for " + id);
                        } else {
                            ReadablePipe pipe = null;
                            pipe = new ReadableData(runtime, XProcConstants.c_data, fi.getInputStream(), fi.getContentType());
                            doc = pipe.read();
                            logger.debug("Posting non-XML document to " + port + " for " + id);
                        }
                        xpipeline.writeTo(port, doc);
                    } catch (Exception e) {
                        throw new XProcException(e);
                    }

                    message += "Posted input to port '" + port + "'\n";
                }
            }


            DeclareStep pipeline = xpipeline.getDeclareStep();
            for (String fieldName : nameValuePairs.keySet()) {
                RuntimeValue value = new RuntimeValue(nameValuePairs.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());
                    message += "Parameter " + qname.getClarkName() + "=" + value.getString() + "\n";
                } else {
                    logger.debug("Option " + fieldName + "=" + value.getString() + " for " + id);

                    QName qname = qnameFromForm(fieldName, nsBindings);
                    xpipeline.passOption(qname, value);
                    pipeconfig.setGVOption(qname);
                    message += "Option " + qname.getClarkName() + "=" + value.getString() + "\n";
                }
            }

            return okResponse(message, variant.getMediaType(), Status.SUCCESS_OK);
        } catch (XProcException e) {
            pipeconfig.reset();
            xpipeline.reset();
            throw e;
        } catch (Exception e) {
            pipeconfig.reset();
            xpipeline.reset();
            throw new XProcException(e);
        }
    }
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

        if (errorCode != null) {
            throw new XProcException(errorCode, errorNode, errorMessage);
        }

        xpipeline = new XPipeline(this, pipeline, root);
        xpipeline.instantiate(decl);

        if (errorCode != null) {
            throw new XProcException(errorCode, errorMessage);
        }
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

        if (errorCode != null) {
            throw new XProcException(errorCode, errorMessage);
        }

        xpipeline = new XPipeline(this, pipeline, root);
        xpipeline.instantiate(decl);

        if (errorCode != null) {
            throw new XProcException(errorCode, errorMessage);
        }
View Full Code Here

Examples of com.xmlcalabash.runtime.XPipeline

        XdmNode libDoc = runLoader(library, loaderURI, data);
        return useLibrary(libDoc);
    }

    private XdmNode runLoader(Input pipeline, String loaderURI, boolean data) throws SaxonApiException {
        XPipeline loader = null;

        try {
            loader = _load(new Input(loaderURI));
        } catch (SaxonApiException sae) {
            error(sae);
            throw sae;
        } catch (XProcException xe) {
            error(xe);
            throw xe;
        } catch (IOException ioe) {
            error(ioe);
            throw new XProcException(ioe);
        }

        XdmNode pipeDoc = null;
        switch (pipeline.getKind()) {
            case URI:
                if (data) {
                    ReadableData rdata = new ReadableData(this, XProcConstants.c_result, getStaticBaseURI().resolve(pipeline.getUri()).toASCIIString(), "text/plain");
                    pipeDoc = rdata.read();
                } else {
                    pipeDoc = parse(pipeline.getUri(), getStaticBaseURI().toASCIIString());
                }
                break;

            case INPUT_STREAM:
                if (data) {
                    ReadableData rdata = new ReadableData(this, XProcConstants.c_result, pipeline.getInputStream(), "text/plain");
                    pipeDoc = rdata.read();
                } else {
                    pipeDoc = parse(new InputSource(pipeline.getInputStream()));
                }
                break;

            default:
                throw new UnsupportedOperationException(format("Unsupported pipeline kind '%s'", pipeline.getKind()));
        }

        loader.clearInputs("source");
        loader.writeTo("source", pipeDoc);
        loader.run();
        ReadablePipe xformed = loader.readFrom("result");
        pipeDoc = xformed.read();

        reset();
        return pipeDoc;
    }
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.