Finds the entry point to a sitemap.<p>

@param cms the CMS context
@param openPath the resource path to find the sitemap to

@return the sitemap entry point
349795
public String findEntryPoint(CmsObject cms, String openPath) {

        CmsADEConfigData configData = lookupConfiguration(cms, openPath);
        String result = configData.getBasePath();
        if (result == null) {
            return cms.getRequestContext().addSiteRoot("/");
        }
        return result;
    }
1092486
public CmsResource createResource() throws CmsException {

        String path = OpenCms.getResourceManager().getNameGenerator().getNewFileName(
            m_cms,
            m_pathWithPattern,
            5,
            m_explorerNameGeneration);
        Locale contentLocale = OpenCms.getLocaleManager().getDefaultLocale(m_cms, CmsResource.getFolderPath(path));
        CmsRequestContext context = m_cms.getRequestContext();
        if (m_modelResource != null) {
            context.setAttribute(CmsRequestContext.ATTRIBUTE_MODEL, m_modelResource.getRootPath());
        }
        context.setAttribute(CmsRequestContext.ATTRIBUTE_NEW_RESOURCE_LOCALE, contentLocale);
        CmsResource res = m_cms.createResource(
            path,
            OpenCms.getResourceManager().getResourceType(m_type),
            null,
            new ArrayList<CmsProperty>());
        if (m_propChanges != null) {
            CmsPropertyEditorHelper helper = new CmsPropertyEditorHelper(m_cms);
            helper.overrideStructureId(res.getStructureId());
            helper.saveProperties(m_propChanges);
        }
        // Path or other metadata may have changed
        m_createdResource = m_cms.readResource(res.getStructureId(), CmsResourceFilter.IGNORE_EXPIRATION);
        try {
            m_cms.unlockResource(m_createdResource);
        } catch (CmsException e) {
            LOG.info(e.getLocalizedMessage(), e);
        }
        for (I_Callback callback : m_callbacks) {
            callback.onResourceCreated(this);
        }
        return m_createdResource;
    }
1189526
public CmsADEConfigData lookupConfiguration(CmsObject cms, String rootPath) {

        CmsADEConfigData configData = internalLookupConfiguration(cms, rootPath);
        return configData;
    }
328382
public Map<String, String> getSitePath() {

        if (m_sitePaths == null) {
            m_sitePaths = CmsCollectionsGenericWrapper.createLazyMap(new Transformer() {

                public Object transform(Object rootPath) {

                    if (rootPath instanceof String) {
                        return getRequestContext().removeSiteRoot((String)rootPath);
                    }
                    return null;
                }
            });
        }
        return m_sitePaths;
    }
1004616
String getTransformationPath() {

        String path = System.getProperty("opencms.config.transform");
        if (path == null) {
            path = CmsStringUtil.joinPaths(m_baseFolder.getAbsolutePath(), DEFAULT_XSLT_FILENAME);
        }
        return path;
    }
928431
public CmsJspResourceWrapper readSubsiteFor(String path) throws CmsException {

        CmsADEConfigData config = OpenCms.getADEManager().lookupConfiguration(
            m_cms,
            m_cms.getRequestContext().addSiteRoot(path));
        return CmsJspResourceWrapper.wrap(
            m_cms,
            m_cms.readResource(m_cms.getRequestContext().removeSiteRoot(config.getBasePath())));
    }
1091448
public static List<CmsCategoryTreeEntry> getCategoriesForSitePathStatic(CmsObject cms, String sitePath)
    throws CmsException {

        return getCategoriesForSitePathStatic(cms, sitePath, null);
    }
1146859
public List<String> getSubSitePaths(CmsObject cms, String subSiteRoot) {

        List<String> result = new ArrayList<String>();
        String normalizedRootPath = CmsStringUtil.joinPaths("/", subSiteRoot, "/");
        CmsADEConfigCacheState state = getCacheState(isOnline(cms));
        Set<String> siteConfigurationPaths = state.getSiteConfigurationPaths();
        for (String path : siteConfigurationPaths) {
            if ((path.length() > normalizedRootPath.length()) && path.startsWith(normalizedRootPath)) {
                result.add(path);
            }
        }
        return result;
    }
