info.magnolia.cms.core
Class AbstractContent

java.lang.Object
  extended by info.magnolia.cms.core.ContentHandler
      extended by info.magnolia.cms.core.AbstractContent
All Implemented Interfaces:
Content, Cloneable
Direct Known Subclasses:
ContentWrapper, DefaultContent

public abstract class AbstractContent
extends ContentHandler
implements Content

A base class by implementing some default behavior. A subclass must carefully implement newNodeDataInstance(String, int, boolean), getChildren(info.magnolia.cms.core.Content.ContentFilter, String, java.util.Comparator) and Content.getNodeDataCollection(String).

Version:
$Id$
Author:
pbaerfuss

Nested Class Summary
 
Nested classes/interfaces inherited from interface info.magnolia.cms.core.Content
Content.ContentFilter
 
Constructor Summary
AbstractContent()
           
 
Method Summary
 Content createContent(String name)
          Creates a Content node under the current node with the specified name.
 Content createContent(String name, ItemType contentType)
          Creates a Content node under the current node with the specified name.
 NodeData createNodeData(String name)
          Creates a node data of type STRING with an empty String as default value.
 NodeData createNodeData(String name, int type)
          Deprecated.  
 NodeData createNodeData(String name, Object valueObj)
          Deprecated.  
 NodeData createNodeData(String name, javax.jcr.Value value)
          Creates a node data setting the value.
 NodeData createNodeData(String name, javax.jcr.Value[] value)
          Deprecated.  
 void delete(String path)
          Remove specified path.
 void deleteNodeData(String name)
          Delete NodeData with the specified name.
protected  Collection<NodeData> getBinaryNodeDatas(String namePattern)
           
 Content getChildByName(String namePattern)
          Deprecated.  
 Collection<Content> getChildren()
          Gets a Collection containing all child nodes of the same NodeType as "this" object.
 Collection<Content> getChildren(Content.ContentFilter filter)
          Get a collection containing child nodes which satisfies the given filter.
 Collection<Content> getChildren(Content.ContentFilter filter, Comparator<Content> orderCriteria)
          Get a collection containing child nodes which satisfies the given filter.
abstract  Collection<Content> getChildren(Content.ContentFilter filter, String namePattern, Comparator<Content> orderCriteria)
           
 Collection<Content> getChildren(ItemType itemType)
          Get collection of specified content type.
 Collection<Content> getChildren(String contentType)
          Get collection of specified content type and its subtypes.
 Collection<Content> getChildren(String contentType, String namePattern)
          Get collection of specified content type.
 NodeData getNodeData(String name)
          Returns a NodeData object.
 Collection<NodeData> getNodeDataCollection()
          Gets all properties bind in NodeData object excluding JCR system properties.
 String getTemplate()
          Returns the template name which is assigned to this content.
 String getTitle()
           
 javax.jcr.Workspace getWorkspace()
          get workspace to which this node attached to.
 boolean hasChildren()
           
 boolean hasChildren(String contentType)
           
 boolean hasNodeData(String name)
          Delegates to NodeData.isExist().
 boolean isGranted(long permissions)
          Checks for the allowed access rights.
 boolean isNodeData(String path)
          checks if the requested resource is an NodeData (Property).
abstract  NodeData newNodeDataInstance(String name, int type, boolean createIfNotExisting)
          As defined in Content.getNodeData(String) this method always returns a node data object.
 NodeData setNodeData(String name, boolean value)
          Sets the node data.
 NodeData setNodeData(String name, Calendar value)
          Sets the node data.
 NodeData setNodeData(String name, Content value)
          Sets the node data.
 NodeData setNodeData(String name, double value)
          Sets the node data.
 NodeData setNodeData(String name, InputStream value)
          Sets the node data.
 NodeData setNodeData(String name, long value)
          Sets the node data.
 NodeData setNodeData(String name, Object value)
          Uses the NodeDataUtil to create and set the node data based on the object type.
 NodeData setNodeData(String name, String value)
          Sets the node data.
 NodeData setNodeData(String name, javax.jcr.Value value)
          Sets the node data.
 NodeData setNodeData(String name, javax.jcr.Value[] value)
          Sets the node data.
 String toString()
           
 void updateMetaData()
          You could call this method anytime to update working page properties - Modification date & Author ID.
 
