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();
}
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;
}
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();
}
}
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;
}
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());
}
Aggregations