📄 maprequesthandler.java
字号:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/image/MapRequestHandler.java,v $// $RCSfile: MapRequestHandler.java,v $// $Revision: 1.6.2.5 $// $Date: 2005/08/09 19:18:31 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.image;import java.io.IOException;import java.io.OutputStream;import java.net.URLDecoder;import java.util.Properties;import java.util.Vector;import com.bbn.openmap.Layer;import com.bbn.openmap.layer.util.http.HttpConnection;import com.bbn.openmap.proj.Proj;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.proj.ProjectionFactory;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PropUtils;import com.bbn.openmap.util.PropertyStringFormatException;/** * 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. * <P> * * 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. * <P> * * 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). * <P> * * 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. */public class MapRequestHandler extends ImageServer implements ImageServerConstants { public final static String valueSeparator = ","; public final static String hexSeparator = "%"; public final static String defaultLayersProperty = OpenMapPrefix + "startUpLayers"; /** * 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) */ public final static String DefaultLayersProperty = "defaultLayers"; /** * 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. */ public final static String UseVisibilityProperty = "useLayerVisibility"; /** * 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. */ protected String defaultLayers; /** * The default projection that provides projection parameters that * are missing from the request. */ protected Projection defaultProjection; /** * 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. */ protected boolean useVisibility = false; public MapRequestHandler(Properties props) throws IOException { this(null, props); } public MapRequestHandler(String prefix, Properties props) throws IOException { setProperties(prefix, props); } public void setProperties(String prefix, Properties props) { super.setProperties(prefix, props); prefix = PropUtils.getScopedPropertyPrefix(prefix); defaultProjection = initProjection(props); defaultLayers = props.getProperty(prefix + DefaultLayersProperty); if (defaultLayers == null) { defaultLayers = props.getProperty(defaultLayersProperty); } setUseVisibility(PropUtils.booleanFromProperties(props, prefix + UseVisibilityProperty, getUseVisibility())); } public Properties getPropertyInfo(Properties props) { props = super.getPropertyInfo(props); // Still have to do projection, and default layers. props.put(UseVisibilityProperty, "Flag to use layer visibility settings to determine default layers"); return props; } /** * Set whether the layer visibility is used in order to determine * default layers for the image. */ public void setUseVisibility(boolean value) { useVisibility = value; } public boolean getUseVisibility() { return useVisibility; } /** * Set up the default projection, which parts are used if any * parts of a projection are missing on an image request. * * @param props the properties to look for openmap projection * parameters. * @return a projection created from the properties. A mercator * projection is created if no properties pertaining to a * projection are found. */ protected Projection initProjection(Properties props) { loadProjections(props); Projection proj = ProjectionFactory.getDefaultProjectionFromEnvironment(); if (Debug.debugging("imageserver")) { Debug.output("MRH starting with default projection = " + proj); } return proj; } /** * 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. * * * @param props Properties that can be used to figure out what to * do. This implementation of the method doesn't use the * Properties. */ protected void loadProjections(Properties props) { ProjectionFactory.loadDefaultProjections(); } /** * Set the default projection to grab parameters from in case some * projection terms are missing from the request string. */ public void setDefaultProjection(Projection proj) { defaultProjection = proj; } /** * Get the Projection being used for parameters in case some * parameters are missing from request strings. */ public Projection getDefaultProjection() { return defaultProjection; } /** * 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()). */ public void setDefaultLayers(String dLayers) { defaultLayers = dLayers; } public String getDefaultLayers() { return defaultLayers; } /** * Get a list of all the layer identifiers that can be used in a * request, for the current configuration of the * MapRequestHandler. */ public String getAllLayerNames() { Layer[] layers = getLayers(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < layers.length; i++) { sb.append((i > 0 ? " " : "") + layers[i].getPropertyPrefix()); } return sb.toString(); } protected Properties convertRequestToProps(String request) throws MapRequestFormatException { try { // Convert any %XX to the real ASCII value. request = URLDecoder.decode(request, "UTF-8"); Properties requestProperties = PropUtils.parsePropertyList(request); if (Debug.debugging("imageserver")) { Debug.output("MRH: parsed request " + requestProperties); } return requestProperties; } catch (PropertyStringFormatException psfe) { throw new MapRequestFormatException(psfe.getMessage()); } catch (Exception e) { throw new MapRequestFormatException(e.getMessage()); } } /** * Given a general request, parse it and handle it. This is the * method that servlets should call. Currently only handles image * requests. * * @param request the request string of key value pairs. * @return a byte[] for the image.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -