public void removeFolder(CmsDbContext dbc, CmsProject currentProject, CmsResource resource)
    throws CmsDataAccessException {

        if ((dbc.getRequestContext() != null)
            && (dbc.getRequestContext().getAttribute(REQ_ATTR_CHECK_PERMISSIONS) != null)) {
            // only check write permissions
            checkWritePermissionsInFolder(dbc, resource);
            return;
        }

        // check if the folder has any resources in it
        Iterator<CmsResource> childResources = readChildResources(dbc, currentProject, resource, true, true).iterator();

        CmsUUID projectId = CmsProject.ONLINE_PROJECT_ID;
        if (currentProject.isOnlineProject()) {
            projectId = CmsUUID.getOpenCmsUUID(); // HACK: to get an offline project id
        }

        // collect the names of the resources inside the folder, excluding the moved resources
        I_CmsVfsDriver vfsDriver = m_driverManager.getVfsDriver(dbc);
        StringBuffer errorResNames = new StringBuffer(128);
        while (childResources.hasNext()) {
            CmsResource errorRes = childResources.next();
            // if deleting offline, or not moved, or just renamed inside the deleted folder
            // so, it may remain some orphan online entries for moved resources
            // which will be fixed during the publishing of the moved resources
            boolean error = !currentProject.isOnlineProject();
            if (!error) {
                try {
                    String originalPath = vfsDriver.readResource(
                        dbc,
                        projectId,
                        errorRes.getRootPath(),
                        true).getRootPath();
                    error = originalPath.equals(errorRes.getRootPath())
                        || originalPath.startsWith(resource.getRootPath());
                } catch (CmsVfsResourceNotFoundException e) {
                    // ignore
                }
            }
            if (error) {
                if (errorResNames.length() != 0) {
                    errorResNames.append(", ");
                }
                errorResNames.append("[" + dbc.removeSiteRoot(errorRes.getRootPath()) + "]");
            }
        }

        // the current implementation only deletes empty folders
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(errorResNames.toString())) {

            throw new CmsVfsException(
                Messages.get().container(
                    Messages.ERR_DELETE_NONEMTY_FOLDER_2,
                    dbc.removeSiteRoot(resource.getRootPath()),
                    errorResNames.toString()));
        }
        internalRemoveFolder(dbc, currentProject, resource);

        // remove project resources
        String deletedResourceRootPath = resource.getRootPath();
        if (dbc.getRequestContext() != null) {
            dbc.getRequestContext().setAttribute(CmsProjectDriver.DBC_ATTR_READ_PROJECT_FOR_RESOURCE, Boolean.TRUE);
            I_CmsProjectDriver projectDriver = m_driverManager.getProjectDriver(dbc);
            Iterator<CmsProject> itProjects = projectDriver.readProjects(dbc, deletedResourceRootPath).iterator();
            while (itProjects.hasNext()) {
                CmsProject project = itProjects.next();
                projectDriver.deleteProjectResource(dbc, project.getUuid(), deletedResourceRootPath);
            }
        }
    }
public void removeFolder ( CmsDbContext dbc , CmsProject currentProject , CmsResource resource ) throws CmsDataAccessException { if ( ( dbc . getRequestContext ( ) != null ) && ( dbc . getRequestContext ( ) . getAttribute ( REQ_ATTR_CHECK_PERMISSIONS ) != null ) ) { checkWritePermissionsInFolder ( dbc , resource ) ; return ; } Iterator < CmsResource > childResources = readChildResources ( dbc , currentProject , resource , true , true ) . iterator ( ) ; CmsUUID projectId = CmsProject . ONLINE_PROJECT_ID ; if ( currentProject . isOnlineProject ( ) ) { projectId = CmsUUID . getOpenCmsUUID ( ) ; } I_CmsVfsDriver vfsDriver = m_driverManager . getVfsDriver ( dbc ) ; StringBuffer errorResNames = new StringBuffer ( 128 ) ; while ( childResources . hasNext ( ) ) { CmsResource errorRes = childResources . next ( ) ; boolean error = ! currentProject . isOnlineProject ( ) ; if ( ! error ) { try { String originalPath = vfsDriver . readResource ( dbc , projectId , errorRes . getRootPath ( ) , true ) . getRootPath ( ) ; error = originalPath . equals ( errorRes . getRootPath ( ) ) || originalPath . startsWith ( resource . getRootPath ( ) ) ; } catch ( CmsVfsResourceNotFoundException e ) { } } if ( error ) { if ( errorResNames . length ( ) != 0 ) { errorResNames . append ( ", " ) ; } errorResNames . append ( "[" + dbc . removeSiteRoot ( errorRes . getRootPath ( ) ) + "]" ) ; } } if ( CmsStringUtil . isNotEmptyOrWhitespaceOnly ( errorResNames . toString ( ) ) ) { throw new CmsVfsException ( Messages . get ( ) . container ( Messages . ERR_DELETE_NONEMTY_FOLDER_2 , dbc . removeSiteRoot ( resource . getRootPath ( ) ) , errorResNames . toString ( ) ) ) ; } internalRemoveFolder ( dbc , currentProject , resource ) ; String deletedResourceRootPath = resource . getRootPath ( ) ; if ( dbc . getRequestContext ( ) != null ) { dbc . getRequestContext ( ) . setAttribute ( CmsProjectDriver . DBC_ATTR_READ_PROJECT_FOR_RESOURCE , Boolean . TRUE ) ; I_CmsProjectDriver projectDriver = m_driverManager . getProjectDriver ( dbc ) ; Iterator < CmsProject > itProjects = projectDriver . readProjects ( dbc , deletedResourceRootPath ) . iterator ( ) ; while ( itProjects . hasNext ( ) ) { CmsProject project = itProjects . next ( ) ; projectDriver . deleteProjectResource ( dbc , project . getUuid ( ) , deletedResourceRootPath ) ; } } }
@see org.opencms.db.I_CmsVfsDriver#removeFolder(org.opencms.db.CmsDbContext, org.opencms.file.CmsProject, org.opencms.file.CmsResource)