com.bbn.openmap.image
Class MapRequestHandler

java.lang.Object
  extended by com.bbn.openmap.image.ImageServer
      extended by com.bbn.openmap.image.MapRequestHandler
All Implemented Interfaces:
ImageServerConstants, WMTConstants, PropertyConsumer

public class MapRequestHandler
extends ImageServer
implements ImageServerConstants

The MapRequestHandler is the front end for String requests to the ImageServer. It's goal is to be able to handle OpenGIS WMT mapserver requests, so the String request format is in the same format. We've included some OpenMap extensions to that format, so an OpenMap projection can be defined.

The MapRequestHandler should be able to handle map requests, resulting in a map image, and capabilities requests, so a client can find out what layers, projection types and image formats are available.

If the 'layers' property is not defined the openmap.properties file, then the 'openmap.layers' property will be used, and the 'openmap.startUpLayers' property will be used to define the default set of layers. This lets there be more layers available to the client than would be sent by default (if the client doesn't specify layers).

The MapRequestHandler assumes that the ProjectionFactory shared instance has ProjectionLoaders added to it to let it know how to handle different projection names. A call to ProjectionFactory.loadDefaultProjections() will take care of this requirement if you just want the standard projections loaded.


Field Summary
protected  java.lang.String defaultLayers
          Comma-separated list of layer scoping prefixes that specify what layers, and their order, should be used for default images where layers are not specified in the request.
static java.lang.String defaultLayersProperty
           
static java.lang.String DefaultLayersProperty
          The real new property for doing this.
protected  Projection defaultProjection
          The default projection that provides projection parameters that are missing from the request.
static java.lang.String hexSeparator
           
protected  boolean useVisibility
          The layers' visibility will be set to true at initialization if this property is set, and the layers' visibility will determine if a layer will be part of the image.
static java.lang.String UseVisibilityProperty
          The property for using visibility of the layers to mark the default layers.
static java.lang.String valueSeparator
           
 
Fields inherited from class com.bbn.openmap.image.ImageServer
AntiAliasingProperty, background, BackgroundProperty, doAntiAliasing, formatter, imageFormatters, ImageFormattersProperty, ImageServerLayersProperty, layers, logger, OpenMapPrefix, projectionFactory, propertiesPrefix
 
Fields inherited from interface com.bbn.openmap.image.ImageServerConstants
AZIMUTH, LAT, LAYERMASK, LAYERS, LON, PAN, PROJTYPE, QUERY, RECENTER, SCALE, X, Y
 
Fields inherited from interface com.bbn.openmap.image.WMTConstants
BBOX, BGCOLOR, CAPABILITIES, CRS, EXCEPTIONS, FORMAT, GETCAPABILITIES, GETFEATUREINFO, GETLEGENDGRAPHIC, GETMAP, HEIGHT, IMAGEFORMAT_GEOTIFF, IMAGEFORMAT_GIF, IMAGEFORMAT_JPEG, IMAGEFORMAT_PNG, IMAGEFORMAT_PPM, IMAGEFORMAT_SVG, IMAGEFORMAT_TIFF, IMAGEFORMAT_WBMP, INFO_FORMAT, LAYER, MAP, QUERY_LAYERS, REQUEST, SERVICE, SRS, STYLE, STYLES, TRANSPARENT, VERSION, WIDTH, WMTVER
 
Fields inherited from interface com.bbn.openmap.PropertyConsumer
EditorProperty, initPropertiesProperty, LabelEditorProperty, ScopedEditorProperty
 
Constructor Summary
MapRequestHandler(java.util.Properties props)
           
MapRequestHandler(java.lang.String prefix, java.util.Properties props)
           
 
Method Summary
protected  java.util.Properties convertRequestToProps(java.lang.String request)
           
 java.lang.String getAllLayerNames()
          Get a list of all the layer identifiers that can be used in a request, for the current configuration of the MapRequestHandler.
 java.lang.String getDefaultLayers()
           
 Projection getDefaultProjection()
          Get the Projection being used for parameters in case some parameters are missing from request strings.
 java.lang.String getFormatterContentType(ImageFormatter formatter)
          Given an ImageFormatter, get the HttpConnection content type that matches it.
 java.util.Properties getPropertyInfo(java.util.Properties props)
          Part of the PropertyConsumer interface.
 boolean getUseVisibility()
           
 void handleCapabilitiesRequest(java.util.Properties requestProperties, java.io.OutputStream out)
          Handle a capabilities request.
 byte[] handleMapRequest(java.util.Properties requestProperties)
          Handle a map request, and create and image for it.
 void handleMapRequest(java.util.Properties requestProperties, java.io.OutputStream out)
          Handle a Map Request.
 void handlePanRequest(java.util.Properties requestProperties, java.io.OutputStream out)
          Handle a Pan Request.
 void handleRecenterRequest(java.util.Properties requestProperties, java.io.OutputStream out)
          Handle a Recenter Request.
 byte[] handleRequest(java.lang.String request)
          Given a general request, parse it and handle it.
 void handleRequest(java.lang.String request, java.io.OutputStream out)
          Given a general request, parse it and handle it.
protected  Projection initProjection(java.util.Properties props)
          Set up the default projection, which parts are used if any parts of a projection are missing on an image request.
protected  void loadProjections(java.util.Properties props)
          Method called from initProjection to initialize the ProjectionFactory.
 void setDefaultLayers(java.lang.String dLayers)
          Set the default layers that will be used for requests that don't specify layers.
 void setDefaultProjection(Projection proj)
          Set the default projection to grab parameters from in case some projection terms are missing from the request string.
 void setProperties(java.lang.String prefix, java.util.Properties props)
          Set the layers and image type in the properties.
 void setUseVisibility(boolean value)
          Set whether the layer visibility is used in order to determine default layers for the image.
 
Methods inherited from class com.bbn.openmap.image.ImageServer
calculateVisibleLayerMask, createGraphics, createImage, createImage, createImage, createImage, createImage, createImage, createImageFile, createImageFromLayers, createImageFromLayers, getBackground, getBackground, getDoAntiAliasing, getFormattedImage, getFormatter, getFormatters, getFormatters, getLayers, getLayers, getLayers, getMaskedLayers, getProjectionFactory, getProperties, getPropertyPrefix, getTransparent, main, setBackground, setDoAntiAliasing, setFormatter, setFormatter, setFormatters, setLayers, setProjectionFactory, setProperties, setProperties, setPropertyPrefix, setTransparent, writeImageFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

valueSeparator

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

hexSeparator

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

defaultLayersProperty

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

DefaultLayersProperty

public static final java.lang.String DefaultLayersProperty
The real new property for doing this. The old property, defaultLayersProperty set to openmap.startUpLayers, will work if this is not set. At some point, we should all start using this one, it's just right. (defaultLayers)

See Also:
Constant Field Values

UseVisibilityProperty

public static final java.lang.String UseVisibilityProperty
The property for using visibility of the layers to mark the default layers. The order that they are used depends on how they are specified in the layers property.

See Also:
Constant Field Values

defaultLayers

protected java.lang.String defaultLayers
Comma-separated list of layer scoping prefixes that specify what layers, and their order, should be used for default images where layers are not specified in the request.


defaultProjection

protected Projection defaultProjection
The default projection that provides projection parameters that are missing from the request.


useVisibility

protected boolean useVisibility
The layers' visibility will be set to true at initialization if this property is set, and the layers' visibility will determine if a layer will be part of the image. If you set this flag, then you have to set the layers' visibility yourself. This property takes precedence over the default layers property if both are defined.

Constructor Detail

MapRequestHandler

public MapRequestHandler(java.util.Properties props)
                  throws java.io.IOException
Throws:
java.io.IOException

MapRequestHandler

public MapRequestHandler(java.lang.String prefix,
                         java.util.Properties props)
                  throws java.io.IOException
Throws:
java.io.IOException
Method Detail

setProperties

public void setProperties(java.lang.String prefix,
                          java.util.Properties props)
Description copied from class: ImageServer
Set the layers and image type in the properties. The properties might have a prefix in the file.

Specified by:
setProperties in interface PropertyConsumer
Overrides:
setProperties in class ImageServer
Parameters:
prefix - a String used by the PropertyConsumer to prepend to each property value it wants to look up - setList.getProperty(prefix.propertyKey). If the prefix had already been set, then the prefix passed in should replace that previous value.
props - a Properties object that the PropertyConsumer can use to retrieve expected properties it can use for configuration.

getPropertyInfo

public java.util.Properties getPropertyInfo(java.util.Properties props)
Description copied from class: ImageServer
Part of the PropertyConsumer interface.

Specified by:
getPropertyInfo in interface PropertyConsumer
Overrides:
getPropertyInfo in class ImageServer
Parameters:
props - a Properties object to load the PropertyConsumer properties into. If getList equals null, then a new Properties object should be created.
Returns:
Properties object containing PropertyConsumer property values. If getList was not null, this should equal getList. Otherwise, it should be the Properties object created by the PropertyConsumer.

setUseVisibility

public void setUseVisibility(boolean value)
Set whether the layer visibility is used in order to determine default layers for the image.


getUseVisibility

public boolean getUseVisibility()

initProjection

protected Projection initProjection(java.util.Properties props)
Set up the default projection, which parts are used if any parts of a projection are missing on an image request.

Parameters:
props - the properties to look for openmap projection parameters.
Returns:
a projection created from the properties. A mercator projection is created if no properties pertaining to a projection are found.

loadProjections

protected void loadProjections(java.util.Properties props)
Method called from initProjection to initialize the ProjectionFactory. By default, the standard OpenMap projections are loaded into the ProjectionFactory. If you want those projections replaced or add more projections to the default set, override this method and do what you need. *

Parameters:
props - Properties that can be used to figure out what to do. This implementation of the method doesn't use the Properties.

setDefaultProjection

public void setDefaultProjection(Projection proj)
Set the default projection to grab parameters from in case some projection terms are missing from the request string.


getDefaultProjection

public Projection getDefaultProjection()
Get the Projection being used for parameters in case some parameters are missing from request strings.


setDefaultLayers

public void setDefaultLayers(java.lang.String dLayers)
Set the default layers that will be used for requests that don't specify layers. The String should be a comma separated list of prefix scoping strings for the layer (layer.getPropertyPrefix()).


getDefaultLayers

public java.lang.String getDefaultLayers()

getAllLayerNames

public java.lang.String getAllLayerNames()
Get a list of all the layer identifiers that can be used in a request, for the current configuration of the MapRequestHandler.


convertRequestToProps

protected java.util.Properties convertRequestToProps(java.lang.String request)
                                              throws MapRequestFormatException
Throws:
MapRequestFormatException

handleRequest

public byte[] handleRequest(java.lang.String request)
                     throws java.io.IOException,
                            MapRequestFormatException
Given a general request, parse it and handle it. This is the method that servlets should call. Currently only handles image requests.

Parameters:
request - the request string of key value pairs.
Returns:
a byte[] for the image.
Throws:
java.io.IOException
MapRequestFormatException

handleRequest

public void handleRequest(java.lang.String request,
                          java.io.OutputStream out)
                   throws java.io.IOException,
                          MapRequestFormatException
Given a general request, parse it and handle it. Appends a content type to the output stream which may mess things up for servlets asking for images.

Parameters:
request - the request string of key value pairs.
out - OutputStream to reply on.
Throws:
java.io.IOException
MapRequestFormatException

handleMapRequest

public byte[] handleMapRequest(java.util.Properties requestProperties)
                        throws java.io.IOException,
                               MapRequestFormatException
Handle a map request, and create and image for it.

Parameters:
requestProperties - the request in properties format.
Returns:
byte[] of formatted image.
Throws:
java.io.IOException
MapRequestFormatException

handleMapRequest

public void handleMapRequest(java.util.Properties requestProperties,
                             java.io.OutputStream out)
                      throws java.io.IOException,
                             MapRequestFormatException
Handle a Map Request. Appends a content type to the output stream which may mess things up for servlets.

Throws:
java.io.IOException
MapRequestFormatException

handlePanRequest

public void handlePanRequest(java.util.Properties requestProperties,
                             java.io.OutputStream out)
                      throws java.io.IOException,
                             MapRequestFormatException
Handle a Pan Request.

Throws:
java.io.IOException
MapRequestFormatException

handleRecenterRequest

public void handleRecenterRequest(java.util.Properties requestProperties,
                                  java.io.OutputStream out)
                           throws java.io.IOException,
                                  MapRequestFormatException
Handle a Recenter Request. Appends a content type to the output stream which may mess things up for servlets.

Throws:
java.io.IOException
MapRequestFormatException

getFormatterContentType

public java.lang.String getFormatterContentType(ImageFormatter formatter)
Given an ImageFormatter, get the HttpConnection content type that matches it.


handleCapabilitiesRequest

public void handleCapabilitiesRequest(java.util.Properties requestProperties,
                                      java.io.OutputStream out)
                               throws java.io.IOException,
                                      MapRequestFormatException
Handle a capabilities request.

Throws:
java.io.IOException
MapRequestFormatException


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details