## org.exist.cocoon
Class XMLDBSource

    java.lang.Object
      org.apache.avalon.framework.logger.AbstractLogEnabled
          org.exist.cocoon.XMLDBSource

All Implemented Interfaces:
  org.apache.avalon.framework.logger.LogEnabled, org.apache.excalibur.source.ModifiableSource, org.apache.excalibur.source.ModifiableTraversableSource, org.apache.excalibur.source.Source, org.apache.excalibur.source.TraversableSource, org.apache.excalibur.xml.sax.XMLizable

public class XMLDBSource
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.excalibur.source.ModifiableTraversableSource, org.apache.excalibur.xml.sax.XMLizable

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 :

- cacheable for a resource read
- handle userinfo urls like <...//user:password@host/...> (for read)
- setContentAsDOM() to avoid encodings problem when writing a resource
- resourceToSAX() plug a lexical handler to get comments of the XML document
- getCollection(), getResource() (xmldb objects)
- getUser(), getPassword()

Version:
  CVS $Id: XMLDBSource.java 4751 2006-10-28 15:34:44Z wolfgang_m $

Field Summary
`Collection` `collection`
`java.lang.String` `encoding` default encoding to write outputStream
`java.lang.String` `password` The supplied password
`static java.lang.String` `PREFIX` Source prefix
`Resource` `resource`
`static java.lang.String` `URI` Source namespace
`java.lang.String` `url` The requested URL
`java.lang.String` `user` The supplied user

Constructor Summary
`XMLDBSource(org.apache.avalon.framework.logger.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.
`org.apache.excalibur.source.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.
`org.apache.excalibur.source.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
`org.apache.excalibur.source.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 org.apache.avalon.framework.logger.AbstractLogEnabled
`enableLogging`

Methods inherited from class java.lang.Object
`equals, 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

### 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

### collection

    public Collection collection

### resource

    public Resource resource

Constructor Detail

### XMLDBSource

    public XMLDBSource(org.apache.avalon.framework.logger.Logger logger,
                       java.lang.String user,
                       java.lang.String password,
                       java.lang.String srcUrl)

  The constructor.

Parameters:
  `logger` - the Logger instance.
  `user` -
  `password` -
  `srcUrl` - the URL being queried.

Method Detail

### getCollection

    public Collection getCollection()
                             throws org.apache.excalibur.source.SourceException,
                                    XMLDBException

  A getter for the xmldb Collection object for this Source

  Throws:
    `org.apache.excalibur.source.SourceException`
    `XMLDBException`

### getResource

    public Resource getResource()
                         throws org.apache.excalibur.source.SourceException,
                                XMLDBException

  A getter for the xmldb Resource object for this Source

  Throws:
    `org.apache.excalibur.source.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.

  Specified by:
    `toSAX` in interface `org.apache.excalibur.xml.sax.XMLizable`
  Throws:
    `org.xml.sax.SAXException`

### getURI

    public java.lang.String getURI()

  Specified by:
    `getURI` in interface `org.apache.excalibur.source.Source`

### getContentLength

    public long getContentLength()

  Specified by:
    `getContentLength` in interface `org.apache.excalibur.source.Source`

### getLastModified

    public long getLastModified()

  Specified by:
    `getLastModified` in interface `org.apache.excalibur.source.Source`

### exists

    public boolean exists()

  Specified by:
    `exists` in interface `org.apache.excalibur.source.Source`

### getMimeType

    public java.lang.String getMimeType()

  Specified by:
    `getMimeType` in interface `org.apache.excalibur.source.Source`

### getScheme

    public java.lang.String getScheme()

  Specified by:
    `getScheme` in interface `org.apache.excalibur.source.Source`

### getValidity

    public org.apache.excalibur.source.SourceValidity getValidity()

  Specified by:
    `getValidity` in interface `org.apache.excalibur.source.Source`

### refresh

    public void refresh()

  Specified by:
    `refresh` in interface `org.apache.excalibur.source.Source`

### getInputStream

    public java.io.InputStream getInputStream()
                                       throws java.io.IOException

  Get an InputSource for the given URL.

  Specified by:
    `getInputStream` in interface `org.apache.excalibur.source.Source`
  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()`.

  Specified by:
    `getOutputStream` in interface `org.apache.excalibur.source.ModifiableSource`
  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:
    XMLDB API

### 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:
    XMLDB API

### 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 org.apache.excalibur.source.SourceException

  Create a new identifier for a resource within a collection. The current source must be an existing collection.

  Throws:
    `org.apache.excalibur.source.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 org.apache.excalibur.source.SourceException

  Delete the source

  Specified by:
    `delete` in interface `org.apache.excalibur.source.ModifiableSource`
  Throws:
    `org.apache.excalibur.source.SourceException`

### canCancel

    public boolean canCancel(java.io.OutputStream stream)

  Can the data sent to an `OutputStream` returned by `getOutputStream()` be cancelled ?

  Specified by:
    `canCancel` in interface `org.apache.excalibur.source.ModifiableSource`
  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.

  Specified by:
    `cancel` in interface `org.apache.excalibur.source.ModifiableSource`
  Throws:
    `java.io.IOException`

### makeCollection

    public void makeCollection()
                        throws org.apache.excalibur.source.SourceException

  Specified by:
    `makeCollection` in interface `org.apache.excalibur.source.ModifiableTraversableSource`
  Throws:
    `org.apache.excalibur.source.SourceException`

### isCollection

    public boolean isCollection()

  Specified by:
    `isCollection` in interface `org.apache.excalibur.source.TraversableSource`

### getChildren

    public java.util.Collection getChildren()
                                     throws org.apache.excalibur.source.SourceException

  Specified by:
    `getChildren` in interface `org.apache.excalibur.source.TraversableSource`
  Throws:
    `org.apache.excalibur.source.SourceException`

### getChild

    public org.apache.excalibur.source.Source getChild(java.lang.String name)
                                                throws org.apache.excalibur.source.SourceException

  Specified by:
    `getChild` in interface `org.apache.excalibur.source.TraversableSource`
  Throws:
    `org.apache.excalibur.source.SourceException`

### getName

    public java.lang.String getName()

  Specified by:
    `getName` in interface `org.apache.excalibur.source.TraversableSource`

### getParent

    public org.apache.excalibur.source.Source getParent()
                                                 throws org.apache.excalibur.source.SourceException

  Specified by:
    `getParent` in interface `org.apache.excalibur.source.TraversableSource`
  Throws:
    `org.apache.excalibur.source.SourceException`

Copyright (C) Wolfgang Meier. All rights reserved.