org.apache.cocoon.jcr.source
Class JCRSourceFactory

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

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.java 240329 2005-08-26 20:04:15Z vgritsenko $

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  javax.jcr.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)
           
 javax.jcr.Node createContentNode(javax.jcr.Node fileNode)
          Create the content node for a file node.
 javax.jcr.Node createFileNode(javax.jcr.Node folderNode, String name)
          Create a child file node in a folder node.
 JCRNodeSource createSource(JCRNodeSource parent, javax.jcr.Node node)
          Creates a new source given its parent and its node
 JCRNodeSource createSource(javax.jcr.Session session, String path)
          Creates a new source given a session and a path
 javax.jcr.Node getContentNode(javax.jcr.Node node)
          Get the content node for a given node
 javax.jcr.Property getContentProperty(javax.jcr.Node node)
          Get the content property for a given node
 String getFolderNodeType(javax.jcr.Node folderNode)
          Get the node type to create a new subfolder of a given folder node.
 javax.jcr.Property getLastModifiedDateProperty(javax.jcr.Node node)
          Get the lastmodified property for a given node
 javax.jcr.Property getMimeTypeProperty(javax.jcr.Node node)
          Get the mime-type property for a given node
 String getScheme()
           
 Source getSource(String uri, Map parameters)
           
 JCRSourceFactory.NodeTypeInfo getTypeInfo(javax.jcr.Node node)
          Get the type info for a node.
 JCRSourceFactory.NodeTypeInfo getTypeInfo(String typeName)
          Get the type info for a given node type name.
 javax.jcr.Property getValidityProperty(javax.jcr.Node node)
          Get the validity property for a given node
 boolean isCollection(javax.jcr.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 javax.jcr.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(javax.jcr.Node node)
                                          throws javax.jcr.RepositoryException
Get the type info for a node.

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

getTypeInfo

public JCRSourceFactory.NodeTypeInfo getTypeInfo(String typeName)
                                          throws javax.jcr.RepositoryException
Get the type info for a given node type name.

Parameters:
typeName - the type name
Returns:
the type info
Throws:
javax.jcr.RepositoryException - if no type info is found

getContentNode

public javax.jcr.Node getContentNode(javax.jcr.Node node)
                              throws javax.jcr.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:
javax.jcr.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,
                                  javax.jcr.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(javax.jcr.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 javax.jcr.Node createFileNode(javax.jcr.Node folderNode,
                                     String name)
                              throws javax.jcr.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:
javax.jcr.RepositoryException - if some error occurs

createContentNode

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

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

getContentProperty

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

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

getMimeTypeProperty

public javax.jcr.Property getMimeTypeProperty(javax.jcr.Node node)
                                       throws javax.jcr.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:
javax.jcr.RepositoryException - if some error occurs

getLastModifiedDateProperty

public javax.jcr.Property getLastModifiedDateProperty(javax.jcr.Node node)
                                               throws javax.jcr.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:
javax.jcr.RepositoryException - if some error occurs

getValidityProperty

public javax.jcr.Property getValidityProperty(javax.jcr.Node node)
                                       throws javax.jcr.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:
javax.jcr.RepositoryException - if some error occurs

isCollection

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

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

getFolderNodeType

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

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


Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.