Package com.xmlcalabash.model

Examples of com.xmlcalabash.model.RuntimeValue


        if (runtime.getSafeMode()) {
            throw XProcException.dynamicError(21);
        }

        RuntimeValue href = getOption(_href);

        try {
            final DataStore store = runtime.getDataStore();
            String base = href.getBaseURI().toASCIIString();
            store.readEntry(href.getString(), base, "*/*", 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


        if (runtime.getSafeMode()) {
            throw XProcException.dynamicError(21);
        }

        RuntimeValue href = getOption(_href);

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

        try {
            DataStore store = runtime.getDataStore();
            URI uri = store.createList(href.getString(), href.getBaseURI().toASCIIString());
            tree.addText(uri.toASCIIString());
        } catch (FileNotFoundException e) {
            throw new XProcException(step.getNode(), "Cannot mkdir: file exists: " + href.getString());
        } catch (IOException e) {
            throw new XProcException(step.getNode(), "Mkdir failed for: " + href.getString());
        }

        tree.addEndElement();
        tree.endDocument();
View Full Code Here

        if (all && relative) {
            throw XProcException.stepError(58);
        }

        matcher = new ProcessMatch(runtime, this);
        matcher.match(source.read(), new RuntimeValue("*", step.getNode()));

        XdmNode doc = matcher.getResult();
        result.write(doc);
    }
View Full Code Here

            XdmNode doc = runtime.getConfigurer().getXMLCalabashConfigurer().loadDocument(this);
            result.write(doc);
        } catch (XProcException e) {
            logger.debug(e.getMessage(), e);
            if (err_XD0011.equals(e.getErrorCode())) {
                RuntimeValue href = getOption(_href);
                String baseURI = href.getBaseURI().toASCIIString();
                boolean validate = getOption(_dtd_validate, false);
                throw XProcException.stepError(11, "Could not load " + href.getString() + " (" + baseURI + ") dtd-validate=" + validate);
            }
            throw e;
        } catch (Exception e) {
            throw new XProcException(e);
        }
View Full Code Here

    }

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

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

        boolean failOnError = getOption(_fail_on_error, true);

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

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

        if ("file".equals(uri.getScheme())) {
            File file = new File(uri.getPath());

            if (!file.exists()) {
                if (failOnError) {
                    throw new XProcException(err_fu01);
                } else {
                    tree.addStartElement(c_error);
                    tree.addText("File not found");
                    tree.addEndElement();
                    tree.endDocument();
                    result.write(tree.getResult());
                    return;
                }
            }

            if (file.isDirectory()) {
                tree.addStartElement(c_directory);
            } else if (file.isFile()) {
                tree.addStartElement(c_file);
            } else {
                tree.addStartElement(c_other);
            }

            tree.addAttribute(_href, uri.toASCIIString());

            if (file.canRead())  { tree.addAttribute(_readable, "true"); }
            if (file.canWrite()) { tree.addAttribute(_writable, "true"); }
            if (file.isHidden()) { tree.addAttribute(_hidden, "true"); }
            tree.addAttribute(_size, "" + file.length());

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

            TimeZone tz = TimeZone.getDefault();
            long gmt = file.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)));

            tree.startContent();
            tree.addEndElement();
        } else {
            tree.addStartElement(c_uri);

            // 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

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

        String message = getOption(_message).getString();
        RuntimeValue loglevel = getOption(_log);

        if (loglevel == null) {
            System.err.println("Message: " + message);
        } else {
            String level = loglevel.getString();
            if ("error".equals(level)) {
                logger.error(message);
            } else if ("warn".equals(level)) {
                logger.warn(message);
            } else if ("info".equals(level)) {
View Full Code Here

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

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

                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);
                    }
View Full Code Here

    }

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

        RuntimeValue attrNameValue = getOption(_attribute);
        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(":")) {
            attribute = new QName(attrNameStr, attrNameValue.getNode());
        } else {
            // For Saxon 9.4, make sure there's some sort of prefix if there's a namespace;
            // Saxon will take care of resolving collisions, if necessary
            if (apfx == null && ans != null) {
                apfx = "_1";
View Full Code Here

            path = path + "/";
        }

        logger.trace(MessageFormatter.nodeMessage(step.getNode(), "path: " + path));

        RuntimeValue value = getOption(_include_filter);
        if (value != null) {
            inclFilter = value.getString();
            logger.trace(MessageFormatter.nodeMessage(step.getNode(), "include: " + inclFilter));
        }
        value = getOption(_exclude_filter);
        if (value != null) {
            exclFilter = value.getString();
            logger.trace(MessageFormatter.nodeMessage(step.getNode(), "exclude: " + exclFilter));
        }

        final boolean showExcluded = "true".equals(step.getExtensionAttribute(px_show_excluded));
View Full Code Here

TOP

Related Classes of com.xmlcalabash.model.RuntimeValue

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.