Methods inherited from class info.magnolia.cms.core.ContentHandler
clone, getAccessManager, getHierarchyManager, setAccessManager
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface info.magnolia.cms.core.Content
addMixin, addVersion, addVersion, createContent, delete, getAccessManager, getAllVersions, getAncestor, getAncestors, getBaseVersion, getContent, getHandle, getHierarchyManager, getIndex, getItemType, getJCRNode, getLevel, getLock, getMetaData, getMixinNodeTypes, getName, getNodeDataCollection, getNodeType, getNodeTypeName, getParent, getUUID, getVersionedContent, getVersionedContent, getVersionHistory, hasContent, hasMetaData, hasMixin, holdsLock, isLocked, isModified, isNodeType, lock, lock, orderBefore, refresh, removeMixin, removeVersionHistory, restore, restore, restore, restoreByLabel, save, unlock
 

Constructor Detail

AbstractContent

public AbstractContent()
Method Detail

createContent

public Content createContent(String name)
                      throws javax.jcr.PathNotFoundException,
                             javax.jcr.RepositoryException,
                             AccessDeniedException
Description copied from interface: Content
Creates a Content node under the current node with the specified name. The default node type ItemType.CONTENT will be use as the contents primary type.

Specified by:
createContent in interface Content
Parameters:
name - of the node to be created as Content
Returns:
newly created Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException - if an error occurs
AccessDeniedException - if the current session does not have sufficient access rights to complete the operation

createContent

public Content createContent(String name,
                             ItemType contentType)
                      throws javax.jcr.PathNotFoundException,
                             javax.jcr.RepositoryException,
                             AccessDeniedException
Description copied from interface: Content
Creates a Content node under the current node with the specified name.

Specified by:
createContent in interface Content
Parameters:
name - of the node to be created as Content
contentType - ItemType
Returns:
newly created Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException - if an error occurs
AccessDeniedException - if the current session does not have sufficient access rights to complete the operation

createNodeData

public NodeData createNodeData(String name)
                        throws javax.jcr.PathNotFoundException,
                               javax.jcr.RepositoryException,
                               AccessDeniedException
Description copied from interface: Content
Creates a node data of type STRING with an empty String as default value.

Specified by:
createNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

createNodeData

public NodeData createNodeData(String name,
                               javax.jcr.Value value)
                        throws javax.jcr.PathNotFoundException,
                               javax.jcr.RepositoryException,
                               AccessDeniedException
Description copied from interface: Content
Creates a node data setting the value.

Specified by:
createNodeData in interface Content
Throws:
AccessDeniedException - if the current session does not have sufficient access rights to complete the operation
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

createNodeData

@Deprecated
public NodeData createNodeData(String name,
                                          javax.jcr.Value[] value)
                        throws javax.jcr.PathNotFoundException,
                               javax.jcr.RepositoryException,
                               AccessDeniedException
Deprecated. 

Description copied from interface: Content
Create a multi value node data.

Specified by:
createNodeData in interface Content
Throws:
AccessDeniedException - if the current session does not have sufficient access rights to complete the operation
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

createNodeData

@Deprecated
public NodeData createNodeData(String name,
                                          int type)
                        throws javax.jcr.PathNotFoundException,
                               javax.jcr.RepositoryException,
                               AccessDeniedException
Deprecated. 

Description copied from interface: Content
Creates a node data of type with an default value set. If the no default value can be set (for BINARY, REFERENCE type) the returned node data will be empty and per definition not yet exist.

Specified by:
createNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

createNodeData

@Deprecated
public NodeData createNodeData(String name,
                                          Object valueObj)
                        throws javax.jcr.RepositoryException
Deprecated. 

Description copied from interface: Content
Creates a property and set its value immediately, according to the type of the passed instance, hiding the complexity of using JCR's ValueFactory and providing a sensible default behavior.

Specified by:
createNodeData in interface Content
Throws:
javax.jcr.RepositoryException

getNodeData

public NodeData getNodeData(String name)
Returns a NodeData object. If the node data does not exist (respectively if it has no value) an empty representation is returned whose NodeData.isExist() will return false. Delegates to newNodeDataInstance(String, int, boolean) by setting the type to PropertyType.UNDEFINED. A subclass has to handle this by trying to determine the type if the node data exists. The reason for this is that implementations want to instantiate different node data classes per type

Specified by:
getNodeData in interface Content
Returns:
NodeData requested NodeData object

newNodeDataInstance

public abstract NodeData newNodeDataInstance(String name,
                                             int type,
                                             boolean createIfNotExisting)
                                      throws AccessDeniedException,
                                             javax.jcr.RepositoryException
As defined in Content.getNodeData(String) this method always returns a node data object. If the type is PropertyType.UNDEFINED the implementation should check if the node data exists and determine the type to use.

Parameters:
createIfNotExisting - if false an empty non-mutable node data will be returned if the node data doesn't exist otherwise a mutable nodedata object is returned (depending on the type)
Throws:
AccessDeniedException
javax.jcr.RepositoryException

