org.exist.cocoon
Class XMLDBSource

java.lang.Object
  extended byAbstractLogEnabled
      extended byorg.exist.cocoon.XMLDBSource

public class XMLDBSource
extends AbstractLogEnabled

This class implements the xmldb:// pseudo-protocol and allows to get XML content from an XML:DB enabled XML database.

This class starts on XMLDBSource from Cocoon project. Some improvments may be useful for Cocoon, some others may be Exist specific. Interesting new features :

Version:
CVS $Id: XMLDBSource.java,v 1.2 2006/01/20 20:56:17 glorieux Exp $
See Also:
Serialized Form

Field Summary
protected static java.lang.String CDATA
           
 Collection collection
           
protected static java.lang.String COLLECTION
          Element <collection>
protected static java.lang.String COLLECTION_BASE_ATTR
           
protected static java.lang.String COLLECTION_COUNT_ATTR
          Attribute collections on the root element indicates count of collections in the collection
protected static java.lang.String COLLECTIONS
          Root element <collections>
 java.lang.String encoding
          default encoding to write outputStream
protected static java.lang.String NAME_ATTR
          Attribute name on the collection/resource element
 java.lang.String password
          The supplied password
static java.lang.String PREFIX
          Source prefix
protected static java.lang.String QCOLLECTION
          Element <xmldb:collection> (raw name)
protected static java.lang.String QCOLLECTIONS
          Root element <xmldb:collections> (raw name)
protected static java.lang.String QRESOURCE
          Element <resource> (raw name)
protected static java.lang.String QRESULT
          Element <xmldb:result> (raw name)
protected static java.lang.String QRESULTSET
          Root element <xmldb:results> (raw name)
protected  java.lang.String query
          The part of URL after # sign
protected static java.lang.String QUERY_ATTR
           
 Resource resource
           
protected static java.lang.String RESOURCE
          Element <resource>
protected static java.lang.String RESOURCE_COUNT_ATTR
          Attribute resources on the root element indicates count of resources in the collection
protected static java.lang.String RESULT
          Element <result>
protected static java.lang.String RESULT_DOCID_ATTR
           
protected static java.lang.String RESULT_ID_ATTR
           
protected static java.lang.String RESULTS_COUNT_ATTR
           
protected static java.lang.String RESULTSET
          Root element <results>
protected  java.lang.String systemId
          The System ID
static java.lang.String URI
          Source namespace
 java.lang.String url
          The requested URL
 java.lang.String user
          The supplied user
 
Constructor Summary
XMLDBSource(Logger logger, java.lang.String user, java.lang.String password, java.lang.String srcUrl)
          The constructor.
 
Method Summary
 boolean canCancel(java.io.OutputStream stream)
          Can the data sent to an OutputStream returned by getOutputStream() be cancelled ?
 void cancel(java.io.OutputStream stream)
          Cancel the data sent to an OutputStream returned by getOutputStream().
 java.lang.String createId()
          Create a new identifier for a resource within a collection.
 void delete()
          Delete the source
 boolean exists()
           
 java.io.OutputStream getBinaryOutputStream()
          Return an OutputStream to write data to a binary resource.
 Source getChild(java.lang.String name)
           
 java.util.Collection getChildren()
           
 Collection getCollection()
          A getter for the xmldb Collection object for this Source
 org.w3c.dom.Node getContentAsDOM()
          get content as DOM
 long getContentLength()
           
 java.lang.String getEncoding()
          Set a default encoding for outputStream
 java.io.InputStream getInputStream()
          Get an InputSource for the given URL.
 long getLastModified()
           
 java.lang.String getMimeType()
           
 java.lang.String getName()
           
 java.io.OutputStream getOutputStream()
          Return an OutputStream to write to.
 Source getParent()
           
 java.lang.String getPassword()
          A getter for the password configured in cocoon.xconf for the connection
 Resource getResource()
          A getter for the xmldb Resource object for this Source
 java.lang.String getScheme()
           
 java.lang.String getURI()
           
 java.lang.String getUser()
          A getter for the user login configured in cocoon.xconf
 SourceValidity getValidity()
           
 boolean isCollection()
           
 void makeCollection()
           
 void refresh()
           
 void setContentAsDOM(org.w3c.dom.Node doc)
          set content as DOM
 void setEncoding(java.lang.String s)
          Set a default encoding for outputStream
 void toSAX(org.xml.sax.ContentHandler handler)
          Stream SAX events to a given ContentHandler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URI

