Module com.github.robtimus.servlet
Class URLParameter
- java.lang.Object
-
- com.github.robtimus.servlet.parameters.URLParameter
-
public final class URLParameter extends Object
Represents a parameter that should have a URL value.- Author:
- Rob Spoor
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isSet()
Returns whether or not the parameter is set.static URLParameter
of(FilterConfig config, String name)
Returns a URL init parameter for a filter.static URLParameter
of(ServletConfig config, String name)
Returns a URL init parameter for a servlet.static URLParameter
of(ServletContext context, String name)
Returns a URL init parameter for a servlet context.static URLParameter
of(ServletRequest request, String name)
Returns a URL parameter for a servlet request.URLParameter
protocolIn(String... protocols)
Validates that the parameter value's protocol has a specific value.URLParameter
protocolIn(Collection<String> protocols)
Validates that the parameter value's protocol has a specific value.URLParameter
protocolIs(String protocol)
Validates that the parameter value's protocol has a specific value.URL
requiredValue()
Returns the parameter value.String
toString()
URL
valueWithDefault(URL defaultValue)
Returns the parameter if it is set.
-
-
-
Method Detail
-
isSet
public boolean isSet()
Returns whether or not the parameter is set.- Returns:
true
if the parameter is set, orfalse
otherwise.
-
requiredValue
public URL requiredValue()
Returns the parameter value.- Returns:
- The parameter value.
- Throws:
IllegalStateException
- If the parameter is not set.
-
valueWithDefault
public URL valueWithDefault(URL 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.
-
protocolIs
public URLParameter protocolIs(String protocol)
Validates that the parameter value's protocol has a specific value.- Parameters:
protocol
- The protocol to check for.- Returns:
- This object.
- Throws:
IllegalStateException
- If the parameter is set but its value's protocol does not match the given protocol.
-
protocolIn
public URLParameter protocolIn(String... protocols)
Validates that the parameter value's protocol has a specific value.- Parameters:
protocols
- The protocols to check for.- Returns:
- This object.
- Throws:
IllegalStateException
- If the parameter is set but its value's protocol does not match any of the given protocols.
-
protocolIn
public URLParameter protocolIn(Collection<String> protocols)
Validates that the parameter value's protocol has a specific value.- Parameters:
protocols
- The protocols to check for.- Returns:
- This object.
- Throws:
NullPointerException
- If the given collection isnull
.IllegalStateException
- If the parameter is set but its value's protocol does not match any of the given protocols.
-
of
public static URLParameter of(FilterConfig config, String name)
Returns a URL 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 URL value.
-
of
public static URLParameter of(ServletConfig config, String name)
Returns a URL 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 URL value.
-
of
public static URLParameter of(ServletContext context, String name)
Returns a URL 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 URL value.
-
of
public static URLParameter of(ServletRequest request, String name)
Returns a URL 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 URL value.
-
-