Class CmsJspTagLink

java.lang.Object
javax.servlet.jsp.tagext.TagSupport
javax.servlet.jsp.tagext.BodyTagSupport
org.opencms.jsp.CmsJspTagLink
All Implemented Interfaces:
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:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Parameters for the link tag.
    static enum 
    Link type.
  • 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
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    Returns the base URI used to create the link target.
    static Locale
    Tries to read the active locale for the given (site) path, or for its parent path if the path can't be read.
    Returns the target detail page path.
    static String
    linkTagAction(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 String
    linkTagAction(String target, javax.servlet.ServletRequest req, 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 String
    linkTagAction(String target, javax.servlet.ServletRequest req, String baseUri, String detailPage, 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 String
    linkTagAction(String target, javax.servlet.ServletRequest req, String baseUri, 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 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
     
    void
    setBaseUri(String baseUri)
    Sets the base URI used to create the link target.
    void
    setDetailPage(String detailPage)
    Sets the target detail page path.
    void
    setLocale(String localeName)
    Sets the locale for the link to create.
    void
    setLocale(Locale locale)
    Sets the locale to use for the link.
    void
    Sets the scope (only used in combination with the var parameter).
    void
    Sets the type.
    void
    Sets the type.
    void
    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
  • Constructor Details

  • Method Details

    • getBaseUriLocale

      public static Locale getBaseUriLocale(CmsObject cms, 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 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

      public static String linkTagAction(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:
    • linkTagAction

      public static String linkTagAction(String target, javax.servlet.ServletRequest req, 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

      public static String linkTagAction(String target, javax.servlet.ServletRequest req, String baseUri, 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

      public static String linkTagAction(String target, javax.servlet.ServletRequest req, String baseUri, String detailPage, 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:
    • 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 String getBaseUri()
      Returns the base URI used to create the link target.

      Returns:
      the base URI used to create the link target
    • 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(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(String detailPage)
      Sets the target detail page path.

      Parameters:
      detailPage - the target detail page path
    • setLocale

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

      public void setLocale(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(String scope)
      Sets the scope (only used in combination with the var parameter).
      Parameters:
      scope - the scope for the variable
    • setType

      public void setType(String type)
      Sets the type.
      Parameters:
      type - the link type
    • setType

      public void setType(CmsJspTagLink.Type type)
      Sets the type.
      Parameters:
      type - the type
    • setVar

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