org.apache.lenya.modules.collection
Class CollectionWrapper

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.lenya.modules.collection.CollectionWrapper
All Implemented Interfaces:
org.apache.avalon.framework.logger.LogEnabled, Collection

public class CollectionWrapper
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements Collection

Document wrapper for collection functionality.


Field Summary
protected static java.lang.String[] TYPES
           
 
Fields inherited from interface org.apache.lenya.modules.collection.Collection
ATTRIBUTE_HREF, ATTRIBUTE_TYPE, ATTRIBUTE_UUID, DEFAULT_PREFIX, ELEMENT_COLLECTION, ELEMENT_DOCUMENT, NAMESPACE, TYPE_CHILDREN, TYPE_LINK, TYPE_MANUAL
 
Constructor Summary
CollectionWrapper(org.apache.lenya.cms.publication.Document doc, org.apache.avalon.framework.logger.Logger logger)
          Ctor.
 
Method Summary
 void add(org.apache.lenya.cms.publication.Document document)
          Adds a document to the collection.
 void add(int position, org.apache.lenya.cms.publication.Document document)
          Inserts a document into the collection at a specific position.
 void clear()
          Removes all documents from this collection.
 boolean contains(org.apache.lenya.cms.publication.Document document)
          Checks if this collection contains a specific document.
protected  org.w3c.dom.Element createDocumentElement(org.apache.lenya.cms.publication.Document document, org.apache.lenya.xml.NamespaceHelper helper)
          Creates an element to store a document.
protected  java.util.List documents()
          Returns the list that holds the documents.
 org.apache.lenya.cms.publication.Document getDelegate()
           
 org.apache.lenya.cms.publication.Document[] getDocuments()
          Returns the documents in this collection.
 int getFirstPosition(org.apache.lenya.cms.publication.Document document)
          Returns the first position of this document in the collection.
 java.lang.String getHref()
           
protected  org.apache.lenya.xml.NamespaceHelper getNamespaceHelper()
          Returns the namespace helper for the XML source.
 java.lang.String getType()
           
protected  org.apache.lenya.xml.NamespaceHelper initializeNamespaceHelper()
           
protected  void load()
          Loads the collection from its XML source.
protected  org.apache.lenya.cms.publication.Document loadDocument(org.w3c.dom.Element documentElement)
          Loads a document from an XML element.
protected  void loadXml(org.apache.lenya.xml.NamespaceHelper helper)
           
 void remove(org.apache.lenya.cms.publication.Document document)
          Removes a document from the collection.
 void save()
          Saves the collection.
protected  void saveXml(org.apache.lenya.xml.NamespaceHelper helper)
           
 void setHref(java.lang.String href)
           
 void setType(java.lang.String type)
           
 int size()
          Returns the number of documents in this collection.
 
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

TYPES

protected static final java.lang.String[] TYPES
Constructor Detail

CollectionWrapper

public CollectionWrapper(org.apache.lenya.cms.publication.Document doc,
                         org.apache.avalon.framework.logger.Logger logger)
Ctor.

Parameters:
doc - The document.
logger - The logger.
Method Detail

getDelegate

public org.apache.lenya.cms.publication.Document getDelegate()
Specified by:
getDelegate in interface Collection
Returns:
The document which the collection is stored in.

documents

protected java.util.List documents()
                            throws org.apache.lenya.cms.publication.DocumentException
Returns the list that holds the documents. Use this method to invoke lazy loading.

Returns:
A list.
Throws:
org.apache.lenya.cms.publication.DocumentException - when something went wrong.

getDocuments

public org.apache.lenya.cms.publication.Document[] getDocuments()
                                                         throws org.apache.lenya.cms.publication.DocumentException
Description copied from interface: Collection
Returns the documents in this collection.

Specified by:
getDocuments in interface Collection
Returns:
An array of documents.
Throws:
org.apache.lenya.cms.publication.DocumentException - when something went wrong.
See Also:
Collection.getDocuments()

add

public void add(org.apache.lenya.cms.publication.Document document)
         throws org.apache.lenya.cms.publication.DocumentException
Description copied from interface: Collection
Adds a document to the collection.

Specified by:
add in interface Collection
Parameters:
document - A document.
Throws:
org.apache.lenya.cms.publication.DocumentException - when an error occurs.
See Also:
Collection.add(org.apache.lenya.cms.publication.Document)

add

public void add(int position,
                org.apache.lenya.cms.publication.Document document)
         throws org.apache.lenya.cms.publication.DocumentException
Description copied from interface: Collection
Inserts a document into the collection at a specific position.

Specified by:
add in interface Collection
Parameters:
position - The position of the document after insertion, starting with 0.
document - A document.
Throws:
org.apache.lenya.cms.publication.DocumentException - when something went wrong.
See Also:
Collection.add(int, org.apache.lenya.cms.publication.Document)

remove

public void remove(org.apache.lenya.cms.publication.Document document)
            throws org.apache.lenya.cms.publication.DocumentException
Description copied from interface: Collection
Removes a document from the collection.

