Revision 4493

View differences:

trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/utils/DescribeCoverageTags.java
90 90
	public static final String DEFAULT = "default";
91 91
	public static final String NULLVALUES = "NullValues";
92 92
	
93
	public static final String SUPPORTEDCRSS = "supportedCRSs";
94
	public static final String REQUESTRESPONSECRSS = "requestResponseCRSs";
95
	public static final String NATIVECRS = "nativeCRSs";
96
	public static final String REQUESTCRSS = "requestCRSs";
97
	public static final String RESPONSECRSS = "responseCRSs";
93
	public static final String SUPPORTED_CRSS = "supportedCRSs";
94
	public static final String REQUEST_RESPONSE_CRSS = "requestResponseCRSs";
95
	public static final String NATIVE_CRS = "nativeCRSs";
96
	public static final String REQUEST_CRSS = "requestCRSs";
97
	public static final String RESPONSE_CRSS = "responseCRSs";
98 98
	
99
	public static final String SUPPORTEDFORMATS = "supportedFormats";
100
	public static final String NATIVEFORMAT = "nativeFormat";
99
	public static final String SUPPORTED_FORMATS = "supportedFormats";
100
	public static final String NATIVE_FORMAT = "nativeFormat";
101 101
	public static final String FORMATS = "formats";
102
	public static final String SUPPORTED_INTERPOLATIONS = "supportedInterpolations";
103
	public static final String INTERPOLATION_METHOD = "interpolationMethod";
102 104
	
103 105
	
104 106
}
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/exceptions/WCSException.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

  
42
/* CVS MESSAGES:
43
*
44
* $Id$
45
* $Log$
46
* Revision 1.1  2006-03-21 11:30:27  jaume
47
* some wcs client operation stuff
48
*
49
*
50
*/
51
package org.gvsig.remoteClient.exceptions;
52

  
53
/**
54
 * Excepci?n provocada por el WCS.
55
 *
56
 * @author Jaume Dominguez Faus - jaume.dominguez@iver.es
57
 */
58
public class WCSException extends Exception 
59
{	
60
	private String wcs_message = null;
61
	
62
	/**
63
	 *
64
	 */
65
	public WCSException() {
66
		super();
67
	}
68

  
69
	/**
70
	 * Creates a new WCS Exception
71
	 *
72
	 * @param message
73
	 */
74
	public WCSException(String message) {
75
		super(message);
76
	}
77

  
78
	/**
79
	 * Creates a new WCS Exception
80
	 *
81
	 * @param message
82
	 * @param cause
83
	 */
84
	public WCSException(String message, Throwable cause) {
85
		super(message, cause);
86
	}
87

  
88
	/**
89
	 * Creates a new WCSException
90
	 *
91
	 * @param cause
92
	 */
93
	public WCSException(Throwable cause) {
94
		super(cause);
95
	}
96
	
97
	public String getWCSMessage()
98
	{
99
		if (wcs_message == null)
100
			return "";
101
		else
102
			return wcs_message;
103
	}
104
	
105
	public void setWCSMessage(String mes)
106
	{
107
		wcs_message = mes;
108
	}
109
}
110

  
111

  
0 112

  
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wms/wms_1_1_0/WMSProtocolHandler1_1_0.java
152 152
    	}
153 153
    	parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.SERVICE);
154 154
    }
155
    
