org.gcube.server.io
Class GcubeHandler

java.lang.Object
  extended by org.gcube.server.io.GcubeHandler
All Implemented Interfaces:
org.apache.jackrabbit.server.io.CopyMoveHandler, org.apache.jackrabbit.server.io.IOHandler, org.apache.jackrabbit.server.io.PropertyHandler

public class GcubeHandler
extends Object
implements org.apache.jackrabbit.server.io.IOHandler, org.apache.jackrabbit.server.io.PropertyHandler, org.apache.jackrabbit.server.io.CopyMoveHandler

DefaultHandler implements a simple IOHandler that creates 'file' and 'folder' nodes. This handler will create the following nodes:

Import of the content:
The content is imported to the JcrConstants.JCR_DATA property of the content node. By default this handler will fail on a attempt to create/replace a collection if IOContext.hasStream() is true. Subclasses therefore should provide their own importData method, that handles the data according their needs.


Constructor Summary
GcubeHandler()
          Creates a new DefaultHandler with default nodetype definitions:
Nodetype for Collection: nt:folder Nodetype for Non-Collection: nt:file Nodetype for Non-Collection content: nt:unstructured
GcubeHandler(org.apache.jackrabbit.server.io.IOManager ioManager)
          Creates a new DefaultHandler with default nodetype definitions:
Nodetype for Collection: nt:folder Nodetype for Non-Collection: nt:file Nodetype for Non-Collection content: nt:unstructured
GcubeHandler(org.apache.jackrabbit.server.io.IOManager ioManager, String collectionNodetype, String defaultNodetype, String contentNodetype)
          Creates a new DefaultHandler.
 
Method Summary
 boolean canCopy(org.apache.jackrabbit.server.io.CopyMoveContext context, org.apache.jackrabbit.webdav.DavResource source, org.apache.jackrabbit.webdav.DavResource destination)
           
 boolean canExport(org.apache.jackrabbit.server.io.ExportContext context, boolean isCollection)
          Returns true if the export root is a node and if it contains a child node with name jcr:content in case this export is not intended for a collection.
 boolean canExport(org.apache.jackrabbit.server.io.ExportContext context, org.apache.jackrabbit.webdav.DavResource resource)
           
 boolean canExport(org.apache.jackrabbit.server.io.PropertyExportContext context, boolean isCollection)
           
 boolean canImport(org.apache.jackrabbit.server.io.ImportContext context, boolean isCollection)
           
 boolean canImport(org.apache.jackrabbit.server.io.ImportContext context, org.apache.jackrabbit.webdav.DavResource resource)
           
 boolean canImport(org.apache.jackrabbit.server.io.PropertyImportContext context, boolean isCollection)
           
 boolean canMove(org.apache.jackrabbit.server.io.CopyMoveContext context, org.apache.jackrabbit.webdav.DavResource source, org.apache.jackrabbit.webdav.DavResource destination)
           
 boolean copy(org.apache.jackrabbit.server.io.CopyMoveContext context, org.apache.jackrabbit.webdav.DavResource source, org.apache.jackrabbit.webdav.DavResource destination)
           
