Table of Contents

Class: eXistDA trunk/eXistDA.py

An eXist connector object.

The class which represents an eXist "proxy" or database adapter.

Base Classes   
OFS.SimpleItem.Item
Persistent
Acquisition.Implicit
AccessControl.Role.RoleManager
Methods   
__init__
_getAnythingAsString
_getConnection
_serverIsMe
createColl
delColl
delDoc
delRsc
findXMLRPCAddress
getDA
getDictFromDoc
getDoc
getFilesFromQuery
isCollection
isDocument
isOnline
listColl
listDoc
manage_edit
query
saveDoc
xupdate
  __init__ 
__init__ (
        self,
        id,
        title,
        server='',
        port=utils.DEFAULT_PORT,
        username='',
        password='',
        encoding=utils.DEFAULT_ENCODING,
        xmlrpc_path=utils.DEFAULT_XMLRPC_PATH,
        )

Class constructor.

  • Returns a new object !!

  • id : string containing the id of the Zope object created

  • title : string containing the title property of the Zope object

  • server : server name which runs the DB. Should be a complete name and SHOULD NEVER BE LOCALHOST or 127.0.0.1 because it may be, sometimes, evaluated from the client within a link. Ex : www.mycomputer.org

  • port : port number used by the eXist's XMLRPC server. Default is 8080. Ex : 8080

  • username : login of the user on the DB. Leave empty for guest (for python2.1). Ex: my_user

  • password : password of the selected user. Leave empty if none. Ex : '******' ;-)

  • encoding : encoding of the string which are passed and will be returned by the DB. Default is ISO-8859-1, if an empty string is passed. Ex : UTF-8

  • xmlrpc_path : address of eXist embedded XMLRPC server. Ex : /xmlrpc

  _getAnythingAsString 
_getAnythingAsString (
        self,
        my_data,
        object_only=0,
        )

Returns my_data as a string. Raise an error if nothing can be returned. 1 level depth only (ie an HTTP URI in a file will return the HTTP URI, not the string contained in the page at the URI)

  • my_data : a string, a file like object, a zope object, an HTTP URI, an eXist URI

  • object_only : an integer, which determines if we only do a test for an object (1) or not (0). Useful for URI-like parameters

  _getConnection 
_getConnection ( self,  xmlrpc_path=None )

Opens a connection to the eXist server if there's no one available.

  • Returns the object which is the proxy to the XMLRPC server

  _serverIsMe 
_serverIsMe (
        self,
        URI,
        **kws,
        )

Returns 1 if URI "represents" this object.

  • URI : a string containing an URI

  • kws : dict for any other parameters. See README.txt for recognized parameters

  createColl 
createColl ( self,  coll_name )

Creates a new collection in the coll_name collection.

  • Returns 1 if no problem. Returns 0 if collection has not been created

  • coll_name : string containing the name of the collection to create, with the FULL path

  delColl 
delColl ( self,  coll_name )

Deletes a collection and ALL what it contains.

  • Returns 1 if no problem. Returns 0 if collection has not been deleted

  • coll_name : string containing the name of the collection to delete, with the FULL path

  delDoc 
delDoc ( self,  doc_name )

Deletes a document of the DB.

  • Returns 1 if no problem. Returns 0 if document has not been deleted

  • doc_name : string containing the name of the document to delete, with the FULL path

  delRsc 
delRsc ( self,  rsc_name )

Wrapper to delColl or delDoc. Automatically chooses the good one (TM)

  • Returns 1 if no problem. Returns 0 if resource has not been deleted

  • rsc_name : string containing the name of a document or collection that must be deleted, with the FULL path

  findXMLRPCAddress 
findXMLRPCAddress ( self )

Tries to find the address of the eXist XMLRPC embedded server.

  • Returns the first address if found, or an empty string if nothing is found.

  getDA 
getDA ( self )

Returns a reference to the object itself

  getDictFromDoc 
getDictFromDoc ( self,  doc_name )

Returns a dictionary which keys are XML tags and values are XML values from the doc.

WARNING : for the moment, attributes are ignored and forgotten.

  • Returns a python dictionary

  • doc_name : a string containing the full path and name of an existing document in the DB

  getDoc 
getDoc (
        self,
        doc_name,
        xsl='',
        pretty_print=utils.DEFAULT_PP,
        **kws,
        )

