Examples of RuntimeValue


Examples of com.xmlcalabash.model.RuntimeValue

    }

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

        RuntimeValue test = getOption(_test);
        initialOnly = getOption(_initial_only, false);
        boolean stillOk = true;

        int count = 0;
        while (source.moreDocuments()) {
            count++;
            source.read();
        }
        source.resetReader();

        DocumentSequenceIterator xsi = new DocumentSequenceIterator(); // See below
        xsi.setLast(count);

        XPathCompiler xcomp = runtime.getProcessor().newXPathCompiler();
        xcomp.setBaseURI(step.getNode().getBaseURI());

        for (String prefix : test.getNamespaceBindings().keySet()) {
            xcomp.declareNamespace(prefix, test.getNamespaceBindings().get(prefix));
        }

        XPathExecutable xexec = xcomp.compile(test.getString());

        // From Michael Kay: http://markmail.org/message/vkb2vaq2miylgndu
        //
        // Underneath the s9api XPathExecutable is a net.sf.saxon.sxpath.XPathExpression.
View Full Code Here

Examples of com.xmlcalabash.model.RuntimeValue

    }

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

        RuntimeValue attrNameValue = getOption(_attribute_name);
        String attrNameStr = attrNameValue.getString();
        String apfx = getOption(_attribute_prefix, (String) null);
        String ans = getOption(_attribute_namespace, (String) null);

        if (apfx != null && ans == null) {
            throw XProcException.dynamicError(34, "You can't specify a prefix without a namespace");
        }

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

        if (attrNameStr.contains(":")) {
            attrName = new QName(attrNameStr, attrNameValue.getNode());
        } else {
            attrName = new QName(apfx == null ? "" : apfx, ans, attrNameStr);
        }

        attrValue = getOption(_attribute_value).getString();
View Full Code Here

Examples of com.xmlcalabash.model.RuntimeValue

            portOutputs.put(port, output);
        }

        for (QName optname : config.options.keySet()) {
            RuntimeValue value = new RuntimeValue(config.options.get(optname), null, null);
            pipeline.passOption(optname, value);
        }

        for (QName optname : userArgs.getOptionNames()) {
            RuntimeValue value = new RuntimeValue(userArgs.getOption(optname), null, null);
            pipeline.passOption(optname, value);
        }

        pipeline.run();
View Full Code Here

Examples of com.xmlcalabash.model.RuntimeValue

    }

    private void setParametersOnPipeline(XPipeline pipeline, String port, Map<QName, String> parameters) {
        if ("*".equals(port)) {
            for (QName name : parameters.keySet()) {
                pipeline.setParameter(name, new RuntimeValue(parameters.get(name)));
            }
        } else {
            for (QName name : parameters.keySet()) {
                pipeline.setParameter(port, name, new RuntimeValue(parameters.get(name)));
            }
        }
    }
View Full Code Here

Examples of com.xmlcalabash.model.RuntimeValue

            logger.trace("Error step read empty");
        } else {
            logger.trace("Error step read " + doc.getDocumentURI());
        }

        RuntimeValue codeNameValue = getOption(_code);
        String codeNameStr = codeNameValue.getString();
        String cpfx = getOption(_code_prefix, (String) null);
        String cns = getOption(_code_namespace, (String) null);

        if (cpfx == null && cns != null) {
            cpfx = "ERR";
        }

        if (cpfx != null && cns == null) {
            throw XProcException.dynamicError(34, "You can't specify a prefix without a namespace");
        }

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

        QName errorCode = null;
        if (codeNameStr.contains(":")) {
            errorCode = new QName(codeNameStr, codeNameValue.getNode());
        } else {
            errorCode = new QName(cpfx == null ? "" : cpfx, cns, codeNameStr);
        }

        cpfx = errorCode.getPrefix();
View Full Code Here

