Revision: 29301 Author: wko Date: 2011-08-04 00:40:20 +0200 (Thu, 04 Aug 2011) Log Message: ----------- HSTTWO-1618: (backporting from trunk) Allowing to use either sitemapitem refid or sitemapitem path for properties: hst:homepage and hst:pagenotfound
Modified Paths: -------------- hippo-cms7/site-toolkit/branches/hst-2.22.xx/client/src/main/java/org/hippoecm/hst/tag/HstLinkTag.java hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/core/linking/DefaultHstLinkCreator.java hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/core/sitemenu/HstSiteMenuItemImpl.java hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/site/request/ResolvedMountImpl.java hippo-cms7/site-toolkit/branches/hst-2.22.xx/demosuite/content/src/main/resources/hst-virtualhosts.xml hippo-cms7/site-toolkit/branches/hst-2.22.xx/demosuite/content/src/main/resources/hstconfiguration/demosite_fr/sitemap.xml Added Paths: ----------- hippo-cms7/site-toolkit/branches/hst-2.22.xx/commons/src/main/java/org/hippoecm/hst/util/HstSiteMapUtils.java Removed Paths: ------------- hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/core/util/HstSiteMapUtils.java Modified: hippo-cms7/site-toolkit/branches/hst-2.22.xx/client/src/main/java/org/hippoecm/hst/tag/HstLinkTag.java =================================================================== --- hippo-cms7/site-toolkit/branches/hst-2.22.xx/client/src/main/java/org/hippoecm/hst/tag/HstLinkTag.java 2011-08-03 22:10:55 UTC (rev 29300) +++ hippo-cms7/site-toolkit/branches/hst-2.22.xx/client/src/main/java/org/hippoecm/hst/tag/HstLinkTag.java 2011-08-03 22:40:20 UTC (rev 29301) @@ -41,6 +41,7 @@ import org.hippoecm.hst.core.request.HstRequestContext; import org.hippoecm.hst.core.request.ResolvedVirtualHost; import org.hippoecm.hst.util.HstRequestUtils; +import org.hippoecm.hst.util.HstSiteMapUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -184,11 +185,12 @@ Mount mount = null; if(mountAlias != null) { - mount = reqContext.getMount(mountAlias); - if(mount == null) { - log.warn("Cannot resolve mount with alias '{}' for current request. Cannot create a link for '{}'. Return page not found Link for current Mount", mountAlias, path); - this.link = reqContext.getHstLinkCreator().create(reqContext.getResolvedMount().getMount().getPageNotFound(), reqContext.getResolvedMount().getMount()); - } + mount = reqContext.getMount(mountAlias); + if(mount == null) { + log.warn("Cannot resolve mount with alias '{}' for current request. Cannot create a link for '{}'. Return page not found Link for current Mount", mountAlias, path); + Mount requestedMount = reqContext.getResolvedMount().getMount(); + this.link = reqContext.getHstLinkCreator().create(HstSiteMapUtils.getPath(requestedMount, requestedMount.getPageNotFound()), requestedMount); + } } else { mount = reqContext.getResolvedMount().getMount(); } Added: hippo-cms7/site-toolkit/branches/hst-2.22.xx/commons/src/main/java/org/hippoecm/hst/util/HstSiteMapUtils.java =================================================================== --- hippo-cms7/site-toolkit/branches/hst-2.22.xx/commons/src/main/java/org/hippoecm/hst/util/HstSiteMapUtils.java (rev 0) +++ hippo-cms7/site-toolkit/branches/hst-2.22.xx/commons/src/main/java/org/hippoecm/hst/util/HstSiteMapUtils.java 2011-08-03 22:40:20 UTC (rev 29301) @@ -0,0 +1,113 @@ +/* + * Copyright 2008 Hippo. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hippoecm.hst.util; + +import org.hippoecm.hst.configuration.hosting.Mount; +import org.hippoecm.hst.configuration.sitemap.HstSiteMapItem; + +public class HstSiteMapUtils { + + private HstSiteMapUtils() { + + } + + /** + * Returns string representation of the sitemap item path + * @param siteMapItem + * @return String representation of the path + */ + public static String getPath(HstSiteMapItem siteMapItem) { + StringBuilder path = new StringBuilder(siteMapItem.getValue()); + + while (siteMapItem.getParentItem() != null) { + siteMapItem = siteMapItem.getParentItem(); + path.insert(0, "/").insert(0, siteMapItem.getValue()); + } + + return path.toString(); + } + + /** + * Returns string representation of the child sitemap item specified by the relPath from the specified sitemap item + * @param siteMapItem + * @param relPath + * @return String representation of the path + */ + public static String getPath(HstSiteMapItem siteMapItem, String relPath) { + StringBuilder path = new StringBuilder(siteMapItem.getValue()); + + while (siteMapItem.getParentItem() != null) { + siteMapItem = siteMapItem.getParentItem(); + path.insert(0, "/").insert(0, siteMapItem.getValue()); + } + + if (relPath == null) { + return path.toString(); + } + + if (relPath.startsWith("/")) { + path.append(relPath); + } else { + path.append("/").append(relPath); + } + + return path.toString(); + } + + /** + * Returns string representation of the sitemap item which is specified by either refId or path. + * If <CODE>refIdOrPath</CODE> doesn't represent a refId, then it returns the <CODE>refIdOrPath</CODE> as sitemap item path. + * @param mount + * @param refIdOrPath + * @return + */ + public static String getPath(Mount mount, String refIdOrPath) { + if (refIdOrPath == null) { + return null; + } + + HstSiteMapItem siteMapItemByRefId = mount.getHstSite().getSiteMap().getSiteMapItemByRefId(refIdOrPath); + + if (siteMapItemByRefId != null) { + return getPath(siteMapItemByRefId); + } + + return refIdOrPath; + } + + /** + * Returns string representation of the sitemap item which is specified by either refId or path + * If <CODE>refIdOrRelPath</CODE> doesn't represent a refId, then its return will be equivalent to {@link #getPath(HstSiteMapItem siteMapItem, String relPath)}. + * @param mount + * @param refIdOrPath + * @return + */ + public static String getPath(Mount mount, HstSiteMapItem siteMapItem, String refIdOrRelPath) { + if (refIdOrRelPath != null) { + HstSiteMapItem siteMapItemByRefId = mount.getHstSite().getSiteMap().getSiteMapItemByRefId(refIdOrRelPath); + + if (siteMapItemByRefId != null) { + return getPath(siteMapItemByRefId); + } + } + + if (siteMapItem == null) { + return null; + } + + return getPath(siteMapItem, refIdOrRelPath); + } +} Modified: hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/core/linking/DefaultHstLinkCreator.java =================================================================== --- hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/core/linking/DefaultHstLinkCreator.java 2011-08-03 22:10:55 UTC (rev 29300) +++ hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/core/linking/DefaultHstLinkCreator.java 2011-08-03 22:40:20 UTC (rev 29301) @@ -33,7 +33,7 @@ import org.hippoecm.hst.core.request.HstRequestContext; import org.hippoecm.hst.core.request.ResolvedSiteMapItem; import org.hippoecm.hst.provider.jcr.JCRUtilities; -import org.hippoecm.hst.core.util.HstSiteMapUtils; +import org.hippoecm.hst.util.HstSiteMapUtils; import org.hippoecm.hst.util.PathUtils; import org.hippoecm.repository.api.HippoNodeType; import org.slf4j.Logger; @@ -460,14 +460,14 @@ if(!virtual && nodePath.equals(mount.getCanonicalContentPath())) { // the root node of the site. Return the homepage - return new HstLinkImpl(mount.getHomePage(), mount); + return new HstLinkImpl(HstSiteMapUtils.getPath(mount, mount.getHomePage()), mount); } if(!virtual && nodePath.startsWith(mount.getCanonicalContentPath() + "/")) { nodePath = nodePath.substring(mount.getCanonicalContentPath().length()); matchedMount = true; } else if (virtual && nodePath.equals(mount.getContentPath())) { // the root node of the site. Return the homepage - return new HstLinkImpl(mount.getHomePage(), mount); + return new HstLinkImpl(HstSiteMapUtils.getPath(mount, mount.getHomePage()), mount); } else if (virtual && nodePath.startsWith(mount.getContentPath() + "/")) { nodePath = nodePath.substring(mount.getContentPath().length()); matchedMount = true; @@ -542,7 +542,7 @@ if(nodePath.equals("")) { // the root node of the found mount. Return the homepage for this mount - return new HstLinkImpl(mount.getHomePage(), mount); + return new HstLinkImpl(HstSiteMapUtils.getPath(mount, mount.getHomePage()), mount); } matchedMount = true; Modified: hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/core/sitemenu/HstSiteMenuItemImpl.java =================================================================== --- hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/core/sitemenu/HstSiteMenuItemImpl.java 2011-08-03 22:10:55 UTC (rev 29300) +++ hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/core/sitemenu/HstSiteMenuItemImpl.java 2011-08-03 22:40:20 UTC (rev 29301) @@ -29,8 +29,8 @@ import org.hippoecm.hst.core.linking.HstLinkCreator; import org.hippoecm.hst.core.request.HstRequestContext; import org.hippoecm.hst.core.request.ResolvedSiteMapItem; -import org.hippoecm.hst.core.util.HstSiteMapUtils; import org.hippoecm.hst.core.util.PropertyParser; +import org.hippoecm.hst.util.HstSiteMapUtils; import org.hippoecm.hst.util.PathUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; Deleted: hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/core/util/HstSiteMapUtils.java =================================================================== --- hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/core/util/HstSiteMapUtils.java 2011-08-03 22:10:55 UTC (rev 29300) +++ hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/core/util/HstSiteMapUtils.java 2011-08-03 22:40:20 UTC (rev 29301) @@ -1,62 +0,0 @@ -/* - * Copyright 2008 Hippo. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.hippoecm.hst.core.util; - -import org.hippoecm.hst.configuration.sitemap.HstSiteMapItem; - -public class HstSiteMapUtils { - - private HstSiteMapUtils() { - - } - - /** - * @param siteMapItem - * @return String representation of the path - */ - public static String getPath(HstSiteMapItem siteMapItem) { - StringBuilder path = new StringBuilder(siteMapItem.getValue()); - - while (siteMapItem.getParentItem() != null) { - siteMapItem = siteMapItem.getParentItem(); - path.insert(0, "/").insert(0, siteMapItem.getValue()); - } - - return path.toString(); - } - - public static String getPath(HstSiteMapItem siteMapItem, String relPath) { - StringBuilder path = new StringBuilder(siteMapItem.getValue()); - - while (siteMapItem.getParentItem() != null) { - siteMapItem = siteMapItem.getParentItem(); - path.insert(0, "/").insert(0, siteMapItem.getValue()); - } - - if (relPath == null) { - return path.toString(); - } - - if (relPath.startsWith("/")) { - path.append(relPath); - } else { - path.append("/").append(relPath); - } - - return path.toString(); - } - -} Modified: hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/site/request/ResolvedMountImpl.java =================================================================== --- hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/site/request/ResolvedMountImpl.java 2011-08-03 22:10:55 UTC (rev 29300) +++ hippo-cms7/site-toolkit/branches/hst-2.22.xx/components/core/src/main/java/org/hippoecm/hst/site/request/ResolvedMountImpl.java 2011-08-03 22:40:20 UTC (rev 29301) @@ -24,6 +24,7 @@ import org.hippoecm.hst.core.request.ResolvedSiteMapItem; import org.hippoecm.hst.core.request.ResolvedMount; import org.hippoecm.hst.core.request.ResolvedVirtualHost; +import org.hippoecm.hst.util.HstSiteMapUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,7 +71,7 @@ if("".equals(siteMapPathInfo) || "/".equals(siteMapPathInfo)) { log.debug("siteMapPathInfo is '' or '/'. If there is a homepage path configured, we try to map this path to the sitemap"); - siteMapPathInfo = mount.getHomePage(); + siteMapPathInfo = HstSiteMapUtils.getPath(mount, mount.getHomePage()); if(siteMapPathInfo == null || "".equals(siteMapPathInfo) || "/".equals(siteMapPathInfo)) { log.warn("Mount '{}' for host '{}' does not have a homepage configured and the path info is empty. Cannot map to sitemap item. Return null", getMount().getName(), getResolvedVirtualHost().getResolvedHostName()); throw new MatchException("No homepage configured and empty path after Mount"); @@ -88,7 +89,7 @@ item = matcher.match(siteMapPathInfo, this); } catch(NotFoundException e){ log.debug("Cannot match '{}'. Try getting the pagenotfound", siteMapPathInfo); - String pageNotFound = mount.getPageNotFound(); + String pageNotFound = HstSiteMapUtils.getPath(mount, mount.getPageNotFound()); if(pageNotFound == null) { throw new MatchException("There is no pagenotfound configured for '"+mount.getName()+"'"); } Modified: hippo-cms7/site-toolkit/branches/hst-2.22.xx/demosuite/content/src/main/resources/hst-virtualhosts.xml =================================================================== --- hippo-cms7/site-toolkit/branches/hst-2.22.xx/demosuite/content/src/main/resources/hst-virtualhosts.xml 2011-08-03 22:10:55 UTC (rev 29300) +++ hippo-cms7/site-toolkit/branches/hst-2.22.xx/demosuite/content/src/main/resources/hst-virtualhosts.xml 2011-08-03 22:40:20 UTC (rev 29301) @@ -465,10 +465,10 @@ <sv:value>fr_FR</sv:value> </sv:property> <sv:property sv:name="hst:homepage" sv:type="String"> - <sv:value>accueil</sv:value> + <sv:value>home</sv:value> </sv:property> <sv:property sv:name="hst:pagenotfound" sv:type="String"> - <sv:value>erreur</sv:value> + <sv:value>error</sv:value> </sv:property> </sv:node> <sv:node sv:name="restapi"> Modified: hippo-cms7/site-toolkit/branches/hst-2.22.xx/demosuite/content/src/main/resources/hstconfiguration/demosite_fr/sitemap.xml =================================================================== --- hippo-cms7/site-toolkit/branches/hst-2.22.xx/demosuite/content/src/main/resources/hstconfiguration/demosite_fr/sitemap.xml 2011-08-03 22:10:55 UTC (rev 29300) +++ hippo-cms7/site-toolkit/branches/hst-2.22.xx/demosuite/content/src/main/resources/hstconfiguration/demosite_fr/sitemap.xml 2011-08-03 22:40:20 UTC (rev 29301) @@ -31,13 +31,16 @@ <sv:value>about</sv:value> </sv:property> </sv:node> - <sv:node sv:name="error"> + <sv:node sv:name="erreur"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> <sv:value>hst:sitemapitem</sv:value> </sv:property> <sv:property sv:name="hst:componentconfigurationid" sv:type="String"> <sv:value>hst:pages/errorpage</sv:value> </sv:property> + <sv:property sv:name="hst:refId" sv:type="String"> + <sv:value>error</sv:value> + </sv:property> </sv:node> <sv:node sv:name="_any_"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> _______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.hippocms.org http://lists.hippo.nl/mailman/listinfo/hippocms-svn