use of org.exist.dom.memtree.ElementImpl in project exist by eXist-db.
the class XQueryDeclareContextItemTest method declareContextItemExternalElement.
@Test
public void declareContextItemExternalElement() throws EXistException, PermissionDeniedException, XPathException, SAXException {
final String query = "xquery version \"3.0\";\n" + "declare namespace env=\"http://www.w3.org/2003/05/soap-envelope\";\n" + "declare context item as element(env:Envelope) external;\n" + "<wrap>{.}</wrap>";
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final XQuery xquery = pool.getXQueryService();
try (final DBBroker broker = pool.getBroker()) {
final MemTreeBuilder builder = new MemTreeBuilder();
builder.startDocument();
builder.startElement(new QName("Envelope", "http://www.w3.org/2003/05/soap-envelope"), null);
builder.endElement();
builder.endDocument();
final ElementImpl elem = (ElementImpl) builder.getDocument().getDocumentElement();
final Sequence result = xquery.execute(broker, query, elem);
assertEquals(1, result.getItemCount());
assertEquals("<wrap><Envelope xmlns=\"http://www.w3.org/2003/05/soap-envelope\"/></wrap>", serialize(broker, (NodeValue) result.itemAt(0)));
}
}
use of org.exist.dom.memtree.ElementImpl in project exist by eXist-db.
the class GetPermissionsTest method getPermissionsNestedXml.
/**
* See https://github.com/eXist-db/exist/issues/3231
*/
@Test
public void getPermissionsNestedXml() throws EXistException, PermissionDeniedException, XPathException {
final String query = "<outer><inner perm=\"{sm:get-permissions(xs:anyURI(\"/db\"))/sm:permission/@owner}\"/></outer>";
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.getBroker()) {
final XQuery xquery = existEmbeddedServer.getBrokerPool().getXQueryService();
final Sequence result = xquery.execute(broker, query, null);
assertEquals(1, result.getItemCount());
final Source expected = Input.fromString("<outer><inner perm=\"" + SecurityManagerImpl.SYSTEM + "\"/></outer>").build();
final Source actual = Input.fromDocument(((ElementImpl) result.itemAt(0)).getOwnerDocument()).build();
final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
assertFalse(diff.toString(), diff.hasDifferences());
}
}
use of org.exist.dom.memtree.ElementImpl in project exist by eXist-db.
the class InspectModuleTest method xqDoc_withAtSignInline.
@Ignore("https://github.com/eXist-db/exist/issues/1386")
@Test
public void xqDoc_withAtSignInline() throws PermissionDeniedException, XPathException, EXistException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final XQuery xqueryService = pool.getXQueryService();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final String query = "import module namespace inspect = \"http://exist-db.org/xquery/inspection\";\n" + "inspect:inspect-module(xs:anyURI(\"xmldb:exist://" + TEST_COLLECTION.append(TEST_MODULE).toCollectionPathURI() + "\"))\n" + "/function[@name eq \"x:fun1\"]";
final Sequence result = xqueryService.execute(broker, query, null);
assertNotNull(result);
assertEquals(1, result.getItemCount());
final Item item1 = result.itemAt(0);
assertTrue(item1 instanceof ElementImpl);
final Element function = (Element) item1;
final NodeList descriptions = function.getElementsByTagName("description");
assertEquals(1, descriptions.getLength());
assertEquals("Some description.", descriptions.item(0).getFirstChild().getTextContent());
final NodeList arguments = function.getElementsByTagName("argument");
assertEquals(0, arguments.getLength());
final NodeList returns = function.getElementsByTagName("returns");
assertEquals(1, returns.getLength());
assertEquals("taxonomy[@type = \"reign\"]", returns.item(0).getFirstChild().getTextContent());
transaction.commit();
}
}
use of org.exist.dom.memtree.ElementImpl in project exist by eXist-db.
the class InspectModuleTest method xqDoc_withParamsAndReturn.
@Test
public void xqDoc_withParamsAndReturn() throws PermissionDeniedException, XPathException, EXistException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final XQuery xqueryService = pool.getXQueryService();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final String query = "import module namespace inspect = \"http://exist-db.org/xquery/inspection\";\n" + "inspect:inspect-module(xs:anyURI(\"xmldb:exist://" + TEST_COLLECTION.append(TEST_MODULE).toCollectionPathURI() + "\"))\n" + "/function[@name eq \"x:fun2\"]";
final Sequence result = xqueryService.execute(broker, query, null);
assertNotNull(result);
assertEquals(1, result.getItemCount());
final Item item1 = result.itemAt(0);
assertTrue(item1 instanceof ElementImpl);
final Element function = (Element) item1;
final NodeList descriptions = function.getElementsByTagName("description");
assertEquals(1, descriptions.getLength());
assertEquals("Some other description.", descriptions.item(0).getFirstChild().getNodeValue());
final NodeList arguments = function.getElementsByTagName("argument");
assertEquals(2, arguments.getLength());
assertEquals("first parameter", arguments.item(0).getFirstChild().getNodeValue());
assertEquals("second parameter", arguments.item(1).getFirstChild().getNodeValue());
final NodeList returns = function.getElementsByTagName("returns");
assertEquals(1, returns.getLength());
assertEquals("our result", returns.item(0).getFirstChild().getNodeValue());
transaction.commit();
}
}
use of org.exist.dom.memtree.ElementImpl in project exist by eXist-db.
the class RESTServer method parseXML.
private ElementImpl parseXML(final BrokerPool pool, final String content, final NamespaceExtractor nsExtractor) throws SAXException, IOException {
final InputSource src = new InputSource(new StringReader(content));
final XMLReaderPool parserPool = pool.getParserPool();
XMLReader reader = null;
try {
reader = parserPool.borrowXMLReader();
final SAXAdapter adapter = new SAXAdapter();
nsExtractor.setContentHandler(adapter);
reader.setProperty(Namespaces.SAX_LEXICAL_HANDLER, adapter);
nsExtractor.setParent(reader);
nsExtractor.parse(src);
final Document doc = adapter.getDocument();
return (ElementImpl) doc.getDocumentElement();
} finally {
if (reader != null) {
parserPool.returnXMLReader(reader);
}
}
}
Aggregations