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);
}
}
}
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);
}
}
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());
}
}
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);
}
}
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());
}
}
}
Aggregations