155 156
    /**
156 157
     * <p>Parses the Capability Tag </p>
157 158
     */    
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wcs/WCSStatus.java
41 41
/*
42 42
 * $Id$ 
43 43
 * $Log$
44
 * Revision 1.2  2006-03-15 08:54:42  jaume
44
 * Revision 1.3  2006-03-21 11:30:26  jaume
45
 * some wcs client operation stuff
46
 *
47
 * Revision 1.2  2006/03/15 08:54:42  jaume
45 48
 * *** empty log message ***
46 49
 *
47 50
 * Revision 1.1.2.1  2006/03/08 09:08:31  jaume
......
54 57
package org.gvsig.remoteClient.wcs;
55 58

  
56 59
import java.awt.geom.Rectangle2D;
60
import java.util.Vector;
57 61

  
58 62
import org.gvsig.remoteClient.RemoteClientStatus;
59 63

  
60 64
public class WCSStatus extends RemoteClientStatus {
61
	private String layerName;
62
	private String time;
63
	private String parameter;
64
	private String resolution;
65
	private Rectangle2D bBox;
66
	private String coverageName;
67
	private String onlineResource;
65
	private String		layerName		= null;
66
	private String		time			= null;
67
	private String		parameter		= null;
68
	private String		resolution		= null;
69
	private Rectangle2D	bBox			= null;
70
	private String		coverageName	= null;
71
	private String		onlineResource	= null;
72
	private Integer		depth			= null;
73
	private String		times			= null;
74
	private String		parameters		= null;
68 75
	
69 76
	public void setExtent(Rectangle2D bBox) {
70 77
		this.bBox = bBox;
......
89 96
	public String getOnlineResource() {
90 97
		return onlineResource;
91 98
	}
99

  
100

  
101
	public String getCoverageName() {
102
		return this.coverageName;
103
	}
92 104
	
105
	public Rectangle2D getExtent() {
106
		return this.bBox;
107
	}
108

  
109

  
110
	public Integer getDepth() {
111
		return depth;
112
	}
113

  
114
	public String getTime() {
115
		return times;
116
	}
117
	
118
	public String getParameters() {
119
		return parameters;
120
	}
93 121
}
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wcs/WCSCoverage.java
72 72
	public  Hashtable 		axisPool = new Hashtable();
73 73
	private String 			nativeSRS;
74 74
	private ArrayList 		supportedSRSs = new ArrayList();
75
	private ArrayList		interpolationMethods;
75 76
	private String 			nativeFormat; 
76 77
	private ArrayList 		formats = new ArrayList();
77 78
	
......
211 212
        lonLatBbox = box;
212 213
    }   
213 214

  
215
    public void addInterpolationMethod(String method) {
216
    	if (interpolationMethods==null) interpolationMethods = new ArrayList();
217
    	interpolationMethods.add(method);
218
    }
219
    
220
    public ArrayList getInterpolationMethods() {
221
    	return interpolationMethods;
222
    }
214 223
    /**
215 224
     * Parses the fragment of the XML document that describes this layer (or coverage)
216 225
     * @param parser
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wcs/wcs_1_0_0/WCSCoverage1_0_0.java
91 91
                    	parseDomainSet(parser);
92 92
                    } else if (parser.getName().compareTo(DescribeCoverageTags.RANGESET) == 0) {
93 93
                    	parseRangeSet(parser);
94
                    } else if (parser.getName().compareTo(DescribeCoverageTags.SUPPORTEDCRSS) == 0) {
94
                    } else if (parser.getName().compareTo(DescribeCoverageTags.SUPPORTED_CRSS) == 0) {
95 95
                    	parseSupportedCRSS(parser);
96
                    } else if (parser.getName().compareTo(DescribeCoverageTags.SUPPORTEDFORMATS) == 0) {
97
                    	setNativeFormat(parser.getAttributeValue("", DescribeCoverageTags.NATIVEFORMAT));
96
                    } else if (parser.getName().compareTo(DescribeCoverageTags.SUPPORTED_FORMATS) == 0) {
97
                    	setNativeFormat(parser.getAttributeValue("", DescribeCoverageTags.NATIVE_FORMAT));
98 98
                    	parser.nextTag();
99 99
                    	parser.require(KXmlParser.START_TAG, null, DescribeCoverageTags.FORMATS);
100 100
                    	String[] formats = parser.nextText().split(SEPARATOR);
101 101
                    	for (int i = 0; i < formats.length; i++) {
102 102
							addFormat(formats[i]);
103 103
						}
104
                    } else if (parser.getName().compareTo(DescribeCoverageTags.SUPPORTED_INTERPOLATIONS) == 0) {
105
                    	boolean bInterpolationsEnd = false;
106
                    	int interpolationsTag = parser.next();
107
                    	while (!bInterpolationsEnd) {
108
                    		switch(interpolationsTag) {
109
	                    		case KXmlParser.START_TAG:
110
	                    			if (parser.getName().compareTo(DescribeCoverageTags.INTERPOLATION_METHOD)==0) {
111
	                    				addInterpolationMethod(parser.nextText());
112
	                    			}
113
	                    			break;
114
	                    		case KXmlParser.END_TAG:
115
	                    			if (parser.getName().compareTo(DescribeCoverageTags.SUPPORTED_INTERPOLATIONS) == 0)
116
	                    				bInterpolationsEnd = true;
117
	                    			break;
118
	                    		case KXmlParser.TEXT:
119
	                    			if (parser.getName()!=null)
120
	                    				System.out.println("[TAG]["+parser.getName()+"]\n[TEXT]["+parser.getText().trim()+"]");    
121
	                    			break;
122
                    		}
123
                    		interpolationsTag = parser.next();
124
                    	}
104 125
                    } else {
105 126
                    	if (!parser.getName().equals("rangeSet")) // just a patch to avoid too much messages
106 127
                    		System.out.println("Skiped "+parser.getName());
......
118 139
             }
119 140
             currentTag = parser.next();
120 141
        }
121
        
122
        
123 142
    }
124 143

  
125 144
    private void parseSupportedCRSS(KXmlParser parser) throws XmlPullParserException, IOException {
126 145
    	int currentTag;
127 146
    	boolean end = false;
128 147
    	
129
    	parser.require(KXmlParser.START_TAG, null, DescribeCoverageTags.SUPPORTEDCRSS);
148
    	parser.require(KXmlParser.START_TAG, null, DescribeCoverageTags.SUPPORTED_CRSS);
130 149
    	currentTag = parser.next();
131 150
    	
132 151
    	while (!end) 
......
134 153
    		switch(currentTag)
135 154
    		{
136 155
	    		case KXmlParser.START_TAG:
137
	    			if (parser.getName().compareTo(DescribeCoverageTags.REQUESTRESPONSECRSS)==0) {
156
	    			if (parser.getName().compareTo(DescribeCoverageTags.REQUEST_RESPONSE_CRSS)==0) {
138 157
	    				String[] values = parser.nextText().split(SEPARATOR);
139 158
	    				for (int i = 0; i < values.length; i++) {
140 159
							addSRSs(values[i]);
141 160
						}
142 161
	    			}
143
	    			else if (parser.getName().compareTo(DescribeCoverageTags.NATIVECRS) == 0) {
162
	    			else if (parser.getName().compareTo(DescribeCoverageTags.NATIVE_CRS) == 0) {
144 163
	    				setNativeSRS(parser.nextText());
145
	    			} else if (parser.getName().compareTo(DescribeCoverageTags.REQUESTCRSS) == 0) {
164
	    			} else if (parser.getName().compareTo(DescribeCoverageTags.REQUEST_CRSS) == 0) {
146 165
	    				// TODO
147 166
                    	System.out.println("Skiped "+parser.getName());
148
	    			} else if (parser.getName().compareTo(DescribeCoverageTags.RESPONSECRSS) == 0) {
167
	    			} else if (parser.getName().compareTo(DescribeCoverageTags.RESPONSE_CRSS) == 0) {
149 168
	    				// TODO
150 169
                    	System.out.println("Skiped "+parser.getName());
151 170
                    } else {
......
154 173
	    				
155 174
	    			break;
156 175
	    		case KXmlParser.END_TAG:
157
	    			if (parser.getName().compareTo(DescribeCoverageTags.SUPPORTEDCRSS) == 0)
176
	    			if (parser.getName().compareTo(DescribeCoverageTags.SUPPORTED_CRSS) == 0)
158 177
	    				end = true;
159 178
	    			break;
160 179
	    		case KXmlParser.TEXT: 
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wcs/WCSClient.java
41 41
package org.gvsig.remoteClient.wcs;
42 42

  
43 43
import java.awt.geom.Rectangle2D;
44
import java.io.File;
44 45
import java.io.IOException;
45 46
import java.net.ConnectException;
46 47
import java.util.ArrayList;
47 48
import java.util.Hashtable;
48 49
import java.util.Iterator;
49 50

  
51
import org.gvsig.remoteClient.exceptions.ServerErrorException;
52
import org.gvsig.remoteClient.exceptions.WCSException;
50 53
import org.gvsig.remoteClient.utils.BoundaryBox;
51 54
import org.gvsig.remoteClient.wcs.wcs_1_0_0.WCSProtocolHandler1_0_0;
52 55
import org.gvsig.remoteClient.wms.WMSProtocolHandlerFactory;
......
159 162
        double ymax = bbox.getYmax();
160 163
		return new Rectangle2D.Double(xmin, ymin, xmax-xmin, ymax-ymin);
161 164
	}
162
	
165

  
166
	public File getCoverage(WCSStatus status) throws ServerErrorException, WCSException {
167
		return handler.getCoverage(status);
168
	}
163 169
}
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wcs/WCSProtocolHandler.java
41 41
package org.gvsig.remoteClient.wcs;
42 42

  
43 43
import java.io.File;
44
import java.io.FileInputStream;
45
import java.io.IOException;
44 46
import java.net.URL;
47
import java.nio.ByteBuffer;
48
import java.nio.channels.FileChannel;
45 49
import java.util.ArrayList;
46 50
import java.util.HashMap;
47 51
import java.util.Hashtable;
48 52
import java.util.Vector;
49 53

  
50 54
import org.gvsig.remoteClient.OGCProtocolHandler;
55
import org.gvsig.remoteClient.exceptions.ServerErrorException;
56
import org.gvsig.remoteClient.exceptions.WCSException;
57
import org.gvsig.remoteClient.utils.Utilities;
51 58
/**
52 59
 * 
53 60
 * @author jaume
......
137 144
        }
138 145
    }
139 146
    
140
    public void getCoverage() {
147
    public File getCoverage(WCSStatus status) throws ServerErrorException, WCSException {
148
    	URL request = null;
149
		try
150
		{
151
			//TODO:
152
			//pass this buildXXXRequest to the WCSProtocolHandlerXXX: The request can depend on the WCS version.
153
			request = new URL(buildCoverageRequest(status));
154
            
155
            File f = com.iver.andami.Utilities.downloadFile(request, "wcsGetMap");            		    	
156
	    	
157
            if (Utilities.isTextFile(f)) {
158
	    		FileInputStream fis = new FileInputStream(f);
159
	    		FileChannel fc = fis.getChannel();
160
	    		byte[] data = new byte[(int)fc.size()];   // fc.size returns the size of the file which backs the channel
161
	    		ByteBuffer bb = ByteBuffer.wrap(data);
162
	    		fc.read(bb);
163
	    		
164
	    		WCSException wcsEx = null;
165
               	
166
            	String exceptionMessage = parseException(data);
167
                if (exceptionMessage==null)
168
                {
169
                 	String error = new String(data);
170
                	int pos = error.indexOf("<?xml");
171
                	if (pos!= -1)
172
                	{
173
                		String xml = error.substring(pos,error.length());
174
                		exceptionMessage = parseException(xml.getBytes());
175
                	}               
176
                    if (exceptionMessage == null)
177
                    	exceptionMessage = new String(data);
178
                	
179
                }
180
             	wcsEx = new WCSException(exceptionMessage);
181
            	wcsEx.setWCSMessage(new String(data));
182
            	
183
            	// Since it is an error file, It must be deleted from the cache
184
            	com.iver.andami.Utilities.removeURL(request);
185
                throw wcsEx;
186
            }
187
			return f;	    	
188
		}
189
		catch(IOException e)
190
		{
191
			e.printStackTrace();
192
            throw new ServerErrorException();
193
		}
194
    } 
195
    
196
    
197
    
198
    private String parseException(byte[] bytes) {
199
		// TODO Auto-generated method stub
200
		return null;
201
	}
202

  
203
	/**
204
     * Builds the GetMapRequest according to the OGC WCS Specifications
205
     */
