Saves the rewrite alias for a given site root.<p>

@param cms the current CMS context
@param siteRoot the site root for which the rewrite aliases should be saved
@param newAliases the list of aliases to save

@throws CmsException if something goes wrong
176722
public void saveRewriteAliases(CmsObject cms, String siteRoot, List<CmsRewriteAlias> newAliases)
    throws CmsException {

        checkPermissionsForMassEdit(cms, siteRoot);
        m_securityManager.saveRewriteAliases(cms.getRequestContext(), siteRoot, newAliases);
    }
452265
public void saveTreeState(final String treeName, final String siteRoot, final Set<CmsUUID> openItemIds) {

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

            @Override
            public void execute() {

                start(600, false);
                getGalleryService().saveTreeOpenState(treeName, getTreeToken(), siteRoot, openItemIds, this);
            }

            @Override
            protected void onResponse(Void result) {

                stop(false);
            }
        };
        treeStateAction.execute();

    }
798849
private CmsResource createSiteRootIfNeeded(String siteRoot) throws CmsException {

        CmsResource siteRootResource = null;

        // check if the site root already exists
        try {
            // take the existing site and do not perform any OU related actions
            if (m_cms.existsResource(siteRoot)) {
                siteRootResource = m_cms.readResource(siteRoot);
            } else {
                CmsResource onlineVersion = m_cmsOnline.readResource(siteRoot);
                siteRootResource = m_cms.readResource(onlineVersion.getStructureId());
            }

        } catch (CmsVfsResourceNotFoundException e) {
            // not create a new site folder and the according OU if option is checked checked
            getReport().println(
                Messages.get().container(Messages.RPT_SITE_CREATE_RESOURCES_0),
                I_CmsReport.FORMAT_DEFAULT);
            I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(
                CmsResourceTypeFolderSubSitemap.TYPE_SUBSITEMAP);
            siteRootResource = m_cms.createResource(siteRoot, type);
            CmsProperty folderTitle = new CmsProperty(
                CmsPropertyDefinition.PROPERTY_TITLE,
                m_site.getTitle(),
                m_site.getTitle());
            m_cms.writePropertyObject(siteRoot, folderTitle);

        }
        return siteRootResource;
    }
280364
CmsObject getCmsObjectWithSite(String siteRoot) {

        if (siteRoot == null) {
            siteRoot = "/";
        }
        try {
            CmsObject res = OpenCms.initCmsObject(m_cms);
            res.getRequestContext().setSiteRoot(siteRoot);
            return res;
        } catch (CmsException e) {
            LOG.error("Unable to initialize CmsObject", e);
            return m_cms;
        }
    }
907769
public List<CmsAlias> getAliasesForSite(CmsRequestContext requestContext, String siteRoot) throws CmsException {

        CmsDbContext dbc = m_dbContextFactory.getDbContext(requestContext);
        try {
            List<CmsAlias> aliases = m_driverManager.readAliasesBySite(
                dbc,
                requestContext.getCurrentProject(),
                siteRoot);
            return aliases;
        } catch (Exception e) {
            dbc.report(null, Messages.get().container(Messages.ERR_DB_OPERATION_0), e);
            return null; // will never be executed
        } finally {
            dbc.clear();
        }
    }
682666
private CmsPair<String, List<Object>> prepareRewriteAliasConditions(CmsRewriteAliasFilter filter) {

        List<String> conditions = new ArrayList<String>();
        conditions.add("1 = 1");
        List<Object> parameters = new ArrayList<Object>();
        if (filter.getSiteRoot() != null) {
            parameters.add(filter.getSiteRoot());
            conditions.add("SITE_ROOT = ?");
        }
        if (filter.getId() != null) {
            parameters.add(filter.getId().toString());
            conditions.add("ID = ?");
        }
        return CmsPair.create(CmsStringUtil.listAsString(conditions, " AND "), parameters);
    }
754518
private void selectSite(String siteRoot) {

        if (m_sortSelectBox == null) {
            return;
        }
        Map<String, String> options = m_sortSelectBox.getItems();
        String option = null;
        for (Map.Entry<String, String> entry : options.entrySet()) {
            if (CmsStringUtil.comparePaths(entry.getKey(), siteRoot)) {
                option = entry.getKey();
                break;
            }
        }
        if (option != null) {
            m_sortSelectBox.setFormValue(option, false);
        }
    }
1179157
private void saveFavIcon(String siteRoot) {

        if (m_os == null) {
            return;
        }
        if (m_os.size() == 0) {
            return;
        }

        getReport().println(Messages.get().container(Messages.RPT_SITE_SET_FAVICON_0), I_CmsReport.FORMAT_DEFAULT);
        CmsResource favicon = null;
        try {
            favicon = m_cms.createResource(
                siteRoot + CmsSiteManager.FAVICON,
                OpenCms.getResourceManager().getResourceType(CmsResourceTypeImage.getStaticTypeName()));
        } catch (CmsVfsResourceAlreadyExistsException e) {
            //OK, Resource already there
            try {
                favicon = m_cms.readResource(siteRoot + CmsSiteManager.FAVICON);
            } catch (CmsException e2) {
                //no, it wasn't..
                getReport().println(
                    Messages.get().container(Messages.RPT_SITE_ERROR_FAVICON_0),
                    I_CmsReport.FORMAT_ERROR);
                getReport().println(e);
                getReport().println(e2);
                return;
            }
        } catch (CmsIllegalArgumentException | CmsException e) {
            getReport().println(Messages.get().container(Messages.RPT_SITE_ERROR_FAVICON_0), I_CmsReport.FORMAT_ERROR);
            getReport().println(e);
            return;
        }
        try {
            m_cms.lockResource(siteRoot + CmsSiteManager.FAVICON);
            CmsFile faviconFile = new CmsFile(favicon);
            faviconFile.setContents(m_os.toByteArray());
            m_cms.writeFile(faviconFile);
            m_cms.unlockResource(siteRoot + CmsSiteManager.FAVICON);
        } catch (CmsException e) {
            getReport().println(Messages.get().container(Messages.RPT_SITE_ERROR_FAVICON_0), I_CmsReport.FORMAT_ERROR);
            getReport().println(e);
            return;
        }

    }
