public abstract class RequestHandler extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
(package private) static class |
RequestHandler.PermissionCache |
static class |
RequestHandler.RawURLParseRequestHandler |
static class |
RequestHandler.RequestHandlerBadRequestException |
static class |
RequestHandler.RequestHandlerErrorException |
static class |
RequestHandler.RequestHandlerException |
static class |
RequestHandler.RequestHandlerForbiddenException |
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.String> |
args
The GET request arguments
|
protected java.lang.String |
content
default response
|
protected java.lang.String |
contentType
default content type
|
static boolean |
globalConfirmationDefault |
static java.lang.String |
globalConfirmationKey |
static boolean |
loadInNewLayerDefault |
static java.lang.String |
loadInNewLayerKey |
protected java.lang.String |
myCommand
will be filled with the command assigned to the subclass
|
protected static RequestHandler.PermissionCache |
PERMISSIONS
past confirmations
|
protected java.lang.String |
request
The request URL without "GET".
|
protected java.lang.String |
sender
who sent the request?
the host from referer header or IP of request sender
|
Constructor and Description |
---|
RequestHandler() |
Modifier and Type | Method and Description |
---|---|
(package private) void |
checkMandatoryParams() |
void |
checkPermission()
Check permissions in preferences and display error message or ask for permission.
|
java.lang.String |
getContent() |
java.lang.String |
getContentType() |
abstract java.lang.String[] |
getMandatoryParams() |
java.lang.String[] |
getOptionalParams() |
abstract java.lang.String |
getPermissionMessage()
Get a specific message to ask the user for permission for the operation
requested via remote control.
|
abstract PermissionPrefWithDefault |
getPermissionPref()
Get a PermissionPref object containing the name of a special permission
preference to individually allow the requested operation and an error
message to be displayed when a disabled operation is requested.
|
(package private) static java.util.Map<java.lang.String,java.lang.String> |
getRequestParameter(java.net.URI uri)
Returns the request parameters.
|
java.lang.String |
getUsage() |
java.lang.String[] |
getUsageExamples() |
java.lang.String[] |
getUsageExamples(java.lang.String cmd)
Returns usage examples for the given command.
|
void |
handle()
Check permission and parameters and handle request.
|
protected abstract void |
handleRequest()
Handle a specific command sent as remote control.
|
protected boolean |
isLoadInNewLayer() |
protected void |
parseArgs()
Parse the request parameters as key=value pairs.
|
void |
setCommand(java.lang.String command)
Save command associated with this handler.
|
void |
setSender(java.lang.String sender) |
void |
setUrl(java.lang.String url)
Set request URL and parse args.
|
protected abstract void |
validateRequest()
Validates the request before attempting to perform it.
|
public static final java.lang.String globalConfirmationKey
public static final boolean globalConfirmationDefault
public static final java.lang.String loadInNewLayerKey
public static final boolean loadInNewLayerDefault
protected static final RequestHandler.PermissionCache PERMISSIONS
protected java.util.Map<java.lang.String,java.lang.String> args
protected java.lang.String request
protected java.lang.String content
protected java.lang.String contentType
protected java.lang.String myCommand
protected java.lang.String sender
public RequestHandler()
public final void handle() throws RequestHandler.RequestHandlerForbiddenException, RequestHandler.RequestHandlerBadRequestException, RequestHandler.RequestHandlerErrorException
RequestHandler.RequestHandlerForbiddenException
- if request is forbidden by preferencesRequestHandler.RequestHandlerBadRequestException
- if request is invalidRequestHandler.RequestHandlerErrorException
- if an error occurs while processing requestprotected abstract void validateRequest() throws RequestHandler.RequestHandlerBadRequestException
RequestHandler.RequestHandlerBadRequestException
- if request is invalidprotected abstract void handleRequest() throws RequestHandler.RequestHandlerErrorException, RequestHandler.RequestHandlerBadRequestException
RequestHandler.RequestHandlerErrorException
- if an error occurs while processing requestRequestHandler.RequestHandlerBadRequestException
- if request is invalidpublic abstract java.lang.String getPermissionMessage()
public abstract PermissionPrefWithDefault getPermissionPref()
public abstract java.lang.String[] getMandatoryParams()
public java.lang.String[] getOptionalParams()
public java.lang.String getUsage()
public java.lang.String[] getUsageExamples()
public java.lang.String[] getUsageExamples(java.lang.String cmd)
cmd
- The command askedpublic final void checkPermission() throws RequestHandler.RequestHandlerForbiddenException
RequestHandler.RequestHandlerForbiddenException
- if request is forbidden by preferencespublic void setUrl(java.lang.String url) throws RequestHandler.RequestHandlerBadRequestException
url
- The request URL.RequestHandler.RequestHandlerBadRequestException
- if request URL is invalidprotected void parseArgs() throws java.net.URISyntaxException
this.args
.
Can be overridden by subclass.java.net.URISyntaxException
- if request URL is invalidstatic java.util.Map<java.lang.String,java.lang.String> getRequestParameter(java.net.URI uri)
uri
- URI as stringvoid checkMandatoryParams() throws RequestHandler.RequestHandlerBadRequestException
public void setCommand(java.lang.String command)
command
- The command.public java.lang.String getContent()
public java.lang.String getContentType()
protected boolean isLoadInNewLayer()
public void setSender(java.lang.String sender)