206
    private String buildCoverageRequest(WCSStatus status)
207
    { 
208
		StringBuffer req = new StringBuffer();
209
		String symbol = null;
210
		String onlineResource = null;
211
		
212
		if (status.getOnlineResource() == null)
213
			onlineResource = getHost();
214
		else 
215
			onlineResource = status.getOnlineResource();
216
		symbol = getSymbol(onlineResource);
141 217
        
218
		req.append(onlineResource + symbol + "REQUEST=GetMap&SERVICE=WCS&VERSION=").append(getVersion()).append("&");
219
		req.append(getPartialQuery(status));
220
       if (status.getExceptionFormat() != null) {
221
            req.append("&EXCEPTIONS=" + status.getExceptionFormat());
222
        } else {
223
            req.append("&EXCEPTIONS=XML");
224
        }
225
		return req.toString().replaceAll(" ", "%20");
142 226
    }
143 227
    
144 228
    /**
229
     * Gets the part of the OGC request that share GetMap and GetFeatureInfo
230
     * @return String request
231
     */
232
    public String getPartialQuery(WCSStatus status)
233
    {    	
234
        StringBuffer req = new StringBuffer();
235
        req.append("COVERAGE=" + status.getCoverageName())
236
           .append("&SRS=" + status.getSrs())
237
           .append("&BBOX=" + status.getExtent().getMinX()+ "," )
238
           .append(status.getExtent().getMinY()+ ",")
239
           .append(status.getExtent().getMaxX()+ ",")
240
           .append(status.getExtent().getMaxY())
241
           .append("&WIDTH=" + status.getWidth())
242
           .append("&HEIGHT=" + status.getHeight())
243
           .append( (status.getDepth() != null) ? "&DEPTH="+status.getDepth().intValue() : "" )
244
           .append( (status.getTime() != null) ? "&TIME="+status.getTime() : "" )
245
           .append( (status.getParameters() != null) ? "&"+status.getParameters() : "");
246
       
247
        return req.toString();
248
    }
249
    
250
    /**
145 251
     * Builds the GetCapabilitiesRequest according to the OGC WCS Specifications
146 252
     * without a VERSION, to get the highest version than a WCS supports.
147 253
     */
......
153 259
        	req += ("&VERSION=" + _version);
154 260
        }
155 261
		req += ("&EXCEPTIONS=XML");
156
		return req;   	
262
		return req.toString().replaceAll(" ", "%20");   	
157 263
    }
158 264
    
159 265
    

Also available in: Unified diff