Package org.moera.lib
Class UniversalLocation
java.lang.Object
org.moera.lib.UniversalLocation
This class represents a Moera universal URL and contains routines for constructing and parsing it.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The host used as a redirector in universal URLs. -
Constructor Summary
ConstructorsConstructorDescriptionUniversalLocation
(String uri) Constructs aUniversalLocation
object based on the location part of the provided URI.UniversalLocation
(String nodeName, String scheme, String authority, String path, String query, String fragment) Constructs aUniversalLocation
object using the provided parameters. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the authority component of the URI.Retrieves the fragment component of the URI.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).Retrieves the name of the node associated with this location.getPath()
Retrieves the path component of the URI.getQuery()
Retrieves the query component of the URI.Retrieves the URI scheme associated with this location.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.static String
Build a universal Moera URL from the node name, the Moera root URL of the node, virtual path and other components.void
setAuthority
(String authority) Sets the authority component of the URI.void
setFragment
(String fragment) Sets the fragment component of the URI.void
setNodeName
(String nodeName) Sets the name of the node associated with this location.void
Sets the path component of the URI.void
Sets the query component of the URI.void
Sets the URI scheme for this location.void
setSchemeAndAuthority
(URI uri) Sets the scheme and authority components of the current object, taking them from the given URI.toString()
Provides a string representation of the URI.
-
Field Details
-
REDIRECTOR
The host used as a redirector in universal URLs.- See Also:
-
-
Constructor Details
-
UniversalLocation
Constructs aUniversalLocation
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 aUniversalLocation
object using the provided parameters.- Parameters:
nodeName
- the node name associated with the location, which will be processed and shortened if necessaryscheme
- the URI scheme (e.g., "http", "https"); defaults to "https" if not providedauthority
- the authority component of the URI, typically containing the host and optionally the portpath
- the path component of the URI; adjusted automatically if it starts with"/moera"
or isnull
query
- the query string of the URIfragment
- the fragment identifier of the URI
-
-
Method Details
-
redirectTo
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 URLurl
- the direct URL to be transformed into a universal URL, may benull
- 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 URLrootUrl
- the Moera root URL of the node (may benull
)path
- the virtual path component of the URL (may benull
)query
- the query string of the URLfragment
- 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
Retrieves the name of the node associated with this location.- Returns:
- the node name as a String
-
setNodeName
Sets the name of the node associated with this location. The provided node name is shortened using theNodeName.shorten(java.lang.String)
method before being assigned.- Parameters:
nodeName
- the node name to set; may be transformed into a shortened format
-
getScheme
Retrieves the URI scheme associated with this location.- Returns:
- the URI scheme.
-
setScheme
Sets the URI scheme for this location. If the provided scheme isnull
, it defaults to "https".- Parameters:
scheme
- the URI scheme to set
-
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
Sets the authority component of the URI.- Parameters:
authority
- the authority component, typically containing the host and optionally the port
-
setSchemeAndAuthority
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
Retrieves the path component of the URI.- Returns:
- the path component
-
setPath
Sets the path component of the URI. If the provided path starts with"/moera"
, this prefix is removed. If the path isnull
or empty, it defaults to the root path"/"
.- Parameters:
path
- the path component of the URI; may benull
or empty
-
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
Retrieves the query component of the URI.- Returns:
- the query string, or
null
if the query is not defined
-
setQuery
Sets the query component of the URI.- Parameters:
query
- the query string to be set
-
getFragment
Retrieves the fragment component of the URI.- Returns:
- the fragment component of the URI, or
null
if no fragment is defined
-
setFragment
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 benull
-
toString
Provides a string representation of the URI.
-