Class UriContext
A typical request against a URL takes the following form:
http://host:port/context-root/servlet-path/path-info | authority | context | resource | path | +--------------------------------------------------+
This class allows you to convert URL strings to absolute (e.g.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.UriContext(String s) String constructor.UriContext(String authority, String contextRoot, String servletPath, String pathInfo) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns the absolute URI of just the authority portion of this URI context.Returns the absolute URI of the context-root portion of this URI context.Returns the absolute URI of the path portion of this URI context.Returns the parent of the URL returned bygetAbsolutePathInfo().Returns the absolute URI of the resource portion of this URI context.Returns the parent of the URL returned bygetAbsoluteServletPath().Returns the root-relative URI of the context portion of this URI context.Returns the root-relative URI of the path portion of this URI context.Returns the parent of the URL returned bygetRootRelativePathInfo().Returns the root-relative URI of the resource portion of this URI context.Returns the parent of the URL returned bygetRootRelativeServletPath().static UriContextStatic creator.static UriContextStatic creator.toString()
-
Field Details
-
DEFAULT
Default URI context.No information about authority, servlet-root, context-root, or path-info is known.
-
authority
-
contextRoot
-
servletPath
-
pathInfo
-
parentPath
-
-
Constructor Details
-
UriContext
public UriContext()Default constructor.All
null values. -
UriContext
String constructor.Input string is a JSON object with the following format:
{authority:'xxx',contextRoot:'xxx',servletPath:'xxx',pathInfo:'xxx'} - Parameters:
s- The input string.
Example:{authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'} - Throws:
ParseException- If input string is not a valid JSON object.
-
UriContext
@Beanc public UriContext(@Name("authority") String authority, @Name("contextRoot") String contextRoot, @Name("servletPath") String servletPath, @Name("pathInfo") String pathInfo) Constructor.Leading and trailing slashes are trimmed of all parameters.
Any parameter can be
null . Blanks and nulls are equivalent.- Parameters:
authority- The authority portion of URL (e.g."http://hostname:port" )contextRoot- The context root of the application (e.g."/context-root" , or"context-root" )servletPath- The servlet path (e.g."/servlet-path" , or"servlet-path" )pathInfo- The path info (e.g."/path-info" , or"path-info" )
-
-
Method Details
-
of
Static creator.- Parameters:
s- The input string.
Example:{authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'} - Returns:
- A new
UriContextobject.
-
of
public static UriContext of(String authority, String contextRoot, String servletPath, String pathInfo) Static creator.- Parameters:
authority- The authority portion of URL (e.g."http://hostname:port" )contextRoot- The context root of the application (e.g."/context-root" , or"context-root" )servletPath- The servlet path (e.g."/servlet-path" , or"servlet-path" )pathInfo- The path info (e.g."/path-info" , or"path-info" )- Returns:
- A new
UriContextobject.
-
getAbsoluteAuthority
Returns the absolute URI of just the authority portion of this URI context.Example:
"http://hostname:port" If the authority is null/empty, returns
"/" .- Returns:
- The absolute URI of just the authority portion of this URI context.
Never
null .
-
getAbsoluteContextRoot
Returns the absolute URI of the context-root portion of this URI context.Example:
"http://hostname:port/context-root" - Returns:
- The absolute URI of the context-root portion of this URI context.
Never
null .
-
getAbsolutePathInfo
Returns the absolute URI of the path portion of this URI context.Example:
"http://hostname:port/context-root/servlet-path/path-info" - Returns:
- The absolute URI of the path portion of this URI context.
Never
null .
-
getAbsolutePathInfoParent
Returns the parent of the URL returned bygetAbsolutePathInfo().- Returns:
- The parent of the URL returned by
getAbsolutePathInfo().
-
getAbsoluteServletPath
Returns the absolute URI of the resource portion of this URI context.Example:
"http://hostname:port/context-root/servlet-path" - Returns:
- The absolute URI of the resource portion of this URI context.
Never
null .
-
getAbsoluteServletPathParent
Returns the parent of the URL returned bygetAbsoluteServletPath().- Returns:
- The parent of the URL returned by
getAbsoluteServletPath().
-
getRootRelativeContextRoot
Returns the root-relative URI of the context portion of this URI context.Example:
"/context-root" - Returns:
- The root-relative URI of the context portion of this URI context.
Never
null .
-
getRootRelativePathInfo
Returns the root-relative URI of the path portion of this URI context.Example:
"/context-root/servlet-path/path-info" - Returns:
- The root-relative URI of the path portion of this URI context.
Never
null .
-
getRootRelativePathInfoParent
Returns the parent of the URL returned bygetRootRelativePathInfo().- Returns:
- The parent of the URL returned by
getRootRelativePathInfo().
-
getRootRelativeServletPath
Returns the root-relative URI of the resource portion of this URI context.Example:
"/context-root/servlet-path" - Returns:
- The root-relative URI of the resource portion of this URI context.
Never
null .
-
getRootRelativeServletPathParent
Returns the parent of the URL returned bygetRootRelativeServletPath().- Returns:
- The parent of the URL returned by
getRootRelativeServletPath().
-
properties
-
toString
-