Revision 34316

View differences:

branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/request/WMTSGetFeatureInfoRequest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 Iver T.I.  {{Task}}
26
*/
27
 
28
package org.gvsig.remoteclient.wmts.request;
29

  
30
import org.gvsig.remoteclient.utils.CapabilitiesTags;
31
import org.gvsig.remoteclient.wmts.WMTSProtocolHandler;
32
import org.gvsig.remoteclient.wmts.WMTSStatus;
33

  
34
/**
35
 * Base class for WMTS GetFeatureInfo
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public abstract class WMTSGetFeatureInfoRequest extends WMTSRequest {
39
	protected int x;
40
	protected int y;
41
	
42
	public WMTSGetFeatureInfoRequest(WMTSStatus status, WMTSProtocolHandler protocolHandler, int x, int y) {
43
		super(status, protocolHandler);	
44
		this.x = x;
45
		this.y = y;
46
	}
47

  
48
	/*
49
	 * (non-Javadoc)
50
	 * @see org.gvsig.remoteclient.ogc.request.OGCRequest#getHttpPostRequest(java.lang.String)
51
	 */
52
	protected String getHttpPostRequest(String onlineResource) {
53
		// TODO Auto-generated method stub
54
		return null;
55
	}
56

  
57
	/*
58
	 * (non-Javadoc)
59
	 * @see org.gvsig.remoteclient.ogc.request.OGCRequest#getOperationName()
60
	 */
61
	protected String getOperationName() {
62
		return CapabilitiesTags.GETFEATUREINFO;
63
	}
64

  
65
	/*
66
	 * (non-Javadoc)
67
	 * @see org.gvsig.remoteClient.wfs.requests.WFSRequest#getTempFilePrefix()
68
	 */
69
	protected String getTempFilePrefix() {
70
		return "wms_getFeatureInfo.xml";
71
	}
72
}
73

  
74

  
0 75

  
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/wmts_1_0_0/request/WMTSGetFeatureInfoRequest1_0_0.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 Iver T.I.  {{Task}}
26
*/
27
 
28
package org.gvsig.remoteclient.wmts.wmts_1_0_0.request;
29

  
30
import org.gvsig.remoteclient.utils.CapabilitiesTags;
31
import org.gvsig.remoteclient.wmts.WMTSProtocolHandler;
32
import org.gvsig.remoteclient.wmts.WMTSStatus;
33
import org.gvsig.remoteclient.wmts.request.WMTSGetFeatureInfoRequest;
34

  
35
/**
36
 * GetFeatureInfo for WMTS version 1.1.0
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 */
39
public class WMTSGetFeatureInfoRequest1_0_0 extends WMTSGetFeatureInfoRequest {
40
    
41
    //private static final StringUtils stringUtils = CompatLocator.getStringUtils();
42
	
43
    public WMTSGetFeatureInfoRequest1_0_0(WMTSStatus status,
44
			WMTSProtocolHandler protocolHandler, int x, int y) {
45
		super(status, protocolHandler, x, y);		
46
	}
47

  
48
	/*
49
	 * (non-Javadoc)
50
	 * @see org.gvsig.remoteClient.ogc.request.OGCRequest#getHttpGetRequest(java.lang.String)
51
	 */
52
	protected String getHttpGetRequest(String onlineResource) {
53
		StringBuffer req = new StringBuffer();
54
		WMTSStatus stat = (WMTSStatus)status;
55
		req.append(onlineResource);
56
		req.append("Request=GetFeatureInfo");
57
		req.append("&Service=WMTS");
58
		req.append("&Version=" + protocolHandler.getVersion());
59
		req.append("&Layer=" + stat.getLayer());
60
		req.append("&Format=" + stat.getFormat());
61
		req.append("&Style=" + stat.getStyle());
62
		req.append("&TileMatrixSet=" + stat.getTileMatrixSet());
63
		req.append("&TileMatrix=" + stat.getTileMatrix());
64
		req.append("&TileRow=" + stat.getTileRow());
65
		req.append("&TileCol=" + stat.getTileCol());
66
		req.append("&J=" + y);
67
		req.append("&I=" + x);
68
		req.append("&InfoFormat=" + stat.getInfoFormat());
69
		return req.toString();
70
	}
71
	
72
	/**
73
	 * @return the exceptions format
74
	 */
75
	protected String getExceptionsFormat(){
76
		return CapabilitiesTags.EXCEPTIONS_1_1_x;
77
	}
78

  
79
}
80

  
0 81

  
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/wmts_1_0_0/WMTSProtocolHandler1_0_0.java
31 31
import org.gvsig.remoteclient.wmts.WMTSServerDescription;
32 32
import org.gvsig.remoteclient.wmts.WMTSStatus;
33 33
import org.gvsig.remoteclient.wmts.request.WMTSGetCapabilitiesRequest;
34
import org.gvsig.remoteclient.wmts.request.WMTSGetFeatureInfoRequest;
34 35
import org.gvsig.remoteclient.wmts.request.WMTSGetTileRequest;
35 36
import org.gvsig.remoteclient.wmts.struct.WMTSLayer;
36 37
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrixSet;
37 38
import org.gvsig.remoteclient.wmts.wmts_1_0_0.request.WMTSGetCapabilitiesRequest1_0_0;
39
import org.gvsig.remoteclient.wmts.wmts_1_0_0.request.WMTSGetFeatureInfoRequest1_0_0;
38 40
import org.gvsig.remoteclient.wmts.wmts_1_0_0.request.WMTSGetTileRequest1_0_0;
39 41
import org.kxml2.io.KXmlParser;
40 42
import org.xmlpull.v1.XmlPullParserException;
......
190 192
	 */