Retrieve a document in the database.

  • Returns a string containing the (XSL transformed if suited) XML document.

  • doc_name : a string containing the full path and name of an existing document in the DB

  • xsl : a string containing the full path and name of an existing XSL document in the DB. If an empty string is passed, no XSLT is done

  • if pretty_print == 1, then the returned string is "pretty printed", ie indented. Else, the string is returned as it is saved in the DB

  • kws : dict for any other parameters. See README.txt for recognized parameters

  getFilesFromQuery 
getFilesFromQuery (
        self,
        query,
        **kws,
        )

BROKEN SINCE JUNE SNAPSHOTS -> modify eXist src to make it work

Executes an XPATH query or an XQuery on the DB.

  • Returns a list of string containing the name and full path of files in the DB which matches the query

  • query : a object/URI/string containing an XPATH query or an XQuery

  • kws : dict for any other parameters. See README.txt and query for recognized parameters

  isCollection 
isCollection ( self,  resource_name )

Determines if resource_name is a collection in the DB or not.

  • Returns 1 if resource_name is a collection, 0 otherwise

  • resource_name : a string containing the full path and name of the resource to test

  isDocument 
isDocument ( self,  resource_name )

Determines if resource_name is a document in the DB or not.

  • Returns 1 if resource_name is a document, 0 otherwise

  • resource_name : a string containing the full path and name of the resource to test

  isOnline 
isOnline ( self )

Determines (by trying a sync() on the DB if the server is online.

  • Returns a tuple consisting of the id of the server, and 1 if it's up, 0 if not

  listColl 
listColl (
        self,
        coll_name=utils.EXIST_ROOT_COLL,
        recursive=0,
        full_path=1,
        )

Lists the collections contained in collection coll_name.

  • Returns a list containing strings which are sub-collections of coll_name

  • coll_name : a string containing the base collection, containing the others. If the parameter is not passed, defaults to EXIST_ROOT_COLL (ie /db)

  • if recursive == 0, returned values will be the direct children collections of coll_name. Otherwise, all sub-collections will be recursively returned (even the children of the children)

  • if full_path == 1, the full path to the collections is returned (including /db/...). Otherwise, the path returned is relative to coll_name

  listDoc 
listDoc (
        self,
        coll_name='',
        full_path=0,
        )

Returns the list of all documents contained in collection coll_name.

  • coll_name : the name (with complete path) of the collection you want to list the child collections

  • full_path : if != 0 returns the full path of the document, otherwise, only the document name

  manage_edit 
manage_edit (
        self,
        title="",
        server="",
        port=utils.DEFAULT_PORT,
        username="",
        password="",
        encoding=utils.DEFAULT_ENCODING,
        xmlrpc_path=utils.DEFAULT_XMLRPC_PATH,
        REQUEST=None,
        )

Change values of object's parameters. (see __init__)

  query 
query (
        self,
        query,
        **kws,
        )

Execute an XPATH query or an XQuery on the DB.

  • Returns a eXistDAresultsSet object containing all the results returned by the query.

  • query : an object/URI/string containing an XPATH query or an XQuery

  • kws : dict for any other parameters. See README.txt for recognized parameters

    • object_only : cf. README.txt

    • variables : key to a dict containing variables to pass to the xquery

  saveDoc 
saveDoc (
        self,
        my_doc,
        doc_uri,
        overwrite=1,
        **kws,
        )

Save a document in the database.

  • Returns 1 if saved, 0 otherwise

  • my_doc : an object/URI/string containing the doc

  • doc_uri : a string containing the complete URI (server, path and name) of the doc in the DB

  • if overwrite == 1 then if there's an existing doc with the same name, it will be overwritten

  • kws : dict for any other parameters. See README.txt for recognized parameters

Exceptions   
utils.EXC_CANT_SAVE
utils.EXC_NOT_THIS_DB
  xupdate 
xupdate (
        self,
        res_name,
        xupdate_doc,
        **kws,
        )

Issues an XUpdate command to update a document or a whole collection in the database.

  • Returns a number > 0 (nb of updates done ?) if AOK or raise an exception if pb

  • res_name : the name (with complete path) of a collection or a document

  • xupdate_doc : an object/URI/string containing an XUpdate string

  • kws : dict for any other parameters. See README.txt for recognized parameters

Exceptions   
utils.EXC_NOT_RESOURCE

Table of Contents

This document was automatically generated on Wed Apr 4 20:49:08 2007 by HappyDoc version 2.1