hasNodeData

public boolean hasNodeData(String name)
                    throws javax.jcr.RepositoryException
Delegates to NodeData.isExist().

Specified by:
hasNodeData in interface Content
Throws:
javax.jcr.RepositoryException - if an error occurs

setNodeData

public NodeData setNodeData(String name,
                            javax.jcr.Value value)
                     throws javax.jcr.PathNotFoundException,
                            javax.jcr.RepositoryException,
                            AccessDeniedException
Description copied from interface: Content
Sets the node data. If the node data does not yet exist the node data is created. Setting null is not allowed

Specified by:
setNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

setNodeData

public NodeData setNodeData(String name,
                            javax.jcr.Value[] value)
                     throws javax.jcr.PathNotFoundException,
                            javax.jcr.RepositoryException,
                            AccessDeniedException
Description copied from interface: Content
Sets the node data. If the node data does not yet exist the node data is created. Setting null is not allowed.

Specified by:
setNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

setNodeData

public NodeData setNodeData(String name,
                            boolean value)
                     throws javax.jcr.PathNotFoundException,
                            javax.jcr.RepositoryException,
                            AccessDeniedException
Description copied from interface: Content
Sets the node data. If the node data does not yet exist the node data is created. Setting null will remove the node data.

Specified by:
setNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

setNodeData

public NodeData setNodeData(String name,
                            long value)
                     throws javax.jcr.PathNotFoundException,
                            javax.jcr.RepositoryException,
                            AccessDeniedException
Description copied from interface: Content
Sets the node data. If the node data does not yet exist the node data is created. Setting null is not allowed.

Specified by:
setNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

setNodeData

public NodeData setNodeData(String name,
                            double value)
                     throws javax.jcr.PathNotFoundException,
                            javax.jcr.RepositoryException,
                            AccessDeniedException
Description copied from interface: Content
Sets the node data. If the node data does not yet exist the node data is created. Setting null will remove the node data.

Specified by:
setNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

setNodeData

public NodeData setNodeData(String name,
                            String value)
                     throws javax.jcr.PathNotFoundException,
                            javax.jcr.RepositoryException,
                            AccessDeniedException
Description copied from interface: Content
Sets the node data. If the node data does not yet exist the node data is created. Setting null is not allowed.

Specified by:
setNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

setNodeData

public NodeData setNodeData(String name,
                            InputStream value)
                     throws javax.jcr.PathNotFoundException,
                            javax.jcr.RepositoryException,
                            AccessDeniedException
Description copied from interface: Content
Sets the node data. If the node data does not yet exist the node data is created. Setting null is not allowed.

Specified by:
setNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

setNodeData

public NodeData setNodeData(String name,
                            Calendar value)
                     throws javax.jcr.PathNotFoundException,
                            javax.jcr.RepositoryException,
                            AccessDeniedException
Description copied from interface: Content
Sets the node data. If the node data does not yet exist the node data is created. Setting null will remove the node data.

Specified by:
setNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

setNodeData

public NodeData setNodeData(String name,
                            Content value)
                     throws javax.jcr.PathNotFoundException,
                            javax.jcr.RepositoryException,
                            AccessDeniedException
Description copied from interface: Content
Sets the node data. If the node data does not yet exist the node data is created. Setting null will remove the node data.

Specified by:
setNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

setNodeData

public NodeData setNodeData(String name,
                            Object value)
                     throws javax.jcr.PathNotFoundException,
                            javax.jcr.RepositoryException,
                            AccessDeniedException
Uses the NodeDataUtil to create and set the node data based on the object type.

Specified by:
setNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException
AccessDeniedException

deleteNodeData

public void deleteNodeData(String name)
                    throws javax.jcr.PathNotFoundException,
                           javax.jcr.RepositoryException
Description copied from interface: Content
Delete NodeData with the specified name.

Specified by:
deleteNodeData in interface Content
Throws:
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException - if an error occurs

getChildren

public Collection<Content> getChildren()
Gets a Collection containing all child nodes of the same NodeType as "this" object. Delegates to getChildren(ItemType) passing the current node's type.

Specified by:
getChildren in interface Content
Returns:
Collection of content objects

getChildren

public Collection<Content> getChildren(Content.ContentFilter filter)
Get a collection containing child nodes which satisfies the given filter. Delegates to getChildren(info.magnolia.cms.core.Content.ContentFilter, java.util.Comparator).

Specified by:
getChildren in interface Content
Returns:
Collection of content objects or empty collection when no children are found.

getChildren

