Handles the file deletions.

@param cms the CMS context to use
@param toDelete the resources to delete

@throws CmsException if something goes wrong
326844
protected void processDeletions(CmsObject cms, List<CmsResource> toDelete) throws CmsException {

        Collections.sort(toDelete, (a, b) -> b.getRootPath().compareTo(a.getRootPath()));
        for (CmsResource deleteRes : toDelete) {
            m_report.print(
                org.opencms.importexport.Messages.get().container(org.opencms.importexport.Messages.RPT_DELFOLDER_0),
                I_CmsReport.FORMAT_NOTE);
            m_report.print(
                org.opencms.report.Messages.get().container(
                    org.opencms.report.Messages.RPT_ARGUMENT_1,
                    deleteRes.getRootPath()));
            CmsLock lock = cms.getLock(deleteRes);
            if (lock.isUnlocked()) {
                lock(cms, deleteRes);
            }
            cms.deleteResource(deleteRes, CmsResource.DELETE_PRESERVE_SIBLINGS);
            m_report.println(
                org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                I_CmsReport.FORMAT_OK);

        }
    }
879992
private void removeOldValues() throws CmsException {

        Locale locale = getLocale();
        I_CmsXmlContentValue value = m_document.getValue(N_DETAIL_PAGE, locale);
        do {
            value = m_document.getValue(N_DETAIL_PAGE, locale);
            if (value != null) {
                m_document.removeValue(value.getPath(), locale, 0);
            }
        } while (value != null);
    }
81113
public function deleteAction()
    {
        $file = (new CmsFileQuery)->findPk($this->id);
        if ($file && $file->delete()) {
            $this->getMessenger()->addMessage('messenger.file.deleted', true);
        }
        $this->getResponse()->redirect('cmsAdmin', 'file', 'index');
    }
1147731
void handleDelete(HttpRequest request,
                      HttpResponse response,
                      String pathInContext,
                      Resource resource)
        throws IOException
    {
        if(log.isDebugEnabled())log.debug("DELETE "+pathInContext+" from "+resource);  
 
        if (!resource.exists() ||
            !passConditionalHeaders(request,response,resource))
            return;
 
        try
        {
            // delete the file
            if (resource.delete())
                response.setStatus(HttpResponse.__204_No_Content);
            else
                response.sendError(HttpResponse.__403_Forbidden);

            // Send response
            request.setHandled(true);
        }
        catch (SecurityException sex)
        {
            log.warn(LogSupport.EXCEPTION,sex);
            response.sendError(HttpResponse.__403_Forbidden, sex.getMessage());
        }
    }
1183637
protected void remove(CmsPublishJobInfoBean publishJob) throws CmsException {

        OpenCms.getMemoryMonitor().uncachePublishJobInHistory(publishJob);
        // delete job from db if necessary
        if (OpenCms.getMemoryMonitor().requiresPersistency()) {
            CmsDbContext dbc = m_publishEngine.getDbContext(null);
            try {
                OpenCms.getPublishManager().getEngine().getDriverManager().deletePublishJob(
                    dbc,
                    publishJob.getPublishHistoryId());
            } catch (CmsException e) {
                dbc.rollback();
                LOG.error(e.getLocalizedMessage(), e);
                throw e;
            } finally {
                dbc.clear();
            }
        }

        m_publishEngine.publishJobRemoved(publishJob);
    }
464058
@Override
    protected boolean performDialogOperation() throws CmsException {

        // check if the current resource is a folder for single operation
        boolean isFolder = isOperationOnFolder();
        // on folder undelete or multi operation display "please wait" screen, not for simple file undeletion
        if ((isMultiOperation() || isFolder) && !DIALOG_WAIT.equals(getParamAction())) {
            // return false, this will trigger the "please wait" screen
            return false;
        }

        Iterator<String> i = getResourceList().iterator();
        // iterate the resources to undelete
        while (i.hasNext()) {
            String resName = i.next();
            try {
                // lock resource if autolock is enabled
                checkLock(resName);
                // undelete the resource
                getCms().undeleteResource(resName, true);
            } catch (CmsException e) {
                if (isMultiOperation()) {
                    // collect exceptions to create a detailed output
                    addMultiOperationException(e);
                } else {
                    // for single operation, throw the exception immediately
                    throw e;
                }
            }
        }
        // check if exceptions occurred
        checkMultiOperationException(Messages.get(), Messages.ERR_UNDELETE_MULTI_0);
        return true;
    }
