Package org.opencms.util
Class CmsUriSplitter
- java.lang.Object
-
- org.opencms.util.CmsUriSplitter
-
public class CmsUriSplitter extends java.lang.Object
Splits an URI String into separate components.An URI is splitted into a
prefix
, aanchor
and aquery
part.
-
-
Constructor Summary
Constructors Constructor Description CmsUriSplitter(java.lang.String uri)
Creates a splitted URI using the strict parsing mode.CmsUriSplitter(java.lang.String uri, boolean strict)
Creates a splitted URI using the given parsing mode.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
java.lang.String
getAnchor()
Returns the anchor part of the uri, for examplesomeanchor
, ornull
if no anchor is available.java.lang.String
getPrefix()
Returns the prefix part of the uri, for examplehttp://www.opencms.org/some/path/
, ornull
if no prefix is available.java.lang.String
getProtocol()
Returns the URI protocol, for examplehttp
orhttps
.java.lang.String
getQuery()
Returns the query part of the uri, for examplea=b&c=d
, ornull
if no query is available.java.lang.String
getSuffix()
Returns the suffix part of the uri, a combination of query and anchor, for example?a=b&c=d#someanchor
, or the empty String if no suffix is available.java.lang.String
getUri()
Returns the URI String passed to this URI splitter.int
hashCode()
boolean
isErrorFree()
Returnstrue
if the URI was parsed error free in 'strict' mode, or if the simple mode was used.static boolean
isValidUri(java.lang.String uri)
Checks if the given URI is well formed.java.net.URI
toURI()
Returns an URI object created from the original input String.
-
-
-
Constructor Detail
-
CmsUriSplitter
public CmsUriSplitter(java.lang.String uri)
Creates a splitted URI using the strict parsing mode.- Parameters:
uri
- the URI to split
-
CmsUriSplitter
public CmsUriSplitter(java.lang.String uri, boolean strict)
Creates a splitted URI using the given parsing mode.Using 'strict' parsing mode, all requirements for an URI are checked. If 'strict' is set to
false
, then only some simple parsing rules are applied, in which case the result may not be 100% valid (but still usable). If 'strict' parsing generates an error, then simple parsing is used as a fallback.- Parameters:
uri
- the URI to splitstrict
- iftrue
, then 'strict' parsing mode is used, otherwise a relaxed URI parsing is done
-
-
Method Detail
-
isValidUri
public static boolean isValidUri(java.lang.String uri)
Checks if the given URI is well formed.- Parameters:
uri
- the URI to check- Returns:
true
if the given URI is well formed
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
- See Also:
Object.equals(java.lang.Object)
-
getAnchor
public java.lang.String getAnchor()
Returns the anchor part of the uri, for examplesomeanchor
, ornull
if no anchor is available.- Returns:
- the anchor part of the uri
-
getPrefix
public java.lang.String getPrefix()
Returns the prefix part of the uri, for examplehttp://www.opencms.org/some/path/
, ornull
if no prefix is available.- Returns:
- the prefix part of the uri
-
getProtocol
public java.lang.String getProtocol()
Returns the URI protocol, for examplehttp
orhttps
.- Returns:
- the URI protocol
-
getQuery
public java.lang.String getQuery()
Returns the query part of the uri, for examplea=b&c=d
, ornull
if no query is available.- Returns:
- the query part of the uri
-
getSuffix
public java.lang.String getSuffix()
Returns the suffix part of the uri, a combination of query and anchor, for example?a=b&c=d#someanchor
, or the empty String if no suffix is available.- Returns:
- the suffix part of the uri
-
getUri
public java.lang.String getUri()
Returns the URI String passed to this URI splitter.- Returns:
- the URI String passed to this URI splitter
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
- See Also:
Object.hashCode()
-
isErrorFree
public boolean isErrorFree()
Returnstrue
if the URI was parsed error free in 'strict' mode, or if the simple mode was used.- Returns:
true
if the URI was parsed error free in 'strict' mode, or if the simple mode was used
-
toURI
public java.net.URI toURI() throws java.net.URISyntaxException
Returns an URI object created from the original input String.This method will do a "best effort" to convert the original input String to a legal URI. Most notably, it will be able to handle original input Strings that contain a space " " and other usually illegal characters.
- Returns:
- an URI object created from the original input String
- Throws:
java.net.URISyntaxException
- in case no URI object can be created from the original input String
-
-