Applys the given remove change.<p>

@param change the change to apply

@return the changed client sitemap entry or <code>null</code>

@throws CmsException if something goes wrong
199811
private CmsSitemapChange removeEntryFromNavigation(CmsSitemapChange change) throws CmsException {

        CmsObject cms = getCmsObject();
        CmsResource entryFolder = cms.readResource(change.getEntryId(), CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
        ensureLock(entryFolder);
        List<CmsProperty> properties = new ArrayList<CmsProperty>();
        properties.add(
            new CmsProperty(
                CmsPropertyDefinition.PROPERTY_NAVTEXT,
                CmsProperty.DELETE_VALUE,
                CmsProperty.DELETE_VALUE));
        properties.add(
            new CmsProperty(CmsPropertyDefinition.PROPERTY_NAVPOS, CmsProperty.DELETE_VALUE, CmsProperty.DELETE_VALUE));
        cms.writePropertyObjects(cms.getSitePath(entryFolder), properties);
        tryUnlock(entryFolder);
        return change;
    }
709477
public void deleteDescriptorIfNecessary() throws CmsException {

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

    }
625246
private byte[] replaceInXml(CmsFile cmsFile) throws Exception {

        Exception e = null;
        CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), cmsFile);
        Pattern pattern = Pattern.compile(m_settings.getSearchpattern());
        // loop over the locales of the content
        boolean modified = false;
        boolean matched = false;
        String requestedLocale = m_settings.getLocale();
        for (Locale locale : xmlContent.getLocales()) {
            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(requestedLocale)
                && !locale.toString().equalsIgnoreCase(requestedLocale)) {
                // does not match the requested locale, skip it
                continue;
            }
            // loop over the available element paths of the current content locale
            List<String> paths = xmlContent.getNames(locale);
            for (String xpath : paths) {
                // try to get the value extraction for the current element path
                I_CmsXmlContentValue value = xmlContent.getValue(xpath, locale);
                if (value.isSimpleType()) {
                    try {
                        String currPath = value.getPath();
                        if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_settings.getXpath())
                            || currPath.equals(m_settings.getXpath())
                            || (CmsXmlUtils.removeXpath(currPath).equals(m_settings.getXpath()))) {
                            // xpath match
                            String oldVal = value.getStringValue(getCms());
                            Matcher matcher = pattern.matcher(oldVal);
                            matcher = Pattern.compile(m_settings.getSearchpattern()).matcher(oldVal);
                            if (matcher.find()) {
                                matched = true;
                                m_matchedResources.add(cmsFile);
                                if (m_replace) {
                                    String newVal = matcher.replaceAll(m_settings.getReplacepattern());
                                    if (!oldVal.equals(newVal)) {
                                        value.setStringValue(getCms(), newVal);
                                        modified = true;
                                    }
                                }
                            }
                        }
                    } catch (Exception ex) {
                        // log and go on
                        LOG.error(ex.getMessage(), ex);
                        e = ex;
                    }
                }
            }
        }
        if (e != null) {
            throw e;
        }
        if (matched) {
            getReport().println(Messages.get().container(Messages.RPT_SOURCESEARCH_MATCHED_0), I_CmsReport.FORMAT_OK);
        } else {
            getReport().println(
                Messages.get().container(Messages.RPT_SOURCESEARCH_NOT_MATCHED_0),
                I_CmsReport.FORMAT_NOTE);
        }
        if (modified) {
            return xmlContent.marshal();
        }
        return null;
    }
1108707
public void addToNavigation(CmsClientSitemapEntry entry) {

        entry.setInNavigation(true);
        CmsSitemapChange change = new CmsSitemapChange(entry.getId(), entry.getSitePath(), ChangeType.modify);
        CmsPropertyModification mod = new CmsPropertyModification(
            entry.getId(),
            CmsClientProperty.PROPERTY_NAVTEXT,
            entry.getTitle(),
            true);
        change.setPropertyChanges(Collections.singletonList(mod));
        change.setPosition(entry.getPosition());
        commitChange(change, null);
    }
496598
private CmsObject getAdminCms(CmsObject cms) throws CmsException {

        CmsObject adminCms = OpenCms.initCmsObject(m_adminCms);
        adminCms.getRequestContext().setSiteRoot(cms.getRequestContext().getSiteRoot());
        adminCms.getRequestContext().setRequestTime(cms.getRequestContext().getRequestTime());
        adminCms.getRequestContext().setCurrentProject(cms.getRequestContext().getCurrentProject());
        adminCms.getRequestContext().setEncoding(cms.getRequestContext().getEncoding());
        adminCms.getRequestContext().setUri(cms.getRequestContext().getUri());
        return adminCms;
    }
348775
public int remove(CmsUUID id) {

        CmsDetailPageInfo info = m_infoById.get(id);
        if (info == null) {
            throw new IllegalArgumentException();
        }
        String type = info.getType();
        List<CmsDetailPageInfo> infos = m_map.get(type);
        int pos = infos.indexOf(info);
        infos.remove(pos);
        m_infoById.remove(id);
        return pos;

    }
