Module com.github.robtimus.servlet
Class URIParameter
- java.lang.Object
-
- com.github.robtimus.servlet.parameters.URIParameter
-
public final class URIParameter extends Object
Represents a parameter that should have a URI value.- Author:
- Rob Spoor
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisSet()Returns whether or not the parameter is set.static URIParameterof(FilterConfig config, String name)Returns a URI init parameter for a filter.static URIParameterof(ServletConfig config, String name)Returns a URI init parameter for a servlet.static URIParameterof(ServletContext context, String name)Returns a URI init parameter for a servlet context.static URIParameterof(ServletRequest request, String name)Returns a URI parameter for a servlet request.URIrequiredValue()Returns the parameter value.URIParameterschemeIn(String... schemes)Validates that the parameter value's scheme has a specific value.URIParameterschemeIn(Collection<String> schemes)Validates that the parameter value's scheme has a specific value.URIParameterschemeIs(String scheme)Validates that the parameter value's scheme has a specific value.StringtoString()URIvalueWithDefault(URI defaultValue)Returns the parameter if it is set.
-
-
-
Method Detail
-
isSet
public boolean isSet()
Returns whether or not the parameter is set.- Returns:
trueif the parameter is set, orfalseotherwise.
-
requiredValue
public URI requiredValue()
Returns the parameter value.- Returns:
- The parameter value.
- Throws:
IllegalStateException- If the parameter is not set.
-
valueWithDefault
public URI valueWithDefault(URI defaultValue)
Returns the parameter if it is set.- Parameters:
defaultValue- The value to return if the parameter is not set.- Returns:
- The parameter value, or the given default value if the parameter is not set.
-
schemeIs
public URIParameter schemeIs(String scheme)
Validates that the parameter value's scheme has a specific value.- Parameters:
scheme- The scheme to check for.- Returns:
- This object.
- Throws:
IllegalStateException- If the parameter is set but its value's scheme does not match the given scheme.
-
schemeIn
public URIParameter schemeIn(String... schemes)
Validates that the parameter value's scheme has a specific value.- Parameters:
schemes- The schemes to check for.- Returns:
- This object.
- Throws:
IllegalStateException- If the parameter is set but its value's scheme does not match any of the given schemes.
-
schemeIn
public URIParameter schemeIn(Collection<String> schemes)
Validates that the parameter value's scheme has a specific value.- Parameters:
schemes- The schemes to check for.- Returns:
- This object.
- Throws:
NullPointerException- If the given collection isnull.IllegalStateException- If the parameter is set but its value's scheme does not match any of the given schemes.
-
of
public static URIParameter of(FilterConfig config, String name)
Returns a URI init parameter for a filter.- Parameters:
config- The filter config to read the init parameter from.name- The name of the init parameter.- Returns:
- An object representing the init parameter with the given name from the given filter config. It may or may not be set.
- Throws:
NullPointerException- If the given filter config or name isnull.IllegalStateException- If the init parameter is set but does not have a URI value.
-
of
public static URIParameter of(ServletConfig config, String name)
Returns a URI init parameter for a servlet.- Parameters:
config- The servlet config to read the init parameter from.name- The name of the init parameter.- Returns:
- An object representing the init parameter with the given name from the given servlet config. It may or may not be set.
- Throws:
NullPointerException- If the given servlet config or name isnull.IllegalStateException- If the init parameter is set but does not have a URI value.
-
of
public static URIParameter of(ServletContext context, String name)
Returns a URI init parameter for a servlet context.- Parameters:
context- The servlet context config to read the init parameter from.name- The name of the init parameter.- Returns:
- An object representing the init parameter with the given name from the given servlet context. It may or may not be set.
- Throws:
IllegalStateException- If the init parameter is set but does not have a URI value.
-
of
public static URIParameter of(ServletRequest request, String name)
Returns a URI parameter for a servlet request.- Parameters:
request- The servlet request to read the parameter from.name- The name of the parameter.- Returns:
- An object representing the parameter with the given name from the given servlet request. It may or may not be set.
- Throws:
IllegalStateException- If the parameter is set but does not have a URI value.
-
-