Package com.xmlcalabash.core

Examples of com.xmlcalabash.core.XProcException


                runtime.warning(this, doc, doc.getStringValue());
            }
        }

        if (errorCode != null) {
            throw new XProcException(errorCode, "error code?");
        }

        while (source.moreDocuments()) {
            XdmNode doc = source.read();
            logger.trace(MessageFormatter.nodeMessage(step.getNode(),
View Full Code Here


            try {
                byte[] bytes = string.getBytes("US-ASCII");
                append(bytes, bytes.length);
            } catch (UnsupportedEncodingException uee) {
                // This never happens!
                throw new XProcException(uee);
            }
        }
View Full Code Here

            if (!path.startsWith("/")) {
                path = "/" + path;
            }
            cwd = new URI("file:" + path);
        } catch (URISyntaxException use) {
            throw new XProcException(use);
        }
       
        return cwd;
    }
View Full Code Here

            writer.close();

            ByteArrayInputStream bais = new ByteArrayInputStream(writer.toString().getBytes("UTF-8"));
            sp.process(bais, doc.getBaseURI().toASCIIString());
        } catch (IOException e) {
            throw new XProcException(e);
        } catch (ParseException e) {
            throw new XProcException(e);
        }
    }
View Full Code Here

                    xformed.getUnderlyingNode().setSystemId(sysId);
                }
                resultPipe.write(xformed);
            }
        } catch (SaxonApiException sae) {
            throw new XProcException(sae);
        } catch (TransformerConfigurationException tce) {
            throw new XProcException(tce);
        } catch (TransformerException te) {
            throw new XProcException(te);
        }
    }