384307
public int change( final int    add,
                       final int    remove )
    {
        for (;;)
        {
            int    current = _flags.get();
            int    newValue = ( current | add ) & ~remove;

            if ( _flags.compareAndSet( current, newValue ) )
            {
                return current;
            }
        }
    }
1137638
public CmsVfsSitemapService getSitemapService() throws CmsException {

        CmsVfsSitemapService svc = new CmsVfsSitemapService();
        CmsObject cms = OpenCms.initCmsObject(m_cms);
        cms.getRequestContext().setSiteRoot("");
        svc.setCms(cms);
        return svc;
    }
602283
private void changeElementLocales() throws CmsException {

        // create Locale objects to work with
        Locale oldLocale = CmsLocaleManager.getLocale(m_settings.getOldLocale());
        Locale newLocale = CmsLocaleManager.getLocale(m_settings.getNewLocale());
        boolean checkTemplate = CmsStringUtil.isNotEmpty(m_settings.getTemplate());

        // set the resource filter to filter xml pages
        int xmlPageId = OpenCms.getResourceManager().getResourceType(
            CmsResourceTypeXmlPage.getStaticTypeName()).getTypeId();
        CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireType(xmlPageId);
        String path = CmsResource.getFolderPath(m_settings.getVfsFolder());
        // get the list of resources to change
        List resources = getCms().readResources(path, filter, m_settings.isIncludeSubFolders());

        // set the report counters
        int count = 0;
        int resSize = resources.size();

        // iterate the resources
        Iterator i = resources.iterator();
        while (i.hasNext()) {

            count++;
            CmsResource res = (CmsResource)i.next();

            // generate report output
            getReport().print(
                org.opencms.report.Messages.get().container(
                    org.opencms.report.Messages.RPT_SUCCESSION_2,
                    String.valueOf(count),
                    String.valueOf(resSize)),
                I_CmsReport.FORMAT_NOTE);
            getReport().print(Messages.get().container(Messages.RPT_PROCESSING_PAGE_0), I_CmsReport.FORMAT_NOTE);
            getReport().print(
                org.opencms.report.Messages.get().container(
                    org.opencms.report.Messages.RPT_ARGUMENT_1,
                    getCms().getSitePath(res)));
            getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));

            try {

                if (checkTemplate) {
                    // check the template property
                    String template = getCms().readPropertyObject(
                        res,
                        CmsPropertyDefinition.PROPERTY_TEMPLATE,
                        true).getValue("");
                    if (!m_settings.getTemplate().equals(template)) {
                        // template property does not match, report and continue with next resource
                        getReport().println(
                            Messages.get().container(Messages.RPT_CHANGEELEMENTLOCALE_TEMPLATE_0),
                            I_CmsReport.FORMAT_NOTE);
                        continue;
                    }
                }

                // get the file contents
                CmsFile file = getCms().readFile(res);
                // get the page object
                CmsXmlPage page = CmsXmlPageFactory.unmarshal(getCms(), file);
                // write the report output

                if (!page.hasLocale(oldLocale)) {
                    // old Locale not present, report and continue with next resource
                    getReport().println(
                        Messages.get().container(
                            Messages.RPT_CHANGEELEMENTLOCALE_OLDLOCALE_1,
                            m_settings.getOldLocale()),
                        I_CmsReport.FORMAT_NOTE);
                    continue;
                }

                if (page.hasLocale(newLocale)) {
                    // target Locale present, report and continue with next resource
                    getReport().println(
                        Messages.get().container(
                            Messages.RPT_CHANGEELEMENTLOCALE_NEWLOCALE_1,
                            m_settings.getNewLocale()),
                        I_CmsReport.FORMAT_NOTE);
                    continue;
                }

                // change the Locale of the elements
                page.moveLocale(oldLocale, newLocale);

                // set the file contents
                file.setContents(page.marshal());

                // check the lock state of the file to write
                CmsLock lock = getCms().getLock(res);
                boolean isLocked = false;
                boolean canWrite = false;
                if (lock.isNullLock()) {
                    // file not locked, lock it
                    getCms().lockResource(getCms().getSitePath(res));
                    isLocked = true;
                    canWrite = true;
                } else if (lock.isOwnedBy(getCms().getRequestContext().getCurrentUser())) {
                    // file locked by current user
                    canWrite = true;
                }

                if (canWrite) {
                    // write the file contents
                    getCms().writeFile(file);
                } else {
                    // no write operation possible
                    getReport().println(
                        Messages.get().container(Messages.RPT_CHANGEELEMENTLOCALE_NOTLOCKED_0),
                        I_CmsReport.FORMAT_NOTE);
                }

                if (isLocked) {
                    // unlock previously locked resource
                    getCms().unlockResource(getCms().getSitePath(res));
                }

                if (canWrite) {
                    // successfully changed, report it
                    getReport().println(
                        org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                        I_CmsReport.FORMAT_OK);
                }

            } catch (CmsException e) {
                // an error occurred, show exception on report output
                getReport().println(e);
            }
        }
    }