3444
public void addCurrentSubsite(String referencePath) {

        CmsADEConfigData configData = OpenCms.getADEManager().lookupConfiguration(m_cms, referencePath);
        String basePath = configData.getBasePath();
        if (basePath != null) {
            addOption(
                Type.currentSubsite,
                basePath,
                Messages.get().getBundle(OpenCms.getWorkplaceManager().getWorkplaceLocale(m_cms)).key(
                    Messages.GUI_SITESELECTOR_CURRENT_SUBSITE_0));
        }
    }
77955
void openPath(String path, boolean initTree) {

        if (path == null) {
            String siteRoot = A_CmsUI.getCmsObject().getRequestContext().getSiteRoot();
            path = m_locationCache.getFileExplorerLocation(siteRoot);
            if (path == null) {
                path = "";
            } else if (OpenCms.getSiteManager().startsWithShared(path)) {
                path = path.substring(siteRoot.length());
            }
        }
        boolean existsPath = CmsStringUtil.isNotEmptyOrWhitespaceOnly(path)
            && A_CmsUI.getCmsObject().existsResource(path, FILES_N_FOLDERS);

        if (path.startsWith("/")) {
            // remove a leading slash to avoid an empty first path fragment
            path = path.substring(1);
        }

        String[] pathItems = path.split("/");

        if (initTree) {
            try {
                initFolderTree(existsPath);
            } catch (CmsException e) {
                CmsErrorDialog.showErrorDialog(
                    CmsVaadinUtils.getMessageText(Messages.ERR_EXPLORER_CAN_NOT_OPEN_PATH_1, path),
                    e);
                LOG.error(e.getLocalizedMessage(), e);
                return;
            }
        }

        Collection<?> rootItems = m_treeContainer.rootItemIds();
        if (rootItems.size() != 1) {
            throw new RuntimeException("Illeagal state, folder tree has " + rootItems.size() + " children");
        }

        CmsUUID folderId = (CmsUUID)rootItems.iterator().next();
        if (initTree) {
            if (existsPath) {
                m_expandListener.setOpenPathFragment(pathItems[0]);
            }
            m_fileTree.expandItem(folderId);
            m_expandListener.setOpenPathFragment(null);
        }
        Collection<?> children = m_treeContainer.getChildren(folderId);
        for (int i = 0; i < pathItems.length; i++) {
            if (CmsStringUtil.isEmptyOrWhitespaceOnly(pathItems[i])) {
                continue;
            }
            CmsUUID level = null;
            if (children != null) {
                for (Object id : children) {
                    if (m_treeContainer.getItem(id).getItemProperty(
                        CmsResourceTableProperty.PROPERTY_RESOURCE_NAME).getValue().equals(pathItems[i])) {
                        level = (CmsUUID)id;
                        m_expandListener.setOpenPathFragment(
                            existsPath && (i < (pathItems.length - 1)) ? pathItems[i + 1] : null);
                        m_fileTree.expandItem(level);
                        m_expandListener.setOpenPathFragment(null);
                        break;
                    }
                }
            }
            if ((level == null) || level.equals(folderId)) {
                break;
            }
            folderId = level;
            children = m_treeContainer.getChildren(folderId);
        }
        try {
            readFolder(folderId);
        } catch (CmsException e) {
            CmsErrorDialog.showErrorDialog(
                CmsVaadinUtils.getMessageText(Messages.ERR_EXPLORER_CAN_NOT_OPEN_PATH_1, path),
                e);
            LOG.error(e.getLocalizedMessage(), e);
            return;
        }
    }
