Search in sources :

Example 86 with QName

use of org.exist.dom.QName in project exist by eXist-db.

the class ExceptTest method createInMemoryDocument.

private Document createInMemoryDocument() {
    final MemTreeBuilder memtree = new MemTreeBuilder();
    memtree.startDocument();
    memtree.startElement(new QName("m1", XMLConstants.NULL_NS_URI), null);
    memtree.startElement(new QName("m2", XMLConstants.NULL_NS_URI), null);
    memtree.characters("test data");
    memtree.endElement();
    memtree.endElement();
    memtree.endDocument();
    return memtree.getDocument();
}
Also used : MemTreeBuilder(org.exist.dom.memtree.MemTreeBuilder) QName(org.exist.dom.QName)

Example 87 with QName

use of org.exist.dom.QName in project exist by eXist-db.

the class CleanupTest method resetStateofInternalModule.

@Test
public void resetStateofInternalModule() throws XMLDBException, XPathException {
    final EXistXQueryService service = (EXistXQueryService) collection.getService("XQueryService", "1.0");
    final CompiledExpression compiled = service.compile(INTERNAL_MODULE_TEST);
    final Module[] modules = ((PathExpr) compiled).getContext().getModules(MODULE_NS);
    assertEquals(1, modules.length);
    final Module module = modules[0];
    module.declareVariable(new QName("VAR", MODULE_NS, "t"), "TEST");
    final InternalFunctionCall root = (InternalFunctionCall) ((PathExpr) compiled).getFirst();
    final TestModule.TestFunction func = (TestModule.TestFunction) root.getFunction();
    final ResourceSet result = service.execute(compiled);
    assertEquals(result.getSize(), 1);
    assertEquals(result.getResource(0).getContent(), "TEST");
    assertFalse(func.dummyProperty);
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) QName(org.exist.dom.QName)

Example 88 with QName

use of org.exist.dom.QName in project exist by eXist-db.

the class CleanupTest method preserveExternalVariable.

@Test
public void preserveExternalVariable() throws XMLDBException, XPathException {
    // see https://github.com/eXist-db/exist/pull/1512 and use of util:eval
    final EXistXQueryService service = (EXistXQueryService) collection.getService("XQueryService", "1.0");
    final CompiledExpression compiled = service.compile(INTERNAL_MODULE_EVAL_TEST);
    final Module[] modules = ((PathExpr) compiled).getContext().getModules(MODULE_NS);
    assertEquals(1, modules.length);
    final Module module = modules[0];
    module.declareVariable(new QName("VAR", MODULE_NS, "t"), "TEST");
    final ResourceSet result = service.execute(compiled);
    assertEquals(result.getSize(), 2);
    assertEquals(result.getResource(1).getContent(), "TEST");
    final Variable var = module.resolveVariable(new QName("VAR", MODULE_NS, "t"));
    assertNull(var);
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) QName(org.exist.dom.QName)

Example 89 with QName

use of org.exist.dom.QName in project exist by eXist-db.

the class ValueSequenceTest method sortInDocumentOrder.

@Test
public void sortInDocumentOrder() throws EXistException, PermissionDeniedException, AuthenticationException {
    final ValueSequence seq = new ValueSequence(true);
    seq.keepUnOrdered(true);
    // in-memory doc
    final MemTreeBuilder memtree = new MemTreeBuilder();
    memtree.startDocument();
    memtree.startElement(new QName("m1", XMLConstants.NULL_NS_URI), null);
    memtree.startElement(new QName("m2", XMLConstants.NULL_NS_URI), null);
    memtree.characters("test data");
    memtree.endElement();
    memtree.endElement();
    memtree.endDocument();
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final Subject admin = pool.getSecurityManager().authenticate("admin", "");
    try (final DBBroker broker = pool.get(Optional.of(admin))) {
        // persistent doc
        final Collection sysCollection = broker.getCollection(SecurityManager.SECURITY_COLLECTION_URI);
        final DocumentImpl doc = sysCollection.getDocument(broker, XmldbURI.create("config.xml"));
        final NodeProxy docProxy = new NodeProxy(doc);
        final NodeProxy nodeProxy = new NodeProxy(doc, ((NodeImpl) doc.getFirstChild()).getNodeId());
        seq.add(memtree.getDocument());
        seq.add(docProxy);
        seq.add((org.exist.dom.memtree.NodeImpl) memtree.getDocument().getFirstChild());
        seq.add(nodeProxy);
        // call sort
        seq.sortInDocumentOrder();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) MemTreeBuilder(org.exist.dom.memtree.MemTreeBuilder) QName(org.exist.dom.QName) Collection(org.exist.collections.Collection) DocumentImpl(org.exist.dom.persistent.DocumentImpl) NodeProxy(org.exist.dom.persistent.NodeProxy) BrokerPool(org.exist.storage.BrokerPool)

Example 90 with QName

use of org.exist.dom.QName in project exist by eXist-db.

the class EXistTreeBuilder method startElem.

// TODO EXPath Caller should send QName, otherwise we duplicate code and reduce reuse!
@Override
public void startElem(final String localname) throws ToolsException {
    final String prefix = HttpConstants.HTTP_CLIENT_NS_PREFIX;
    final String uri = HttpConstants.HTTP_CLIENT_NS_URI;
    builder.startElement(new QName(localname, uri, prefix), null);
}
Also used : QName(org.exist.dom.QName)

Aggregations

QName (org.exist.dom.QName)271 Test (org.junit.Test)54 Sequence (org.exist.xquery.value.Sequence)39 DBBroker (org.exist.storage.DBBroker)31 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)28 IOException (java.io.IOException)23 Document (org.w3c.dom.Document)23 DocumentSet (org.exist.dom.persistent.DocumentSet)20 Text (org.w3c.dom.Text)20 AttributesImpl (org.xml.sax.helpers.AttributesImpl)18 NameTest (org.exist.xquery.NameTest)17 XPathException (org.exist.xquery.XPathException)17 BrokerPool (org.exist.storage.BrokerPool)15 IllegalQNameException (org.exist.dom.QName.IllegalQNameException)13 Node (org.w3c.dom.Node)12 ReentrantLock (java.util.concurrent.locks.ReentrantLock)11 NodeSet (org.exist.dom.persistent.NodeSet)11 SAXException (org.xml.sax.SAXException)11 DefaultDocumentSet (org.exist.dom.persistent.DefaultDocumentSet)10 MutableDocumentSet (org.exist.dom.persistent.MutableDocumentSet)10