org.apache.cocoon.components.source.impl
Class XMLDBSource

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.components.source.impl.XMLDBSource
All Implemented Interfaces:
LogEnabled, ModifiableSource, ModifiableTraversableSource, Source, TraversableSource, XMLizable

public class XMLDBSource
extends AbstractLogEnabled
implements ModifiableTraversableSource, XMLizable

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

Version:
CVS $Id: XMLDBSource.html 1304258 2012-03-23 10:09:27Z ilgrosso $

Field Summary
protected static String CDATA
           
protected static String COLLECTION
          Element <collection>
protected static String COLLECTION_BASE_ATTR
           
protected static String COLLECTION_COUNT_ATTR
          Attribute collections on the root element indicates count of collections in the collection
protected static String COLLECTIONS
          Root element <collections>
protected static String NAME_ATTR
          Attribute name on the collection/resource element
protected  String password
          The supplied password
static String PREFIX
          Source prefix
protected static String QCOLLECTION
          Element <xmldb:collection> (raw name)
protected static String QCOLLECTIONS
          Root element <xmldb:collections> (raw name)
protected static String QRESOURCE
          Element <resource> (raw name)
protected static String QRESULT
          Element <xmldb:result> (raw name)
protected static String QRESULTSET
          Root element <xmldb:results> (raw name)
protected  String query
          The part of URL after # sign
protected static String QUERY_ATTR
           
protected static String RESOURCE
          Element <resource>
protected static String RESOURCE_COUNT_ATTR
          Attribute resources on the root element indicates count of resources in the collection
protected static String RESULT
          Element <result>
protected static String RESULT_DOCID_ATTR
           
protected static String RESULT_ID_ATTR
           
protected static String RESULTS_COUNT_ATTR
           
protected static String RESULTSET
          Root element <results>
static String URI
          Source namespace
protected  String url
          The requested URL
protected  String user
          The supplied user
 
Constructor Summary
XMLDBSource(Logger logger, String user, String password, String srcUrl)
          The constructor.
 
Method Summary
 boolean canCancel(OutputStream stream)
          Can the data sent to an OutputStream returned by getOutputStream() be cancelled ?
 void cancel(OutputStream stream)
          Cancel the data sent to an OutputStream returned by getOutputStream().
 String createId()
          Create a new identifier for a resource within a collection.
 void delete()
          Delete the source
 boolean exists()
           
 OutputStream getBinaryOutputStream()
          Return an OutputStream to write data to a binary resource.
 Source getChild(String name)
           
 Collection getChildren()
           
 long getContentLength()
           
 InputStream getInputStream()
          Get an InputSource for the given URL.
 long getLastModified()
           
 String getMimeType()
           
 String getName()
           
 OutputStream getOutputStream()
          Return an OutputStream to write to.
 Source getParent()
           
 String getScheme()
           
 String getURI()
           
 SourceValidity getValidity()
           
 boolean isCollection()
           
 void makeCollection()
           
 void refresh()
           
 void toSAX(ContentHandler handler)
          Stream SAX events to a given ContentHandler.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URI

public static final String URI
Source namespace

See Also:
Constant Field Values

PREFIX

public static final String PREFIX
Source prefix

See Also:
Constant Field Values

COLLECTIONS

protected static final String COLLECTIONS
Root element <collections>

See Also:
Constant Field Values

QCOLLECTIONS

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

See Also:
Constant Field Values

RESOURCE_COUNT_ATTR

protected static final 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 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 String COLLECTION_BASE_ATTR
See Also:
Constant Field Values

COLLECTION

protected static final String COLLECTION
Element <collection>

See Also:
Constant Field Values

QCOLLECTION

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

See Also:
Constant Field Values

RESOURCE

protected static final String RESOURCE
Element <resource>

See Also:
Constant Field Values

QRESOURCE

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

See Also:
Constant Field Values

NAME_ATTR

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

See Also:
Constant Field Values

RESULTSET

protected static final String RESULTSET
Root element <results>

See Also:
Constant Field Values

QRESULTSET

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

See Also:
Constant Field Values

QUERY_ATTR

protected static final String QUERY_ATTR
See Also:
Constant Field Values

RESULTS_COUNT_ATTR

protected static final String RESULTS_COUNT_ATTR
See Also:
Constant Field Values

RESULT

protected static final String RESULT
Element <result>

See Also:
Constant Field Values

QRESULT

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

See Also:
Constant Field Values

RESULT_DOCID_ATTR

protected static final String RESULT_DOCID_ATTR
See Also:
Constant Field Values

RESULT_ID_ATTR

protected static final String RESULT_ID_ATTR
See Also:
Constant Field Values

CDATA

protected static final String CDATA
See Also:
Constant Field Values

url

protected String url
The requested URL


user

protected String user
The supplied user


password

protected String password
The supplied password


query

protected String query
The part of URL after # sign

Constructor Detail

XMLDBSource

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

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

toSAX

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

Specified by:
toSAX in interface XMLizable
Throws:
SAXException

getURI

public String getURI()
Specified by:
getURI in interface Source

getContentLength

public long getContentLength()
Specified by:
getContentLength in interface Source

getLastModified

public long getLastModified()
Specified by:
getLastModified in interface Source

exists

public boolean exists()
Specified by:
exists in interface Source

getMimeType

public String getMimeType()
Specified by:
getMimeType in interface Source

getScheme

public String getScheme()
Specified by:
getScheme in interface Source

getValidity

public SourceValidity getValidity()
Specified by:
getValidity in interface Source

refresh

public void refresh()
Specified by:
refresh in interface Source

getInputStream

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

Specified by:
getInputStream in interface Source
Throws:
IOException

getOutputStream

public OutputStream getOutputStream()
                             throws IOException,
                                    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().

Specified by:
getOutputStream in interface ModifiableSource
Throws:
IOException
MalformedURLException

getBinaryOutputStream

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

Throws:
IOException
MalformedURLException

createId

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

Throws:
SourceException - if collection does not exist or failed to create id

delete

public void delete()
            throws SourceException
Delete the source

Specified by:
delete in interface ModifiableSource
Throws:
SourceException

canCancel

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

Specified by:
canCancel in interface ModifiableSource
Returns:
true if the stream can be cancelled

cancel

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

After cancelling, the stream should no longer be used.

Specified by:
cancel in interface ModifiableSource
Throws:
IOException

makeCollection

public void makeCollection()
                    throws SourceException
Specified by:
makeCollection in interface ModifiableTraversableSource
Throws:
SourceException

isCollection

public boolean isCollection()
Specified by:
isCollection in interface TraversableSource

getChildren

public Collection getChildren()
                       throws SourceException
Specified by:
getChildren in interface TraversableSource
Throws:
SourceException

getChild

public Source getChild(String name)
                throws SourceException
Specified by:
getChild in interface TraversableSource
Throws:
SourceException

getName

public String getName()
Specified by:
getName in interface TraversableSource

getParent

public Source getParent()
                 throws SourceException
Specified by:
getParent in interface TraversableSource
Throws:
SourceException


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.