108612
public void moveTo(String cmsNewPath) throws CmsException {

        ensureLock();
        m_cms.moveResource(m_cms.getSitePath(m_resource), cmsNewPath);
        CmsUUID id = m_resource.getStructureId();
        CmsResource updatedRes = m_cms.readResource(id, CmsJlanDiskInterface.STANDARD_FILTER);
        m_resource = updatedRes;
        updateFromResource();
    }
1289009
protected CmsSitemapChange saveInternal(String entryPoint, CmsSitemapChange change) throws CmsException {

        ensureSession();
        switch (change.getChangeType()) {
            case clipboardOnly:
                // do nothing
                break;
            case remove:
                change = removeEntryFromNavigation(change);
                break;
            case undelete:
                change = undelete(change);
                break;
            default:
                change = applyChange(entryPoint, change);
        }
        setClipboardData(change.getClipBoardData());
        return change;
    }
1080213
private void updateProjectResources() throws CmsException {

        CmsObject cms = A_CmsUI.getCmsObject();
        Set<String> resourceRootPaths = getResourcePaths();
        // write the edited project resources
        CmsProject currentProject = cms.getRequestContext().getCurrentProject();
        // change the current project
        cms.getRequestContext().setCurrentProject(m_project);
        // store the current site root
        String currentSite = cms.getRequestContext().getSiteRoot();
        // copy the resources to the current project
        try {
            // switch to the root site
            cms.getRequestContext().setSiteRoot("");
            // remove deleted resources
            for (String resName : cms.readProjectResources(m_project)) {
                if (!resourceRootPaths.contains(resName)) {
                    cms.removeResourceFromProject(resName);
                }
            }
            // read project resources again!
            List<String> currentResNames = cms.readProjectResources(m_project);
            // copy missing resources
            for (String resName : resourceRootPaths) {
                if (!currentResNames.contains(resName)) {
                    cms.copyResourceToProject(resName);
                }
            }
        } finally {
            // switch back to current site and project
            cms.getRequestContext().setSiteRoot(currentSite);
            cms.getRequestContext().setCurrentProject(currentProject);
        }
    }
245713
protected void performSingleDeleteOperation(String resource, CmsResourceDeleteMode deleteOption)
    throws CmsException {

        // lock resource if autolock is enabled
        checkLock(resource);
        // delete the resource
        getCms().deleteResource(resource, deleteOption);
    }
744361
public void edit(
        CmsClientSitemapEntry entry,
        List<CmsPropertyModification> propertyChanges,
        final CmsReloadMode reloadStatus) {

        CmsSitemapChange change = getChangeForEdit(entry, propertyChanges);
        final String updateTarget = ((reloadStatus == CmsReloadMode.reloadParent))
        ? getParentEntry(entry).getSitePath()
        : entry.getSitePath();
        Command callback = new Command() {

            public void execute() {

                if ((reloadStatus == CmsReloadMode.reloadParent) || (reloadStatus == CmsReloadMode.reloadEntry)) {
                    updateEntry(updateTarget);
                }
            }
        };
        if (change != null) {
            commitChange(change, callback);
        }
    }
1196719
private CmsSitemapChange undelete(CmsSitemapChange change) throws CmsException {

        CmsObject cms = getCmsObject();
        CmsResource deleted = cms.readResource(change.getEntryId(), CmsResourceFilter.ALL);
        if (deleted.getState().isDeleted()) {
            ensureLock(deleted);
            cms.undeleteResource(getCmsObject().getSitePath(deleted), true);
            tryUnlock(deleted);
        }
        String parentPath = CmsResource.getParentFolder(cms.getSitePath(deleted));
        CmsJspNavElement navElement = getNavBuilder().getNavigationForResource(
            parentPath,
            CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
        CmsClientSitemapEntry entry = toClientEntry(navElement, navElement.isInNavigation());
        entry.setSubEntries(getChildren(parentPath, 2, null), null);
        change.setUpdatedEntry(entry);
        change.setParentId(cms.readParentFolder(deleted.getStructureId()).getStructureId());
        return change;
    }
1144941
private void deleteResourceFromProject(CmsObject cms, CmsResource res) throws CmsException {

        CmsLock lock = cms.getLock(res);
        if (lock.isUnlocked() || lock.isLockableBy(cms.getRequestContext().getCurrentUser())) {
            cms.lockResourceTemporary(res);
        } else {
            cms.changeLock(res);
        }
        cms.deleteResource(cms.getSitePath(res), CmsResource.DELETE_PRESERVE_SIBLINGS);
    }
606790
public void deleteUser(CmsRequestContext context, String username) throws CmsException {

        CmsUser user = readUser(context, username);
        deleteUser(context, user, null);
    }