You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christoph Hermann <ch...@tu-clausthal.de> on 2005/07/05 16:34:17 UTC
Integration of Cocoon and eXist - user/password accessing database
Hello,
i'm trying to integrate Cocoon and eXist XML DB. So far it works fine, i
can edit and save a document through cforms and the bindings, but this
is only working if i make the documents in my collection
world-writable/updatable.
So my question is: where do i specify which user/password is used when
accessing the eXist database (i would like to do this in flow (if
possible) alternatively which configuration file handles this)?
What i basically do is the following (in flow):
---snip---
var form = new Form("cforms/definition/test_def.xml");
var bindingURI = "cforms/binding/test_bind.xml";
form.createBinding(bindingURI);
var docURI = "xmldb:exist:///db/test/test.xml";
var document = loadDocument(docURI);
form.load(document);
form.showForm("test-display-pipeline");
form.save(document);
saveDocument(document, docURI);
---snap---
The functions loadDocument and saveDocument are taken from the samples.
When the document is not writable for everyone i get the following error:
---snip---
org.exist.security.PermissionDeniedException: Document exists and update
is not allowed
at
org.exist.collections.Collection.checkPermissions(Collection.java:1263)
at
org.exist.collections.Collection.determineTreeStructure(Collection.java:1099)
at org.exist.collections.Collection.validate(Collection.java:851)
at
org.exist.xmldb.LocalCollection.storeXMLResource(LocalCollection.java:589)
...
---snap---
Christoph
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Integration of Cocoon and eXist - user/password accessing database
Posted by Suzan Foster <su...@nerocmediaware.nl>.
You can use org.exist.cocoon.XMLDBSessionLoginAction to login to the
database.
Regards,
Suzan Foster.
--
Christoph Hermann wrote:
>Hello,
>
>i'm trying to integrate Cocoon and eXist XML DB. So far it works fine, i
>can edit and save a document through cforms and the bindings, but this
>is only working if i make the documents in my collection
>world-writable/updatable.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Integration of Cocoon and eXist - user/password accessing database
Posted by Christoph Hermann <ch...@tu-clausthal.de>.
Christoph Hermann schrieb:
Hello,
> i'm trying to integrate Cocoon and eXist XML DB. So far it works fine, i
> can edit and save a document through cforms and the bindings, but this
> is only working if i make the documents in my collection
> world-writable/updatable.
>
> So my question is: where do i specify which user/password is used when
> accessing the eXist database (i would like to do this in flow (if
> possible) alternatively which configuration file handles this)?
I now wrote a new saveDocumentAuth() function for this:
> ---snip---
> var form = new Form("cforms/definition/test_def.xml");
> var bindingURI = "cforms/binding/test_bind.xml";
> form.createBinding(bindingURI);
var docBaseURI = "xmldb:exist:///db/test/";
var docName = "test.xml";
var document = loadDocument(docBaseURI + docName);
form.load(document);
form.showForm("test-display-pipeline");
form.save(document);
// saveDocument(document, docURI);
saveDocumentAuth(document, "test.xml", docBaseURI, "user", "pass",
"true");
and the function looks like this:
---snip---
function saveDocumentAuth(document, docname, dburi, user, password,
overwrite) {
// exist API http://exist.sourceforge.net/api/index.html
// XMLUtils API http://cocoon.apache.org/2.1/apidocs/
importClass(Packages.org.xmldb.api.DatabaseManager);
importClass(Packages.org.xmldb.api.base.Collection);
importClass(Packages.org.xmldb.api.modules.XMLResource);
importClass(Packages.org.apache.excalibur.xml.sax.SAXParser);
// Error Messages
var _errmsg = null;
var _errdesc = null;
// set the document xml data
var xmldata =
Packages.org.apache.cocoon.xml.XMLUtils.serializeNodeToXML(document);
// Collection (org.xmldb.api.base.Collection)
var collection = null;
// ressource (org.xmldb.api.modules.XMLResource)
var _resource = null;
try {
collection = DatabaseManager.getCollection(dburi, user, password);
collection.setProperty("sax-document-events", "false");
try {
_resource = collection.getResource(docname);
if(_resource != null) {
if(overwrite.equals("true")) {
collection.removeResource(_resource);
_resource = collection.createResource( docname, "XMLResource" );
_resource.setContent(xmldata);
collection.storeResource(_resource);
} else {
_errmsg = "Resource " + docname + " does already exist";
_errdesc = "Resource " + docname + " does already exist";
cocoon.log.error(_errmsg);
cocoon.log.error(_errdesc);
}
} else {
_resource = collection.createResource( docname, "XMLResource" );
_resource.setContent(xmldata);
collection.storeResource(_resource);
}
} catch(_ex) { // XMLDBException
_errmsg = _ex.getMessage;
_errdesc = "Failed to store document" + docname;
cocoon.log.error(_errmsg);
cocoon.log.error(_errdesc);
}
} catch(_e) { // XMLDBException
_errmsg = _e.toString();
_errdesc = "Failed to get collection " + dburi;
cocoon.log.error(_errmsg);
cocoon.log.error(_errdesc);
}
}
---snap---
So if anyone is able to use this, or to find a better way of handling
this, feel free to modify it to your needs.
With kind regards,
Christoph Hermann
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org