Examples of com.xmlcalabash.model.RuntimeValue

    }

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

        RuntimeValue href = getOption(_href);
        URI uri = href.getBaseURI().resolve(href.getString());

        logger.trace(MessageFormatter.nodeMessage(step.getNode(), "Checking uri-info for " + uri));

        TreeWriter tree = new TreeWriter(runtime);
        tree.startDocument(step.getNode().getBaseURI());
        tree.addStartElement(c_uriinfo);

        if (uri.getScheme().equals("file")) {
            String fn = href.getString();
            if (fn.startsWith("file:")) {
                fn = fn.substring(5);
                if (fn.startsWith("///")) {
                    fn = fn.substring(2);
                }
            }

            File f = new File(fn);

            tree.addAttribute(_href, href.getString());
            tree.addAttribute(_exists, f.exists() ? "true" : "false");
            tree.addAttribute(_readable, f.canRead() ? "true" : "false");

            if (f.exists()) {
                tree.addAttribute(_writable, f.canWrite() ? "true" : "false");
                tree.addAttribute(_size, "" + f.length());
                tree.addAttribute(_absolute, f.isAbsolute() ? "true" : "false");
                tree.addAttribute(_directory, f.isDirectory() ? "true" : "false");
                tree.addAttribute(_hidden, f.isHidden() ? "true" : "false");
                tree.addAttribute(_file, f.isFile() ? "true" : "false");

                GregorianCalendar cal = new GregorianCalendar();
                cal.setTimeInMillis(f.lastModified());

                TimeZone tz = TimeZone.getDefault();
                long gmt = f.lastModified() - tz.getRawOffset();
                if (tz.useDaylightTime() && tz.inDaylightTime(cal.getTime())) {
                    gmt -= tz.getDSTSavings();
                }
                cal.setTimeInMillis(gmt);
                tree.addAttribute(_last_modified, String.format("%1$04d-%2$02d-%3$02dT%4$02d:%5$02d:%6$02dZ",
                        cal.get(Calendar.YEAR), cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH),
                        cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND)));
            } else {
                String path = f.getAbsolutePath();
                int slash = path.lastIndexOf("/");
                path = path.substring(0,slash);
                File parent = new File(path);
                tree.addAttribute(_writable, parent.canWrite() ? "true" : "false");
            }

            tree.addAttribute(_absolute_path, f.getAbsolutePath());
            tree.addAttribute(_uri, f.toURI().toASCIIString());

            try {
                String cp = f.getCanonicalPath();
                tree.addAttribute(_canonical_path, cp);
            } catch (Exception e) {
                // nevermind
            }
            tree.startContent();
            tree.addEndElement();
        } else {
            // Let's try HTTP
            HttpRequest httpReq = new HttpRequest(runtime, step);
            Pipe inputPipe = new Pipe(runtime);
            Pipe outputPipe = new Pipe(runtime);
            httpReq.setInput("source", inputPipe);
            httpReq.setOutput("result", outputPipe);

            TreeWriter req = new TreeWriter(runtime);
            req.startDocument(step.getNode().getBaseURI());
            req.addStartElement(XProcConstants.c_request);
            req.addAttribute(_method, "HEAD");
            req.addAttribute(_href, uri.toASCIIString());
            req.addAttribute(_status_only, "true");
            req.addAttribute(_detailed, "true");

            for (QName name : new QName[] {_username, _password, _auth_method, _send_authorization } ) {
                RuntimeValue v = getOption(name);
                if (v != null) { req.addAttribute(name, v.getString()); }
            }
           
            req.startContent();
            req.addEndElement();
            req.endDocument();
View Full Code Here

Examples of com.xmlcalabash.model.RuntimeValue

            throw XProcException.dynamicError(21);
        }

        boolean failOnError = getOption(_fail_on_error, true);

        RuntimeValue href = getOption(_href);

        try {
            final DataStore store = runtime.getDataStore();
            store.readEntry(href.getString(), href.getBaseURI().toASCIIString(), "*/*", null, new DataReader() {
                public void load(URI id, String media, final InputStream src, long len)
                        throws IOException {
                    RuntimeValue target = getOption(_target);
                    URI uri = store.writeEntry(target.getString(), target.getBaseURI().toASCIIString(), media, new DataWriter() {
                        public void store(OutputStream dst) throws IOException {
                            byte[] buffer = new byte[bufsize];
                            int read = src.read(buffer, 0, bufsize);
                            while (read >= 0) {
                                dst.write(buffer, 0, read);
View Full Code Here

Examples of com.xmlcalabash.model.RuntimeValue

        boolean failOnError = getOption(_fail_on_error, true);
        int count = getOption(_count, 10);
        final boolean tail = count >= 0;
        final int maxCount = count >= 0 ? count : -count;

        RuntimeValue href = getOption(_href);

        try {
            DataStore store = runtime.getDataStore();
            store.readEntry(href.getString(), href.getBaseURI().toASCIIString(), "text/*, */*", null, new DataReader() {
                public void load(URI id, String media, InputStream content, long len)
                        throws IOException {
                    TreeWriter tree = new TreeWriter(runtime);
                    tree.startDocument(id);
                    tree.addStartElement(XProcConstants.c_result);
                    tree.startContent();

                    Reader rdr = new InputStreamReader(content);
                    BufferedReader brdr = new BufferedReader(rdr);
                    Vector<String> lines = new Vector<String> ();
                    try {
                        int count = 0;
                        String line = brdr.readLine();
                        while (line != null) {
                            count++;
                            lines.add(line);

                            if (count > maxCount) {
                                line = lines.remove(0);
                                if (!tail) {
                                    tree.addStartElement(c_line);
                                    tree.startContent();
                                    tree.addText(line);
                                    tree.addEndElement();
                                    tree.addText("\n");
                                }
                            }

                            line = brdr.readLine();
                        }
                    } finally {
                        brdr.close();
                    }

                    if (tail) {
                        for (String lline : lines) {
                            tree.addStartElement(c_line);
                            tree.startContent();
                            tree.addText(lline);
                            tree.addEndElement();
                            tree.addText("\n");
                        }
                    }

                    tree.addEndElement();
                    tree.endDocument();

                    result.write(tree.getResult());
                }
            });
        } catch (FileNotFoundException fnfe) {
            URI uri = href.getBaseURI().resolve(href.getString());
            throw new XProcException(href.getNode(), "Cannot read: file does not exist: " + uri.toASCIIString());
        } catch (IOException ioe) {
            throw new XProcException(ioe);
        }
    }
View Full Code Here

Examples of com.xmlcalabash.model.RuntimeValue

        }

        boolean recursive = getOption(_recursive, false);
        boolean fail_on_error = getOption(_fail_on_error, true);
       
        RuntimeValue href = getOption(_href);
        String base = href.getBaseURI().toASCIIString();
        URI uri = href.getBaseURI().resolve(href.getString());

        TreeWriter tree = new TreeWriter(runtime);
        tree.startDocument(step.getNode().getBaseURI());
        tree.addStartElement(XProcConstants.c_result);
        tree.startContent();
View Full Code Here

Examples of com.xmlcalabash.model.RuntimeValue

        // Do nothing
    }

    public XdmNode loadDocument(Load load) {
        boolean      validate = load.getOption(_dtd_validate, false);
        RuntimeValue href     = load.getOption(_href);
        String       base     = href.getBaseURI().toASCIIString();
        if (runtime.getSafeMode() && base.startsWith("file:")) {
            throw XProcException.dynamicError(21);
        }
        return runtime.parse(href.getString(), base, validate);
    }
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.