/** * Checks whether a given root path is a site root.<p> * * @param rootPath a root path * * @return true if the given path is the path of a site root */ public boolean isSiteRoot(String rootPath) { String siteRoot = getSiteRoot(rootPath); rootPath = CmsStringUtil.joinPaths(rootPath, "/"); return rootPath.equals(siteRoot); }
/** * Return the site root if the target of this link is internal, or <code>null</code> otherwise.<p> * * @return the site root if the target of this link is internal, or <code>null</code> otherwise */ public String getSiteRoot() { if (m_internal && (m_siteRoot == null)) { m_siteRoot = OpenCms.getSiteManager().getSiteRoot(m_target); if (m_siteRoot == null) { m_siteRoot = ""; } } return m_siteRoot; }
/** * Return the site root if the target of this link is internal, or <code>null</code> otherwise.<p> * * @return the site root if the target of this link is internal, or <code>null</code> otherwise */ public String getSiteRoot() { if (m_internal && (m_siteRoot == null)) { m_siteRoot = OpenCms.getSiteManager().getSiteRoot(m_target); if (m_siteRoot == null) { m_siteRoot = ""; } } return m_siteRoot; }
/** * Returns the site root part of the resources root path, * or <code>null</code> if the path does not match any site root.<p> * * The site root returned will have the form: * <code>/sites/default</code>.<br> * That means there will a leading, but no trailing slash.<p> * * @param rootPath the root path of a resource * * @return the site root part of the resources root path, * or <code>null</code> if the path does not match any site root * * @deprecated Use {@link OpenCms#getSiteManager()} to obtain the configured site manager instance, * then use the method with the same name and signature. */ public static String getSiteRoot(String rootPath) { return OpenCms.getSiteManager().getSiteRoot(rootPath); } }
/** * Tries to get the subsite root for a given resource root path.<p> * * @param cms the current CMS context * @param rootPath the root path for which the subsite root should be found * * @return the subsite root */ public String getSubSiteRoot(CmsObject cms, String rootPath) { CmsADEConfigData configData = lookupConfiguration(cms, rootPath); String basePath = configData.getBasePath(); String siteRoot = OpenCms.getSiteManager().getSiteRoot(rootPath); if (siteRoot == null) { siteRoot = ""; } if ((basePath == null) || !basePath.startsWith(siteRoot)) { // the subsite root should always be below the site root return siteRoot; } else { return basePath; } }
/** * Returns the target site for the given path.<p> * * @param cms the cms context * @param path the path * @param basePath the base path * * @return the target site */ private String getTargetSiteRoot(CmsObject cms, String path, String basePath) { if (OpenCms.getSiteManager().startsWithShared(path) || path.startsWith(CmsWorkplace.VFS_PATH_SYSTEM)) { return null; } String targetSiteRoot = OpenCms.getSiteManager().getSiteRoot(path); if ((targetSiteRoot == null) && (basePath != null)) { targetSiteRoot = OpenCms.getSiteManager().getSiteRoot(basePath); } if (targetSiteRoot == null) { targetSiteRoot = cms.getRequestContext().getSiteRoot(); } return targetSiteRoot; }
/** * Returns the site of the current resources, * taking into account the set site mode.<p> * * @return the site path */ public String getSite() { String site = null; if ((m_siteMode == SITE_MODE_MATCHING) || (m_cms == null)) { site = OpenCms.getSiteManager().getSiteRoot(m_resource.getRootPath()); } else if (m_siteMode == SITE_MODE_CURRENT) { site = m_cms.getRequestContext().getSiteRoot(); } else if (m_siteMode == SITE_MODE_ROOT) { site = ""; } return (site == null ? "" : site); }
/** * Returns the site of the current resources, * taking into account the set site mode.<p> * * @return the site path */ public String getSite() { String site = null; if ((m_siteMode == SITE_MODE_MATCHING) || (m_cms == null)) { site = OpenCms.getSiteManager().getSiteRoot(m_resource.getRootPath()); } else if (m_siteMode == SITE_MODE_CURRENT) { site = m_cms.getRequestContext().getSiteRoot(); } else if (m_siteMode == SITE_MODE_ROOT) { site = ""; } return (site == null ? "" : site); }
/** * Parses the formatter change set.<p> * * @param basePath the configuration base path * @param node the parent node * @param removeAllFormatters flag, indicating if all formatters that are not explicitly added should be removed * @return the formatter change set */ protected CmsFormatterChangeSet parseFormatterChangeSet( String basePath, I_CmsXmlContentLocation node, boolean removeAllFormatters) { Set<String> addFormatters = parseAddFormatters(node); addFormatters.addAll(readLocalMacroFormatters(node)); Set<String> removeFormatters = removeAllFormatters ? new HashSet<String>() : parseRemoveFormatters(node); String siteRoot = null; if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(basePath)) { siteRoot = OpenCms.getSiteManager().getSiteRoot(basePath); } CmsFormatterChangeSet result = new CmsFormatterChangeSet( removeFormatters, addFormatters, siteRoot, removeAllFormatters); return result; }
/** * Returns the most possible right resource name.<p> * * @return the most possible right resource name */ protected String getResourceName() { String resource = getItem().get(m_resColumnPathId).toString(); if (!getWp().getCms().existsResource(resource, CmsResourceFilter.DEFAULT)) { String siteRoot = OpenCms.getSiteManager().getSiteRoot(resource); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(siteRoot)) { resource = resource.substring(siteRoot.length()); } if (!getWp().getCms().existsResource(resource, CmsResourceFilter.DEFAULT)) { resource = null; } } return resource; } }
/** * Returns the most possible right resource name.<p> * * @return the most possible right resource name */ protected String getResourceName() { String resource = getItem().get(m_resColumnPathId).toString(); if (!getWp().getCms().existsResource(resource, CmsResourceFilter.DEFAULT)) { String siteRoot = OpenCms.getSiteManager().getSiteRoot(resource); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(siteRoot)) { resource = resource.substring(siteRoot.length()); } if (!getWp().getCms().existsResource(resource, CmsResourceFilter.DEFAULT)) { resource = null; } } return resource; } }
/** * Returns the most possible right resource name.<p> * * @return the most possible right resource name */ private String getResourceName() { String resource = getItem().get(m_resColumnPathId).toString(); if (!getWp().getCms().existsResource(resource, CmsResourceFilter.DEFAULT)) { String siteRoot = OpenCms.getSiteManager().getSiteRoot(resource); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(siteRoot)) { resource = resource.substring(siteRoot.length()); } if (!getWp().getCms().existsResource(resource, CmsResourceFilter.DEFAULT)) { resource = null; } } return resource; } }
/** * Returns the most possible right resource name.<p> * * @return the most possible right resource name */ private String getResourceName() { String resource = getItem().get(m_resColumnPathId).toString(); if (!getWp().getCms().existsResource(resource, CmsResourceFilter.DEFAULT)) { String siteRoot = OpenCms.getSiteManager().getSiteRoot(resource); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(siteRoot)) { resource = resource.substring(siteRoot.length()); } if (!getWp().getCms().existsResource(resource, CmsResourceFilter.DEFAULT)) { resource = null; } } return resource; } }
/** * Gets the common site root of a set of resources.<p> * @param resourceSet the resources * * @return the common site root (may also be the shared folder or root folder) */ protected String getCommonSite(Collection<CmsResource> resourceSet) { String commonPath = getCommonAncestorPath(resourceSet); String result = null; CmsSiteManagerImpl siteManager = OpenCms.getSiteManager(); if (siteManager.startsWithShared(commonPath)) { result = siteManager.getSharedFolder(); } else { String siteRoot = siteManager.getSiteRoot(CmsStringUtil.joinPaths(commonPath, "/")); if (siteRoot == null) { result = "/"; } else { result = siteRoot; } } return result; }
/** * Computes the folder path for this resource type.<p> * * @param cms the cms context to use * @param pageFolderRootPath root path of the folder containing the current container page * * @return the folder root path for this resource type */ public String getFolderPath(CmsObject cms, String pageFolderRootPath) { checkInitialized(); if (m_folderOrName != null) { return m_folderOrName.getFolderPath(cms, pageFolderRootPath); } else { String siteRoot = null; if (pageFolderRootPath != null) { siteRoot = OpenCms.getSiteManager().getSiteRoot(pageFolderRootPath); } if (siteRoot == null) { siteRoot = cms.getRequestContext().getSiteRoot(); } return CmsStringUtil.joinPaths(siteRoot, CmsADEManager.CONTENT_FOLDER_NAME, m_typeName); } }
/** * Creates a new instance.<p> * * @param cms the CMS context to use * @param rootResource the root resource for the sitemap * * @throws CmsException if something goes wrong */ public CmsModelPageHelper(CmsObject cms, CmsResource rootResource) throws CmsException { m_cms = OpenCms.initCmsObject(cms); m_cms.getRequestContext().setSiteRoot(""); m_rootResource = rootResource; m_adeConfig = OpenCms.getADEManager().lookupConfiguration(m_cms, rootResource.getRootPath()); m_siteRoot = OpenCms.getSiteManager().getSiteRoot(rootResource.getRootPath()); if (m_siteRoot == null) { m_siteRoot = ""; } }
/** * @see org.opencms.ui.I_CmsDialogContext#focus(org.opencms.util.CmsUUID) */ @Override public void focus(CmsUUID cmsUUID) { try { CmsObject cms = A_CmsUI.getCmsObject(); CmsResource res = cms.readResource(cmsUUID, CmsResourceFilter.ALL); String rootPath = res.getRootPath(); String siteRoot = OpenCms.getSiteManager().getSiteRoot(rootPath); String sitePath = null; if (siteRoot == null) { if (OpenCms.getSiteManager().startsWithShared(rootPath)) { siteRoot = OpenCms.getSiteManager().getSharedFolder(); sitePath = CmsResource.getParentFolder( rootPath.substring(OpenCms.getSiteManager().getSharedFolder().length())); } else { sitePath = CmsResource.getParentFolder(rootPath); siteRoot = ""; } } else { CmsObject otherSiteCms = OpenCms.initCmsObject(cms); otherSiteCms.getRequestContext().setSiteRoot(siteRoot); sitePath = otherSiteCms.getRequestContext().removeSiteRoot(CmsResource.getParentFolder(rootPath)); } m_explorer.changeSite(siteRoot, sitePath, true); } catch (CmsException e) { CmsErrorDialog.showErrorDialog(e); } }
/** * Returns the no preview reason if there is any.<p> * * @param cms the current cms context * @param resource the resource to check * * @return the no preview reason if there is any */ public static String getNoPreviewReason(CmsObject cms, CmsResource resource) { Locale locale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms); String noPreviewReason = null; if (resource.getState().isDeleted() && !(resource instanceof I_CmsHistoryResource)) { noPreviewReason = Messages.get().getBundle(locale).key(Messages.GUI_NO_PREVIEW_DELETED_0); } else if (resource.isFolder()) { noPreviewReason = Messages.get().getBundle(locale).key(Messages.GUI_NO_PREVIEW_FOLDER_0); } else { String siteRoot = OpenCms.getSiteManager().getSiteRoot(resource.getRootPath()); // previewing only resources that are in the same site or don't have a site root at all if ((siteRoot != null) && !siteRoot.equals(cms.getRequestContext().getSiteRoot())) { noPreviewReason = Messages.get().getBundle(locale).key(Messages.GUI_NO_PREVIEW_OTHER_SITE_0); } else if (resource.getTypeId() == CmsResourceTypeBinary.getStaticTypeId()) { String mimeType = OpenCms.getResourceManager().getMimeType(resource.getName(), null, "empty"); if (!m_previewMimeTypes.contains(mimeType)) { noPreviewReason = Messages.get().getBundle(locale).key(Messages.GUI_NO_PREVIEW_WRONG_MIME_TYPE_0); } } } return noPreviewReason; }
/** * Returns <code>true</code> if the given resource is editable by the current user.<p> * * Returns <code>false</code> if no request context is set.<p> * * @return <code>true</code> if the given resource is editable by the current user */ public boolean isEditable() { if (m_request == null) { return false; } CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(getResourceTypeName()); if (settings != null) { String rightSite = OpenCms.getSiteManager().getSiteRoot(getResource().getRootPath()); if (rightSite == null) { rightSite = ""; } String currentSite = getCms().getRequestContext().getSiteRoot(); try { getCms().getRequestContext().setSiteRoot(rightSite); return settings.isEditable(getCms(), getResource()); } finally { getCms().getRequestContext().setSiteRoot(currentSite); } } return false; }
/** * Returns <code>true</code> if the given resource is editable by the current user.<p> * * Returns <code>false</code> if no request context is set.<p> * * @return <code>true</code> if the given resource is editable by the current user */ public boolean isEditable() { if (m_request == null) { return false; } CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(getResourceTypeName()); if (settings != null) { String rightSite = OpenCms.getSiteManager().getSiteRoot(getResource().getRootPath()); if (rightSite == null) { rightSite = ""; } String currentSite = getCms().getRequestContext().getSiteRoot(); try { getCms().getRequestContext().setSiteRoot(rightSite); return settings.isEditable(getCms(), getResource()); } finally { getCms().getRequestContext().setSiteRoot(currentSite); } } return false; }