Class ViewerPathBuilder

java.lang.Object
io.goobi.viewer.model.urlresolution.ViewerPathBuilder

public final class ViewerPathBuilder extends Object
Offers static methods to create ViewerPaths from a http request.
Author:
Florian Alpers
  • Method Details

    • createPath

      public static Optional<ViewerPath> createPath(HttpServletRequest httpRequest) throws DAOException
      Returns the request path of the given httpRequest as a ViewerPath, including information on associated CMSPage and targeted PageType.

      If the url has a pretty-url context and only consists of the server url, "/index" is appended to the url to redirect to the index pretty-mapping Any occurrences of "index.(x)html" are removed from the url to get the actual pretty url

      Parameters:
      httpRequest - The request from which the path is generated
      Returns:
      an Optional containing the ViewerPath for the request URL, or empty if not resolvable
      Throws:
      DAOException - if any.
    • createPath

      public static Optional<ViewerPath> createPath(HttpServletRequest request, String baseUrl) throws DAOException
      createPath.
      Parameters:
      request - incoming HTTP request providing server URL and context
      baseUrl - absolute URL to resolve into a ViewerPath
      Returns:
      an Optional containing the ViewerPath for the given URL, or empty if not resolvable
      Throws:
      DAOException - if any.
    • createPath

      public static Optional<ViewerPath> createPath(String applicationUrl, String applicationName, String serviceUrl, String queryString) throws DAOException
      Create a combined path from the given url.

      If the url leads to a known PageType, associates the PageType with the combined path. If the path leads to a cmsPage, either through direct url /cmds/..., the cmsPages alternative url or a static page mapping, the cmsPage is associated with this path

      Parameters:
      applicationUrl - The absolute url of the web-application including the application name ('viewer')
      applicationName - The name of the web-application. This is always the last part of the hostUrl. May be empty
      serviceUrl - The complete requested url, optionally including the hostUrl
      queryString - the raw HTTP query string, may be null
      Returns:
      A ViewerPath containing the complete path information
      Throws:
      DAOException - if any.
    • getCmsPage

      public static Optional<CMSPage> getCmsPage(URI servicePath) throws DAOException
      Gets the best matching CMSPage which alternative url ('persistent url') matches the beginning of the given path.
      Parameters:
      servicePath - requested service path to match against CMS page URLs
      Returns:
      an Optional containing the best-matching CMSPage, or empty if none matches
      Throws:
      DAOException - if any.
    • getCampaign

      public static Optional<Campaign> getCampaign(URI servicePath) throws DAOException
      getCampaign.
      Parameters:
      servicePath - requested service path to match against campaign permalinks
      Returns:
      an Optional containing the best-matching Campaign, or empty if none matches
      Throws:
      DAOException - if any.
    • getPageType

      public static Optional<PageType> getPageType(URI servicePath)
      Gets the PageType that the given path refers to, if any.
      Parameters:
      servicePath - requested service path to match against known page types
      Returns:
      an Optional containing the best-matching PageType, or empty if the path matches no known page type
    • startsWith

      public static boolean startsWith(URI uri, String string)
      Returns true if the first parts of the uri (separated by '/') are equal to all parts of the given string (separated by '/'). If the string has more parts than the uri, false is returned
      Parameters:
      uri - URI whose leading path segments are compared
      string - path string to match against the URI prefix
      Returns:
      true if the leading path segments of the URI match all segments of the given string, false otherwise
    • resolve

      public static URI resolve(URI master, URI slave, String fragment, String query)
      resolve.
      Parameters:
      master - base URI to resolve against
      slave - URI whose string form is appended to the base URI
      fragment - optional URL fragment to append (without '#')
      query - optional query string to append (without '?')
      Returns:
      the resolved URI combining master and slave with optional fragment and query
    • resolve

      public static URI resolve(URI master, String slave)
      Parameters:
      master - the base URI
      slave - the path segment to append to the base URI
      Returns:
      a URI object
    • resolve

      public static URI resolve(URI master, String slave, String fragment, String query)
      resolve.
      Parameters:
      master - base URI to resolve against
      slave - path string to append to the base URI
      fragment - optional URL fragment to append (without '#')
      query - optional query string to append (without '?')
      Returns:
      the resolved URI combining master and slave path with optional fragment and query