/** * Converts a path to a normalized form.<p> * * @param path the path to normalize * * @return the normalized path */ protected String normalizePath(String path) { if (path.equals("/")) { return path; } else { return CmsFileUtil.removeTrailingSeparator(path); } } }
/** * Normalizes a given OU name.<p> * * @param ou the OU name * @return the normalized version */ String normalizeOuName(String ou) { ou = CmsFileUtil.removeLeadingSeparator(ou); ou = CmsFileUtil.removeTrailingSeparator(ou); return ou; }
/** * Gets the site which is mapped to the default uri, or the 'absent' value of no such site exists.<p> * * @return the optional site mapped to the default uri */ public Optional<CmsSite> getSiteForDefaultUri() { String defaultUri = getDefaultUri(); CmsSite candidate = m_siteRootSites.get(CmsFileUtil.removeTrailingSeparator(defaultUri)); return Optional.fromNullable(candidate); }
/** * Adds an URL bean to the internal map of results, but only if there is no existing entry with higher internal priority * than the priority given as an argument.<p> * * @param result the result URL bean to add * * @param resultPriority the internal priority to use for updating the map of results */ protected void addResult(CmsXmlSitemapUrlBean result, int resultPriority) { String url = CmsFileUtil.removeTrailingSeparator(result.getUrl()); boolean writeEntry = true; if (m_resultMap.containsKey(url)) { LOG.warn("Encountered duplicate URL with while generating sitemap: " + result.getUrl()); ResultEntry entry = m_resultMap.get(url); writeEntry = entry.getPriority() <= resultPriority; } if (writeEntry) { m_resultMap.put(url, new ResultEntry(result, resultPriority)); } }
/** * Gets the types for which a given resource is configured as a detail page.<p> * * @param resource a resource for which we want to find the detail page types * * @return the list of resource types for which the given page is configured as a detail page */ protected List<I_CmsResourceType> getDetailTypesForPage(CmsResource resource) { Collection<String> typesForPage = m_detailTypesByPage.get(resource.getRootPath()); String parentPath = CmsFileUtil.removeTrailingSeparator(CmsResource.getParentFolder(resource.getRootPath())); Collection<String> typesForFolder = m_detailTypesByPage.get(parentPath); Set<String> allTypes = new HashSet<String>(); allTypes.addAll(typesForPage); allTypes.addAll(typesForFolder); List<I_CmsResourceType> resTypes = new ArrayList<I_CmsResourceType>(); CmsResourceManager resMan = OpenCms.getResourceManager(); for (String typeName : allTypes) { try { I_CmsResourceType resType = resMan.getResourceType(typeName); resTypes.add(resType); } catch (CmsLoaderException e) { LOG.warn("Invalid resource type name" + typeName + "! " + e.getLocalizedMessage(), e); } } return resTypes; }
/** * Gets all resources from the folder tree beneath the base folder or the shared folder which have a given type.<p> * * @param type the type to filter by * * @return the list of resources with the given type * * @throws CmsException if something goes wrong */ private List<CmsResource> getDetailResources(I_CmsResourceType type) throws CmsException { String typeName = type.getTypeName(); if (!m_detailResources.containsKey(typeName)) { List<CmsResource> result = new ArrayList<CmsResource>(); CmsResourceFilter filter = CmsResourceFilter.DEFAULT_FILES.addRequireType(type); List<CmsResource> siteFiles = m_guestCms.readResources(m_siteRoot, filter, true); result.addAll(siteFiles); String shared = CmsFileUtil.removeTrailingSeparator(OpenCms.getSiteManager().getSharedFolder()); if (shared != null) { List<CmsResource> sharedFiles = m_guestCms.readResources(shared, filter, true); result.addAll(sharedFiles); } m_detailResources.put(typeName, result); } return m_detailResources.get(typeName); }
/** * Reads the resources in a subtree.<p> * * @param rootPath the root of the subtree * * @return the list of resources from the subtree * * @throws CmsException if something goes wrong */ 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; }
/** * Reads the contents of a given type and stores them in a path map.<p> * * @param type the type for which to read the contents * @return the path map containing the contents */ private CmsPathMap<CmsResource> readPathMapForType(I_CmsResourceType type) { List<CmsResource> result = new ArrayList<CmsResource>(); CmsResourceFilter filter = CmsResourceFilter.DEFAULT_FILES.addRequireType(type); try { List<CmsResource> siteFiles = m_guestCms.readResources(m_siteRoot, filter, true); result.addAll(siteFiles); } catch (CmsException e) { LOG.error("XML sitemap generator error: " + e.getLocalizedMessage(), e); } String shared = CmsFileUtil.removeTrailingSeparator(OpenCms.getSiteManager().getSharedFolder()); if (shared != null) { try { List<CmsResource> sharedFiles = m_guestCms.readResources(shared, filter, true); result.addAll(sharedFiles); } catch (CmsException e) { LOG.error("XML sitemap generator error: " + e.getLocalizedMessage(), e); } } CmsPathMap<CmsResource> resultMap = new CmsPathMap<CmsResource>(); for (CmsResource resource : result) { resultMap.add(resource.getRootPath(), resource); } return resultMap; }
/** * Reads the data necessary for building the sitemap from the VFS and initializes the internal data structures.<p> * * @param baseSitePath the base site path * * @throws CmsException if something goes wrong */ private void initializeFileData(String baseSitePath) throws CmsException { m_resultMap.clear(); m_siteRootLink = OpenCms.getLinkManager().getOnlineLink(m_siteGuestCms, "/"); m_siteRootLink = CmsFileUtil.removeTrailingSeparator(m_siteRootLink); m_detailPageInfos = OpenCms.getADEManager().getAllDetailPages(m_guestCms); for (CmsDetailPageInfo detailPageInfo : m_detailPageInfos) { String type = detailPageInfo.getType(); String path = detailPageInfo.getUri(); path = CmsFileUtil.removeTrailingSeparator(path); m_detailTypesByPage.put(path, type); } List<CmsAlias> siteAliases = OpenCms.getAliasManager().getAliasesForSite( m_siteGuestCms, m_siteGuestCms.getRequestContext().getSiteRoot()); for (CmsAlias alias : siteAliases) { if (isAliasBelowBaseFolder(alias) && (alias.getMode() == CmsAliasMode.page)) { CmsUUID aliasId = alias.getStructureId(); m_pageAliasesBelowBaseFolderByStructureId.put(aliasId, alias); } } }
/** * @see org.opencms.db.I_CmsVfsDriver#readFolder(org.opencms.db.CmsDbContext, CmsUUID, java.lang.String) */ public CmsFolder readFolder(CmsDbContext dbc, CmsUUID projectId, String folderPath) throws CmsDataAccessException { CmsFolder folder = null; folderPath = CmsFileUtil.removeTrailingSeparator(folderPath); try { Query q = m_sqlManager.createQuery(dbc, projectId, C_RESOURCES_READ); q.setParameter(1, folderPath); try { Object[] o = (Object[])q.getSingleResult(); folder = createFolder(o, projectId, true); } catch (NoResultException e) { throw new CmsVfsResourceNotFoundException( Messages.get().container(Messages.ERR_READ_FOLDER_1, dbc.removeSiteRoot(folderPath))); } } catch (PersistenceException e) { throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e); } return folder; }
Connection conn = null; folderPath = CmsFileUtil.removeTrailingSeparator(folderPath); try { conn = m_sqlManager.getConnection(dbc);
Connection conn = null; folderPath = CmsFileUtil.removeTrailingSeparator(folderPath); try { conn = m_sqlManager.getConnection(dbc);
parent = CmsFileUtil.removeTrailingSeparator(parent);
/** * Writes the XML sitemap to the response.<p> * * @throws Exception if something goes wrong */ public void renderXmlSitemap() throws Exception { CmsObject cms = getCmsObject(); String baseFolderRootPath = CmsFileUtil.removeTrailingSeparator( CmsResource.getParentFolder(cms.getRequestContext().addSiteRoot(cms.getRequestContext().getUri()))); CmsXmlSitemapGenerator xmlSitemapGenerator = createSitemapGenerator( m_configuration.getSitemapGeneratorClassName(), baseFolderRootPath); xmlSitemapGenerator.setComputeContainerPageDates(m_configuration.shouldComputeContainerPageModificationDates()); CmsPathIncludeExcludeSet inexcludeSet = xmlSitemapGenerator.getIncludeExcludeSet(); for (String include : m_configuration.getIncludes()) { inexcludeSet.addInclude(include); } for (String exclude : m_configuration.getExcludes()) { inexcludeSet.addExclude(exclude); } xmlSitemapGenerator.setServerUrl(m_configuration.getServerUrl()); String xmlSitemap = xmlSitemapGenerator.renderSitemap(); getResponse().getWriter().print(xmlSitemap); }
path = CmsFileUtil.removeTrailingSeparator(path); boolean endsWithSlash = path.endsWith("/");
/** * Creates a new sitemap generator instance.<p> * * @param folderRootPath the root folder for the XML sitemap to generate * * @throws CmsException if something goes wrong */ public CmsXmlSitemapGenerator(String folderRootPath) throws CmsException { m_baseFolderRootPath = CmsFileUtil.removeTrailingSeparator(folderRootPath); m_guestCms = OpenCms.initCmsObject(OpenCms.getDefaultUsers().getUserGuest()); m_siteGuestCms = OpenCms.initCmsObject(m_guestCms); CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(CmsStringUtil.joinPaths(folderRootPath, "/")); m_siteRoot = site.getSiteRoot(); m_siteGuestCms.getRequestContext().setSiteRoot(m_siteRoot); m_baseFolderSitePath = CmsStringUtil.joinPaths( "/", m_siteGuestCms.getRequestContext().removeSiteRoot(m_baseFolderRootPath)); }
/** * Adds the detail page links for a given page to the results.<p> * * @param containerPage the container page resource * @param locale the locale of the container page * * @throws CmsException if something goes wrong */ protected void addDetailLinks(CmsResource containerPage, Locale locale) throws CmsException { List<I_CmsResourceType> types = getDetailTypesForPage(containerPage); for (I_CmsResourceType type : types) { List<CmsResource> resourcesForType = getDetailResources(type); for (CmsResource detailRes : resourcesForType) { if (!isValidDetailPageCombination(containerPage, locale, detailRes)) { continue; } List<CmsProperty> detailProps = m_guestCms.readPropertyObjects(detailRes, true); String detailLink = getDetailLink(containerPage, detailRes, locale); detailLink = CmsFileUtil.removeTrailingSeparator(detailLink); CmsXmlSitemapUrlBean detailUrlBean = new CmsXmlSitemapUrlBean( replaceServerUri(detailLink), detailRes.getDateLastModified(), getChangeFrequency(detailProps), getPriority(detailProps)); detailUrlBean.setOriginalResource(detailRes); detailUrlBean.setDetailPageResource(containerPage); addResult(detailUrlBean, 2); } } }
/** * @see org.opencms.ade.sitemap.shared.rpc.I_CmsSitemapService#savePropertiesForLocaleCompareMode(org.opencms.util.CmsUUID, java.lang.String, java.util.List, boolean) */ public void savePropertiesForLocaleCompareMode( CmsUUID id, String newUrlName, List<CmsPropertyModification> propertyChanges, boolean editedName) throws CmsRpcException { try { CmsObject cms = getCmsObject(); CmsResource ownRes = cms.readResource(id, CmsResourceFilter.IGNORE_EXPIRATION); CmsResource defaultFileRes = cms.readDefaultFile("" + id); try (Closeable c = CmsLockUtil.withLockedResources(cms, ownRes)) { updateProperties(cms, ownRes, defaultFileRes, propertyChanges); if (editedName) { String parent = CmsResource.getParentFolder(ownRes.getRootPath()); newUrlName = CmsFileUtil.removeTrailingSeparator(newUrlName); String newPath = CmsStringUtil.joinPaths(parent, newUrlName); CmsObject rootCms = OpenCms.initCmsObject(cms); rootCms.getRequestContext().setSiteRoot(""); rootCms.moveResource(ownRes.getRootPath(), newPath); } } } catch (Exception e) { error(e); } }
/** * @see org.opencms.site.xmlsitemap.CmsXmlSitemapGenerator#addDetailLinks(org.opencms.file.CmsResource, java.util.Locale) */ @Override protected void addDetailLinks(CmsResource containerPage, Locale locale) throws CmsException { Collection<DetailInfo> detailInfos = getDetailInfosForPage(containerPage); for (DetailInfo info : detailInfos) { List<CmsResource> contents = getContents(info.getFolderPath(), info.getType()); for (CmsResource detailRes : contents) { List<CmsProperty> detailProps = m_guestCms.readPropertyObjects(detailRes, true); String detailLink = getDetailLink(containerPage, detailRes, locale); detailLink = CmsFileUtil.removeTrailingSeparator(detailLink); CmsXmlSitemapUrlBean detailUrlBean = new CmsXmlSitemapUrlBean( replaceServerUri(detailLink), detailRes.getDateLastModified(), getChangeFrequency(detailProps), getPriority(detailProps)); detailUrlBean.setLocale(locale); detailUrlBean.setOriginalResource(detailRes); detailUrlBean.setDetailPageResource(containerPage); detailUrlBean.setSubsite(info.getBasePath()); addResult(detailUrlBean, 2); } } }
result.setInheritedProperties(createClientProperties(cms.readPropertyObjects(parent, true), true)); result.setPath(resource.getRootPath()); String name = CmsFileUtil.removeTrailingSeparator(CmsResource.getName(resource.getRootPath())); result.setName(name); result.setHasEditableName(!CmsStringUtil.isEmptyOrWhitespaceOnly(name));