Search in sources :

Example 81 with QName

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

the class IdFunction method subjectToXml.

private void subjectToXml(final MemTreeBuilder builder, final Subject subject) {
    builder.startElement(new QName("username", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);
    builder.characters(subject.getName());
    builder.endElement();
    builder.startElement(new QName("groups", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);
    for (final String group : subject.getGroups()) {
        builder.startElement(new QName("group", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);
        builder.characters(group);
        builder.endElement();
    }
    builder.endElement();
}
Also used : QName(org.exist.dom.QName)

Example 82 with QName

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

the class PermissionsFunction method permissionsToXml.

private org.exist.dom.memtree.DocumentImpl permissionsToXml(final Permission permission) {
    context.pushDocumentContext();
    final MemTreeBuilder builder = context.getDocumentBuilder();
    builder.startDocument();
    builder.startElement(new QName("permission", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);
    builder.addAttribute(new QName("owner", XMLConstants.NULL_NS_URI), permission.getOwner().getName());
    builder.addAttribute(new QName("group", XMLConstants.NULL_NS_URI), permission.getGroup().getName());
    builder.addAttribute(new QName("mode", XMLConstants.NULL_NS_URI), permission.toString());
    if (permission instanceof SimpleACLPermission) {
        final SimpleACLPermission aclPermission = (SimpleACLPermission) permission;
        builder.startElement(new QName("acl", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);
        builder.addAttribute(new QName("entries", XMLConstants.NULL_NS_URI), String.valueOf(aclPermission.getACECount()));
        for (int i = 0; i < aclPermission.getACECount(); i++) {
            builder.startElement(new QName("ace", SecurityManagerModule.NAMESPACE_URI, SecurityManagerModule.PREFIX), null);
            builder.addAttribute(new QName("index", XMLConstants.NULL_NS_URI), String.valueOf(i));
            builder.addAttribute(new QName("target", XMLConstants.NULL_NS_URI), aclPermission.getACETarget(i).name());
            builder.addAttribute(new QName("who", XMLConstants.NULL_NS_URI), aclPermission.getACEWho(i));
            builder.addAttribute(new QName("access_type", XMLConstants.NULL_NS_URI), aclPermission.getACEAccessType(i).name());
            builder.addAttribute(new QName("mode", XMLConstants.NULL_NS_URI), aclPermission.getACEModeString(i));
            builder.endElement();
        }
        builder.endElement();
    }
    builder.endElement();
    builder.endDocument();
    final org.exist.dom.memtree.DocumentImpl doc = builder.getDocument();
    context.popDocumentContext();
    return doc;
}
Also used : MemTreeBuilder(org.exist.dom.memtree.MemTreeBuilder) QName(org.exist.dom.QName)

Example 83 with QName

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

the class GetRunningJobs method eval.

public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    if (!context.getSubject().hasDbaRole()) {
        throw (new XPathException(this, "Permission denied, calling user '" + context.getSubject().getName() + "' must be a DBA to get the list of running jobs"));
    }
    context.pushDocumentContext();
    try {
        final MemTreeBuilder builder = context.getDocumentBuilder();
        builder.startDocument();
        builder.startElement(new QName("jobs", NAMESPACE_URI, PREFIX), null);
        final BrokerPool brokerPool = context.getBroker().getBrokerPool();
        final ProcessMonitor monitor = brokerPool.getProcessMonitor();
        final ProcessMonitor.JobInfo[] jobs = monitor.runningJobs();
        for (ProcessMonitor.JobInfo job : jobs) {
            final Thread process = job.getThread();
            final Date startDate = new Date(job.getStartTime());
            builder.startElement(new QName("job", NAMESPACE_URI, PREFIX), null);
            builder.addAttribute(new QName("id", null, null), process.getName());
            builder.addAttribute(new QName("action", null, null), job.getAction());
            builder.addAttribute(new QName("start", null, null), new DateTimeValue(startDate).getStringValue());
            builder.addAttribute(new QName("info", null, null), job.getAddInfo().toString());
            builder.endElement();
        }
        builder.endElement();
        builder.endDocument();
        return (NodeValue) builder.getDocument().getDocumentElement();
    } finally {
        context.popDocumentContext();
    }
}
Also used : NodeValue(org.exist.xquery.value.NodeValue) MemTreeBuilder(org.exist.dom.memtree.MemTreeBuilder) DateTimeValue(org.exist.xquery.value.DateTimeValue) XPathException(org.exist.xquery.XPathException) QName(org.exist.dom.QName) ProcessMonitor(org.exist.storage.ProcessMonitor) BrokerPool(org.exist.storage.BrokerPool) Date(java.util.Date)

Example 84 with QName

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

the class SequenceType method checkType.

/**
 * Check a single item against this SequenceType.
 *
 * @param item the item to check
 * @return true, if item is a subtype of primaryType
 */
public boolean checkType(Item item) {
    Node realNode = null;
    int type = item.getType();
    if (type == Type.NODE) {
        realNode = ((NodeValue) item).getNode();
        type = realNode.getNodeType();
    }
    if (!Type.subTypeOf(type, primaryType)) {
        return false;
    }
    if (nodeName != null) {
        // TODO : how to improve performance ?
        final NodeValue nvItem = (NodeValue) item;
        QName realName = null;
        if (item.getType() == Type.DOCUMENT) {
            // it's a document... we need to get the document element's name
            final Document doc;
            if (nvItem instanceof Document) {
                doc = (Document) nvItem;
            } else {
                doc = nvItem.getOwnerDocument();
            }
            if (doc != null) {
                final Element elem = doc.getDocumentElement();
                if (elem != null) {
                    realName = new QName(elem.getLocalName(), elem.getNamespaceURI());
                }
            }
        } else {
            // get the name of the element/attribute
            realName = nvItem.getQName();
        }
        if (realName == null) {
            return false;
        }
        if (nodeName.getNamespaceURI() != null) {
            if (!nodeName.getNamespaceURI().equals(realName.getNamespaceURI())) {
                return false;
            }
        }
        if (nodeName.getLocalPart() != null) {
            return nodeName.getLocalPart().equals(realName.getLocalPart());
        }
    }
    return true;
}
Also used : QName(org.exist.dom.QName) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 85 with QName

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

the class MoveOverwriteCollectionTest method checkIndex.

private void checkIndex(final DBBroker broker, final DocumentSet docs) throws Exception {
    final StructuralIndex index = broker.getStructuralIndex();
    final NodeSelector selector = NodeProxy::new;
    NodeSet nodes;
    nodes = index.findElementsByTagName(ELEMENT, docs, new QName("test2"), selector);
    assertTrue(nodes.isEmpty());
    nodes = index.findElementsByTagName(ELEMENT, docs, new QName("test1"), selector);
    assertTrue(nodes.isEmpty());
    nodes = index.findElementsByTagName(ELEMENT, docs, new QName("test3"), selector);
    assertFalse(nodes.isEmpty());
}
Also used : StructuralIndex(org.exist.indexing.StructuralIndex) QName(org.exist.dom.QName) NodeSelector(org.exist.xquery.NodeSelector)

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