use of org.exist.util.serializer.XQuerySerializer in project exist by eXist-db.
the class ExtTestFailureFunction method seqToString.
private String seqToString(final Sequence seq) throws IOException, XPathException, SAXException {
try (final StringWriter writer = new StringWriter()) {
final XQuerySerializer xquerySerializer = new XQuerySerializer(context.getBroker(), new Properties(), writer);
xquerySerializer.serialize(seq);
return writer.toString();
}
}
use of org.exist.util.serializer.XQuerySerializer in project exist by eXist-db.
the class ForwardReferenceTest method test1.
@Test
public void test1() throws EXistException, PermissionDeniedException, IOException, TriggerException, XPathException {
final StringSource testXquerySource = new StringSource("xquery version \"3.1\";\n" + "\n" + "import module namespace xqsuite = \"http://exist-db.org/xquery/xqsuite\"\n" + " at \"resource:org/exist/xquery/lib/xqsuite/xqsuite.xql\";\n" + "\n" + "xqsuite:suite((\n" + " inspect:module-functions(xs:anyURI(\"xmldb:exist://" + TEST_PAGES_MODULE_URI + "\"))\n" + "))");
final BrokerPool brokerPool = EXIST_EMBEDDED_SERVER.getBrokerPool();
try (final DBBroker broker = brokerPool.get(Optional.of(brokerPool.getSecurityManager().getSystemSubject()));
final Txn transaction = brokerPool.getTransactionManager().beginTransaction()) {
final String xqSuiteXmlResult = withCompiledQuery(broker, testXquerySource, compiledQuery -> {
final Sequence result = executeQuery(broker, compiledQuery);
try (final StringWriter writer = new StringWriter()) {
final XQuerySerializer xquerySerializer = new XQuerySerializer(broker, new Properties(), writer);
xquerySerializer.serialize(result);
return writer.toString();
} catch (final IOException | SAXException e) {
throw new XPathException(e);
}
});
assertNotNull(xqSuiteXmlResult);
transaction.commit();
}
}
use of org.exist.util.serializer.XQuerySerializer in project exist by eXist-db.
the class FunSerialize method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
final Properties outputProperties;
if (getArgumentCount() == 2 && !args[1].isEmpty()) {
outputProperties = getSerializationProperties(this, args[1].itemAt(0));
} else {
outputProperties = new Properties();
}
try (final StringWriter writer = new StringWriter()) {
final XQuerySerializer xqSerializer = new XQuerySerializer(context.getBroker(), outputProperties, writer);
Sequence seq = args[0];
if (xqSerializer.normalize()) {
seq = normalize(this, context, seq);
}
xqSerializer.serialize(seq);
return new StringValue(writer.toString());
} catch (final IOException | SAXException e) {
throw new XPathException(this, FnModule.SENR0001, e.getMessage());
}
}
use of org.exist.util.serializer.XQuerySerializer in project exist by eXist-db.
the class FunTrace method eval.
/*
* (non-Javadoc)
* @see org.exist.xquery.BasicFunction#eval(Sequence[], Sequence)
*/
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
// Get value for label, default to "-"
final String label = (args.length == 2) ? StringUtils.defaultIfBlank(args[1].getStringValue(), "-") : "-";
final Sequence result;
if (args[0].isEmpty()) {
// Write to log
LOG.debug("{} [{}] [{}]: {}", label, "-", Type.getTypeName(Type.EMPTY), "-");
result = Sequence.EMPTY_SEQUENCE;
} else {
// Copy all Items from input to output sequence
result = new ValueSequence();
int position = 0;
// Force adaptive serialization
final Properties props = new Properties();
props.setProperty(OutputKeys.METHOD, "adaptive");
for (final SequenceIterator i = args[0].iterate(); i.hasNext(); ) {
// Get item
final Item next = i.nextItem();
// Only write if logger is set to debug mode
if (LOG.isDebugEnabled()) {
position++;
try (final StringWriter writer = new StringWriter()) {
final XQuerySerializer xqs = new XQuerySerializer(context.getBroker(), props, writer);
xqs.serialize(next.toSequence());
// Write to log
LOG.debug("{} [{}] [{}]: {}", label, position, Type.getTypeName(next.getType()), writer.toString());
} catch (final IOException | SAXException e) {
throw new XPathException(this, e.getMessage());
}
}
// Add to result
result.add(next);
}
}
return result;
}
use of org.exist.util.serializer.XQuerySerializer in project exist by eXist-db.
the class FnDocSecurityTest method serialize.
private String serialize(final DBBroker broker, final Sequence sequence) throws IOException, XPathException, SAXException {
try (final StringWriter writer = new StringWriter()) {
final XQuerySerializer serializer = new XQuerySerializer(broker, new Properties(), writer);
serializer.serialize(sequence);
return writer.toString();
}
}
Aggregations