org.apache.cocoon.jcr.source
Class JCRSourceFactory

java.lang.Object
  extended by org.apache.cocoon.jcr.source.JCRSourceFactory
All Implemented Interfaces:
Configurable, Serviceable, ThreadSafe, SourceFactory

public class JCRSourceFactory
extends Object
implements ThreadSafe, SourceFactory, Configurable, Serviceable

JCRSourceFactory is an implementation of ModifiableTraversableSource on top of a JCR (aka JSR-170) repository.

Since JCR allows a repository to define its own node types, it is necessary to configure this source factory with a description of what node types map to "files" and "folders" and the properties used to store source-related data.

A typical configuration for a naked Jackrabbit repository is as follows:


    <source-factories>
      <component-instance class="org.apache.cocoon.jcr.source.JCRSourceFactory" name="jcr">
        <folder-node type="rep:root"  new-file="nt:file" new-folder="nt:folder"/>
        <folder-node type="nt:folder" new-file="nt:file"/>
        <file-node type="nt:file" content-path="jcr:content" content-type="nt:resource"/>
        <file-node type="nt:linkedFile" content-ref="jcr:content"/>
        <content-node type="nt:resource"
                      content-prop="jcr:data"
                      mimetype-prop="jcr:mimeType"
                      lastmodified-prop="jcr:lastModified"
                      validity-prop="jcr:lastModified"/>
      </component-instance>
    </source-factories>

 
A <folder-node> defines a node type that is mapped to a non-terminal source (i.e. that can have children). The new-file and new-folder attributes respectively define what node types should be used to create a new terminal and non-terminal source.

A <file-node> defines a note type that is mapped to a terminal source (i.e. that can have some content). The content-path attribute defines the path to the node's child that actually holds the content, and content-type defines the type of this content node.

The content-ref attribute is used to comply with JCR's nt:linkedFile definition where the content node is not a direct child of the file node, but is referenced by a property of this file node. Such node types are read-only as there's no way to indicate where the referenced content node should be created.

A <content-node> defines a node type that actually holds the content of a file-node. The content-prop attribute must be present and gives the name of the node's binary property that will hold the actual content. Other attributes are optional:

The format of URIs for this source is a path in the repository, and it is therefore currently limited to repository traversal. Further work will add the ability to specify query strings.

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

Nested Class Summary
protected static class JCRSourceFactory.ContentTypeInfo
           
protected static class JCRSourceFactory.FileTypeInfo
           
protected static class JCRSourceFactory.FolderTypeInfo
           
protected static class JCRSourceFactory.NodeTypeInfo
           
 
Field Summary
protected  ServiceManager manager
           
protected  Repository repo
          The repository we use
protected  String scheme
          Scheme, lazily computed at the first call to getSource()
protected  Map typeInfos
          The NodeTypeInfo for each of the types described in the configuration
 
Fields inherited from interface org.apache.excalibur.source.SourceFactory
ROLE
 
Constructor Summary
JCRSourceFactory()
           
 
Method Summary
 void configure(Configuration config)
           
 Node createContentNode(Node fileNode)
          Create the content node for a file node.
 Node createFileNode(Node folderNode, String name)
          Create a child file node in a folder node.
 JCRNodeSource createSource(JCRNodeSource parent, Node node)
          Creates a new source given its parent and its node
 JCRNodeSource createSource(Session session, String path)
          Creates a new source given a session and a path
 Node getContentNode(Node node)
          Get the content node for a given node
 Property getContentProperty(Node node)
          Get the content property for a given node
 String getFolderNodeType(Node folderNode)
          Get the node type to create a new subfolder of a given folder node.
 Property getLastModifiedDateProperty(Node node)
          Get the lastmodified property for a given node
 Property getMimeTypeProperty(Node node)
          Get the mime-type property for a given node
 String getScheme()
           
 Source getSource(String uri, Map parameters)
           
 JCRSourceFactory.NodeTypeInfo getTypeInfo(Node node)
          Get the type info for a node.
 Property getValidityProperty(Node node)
          Get the validity property for a given node
 boolean isCollection(Node node)
          Does a node represent a collection (i.e. folder-node)?