protected  String detect(String name)
          Detects the media type of a document based on the given name.
 boolean exportContent(org.apache.jackrabbit.server.io.ExportContext context, boolean isCollection)
          Retrieves the content node that will be used for exporting properties and data and calls the corresponding methods.
 boolean exportContent(org.apache.jackrabbit.server.io.ExportContext context, org.apache.jackrabbit.webdav.DavResource resource)
          Same as (@link IOHandler#exportContent(ExportContext, boolean)} where the boolean values is defined by DavResource.isCollection().
protected  void exportData(org.apache.jackrabbit.server.io.ExportContext context, boolean isCollection, javax.jcr.Node contentNode)
          Checks if the given content node contains a jcr:data property and spools its value to the output stream of the export context.
Please note, that subclasses that define a different structure of the content node should create their own exportData method.
protected  void exportProperties(org.apache.jackrabbit.server.io.ExportContext context, boolean isCollection, javax.jcr.Node contentNode)
          Retrieves mimetype, encoding and modification time from the content node.
 boolean exportProperties(org.apache.jackrabbit.server.io.PropertyExportContext exportContext, boolean isCollection)
           
protected  boolean forceCompatibleContentNodes()
          Defines if content nodes should be replace if they don't have the node type given by getCollectionNodeType().
 String getCollectionNodeType()
          Name of the nodetype to be used to create a new collection node (folder)
protected  javax.jcr.Node getContentNode(org.apache.jackrabbit.server.io.ExportContext context, boolean isCollection)
          Retrieves the content node that contains the data to be exported.
protected  javax.jcr.Node getContentNode(org.apache.jackrabbit.server.io.ImportContext context, boolean isCollection)
          Retrieves/creates the node that will be used to import properties and data.
 String getContentNodeType()
          Name of the nodetype to be used to create the content node below a new non-collection node, whose name is always jcr:content.
 org.apache.jackrabbit.server.io.IOManager getIOManager()
           
 String getName()
           
 String getNodeType()
          Name of the nodetype to be used to create a new non-collection node (file)
 boolean importContent(org.apache.jackrabbit.server.io.ImportContext context, boolean isCollection)
           
 boolean importContent(org.apache.jackrabbit.server.io.ImportContext context, org.apache.jackrabbit.webdav.DavResource resource)
           
protected  boolean importData(org.apache.jackrabbit.server.io.ImportContext context, boolean isCollection, javax.jcr.Node contentNode)
          Imports the data present on the import context to the specified content node.
protected  boolean importProperties(org.apache.jackrabbit.server.io.ImportContext context, boolean isCollection, javax.jcr.Node contentNode)
          Imports the properties present on the specified context to the content node.
 Map<? extends org.apache.jackrabbit.webdav.property.PropEntry,?> importProperties(org.apache.jackrabbit.server.io.PropertyImportContext importContext, boolean isCollection)
           
 boolean move(org.apache.jackrabbit.server.io.CopyMoveContext context, org.apache.jackrabbit.webdav.DavResource source, org.apache.jackrabbit.webdav.DavResource destination)
           
 void setCollectionNodetype(String collectionNodetype)
           
 void setContentNodetype(String contentNodetype)
           
 void setDefaultNodetype(String defaultNodetype)
           
 void setIOManager(org.apache.jackrabbit.server.io.IOManager ioManager)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GcubeHandler

public GcubeHandler()
Creates a new DefaultHandler with default nodetype definitions:


GcubeHandler

public GcubeHandler(org.apache.jackrabbit.server.io.IOManager ioManager)
Creates a new DefaultHandler with default nodetype definitions:

Parameters:
ioManager - the I/O manager

GcubeHandler

public GcubeHandler(org.apache.jackrabbit.server.io.IOManager ioManager,
                    String collectionNodetype,
                    String defaultNodetype,
                    String contentNodetype)
Creates a new DefaultHandler. Please note that the specified nodetypes must match the definitions of the defaults.

Parameters:
ioManager -
collectionNodetype -
defaultNodetype -
contentNodetype -
Method Detail

getIOManager

public org.apache.jackrabbit.server.io.IOManager getIOManager()
Specified by:
getIOManager in interface org.apache.jackrabbit.server.io.IOHandler
See Also:
IOHandler.getIOManager()

setIOManager

public void setIOManager(org.apache.jackrabbit.server.io.IOManager ioManager)
Specified by:
setIOManager in interface org.apache.jackrabbit.server.io.IOHandler
See Also:
IOHandler.setIOManager(IOManager)

getName

public String getName()
Specified by:
getName in interface org.apache.jackrabbit.server.io.IOHandler
See Also:
IOHandler.getName()

canImport

public boolean canImport(org.apache.jackrabbit.server.io.ImportContext context,
                         boolean isCollection)
Specified by:
canImport in interface org.apache.jackrabbit.server.io.IOHandler
See Also:
IOHandler.canImport(ImportContext, boolean)

canImport

public boolean canImport(org.apache.jackrabbit.server.io.ImportContext context,
                         org.apache.jackrabbit.webdav.DavResource resource)
Specified by:
canImport in interface org.apache.jackrabbit.server.io.IOHandler
See Also:
IOHandler.canImport(ImportContext, DavResource)

importContent

public boolean importContent(org.apache.jackrabbit.server.io.ImportContext context,
                             boolean isCollection)
                      throws IOException
Specified by:
importContent in interface org.apache.jackrabbit.server.io.IOHandler
Throws:
IOException
See Also:
IOHandler.importContent(ImportContext, boolean)

importContent

public boolean importContent(org.apache.jackrabbit.server.io.ImportContext context,
                             org.apache.jackrabbit.webdav.DavResource resource)
                      throws IOException
Specified by:
importContent in interface org.apache.jackrabbit.server.io.IOHandler
Throws:
IOException
See Also:
IOHandler.importContent(ImportContext, DavResource)

importData

protected boolean importData(org.apache.jackrabbit.server.io.ImportContext context,
                             boolean isCollection,
                             javax.jcr.Node contentNode)
                      throws IOException,
                             javax.jcr.RepositoryException
Imports the data present on the import context to the specified content node.

Parameters:
context -
isCollection -
contentNode -
Returns:
Throws:
IOException
javax.jcr.RepositoryException

importProperties

protected boolean importProperties(org.apache.jackrabbit.server.io.ImportContext context,
                                   boolean isCollection,
                                   javax.jcr.Node contentNode)
Imports the properties present on the specified context to the content node.

Parameters:
context -
isCollection -
contentNode -
Returns:

getContentNode

protected javax.jcr.Node getContentNode(org.apache.jackrabbit.server.io.ImportContext context,
                                        boolean isCollection)
                                 throws javax.jcr.RepositoryException
Retrieves/creates the node that will be used to import properties and data. In case of a non-collection this includes and additional content node to be created beside the 'file' node.
Please note: If the jcr:content node already exists and contains child nodes, those will be removed in order to make sure, that the import really replaces the existing content of the file-node.

Parameters:
context -
isCollection -
Returns:
Throws:
javax.jcr.RepositoryException

forceCompatibleContentNodes

protected boolean forceCompatibleContentNodes()
Defines if content nodes should be replace if they don't have the node type given by getCollectionNodeType().

Returns:
true if content nodes should be replaced.

canExport

public boolean canExport(org.apache.jackrabbit.server.io.ExportContext context,
                         boolean isCollection)
Returns true if the export root is a node and if it contains a child node with name jcr:content in case this export is not intended for a collection.

Specified by:
canExport in interface org.apache.jackrabbit.server.io.IOHandler
Returns:
true if the export root is a node. If the specified boolean parameter is false (not a collection export) the given export root must contain a child node with name jcr:content.
See Also:
IOHandler.canExport(ExportContext, boolean)

canExport

public boolean canExport(org.apache.jackrabbit.server.io.ExportContext context,
                         org.apache.jackrabbit.webdav.DavResource resource)
Specified by:
canExport in interface org.apache.jackrabbit.server.io.IOHandler
See Also:
IOHandler.canExport(ExportContext, DavResource)

exportContent

public boolean exportContent(org.apache.jackrabbit.server.io.ExportContext context,
                             boolean isCollection)
                      throws IOException
Retrieves the content node that will be used for exporting properties and data and calls the corresponding methods.

Specified by:
exportContent in interface org.apache.jackrabbit.server.io.IOHandler
Parameters:
context - the export context
isCollection - true if collection
Throws:
IOException
See Also:
exportProperties(ExportContext, boolean, Node), exportData(ExportContext, boolean, Node)

exportContent

public boolean exportContent(org.apache.jackrabbit.server.io.ExportContext context,
                             org.apache.jackrabbit.webdav.DavResource resource)
                      throws IOException
Same as (@link IOHandler#exportContent(ExportContext, boolean)} where the boolean values is defined by DavResource.isCollection().

Specified by:
exportContent in interface org.apache.jackrabbit.server.io.IOHandler
Throws:
IOException
See Also:
IOHandler.exportContent(ExportContext, DavResource)

exportData

protected void exportData(org.apache.jackrabbit.server.io.ExportContext context,
                          boolean isCollection,
                          javax.jcr.Node contentNode)
                   throws IOException,
                          javax.jcr.RepositoryException
Checks if the given content node contains a jcr:data property and spools its value to the output stream of the export context.
Please note, that subclasses that define a different structure of the content node should create their own exportData method.

Parameters:
context - export context
isCollection - true if collection
contentNode - the content node
Throws:
IOException - if an I/O error occurs
javax.jcr.RepositoryException

exportProperties

protected void exportProperties(org.apache.jackrabbit.server.io.ExportContext context,
                                boolean isCollection,
                                javax.jcr.Node contentNode)
                         throws IOException
Retrieves mimetype, encoding and modification time from the content node. The content length is determined by the length of the jcr:data property if it is present. The creation time however is retrieved from the parent node (in case of isCollection == false only).

Parameters:
context - the export context
isCollection - true if collection
contentNode - the content node
Throws:
IOException - If an error occurs.

getContentNode

protected javax.jcr.Node getContentNode(org.apache.jackrabbit.server.io.ExportContext context,
                                        boolean isCollection)
                                 throws javax.jcr.RepositoryException
Retrieves the content node that contains the data to be exported. In case isCollection is true, this corresponds to the export root. Otherwise there must be a child node with name jcr:content.

Parameters:
context - the export context
isCollection - true if collection
Returns:
content node used for the export
Throws:
javax.jcr.RepositoryException - if an error during repository access occurs.

getCollectionNodeType

public String getCollectionNodeType()
Name of the nodetype to be used to create a new collection node (folder)

Returns:
nodetype name

getNodeType

public String getNodeType()
Name of the nodetype to be used to create a new non-collection node (file)

Returns:
nodetype name

getContentNodeType

public String getContentNodeType()
Name of the nodetype to be used to create the content node below a new non-collection node, whose name is always jcr:content.

Returns:
nodetype name

canExport

public boolean canExport(org.apache.jackrabbit.server.io.PropertyExportContext context,
                         boolean isCollection)
Specified by:
canExport in interface org.apache.jackrabbit.server.io.PropertyHandler

exportProperties

public boolean exportProperties(org.apache.jackrabbit.server.io.PropertyExportContext exportContext,
                                boolean isCollection)
                         throws javax.jcr.RepositoryException
Specified by:
exportProperties in interface org.apache.jackrabbit.server.io.PropertyHandler
Throws:
javax.jcr.RepositoryException

canImport

public boolean canImport(org.apache.jackrabbit.server.io.PropertyImportContext context,
                         boolean isCollection)
Specified by:
canImport in interface org.apache.jackrabbit.server.io.PropertyHandler

importProperties

public Map<? extends org.apache.jackrabbit.webdav.property.PropEntry,?> importProperties(org.apache.jackrabbit.server.io.PropertyImportContext importContext,
                                                                                         boolean isCollection)
                                                                                  throws javax.jcr.RepositoryException
Specified by:
importProperties in interface org.apache.jackrabbit.server.io.PropertyHandler
Throws:
javax.jcr.RepositoryException

detect

protected String detect(String name)
Detects the media type of a document based on the given name.

Parameters:
name - document name
Returns:
detected content type (or application/octet-stream)

canCopy

public boolean canCopy(org.apache.jackrabbit.server.io.CopyMoveContext context,
                       org.apache.jackrabbit.webdav.DavResource source,
                       org.apache.jackrabbit.webdav.DavResource destination)
Specified by:
canCopy in interface org.apache.jackrabbit.server.io.CopyMoveHandler
See Also:
CopyMoveHandler.canCopy(CopyMoveContext, org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.DavResource)

copy

public boolean copy(org.apache.jackrabbit.server.io.CopyMoveContext context,
                    org.apache.jackrabbit.webdav.DavResource source,
                    org.apache.jackrabbit.webdav.DavResource destination)
             throws org.apache.jackrabbit.webdav.DavException
Specified by:
copy in interface org.apache.jackrabbit.server.io.CopyMoveHandler
Throws:
org.apache.jackrabbit.webdav.DavException
See Also:
CopyMoveHandler.copy(CopyMoveContext, org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.DavResource)

canMove

public boolean canMove(org.apache.jackrabbit.server.io.CopyMoveContext context,
                       org.apache.jackrabbit.webdav.DavResource source,
                       org.apache.jackrabbit.webdav.DavResource destination)
Specified by:
canMove in interface org.apache.jackrabbit.server.io.CopyMoveHandler
See Also:
CopyMoveHandler.canMove(CopyMoveContext, org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.DavResource)

move

public boolean move(org.apache.jackrabbit.server.io.CopyMoveContext context,
                    org.apache.jackrabbit.webdav.DavResource source,
                    org.apache.jackrabbit.webdav.DavResource destination)
             throws org.apache.jackrabbit.webdav.DavException
Specified by:
move in interface org.apache.jackrabbit.server.io.CopyMoveHandler
Throws:
org.apache.jackrabbit.webdav.DavException
See Also:
CopyMoveHandler.move(CopyMoveContext, org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.DavResource)

setCollectionNodetype

public void setCollectionNodetype(String collectionNodetype)

setDefaultNodetype

public void setDefaultNodetype(String defaultNodetype)

setContentNodetype

public void setContentNodetype(String contentNodetype)


Copyright © 2013. All Rights Reserved.