001: /*
002: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004: * under the terms of the GNU Lesser General Public License as published by the Free Software
005: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008: */
009: package net.refractions.udig.tool.info;
010:
011: import java.io.IOException;
012: import java.net.URL;
013: import java.text.MessageFormat;
014:
015: import net.refractions.udig.project.ILayer;
016: import net.refractions.udig.tool.info.internal.Messages;
017:
018: /**
019: * The response to a getInfo request of a service w.r.t. a layer.
020: * <p>
021: * This LayerPointInfo object allows the wrapping arbitrary content, providing type information as a MIME
022: * type, and the possability of lazy access.
023: * </p>
024: * <p>
025: * This class is expected to be subclassed inorder to perform lazy parsing via a custom
026: * implementation of getValue();
027: * </p>
028: */
029: public abstract class LayerPointInfo {
030:
031: /**
032: * Layer responsible for providing this information.
033: */
034: ILayer layer;
035:
036: /**
037: * Used to indicate an NOT_FOUND result.
038: * <p>
039: * Not found is different from "unavailable".
040: * </p>
041: */
042: public static final LayerPointInfo NOT_FOUND = new LayerPointInfo(
043: null) {
044: public String getMimeType() {
045: return ""; //$NON-NLS-1$
046: }
047:
048: public Object acquireValue() {
049: return null;
050: }
051: };
052: /** The mime type for gml - aka Feature */
053: public static final String GML = "application/vnd.ogc.gml"; //$NON-NLS-1$
054:
055: /** The mime type for text/plain */
056: public static final String TEXT = "text/plain"; //$NON-NLS-1$
057:
058: /** The mime type for text/html */
059: public static final String HTML = "text/html"; //$NON-NLS-1$
060:
061: /** The mime type for text/xml */
062: public static final String XML = "text/xml"; //$NON-NLS-1$
063:
064: /** Server Error - value is Exception or String */
065: public static final String ERROR = "application/vnd.ogc.se_xml"; //$NON-NLS-1$
066:
067: /** Construct an LayerPointInfo for the provided Layer */
068: public LayerPointInfo(ILayer layer) {
069: this .layer = layer;
070: }
071:
072: /**
073: * Subclass must implement to acquire value in a lazy manner.
074: * <p>
075: * The default implementation will make the request specified by getRequestURL().getContent();
076: * </p>
077: *
078: * @return Object to be used as the Value of this LayerPointInfo
079: * @throws IOException if an IO error occurs during the request process
080: */
081: public Object acquireValue() throws IOException {
082: return getRequestURL().getContent();
083: }
084:
085: /**
086: * The data's MIME type.
087: * <p>
088: * Well known MIME types:
089: * <ul>
090: * <li>"application/vnd.ogc.gml" - represents a FeatureCollection
091: * <li>"text/html" - represents a web page
092: * <li>"text/plain"
093: * <li>"" - indicates LayerPointInfo.EMPTY
094: * </ul>
095: * </p>
096: * <p>
097: * The system may be extended at a later time to allow the use of additional MIME types. The
098: * goal should be to allow the complete set used in WMS getFeatureInfo opperations.
099: * </p>
100: *
101: * @see http://www.w3.org/Protocols/HTTP/1.1/spec.html#MIME
102: */
103: abstract public String getMimeType();
104:
105: /**
106: * Request url, if applicable, will be sent to an embded browser or something similar.
107: * <p>
108: * For *real objects* please just return the default value, aka null. acquireValue will be
109: * called.
110: * </p>
111: *
112: * @return requested URL or null if working with a real objects.
113: */
114: public URL getRequestURL() {
115: return null;
116: }
117:
118: /**
119: * Layer responsible for providing this information.
120: * <p>
121: * Can be used as a back point to focus the map on the indicated hit.
122: * </p>
123: *
124: * @return Returns the layer.
125: */
126: public ILayer getLayer() {
127: return layer;
128: }
129:
130: /** @return LayerPointInfo mimeType : request */
131: public String toString() {
132: return MessageFormat.format(Messages.LayerPointInfo_toString,
133: new Object[] { getMimeType(), getRequestURL() });
134: }
135: }
|