protected  void lazyInit()
           
 void release(Source source)
           
 void service(ServiceManager manager)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

repo

protected Repository repo
The repository we use


scheme

protected String scheme
Scheme, lazily computed at the first call to getSource()


typeInfos

protected Map typeInfos
The NodeTypeInfo for each of the types described in the configuration


manager

protected ServiceManager manager
Constructor Detail

JCRSourceFactory

public JCRSourceFactory()
Method Detail

service

public void service(ServiceManager manager)
             throws ServiceException
Specified by:
service in interface Serviceable
Throws:
ServiceException

configure

public void configure(Configuration config)
               throws ConfigurationException
Specified by:
configure in interface Configurable
Throws:
ConfigurationException

lazyInit

protected void lazyInit()

getSource

public Source getSource(String uri,
                        Map parameters)
                 throws IOException,
                        MalformedURLException
Specified by:
getSource in interface SourceFactory
Throws:
IOException
MalformedURLException

release

public void release(Source source)
Specified by:
release in interface SourceFactory

getScheme

public String getScheme()

getTypeInfo

public JCRSourceFactory.NodeTypeInfo getTypeInfo(Node node)
                                          throws RepositoryException
Get the type info for a node.

Parameters:
node - the node
Returns:
the type info
Throws:
RepositoryException - if node type couldn't be accessed or if no type info is found

getContentNode

public Node getContentNode(Node node)
                    throws RepositoryException
Get the content node for a given node

Parameters:
node - the node for which we want the content node
Returns:
the content node
Throws:
RepositoryException - if some error occurs, or if the given node isn't a file node or a content node

createSource

public JCRNodeSource createSource(JCRNodeSource parent,
                                  Node node)
                           throws SourceException
Creates a new source given its parent and its node

Parameters:
parent - the parent
node - the node
Returns:
a new source
Throws:
SourceException

createSource

public JCRNodeSource createSource(Session session,
                                  String path)
                           throws SourceException
Creates a new source given a session and a path

Parameters:
session - the session
path - the absolute path
Returns:
a new source
Throws:
SourceException

createFileNode

public Node createFileNode(Node folderNode,
                           String name)
                    throws RepositoryException
Create a child file node in a folder node.

Parameters:
folderNode - the folder node
name - the child's name
Returns:
the newly created child node
Throws:
RepositoryException - if some error occurs

createContentNode

public Node createContentNode(Node fileNode)
                       throws RepositoryException
Create the content node for a file node.

Parameters:
fileNode - the file node
Returns:
the content node for this file node
Throws:
RepositoryException - if some error occurs

getContentProperty

public Property getContentProperty(Node node)
                            throws RepositoryException
Get the content property for a given node

Parameters:
node - a file or content node
Returns:
the content property
Throws:
RepositoryException - if some error occurs

getMimeTypeProperty

public Property getMimeTypeProperty(Node node)
                             throws RepositoryException
Get the mime-type property for a given node

Parameters:
node - a file or content node
Returns:
the mime-type property, or null if no such property exists
Throws:
RepositoryException - if some error occurs

getLastModifiedDateProperty

public Property getLastModifiedDateProperty(Node node)
                                     throws RepositoryException
Get the lastmodified property for a given node

Parameters:
node - a file or content node
Returns:
the lastmodified property, or null if no such property exists
Throws:
RepositoryException - if some error occurs

getValidityProperty

public Property getValidityProperty(Node node)
                             throws RepositoryException
Get the validity property for a given node

Parameters:
node - a file or content node
Returns:
the validity property, or null if no such property exists
Throws:
RepositoryException - if some error occurs

isCollection

public boolean isCollection(Node node)
                     throws RepositoryException
Does a node represent a collection (i.e. folder-node)?

Parameters:
node - the node
Returns:
true if it's a collection
Throws:
RepositoryException - if some error occurs

getFolderNodeType

public String getFolderNodeType(Node folderNode)
                         throws RepositoryException
Get the node type to create a new subfolder of a given folder node.

Parameters:
folderNode -
Returns:
the child folder node type
Throws:
RepositoryException - if some error occurs


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