248542
protected void deleteRelationsWithSiblings(CmsDbContext dbc, CmsResource resource) throws CmsException {

        // get all siblings
        List<CmsResource> siblings;
        if (resource.getSiblingCount() > 1) {
            siblings = readSiblings(dbc, resource, CmsResourceFilter.ALL);
        } else {
            siblings = new ArrayList<CmsResource>();
            siblings.add(resource);
        }
        // clean the relations in content for all siblings
        I_CmsVfsDriver vfsDriver = getVfsDriver(dbc);
        Iterator<CmsResource> it = siblings.iterator();
        while (it.hasNext()) {
            CmsResource sibling = it.next();
            // clean the relation information for this sibling
            vfsDriver.deleteRelations(
                dbc,
                dbc.currentProject().getUuid(),
                sibling,
                CmsRelationFilter.TARGETS.filterDefinedInContent());
        }
    }
819036
void submit() {

        CmsObject cms = A_CmsUI.getCmsObject();
        try {
            List<CmsUUID> changedIds = Lists.newArrayList();
            CmsResourceDeleteMode mode = (CmsResourceDeleteMode)m_deleteSiblings.getValue();
            for (CmsResource resource : m_context.getResources()) {
                changedIds.add(resource.getStructureId());
                CmsLockActionRecord lockRecord = CmsLockUtil.ensureLock(cms, resource);
                try {
                    cms.deleteResource(cms.getSitePath(resource), mode);
                } finally {
                    if (lockRecord.getChange().equals(LockChange.locked)) {
                        if (!resource.getState().isNew()) {
                            try {
                                cms.unlockResource(resource);
                            } catch (CmsVfsResourceNotFoundException e) {
                                LOG.warn(e.getLocalizedMessage(), e);
                            } catch (CmsLockException e) {
                                LOG.warn(e.getLocalizedMessage(), e);
                            }
                        }
                    }
                }
            }
            m_context.finish(changedIds);
        } catch (Exception e) {
            m_context.error(e);
        }
    }
282561
protected void doLoadNextFile() throws CmsException {

        super.doLoadNextResource();
        if (m_resource == null) {
            return;
        }

        // upgrade the resource to a file
        CmsFile file = m_cms.readFile(m_resource);

        // unmarshal the XML content from the resource, don't use unmarshal(CmsObject, CmsResource)
        // as no support for getting the historic version that has been cached by a CmsHistoryResourceHandler
        // will come from there!
        m_content = CmsXmlContentFactory.unmarshal(m_cms, file, pageContext.getRequest());

        // check if locale is available
        m_contentLocale = m_locale;
        if (!m_content.hasLocale(m_contentLocale)) {
            Iterator<Locale> it = OpenCms.getLocaleManager().getDefaultLocales().iterator();
            while (it.hasNext()) {
                Locale locale = it.next();
                if (m_content.hasLocale(locale)) {
                    // found a matching locale
                    m_contentLocale = locale;
                    break;
                }
            }
        }
    }
20165
public function deleteAction()
	{
		$page = $this->getPageLocalization()
				->getMaster();

		$entityManager = $this->getEntityManager();

		$count = (int) $entityManager->createQuery(sprintf('SELECT COUNT(p.id) FROM %s p WHERE p.template = ?0', PageLocalization::CN()))
				->setParameters(array($page->getId()))
				->getSingleScalarResult();

		if ($count > 0) {
			throw new CmsException(null, "Cannot remove template, {$count} page(s) still uses it.");
		}

		$entityManager->remove($page);
		$entityManager->flush();

		return new SupraJsonResponse();
	}
904312
public void forceDeleteModule(String moduleName) throws Exception {

        OpenCms.getModuleManager().deleteModule(
            m_cms,
            moduleName,
            true,
            new CmsShellReport(m_cms.getRequestContext().getLocale()));
    }
492340
public function deleteAction()
	{
		$repository = $this->container->getDoctrine()->getManager()->getRepository(FileAbstraction::CN());
		/* @var $repository FileNestedSetRepository */
		$repository->getNestedSetRepository()->lock();

		$file = $this->getEntity();

		$this->checkActionPermission($file, FileAbstraction::PERMISSION_DELETE_NAME);

		if (is_null($file)) {
			throw new CmsException(null, 'File doesn\'t exist anymore');
		}

		// try to delete
		try {
			if ($file->hasChildren()) {
				$confirmation = $this->getConfirmation('Are You sure?');

				if ($confirmation instanceof Response) {
					return $confirmation;
				}

				$this->removeFilesRecursively($file);
			} else {
				$this->removeSingleFile($file);
			}
		} catch (NotEmptyException $e) {
			// Should not happen
			throw new CmsException(null, "Cannot delete not empty folders");
		}

		return new SupraJsonResponse(null);
	}