180912
private void createNewContainerElements(CmsObject cms, CmsXmlContainerPage page, String sitePath)
    throws CmsException {

        CmsADEConfigData configData = OpenCms.getADEManager().lookupConfiguration(cms, cms.addSiteRoot(sitePath));
        Locale contentLocale = OpenCms.getLocaleManager().getDefaultLocale(cms, CmsResource.getFolderPath(sitePath));
        CmsObject cloneCms = OpenCms.initCmsObject(cms);
        cloneCms.getRequestContext().setLocale(contentLocale);
        CmsContainerPageBean pageBean = page.getContainerPage(cms);
        boolean needsChanges = false;
        List<CmsContainerBean> updatedContainers = new ArrayList<CmsContainerBean>();
        for (CmsContainerBean container : pageBean.getContainers().values()) {
            List<CmsContainerElementBean> updatedElements = new ArrayList<CmsContainerElementBean>();
            for (CmsContainerElementBean element : container.getElements()) {
                if (element.isCreateNew() && !element.isGroupContainer(cms) && !element.isInheritedContainer(cms)) {
                    needsChanges = true;
                    String typeName = OpenCms.getResourceManager().getResourceType(element.getResource()).getTypeName();
                    CmsResourceTypeConfig typeConfig = configData.getResourceType(typeName);
                    if (typeConfig == null) {
                        throw new IllegalArgumentException(
                            "Can not copy template model element '"
                                + element.getResource().getRootPath()
                                + "' because the resource type '"
                                + typeName
                                + "' is not available in this sitemap.");
                    }

                    CmsResource newResource = typeConfig.createNewElement(
                        cloneCms,
                        element.getResource(),
                        CmsResource.getParentFolder(cms.getRequestContext().addSiteRoot(sitePath)));
                    CmsContainerElementBean newBean = new CmsContainerElementBean(
                        newResource.getStructureId(),
                        element.getFormatterId(),
                        element.getIndividualSettings(),
                        false);
                    updatedElements.add(newBean);
                } else {
                    updatedElements.add(element);
                }
            }

            CmsContainerBean updatedContainer = new CmsContainerBean(
                container.getName(),
                container.getType(),
                container.getParentInstanceId(),
                container.isRootContainer(),
                container.getMaxElements(),
                updatedElements);
            updatedContainers.add(updatedContainer);
        }
        if (needsChanges) {
            CmsContainerPageBean updatedPage = new CmsContainerPageBean(updatedContainers);
            page.writeContainerPage(cms, updatedPage);
        }
    }
1093483
public void setSiteParam(String siteRoot, String key, String value) {

        CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(siteRoot);
        if (site == null) {
            throw new IllegalArgumentException("No site found for path: " + siteRoot);
        } else {
            site.getParameters().put(key, value);
            OpenCms.writeConfiguration(CmsSitesConfiguration.class);
        }
    }
180537
protected I_CmsContextMenuEntry createViewOnlineEntry() {

        final String onlineLink = m_controller.getData().getOnlineLink();
        CmsContextMenuEntry entry = null;
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(onlineLink)) {
            I_CmsContextMenuCommand command = new I_CmsContextMenuCommand() {

                public void execute(
                    CmsUUID structureId,
                    I_CmsContextMenuHandler handler,
                    CmsContextMenuEntryBean bean) {

                    Window.open(onlineLink, "opencms-online", null);
                }

                public A_CmsContextMenuItem getItemWidget(
                    CmsUUID structureId,
                    I_CmsContextMenuHandler handler,
                    CmsContextMenuEntryBean bean) {

                    return null;
                }

                public boolean hasItemWidget() {

                    return false;
                }
            };
            entry = new CmsContextMenuEntry(this, null, command);
            CmsContextMenuEntryBean entryBean = new CmsContextMenuEntryBean();
            entryBean.setLabel(Messages.get().key(Messages.GUI_VIEW_ONLINE_0));
            entryBean.setActive(true);
            entryBean.setVisible(true);
            entry.setBean(entryBean);
        }
        return entry;
    }
