org.apache.lenya.cms.publication
Class CollectionImpl

java.lang.Object
  extended by org.apache.lenya.cms.publication.DefaultDocument
      extended by org.apache.lenya.cms.publication.CollectionImpl
All Implemented Interfaces:
Collection, Document
Direct Known Subclasses:
XlinkCollection

public class CollectionImpl
extends DefaultDocument
implements Collection

Implementation of a Collection.


Field Summary
 
Fields inherited from interface org.apache.lenya.cms.publication.Collection
ATTRIBUTE_ID, DEFAULT_PREFIX, ELEMENT_COLLECTION, ELEMENT_DOCUMENT, NAMESPACE
 
Constructor Summary
CollectionImpl(Publication publication, java.lang.String id, java.lang.String area)
          Ctor.
CollectionImpl(Publication publication, java.lang.String id, java.lang.String area, java.lang.String language)
          Ctor.
 
Method Summary
 void add(Document document)
          Adds a document to the collection.
 void add(int position, Document document)
          Inserts a document into the collection at a specific position.
 void clear()
          Removes all documents from this collection.
 boolean contains(Document document)
          Checks if this collection contains a specific document.
protected  org.w3c.dom.Element createDocumentElement(Document document, NamespaceHelper helper)
          Creates an element to store a document.
protected  java.util.List documents()
          Returns the list that holds the documents.
 Document[] getDocuments()
          Returns the documents in this collection.
 int getFirstPosition(Document document)
          Returns the first position of this document in the collection.
protected  NamespaceHelper getNamespaceHelper()
          Returns the namespace helper for the XML source.
protected  void load()
          Loads the collection from its XML source.
protected  Document loadDocument(org.w3c.dom.Element documentElement)
          Loads a document from an XML element.
 void remove(Document document)
          Removes a document from the collection.
 void save()
          Saves the XML source of this collection.
 int size()
          Returns the number of documents in this collection.
 
Methods inherited from class org.apache.lenya.cms.publication.DefaultDocument
equals, exists, existsInAnyLanguage, getArea, getCompleteInfoURL, getCompleteURL, getCompleteURLWithoutLanguage, getDocumentURL, getDublinCore, getExtension, getFile, getId, getLabel, getLanguage, getLanguages, getLastModified, getName, getNodeId, getPublication, hashCode, setArea, setDocumentURL, setExtension, setLanguage, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.lenya.cms.publication.Document
exists, existsInAnyLanguage, getArea, getCompleteInfoURL, getCompleteURL, getCompleteURLWithoutLanguage, getDocumentURL, getDublinCore, getExtension, getFile, getId, getLabel, getLanguage, getLanguages, getLastModified, getName, getNodeId, getPublication
 

Constructor Detail

CollectionImpl

public CollectionImpl(Publication publication,
                      java.lang.String id,
                      java.lang.String area)
               throws DocumentException
Ctor.

Parameters:
publication - A publication.
id - The document ID.
area - The area the document belongs to.
Throws:
DocumentException - when something went wrong.

CollectionImpl

public CollectionImpl(Publication publication,
                      java.lang.String id,
                      java.lang.String area,
                      java.lang.String language)
               throws DocumentException
Ctor.

Parameters:
publication - A publication.
id - The document ID.
area - The area the document belongs to.
language - The language of the document.
Throws:
DocumentException - when something went wrong.
Method Detail

documents

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

Returns:
A list.
Throws:
DocumentException - when something went wrong.

getDocuments

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

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

add

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

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

add

public void add(int position,
                Document document)
         throws 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:
DocumentException - when something went wrong.
See Also:
Collection.add(int, org.apache.lenya.cms.publication.Document)

remove

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

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

load

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

Throws:
DocumentException - when something went wrong.

loadDocument

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

Parameters:
documentElement - The XML element.
Returns:
A document.
Throws:
DocumentBuildException - when something went wrong.

save

public void save()
          throws DocumentException
Saves the XML source of this collection.

Specified by:
save in interface Collection
Throws:
DocumentException - when something went wrong.

createDocumentElement

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

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

getNamespaceHelper

protected NamespaceHelper getNamespaceHelper()
                                      throws DocumentException,
                                             javax.xml.parsers.ParserConfigurationException,
                                             org.xml.sax.SAXException,
                                             java.io.IOException
Returns the namespace helper for the XML source.

Returns:
A namespace helper.
Throws:
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.

contains

public boolean contains(Document document)
                 throws 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:
DocumentException - when something went wrong.
See Also:
Collection.contains(org.apache.lenya.cms.publication.Document)

clear

public void clear()
           throws DocumentException
Description copied from interface: Collection
Removes all documents from this collection.

Specified by:
clear in interface Collection
Throws:
DocumentException - when something went wrong.
See Also:
Collection.clear()

getFirstPosition

public int getFirstPosition(Document document)
                     throws 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:
DocumentException - when the document is not contained.
See Also:
Collection.getFirstPosition(org.apache.lenya.cms.publication.Document)

size

public int size()
         throws 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:
DocumentException - when something went wrong.
See Also:
Collection.size()


Copyright © 1999-2005 Apache Software Foundation. All Rights Reserved.