709477
public void deleteDescriptorIfNecessary() throws CmsException {

        if (m_removeDescriptorOnCancel && (m_desc != null)) {
            m_cms.deleteResource(m_desc, CmsResourceDeleteMode.valueOf(2));
        }

    }
807419
private void initDeletedResources(CmsObject cms, List<I_CmsHistoryResource> deletedResources) throws CmsException {

        Collections.sort(deletedResources, new Comparator<I_CmsHistoryResource>() {

            public int compare(I_CmsHistoryResource first, I_CmsHistoryResource second) {

                return first.getRootPath().compareTo(second.getRootPath());
            }
        });
        m_deletedResourceContainer.removeAllComponents();
        m_selectionContainer = new IndexedContainer();
        m_selectionContainer.addContainerProperty(PROP_SELECTED, Boolean.class, Boolean.FALSE);
        m_okButton.setEnabled(!deletedResources.isEmpty());
        if (deletedResources.isEmpty()) {
            m_deletedResourceContainer.addComponent(
                new Label(CmsVaadinUtils.getMessageText(org.opencms.workplace.list.Messages.GUI_LIST_EMPTY_0)));

        }
        for (I_CmsHistoryResource deleted : deletedResources) {
            I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(deleted.getTypeId());
            String typeName = resType.getTypeName();
            CmsExplorerTypeSettings explorerType = OpenCms.getWorkplaceManager().getExplorerTypeSetting(typeName);
            String title = cms.getRequestContext().removeSiteRoot(deleted.getRootPath());

            String subtitle = CmsVaadinUtils.getMessageText(
                org.opencms.ui.Messages.GUI_RESTOREDELETED_DATE_VERSION_2,
                CmsVfsService.formatDateTime(cms, deleted.getDateLastModified()),
                "" + deleted.getVersion());
            if (explorerType == null) {
                explorerType = OpenCms.getWorkplaceManager().getExplorerTypeSetting(
                    deleted.isFile()
                    ? CmsResourceTypeUnknownFile.RESOURCE_TYPE_NAME
                    : CmsResourceTypeUnknownFolder.RESOURCE_TYPE_NAME);
            }
            CmsResourceInfo info = new CmsResourceInfo(
                title,
                subtitle,
                CmsResourceUtil.getBigIconResource(explorerType, deleted.getName()));
            info.setWidth("100%");
            HorizontalLayout hl = new HorizontalLayout();
            hl.setWidth("100%");
            CheckBox checkbox = new CheckBox();
            hl.addComponent(checkbox);
            hl.addComponent(info);
            hl.setExpandRatio(info, 1);
            hl.setComponentAlignment(checkbox, Alignment.MIDDLE_LEFT);
            m_selectionContainer.addItem(deleted.getStructureId());
            checkbox.setPropertyDataSource(
                m_selectionContainer.getItem(deleted.getStructureId()).getItemProperty(PROP_SELECTED));
            m_deletedResourceContainer.addComponent(hl);
        }

    }
1346754
public void updateSite(CmsObject cms, CmsSite oldSite, CmsSite newSite) throws CmsException {

        if (oldSite != null) {
            // remove the old site
            removeSite(cms, oldSite);
        }

        if (newSite != null) {
            // add the new site
            addSite(cms, newSite);
        }
    }
561931
private void deleteResource(final String sitePath) {

        CmsRpcAction<Void> action = new CmsRpcAction<Void>() {

            /**
             * @see org.opencms.gwt.client.rpc.CmsRpcAction#execute()
             */
            @Override
            public void execute() {

                CmsCoreProvider.getVfsService().deleteResource(sitePath, this);

            }

            /**
             * @see org.opencms.gwt.client.rpc.CmsRpcAction#onResponse(java.lang.Object)
             */
            @Override
            protected void onResponse(Void result) {

                onAfterDeletion();
            }
        };
        action.execute();
    }
206286
private void recursivelyCheckAndDeleteFiles(final App app, final FailedToDeleteDataImpl result, final AbstractFile toDelete, final Boolean continueOnFailure) throws FrameworkException {

		if (toDelete != null) {

			final Principal owner = toDelete.getOwnerNode();
			if (owner == null || owner.isGranted(Permission.delete, securityContext)) {

				app.delete(toDelete);

				if (toDelete instanceof Folder) {

					final Folder folderToDelete = (Folder)toDelete;

					for (final AbstractFile child : folderToDelete.getChildren()) {

						recursivelyCheckAndDeleteFiles(app, result, child, continueOnFailure);
					}
				}

			} else {

				if (continueOnFailure) {

					result.getIds().add(toDelete.getUuid());

				} else {

					throw new CmisPermissionDeniedException("Cannot delete object with ID " + toDelete.getUuid());
				}
			}
		}
	}