From: Loren C. <lor...@gm...> - 2011-02-23 20:53:30
|
Here is the solution that I was able to create thanks to the pointers. I do need to change this to create the document as a specific user instead of the system user. import org.apache.log4j.Logger; import org.exist.collections.Collection; import org.exist.collections.IndexInfo; import org.exist.memtree.DocumentImpl; import org.exist.memtree.MemTreeBuilder; import org.exist.security.*; import org.exist.security.SecurityManager; import org.exist.security.xacml.AccessContext; import org.exist.storage.BrokerPool; import org.exist.storage.DBBroker; import org.exist.storage.lock.Lock; import org.exist.storage.txn.TransactionManager; import org.exist.storage.txn.Txn; import org.exist.xmldb.XmldbURI; String identity = (String) stringMap.get(IDENTITY_RECORD_PARAMETER); LOG.info("Identity: " + identity); String documentCollection = identity.substring(0, identity.lastIndexOf(".xml")); LOG.info("Collection: " + documentCollection); DBBroker broker = null; TransactionManager transact = brokerPool.getTransactionManager(); Txn txn = transact.beginTransaction(); try { IndexInfo info = null; SecurityManager securityManager = brokerPool.getSecurityManager(); Subject systemSubject = securityManager.getSystemSubject(); LOG.info("SystemSubject: " + systemSubject.getName() + " : " + systemSubject.toString()); broker = brokerPool.get(systemSubject); if (broker == null) { LOG.error("No system subject"); return; } if (!isValidStatus(identity, broker)) return; DocumentImpl document = createDocument(brokerPool); LOG.info("node = " + document); if (document == null) { LOG.info("Failure to create document"); return; } Collection collection = null; try { XmldbURI collectionURI = XmldbURI.xmldbUriFor(documentCollection); XmldbURI docURI = XmldbURI.xmldbUriFor(documentCollection + "/mydoc.xml"); collection = broker.openCollection(collectionURI, Lock.WRITE_LOCK); LOG.info("collection: " + collection); if (collection == null) { transact.abort(txn); return; } info = collection.validateXMLResource(txn, broker, docURI, document); } finally { if (collection != null) collection.release(Lock.WRITE_LOCK); } collection.store(txn, broker, info, document, false); transact.commit(txn); } catch (Exception e) { LOG.error("Failure to create document", e); return; } finally { brokerPool.release(broker); } On Feb 23, 2011, at 1:41 PM, Adam Retter wrote: > On 23 February 2011 20:34, Adam Retter <ad...@ex...> wrote: >> You should be able to use code similar to that in the xmldb:store function... > > But dont use the XMLDB stuff itself, look at the underlying > implementation e.g. > org.exist.xmldb.LocalCollection::storeXMLResource(...) is a good place > to start. It basically shows you how to call > org.exist.collections.Collection::validateXMLResource(...) and > org.exist.collections.Collection::store(...) > When using the Internal API though please be very careful with your > transactions and locks. > >> On 23 February 2011 18:57, Loren Cahlander <lor...@gm...> wrote: >>> Hello folks, >>> >>> It has been a while since I was doing some Java work on eXist. I am working a JavaJob the generates an XML document through org.exist.memtree.MemTreeBuilder. I have a DBBroker and an XmldbURI for the collection and the document where I wish to store the XML document. >>> >>> Is there an existing API that is simple for me to use to do this? >>> >>> Cheers, >>> Loren >>> >>> >>> ------------------------------------------------------------------------------ >>> Free Software Download: Index, Search & Analyze Logs and other IT data in >>> Real-Time with Splunk. Collect, index and harness all the fast moving IT data >>> generated by your applications, servers and devices whether physical, virtual >>> or in the cloud. Deliver compliance at lower cost and gain new business >>> insights. http://p.sf.net/sfu/splunk-dev2dev >>> _______________________________________________ >>> Exist-development mailing list >>> Exi...@li... >>> https://lists.sourceforge.net/lists/listinfo/exist-development >>> >> >> >> >> -- >> Adam Retter >> >> eXist Developer >> { United Kingdom } >> ad...@ex... >> irc://irc.freenode.net/existdb >> > > > > -- > Adam Retter > > eXist Developer > { United Kingdom } > ad...@ex... > irc://irc.freenode.net/existdb |