61195
public void save(CmsObject cms, CmsContainerPageBean cntPage) throws CmsException {

        save(cms, cntPage, false);
    }
18644
protected void makeNewEntry(
        final CmsClientSitemapEntry parent,
        final I_CmsSimpleCallback<CmsClientSitemapEntry> callback) {

        ensureUniqueName(parent, NEW_ENTRY_NAME, new I_CmsSimpleCallback<String>() {

            public void execute(String urlName) {

                CmsClientSitemapEntry newEntry = new CmsClientSitemapEntry();
                //newEntry.setTitle(urlName);
                newEntry.setName(urlName);
                String sitePath = parent.getSitePath() + urlName + "/";
                newEntry.setSitePath(sitePath);
                newEntry.setVfsPath(null);
                newEntry.setPosition(0);
                newEntry.setNew(true);
                newEntry.setInNavigation(true);
                newEntry.setResourceTypeName("folder");
                newEntry.getOwnProperties().put(
                    CmsClientProperty.PROPERTY_TITLE,
                    new CmsClientProperty(CmsClientProperty.PROPERTY_TITLE, NEW_ENTRY_NAME, NEW_ENTRY_NAME));
                callback.execute(newEntry);
            }
        });

    }
872679
protected CmsObject rootCms(CmsObject cms) throws CmsException {

        CmsObject result = OpenCms.initCmsObject(cms);
        result.getRequestContext().setSiteRoot("");
        return result;
    }
146341
protected void updateRoot(CmsObject rootCms, CmsResource siteRootResource) {

        m_root = siteRootResource;
        m_currentCms = rootCms;
        updateView();
    }
1262462
private CmsAliasTableRow createAliasTableEntry(CmsObject cms, CmsAlias alias) throws CmsException {

        CmsResource resource = cms.readResource(alias.getStructureId(), CmsResourceFilter.ALL);
        CmsAliasTableRow result = new CmsAliasTableRow();
        result.setStructureId(alias.getStructureId());
        result.setOriginalStructureId(alias.getStructureId());
        result.setAliasPath(alias.getAliasPath());
        result.setResourcePath(cms.getSitePath(resource));
        result.setKey((new CmsUUID()).toString());
        result.setMode(alias.getMode());
        result.setChanged(false);
        return result;
    }
721355
public void addSite(CmsObject cms, CmsSite site) throws CmsException {

        // check permissions
        if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_1_CORE_OBJECT) {
            // simple unit tests will have runlevel 1 and no CmsObject
            OpenCms.getRoleManager().checkRole(cms, CmsRole.DATABASE_MANAGER);
        }

        // un-freeze
        m_frozen = false;

        // set aliases and parameters, they will be used in the addSite method
        // this is necessary because of a digester workaround
        m_siteParams = site.getParameters();
        m_aliases = site.getAliases();

        String secureUrl = null;
        if (site.hasSecureServer()) {
            secureUrl = site.getSecureUrl();
        }

        // add the site
        addSite(
            site.getUrl(),
            site.getSiteRoot(),
            site.getTitle(),
            Float.toString(site.getPosition()),
            site.getErrorPage(),
            Boolean.toString(site.isWebserver()),
            site.getSSLMode().getXMLValue(),
            secureUrl,
            Boolean.toString(site.isExclusiveUrl()),
            Boolean.toString(site.isExclusiveError()),
            Boolean.toString(site.usesPermanentRedirects()));

        // re-initialize, will freeze the state when finished
        initialize(cms);
        OpenCms.writeConfiguration(CmsSitesConfiguration.class);
    }
167545
private String getNewContentName() throws CmsException {

        String sitePath = OpenCms.getResourceManager().getNameGenerator().getNewFileName(
            m_cms,
            CmsStringUtil.joinPaths(
                m_cms.getRequestContext().removeSiteRoot(m_configuration.getContentParentFolder().getRootPath()),
                m_configuration.getNamePattern()),
            5);
        return sitePath;
    }
604936
protected void onSiteChange(String site) {

        try {
            m_treeData.removeAllItems();
            CmsObject rootCms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
            rootCms.getRequestContext().setSiteRoot("");
            CmsResource siteRootResource = rootCms.readResource(site);

            m_treeData.initRoot(rootCms, siteRootResource);
            m_fileTree.expandItem(siteRootResource.getStructureId());
            m_siteRoot = site;
            updateRoot(rootCms, siteRootResource);
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    }
339230
protected static void checkIsFolder(CmsResource resource) throws CmsException {

        if (!isFolder(resource)) {
            throw new CmsIllegalArgumentException(
                Messages.get().container(
                    org.opencms.file.Messages.ERR_REWRITE_LINKS_ROOT_NOT_FOLDER_1,
                    resource.getRootPath()));
        }
    }