001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.wms.responses.map.kml;
006:
007: import com.vividsolutions.jts.geom.Envelope;
008: import org.geoserver.wms.util.WMSRequests;
009: import org.geotools.map.MapLayer;
010: import org.vfny.geoserver.wms.WMSMapContext;
011: import org.xml.sax.Attributes;
012: import org.xml.sax.helpers.AttributesImpl;
013:
014: /**
015: * Some convenience methods used by the kml transformers.
016: *
017: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
018: * @deprecated use {@link WMSRequests}.
019: */
020: public class KMLUtils {
021: /**
022: * Encodes the url of a GetMap request from a map context + map layer.
023: * <p>
024: * If the <tt>mapLayer</tt> argument is <code>null</code>, the request is
025: * made including all layers in the <tt>mapContexT</tt>.
026: * </p>
027: * <p>
028: * If the <tt>bbox</tt> argument is <code>null</code>. {@link WMSMapContext#getAreaOfInterest()}
029: * is used for the bbox parameter.
030: * </p>
031: *
032: * @param mapContext The map context.
033: * @param mapLayer The Map layer, may be <code>null</code>.
034: * @param bbox The bounding box of the request, may be <code>null</code>.
035: * @param kvp Additional or overidding kvp parameters, may be <code>null</code>
036: * @param tile Flag controlling wether the request should be made against tile cache
037: *
038: * @return The full url for a getMap request.
039: * @deprecated use {@link WMSRequests#getGetMapUrl(WMSMapContext, MapLayer, Envelope, String[])}
040: */
041: public static String getMapUrl(WMSMapContext mapContext,
042: MapLayer mapLayer, Envelope bbox, String[] kvp, boolean tile) {
043:
044: if (tile) {
045: return WMSRequests.getTiledGetMapUrl(mapContext
046: .getRequest(), mapLayer, bbox, kvp);
047:
048: }
049:
050: return WMSRequests.getGetMapUrl(mapContext.getRequest(),
051: mapLayer, bbox, kvp);
052: }
053:
054: /**
055: * Encodes the url of a GetMap request from a map context + map layer.
056: * <p>
057: * If the <tt>mapLayer</tt> argument is <code>null</code>, the request is
058: * made including all layers in the <tt>mapContexT</tt>.
059: * </p>
060: * @param mapContext The map context.
061: * @param mapLayer The Map layer, may be <code>null</code>
062: * @param kvp Additional or overidding kvp parameters, may be <code>null</code>
063: * @param tile Flag controlling wether the request should be made against tile cache
064: *
065: * @return The full url for a getMap request.
066: * @deprecated use {@link WMSRequests#getGetMapUrl(WMSMapContext, MapLayer, Envelope, String[])}
067: */
068: public static String getMapUrl(WMSMapContext mapContext,
069: MapLayer mapLayer, boolean tile) {
070: return getMapUrl(mapContext, mapLayer, mapContext
071: .getAreaOfInterest(), null, tile);
072: }
073:
074: /**
075: * Encodes the url for a GetLegendGraphic request from a map context + map layer.
076: *
077: * @param mapContext The map context.
078: * @param mapLayer The map layer.
079: * @param kvp Additional or overidding kvp parameters, may be <code>null</code>
080: *
081: * @return A map containing all the key value pairs for a GetLegendGraphic request.
082: * @deprecated use {@link WMSRequests#getGetLegendGraphicUrl(WMSMapContext, MapLayer, String[])
083: */
084: public static String getLegendGraphicUrl(WMSMapContext mapContext,
085: MapLayer mapLayer, String[] kvp) {
086: return WMSRequests.getGetLegendGraphicUrl(mapContext
087: .getRequest(), mapLayer, kvp);
088: }
089:
090: /**
091: * Creates sax attributes from an array of key value pairs.
092: *
093: * @param nameValuePairs Alternating key value pair array.
094: *
095: */
096: public static Attributes attributes(String[] nameValuePairs) {
097: AttributesImpl attributes = new AttributesImpl();
098:
099: for (int i = 0; i < nameValuePairs.length; i += 2) {
100: String name = nameValuePairs[i];
101: String value = nameValuePairs[i + 1];
102:
103: attributes.addAttribute("", name, name, "", value);
104: }
105:
106: return attributes;
107: }
108: }
|