org.openstreetmap.josm.io.remotecontrol.handler
Class RequestHandler

java.lang.Object
  extended by org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler
Direct Known Subclasses:
AddNodeHandler, AddWayHandler, ImageryHandler, ImportHandler, LoadAndZoomHandler, LoadObjectHandler, OpenFileHandler, VersionHandler

public abstract class RequestHandler
extends java.lang.Object

This is the parent of all classes that handle a specific remote control command


Nested Class Summary
static class RequestHandler.RequestHandlerBadRequestException
           
static class RequestHandler.RequestHandlerErrorException
           
static class RequestHandler.RequestHandlerException
           
static class RequestHandler.RequestHandlerForbiddenException
           
 
Field Summary
protected  java.util.HashMap<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  java.lang.String request
          The request URL without "GET".
 
Constructor Summary
RequestHandler()
           
 
Method Summary
(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()
           
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.
 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 setUrl(java.lang.String url)
          Set request URL and parse args.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

globalConfirmationKey

public static final java.lang.String globalConfirmationKey
See Also:
Constant Field Values

globalConfirmationDefault

public static final boolean globalConfirmationDefault
See Also:
Constant Field Values

loadInNewLayerKey

public static final java.lang.String loadInNewLayerKey
See Also:
Constant Field Values

loadInNewLayerDefault

public static final boolean loadInNewLayerDefault
See Also:
Constant Field Values

args

protected java.util.HashMap<java.lang.String,java.lang.String> args
The GET request arguments


request

protected java.lang.String request
The request URL without "GET".


content

protected java.lang.String content
default response


contentType

protected java.lang.String contentType
default content type


myCommand

protected java.lang.String myCommand
will be filled with the command assigned to the subclass

Constructor Detail

RequestHandler

public RequestHandler()
Method Detail

handle

public final void handle()
                  throws RequestHandler.RequestHandlerForbiddenException,
                         RequestHandler.RequestHandlerBadRequestException,
                         RequestHandler.RequestHandlerErrorException
Check permission and parameters and handle request.

Throws:
RequestHandler.RequestHandlerForbiddenException
RequestHandler.RequestHandlerBadRequestException
RequestHandler.RequestHandlerErrorException

handleRequest

protected abstract void handleRequest()
                               throws RequestHandler.RequestHandlerErrorException,
                                      RequestHandler.RequestHandlerBadRequestException
Handle a specific command sent as remote control. This method of the subclass will do the real work.

Throws:
RequestHandler.RequestHandlerErrorException
RequestHandler.RequestHandlerBadRequestException

getPermissionMessage

public abstract java.lang.String getPermissionMessage()
Get a specific message to ask the user for permission for the operation requested via remote control. This message will be displayed to the user if the preference remotecontrol.always-confirm is true.

Returns:
the message

getPermissionPref

public 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. Default is not to check any special preference. Override this in a subclass to define permission preference and error message.

Returns:
the preference name and error message or null

getMandatoryParams

public abstract java.lang.String[] getMandatoryParams()

checkPermission

public final void checkPermission()
                           throws RequestHandler.RequestHandlerForbiddenException
Check permissions in preferences and display error message or ask for permission.

Throws:
RequestHandler.RequestHandlerForbiddenException

setUrl

public void setUrl(java.lang.String url)
Set request URL and parse args.

Parameters:
url - The request URL.

parseArgs

protected void parseArgs()
Parse the request parameters as key=value pairs. The result will be stored in this.args. Can be overridden by subclass.


checkMandatoryParams

void checkMandatoryParams()
                    throws RequestHandler.RequestHandlerBadRequestException
Throws:
RequestHandler.RequestHandlerBadRequestException

setCommand

public void setCommand(java.lang.String command)
Save command associated with this handler.

Parameters:
command - The command.

getContent

public java.lang.String getContent()

getContentType

public java.lang.String getContentType()

isLoadInNewLayer

protected boolean isLoadInNewLayer()


JOSM