public class DefaultHandler extends Object implements IOHandler, PropertyHandler, CopyMoveHandler, DeleteHandler
DefaultHandler
implements a simple IOHandler that creates 'file'
and 'folder' nodes. This handler will create the following nodes:
collection nodetype
. The name of the node corresponds to the systemId
present on the import context.non-collection nodetype
. The name of the node corresponds to the systemId
present on the import context. Below it creates a node with name
jcr:content
and the nodetype specified
by getContentNodeType()
.
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 and Description |
---|
DefaultHandler()
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
|
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:unstructured
|
DefaultHandler(IOManager ioManager,
String collectionNodetype,
String defaultNodetype,
String contentNodetype)
Creates a new
DefaultHandler . |
Modifier and Type | Method and Description |
---|---|
boolean |
canCopy(CopyMoveContext context,
DavResource source,
DavResource destination)
Validates if this handler is able to execute a copy with the given
parameters.
|
boolean |
canDelete(DeleteContext deleteContext,
DavResource member)
Validates if this handler is able to execute a delete operation with the given
parameters.
|
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,
DavResource resource)
Returns true, if this handler can run a successful export based on
the specified context and resource.
|
boolean |
canExport(PropertyExportContext context,
boolean isCollection)
Returns true, if this handler can run a successful export based on the
specified context.
|
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,
DavResource resource)
Returns true, if this handler can run a successful import based on
the specified context and resource.
|
boolean |
canImport(PropertyImportContext context,
boolean isCollection)
Returns true, if this handler can run a property import based on the
specified context.
|
boolean |
canMove(CopyMoveContext context,
DavResource source,
DavResource destination)
Validates if this handler is able to execute a move with the given
parameters.
|
boolean |
copy(CopyMoveContext context,
DavResource source,
DavResource destination)
Executes the copy with the given parameters.
|
boolean |
delete(DeleteContext deleteContext,
DavResource member)
Executes the delete operation with the given parameters.
|
protected String |
detect(String name)
Detects the media type of a document based on the given name.
|
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,
DavResource resource)
Same as (@link IOHandler#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 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(ExportContext context,
boolean isCollection,
Node contentNode)
Retrieves mimetype, encoding and modification time from the content node.
|
boolean |
exportProperties(PropertyExportContext exportContext,
boolean isCollection)
Exports properties to the given context.
|
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 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.
|
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 . |
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,
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.
|
Map<? extends PropEntry,?> |
importProperties(PropertyImportContext importContext,
boolean isCollection)
Imports, modifies or removes properties according the the
change list available from
the import context. |
boolean |
move(CopyMoveContext context,
DavResource source,
DavResource destination)
Executes the move with the given parameters.
|
void |
setCollectionNodetype(String collectionNodetype) |
void |
setContentNodetype(String contentNodetype) |
void |
setDefaultNodetype(String defaultNodetype) |
void |
setIOManager(IOManager ioManager)
Sets the
IOManager that called this handler. |
public DefaultHandler()
DefaultHandler
with default nodetype definitions:nt:folder
nt:file
nt:unstructured
public DefaultHandler(IOManager ioManager)
DefaultHandler
with default nodetype definitions:nt:folder
nt:file
nt:unstructured
ioManager
- the I/O managerpublic IOManager getIOManager()
IOHandler
IOManager
that called this handler or null
.getIOManager
in interface IOHandler
IOHandler.getIOManager()
public void setIOManager(IOManager ioManager)
IOHandler
IOManager
that called this handler.setIOManager
in interface IOHandler
IOHandler.setIOManager(IOManager)
public String getName()
IOHandler
IOHandler
.getName
in interface IOHandler
IOHandler.getName()
public boolean canImport(ImportContext context, boolean isCollection)
IOHandler
canImport
in interface IOHandler
IOHandler.canImport(ImportContext, boolean)
public boolean canImport(ImportContext context, DavResource resource)
IOHandler
IOHandler.canImport(ImportContext, boolean)
where the isCollection flag is determined by
DavResource.isCollection()
.canImport
in interface IOHandler
IOHandler.canImport(ImportContext, DavResource)
public boolean importContent(ImportContext context, boolean isCollection) throws IOException
IOHandler
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 IOHandler
s.
importContent
in interface IOHandler
IOException
- if an unexpected error occurs or if this method has
been called although IOHandler.canImport(ImportContext, boolean)
returns false.IOHandler.importContent(ImportContext, boolean)
public boolean importContent(ImportContext context, DavResource resource) throws IOException
IOHandler
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 IOHandler
s.
importContent
in interface IOHandler
IOException
- if an unexpected error occurs or if this method has
been called although IOHandler.canImport(ImportContext, DavResource)
returns false.IOHandler.importContent(ImportContext, DavResource)
protected boolean importData(ImportContext context, boolean isCollection, Node contentNode) throws IOException, RepositoryException
IOException
RepositoryException
protected boolean importProperties(ImportContext context, boolean isCollection, Node contentNode)
protected Node getContentNode(ImportContext context, boolean isCollection) throws RepositoryException
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.
RepositoryException
protected boolean forceCompatibleContentNodes()
getCollectionNodeType()
.true
if content nodes should be replaced.public boolean canExport(ExportContext context, boolean isCollection)
jcr:content
in case this
export is not intended for a collection.canExport
in interface IOHandler
jcr:content
.IOHandler.canExport(ExportContext, boolean)
public boolean canExport(ExportContext context, DavResource resource)
IOHandler
IOHandler.canExport(ExportContext, boolean)
where the isCollection flag is determined by
DavResource.isCollection()
.canExport
in interface IOHandler
IOHandler.canExport(ExportContext, DavResource)
public boolean exportContent(ExportContext context, boolean isCollection) throws IOException
exportContent
in interface IOHandler
context
- the export contextisCollection
- true
if collectionIOException
- if an unexpected error occurs or if this method has
been called although IOHandler.canExport(ExportContext, boolean)
returns false.exportProperties(ExportContext, boolean, Node)
,
exportData(ExportContext, boolean, Node)
public boolean exportContent(ExportContext context, DavResource resource) throws IOException
DavResource.isCollection()
.exportContent
in interface IOHandler
IOException
- if an unexpected error occurs or if this method has
been called although IOHandler.canExport(ExportContext, DavResource)
returns false.IOHandler.exportContent(ExportContext, DavResource)
protected void exportData(ExportContext context, boolean isCollection, Node contentNode) throws IOException, RepositoryException
exportData
method.context
- export contextisCollection
- true
if collectioncontentNode
- the content nodeIOException
- if an I/O error occursRepositoryException
protected void exportProperties(ExportContext context, boolean isCollection, Node contentNode) throws IOException
context
- the export contextisCollection
- true
if collectioncontentNode
- the content nodeIOException
- If an error occurs.protected Node getContentNode(ExportContext context, boolean isCollection) throws RepositoryException
jcr:content
.context
- the export contextisCollection
- true
if collectionRepositoryException
- if an error during repository access occurs.public String getCollectionNodeType()
public String getNodeType()
public String getContentNodeType()
jcr:content
.public boolean canExport(PropertyExportContext context, boolean isCollection)
PropertyHandler
canExport
in interface PropertyHandler
PropertyHandler
is export properties
given the specified parameters.public boolean exportProperties(PropertyExportContext exportContext, boolean isCollection) throws RepositoryException
PropertyHandler
IOHandler.exportContent(ExportContext, boolean)
.exportProperties
in interface PropertyHandler
RepositoryException
- If an attempt is made to export properties
even if PropertyHandler.canExport(PropertyExportContext, boolean)
returns false or if some other unrecoverable error occurs.public boolean canImport(PropertyImportContext context, boolean isCollection)
PropertyHandler
canImport
in interface PropertyHandler
PropertyHandler
can import properties
given the specified parameters.public Map<? extends PropEntry,?> importProperties(PropertyImportContext importContext, boolean isCollection) throws RepositoryException
PropertyHandler
change list
available from
the import context. Note, that according to JSR 170 setting a property
value to null
is equivalent to its removal.
The return value of this method must be used to provided detailed information about any kind of failures.
importProperties
in interface PropertyHandler
RepositoryException
- If
PropertyHandler.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.protected String detect(String name)
name
- document namepublic boolean canCopy(CopyMoveContext context, DavResource source, DavResource destination)
CopyMoveHandler
canCopy
in interface CopyMoveHandler
context
- The context of the copy.source
- The source of the copy.destination
- The destination of the copy.CopyMoveHandler.canCopy(CopyMoveContext, org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.DavResource)
public boolean copy(CopyMoveContext context, DavResource source, DavResource destination) throws DavException
CopyMoveHandler
copy
in interface CopyMoveHandler
context
- The context of the copy.source
- The source of the copy.destination
- The destination of the copy.DavException
- If an error occurs.CopyMoveHandler.copy(CopyMoveContext, org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.DavResource)
public boolean canMove(CopyMoveContext context, DavResource source, DavResource destination)
CopyMoveHandler
canMove
in interface CopyMoveHandler
context
- The context of the move.source
- The source of the move.destination
- The destination of the move.CopyMoveHandler.canMove(CopyMoveContext, org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.DavResource)
public boolean move(CopyMoveContext context, DavResource source, DavResource destination) throws DavException
CopyMoveHandler
move
in interface CopyMoveHandler
context
- The context of the move.source
- The source of the move.destination
- The destination of the move.DavException
- If an error occurs.CopyMoveHandler.move(CopyMoveContext, org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.DavResource)
public boolean canDelete(DeleteContext deleteContext, DavResource member)
DeleteHandler
canDelete
in interface DeleteHandler
deleteContext
- The context of the deletemember
- The resource to be deletedtrue
if this instance can successfully execute the delete operation with the given parameters;
false
otherwise.DeleteHandler.canDelete(DeleteContext, DavResource)
public boolean delete(DeleteContext deleteContext, DavResource member) throws DavException
DeleteHandler
delete
in interface DeleteHandler
deleteContext
- The context of the delete.member
- The resource to be deletedtrue
if this instance successfully executed the delete operation with the given parameters;
false
otherwise.DavException
- If an error occurs.DeleteHandler.delete(DeleteContext, DavResource)
public void setCollectionNodetype(String collectionNodetype)
public void setDefaultNodetype(String defaultNodetype)
public void setContentNodetype(String contentNodetype)
Copyright © 2004–2021 The Apache Software Foundation. All rights reserved.