public boolean copyResource( final ITransaction transaction, final WebdavRequest req, final WebdavResponse resp )
        throws WebdavException, IOException, LockFailedException
    {

        // Parsing destination header
        final String destinationPath = parseDestinationHeader( req, resp );

        if ( destinationPath == null )
        {
            return false;
        }

        final String path = getRelativePath( req );

        if ( path.equals( destinationPath ) )
        {
            resp.sendError( WebdavStatus.SC_FORBIDDEN );
            return false;
        }

        Hashtable<String, WebdavStatus> errorList = new Hashtable<String, WebdavStatus>();
        final String parentDestinationPath = getParentPath( getCleanPath( destinationPath ) );

        if ( !checkLocks( transaction, req, resp, _resourceLocks, parentDestinationPath ) )
        {
            errorList.put( parentDestinationPath, SC_LOCKED );
            sendReport( req, resp, errorList );
            return false; // parentDestination is locked
        }

        if ( !checkLocks( transaction, req, resp, _resourceLocks, destinationPath ) )
        {
            errorList.put( destinationPath, SC_LOCKED );
            sendReport( req, resp, errorList );
            return false; // destination is locked
        }

        // Parsing overwrite header

        boolean overwrite = true;
        final String overwriteHeader = req.getHeader( "Overwrite" );

        if ( overwriteHeader != null )
        {
            overwrite = overwriteHeader.equalsIgnoreCase( "T" );
        }

        // Overwriting the destination
        final String lockOwner = "copyResource" + System.currentTimeMillis() + req.toString();

        if ( _resourceLocks.lock( transaction, destinationPath, lockOwner, false, 0, TEMP_TIMEOUT, TEMPORARY ) )
        {
            StoredObject copySo, destinationSo = null;
            try
            {
                copySo = _store.getStoredObject( transaction, path );
                // Retrieve the resources
                if ( copySo == null )
                {
                    resp.sendError( SC_NOT_FOUND );
                    return false;
                }

                if ( copySo.isNullResource() )
                {
                    final String methodsAllowed = DeterminableMethod.determineMethodsAllowed( copySo );
                    resp.addHeader( "Allow", methodsAllowed );
                    resp.sendError( SC_METHOD_NOT_ALLOWED );
                    return false;
                }

                errorList = new Hashtable<String, WebdavStatus>();

                destinationSo = _store.getStoredObject( transaction, destinationPath );

                if ( overwrite )
                {

                    // Delete destination resource, if it exists
                    if ( destinationSo != null )
                    {
                        _doDelete.deleteResource( transaction, destinationPath, errorList, req, resp );

                    }
                    else
                    {
                        resp.setStatus( WebdavStatus.SC_CREATED );
                    }
                }
                else
                {

                    // If the destination exists, then it's a conflict
                    if ( destinationSo != null )
                    {
                        resp.sendError( WebdavStatus.SC_PRECONDITION_FAILED );
                        return false;
                    }
                    else
                    {
                        resp.setStatus( WebdavStatus.SC_CREATED );
                    }

                }
                copy( transaction, path, destinationPath, errorList, req, resp );

                if ( !errorList.isEmpty() )
                {
                    sendReport( req, resp, errorList );
                }

            }
            finally
            {
                _resourceLocks.unlockTemporaryLockedObjects( transaction, destinationPath, lockOwner );
            }
        }
        else
        {
            resp.sendError( SC_INTERNAL_SERVER_ERROR );
            return false;
        }
        return true;

    }
public boolean copyResource ( final ITransaction transaction , final WebdavRequest req , final WebdavResponse resp ) throws WebdavException , IOException , LockFailedException { final String destinationPath = parseDestinationHeader ( req , resp ) ; if ( destinationPath == null ) { return false ; } final String path = getRelativePath ( req ) ; if ( path . equals ( destinationPath ) ) { resp . sendError ( WebdavStatus . SC_FORBIDDEN ) ; return false ; } Hashtable < String , WebdavStatus > errorList = new Hashtable < String , WebdavStatus > ( ) ; final String parentDestinationPath = getParentPath ( getCleanPath ( destinationPath ) ) ; if ( ! checkLocks ( transaction , req , resp , _resourceLocks , parentDestinationPath ) ) { errorList . put ( parentDestinationPath , SC_LOCKED ) ; sendReport ( req , resp , errorList ) ; return false ; } if ( ! checkLocks ( transaction , req , resp , _resourceLocks , destinationPath ) ) { errorList . put ( destinationPath , SC_LOCKED ) ; sendReport ( req , resp , errorList ) ; return false ; } boolean overwrite = true ; final String overwriteHeader = req . getHeader ( "Overwrite" ) ; if ( overwriteHeader != null ) { overwrite = overwriteHeader . equalsIgnoreCase ( "T" ) ; } final String lockOwner = "copyResource" + System . currentTimeMillis ( ) + req . toString ( ) ; if ( _resourceLocks . lock ( transaction , destinationPath , lockOwner , false , 0 , TEMP_TIMEOUT , TEMPORARY ) ) { StoredObject copySo , destinationSo = null ; try { copySo = _store . getStoredObject ( transaction , path ) ; if ( copySo == null ) { resp . sendError ( SC_NOT_FOUND ) ; return false ; } if ( copySo . isNullResource ( ) ) { final String methodsAllowed = DeterminableMethod . determineMethodsAllowed ( copySo ) ; resp . addHeader ( "Allow" , methodsAllowed ) ; resp . sendError ( SC_METHOD_NOT_ALLOWED ) ; return false ; } errorList = new Hashtable < String , WebdavStatus > ( ) ; destinationSo = _store . getStoredObject ( transaction , destinationPath ) ; if ( overwrite ) { if ( destinationSo != null ) { _doDelete . deleteResource ( transaction , destinationPath , errorList , req , resp ) ; } else { resp . setStatus ( WebdavStatus . SC_CREATED ) ; } } else { if ( destinationSo != null ) { resp . sendError ( WebdavStatus . SC_PRECONDITION_FAILED ) ; return false ; } else { resp . setStatus ( WebdavStatus . SC_CREATED ) ; } } copy ( transaction , path , destinationPath , errorList , req , resp ) ; if ( ! errorList . isEmpty ( ) ) { sendReport ( req , resp , errorList ) ; } } finally { _resourceLocks . unlockTemporaryLockedObjects ( transaction , destinationPath , lockOwner ) ; } } else { resp . sendError ( SC_INTERNAL_SERVER_ERROR ) ; return false ; } return true ; }
Copy a resource.

@param transaction
indicates that the method is within the scope of a WebDAV
transaction
@param req
Servlet request
@param resp
Servlet response
@return true if the copy is successful
@throws WebdavException
if an error in the underlying store occurs
@throws IOException
when an error occurs while sending the response
@throws LockFailedException