View Full Code Here

                        excludeURIs.add(inscopeNS.getURIForPrefix(pfx, false));
                    }
                }

                if (!found) {
                    throw new XProcException(XProcConstants.staticError(57), node, "No binding for '" + pfx + ":'");
                }
            }

            if (all) {
                Iterator<?> pfxiter = inscopeNS.iteratePrefixes();
View Full Code Here

    public void setInput(String port, ReadablePipe pipe) {
        if ("source".equals(port)) {
            sources.add(pipe);
        } else if ("pipeline".equals(port)) {
            if (pipeline != null) {
                throw new XProcException(step.getNode(), "You can't specify more than one pipeline.");
            } else {
                pipeline = pipe;
            }
        } else if ("options".equals(port)) {
            options.add(pipe);
        } else {
            throw new XProcException(step.getNode(), "Unexpected port: " + port);
        }
    }
View Full Code Here

        QName stepName = getOption(_step, (QName) null);
        XPipeline pipeline = null;
        if (XProcConstants.p_pipeline.equals(piperoot.getNodeName())
                || XProcConstants.p_declare_step.equals(piperoot.getNodeName())) {
            if (stepName != null) {
                throw new XProcException(step.getNode(), "Step option can only be used when loading a p:library");
            }
            pipeline = innerRuntime.use(pipedoc);
        } else if (XProcConstants.p_library.equals(piperoot.getNodeName())) {
            XLibrary library = innerRuntime.useLibrary(piperoot);
            if (stepName == null) {
                pipeline = library.getFirstPipeline();
            } else {
                pipeline = library.getPipeline(stepName);
            }
        }

        Set<String> inputports = pipeline.getInputs();
        Set<String> outputports = pipeline.getOutputs();

        int inputCount = 0;
        for (String port : inputports) {
            XInput input = pipeline.getInput(port);
            if (input.getParameters()) {
                // nop; it's ok for these to be unbound
            } else {
                inputCount++;
            }
        }

        boolean detailed = getOption(_detailed, false);

        if (!detailed && (inputCount > 1 || outputports.size() > 1)) {
            throw new XProcException(step.getNode(), "You must specify detailed='true' to eval pipelines with multiple inputs or outputs");
        }

        DeclareStep decl = pipeline.getDeclareStep();
        String primaryin = null;
        Iterator<String> portiter = inputports.iterator();
        while (portiter.hasNext()) {
            String port = portiter.next();
            Input input = decl.getInput(port);
            if (!input.getParameterInput() && ((inputports.size() == 1 && !input.getPrimarySet()) || input.getPrimary())) {
                primaryin = port;
            }
        }

        Hashtable<String,Vector<XdmNode>> inputs = new Hashtable<String,Vector<XdmNode>> ();
        for (ReadablePipe pipe : sources) {
            while (pipe.moreDocuments()) {
                String port = primaryin;
                XdmNode doc = pipe.read();
                XdmNode root = S9apiUtils.getDocumentElement(doc);
                if (detailed && cx_document.equals(root.getNodeName())) {
                    port = root.getAttributeValue(_port);
                    // FIXME: support exclude-inline-prefixes
                    boolean seenelem = false;
                    XdmDestination dest = new XdmDestination();
                    Vector<XdmValue> nodes = new Vector<XdmValue> ();
                    XdmSequenceIterator iter = root.axisIterator(Axis.CHILD);
                    while (iter.hasNext()) {
                        XdmNode child = (XdmNode) iter.next();
                        if (child.getNodeKind() == XdmNodeKind.ELEMENT) {
                            if (seenelem) {
                                throw new IllegalArgumentException("Not a well-formed inline document");
                            }
                            seenelem = true;
                        }
                        nodes.add(child);
                    }

                    S9apiUtils.writeXdmValue(runtime, nodes, dest, root.getBaseURI());
                    doc = dest.getXdmNode();
                }

                if (port == null) {
                    throw new XProcException(step.getNode(), "You must use cx:document for pipelines with no primary input port");
                }

                if (!inputs.containsKey(port)) {
                    inputs.put(port, new Vector<XdmNode> ());
                }

                inputs.get(port).add(doc);
            }
        }

        for (String port : inputs.keySet()) {
            if (inputports.contains(port)) {
                pipeline.clearInputs(port);
                for (XdmNode node : inputs.get(port)) {
                    pipeline.writeTo(port, node);
                }
            } else {
                throw new XProcException(step.getNode(), "Eval pipeline has no input port named '" + port + "'");
            }
        }

        if (params != null) {
            for (QName name : params.keySet()) {
                pipeline.setParameter(name, params.get(name));
            }
        }

        for (ReadablePipe pipe : options) {
            while (pipe.moreDocuments()) {
                XdmNode doc = pipe.read();
                XdmNode root = S9apiUtils.getDocumentElement(doc);

                if (!cx_options.equals(root.getNodeName())) {
                    throw new XProcException(step.getNode(), "Options port must be a cx:options document.");
                }

               
                for (XdmNode opt : new AxisNodes(runtime, root, Axis.CHILD, AxisNodes.SIGNIFICANT)) {
                    if (opt.getNodeKind() != XdmNodeKind.ELEMENT || !cx_option.equals(opt.getNodeName())) {
                        throw new XProcException(step.getNode(), "A cx:options document must only contain cx:option elements");
                    }

                    String name = opt.getAttributeValue(_name);
                    QName qname = new QName(name, opt);

                    String value = opt.getAttributeValue(_value);

                    if (name == null || value == null) {
                        throw new XProcException(step.getNode(), "A cx:option element must have name and value attributes");
                    }

                    RuntimeValue runtimeValue = new RuntimeValue(value);
                    pipeline.passOption(qname, runtimeValue);
                }
View Full Code Here

            URI baseURI = null;
            try {
                baseURI = new URI(base);
                baseURI = baseURI.resolve(href);
            } catch (URISyntaxException use) {
                throw new XProcException(use);
            }

            logger.trace(MessageFormatter.nodeMessage(step.getNode(), "XSLT secondary result document: " + baseURI));

            try {
                XdmDestination xdmResult = new XdmDestination();
                secondaryResults.put(baseURI.toASCIIString(), xdmResult);
                Receiver receiver = xdmResult.getReceiver(runtime.getProcessor().getUnderlyingConfiguration());
                receiver.setSystemId(baseURI.toASCIIString());
                return receiver;
            } catch (SaxonApiException sae) {
                throw new XProcException(sae);
            }
        }
View Full Code Here

                });
            }
        } catch (FileNotFoundException e) {
            throw XProcException.stepError(50);
        } catch (IOException ioe) {
            throw new XProcException(ioe);
        }
    }
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.