398332
private String getPath(CmsObject cms, HttpSession session) {

        CmsQuickLaunchLocationCache locationCache = CmsQuickLaunchLocationCache.getLocationCache(session);
        String page = locationCache.getFileExplorerLocation(cms.getRequestContext().getSiteRoot());
        if (page != null) {
            CmsADEConfigData conf = OpenCms.getADEManager().lookupConfiguration(
                cms,
                cms.getRequestContext().addSiteRoot(page));
            if ((conf == null) || (conf.getBasePath() == null)) {
                page = null;
            } else {
                page = cms.getRequestContext().removeSiteRoot(conf.getBasePath());
            }
        }
        if (page == null) {
            page = locationCache.getSitemapEditorLocation(cms.getRequestContext().getSiteRoot());
        }
        return page;
    }
692064
private String getPath(CmsObject cms, HttpSession session) {

        CmsQuickLaunchLocationCache locationCache = CmsQuickLaunchLocationCache.getLocationCache(session);
        String page = locationCache.getPageEditorLocation(cms.getRequestContext().getSiteRoot());
        if (page == null) {
            try {
                CmsResource mainDefaultFile = cms.readDefaultFile("/");
                if (mainDefaultFile != null) {
                    page = cms.getSitePath(mainDefaultFile);
                }
            } catch (CmsException e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        return page;
    }
272868
protected List<CmsResource> readTree(String rootPath) throws CmsException {

        rootPath = CmsFileUtil.removeTrailingSeparator(rootPath);
        CmsResource base = m_cms.readResource(rootPath);

        I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(base);
        List<CmsResource> result = new ArrayList<CmsResource>();
        if (resType.isFolder()) {
            rootPath = CmsStringUtil.joinPaths(rootPath, "/");
            List<CmsResource> subResources = m_cms.readResources(rootPath, CmsResourceFilter.ALL, true);
            result.add(base);
            result.addAll(subResources);
        } else {
            result.add(base);
        }
        for (CmsResource resource : result) {
            m_cachedResources.put(resource.getStructureId(), resource);
        }

        return result;
    }
1352372
public void openPath(String path) {

        if (!CmsStringUtil.isPrefixPath(m_root.getRootPath(), path)) {
            CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(path);
            if (site != null) {
                // the given path is a root path switch to the determined site
                getSiteSelector().setValue(site.getSiteRoot());
                path = m_currentCms.getRequestContext().removeSiteRoot(path);
            } else if (OpenCms.getSiteManager().startsWithShared(path)) {
                getSiteSelector().setValue(OpenCms.getSiteManager().getSharedFolder());
            } else if (path.startsWith(CmsWorkplace.VFS_PATH_SYSTEM)) {
                Container container = getSiteSelector().getContainerDataSource();
                String newSiteRoot = null;
                for (String possibleSiteRoot : Arrays.asList("", "/", "/system", "/system/")) {
                    if (container.containsId(possibleSiteRoot)) {
                        newSiteRoot = possibleSiteRoot;
                        break;
                    }
                }
                if (newSiteRoot == null) {
                    LOG.warn(
                        "Couldn't open path in site selector because neither root site nor system folder are in the site selector. path="
                            + path);
                    return;
                }
                getSiteSelector().setValue(newSiteRoot);
            }
        }
        if (!"/".equals(path)) {
            List<CmsUUID> idsToOpen = Lists.newArrayList();
            try {
                CmsResource currentFolder = m_currentCms.readResource(CmsResource.getParentFolder(path));
                if (!m_root.getStructureId().equals(currentFolder.getStructureId())) {
                    idsToOpen.add(currentFolder.getStructureId());
                    CmsResource parentFolder = null;

                    do {
                        try {
                            parentFolder = m_currentCms.readParentFolder(currentFolder.getStructureId());
                            idsToOpen.add(parentFolder.getStructureId());
                            currentFolder = parentFolder;
                        } catch (CmsException | NullPointerException e) {
                            LOG.info(e.getLocalizedMessage(), e);
                            break;
                        }
                    } while (!parentFolder.getStructureId().equals(m_root.getStructureId()));
                    // we need to iterate from "top" to "bottom", so we reverse the list of folders
                    Collections.reverse(idsToOpen);

                    for (CmsUUID id : idsToOpen) {
                        m_fileTree.expandItem(id);
                    }
                }
            } catch (CmsException e) {
                LOG.debug("Can not read parent folder of current path.", e);
            }
        }
    }