Class DefaultHandler

    • Constructor Summary

      Constructors 
      Constructor 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.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canCopy​(CopyMoveContext context, org.apache.jackrabbit.webdav.DavResource source, org.apache.jackrabbit.webdav.DavResource destination)
      Validates if this handler is able to execute a copy with the given parameters.
      boolean canDelete​(DeleteContext deleteContext, org.apache.jackrabbit.webdav.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, org.apache.jackrabbit.webdav.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, org.apache.jackrabbit.webdav.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, org.apache.jackrabbit.webdav.DavResource source, org.apache.jackrabbit.webdav.DavResource destination)
      Validates if this handler is able to execute a move with the given parameters.
      boolean copy​(CopyMoveContext context, org.apache.jackrabbit.webdav.DavResource source, org.apache.jackrabbit.webdav.DavResource destination)
      Executes the copy with the given parameters.
      boolean delete​(DeleteContext deleteContext, org.apache.jackrabbit.webdav.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, 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​(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, 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.
      Map<? extends org.apache.jackrabbit.webdav.property.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, org.apache.jackrabbit.webdav.DavResource source, org.apache.jackrabbit.webdav.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.
    • Constructor Detail

      • DefaultHandler

        public 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

        public 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
        Parameters:
        ioManager - the I/O manager
      • 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.
    • Method Detail

      • 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
        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
        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)
      • 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 by getCollectionNodeType().
        Returns:
        true if 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 name jcr:content in case this export is not intended for a collection.
        Specified by:
        canExport in interface 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)
      • 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 own exportData method.
        Parameters:
        context - export context
        isCollection - true if collection
        contentNode - the content node
        Throws:
        IOException - if an I/O error occurs
        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 - the export context
        isCollection - true if collection
        contentNode - 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 name jcr:content.
        Parameters:
        context - the export context
        isCollection - true if 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 always jcr:content.
        Returns:
        nodetype name
      • canExport

        public boolean canExport​(PropertyExportContext context,
                                 boolean isCollection)
        Description copied from interface: PropertyHandler
        Returns true, if this handler can run a successful export based on the specified context.
        Specified by:
        canExport in interface PropertyHandler
        Returns:
        true if this PropertyHandler is export properties given the specified parameters.
      • canImport

        public boolean canImport​(PropertyImportContext context,
                                 boolean isCollection)
        Description copied from interface: PropertyHandler
        Returns true, if this handler can run a property import based on the specified context.
        Specified by:
        canImport in interface PropertyHandler
        Returns:
        true if this PropertyHandler can import properties given the specified parameters.
      • importProperties

        public Map<? extends org.apache.jackrabbit.webdav.property.PropEntry,​?> importProperties​(PropertyImportContext importContext,
                                                                                                       boolean isCollection)
                                                                                                throws RepositoryException
        Description copied from interface: PropertyHandler
        Imports, modifies or removes properties according the the 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.

        Specified by:
        importProperties in interface PropertyHandler
        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 - 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.
      • 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)
      • canDelete

        public boolean canDelete​(DeleteContext deleteContext,
                                 org.apache.jackrabbit.webdav.DavResource member)
        Description copied from interface: DeleteHandler
        Validates if this handler is able to execute a delete operation with the given parameters.
        Specified by:
        canDelete in interface DeleteHandler
        Parameters:
        deleteContext - The context of the delete
        member - The resource to be deleted
        Returns:
        true if this instance can successfully execute the delete operation with the given parameters; false otherwise.
        See Also:
        DeleteHandler.canDelete(DeleteContext, DavResource)
      • delete

        public boolean delete​(DeleteContext deleteContext,
                              org.apache.jackrabbit.webdav.DavResource member)
                       throws org.apache.jackrabbit.webdav.DavException
        Description copied from interface: DeleteHandler
        Executes the delete operation with the given parameters.
        Specified by:
        delete in interface DeleteHandler
        Parameters:
        deleteContext - The context of the delete.
        member - The resource to be deleted
        Returns:
        true if this instance successfully executed the delete operation with the given parameters; false otherwise.
        Throws:
        org.apache.jackrabbit.webdav.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)