Class DefaultHandler
- java.lang.Object
-
- org.apache.jackrabbit.server.io.DefaultHandler
-
- All Implemented Interfaces:
CopyMoveHandler,DeleteHandler,IOHandler,PropertyHandler
- Direct Known Subclasses:
VersionHandler,XmlHandler,ZipHandler
public class DefaultHandler extends Object implements IOHandler, PropertyHandler, CopyMoveHandler, DeleteHandler
DefaultHandlerimplements a simple IOHandler that creates 'file' and 'folder' nodes. This handler will create the following nodes:- New Collection: creates a new node with the
collection nodetype. The name of the node corresponds to the systemId present on the import context. - New Non-Collection: first creates a new node with the
non-collection nodetype. The name of the node corresponds to the systemId present on the import context. Below it creates a node with namejcr:contentand the nodetype specified bygetContentNodeType().
Import of the content:
The content is imported to theJcrConstants.JCR_DATAproperty of the content node. By default this handler will fail on a attempt to create/replace a collection ifIOContext.hasStream()istrue. Subclasses therefore should provide their ownimportDatamethod, that handles the data according their needs.
-
-
Constructor Summary
Constructors Constructor Description DefaultHandler()Creates a newDefaultHandlerwith default nodetype definitions:
Nodetype for Collection:nt:folderNodetype for Non-Collection:nt:fileNodetype for Non-Collection content:nt:unstructuredDefaultHandler(IOManager ioManager)Creates a newDefaultHandlerwith default nodetype definitions:
Nodetype for Collection:nt:folderNodetype for Non-Collection:nt:fileNodetype for Non-Collection content:nt:unstructuredDefaultHandler(IOManager ioManager, String collectionNodetype, String defaultNodetype, String contentNodetype)Creates a newDefaultHandler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanCopy(CopyMoveContext context, DavResource source, DavResource destination)Validates if this handler is able to execute a copy with the given parameters.booleancanDelete(DeleteContext deleteContext, DavResource member)Validates if this handler is able to execute a delete operation with the given parameters.booleancanExport(ExportContext context, boolean isCollection)Returns true if the export root is a node and if it contains a child node with namejcr:contentin case this export is not intended for a collection.booleancanExport(ExportContext context, DavResource resource)Returns true, if this handler can run a successful export based on the specified context and resource.booleancanExport(PropertyExportContext context, boolean isCollection)Returns true, if this handler can run a successful export based on the specified context.booleancanImport(ImportContext context, boolean isCollection)Returns true, if this handler can run a successful import based on the specified context.booleancanImport(ImportContext context, DavResource resource)Returns true, if this handler can run a successful import based on the specified context and resource.booleancanImport(PropertyImportContext context, boolean isCollection)Returns true, if this handler can run a property import based on the specified context.booleancanMove(CopyMoveContext context, DavResource source, DavResource destination)Validates if this handler is able to execute a move with the given parameters.booleancopy(CopyMoveContext context, DavResource source, DavResource destination)Executes the copy with the given parameters.booleandelete(DeleteContext deleteContext, DavResource member)Executes the delete operation with the given parameters.protected Stringdetect(String name)Detects the media type of a document based on the given name.booleanexportContent(ExportContext context, boolean isCollection)Retrieves the content node that will be used for exporting properties and data and calls the corresponding methods.booleanexportContent(ExportContext context, DavResource resource)Same as (@link IOHandler#exportContent(ExportContext, boolean)} where the boolean values is defined byDavResource.isCollection().protected voidexportData(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 of the export context.
Please note, that subclasses that define a different structure of the content node should create their ownexportDatamethod.protected voidexportProperties(ExportContext context, boolean isCollection, Node contentNode)Retrieves mimetype, encoding and modification time from the content node.booleanexportProperties(PropertyExportContext exportContext, boolean isCollection)Exports properties to the given context.protected booleanforceCompatibleContentNodes()Defines if content nodes should be replace if they don't have the node type given bygetCollectionNodeType().StringgetCollectionNodeType()Name of the nodetype to be used to create a new collection node (folder)protected NodegetContentNode(ExportContext context, boolean isCollection)Retrieves the content node that contains the data to be exported.protected NodegetContentNode(ImportContext context, boolean isCollection)Retrieves/creates the node that will be used to import properties and data.StringgetContentNodeType()Name of the nodetype to be used to create the content node below a new non-collection node, whose name is alwaysjcr:content.IOManagergetIOManager()Returns theIOManagerthat called this handler ornull.StringgetName()Returns a human readable name for thisIOHandler.StringgetNodeType()Name of the nodetype to be used to create a new non-collection node (file)booleanimportContent(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.booleanimportContent(ImportContext context, DavResource resource)Runs the import for the given context and resource.protected booleanimportData(ImportContext context, boolean isCollection, Node contentNode)Imports the data present on the import context to the specified content node.protected booleanimportProperties(ImportContext context, boolean isCollection, Node contentNode)Imports the properties present on the specified context to the content node.Map<? extends PropEntry,?>importProperties(PropertyImportContext importContext, boolean isCollection)Imports, modifies or removes properties according the thechange listavailable from the import context.booleanmove(CopyMoveContext context, DavResource source, DavResource destination)Executes the move with the given parameters.voidsetCollectionNodetype(String collectionNodetype)voidsetContentNodetype(String contentNodetype)voidsetDefaultNodetype(String defaultNodetype)voidsetIOManager(IOManager ioManager)Sets theIOManagerthat called this handler.
-
-
-
Constructor Detail
-
DefaultHandler
public DefaultHandler()
Creates a newDefaultHandlerwith default nodetype definitions:
- Nodetype for Collection:
nt:folder - Nodetype for Non-Collection:
nt:file - Nodetype for Non-Collection content:
nt:unstructured
- Nodetype for Collection:
-
DefaultHandler
public DefaultHandler(IOManager ioManager)
Creates a newDefaultHandlerwith default nodetype definitions:
- Nodetype for Collection:
nt:folder - Nodetype for Non-Collection:
nt:file - Nodetype for Non-Collection content:
nt:unstructured
- Parameters:
ioManager- the I/O manager
- Nodetype for Collection:
-
-
Method Detail
-
getIOManager
public IOManager getIOManager()
Description copied from interface:IOHandlerReturns theIOManagerthat called this handler ornull.- Specified by:
getIOManagerin interfaceIOHandler- See Also:
IOHandler.getIOManager()
-
setIOManager
public void setIOManager(IOManager ioManager)
Description copied from interface:IOHandlerSets theIOManagerthat called this handler.- Specified by:
setIOManagerin interfaceIOHandler- See Also:
IOHandler.setIOManager(IOManager)
-
getName
public String getName()
Description copied from interface:IOHandlerReturns a human readable name for thisIOHandler.- Specified by:
getNamein interfaceIOHandler- See Also:
IOHandler.getName()
-
canImport
public boolean canImport(ImportContext context, boolean isCollection)
Description copied from interface:IOHandlerReturns true, if this handler can run a successful import based on the specified context.- Specified by:
canImportin interfaceIOHandler- See Also:
IOHandler.canImport(ImportContext, boolean)
-
canImport
public boolean canImport(ImportContext context, DavResource resource)
Description copied from interface:IOHandlerReturns 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 asIOHandler.canImport(ImportContext, boolean)where the isCollection flag is determined byDavResource.isCollection().- Specified by:
canImportin interfaceIOHandler- See Also:
IOHandler.canImport(ImportContext, DavResource)
-
importContent
public boolean importContent(ImportContext context, boolean isCollection) throws IOException
Description copied from interface:IOHandlerRuns the import for the given context and indicates by a boolean return value, if the import could be completed successfully. If the specifiedImportContextdoes not provide astreamthe implementation is free, to only import properties of to refuse the import.Please note, that it is the responsibility of the specified
ImportContextto assert, that its stream is not consumed multiple times when being passed to a chain ofIOHandlers.- Specified by:
importContentin interfaceIOHandler- Returns:
- true if the import was successful.
- Throws:
IOException- if an unexpected error occurs or if this method has been called althoughIOHandler.canImport(ImportContext, boolean)returns false.- See Also:
IOHandler.importContent(ImportContext, boolean)
-
importContent
public boolean importContent(ImportContext context, DavResource resource) throws IOException
Description copied from interface:IOHandlerRuns the import for the given context and resource. It indicates by a boolean return value, if the import could be completed successfully. If the specifiedImportContextdoes not provide astreamthe implementation is free, to only import properties of to refuse the import. A simple implementation may return the same asIOHandler.importContent(ImportContext, boolean)where the isCollection flag is determined byDavResource.isCollection()Please note, that it is the responsibility of the specified
ImportContextto assert, that its stream is not consumed multiple times when being passed to a chain ofIOHandlers.- Specified by:
importContentin interfaceIOHandler- Returns:
- Throws:
IOException- if an unexpected error occurs or if this method has been called althoughIOHandler.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.- Throws:
IOExceptionRepositoryException
-
importProperties
protected boolean importProperties(ImportContext context, boolean isCollection, Node contentNode)
Imports the properties present on the specified context to the content node.
-
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.
- Throws:
RepositoryException
-
forceCompatibleContentNodes
protected boolean forceCompatibleContentNodes()
Defines if content nodes should be replace if they don't have the node type given bygetCollectionNodeType().- Returns:
trueif content nodes should be replaced.
-
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 namejcr:contentin case this export is not intended for a collection.- Specified by:
canExportin interfaceIOHandler- 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(ExportContext context, DavResource resource)
Description copied from interface:IOHandlerReturns 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 asIOHandler.canExport(ExportContext, boolean)where the isCollection flag is determined byDavResource.isCollection().- Specified by:
canExportin interfaceIOHandler- 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:
exportContentin interfaceIOHandler- Parameters:
context- the export contextisCollection-trueif collection- Returns:
- Throws:
IOException- if an unexpected error occurs or if this method has been called althoughIOHandler.canExport(ExportContext, boolean)returns false.- See Also:
exportProperties(ExportContext, boolean, Node),exportData(ExportContext, boolean, Node)
-
exportContent
public boolean exportContent(ExportContext context, DavResource resource) throws IOException
Same as (@link IOHandler#exportContent(ExportContext, boolean)} where the boolean values is defined byDavResource.isCollection().- Specified by:
exportContentin interfaceIOHandler- Returns:
- Throws:
IOException- if an unexpected error occurs or if this method has been called althoughIOHandler.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 of the export context.
Please note, that subclasses that define a different structure of the content node should create their ownexportDatamethod.- Parameters:
context- export contextisCollection-trueif collectioncontentNode- the content node- Throws:
IOException- if an I/O error occursRepositoryException
-
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- the export contextisCollection-trueif collectioncontentNode- the content node- Throws:
IOException- If an error occurs.
-
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 namejcr:content.- Parameters:
context- the export contextisCollection-trueif collection- Returns:
- content node used for the export
- Throws:
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 alwaysjcr:content.- Returns:
- nodetype name
-
canExport
public boolean canExport(PropertyExportContext context, boolean isCollection)
Description copied from interface:PropertyHandlerReturns true, if this handler can run a successful export based on the specified context.- Specified by:
canExportin interfacePropertyHandler- Returns:
- true if this
PropertyHandleris export properties given the specified parameters.
-
exportProperties
public boolean exportProperties(PropertyExportContext exportContext, boolean isCollection) throws RepositoryException
Description copied from interface:PropertyHandlerExports properties to the given context. Note that the export must be consistent with properties that might be exposed by content export such as defined byIOHandler.exportContent(ExportContext, boolean).- Specified by:
exportPropertiesin interfacePropertyHandler- Returns:
- true if the export succeeded.
- Throws:
RepositoryException- If an attempt is made to export properties even ifPropertyHandler.canExport(PropertyExportContext, boolean)returns false or if some other unrecoverable error occurs.
-
canImport
public boolean canImport(PropertyImportContext context, boolean isCollection)
Description copied from interface:PropertyHandlerReturns true, if this handler can run a property import based on the specified context.- Specified by:
canImportin interfacePropertyHandler- Returns:
- true if this
PropertyHandlercan import properties given the specified parameters.
-
importProperties
public Map<? extends PropEntry,?> importProperties(PropertyImportContext importContext, boolean isCollection) throws RepositoryException
Description copied from interface:PropertyHandlerImports, modifies or removes properties according the thechange listavailable from the import context. Note, that according to JSR 170 setting a property value tonullis equivalent to its removal.The return value of this method must be used to provided detailed information about any kind of failures.
- Specified by:
importPropertiesin interfacePropertyHandler- Returns:
- Map listing those properties that failed to be updated. An empty map indicates a successful import for all properties listed in the context.
- Throws:
RepositoryException- IfPropertyHandler.canImport(PropertyImportContext, boolean)returns false for the given parameters or if some other unrecoverable error occurred. Note, that normal failure of a property update must be reported with the return value and should not result in an exception.
-
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(CopyMoveContext context, DavResource source, DavResource destination)
Description copied from interface:CopyMoveHandlerValidates if this handler is able to execute a copy with the given parameters.- Specified by:
canCopyin interfaceCopyMoveHandler- Parameters:
context- The context of the copy.source- The source of the copy.destination- The destination of the copy.- Returns:
- true if this instance can handle a copy with the given parameters; false otherwise.
- See Also:
CopyMoveHandler.canCopy(CopyMoveContext, org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.DavResource)
-
copy
public boolean copy(CopyMoveContext context, DavResource source, DavResource destination) throws DavException
Description copied from interface:CopyMoveHandlerExecutes the copy with the given parameters.- Specified by:
copyin interfaceCopyMoveHandler- Parameters:
context- The context of the copy.source- The source of the copy.destination- The destination of the copy.- Returns:
- true if this instance successfully executed the copy operation with the given parameters; false otherwise.
- Throws:
DavException- If an error occurs.- See Also:
CopyMoveHandler.copy(CopyMoveContext, org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.DavResource)
-
canMove
public boolean canMove(CopyMoveContext context, DavResource source, DavResource destination)
Description copied from interface:CopyMoveHandlerValidates if this handler is able to execute a move with the given parameters.- Specified by:
canMovein interfaceCopyMoveHandler- Parameters:
context- The context of the move.source- The source of the move.destination- The destination of the move.- Returns:
- true if this instance successfully executed the move operation with the given parameters; false otherwise.
- See Also:
CopyMoveHandler.canMove(CopyMoveContext, org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.DavResource)
-
move
public boolean move(CopyMoveContext context, DavResource source, DavResource destination) throws DavException
Description copied from interface:CopyMoveHandlerExecutes the move with the given parameters.- Specified by:
movein interfaceCopyMoveHandler- Parameters:
context- The context of the move.source- The source of the move.destination- The destination of the move.- Returns:
- true if this instance successfully executed the move operation with the given parameters; false otherwise.
- Throws:
DavException- If an error occurs.- See Also:
CopyMoveHandler.move(CopyMoveContext, org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.DavResource)
-
canDelete
public boolean canDelete(DeleteContext deleteContext, DavResource member)
Description copied from interface:DeleteHandlerValidates if this handler is able to execute a delete operation with the given parameters.- Specified by:
canDeletein interfaceDeleteHandler- Parameters:
deleteContext- The context of the deletemember- The resource to be deleted- Returns:
trueif this instance can successfully execute the delete operation with the given parameters;falseotherwise.- See Also:
DeleteHandler.canDelete(DeleteContext, DavResource)
-
delete
public boolean delete(DeleteContext deleteContext, DavResource member) throws DavException
Description copied from interface:DeleteHandlerExecutes the delete operation with the given parameters.- Specified by:
deletein interfaceDeleteHandler- Parameters:
deleteContext- The context of the delete.member- The resource to be deleted- Returns:
trueif this instance successfully executed the delete operation with the given parameters;falseotherwise.- Throws:
DavException- If an error occurs.- See Also:
DeleteHandler.delete(DeleteContext, DavResource)
-
setCollectionNodetype
public void setCollectionNodetype(String collectionNodetype)
-
setDefaultNodetype
public void setDefaultNodetype(String defaultNodetype)
-
setContentNodetype
public void setContentNodetype(String contentNodetype)
-
-