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__
|
__init__ (
self,
id,
title,
server='',
port=utils.DEFAULT_PORT,
username='',
password='',
encoding=utils.DEFAULT_ENCODING,
)
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
|
|
_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 )
Opens a connection to the eXist server if there's no one available.
|
|
_serverIsMe
|
_serverIsMe (
self,
URI,
**kws,
)
Returns 1 if URI "represents" this object.
|
|
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
|
|
getDA
|
getDA ( self )
|
|
getDictFromDoc
|
getDictFromDoc ( self, doc_name )
Returns a dictionary which keys are XML tags and values are XML values from the doc.
|
|
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
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.
|
|
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,
REQUEST=None,
)
Change values of object's parameters. (see __init__ )
|
|
query
|
query (
self,
query,
xmled=1,
**kws,
)
Execute an XPATH query or an XQuery on the DB.
Returns the XML string which matches the query
query : an object/URI/string containing an XPATH query or an XQuery
if xmled == 1 then the XML string returned is a valid XML document beginning with an <?xml.. header, and with a root element <result>. If 0, the string is returned as an aggregation of all string results
kws : dict for any other parameters. See README.txt for recognized parameters
object_only : cf. README.txt
verbose : if set to 1, query returns a list : [query_result_string, hits_int, query_time]
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
|
|