Specified by:
remove in interface Collection
Parameters:
document - A document.
Throws:
org.apache.lenya.cms.publication.DocumentException - when the document is not contained or another error occurs.
See Also:
Collection.remove(org.apache.lenya.cms.publication.Document)

load

protected final void load()
Loads the collection from its XML source.


loadXml

protected void loadXml(org.apache.lenya.xml.NamespaceHelper helper)

loadDocument

protected org.apache.lenya.cms.publication.Document loadDocument(org.w3c.dom.Element documentElement)
                                                          throws org.apache.lenya.cms.publication.DocumentBuildException
Loads a document from an XML element.

Parameters:
documentElement - The XML element.
Returns:
A document.
Throws:
org.apache.lenya.cms.publication.DocumentBuildException - when something went wrong.

save

public final void save()
Saves the collection.


saveXml

protected void saveXml(org.apache.lenya.xml.NamespaceHelper helper)
                throws javax.xml.transform.TransformerException,
                       org.apache.lenya.cms.publication.DocumentException
Parameters:
helper - Save the XML to the provided namespace helper.
Throws:
javax.xml.transform.TransformerException - if an error occurs.
org.apache.lenya.cms.publication.DocumentException - if an error occurs.

getType

public java.lang.String getType()
Specified by:
getType in interface Collection
Returns:
One of Collection.TYPE_CHILDREN, Collection.TYPE_MANUAL, Collection.TYPE_LINK.

createDocumentElement

protected org.w3c.dom.Element createDocumentElement(org.apache.lenya.cms.publication.Document document,
                                                    org.apache.lenya.xml.NamespaceHelper helper)
                                             throws org.apache.lenya.cms.publication.DocumentException
Creates an element to store a document.

Parameters:
helper - The namespace helper of the document.
document - The document.
Returns:
An XML element.
Throws:
org.apache.lenya.cms.publication.DocumentException - when something went wrong.

getNamespaceHelper

protected org.apache.lenya.xml.NamespaceHelper getNamespaceHelper()
                                                           throws org.apache.lenya.cms.publication.DocumentException,
                                                                  javax.xml.parsers.ParserConfigurationException,
                                                                  org.xml.sax.SAXException,
                                                                  java.io.IOException,
                                                                  org.apache.avalon.framework.service.ServiceException
Returns the namespace helper for the XML source.

Returns:
A namespace helper.
Throws:
org.apache.lenya.cms.publication.DocumentException - when something went wrong.
javax.xml.parsers.ParserConfigurationException - when something went wrong.
org.xml.sax.SAXException - when something went wrong.
java.io.IOException - when something went wrong.
org.apache.avalon.framework.service.ServiceException

initializeNamespaceHelper

protected org.apache.lenya.xml.NamespaceHelper initializeNamespaceHelper()
Returns:
A new, empty namespace helper.

contains

public boolean contains(org.apache.lenya.cms.publication.Document document)
                 throws org.apache.lenya.cms.publication.DocumentException
Description copied from interface: Collection
Checks if this collection contains a specific document.

Specified by:
contains in interface Collection
Parameters:
document - The document to check.
Returns:
A boolean value.
Throws:
org.apache.lenya.cms.publication.DocumentException - when something went wrong.
See Also:
Collection.contains(org.apache.lenya.cms.publication.Document)

clear

public void clear()
           throws org.apache.lenya.cms.publication.DocumentException
Description copied from interface: Collection
Removes all documents from this collection.

Specified by:
clear in interface Collection
Throws:
org.apache.lenya.cms.publication.DocumentException - when something went wrong.
See Also:
Collection.clear()

getFirstPosition

public int getFirstPosition(org.apache.lenya.cms.publication.Document document)
                     throws org.apache.lenya.cms.publication.DocumentException
Description copied from interface: Collection
Returns the first position of this document in the collection.

Specified by:
getFirstPosition in interface Collection
Parameters:
document - The document.
Returns:
An integer.
Throws:
org.apache.lenya.cms.publication.DocumentException - when the document is not contained.
See Also:
Collection.getFirstPosition(org.apache.lenya.cms.publication.Document)

size

public int size()
         throws org.apache.lenya.cms.publication.DocumentException
Description copied from interface: Collection
Returns the number of documents in this collection.

Specified by:
size in interface Collection
Returns:
An integer value.
Throws:
org.apache.lenya.cms.publication.DocumentException - when something went wrong.
See Also:
Collection.size()

setType

public void setType(java.lang.String type)
Specified by:
setType in interface Collection
Parameters:
type - One of Collection.TYPE_CHILDREN, Collection.TYPE_MANUAL, Collection.TYPE_LINK.

getHref

public java.lang.String getHref()
Specified by:
getHref in interface Collection
Returns:
The link target.

setHref

public void setHref(java.lang.String href)
Specified by:
setHref in interface Collection
Parameters:
href - The link target. If the type is not Collection.TYPE_LINK, calling this method has no effect.


Copyright © $ Apache Software Foundation. All Rights Reserved.