Package org.moera.lib

Class UniversalLocation

java.lang.Object
org.moera.lib.UniversalLocation

public class UniversalLocation extends Object
This class represents a Moera universal URL and contains routines for constructing and parsing it.
  • Field Details

  • Constructor Details

    • UniversalLocation

      public UniversalLocation(String uri) throws URISyntaxException
      Constructs a UniversalLocation object based on the location part of the provided URI.
      Parameters:
      uri - the URI to be parsed
      Throws:
      URISyntaxException - URI syntax is incorrect
    • UniversalLocation

      public UniversalLocation(String nodeName, String scheme, String authority, String path, String query, String fragment)
      Constructs a UniversalLocation object using the provided parameters.
      Parameters:
      nodeName - the node name associated with the location, which will be processed and shortened if necessary
      scheme - the URI scheme (e.g., "http", "https"); defaults to "https" if not provided
      authority - the authority component of the URI, typically containing the host and optionally the port
      path - the path component of the URI; adjusted automatically if it starts with "/moera" or is null
      query - the query string of the URI
      fragment - the fragment identifier of the URI
  • Method Details

    • redirectTo

      public static String redirectTo(String nodeName, String url)
      Builds a universal Moera URL from the direct URL of a page on a node, adding the node name provided.
      Parameters:
      nodeName - the name of the node, which will be used for the universal URL
      url - the direct URL to be transformed into a universal URL, may be null
      Returns:
      the constructed universal URL; if a syntax error occurs, a default redirector URI (without location) is returned
    • redirectTo

      public static String redirectTo(String nodeName, String rootUrl, String path, String query, String fragment)
      Build a universal Moera URL from the node name, the Moera root URL of the node, virtual path and other components.
      Parameters:
      nodeName - the name of the node associated with the generated URL
      rootUrl - the Moera root URL of the node (may be null)
      path - the virtual path component of the URL (may be null)
      query - the query string of the URL
      fragment - the fragment identifier for the URL
      Returns:
      the constructed universal URL; if a syntax error occurs, a default redirector URI (without location) is returned
    • getNodeName

      public String getNodeName()
      Retrieves the name of the node associated with this location.
      Returns:
      the node name as a String
    • setNodeName

      public void setNodeName(String nodeName)
      Sets the name of the node associated with this location. The provided node name is shortened using the NodeName.shorten(java.lang.String) method before being assigned.
      Parameters:
      nodeName - the node name to set; may be transformed into a shortened format
    • getScheme

      public String getScheme()
      Retrieves the URI scheme associated with this location.
      Returns:
      the URI scheme.
    • setScheme

      public void setScheme(String scheme)
      Sets the URI scheme for this location. If the provided scheme is null, it defaults to "https".
      Parameters:
      scheme - the URI scheme to set
    • getAuthority

      public String getAuthority()
      Retrieves the authority component of the URI. The authority typically consists of the host, and optionally, the port number.
      Returns:
      the authority component of the URI
    • setAuthority

      public void setAuthority(String authority)
      Sets the authority component of the URI.
      Parameters:
      authority - the authority component, typically containing the host and optionally the port
    • setSchemeAndAuthority

      public void setSchemeAndAuthority(URI uri)
      Sets the scheme and authority components of the current object, taking them from the given URI.
      Parameters:
      uri - the URI from which the scheme and authority will be extracted
    • getPath

      public String getPath()
      Retrieves the path component of the URI.
      Returns:
      the path component
    • setPath

      public void setPath(String path)
      Sets the path component of the URI. If the provided path starts with "/moera", this prefix is removed. If the path is null or empty, it defaults to the root path "/".
      Parameters:
      path - the path component of the URI; may be null or empty
    • getLocation

      public String getLocation()
      Constructs and returns the universal Moera location based on the node name, scheme, authority, and path components of the current object (does not include query and fragment). If the authority is null, a tilde character ('~') is used as a placeholder.
      Returns:
      a string representing the location
    • getQuery

      public String getQuery()
      Retrieves the query component of the URI.
      Returns:
      the query string, or null if the query is not defined
    • setQuery

      public void setQuery(String query)
      Sets the query component of the URI.
      Parameters:
      query - the query string to be set
    • getFragment

      public String getFragment()
      Retrieves the fragment component of the URI.
      Returns:
      the fragment component of the URI, or null if no fragment is defined
    • setFragment

      public void setFragment(String fragment)
      Sets the fragment component of the URI.
      Parameters:
      fragment - the fragment identifier to be set, representing the portion of the URI that comes after the `#` character; may be null
    • toString

      public String toString()
      Provides a string representation of the URI.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the URI that includes the location, query, and fragment, if present