Class CmsJspTagLink

  • All Implemented Interfaces:
    java.io.Serializable, javax.servlet.jsp.tagext.BodyTag, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.Tag

    public class CmsJspTagLink
    extends javax.servlet.jsp.tagext.BodyTagSupport
    Implements the <cms:link>[filename]</cms:link> tag to add OpenCms managed links to a JSP page, required for link management and the static export to work properly.

    Since:
    6.0.0
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport

        bodyContent
      • Fields inherited from class javax.servlet.jsp.tagext.TagSupport

        id, pageContext
      • Fields inherited from interface javax.servlet.jsp.tagext.BodyTag

        EVAL_BODY_BUFFERED, EVAL_BODY_TAG
      • Fields inherited from interface javax.servlet.jsp.tagext.IterationTag

        EVAL_BODY_AGAIN
      • Fields inherited from interface javax.servlet.jsp.tagext.Tag

        EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
    • Constructor Summary

      Constructors 
      Constructor Description
      CmsJspTagLink()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int doEndTag()  
      java.lang.String getBaseUri()
      Returns the base URI used to create the link target.
      static java.util.Locale getBaseUriLocale​(CmsObject cms, java.lang.String baseUri)
      Tries to read the active locale for the given (site) path, or for its parent path if the path can't be read.
      java.lang.String getDetailPage()
      Returns the target detail page path.
      static java.lang.String linkTagAction​(java.lang.String target, javax.servlet.ServletRequest req)
      Returns a link to a file in the OpenCms VFS that has been adjusted according to the web application path and the OpenCms static export rules.
      static java.lang.String linkTagAction​(java.lang.String target, javax.servlet.ServletRequest req, java.lang.String baseUri)
      Returns a link to a file in the OpenCms VFS that has been adjusted according to the web application path and the OpenCms static export rules.
      static java.lang.String linkTagAction​(java.lang.String target, javax.servlet.ServletRequest req, java.lang.String baseUri, java.lang.String detailPage, java.util.Locale locale)
      Returns a link to a file in the OpenCms VFS that has been adjusted according to the web application path and the OpenCms static export rules.
      static java.lang.String linkTagAction​(java.lang.String target, javax.servlet.ServletRequest req, java.lang.String baseUri, java.util.Locale locale)
      Returns a link to a file in the OpenCms VFS that has been adjusted according to the web application path and the OpenCms static export rules.
      static java.lang.String linkTagAction​(CmsJspTagLink.Parameters params, javax.servlet.ServletRequest req)
      Returns a link to a file in the OpenCms VFS that has been adjusted according to the web application path and the OpenCms static export rules.
      void release()  
      void setBaseUri​(java.lang.String baseUri)
      Sets the base URI used to create the link target.
      void setDetailPage​(java.lang.String detailPage)
      Sets the target detail page path.
      void setLocale​(java.lang.String localeName)
      Sets the locale for the link to create.
      void setLocale​(java.util.Locale locale)
      Sets the locale to use for the link.
      void setScope​(java.lang.String scope)
      Sets the scope (only used in combination with the var parameter).
      void setType​(java.lang.String type)
      Sets the type.
      void setType​(CmsJspTagLink.Type type)
      Sets the type.
      void setVar​(java.lang.String var)
      Sets the variable name to store the result in.
      • Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport

        doAfterBody, doInitBody, doStartTag, getBodyContent, getPreviousOut, setBodyContent
      • Methods inherited from class javax.servlet.jsp.tagext.TagSupport

        findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface javax.servlet.jsp.tagext.Tag

        getParent, setPageContext, setParent
    • Method Detail

      • getBaseUriLocale

        public static java.util.Locale getBaseUriLocale​(CmsObject cms,
                                                        java.lang.String baseUri)
        Tries to read the active locale for the given (site) path, or for its parent path if the path can't be read.

        If this fails, null is returned.

        Parameters:
        cms - the CMS context
        baseUri - the base URI for which to read the locale
        Returns:
        the locale
      • linkTagAction

        public static java.lang.String linkTagAction​(CmsJspTagLink.Parameters params,
                                                     javax.servlet.ServletRequest req)
        Returns a link to a file in the OpenCms VFS that has been adjusted according to the web application path and the OpenCms static export rules.

        If the baseUri parameter is provided, this will be treated as the source of the link, if this is null then the current OpenCms user context URI will be used as source.

        If the locale parameter is provided, the locale in the request context will be switched to the provided locale. This influences only the behavior of the CmsLocalePrefixLinkSubstitutionHandler.

        Relative links are converted to absolute links, using the current element URI as base.

        Parameters:
        params - TODO
        req - the current request
        Returns:
        the target link adjusted according to the web application path and the OpenCms static export rules
        Since:
        8.0.3
        See Also:
        linkTagAction(String, ServletRequest)
      • linkTagAction

        public static java.lang.String linkTagAction​(java.lang.String target,
                                                     javax.servlet.ServletRequest req)
        Returns a link to a file in the OpenCms VFS that has been adjusted according to the web application path and the OpenCms static export rules.

        The current OpenCms user context URI will be used as source of the link.

        Since OpenCms version 7.0.2, you can also use this method in case you are not sure if the link is internal or external, as CmsLinkManager.substituteLinkForUnknownTarget(org.opencms.file.CmsObject, String) is used to calculate the link target.

        Relative links are converted to absolute links, using the current element URI as base.

        Parameters:
        target - the link that should be calculated, can be relative or absolute
        req - the current request
        Returns:
        the target link adjusted according to the web application path and the OpenCms static export rules
        See Also:
        CmsLinkManager.substituteLinkForUnknownTarget(org.opencms.file.CmsObject, String)
      • linkTagAction

        public static java.lang.String linkTagAction​(java.lang.String target,
                                                     javax.servlet.ServletRequest req,
                                                     java.lang.String baseUri)
        Returns a link to a file in the OpenCms VFS that has been adjusted according to the web application path and the OpenCms static export rules.

        If the baseUri parameter is provided, this will be treated as the source of the link, if this is null then the current OpenCms user context URI will be used as source.

        Relative links are converted to absolute links, using the current element URI as base.

        Parameters:
        target - the link that should be calculated, can be relative or absolute
        req - the current request
        baseUri - the base URI for the link source
        Returns:
        the target link adjusted according to the web application path and the OpenCms static export rules
        Since:
        8.0.3
        See Also:
        linkTagAction(String, ServletRequest)
      • linkTagAction

        public static java.lang.String linkTagAction​(java.lang.String target,
                                                     javax.servlet.ServletRequest req,
                                                     java.lang.String baseUri,
                                                     java.util.Locale locale)
        Returns a link to a file in the OpenCms VFS that has been adjusted according to the web application path and the OpenCms static export rules.

        If the baseUri parameter is provided, this will be treated as the source of the link, if this is null then the current OpenCms user context URI will be used as source.

        If the locale parameter is provided, the locale in the request context will be switched to the provided locale. This influences only the behavior of the CmsLocalePrefixLinkSubstitutionHandler.

        Relative links are converted to absolute links, using the current element URI as base.

        Parameters:
        target - the link that should be calculated, can be relative or absolute
        req - the current request
        baseUri - the base URI for the link source
        locale - the locale for which the link should be created (see CmsLocalePrefixLinkSubstitutionHandler
        Returns:
        the target link adjusted according to the web application path and the OpenCms static export rules
        Since:
        8.0.3
        See Also:
        linkTagAction(String, ServletRequest)
      • linkTagAction

        public static java.lang.String linkTagAction​(java.lang.String target,
                                                     javax.servlet.ServletRequest req,
                                                     java.lang.String baseUri,
                                                     java.lang.String detailPage,
                                                     java.util.Locale locale)
        Returns a link to a file in the OpenCms VFS that has been adjusted according to the web application path and the OpenCms static export rules.

        If the baseUri parameter is provided, this will be treated as the source of the link, if this is null then the current OpenCms user context URI will be used as source.

        If the locale parameter is provided, the locale in the request context will be switched to the provided locale. This influences only the behavior of the CmsLocalePrefixLinkSubstitutionHandler.

        Relative links are converted to absolute links, using the current element URI as base.

        Parameters:
        target - the link that should be calculated, can be relative or absolute
        req - the current request
        baseUri - the base URI for the link source
        detailPage - the target detail page, in case of linking to a specific detail page
        locale - the locale for which the link should be created (see CmsLocalePrefixLinkSubstitutionHandler
        Returns:
        the target link adjusted according to the web application path and the OpenCms static export rules
        Since:
        8.0.3
        See Also:
        linkTagAction(String, ServletRequest)
      • doEndTag

        public int doEndTag()
                     throws javax.servlet.jsp.JspException
        Specified by:
        doEndTag in interface javax.servlet.jsp.tagext.Tag
        Overrides:
        doEndTag in class javax.servlet.jsp.tagext.BodyTagSupport
        Returns:
        EVAL_PAGE
        Throws:
        javax.servlet.jsp.JspException - in case something goes wrong
        See Also:
        Tag.doEndTag()
      • getBaseUri

        public java.lang.String getBaseUri()
        Returns the base URI used to create the link target.

        Returns:
        the base URI used to create the link target
      • getDetailPage

        public java.lang.String getDetailPage()
        Returns the target detail page path.

        Returns:
        the target detail page path
      • release

        public void release()
        Specified by:
        release in interface javax.servlet.jsp.tagext.Tag
        Overrides:
        release in class javax.servlet.jsp.tagext.BodyTagSupport
        See Also:
        Tag.release()
      • setBaseUri

        public void setBaseUri​(java.lang.String baseUri)
        Sets the base URI used to create the link target.

        Parameters:
        baseUri - the base URI used to create the link target
      • setDetailPage

        public void setDetailPage​(java.lang.String detailPage)
        Sets the target detail page path.

        Parameters:
        detailPage - the target detail page path
      • setLocale

        public void setLocale​(java.util.Locale locale)
        Sets the locale to use for the link.
        Parameters:
        locale - the locale to use for the link
      • setLocale

        public void setLocale​(java.lang.String localeName)
        Sets the locale for the link to create.
        Parameters:
        localeName - name of the locale, e.g. "en", "en_US", ...
      • setScope

        public void setScope​(java.lang.String scope)
        Sets the scope (only used in combination with the var parameter).
        Parameters:
        scope - the scope for the variable
      • setType

        public void setType​(java.lang.String type)
        Sets the type.
        Parameters:
        type - the link type
      • setVar

        public void setVar​(java.lang.String var)
        Sets the variable name to store the result in.
        Parameters:
        var - the variable name to store the result in