191 193
	protected WMTSGetTileRequest createGetTileRequest(WMTSStatus status) {
192 194
		return new WMTSGetTileRequest1_0_0(status, this);
193
	}    
195
	}
196
	
197
	/*
198
	 * (non-Javadoc)
199
	 * @see org.gvsig.remoteclient.wmts.WMTSProtocolHandler#createGetFeatureInfoRequest(org.gvsig.remoteclient.wmts.WMTSStatus, int, int)
200
	 */
201
	protected WMTSGetFeatureInfoRequest createGetFeatureInfoRequest(WMTSStatus status, int x, int y) {
202
		return new WMTSGetFeatureInfoRequest1_0_0(status, this, x, y);
203
	}
194 204
}
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/WMTSClient.java
109 109
    public void getCapabilities(WMTSServerDescription serverDescription, boolean override, ICancellable cancel) {        
110 110
        handler.getCapabilities(serverDescription, override, cancel);
111 111
    } 
112
    
113
    /**
114
     * <p>It will send a GetFeatureInfo request to the WMTS
115
     * Parsing the response and redirecting the info to the WMTS client</p>
116
     */
117
    public String getFeatureInfo(WMTSStatus status, int x, int y, int featureCount, ICancellable cancel) {
118
    	return handler.getFeatureInfo(status, x, y, featureCount, cancel);
119
    }
112 120

  
113 121
	/*
114 122
	 * (non-Javadoc)
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/WMTSProtocolHandler.java
23 23

  
24 24
import java.io.ByteArrayInputStream;
25 25
import java.io.File;
26
import java.io.FileReader;
26 27
import java.io.IOException;
28
import java.net.URL;
27 29
import java.util.ArrayList;
28 30
import java.util.StringTokenizer;
29 31

  
......
36 38
import org.gvsig.remoteclient.wms.WMSServiceInformation;
37 39
import org.gvsig.remoteclient.wmts.exception.WMTSException;
38 40
import org.gvsig.remoteclient.wmts.request.WMTSGetCapabilitiesRequest;
41
import org.gvsig.remoteclient.wmts.request.WMTSGetFeatureInfoRequest;
39 42
import org.gvsig.remoteclient.wmts.request.WMTSGetTileRequest;
40 43
import org.kxml2.io.KXmlParser;
41 44
import org.xmlpull.v1.XmlPullParserException;
......
51 54
	 */
52 55
	protected String                 encoding    = "UTF-8";
53 56
    protected WMSServiceInformation  serviceInfo = null;
57
    
58
    protected abstract WMTSGetFeatureInfoRequest createGetFeatureInfoRequest(WMTSStatus status, int x, int y);
54 59

  
55 60
    protected abstract WMTSGetTileRequest createGetTileRequest(WMTSStatus status);
56 61
    
......
99 104
            throw new ServerErrorException();
100 105
		}
101 106
    }
107
    
108
	/**
109
     * <p>It will send a GetFeatureInfo request to the WMTS
110
     * Parsing the response and redirecting the info to the WMTS client</p>
111
     * TODO: return a stored file instead a String.
112
     */
113
    public String getFeatureInfo(WMTSStatus status, int x, int y, int featureCount, ICancellable cancel) {
114
    	StringBuffer output = new StringBuffer();
115
    	String outputFormat = new String();
116
    	String ServiceException = "ServiceExceptionReport";
117
    	StringBuffer sb = new StringBuffer();
118
    	sb.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
119
		try {
120
			WMTSGetFeatureInfoRequest request = createGetFeatureInfoRequest(status, x, y);
121
			URL url = request.getURL();
122
	    	outputFormat = url.openConnection().getContentType();
123
	    	File f = request.sendRequest(cancel);
124
			if (f == null) {
125
				return "";
126
			}
102 127

  
128
			FileReader fReader = new FileReader(f);
129
			char[] buffer = new char[1024*256];
130
			for (int i = fReader.read(buffer); i > 0; i = fReader.read(buffer)) {
131
		    	String str = new String(buffer,0,i);
132
		    	output.append(str);
133
		    }
134
		    if ( (outputFormat == null) || (outputFormat.indexOf("xml") != -1)
135
		    		||output.toString().toLowerCase().startsWith("<?xml")
136
		    		||(outputFormat.indexOf("gml") != -1)) {
137
		    	KXmlParser kxmlParser = null;
138
		    	kxmlParser = new KXmlParser();
139
		    	//kxmlParser.setInput(new StringReader(output.toString()));
140
		    	kxmlParser.setInput(new FileReader(f));
141

  
142
		    	kxmlParser.nextTag();
143
		    	if (kxmlParser.getName().compareTo(ServiceException) == 0) {
144
		    		sb.append("<INFO>").append(parseException( output.toString().getBytes())).append("</INFO>");
145
		    		return sb.toString();
146
				} else if (kxmlParser.getName().compareToIgnoreCase("ERROR") == 0) {
147
					return output.toString();
148
				} else {
149
					return output.toString();
150
				}
151
	    	} else {  		
152
	    		 return output.toString();
153
	    	}
154
		} catch(XmlPullParserException parserEx) {
155
    		if (output.toString().toLowerCase().indexOf("xml") != -1) {
156
    			return output.toString().trim();
157
    		} else {
158
    	   		sb.append("<INFO>").append("Info format not supported").append("</INFO>");
159
        		return sb.toString();
160
    		}
161
    	} catch(Exception e) {
162
    		e.printStackTrace();
163
    		sb.append("<INFO>").append("Info format not supported").append("</INFO>");
164
    		return sb.toString();
165
    	}
166
    }
167

  
103 168
    /**
104 169
	 * <p>Builds a GetCapabilities request that is sent to the WMS
105 170
	 * the response will be parse to extract the data needed by the
branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wmts/WMTSStatus.java
38 38
	private int        tileCol        = -1;
39 39
	private int        tileRow        = -1;
40 40
	private ArrayList  tileList       = null;
41
	private String     infoFormat     = null;
41 42

  
42 43
	public String getLayer() {
43 44
		return layer;
......
94 95
	public void setTileList(ArrayList tileList) {
95 96
		this.tileList = tileList;
96 97
	}
98
	
99
    public String getInfoFormat() {        
100
        return this.infoFormat;
101
    } 
102
    
103
    public void setInfoFormat(String format) {        
104
    	this.infoFormat = format;
105
    }
97 106
}

Also available in: Unified diff