Class LinkHelper

java.lang.Object
com.helger.photon.app.url.LinkHelper

@ThreadSafe public final class LinkHelper extends Object
Misc utilities to create link URLs.
Author:
Philip Helger
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The default name of the stream servlet.
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.helger.commons.url.SimpleURL
     
    static String
     
    static String
     
    static com.helger.commons.url.SimpleURL
    getStreamURL(com.helger.web.scope.IRequestWebScopeWithoutResponse aRequestScope, String sURL)
    Get the default URL to stream the passed URL.
    static String
    getURIWithContext(com.helger.web.scope.IRequestWebScopeWithoutResponse aRequestScope, String sHRef)
    Prefix the passed href with the relative context path in case the passed href has no protocol yet.
    static String
    Prefix the passed href with the relative context path in case the passed href has no protocol yet.
    Important: this method does not add the session ID in case cookies are disabled by the client!
    static String
    getURIWithServerAndContext(com.helger.web.scope.IRequestWebScopeWithoutResponse aRequestScope, String sHRef)
    Prefix the passed href with the absolute server + context path in case the passed href has no protocol yet.
    static String
    Prefix the passed href with the absolute server + context path in case the passed href has no protocol yet.
    Important: this method does not add the session ID in case cookies are disabled by the client!
    static com.helger.commons.url.SimpleURL
    getURLWithContext(com.helger.web.scope.IRequestWebScopeWithoutResponse aRequestScope, String sHRef)
    Prefix the passed href with the relative context path in case the passed href has no protocol yet.
    static com.helger.commons.url.SimpleURL
    Prefix the passed href with the relative context path in case the passed href has no protocol yet.
    Important: this method does not add the session ID in case cookies are disabled by the client!
    static com.helger.commons.url.SimpleURL
    getURLWithServerAndContext(com.helger.web.scope.IRequestWebScopeWithoutResponse aRequestScope, String sHRef)
    Prefix the passed href with the absolute server + context path in case the passed href has no protocol yet.
    static com.helger.commons.url.SimpleURL
    Prefix the passed href with the absolute server + context path in case the passed href has no protocol yet.
    Important: this method does not add the session ID in case cookies are disabled by the client!
    static boolean
    Special "has known protocol" version that also supports the pseudo protocol "//" that maps to either "http" or "https" depending on the surrounding setup.
    static void
    setStreamServletName(String sStreamServletName)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • STREAM_SERVLET_NAME_REGEX

      public static final String STREAM_SERVLET_NAME_REGEX
      See Also:
    • DEFAULT_STREAM_SERVLET_NAME

      public static final String DEFAULT_STREAM_SERVLET_NAME
      The default name of the stream servlet. If this is different in you application you may not use the methods that refer to this path!
      See Also:
  • Method Details

    • setStreamServletName

      public static void setStreamServletName(@Nonnull @Nonempty String sStreamServletName)
    • getStreamServletName

      @Nonnull @Nonempty public static String getStreamServletName()
      Returns:
      The name of the stream servlet path. Default is stream
      See Also:
    • getStreamServletPath

      @Nonnull @Nonempty public static String getStreamServletPath()
      Returns:
      The relative path of the stream servlet. Default is /stream
      See Also:
    • hasKnownProtocol

      public static boolean hasKnownProtocol(@Nullable String sURI)
      Special "has known protocol" version that also supports the pseudo protocol "//" that maps to either "http" or "https" depending on the surrounding setup.
      Parameters:
      sURI - Source URI. MAy be null.
      Returns:
      true if the URI has a known protocol or "//".
    • getURIWithContext

      @Nonnull public static String getURIWithContext(@Nonnull String sHRef)
      Prefix the passed href with the relative context path in case the passed href has no protocol yet.
      Important: this method does not add the session ID in case cookies are disabled by the client!
      Parameters:
      sHRef - The href to be extended. May not be null.
      Returns:
      Either the original href if already absolute or /webapp-context/href otherwise. Never null.
    • getURIWithContext

      @Nonnull public static String getURIWithContext(@Nonnull com.helger.web.scope.IRequestWebScopeWithoutResponse aRequestScope, @Nonnull String sHRef)
      Prefix the passed href with the relative context path in case the passed href has no protocol yet.
      Parameters:
      aRequestScope - The request web scope to be used. Required for cookie-less handling. May not be null.
      sHRef - The href to be extended. May not be null.
      Returns:
      Either the original href if already absolute or /webapp-context/href otherwise. Never null.
    • getURLWithContext

      @Nonnull public static com.helger.commons.url.SimpleURL getURLWithContext(@Nonnull String sHRef)
      Prefix the passed href with the relative context path in case the passed href has no protocol yet.
      Important: this method does not add the session ID in case cookies are disabled by the client!
      Parameters:
      sHRef - The href to be extended. May not be null.
      Returns:
      Either the original href if already absolute or /webapp-context/href otherwise. Never null.
    • getURLWithContext

      @Nonnull public static com.helger.commons.url.SimpleURL getURLWithContext(@Nonnull com.helger.web.scope.IRequestWebScopeWithoutResponse aRequestScope, @Nonnull String sHRef)
      Prefix the passed href with the relative context path in case the passed href has no protocol yet.
      Parameters:
      aRequestScope - The request web scope to be used. Required for cookie-less handling. May not be null.
      sHRef - The href to be extended. May not be null.
      Returns:
      Either the original href if already absolute or /webapp-context/href otherwise. Never null.
    • getURIWithServerAndContext

      @Nonnull public static String getURIWithServerAndContext(@Nonnull String sHRef)
      Prefix the passed href with the absolute server + context path in case the passed href has no protocol yet.
      Important: this method does not add the session ID in case cookies are disabled by the client!
      Parameters:
      sHRef - The href to be extended. May not be null.
      Returns:
      Either the original href if already absolute or http://servername:8123/webapp-context/href otherwise. Never null.
    • getURIWithServerAndContext

      @Nonnull public static String getURIWithServerAndContext(@Nonnull com.helger.web.scope.IRequestWebScopeWithoutResponse aRequestScope, @Nonnull String sHRef)
      Prefix the passed href with the absolute server + context path in case the passed href has no protocol yet.
      Parameters:
      aRequestScope - The request web scope to be used. Required for cookie-less handling. May not be null.
      sHRef - The href to be extended. May not be null.
      Returns:
      Either the original href if already absolute or http://servername:8123/webapp-context/href otherwise. Never null.
    • getURLWithServerAndContext

      @Nonnull public static com.helger.commons.url.SimpleURL getURLWithServerAndContext(@Nonnull String sHRef)
      Prefix the passed href with the absolute server + context path in case the passed href has no protocol yet.
      Important: this method does not add the session ID in case cookies are disabled by the client!
      Parameters:
      sHRef - The href to be extended.
      Returns:
      Either the original href if already absolute or http://servername:8123/webapp-context/href otherwise.
    • getURLWithServerAndContext

      @Nonnull public static com.helger.commons.url.SimpleURL getURLWithServerAndContext(@Nonnull com.helger.web.scope.IRequestWebScopeWithoutResponse aRequestScope, @Nonnull String sHRef)
      Prefix the passed href with the absolute server + context path in case the passed href has no protocol yet.
      Parameters:
      aRequestScope - The request web scope to be used. Required for cookie-less handling. May not be null.
      sHRef - The href to be extended.
      Returns:
      Either the original href if already absolute or http://servername:8123/webapp-context/href otherwise.
    • getHomeLinkWithoutSession

      @Nonnull public static com.helger.commons.url.SimpleURL getHomeLinkWithoutSession()
      Returns:
      A link to the start page without any session ID. Never null. E.g. / or /context. This is useful for logout links.
    • getStreamURL

      @Nonnull public static com.helger.commons.url.SimpleURL getStreamURL(@Nonnull com.helger.web.scope.IRequestWebScopeWithoutResponse aRequestScope, @Nonnull @Nonempty String sURL)
      Get the default URL to stream the passed URL. It is assumed that the servlet is located under the path "/stream". Because of the logic of the stream servlet, no parameter are assumed.
      Parameters:
      aRequestScope - The request web scope to be used. Required for cookie-less handling. May not be null.
      sURL - The URL to be streamed. If it does not start with a slash ("/") one is prepended automatically. If the URL already has a protocol, it is returned unchanged. May neither be null nor empty.
      Returns:
      The URL incl. the context to be stream. E.g. /webapp-context/stream/URL.