public static final java.lang.String URI
Source namespace

See Also:
Constant Field Values

PREFIX

public static final java.lang.String PREFIX
Source prefix

See Also:
Constant Field Values

COLLECTIONS

protected static final java.lang.String COLLECTIONS
Root element <collections>

See Also:
Constant Field Values

QCOLLECTIONS

protected static final java.lang.String QCOLLECTIONS
Root element <xmldb:collections> (raw name)

See Also:
Constant Field Values

RESOURCE_COUNT_ATTR

protected static final java.lang.String RESOURCE_COUNT_ATTR
Attribute resources on the root element indicates count of resources in the collection

See Also:
Constant Field Values

COLLECTION_COUNT_ATTR

protected static final java.lang.String COLLECTION_COUNT_ATTR
Attribute collections on the root element indicates count of collections in the collection

See Also:
Constant Field Values

COLLECTION_BASE_ATTR

protected static final java.lang.String COLLECTION_BASE_ATTR
See Also:
Constant Field Values

COLLECTION

protected static final java.lang.String COLLECTION
Element <collection>

See Also:
Constant Field Values

QCOLLECTION

protected static final java.lang.String QCOLLECTION
Element <xmldb:collection> (raw name)

See Also:
Constant Field Values

RESOURCE

protected static final java.lang.String RESOURCE
Element <resource>

See Also:
Constant Field Values

QRESOURCE

protected static final java.lang.String QRESOURCE
Element <resource> (raw name)

See Also:
Constant Field Values

NAME_ATTR

protected static final java.lang.String NAME_ATTR
Attribute name on the collection/resource element

See Also:
Constant Field Values

RESULTSET

protected static final java.lang.String RESULTSET
Root element <results>

See Also:
Constant Field Values

QRESULTSET

protected static final java.lang.String QRESULTSET
Root element <xmldb:results> (raw name)

See Also:
Constant Field Values

QUERY_ATTR

protected static final java.lang.String QUERY_ATTR
See Also:
Constant Field Values

RESULTS_COUNT_ATTR

protected static final java.lang.String RESULTS_COUNT_ATTR
See Also:
Constant Field Values

RESULT

protected static final java.lang.String RESULT
Element <result>

See Also:
Constant Field Values

QRESULT

protected static final java.lang.String QRESULT
Element <xmldb:result> (raw name)

See Also:
Constant Field Values

RESULT_DOCID_ATTR

protected static final java.lang.String RESULT_DOCID_ATTR
See Also:
Constant Field Values

RESULT_ID_ATTR

protected static final java.lang.String RESULT_ID_ATTR
See Also:
Constant Field Values

CDATA

protected static final java.lang.String CDATA
See Also:
Constant Field Values

encoding

public java.lang.String encoding
default encoding to write outputStream


url

public java.lang.String url
The requested URL


user

public java.lang.String user
The supplied user


password

public java.lang.String password
The supplied password


query

protected java.lang.String query
The part of URL after # sign


systemId

protected java.lang.String systemId
The System ID


collection

public Collection collection

resource

public Resource resource
Constructor Detail

XMLDBSource

public XMLDBSource(Logger logger,
                   java.lang.String user,
                   java.lang.String password,
                   java.lang.String srcUrl)
The constructor.

Parameters:
logger - the Logger instance.
srcUrl - the URL being queried.
Method Detail

getCollection

public Collection getCollection()
                         throws SourceException,
                                XMLDBException
A getter for the xmldb Collection object for this Source

Throws:
SourceException
XMLDBException

getResource

public Resource getResource()
                     throws SourceException,
                            XMLDBException
A getter for the xmldb Resource object for this Source

Throws:
SourceException
XMLDBException

getUser

public java.lang.String getUser()
A getter for the user login configured in cocoon.xconf


getPassword

public java.lang.String getPassword()
A getter for the password configured in cocoon.xconf for the connection


toSAX

public void toSAX(org.xml.sax.ContentHandler handler)
           throws org.xml.sax.SAXException
Stream SAX events to a given ContentHandler. If the requested resource is a collection, build an XML view of it.

Throws:
org.xml.sax.SAXException

getURI

public java.lang.String getURI()

getContentLength

public long getContentLength()

getLastModified

public long getLastModified()

exists

public boolean exists()

getMimeType

public java.lang.String getMimeType()

getScheme

public java.lang.String getScheme()

getValidity

public SourceValidity getValidity()

refresh

public void refresh()

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Get an InputSource for the given URL.

Throws:
java.io.IOException

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException,
                                            java.net.MalformedURLException
Return an OutputStream to write to. This method expects an XML document to be written in that stream. To create a binary resource, use getBinaryOutputStream().

Throws:
java.io.IOException
java.net.MalformedURLException

setContentAsDOM

public void setContentAsDOM(org.w3c.dom.Node doc)
                     throws java.io.IOException,
                            java.net.MalformedURLException
set content as DOM

Throws:
java.io.IOException
java.net.MalformedURLException
See Also:
http://exist.sourceforge.net/api/org/xmldb/api/modules/XMLResource.html#setContentAsDOM(org.w3c.dom.Node)

getContentAsDOM

public org.w3c.dom.Node getContentAsDOM()
                                 throws java.io.IOException,
                                        java.net.MalformedURLException
get content as DOM

Throws:
java.io.IOException
java.net.MalformedURLException
See Also:
http://exist.sourceforge.net/api/org/xmldb/api/modules/XMLResource.html#setContentAsDOM(org.w3c.dom.Node)

getBinaryOutputStream

public java.io.OutputStream getBinaryOutputStream()
                                           throws java.io.IOException,
                                                  java.net.MalformedURLException
Return an OutputStream to write data to a binary resource.

Throws:
java.io.IOException
java.net.MalformedURLException

createId

public java.lang.String createId()
                          throws SourceException
Create a new identifier for a resource within a collection. The current source must be an existing collection.

Throws:
SourceException

setEncoding

public void setEncoding(java.lang.String s)
Set a default encoding for outputStream


getEncoding

public java.lang.String getEncoding()
Set a default encoding for outputStream


delete

public void delete()
            throws SourceException
Delete the source

Throws:
SourceException

canCancel

public boolean canCancel(java.io.OutputStream stream)
Can the data sent to an OutputStream returned by getOutputStream() be cancelled ?

Returns:
true if the stream can be cancelled

cancel

public void cancel(java.io.OutputStream stream)
            throws java.io.IOException
Cancel the data sent to an OutputStream returned by getOutputStream().

After cancelling, the stream should no longer be used.

Throws:
java.io.IOException

makeCollection

public void makeCollection()
                    throws SourceException
Throws:
SourceException

isCollection

public boolean isCollection()

getChildren

public java.util.Collection getChildren()
                                 throws SourceException
Throws:
SourceException

getChild

public Source getChild(java.lang.String name)
                throws SourceException
Throws:
SourceException

getName

public java.lang.String getName()

getParent

public Source getParent()
                 throws SourceException
Throws:
SourceException


<oXygen/> XML Editor provides support for editing and debugging XQuery expressions against the eXist XML Database.