Search in sources :

Example 1 with ExtendedDOMSerializer

use of org.exist.util.serializer.ExtendedDOMSerializer in project exist by eXist-db.

the class XMLDBXUpdate method evalWithCollection.

/* (non-Javadoc)
	 * @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence)
	 */
public Sequence evalWithCollection(Collection c, Sequence[] args, Sequence contextSequence) throws XPathException {
    final NodeValue data = (NodeValue) args[1].itemAt(0);
    final StringWriter writer = new StringWriter();
    final Properties properties = new Properties();
    properties.setProperty(OutputKeys.INDENT, "yes");
    final DOMSerializer serializer = new ExtendedDOMSerializer(context.getBroker(), writer, properties);
    try {
        serializer.serialize(data.getNode());
    } catch (final TransformerException e) {
        logger.debug("Exception while serializing XUpdate document", e);
        throw new XPathException(this, "Exception while serializing XUpdate document: " + e.getMessage(), e);
    }
    final String xupdate = writer.toString();
    long modifications = 0;
    try {
        final XUpdateQueryService service = (XUpdateQueryService) c.getService("XUpdateQueryService", "1.0");
        logger.debug("Processing XUpdate request: {}", xupdate);
        modifications = service.update(xupdate);
    } catch (final XMLDBException e) {
        throw new XPathException(this, "Exception while processing xupdate: " + e.getMessage(), e);
    }
    context.getRootExpression().resetState(false);
    return new IntegerValue(modifications);
}
Also used : ExtendedDOMSerializer(org.exist.util.serializer.ExtendedDOMSerializer) NodeValue(org.exist.xquery.value.NodeValue) ExtendedDOMSerializer(org.exist.util.serializer.ExtendedDOMSerializer) DOMSerializer(org.exist.util.serializer.DOMSerializer) StringWriter(java.io.StringWriter) XUpdateQueryService(org.xmldb.api.modules.XUpdateQueryService) XPathException(org.exist.xquery.XPathException) IntegerValue(org.exist.xquery.value.IntegerValue) XMLDBException(org.xmldb.api.base.XMLDBException) Properties(java.util.Properties) TransformerException(javax.xml.transform.TransformerException)

Aggregations

StringWriter (java.io.StringWriter)1 Properties (java.util.Properties)1 TransformerException (javax.xml.transform.TransformerException)1 DOMSerializer (org.exist.util.serializer.DOMSerializer)1 ExtendedDOMSerializer (org.exist.util.serializer.ExtendedDOMSerializer)1 XPathException (org.exist.xquery.XPathException)1 IntegerValue (org.exist.xquery.value.IntegerValue)1 NodeValue (org.exist.xquery.value.NodeValue)1 XMLDBException (org.xmldb.api.base.XMLDBException)1 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)1