org.apache.jackrabbit.server.io
Class DefaultHandler

java.lang.Object
  extended byorg.apache.jackrabbit.server.io.DefaultHandler
All Implemented Interfaces:
IOHandler
Direct Known Subclasses:
XmlHandler, ZipHandler

public class DefaultHandler
extends Object
implements IOHandler

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
DefaultHandler(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:resource
DefaultHandler(IOManager ioManager, String collectionNodetype, String defaultNodetype, String contentNodetype)
          Creates a new DefaultHandler.
 
Method Summary
 boolean canExport(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(ExportContext context, org.apache.jackrabbit.webdav.DavResource resource)
          Returns true, if this handler can run a successful export based on the specified context and resource.
 boolean canImport(ImportContext context, boolean isCollection)
          Returns true, if this handler can run a successful import based on the specified context.
 boolean canImport(ImportContext context, org.apache.jackrabbit.webdav.DavResource resource)
          Returns true, if this handler can run a successful import based on the specified context and resource.
 boolean exportContent(ExportContext context, boolean isCollection)
          Retrieves the content node that will be used for exporting properties and data and calls the corresponding methods.
 boolean exportContent(ExportContext context, org.apache.jackrabbit.webdav.DavResource resource)
          Same as (@link #exportContent(ExportContext, boolean)} where the boolean values is defined by DavResource.isCollection().
protected  void exportData(ExportContext context, boolean isCollection, Node contentNode)
          Checks if the given content node contains a jcr:data property and spools its value to the output stream fo 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(ExportContext context, boolean isCollection, Node contentNode)
          Retrieves mimetype, encoding and modification time from the content node.
protected  String getCollectionNodeType()
          Name of the nodetype to be used to create a new collection node (folder)
protected  Node getContentNode(ExportContext context, boolean isCollection)
          Retrieves the content node that contains the data to be exported.
protected  Node getContentNode(ImportContext context, boolean isCollection)
          Retrieves/creates the node that will be used to import properties and data.
protected  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.
 IOManager getIOManager()
          Returns the IOManager that called this handler or null.
 String getName()
          Returns a human readable name for this IOHandler
protected  String getNodeType()
          Name of the nodetype to be used to create a new non-collection node (file)
 boolean importContent(ImportContext context, boolean isCollection)
          Runs the import for the given context and indicates by a boolean return value, if the import could be completed successfully.
 boolean importContent(ImportContext context, org.apache.jackrabbit.webdav.DavResource resource)
          Runs the import for the given context and resource.
protected  boolean importData(ImportContext context, boolean isCollection, Node contentNode)
          Imports the data present on the import context to the specified content node.
protected  boolean importProperties(ImportContext context, boolean isCollection, Node contentNode)
          Imports the properties present on the specified context to the content node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultHandler

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

Parameters:
ioManager -

DefaultHandler

public DefaultHandler(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 IOManager getIOManager()
Description copied from interface: IOHandler
Returns the IOManager that called this handler or null.

Specified by:
getIOManager in interface IOHandler
Returns:
See Also:
IOHandler.getIOManager()

getName

public String getName()
Description copied from interface: IOHandler
Returns a human readable name for this IOHandler

Specified by:
getName in interface IOHandler
Returns:
See Also:
IOHandler.getName()

canImport

public boolean canImport(ImportContext context,
                         boolean isCollection)
Description copied from interface: IOHandler
Returns true, if this handler can run a successful import based on the specified context.

Specified by:
canImport in interface IOHandler
Parameters:
context -
isCollection -
Returns:
See Also:
IOHandler.canImport(ImportContext, boolean)

canImport

public boolean canImport(ImportContext context,
                         org.apache.jackrabbit.webdav.DavResource resource)
Description copied from interface: IOHandler
Returns true, if this handler can run a successful import based on the specified context and resource. A simple implementation may choose to return the same as IOHandler.canImport(ImportContext, boolean) where the isCollection flag is determined by DavResource.isCollection().

Specified by:
canImport in interface IOHandler
Parameters:
context -
resource -
Returns:
See Also:
IOHandler.canImport(ImportContext, DavResource)

importContent

public boolean importContent(ImportContext context,
                             boolean isCollection)
                      throws IOException
Description copied from interface: IOHandler
Runs the import for the given context and indicates by a boolean return value, if the import could be completed successfully. If the specified ImportContext does not provide a stream the implementation is free, to only import properties of to refuse the import.
Please note, that it is the responsibility of the specified ImportContext to assert, that its stream is not consumed multiple times when being passed to a chain of IOHandlers.

Specified by:
importContent in interface IOHandler
Parameters:
context -
isCollection -
Returns:
true if the import was successful.
Throws:
IOException - if an unexpected error occurs or if this method has been called although IOHandler.canImport(ImportContext, boolean) returns false.
See Also:
IOHandler.importContent(ImportContext, boolean)

importContent

public boolean importContent(ImportContext context,
                             org.apache.jackrabbit.webdav.DavResource resource)
                      throws IOException
Description copied from interface: IOHandler
Runs the import for the given context and resource. It indicates by a boolean return value, if the import could be completed successfully. If the specified ImportContext does not provide a stream the implementation is free, to only import properties of to refuse the import. A simple implementation may return the same as IOHandler.importContent(ImportContext, boolean) where the isCollection flag is determined by DavResource.isCollection()
Please note, that it is the responsibility of the specified ImportContext to assert, that its stream is not consumed multiple times when being passed to a chain of IOHandlers.

Specified by:
importContent in interface IOHandler
Parameters:
context -
resource -
Returns:
Throws:
IOException - if an unexpected error occurs or if this method has been called although IOHandler.canImport(ImportContext, DavResource) returns false.
See Also:
IOHandler.importContent(ImportContext, DavResource)

importData

protected boolean importData(ImportContext context,
                             boolean isCollection,
                             Node contentNode)
                      throws IOException,
                             RepositoryException
Imports the data present on the import context to the specified content node.

Parameters:
context -
isCollection -
contentNode -
Returns:
Throws:
IOException
RepositoryException

importProperties

protected boolean importProperties(ImportContext context,
                                   boolean isCollection,
                                   Node contentNode)
Imports the properties present on the specified context to the content node.

Parameters:
context -
isCollection -
contentNode -
Returns:

getContentNode

protected Node getContentNode(ImportContext context,
                              boolean isCollection)
                       throws 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:
RepositoryException

canExport

public boolean canExport(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 IOHandler
Parameters:
context -
isCollection -
Returns:
true if the export root is a node. If the specified boolean paramter 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(ExportContext context,
                         org.apache.jackrabbit.webdav.DavResource resource)
Description copied from interface: IOHandler
Returns true, if this handler can run a successful export based on the specified context and resource. A simple implementation may choose to return the same as IOHandler.canExport(ExportContext, boolean) where the isCollection flag is determined by DavResource.isCollection().

Specified by:
canExport in interface IOHandler
Parameters:
context -
resource -
Returns:
See Also:
IOHandler.canExport(ExportContext, DavResource)

exportContent

public boolean exportContent(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 IOHandler
Parameters:
context -
isCollection -
Returns:
Throws:
IOException - if an unexpected error occurs or if this method has been called although IOHandler.canExport(ExportContext, boolean) returns false.
See Also:
exportProperties(ExportContext, boolean, Node), exportData(ExportContext, boolean, Node)

exportContent

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

Specified by:
exportContent in interface IOHandler
Parameters:
context -
resource -
Returns:
Throws:
IOException - if an unexpected error occurs or if this method has been called although IOHandler.canExport(ExportContext, DavResource) returns false.
See Also:
IOHandler.exportContent(ExportContext, DavResource)

exportData

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

Parameters:
context -
isCollection -
contentNode -
Throws:
IOException
RepositoryException

exportProperties

protected void exportProperties(ExportContext context,
                                boolean isCollection,
                                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 -
isCollection -
contentNode -
Throws:
IOException

getContentNode

protected Node getContentNode(ExportContext context,
                              boolean isCollection)
                       throws 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 -
isCollection -
Returns:
content node used for the export
Throws:
RepositoryException

getCollectionNodeType

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

Returns:
nodetype name

getNodeType

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

Returns:
nodetype name

getContentNodeType

protected 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


Copyright © 2005-2006 . All Rights Reserved.