public Collection<Content> getChildren(ItemType itemType)
Get collection of specified content type. Delegates to getChildren(info.magnolia.cms.core.Content.ContentFilter, java.util.Comparator).

Specified by:
getChildren in interface Content
Parameters:
itemType - ItemType
Returns:
Collection of content nodes

getChildren

public Collection<Content> getChildren(String contentType)
Get collection of specified content type and its subtypes. Delegates to getChildren(info.magnolia.cms.core.Content.ContentFilter, java.util.Comparator).

Specified by:
getChildren in interface Content
Parameters:
contentType - JCR node type as configured
Returns:
Collection of content nodes

getChildren

public Collection<Content> getChildren(String contentType,
                                       String namePattern)
Get collection of specified content type. Delegates to getChildren(info.magnolia.cms.core.Content.ContentFilter, String, java.util.Comparator).

Specified by:
getChildren in interface Content
Parameters:
contentType - JCR node type as configured
Returns:
Collection of content nodes

getChildren

public Collection<Content> getChildren(Content.ContentFilter filter,
                                       Comparator<Content> orderCriteria)
Get a collection containing child nodes which satisfies the given filter. The returned collection is ordered according to the passed in criteria. Delegates to getChildren(info.magnolia.cms.core.Content.ContentFilter, String, java.util.Comparator).

Specified by:
getChildren in interface Content
Parameters:
filter - filter for the child nodes
orderCriteria - ordering for the selected child nodes; if null than no particular order of the child nodes
Returns:
Collection of content objects or empty collection when no children are found.

getChildren

public abstract Collection<Content> getChildren(Content.ContentFilter filter,
                                                String namePattern,
                                                Comparator<Content> orderCriteria)
Parameters:
namePattern - ignored if null.

getChildByName

@Deprecated
public Content getChildByName(String namePattern)
Deprecated. 

Description copied from interface: Content
Returns the first child with the given name, any node type.

Specified by:
getChildByName in interface Content
Parameters:
namePattern - child node name
Returns:
first found node with the given name or null if not found

getNodeDataCollection

public Collection<NodeData> getNodeDataCollection()
Description copied from interface: Content
Gets all properties bind in NodeData object excluding JCR system properties.

Specified by:
getNodeDataCollection in interface Content

getBinaryNodeDatas

protected Collection<NodeData> getBinaryNodeDatas(String namePattern)
                                           throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

hasChildren

public boolean hasChildren()
Specified by:
hasChildren in interface Content
Returns:
Boolean, if sub node(s) exists

hasChildren

public boolean hasChildren(String contentType)
Specified by:
hasChildren in interface Content
Parameters:
contentType - JCR node type as configured
Returns:
Boolean, if sub collectionType exists

delete

public void delete(String path)
            throws javax.jcr.RepositoryException
Description copied from interface: Content
Remove specified path.

Specified by:
delete in interface Content
Throws:
javax.jcr.RepositoryException - if an error occurs

isNodeData

public boolean isNodeData(String path)
                   throws AccessDeniedException,
                          javax.jcr.RepositoryException
Description copied from interface: Content
checks if the requested resource is an NodeData (Property).

Specified by:
isNodeData in interface Content
Parameters:
path - of the requested NodeData
Returns:
boolean true is the requested content is an NodeData
Throws:
AccessDeniedException
javax.jcr.RepositoryException - if an error occurs

getTemplate

public String getTemplate()
Description copied from interface: Content
Returns the template name which is assigned to this content.

Specified by:
getTemplate in interface Content

getTitle

public String getTitle()
Specified by:
getTitle in interface Content
Returns:
String, title

updateMetaData

public void updateMetaData()
                    throws javax.jcr.RepositoryException,
                           AccessDeniedException
Description copied from interface: Content
You could call this method anytime to update working page properties - Modification date & Author ID.

Specified by:
updateMetaData in interface Content
Throws:
AccessDeniedException - if the current session does not have sufficient access rights to complete the operation
javax.jcr.RepositoryException - if an error occurs

isGranted

public boolean isGranted(long permissions)
Description copied from interface: Content
Checks for the allowed access rights.

Specified by:
isGranted in interface Content
Parameters:
permissions - as defined in javax.jcr.Permission
Returns:
true if the current user has specified access on this node.

getWorkspace

public javax.jcr.Workspace getWorkspace()
                                 throws javax.jcr.RepositoryException
Description copied from interface: Content
get workspace to which this node attached to.

Specified by:
getWorkspace in interface Content
Throws:
javax.jcr.RepositoryException - if unable to get this node session

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2003-2012 Magnolia International Ltd.. All Rights Reserved.