Ard Schrijvers pushed to branch release/3.2 at cms / hippo-site-toolkit
Commits: f88bdb56 by Ard Schrijvers at 2016-02-15T10:47:50+01:00 HSTTWO-3593 [Backport 3.2.1] Support nodeId atttribute in hst:link tag applied patch from Woonsan with some small modifations - - - - - 2 changed files: - client/src/main/java/org/hippoecm/hst/tag/HstLinkTag.java - client/src/main/resources/META-INF/hst-core.tld Changes: ===================================== client/src/main/java/org/hippoecm/hst/tag/HstLinkTag.java ===================================== --- a/client/src/main/java/org/hippoecm/hst/tag/HstLinkTag.java +++ b/client/src/main/java/org/hippoecm/hst/tag/HstLinkTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 Hippo B.V. (http://www.onehippo.com) + * Copyright 2010-2016 Hippo B.V. (http://www.onehippo.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package org.hippoecm.hst.tag; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -36,6 +35,7 @@ import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.hippoecm.hst.configuration.hosting.Mount; import org.hippoecm.hst.configuration.sitemap.HstSiteMapItem; +import org.hippoecm.hst.content.beans.ObjectBeanManagerException; import org.hippoecm.hst.content.beans.standard.HippoBean; import org.hippoecm.hst.content.beans.standard.IdentifiableContentBean; import org.hippoecm.hst.core.linking.HstLink; @@ -59,11 +59,14 @@ public class HstLinkTag extends ParamContainerTag { private final static Logger log = LoggerFactory.getLogger(HstLinkTag.class); private static final long serialVersionUID = 1L; + public static final String UNALLOWED_ATTR_COMBINATION_MSG = "Incorrect usage of hst:link tag. Not allowed to specifcy two of the attributes 'link', 'hippobean', 'path', nodeId or 'siteMapItemRefId' at same time."; protected HstLink link; protected IdentifiableContentBean identifiableContentBean; + protected String nodeId; + protected String path; protected String siteMapItemRefId; @@ -157,6 +160,15 @@ public class HstLinkTag extends ParamContainerTag { } } + if (hippoBean == null && nodeId != null) { + try { + hippoBean = (HippoBean) reqContext.getObjectBeanManager().getObjectByUuid(nodeId); + } catch (ObjectBeanManagerException e) { + log.warn("Cannot find content bean by id: '{}'.", nodeId); + return EVAL_PAGE; + } + } + if(linkForAttributeSet) { if(link == null && path == null && hippoBean == null && siteMapItemRefId == null) { String dispatcher = (String)servletRequest.getAttribute("javax.servlet.include.servlet_path"); @@ -346,6 +358,7 @@ public class HstLinkTag extends ParamContainerTag { super.cleanup(); var = null; identifiableContentBean = null; + nodeId = null; scope = null; path = null; siteMapItemRefId = null; @@ -392,6 +405,10 @@ public class HstLinkTag extends ParamContainerTag { return this.identifiableContentBean; } + public String getNodeId(){ + return this.nodeId; + } + public String getPath(){ return path; } @@ -410,7 +427,7 @@ public class HstLinkTag extends ParamContainerTag { public void setLink(HstLink hstLink) { if(linkForAttributeSet) { - log.warn("Incorrect usage of hst:link tag. Not allowed to specifcy two of the attributes 'link', 'hippobean', 'path' or 'siteMapItemRefId' at same time. Ignore the attr link '{}'", link); + log.warn(UNALLOWED_ATTR_COMBINATION_MSG + " Ignore the attr link '{}'", link); return; } linkForAttributeSet = true; @@ -427,7 +444,7 @@ public class HstLinkTag extends ParamContainerTag { public void setPath(String path) { if(linkForAttributeSet) { - log.warn("Incorrect usage of hst:link tag. Not allowed to specifcy two of the attributes 'link', 'hippobean', 'path' or 'siteMapItemRefId' at same time. Ignore the attr path '{}'", path); + log.warn(UNALLOWED_ATTR_COMBINATION_MSG + " Ignore the attr path '{}'", path); return; } linkForAttributeSet = true; @@ -436,7 +453,7 @@ public class HstLinkTag extends ParamContainerTag { public void setSiteMapItemRefId(String siteMapItemRefId) { if(linkForAttributeSet) { - log.warn("Incorrect usage of hst:link tag. Not allowed to specifcy two of the attributes 'link', 'hippobean', 'path' or 'siteMapItemRefId' at same time. Ignore the attr siteMapItemRefId '{}'", siteMapItemRefId); + log.warn(UNALLOWED_ATTR_COMBINATION_MSG + " Ignore the attr siteMapItemRefId '{}'", siteMapItemRefId); return; } linkForAttributeSet = true; @@ -457,13 +474,22 @@ public class HstLinkTag extends ParamContainerTag { public void setHippobean(IdentifiableContentBean identifiableContentBean) { if(linkForAttributeSet) { - log.warn("Incorrect usage of hst:link tag. Not allowed to specifcy two of the attributes 'link', 'hippobean', 'path' or 'siteMapItemRefId' at same time. Ignore the attr identifiableContentBean '{}'", identifiableContentBean.getIdentifier()); + log.warn(UNALLOWED_ATTR_COMBINATION_MSG + " Ignore the attr identifiableContentBean '{}'", identifiableContentBean.getIdentifier()); return; } linkForAttributeSet = true; this.identifiableContentBean = identifiableContentBean; } - + + public void setNodeId(String nodeId) { + if(linkForAttributeSet) { + log.warn(UNALLOWED_ATTR_COMBINATION_MSG + " Ignore the attr nodeId '{}'", nodeId); + return; + } + linkForAttributeSet = true; + this.nodeId = nodeId; + } + public void setMount(String mount) { this.mountAlias = mount; } ===================================== client/src/main/resources/META-INF/hst-core.tld ===================================== --- a/client/src/main/resources/META-INF/hst-core.tld +++ b/client/src/main/resources/META-INF/hst-core.tld @@ -1,6 +1,6 @@ <?xml version="1.0" ?> <!-- - Copyright 2008-2015 Hippo B.V. (http://www.onehippo.com) + Copyright 2008-2016 Hippo B.V. (http://www.onehippo.com) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -332,6 +332,13 @@ <type>org.hippoecm.hst.content.beans.standard.IdentifiableContentBean</type> </attribute> <attribute> + <description>Identifier of an HippoBean object. This is a stringified identifier of one of your bean mapped objects</description> + <name>nodeId</name> + <required>false</required> + <rtexprvalue>true</rtexprvalue> + <type>java.lang.String</type> + </attribute> + <attribute> <description>A string id, which is the refId of a sitemap item you want to link to. Note that the sitemapitem belonging to the refId should not be a wildcard matcher, and non of its ancestors should be a wildcard. Using this to create a link to a sitemap item can be handy when you know to which sitemap item you want to link, but View it on GitLab: https://code.onehippo.org/cms/hippo-site-toolkit/commit/f88bdb56c7b712bc8b2ab283a0ae5ebc593b5341
_______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn