use of org.exist.dom.persistent.DefaultDocumentSet in project exist by eXist-db.
the class LuceneIndexTest method configureAndStore.
private DocumentSet configureAndStore(String configuration, final String[] sampleNames) throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, TriggerException, LockException, IOException {
final MutableDocumentSet docs = new DefaultDocumentSet();
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
if (configuration != null) {
final CollectionConfigurationManager mgr = pool.getConfigurationManager();
mgr.addConfiguration(transaction, broker, root, configuration);
}
for (final String sampleName : sampleNames) {
broker.storeDocument(transaction, XmldbURI.create(sampleName), new InputStreamSupplierInputSource(() -> SAMPLES.getShakespeareSample(sampleName)), MimeType.XML_TYPE, root);
docs.add(root.getDocument(broker, XmldbURI.create(sampleName)));
}
transact.commit(transaction);
}
return docs;
}
use of org.exist.dom.persistent.DefaultDocumentSet in project exist by eXist-db.
the class FunDoctype method eval.
/* (non-Javadoc)
* @see org.exist.xquery.Expression#eval(org.exist.dom.persistent.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
*/
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
final MutableDocumentSet docs = new DefaultDocumentSet();
for (int i = 0; i < getArgumentCount(); i++) {
final Sequence seq = getArgument(i).eval(contextSequence, contextItem);
for (final SequenceIterator j = seq.iterate(); j.hasNext(); ) {
final String next = j.nextItem().getStringValue();
try {
context.getBroker().getXMLResourcesByDoctype(next, docs);
} catch (final PermissionDeniedException | LockException e) {
LOG.error(e.getMessage(), e);
throw new XPathException(this, e);
}
}
}
final NodeSet result = new ExtArrayNodeSet(1);
for (final Iterator<DocumentImpl> i = docs.getDocumentIterator(); i.hasNext(); ) {
result.add(new NodeProxy(i.next(), NodeId.DOCUMENT_NODE));
}
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
use of org.exist.dom.persistent.DefaultDocumentSet in project exist by eXist-db.
the class CustomIndexTest method setUp.
@Before
public void setUp() throws DatabaseConfigurationException, EXistException, PermissionDeniedException, IOException, SAXException, CollectionConfigurationException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(root);
broker.saveCollection(transaction, root);
CollectionConfigurationManager mgr = pool.getConfigurationManager();
mgr.addConfiguration(transaction, broker, root, COLLECTION_CONFIG);
docs = new DefaultDocumentSet();
broker.storeDocument(transaction, XmldbURI.create("test_string.xml"), new StringInputSource(XML), MimeType.XML_TYPE, root);
docs.add(root.getDocument(broker, XmldbURI.create("test_string.xml")));
broker.storeDocument(transaction, XmldbURI.create("test_string2.xml"), new StringInputSource(XML2), MimeType.XML_TYPE, root);
docs.add(root.getDocument(broker, XmldbURI.create("test_string2.xml")));
transact.commit(transaction);
}
}
use of org.exist.dom.persistent.DefaultDocumentSet in project exist by eXist-db.
the class Dumper method prepare.
public void prepare(int event, DBBroker broker, Txn txn, XmldbURI documentName, DocumentImpl existingDocument) throws TriggerException {
System.out.println("\nstoring document " + documentName + " into collection " + getCollection().getURI());
if (existingDocument != null) {
System.out.println("replacing document " + ((DocumentImpl) existingDocument).getFileURI());
}
System.out.println("collection contents:");
final DefaultDocumentSet docs = new DefaultDocumentSet();
try {
getCollection().getDocuments(broker, docs);
} catch (final PermissionDeniedException | LockException e) {
throw new TriggerException(e.getMessage(), e);
}
for (final Iterator<DocumentImpl> i = docs.getDocumentIterator(); i.hasNext(); ) {
System.out.println("\t" + i.next().getFileURI());
}
}
use of org.exist.dom.persistent.DefaultDocumentSet in project exist by eXist-db.
the class FunIdRef method eval.
/**
* @see org.exist.xquery.Expression#eval(Sequence, Item)
*/
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
if (context.getProfiler().isEnabled()) {
context.getProfiler().start(this);
context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
if (contextSequence != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
}
if (contextItem != null) {
context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
}
}
if (getArgumentCount() < 1) {
throw new XPathException(this, ErrorCodes.XPST0017, "function id requires one argument");
}
if (contextItem != null) {
contextSequence = contextItem.toSequence();
}
Sequence result;
boolean processInMem = false;
final Expression arg = getArgument(0);
final Sequence idrefval = arg.eval(contextSequence);
if (idrefval.isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
String nextId;
DocumentSet docs = null;
if (getArgumentCount() == 2) {
// second argument should be a node, whose owner document will be
// searched for the id
final Sequence nodes = getArgument(1).eval(contextSequence);
if (nodes.isEmpty()) {
throw new XPathException(this, ErrorCodes.XPDY0002, "no node or context item for fn:idref");
}
if (!Type.subTypeOf(nodes.itemAt(0).getType(), Type.NODE)) {
throw new XPathException(this, ErrorCodes.XPTY0004, "fn:idref() argument is not a node");
}
NodeValue node = (NodeValue) nodes.itemAt(0);
if (node.getImplementationType() == NodeValue.IN_MEMORY_NODE) // TODO : how to enforce this ?
// If $node, or the context item if the second argument is omitted,
// is a node in a tree whose root is not a document node [err:FODC0001] is raised processInMem = true;
{
processInMem = true;
} else {
MutableDocumentSet ndocs = new DefaultDocumentSet();
ndocs.add(((NodeProxy) node).getOwnerDocument());
docs = ndocs;
}
contextSequence = node;
} else if (contextSequence == null) {
throw new XPathException(this, ErrorCodes.XPDY0002, "no context item specified");
} else if (!Type.subTypeOf(contextSequence.getItemType(), Type.NODE)) {
throw new XPathException(this, ErrorCodes.XPTY0004, "context item is not a node");
} else {
if (contextSequence.isPersistentSet()) {
docs = contextSequence.toNodeSet().getDocumentSet();
} else {
processInMem = true;
}
}
if (processInMem) {
result = new ValueSequence();
} else {
result = new ExtArrayNodeSet();
}
for (final SequenceIterator i = idrefval.iterate(); i.hasNext(); ) {
nextId = i.nextItem().getStringValue();
if (nextId.isEmpty()) {
continue;
}
if (XMLNames.isNCName(nextId)) {
if (processInMem) {
getIdRef(result, contextSequence, nextId);
} else {
getIdRef((NodeSet) result, docs, nextId);
}
}
}
}
result.removeDuplicates();
if (context.getProfiler().isEnabled()) {
context.getProfiler().end(this, "", result);
}
return result;
}
Aggregations