Package com.xmlcalabash.core

Examples of com.xmlcalabash.core.XProcException


        result = pipe;
    }

    public void setParameter(QName name, RuntimeValue value) {
        if (!"".equals(name.getNamespaceURI())) {
            throw new XProcException(step.getNode(), "The cx:css-formatter parameters are in no namespace: " + name + " (" + name.getNamespaceURI() + ")");
        }
        options.setProperty(name.getLocalName(), value.getString());
    }
View Full Code Here


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

        String cssClass = runtime.getConfiguration().cssProcessor;
        if (cssClass == null) {
            throw new XProcException("No CSS processor class defined");
        }

        final CssProcessor provider;
        try {
            provider = (CssProcessor) Class.forName(cssClass).newInstance();
            provider.initialize(runtime,step,options);
        } catch (Exception e) {
            logger.debug(e.getMessage(), e);
            throw new XProcException(step.getNode(), "Failed to instantiate CSS provider");
        }

        while (css.moreDocuments()) {
            XdmNode style = css.read();
            provider.addStylesheet(style);
        }

        final String contentType;
        if (getOption(_content_type) != null) {
            contentType = getOption(_content_type).getString();
        } else {
            contentType = "application/pdf";
        }

        String href = getOption(_href).getString();
        String base = getOption(_href).getBaseURI().toASCIIString();

        try {
            DataStore store = runtime.getDataStore();
            URI id = store.writeEntry(href, base, contentType, new DataWriter() {
                public void store(OutputStream out) throws IOException {
                    try {
                        provider.format(source.read(),out,contentType);
                    } catch(SaxonApiException e) {
                        throw new IOException(e);
                    }
                }
            });

            TreeWriter tree = new TreeWriter(runtime);
            tree.startDocument(step.getNode().getBaseURI());
            tree.addStartElement(XProcConstants.c_result);
            tree.startContent();
            tree.addText(id.toASCIIString());
            tree.addEndElement();
            tree.endDocument();
            result.write(tree.getResult());
        } catch (XProcException e) {
            throw e;
        } catch (Exception e) {
            if (e.getCause() instanceof SaxonApiException) {
                throw (SaxonApiException) e.getCause();
            }
            throw new XProcException(step.getNode(), "Failed to style with CSS document", e);
        }
    }
View Full Code Here

            XdmNode doc = dest.getXdmNode();

            doc = S9apiUtils.removeNamespaces(runtime, doc, excludeNS, true);
            documents.add(doc);
        } catch (SaxonApiException sae) {
            throw new XProcException(sae);
        }
    }
View Full Code Here

        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

        }
    }

    public void add(XdmNode document) {
        if (closed) {
            throw new XProcException("You can't add a document to a closed DocumentSequence.");
        } else {
            S9apiUtils.assertDocument(document);

            //runtime.finest(logger, null, "Wrote " + (document == null ? "null" : document.getBaseURI()) + " to " + toString());
            documents.add(document);
View Full Code Here

                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

                        tree.startContent();
                        tree.addText(rsrc.toString());
                        tree.addEndElement();
                    }
                } else {
                    throw new XProcException("Unexpected node type in sparql results");
                }

                tree.addEndElement();
            }
View Full Code Here

        this.runtime = runtime;
        this.step = step;
        try {
            xep = new FormatterImpl(options, new FoLogger());
        } catch (ConfigurationException ce) {
            throw new XProcException("Failed to initialize XEP", ce);
        }
    }
View Full Code Here

        } else if ("application/PostScript".equals(contentType)) {
            outputFormat = "PostScript";
        } else if ("application/afp".equals(contentType)) {
            outputFormat = "AFP";
        } else {
            throw new XProcException(step.getNode(), "Unsupported content-type on p:xsl-formatter: " + contentType);
        }

        try {
            InputSource fodoc = S9apiUtils.xdmToInputSource(runtime, doc);
            SAXSource source = new SAXSource(fodoc);
            xep.render(source, new FOTarget(out, outputFormat));
        } catch (Exception e) {
            throw new XProcException(step.getNode(), "Failed to process FO document with XEP", e);
        } finally {
            xep.cleanup();
        }
    }
View Full Code Here

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

TOP

Related Classes of com.xmlcalabash.core.XProcException

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.