Search in sources :

Example 1 with ToolsException

use of org.expath.tools.ToolsException in project exist by eXist-db.

the class EXistTreeBuilder method outputHeaders.

@Override
public void outputHeaders(HeaderSet headers) throws HttpClientException {
    for (Header h : headers) {
        assert h.getName() != null : "Header name cannot be null";
        String name = h.getName().toLowerCase();
        try {
            startElem("header");
            attribute("name", name);
            attribute("value", h.getValue());
            // startContent();
            endElem();
        } catch (ToolsException ex) {
            throw new HttpClientException("Error building the header " + name, ex);
        }
    }
}
Also used : ToolsException(org.expath.tools.ToolsException) HttpClientException(org.expath.httpclient.HttpClientException) Header(org.apache.http.Header)

Example 2 with ToolsException

use of org.expath.tools.ToolsException in project exist by eXist-db.

the class EXistSequence method serialize.

@Override
public void serialize(final OutputStream out, final SerialParameters params) throws ToolsException {
    final Properties props = params == null ? null : makeOutputProperties(params);
    props.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");
    final String encoding = props.getProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
    try (final Writer writer = new OutputStreamWriter(new CloseShieldOutputStream(out), encoding)) {
        final XQuerySerializer xqSerializer = new XQuerySerializer(context.getBroker(), props, writer);
        xqSerializer.serialize(sequence);
    } catch (final SAXException | IOException | XPathException e) {
        throw new ToolsException("A problem occurred while serializing the node set: " + e.getMessage(), e);
    }
}
Also used : XQuerySerializer(org.exist.util.serializer.XQuerySerializer) ToolsException(org.expath.tools.ToolsException) XPathException(org.exist.xquery.XPathException) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Properties(java.util.Properties) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) CloseShieldOutputStream(org.apache.commons.io.output.CloseShieldOutputStream) SAXException(org.xml.sax.SAXException)

Example 3 with ToolsException

use of org.expath.tools.ToolsException in project exist by eXist-db.

the class EXistSequence method setOutputKey.

private void setOutputKey(Properties props, String name, Iterable<QName> value) throws ToolsException {
    if (value != null) {
        StringBuilder buf = new StringBuilder();
        for (QName qname : value) {
            if (qname.getNamespaceURI() != null) {
                throw new ToolsException("A QName with a non-null namespace not supported as a serialization param: {" + qname.getNamespaceURI() + "}" + qname.getLocalPart());
            }
            buf.append(qname.getLocalPart());
            buf.append(" ");
        }
        props.setProperty(name, buf.toString());
    }
}
Also used : ToolsException(org.expath.tools.ToolsException) QName(javax.xml.namespace.QName)

Example 4 with ToolsException

use of org.expath.tools.ToolsException in project exist by eXist-db.

the class EXistSequence method next.

@Override
public Sequence next() throws ToolsException {
    try {
        final Item item = sequenceIterator.nextItem();
        final org.exist.xquery.value.Sequence singleton = (org.exist.xquery.value.Sequence) item;
        return new EXistSequence(singleton, context);
    } catch (final XPathException xpe) {
        throw new ToolsException(xpe.getMessage(), xpe);
    }
}
Also used : Item(org.exist.xquery.value.Item) ToolsException(org.expath.tools.ToolsException) XPathException(org.exist.xquery.XPathException) Sequence(org.expath.tools.model.Sequence)

Example 5 with ToolsException

use of org.expath.tools.ToolsException in project exist by eXist-db.

the class EXistElement method noOtherNCNameAttribute.

@Override
public void noOtherNCNameAttribute(final String[] names, String[] forbidden_ns) throws ToolsException {
    if (forbidden_ns == null) {
        forbidden_ns = new String[] {};
    }
    final String[] sorted_names = sortCopy(names);
    final String[] sorted_ns = sortCopy(forbidden_ns);
    final NamedNodeMap attributes = element.getNode().getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        final Node attr = attributes.item(i);
        final String attr_name = attr.getLocalName();
        final String ns = attr.getNamespaceURI();
        if (ns != null && Arrays.binarySearch(sorted_ns, ns) >= 0) {
            if (ns.equals(HttpConstants.HTTP_CLIENT_NS_URI)) {
                throw new ToolsException("@" + attr_name + " in namespace " + ns + " not allowed on " + getDisplayName());
            }
        } else if (ns != null && !ns.isEmpty()) {
        // ignore other-namespace-attributes
        } else if (Arrays.binarySearch(sorted_names, attr.getLocalName()) < 0) {
            throw new ToolsException("@" + attr_name + " not allowed on " + getDisplayName());
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) ToolsException(org.expath.tools.ToolsException) Node(org.w3c.dom.Node)

Aggregations

ToolsException (org.expath.tools.ToolsException)5 XPathException (org.exist.xquery.XPathException)2 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Properties (java.util.Properties)1 QName (javax.xml.namespace.QName)1 CloseShieldOutputStream (org.apache.commons.io.output.CloseShieldOutputStream)1 Header (org.apache.http.Header)1 XQuerySerializer (org.exist.util.serializer.XQuerySerializer)1 Item (org.exist.xquery.value.Item)1 HttpClientException (org.expath.httpclient.HttpClientException)1 Sequence (org.expath.tools.model.Sequence)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 SAXException (org.xml.sax.SAXException)1