Revision 43150

View differences:

tags/org.gvsig.desktop-2.0.173/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/RemoteClientStatus.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient;
26

  
27
import org.gvsig.remoteclient.ogc.OGCClientOperation;
28

  
29
/**
30
 * This class represents the client status at a certain moment
31
 * it describes the "graphic" situation or the requirements of the data
32
 * to be retrieved.
33
 * 
34
 */
35
public abstract class RemoteClientStatus {
36

  
37
	// width and heigh of the map
38
    private int width;
39
    private int height;
40
    
41
    //format of the image to be retrieved
42
    private String format;
43
    private String infoFormat;
44
    // spatial reference system of the image to be retrieved
45
    private String srs;
46
    // exception format, to be retrieved in case of error
47
    private String exceptionFormat;
48
    
49
    //To set if the client has to use GET or POST
50
	private int protocol = OGCClientOperation.PROTOCOL_UNDEFINED;
51

  
52
	public int getWidth() {        
53
        return width;
54
    }
55
    
56
    public void setWidth(int _width) {        
57
    	width = _width;
58
    } 
59

  
60
    public int getHeight() {                
61
        return height;
62
    } 
63
    public void setHeight(int _height) {        
64
        height = _height;
65
    } 
66

  
67
    public String getFormat() {        
68
        return format;
69
    }
70
    
71
    public void setFormat(String _format) {        
72
        format = _format;
73
    } 
74
    
75
    public String getInfoFormat() {        
76
        return infoFormat;
77
    } 
78
    
79
    public void setInfoFormat(String _format) {        
80
        infoFormat = _format;
81
    } 
82

  
83
    public String getSrs() {        
84
        return srs;
85
    } 
86

  
87
    public void setSrs(String _srs) {        
88
        srs = _srs;
89
    } 
90

  
91
    public void setExceptionFormat(String _format) {        
92
        exceptionFormat = _format;
93
    } 
94
    
95
    public String getExceptionFormat() {        
96
        return exceptionFormat;
97
    }
98
    
99
    /**
100
	 * @return the protocol
101
	 */
102
	public int getProtocol() {
103
		return protocol;
104
	}
105

  
106
	/**
107
	 * @param protocol the protocol to set
108
	 */
109
	public void setProtocol(int protocol) {
110
		this.protocol = protocol;
111
	}
112
 
113
 }
0 114

  
tags/org.gvsig.desktop-2.0.173/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/RasterClient.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient;
26

  
27
/**
28
 * <p></p>
29
 * 
30
 */
31
public abstract class RasterClient extends org.gvsig.remoteclient.RemoteClient implements org.gvsig.remoteclient.IRasterClient {
32
 }
0 33

  
tags/org.gvsig.desktop-2.0.173/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/utils/DescribeCoverageTags.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.utils;
25

  
26
public class DescribeCoverageTags {
27
	private DescribeCoverageTags() {};
28
    public static final String COVERAGE_DESCRIPTION = "CoverageDescription";
29
    public static final String COVERAGE_OFFERING = "CoverageOffering";
30
    public static final String NAME = "name";
31
    public static final String LABEL = "label";
32
    public static final String LONLAT_ENVELOPE = "lonLatEnvelope";
33
	public static final String WGS84 = "WGS84(DD)"; // Decimal Degree
34
	public static final String GML_ENVELOPE = "gml:Envelope";
35
	public static final String GML_POS = "gml:pos";
36
	public static final String SRSNAME = "srsName";
37

  
38
	public static final String DOMAINSET = "domainSet";
39
	public static final String SPATIALDOMAIN = "spatialDomain";
40
	public static final String GRID = "gml:Grid";
41
	public static final String RECTIFIEDGRID = "gml:RectifiedGrid";
42
	public static final String GML_GRIDENVELOPE = "gml:GridEnvelope";
43
	public static final String GML_LIMITS = "gml:limits";
44
	public static final String GML_AXISNAME = "gml:axisName";
45
	public static final String GML_ORIGIN = "gml:origin";
46
	public static final String DIMENSION = "dimension";
47
	public static final String GML_LOW = "gml:low";
48
	public static final String GML_HIGH = "gml:high";
49
	public static final String OFFSETVECTOR = "gml:offsetVector";
50
	public static final String TEMPORALDOMAIN = "temporalDomain";
51
	public static final String GML_TIMEPOSITION = "gml:timePosition";
52
	public static final String TIMEPERIOD = "timePeriod";
53
	public static final String BEGINPOSITION = "beginPosition";
54
	public static final String ENDPOSITION = "endPosition";
55
	public static final String TIMERESOLUTION = "timeResolution";
56

  
57
	public static final String RANGESET = "RangeSet";
58
	/* TODO this can cause eventually problems if in a future the "rangeSet" (not "RangeSet")
59
	 * has more than one sub RangeSet subelement since I'm assuming it and a "rangeSet" tag is
60
	 * simply ignored since it has no effect if it just contains one, and only one, RangeSet
61
	 * subelement.
62
	 */
63
	public static final String AXISDESCRIPTION = "AxisDescription" ;
64
	public static final String VALUES = "values";
65
	public static final String SINGLEVALUE = "singleValue";
66
	public static final String INTERVAL = "interval";
67
	public static final String DEFAULT = "default";
68
	public static final String NULLVALUES = "NullValues";
69

  
70
	public static final String SUPPORTED_CRSS = "supportedCRSs";
71
	public static final String REQUEST_RESPONSE_CRSS = "requestResponseCRSs";
72
	public static final String NATIVE_CRS = "nativeCRSs";
73
	public static final String REQUEST_CRSS = "requestCRSs";
74
	public static final String RESPONSE_CRSS = "responseCRSs";
75

  
76
	public static final String SUPPORTED_FORMATS = "supportedFormats";
77
	public static final String NATIVE_FORMAT = "nativeFormat";
78
	public static final String FORMATS = "formats";
79
	public static final String SUPPORTED_INTERPOLATIONS = "supportedInterpolations";
80
	public static final String INTERPOLATION_METHOD = "interpolationMethod";
81

  
82

  
83
}
0 84

  
tags/org.gvsig.desktop-2.0.173/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/utils/Utilities.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.utils;
25

  
26
import java.io.BufferedOutputStream;
27
import java.io.DataOutputStream;
28
import java.io.File;
29
import java.io.FileNotFoundException;
30
import java.io.FileOutputStream;
31
import java.io.FileReader;
32
import java.io.IOException;
33
import java.io.InputStream;
34
import java.io.OutputStream;
35
import java.net.ConnectException;
36
import java.net.URL;
37
import java.net.UnknownHostException;
38
import java.util.Hashtable;
39
import java.util.StringTokenizer;
40
import java.util.Vector;
41

  
42
import org.gvsig.compat.CompatLocator;
43
import org.gvsig.compat.net.Downloader;
44
import org.gvsig.compat.net.ICancellable;
45

  
46

  
47

  
48

  
49
/**
50
 * Clase con m?todos de utilidad en el protocolo WMS
51
 *
52
 * @authors Laura D?az, jaume dominguez faus
53
 */
54
public class Utilities {
55
	private static final Downloader downloader = CompatLocator.getDownloader();
56
    private static String characters;
57
	static boolean canceled;
58
	static final long latency = 500;
59
	/**
60
	 * Used to cancel a group of files
61
	 * <b>key</b>: Group id, <b>value</b>: Boolean (true if
62
	 * the group has to be canceled. Otherwise it is
63
	 * false)
64
	 */
65
	static Hashtable canceledGroup = new Hashtable();
66
	/**
67
	 * <b>key</b>: URL, <b>value</b>: path to the downloaded file.
68
	 */
69
	private static Hashtable downloadedFiles;
70
	static Exception downloadException;
71
	private static final String tempDirectoryPath = System.getProperty("java.io.tmpdir")+"/tmp-andami";
72

  
73

  
74
	static {
75
		characters = "";
76
		for (int j = 32; j<=127; j++){
77
			characters += (char) j;
78
		}
79
		characters += "?????????????????????????????????????????????????\n\r\f\t??";
80
	}
81

  
82

  
83
	/**
84
	 * Checks a File and tries to figure if the file is a text or a binary file.<br>
85
	 * Keep in mind that binary files are those that contains at least one
86
	 * non-printable character.
87
	 *
88
	 * @param file
89
	 * @return <b>true</b> when the file is <b>pretty problably</b> text,
90
	 * <b>false</b> if the file <b>is</b> binary.
91
	 */
92
	public static boolean isTextFile(File file){
93
		return isTextFile(file, 1024);
94
	}
95

  
96
	/**
97
	 * Checks a File and tries to figure if the file is a text or a binary file.<br>
98
	 * Keep in mind that binary files are those that contains at least one
99
	 * non-printable character.
100
	 *
101
	 * @param file
102
	 * @param byteAmount, number of bytes to check.
103
	 * @return <b>true</b> when the file is <b>pretty problably</b> text,
104
	 * <b>false</b> if the file <b>is</b> binary.
105
	 */
106
	public static boolean isTextFile(File file, int byteAmount){
107
		int umbral = byteAmount;
108
		try {
109
			FileReader fr = new FileReader(file);
110
			for (int i = 0; i < umbral; i++) {
111
				int c = fr.read();
112
				if (c==-1){
113
					// End of file. If we reach this
114
					// everything before is printable data.
115
					return true;
116
				}
117
				char ch = (char) c;
118
				if (characters.indexOf(ch)==-1){
119
					// We've found a non-printable character.
120
					// Then we'll assume that this file is binary.
121
					return false;
122
				}
123
			}
124
		} catch (FileNotFoundException e) {
125
			e.printStackTrace();
126
		} catch (IOException e) {
127
			e.printStackTrace();
128
		}
129
		return true;
130
	}
131

  
132
	/**
133
	 * Checks a byte array and tells if it contains only text or contains
134
	 * any binary data.
135
	 *
136
	 * @param file
137
	 * @return <b>true</b> when the data is <b>only</b> text, <b>false</b> otherwise.
138
	 * @deprecated
139
	 */
140
	public static boolean isTextData(byte[] data){
141
		char[] charData = new char[data.length];
142
		for (int i = 0; i<data.length; i++){
143
			charData[i] = (char) data[i];
144
		}
145

  
146
		for (int i = 0; i < data.length; i++) {
147
			int c = charData[i];
148

  
149

  
150
			if (c==-1){
151
				// End of file. If we reach this
152
				// everything before is printable data.
153
				return true;
154
			}
155
			char ch = (char) c;
156
			if (characters.indexOf(ch)==-1){
157
				// We've found a non-printable character.
158
				// Then we'll assume that this file is binary.
159

  
160
				//System.out.println(ch+" at "+i);
161
				return false;
162
			}
163
		}
164
		return true;
165
	}
166

  
167

  
168

  
169

  
170
	/**
171
	 * Copia el contenido de un InputStream en un OutputStream
172
	 *
173
	 * @param in InputStream
174
	 * @param out OutputStream
175
	 */
176
	public static void serializar(InputStream in, OutputStream out) {
177
		byte[] buffer = new byte[102400];
178

  
179
		int n;
180

  
181
		try {
182
			while ((n = in.read(buffer)) != -1) {
183
				out.write(buffer, 0, n);
184
			}
185
		} catch (IOException e) {
186
			e.printStackTrace();
187
		}
188
	}
189

  
190
	/**
191
	 * Elimina del xml la declaraci?n del DTD
192
	 *
193
	 * @param bytes bytes del fichero XML de respuesta a getCapabilities
194
	 * @param startTag Tag raiz del xml respuesta a getCapabilities
195
	 *
196
	 * @return bytes del fichero XML sin la declaraci?n del DTD
197
	 */
198
	public static byte[] eliminarDTD(byte[] bytes, String startTag) {
199
		String text = new String(bytes);
200
		int index1 = text.indexOf("?>") + 2;
201
		int index2;
202

  
203
		try {
204
			index2 = findBeginIndex(bytes, startTag);
205
		} catch (Exception e) {
206
			return bytes;
207
		}
208

  
209
		byte[] buffer = new byte[bytes.length - (index2 - index1)];
210
		System.arraycopy(bytes, 0, buffer, 0, index1);
211
		System.arraycopy(bytes, index2, buffer, index1, bytes.length - index2);
212

  
213
		return buffer;
214
	}
215

  
216
	/**
217
	 * Obtiene el ?ndice del comienzo del xml
218
	 *
219
	 * @param bytes bytes del fichero XML en el que se busca
220
	 * @param tagRaiz Tag raiz del xml respuesta a getCapabilities
221
	 *
222
	 * @return ?ndice donde empieza el tag raiz
223
	 *
224
	 * @throws Exception Si no se encuentra el tag
225
	 */
226
	private static int findBeginIndex(byte[] bytes, String tagRaiz)
227
	throws Exception {
228
		try {
229
			int nodo = 0;
230
			int ret = -1;
231

  
232
			int i = 0;
233

  
234
			while (true) {
235
				switch (nodo) {
236
				case 0:
237

  
238
					if (bytes[i] == '<') {
239
						ret = i;
240
						nodo = 1;
241
					}
242

  
243
					break;
244

  
245
				case 1:
246

  
247
					if (bytes[i] == ' ') {
248
					} else if (bytes[i] == tagRaiz.charAt(0)) {
249
						nodo = 2;
250
					} else {
251
						nodo = 0;
252
					}
253

  
254
					break;
255

  
256
				case 2:
257

  
258
					String aux = new String(bytes, i, 18);
259

  
260
					if (aux.equalsIgnoreCase(tagRaiz.substring(1))) {
261
						return ret;
262
					}
263

  
264
					nodo = 0;
265

  
266
					break;
267
				}
268

  
269
				i++;
270
			}
271
		} catch (Exception e) {
272
			throw new Exception("No se pudo parsear el xml", e);
273
		}
274
	}
275

  
276
	/**
277
	 * Converts the contents of a Vector to a comma separated list
278
	 *
279
	 * */
280
	public static String Vector2CS(Vector v)
281
	{
282
		String str = new String();
283
		if (v != null)
284
		{
285
			int i;
286
			for (i=0; i<v.size() ;i++)
287
			{
288
				str = str + v.elementAt(i);
289
				if (i<v.size()-1)
290
					str = str + ",";
291
			}
292
		}
293
		return str;
294
	}
295

  
296
	public static boolean isValidVersion(String version)
297
	{
298
		if(version.trim().length() == 5)
299
		{
300
			if ( (version.charAt(1)=='.') && (version.charAt(3)=='.'))
301
			{
302
				char x = version.charAt(0);
303
				char y = version.charAt(2);
304
				char z = version.charAt(4);
305

  
306
				if ((Character.isDigit(x)) && (Character.isDigit(y)) && (Character.isDigit(z)))
307
				{
308
					return true;
309
				}
310
				else
311
				{
312
					return false;
313
				}
314
			}
315
			else
316
			{
317
				return false;
318
			}
319
		}
320
		else
321
		{
322
			return false;
323
		}
324
	}
325

  
326
	/**
327
	 * Crea un fichero temporal con un nombre concreto y unos datos pasados por
328
	 * par?metro.
329
	 * @param fileName Nombre de fichero
330
	 * @param data datos a guardar en el fichero
331
	 */
332
	public static void createTemp(String fileName, String data)throws IOException{
333
		File f = new File(fileName);
334
		DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(f)) );
335
		dos.writeBytes(data);
336
		dos.close();
337
		f.deleteOnExit();
338
	}
339

  
340
	/**
341
	 * Checks if a String is a number or not
342
	 *
343
	 * @param String, s
344
	 * @return boolean, true if s is a number
345
	 */
346
	public static boolean isNumber(String s)
347
	{
348
		try
349
		{
350
			//double d = Double.parseDouble(s);
351
			return true;
352
		}
353
		catch(NumberFormatException e)
354
		{
355
			return false;
356
		}
357

  
358
	}
359

  
360
	/**
361
	 * Parses the String containing different items [character] separated and
362
	 * creates a vector with them.
363
	 * @param str String contains item1[c]item2[c]item3...
364
	 * @param c is the string value for separating the items
365
	 * @return Vector containing all the items
366
	 */
367
	public static Vector createVector(String str, String c)
368
	{
369
		StringTokenizer tokens = new StringTokenizer(str, c);
370
		Vector v = new Vector();
371
		try
372
		{
373
			while (tokens.hasMoreTokens())
374
			{
375
				v.addElement(tokens.nextToken());
376
			}
377
			return v;
378
		}
379
		catch (Exception e)
380
		{
381
			return new Vector();
382
		}
383
	}
384

  
385
	/**
386
	 * @param dimensions
387
	 * @return
388
	 */
389
	public static String Vector2URLParamString(Vector v) {
390
		if (v==null) return "";
391
		String s = "";
392
		for (int i = 0; i < v.size(); i++) {
393
			s += v.get(i);
394
			if (i<v.size()-1)
395
				s += "&";
396
		}
397
		return s;
398
	}
399
	
400
	/**
401
	 * Downloads an URL into a temporary file that is removed the next time the
402
	 * tempFileManager class is called, which means the next time gvSIG is launched.
403
	 *
404
	 * @param url
405
	 * @param name
406
	 * @return
407
	 * @throws IOException
408
	 * @throws ServerErrorResponseException
409
	 * @throws ConnectException
410
	 * @throws UnknownHostException
411
	 */
412
	public static synchronized File downloadFile(URL url, String name, ICancellable cancel) throws IOException,ConnectException, UnknownHostException{
413
	    return downloader.downloadFile(url, name, cancel);
414
	}
415
	
416
	private static String calculateFileName(String name){
417
		int index = name.lastIndexOf(".");
418
		if (index > 0){
419
			return tempDirectoryPath + "/" + name.substring(0,index) + System.currentTimeMillis() + 
420
				name.substring(index, name.length());
421
		}
422
		return tempDirectoryPath+"/"+name+System.currentTimeMillis();
423
	}
424

  
425
	/**
426
	 * Downloads a URL using the HTTP Post protocol
427
	 * @param url
428
	 * The server URL
429
	 * @param data
430
	 * The data to send in the request
431
	 * @param name
432
	 * A common name for all the retrieved files
433
	 * @param cancel
434
	 * Used to cancel the downloads
435
	 * @return
436
	 * The retrieved file
437
	 * @throws IOException
438
	 * @throws ConnectException
439
	 * @throws UnknownHostException
440
	 */
441
	public static synchronized File downloadFile(URL url, String data, String name, ICancellable cancel) throws IOException,ConnectException, UnknownHostException{
442
	    return downloader.downloadFile(url, data, name, cancel);
443
	}
444
        
445
	public static synchronized File downloadFile(URL url, String data, String name, ICancellable cancel, int maxbytes) throws IOException,ConnectException, UnknownHostException{
446
	    return downloader.downloadFile(url, data, name, cancel,maxbytes);
447
	}
448

  
449
	/**
450
	 * Cleans every temporal file previously downloaded.
451
	 */
452
	public static void cleanUpTempFiles() {
453
		downloader.cleanUpTempFiles();
454
	}
455

  
456

  
457
	/**
458
	 * Remove an URL from the system cache. The file will remain in the file
459
	 * system for further eventual uses.
460
	 * @param request
461
	 */
462
	public static void removeURL(URL url) {
463
		downloader.removeURL(url);
464
	}
465

  
466
	/**
467
	 * Remove an URL from the system cache. The file will remain in the file
468
	 * system for further eventual uses.
469
	 * @param request
470
	 */
471
	public static void removeURL(Object url) {
472
	    downloader.removeURL(url);
473
	}
474
	
475
        
476
        public static String getAbsolutePathOrEmpty(File f) {
477
            if( f==null ) {
478
                return "";
479
            }
480
            return f.getAbsolutePath();
481
        }
482
        
483
        /**
484
	 * This class has to be deleted when all the classes uses the ICancellable
485
	 * method from libCompat
486
	 * @author gvSIG Team
487
	 * @version $Id: Utilities.java 33983 2010-10-27 12:37:48Z nbrodin $
488
	 * @deprecated You should use always org.gvsig.compat.net.ICancellable
489
	 */
490
	/*private static class CancellableAdapter implements org.gvsig.compat.net.ICancellable {
491
	    private ICancellable cancellable = null;
492

  
493
        public CancellableAdapter(
494
            org.gvsig.remoteclient.wms.ICancellable cancellable) {
495
            super();
496
            this.cancellable = cancellable;
497
        }
498

  
499
        public Object getID() {            
500
            return cancellable.getID();
501
        }
502

  
503
        public boolean isCanceled() {     
504
            return cancellable.isCanceled();
505
        } 	    
506
	}*/
507

  
508
}
0 509

  
tags/org.gvsig.desktop-2.0.173/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/utils/BoundaryBox.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.utils;
26

  
27
public class BoundaryBox {
28
    
29
    private double xmin;
30

  
31
    private double xmax;
32
    private double ymin;
33
    private double ymax;
34
    private String srs;
35
    public double getXmin() {        
36
        return xmin;
37
    } 
38
    public void setXmin(double _xmin) {        
39
        xmin = _xmin;
40
    } 
41
    public double getXmax() {        
42
        return xmax;
43
    } 
44
    public void setXmax(double _xmax) {        
45
        xmax = _xmax;
46
    } 
47
    public double getYmin() {        
48
        return ymin;
49
    } 
50
    public void setYmin(double _ymin) {        
51
        ymin = _ymin;
52
    } 
53
    public double getYmax() {        
54
        return ymax;
55
    } 
56
    public void setYmax(double _ymax) {        
57
        ymax = _ymax;
58
    } 
59
    public String getSrs() {        
60
        return srs;
61
    } 
62
    public void setSrs(String _srs) {        
63
        srs = _srs;
64
    }
65
    
66
    public String toString(){
67
        String s = srs + " (" + xmin + ", " + ymin + ", " + xmax + ", " + ymax + ")";
68
        
69
        return s;
70
    }
71
    
72
    public static boolean validLat(double v) {
73
        return v >= -90 && v <= 90;
74
    }
75
    
76
    public static boolean validLon(double v) {
77
        return v >= -180 && v <= 180;
78
    }
79
    
80
    public static BoundaryBox clipGeodeticBBox(BoundaryBox bbox) {
81
        
82
        BoundaryBox resp = new BoundaryBox();
83
        resp.setSrs(bbox.getSrs());
84
        resp.setXmin(bbox.getXmin());
85
        resp.setXmax(bbox.getXmax());
86
        resp.setYmin(bbox.getYmin());
87
        resp.setYmax(bbox.getYmax());
88
        
89
        // ==================================================
90
        // Fix longitude
91
        // ==================================================
92
        if (resp.getXmax() > resp.getXmin()
93
            && validLon(resp.getXmin()) && !validLon(resp.getXmax())) {
94
            // only xmax is wrong:
95
            resp.setXmax(180);
96
        } else {
97
            if (resp.getXmax() > resp.getXmin()
98
                && !validLon(resp.getXmin()) && validLon(resp.getXmax())) {
99
                // only xmin is wrong:
100
                resp.setXmin(-180);
101
            } else {
102
                if (resp.getXmax() > resp.getXmin()
103
                    && validLon(resp.getXmin()) && validLon(resp.getXmax())) {
104
                    // OK, do nothing
105
                } else {
106
                    resp.setXmax(180);
107
                    resp.setXmin(-180);
108
                }
109
            }
110
        }
111
        // ==================================================
112
        // Fix latitude
113
        // ==================================================
114
        if (resp.getYmax() > resp.getYmin()
115
            && validLat(resp.getYmin()) && !validLat(resp.getYmax())) {
116
            // only ymax is wrong:
117
            resp.setYmax(90);
118
        } else {
119
            if (resp.getYmax() > resp.getYmin()
120
                && !validLat(resp.getYmin()) && validLat(resp.getYmax())) {
121
                // only ymin is wrong:
122
                resp.setYmin(-90);
123
            } else {
124
                if (resp.getYmax() > resp.getYmin()
125
                    && validLat(resp.getYmin()) && validLat(resp.getYmax())) {
126
                    // OK, do nothing
127
                } else {
128
                    // box was a mess, let's fix it
129
                    resp.setYmax(90);
130
                    resp.setYmin(-90);
131
                }
132
            }
133
        }
134
        // ===============================================
135
        return resp;
136
        
137
    }
138
 }
0 139

  
tags/org.gvsig.desktop-2.0.173/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/utils/DateTime.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.remoteclient.utils;
26
import java.util.Calendar;
27
import java.util.Date;
28
import java.util.GregorianCalendar;
29
import java.util.Locale;
30

  
31
/**
32
 * This class contains static methods to manage Dates. It was principally 
33
 * created because of some problems doing the "String do DateTime" 
34
 * and the "DateTime to String" conversions.  
35
 * 
36
 * @author Jorge Piera Llodr� (piera_jor@gva.es)
37
 */
38
public class DateTime {
39

  
40
/**
41
 * returns the current date
42
 * 
43
 * 
44
 * @return java.util.Date
45
 */
46
    public static Date getCurrentDate() {        
47
        Calendar cal = new GregorianCalendar();
48
 
49
        return cal.getTime();
50
    } 
51

  
52
/**
53
 * It trnasforms one date in one String
54
 * 
55
 * 
56
 * @return A String
57
 * @param dtK Date
58
 * @param sFormat Date format. Example: "Y-m-d H:i:s.Z";
59
 */
60
    public static String dateToString(Date dtK, String sFormat) {        
61
        String sDate;
62
        int nYear;
63
        int nMonth;
64
        int nDay;
65
        int nHour;
66
        int nMinute;
67
        int nSecond;
68
        int nMS;
69
        Calendar clnK;
70
        String sf;
71
        int jc;
72
        clnK = Calendar.getInstance(Locale.US);
73
        clnK.setTime(dtK);
74
        nYear = clnK.get(Calendar.YEAR);
75
        nMonth = 1 + clnK.get(Calendar.MONTH);
76
        nDay = clnK.get(Calendar.DAY_OF_MONTH);
77
        nHour = clnK.get(Calendar.HOUR_OF_DAY);
78
        nMinute = clnK.get(Calendar.MINUTE);
79
        nSecond = clnK.get(Calendar.SECOND);
80
        nMS = clnK.get(Calendar.MILLISECOND);
81
        sDate = "";
82
        for (jc = 0; jc < sFormat.length(); jc++) {
83
            switch (sFormat.charAt(jc)) {
84
                case 'Y':
85
                    sDate += nYear;
86
                    break;
87
                case 'm':
88
                    sf = "" + nMonth;
89
                    if (nMonth < 10) {
90
                        sf = "0" + sf;
91
                    }
92
                    sDate += sf;
93
                    break;
94
                case 'd':
95
                    sf = "" + nDay;
96
                    if (nDay < 10) {
97
                        sf = "0" + sf;
98
                    }
99
                    sDate += sf;
100
                    break;
101
                case 'H':
102
                    sf = "" + nHour;
103
                    if (nHour < 10) {
104
                        sf = "0" + sf;
105
                    }
106
                    sDate += sf;
107
                    break;
108
                case 'i':
109
                    sf = "" + nMinute;
110
                    if (nMinute < 10) {
111
                        sf = "0" + sf;
112
                    }
113
                    sDate += sf;
114
                    break;
115
                case 's':
116
                    sf = "" + nSecond;
117
                    if (nSecond < 10) {
118
                        sf = "0" + sf;
119
                    }
120
                    sDate += sf;
121
                    break;
122
                case 'Z':
123
                    sf = "" + nMS;
124
                    if (nMS < 10) {
125
                        sf = "0" + sf;
126
                    }
127
                    sDate += sf;
128
                    break;
129
                default:
130
                    sDate += sFormat.substring(jc, jc + 1);
131
            }
132
        }
133
        return sDate;
134
    } 
135
   
136
/**
137
 * It transfoms one String in one Date
138
 * 
139
 * 
140
 * @return Date
141
 * @param sDate String
142
 */
143
    public static Date stringToDate(String sDate) {        
144
        Date dtRes;
145
        Calendar clnK;
146
        int nYear;
147
        int nMonth;
148
        int nDay;
149
        int nHour;
150
        int nMinute;
151
        int nSecond;
152
        int nMS;
153
        String sf;
154
        for (; sDate.length() < 23;)
155
            sDate += "0";
156
        sf = sDate.substring(0, 4);
157
        nYear = Integer.parseInt(sf);
158
        sf = sDate.substring(5, 7);
159
        nMonth = Integer.parseInt(sf) - 1;
160
        sf = sDate.substring(8, 10);
161
        nDay = Integer.parseInt(sf);
162
        sf = sDate.substring(11, 13);
163
        nHour = Integer.parseInt(sf);
164
        sf = sDate.substring(14, 16);
165
        nMinute = Integer.parseInt(sf);
166
        sf = sDate.substring(17, 19);
167
        nSecond = Integer.parseInt(sf);
168
        sf = sDate.substring(20, 23);
169
        nMS = Integer.parseInt(sf);
170
        clnK = Calendar.getInstance(Locale.US);
171
        clnK.set(nYear, nMonth, nDay, nHour, nMinute, nSecond);
172
        clnK.set(Calendar.MILLISECOND, nMS);
173
        dtRes = new Date();
174
        dtRes = clnK.getTime();
175
        //	    sf=dateToString(dtRes,"Y-m-d H:i:s.Z");
176
        return dtRes;
177
    } 
178
 }
0 179

  
tags/org.gvsig.desktop-2.0.173/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/utils/ExceptionTags.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.utils;
25

  
26
/**
27
 * @author jaume
28
 *
29
 */
30
public class ExceptionTags {
31
	private ExceptionTags() {};
32
    public final static String EXCEPTION_ROOT="ServiceExceptionReport";
33
    public final static String SERVICE_EXCEPTION="ServiceException";
34
    public final static String CODE="code";
35
}
0 36

  
tags/org.gvsig.desktop-2.0.173/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/utils/PropertyManager.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.utils;
25

  
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.util.Hashtable;
29
import java.util.Properties;
30

  
31
/**
32
 * Description: Loads the configuration files
33
 *
34
 * @author  Laura Diaz
35
 * @version 1.0 
36
 */
37
public class PropertyManager
38
{
39
 public final static String LOGGER_PROPERTIES = "org/gvsig/remoteClient/conf/logger.properties";
40
 
41
 //The property file names to load
42
 private final static String[] s_propertyFileNames = new String[]{LOGGER_PROPERTIES};
43
 																	
44

  
45
 //Hashtable containing all properties objects that are loaded
46
 private static Hashtable s_propertyFiles = null;
47

  
48
 /**
49
 * Gets a properties object
50
 * If the the property files are not yet loaded, then loads them first
51
 *
52
 * @param propertyFileName, String
53
 * @return Properties
54
 * @throws java.io.IOException
55
 */
56
 public static Properties getProperties(String propertyFileName) throws IOException
57
 {
58
   if (s_propertyFiles == null)
59
   {
60
     loadProperties();
61
   }
62

  
63
   return (Properties)s_propertyFiles.get(propertyFileName);
64
 }
65

  
66
 //Loads the property files
67
 private static synchronized void loadProperties() throws IOException
68
 {
69
   s_propertyFiles = new Hashtable(s_propertyFileNames.length);
70
   ClassLoader loader = PropertyManager.class.getClassLoader();
71

  
72
   for (int i = 0; i < s_propertyFileNames.length; i++)
73
   {
74
     try
75
     {
76
       InputStream input = loader.getResourceAsStream(s_propertyFileNames[i]);
77
       Properties props = new Properties();
78
       props.load(input);
79
       s_propertyFiles.put(s_propertyFileNames[i], props);
80
     }
81
     catch(Exception e)
82
     {
83
     	System.err.println("\n[PropertyManager] ERROR - Failed to read properties file \""
84
                          + s_propertyFileNames[i] + "\": "
85
                          + e.getMessage());       
86
     }
87
   }
88
 }
89
 
90
 //Loads the property files
91
 /*
92
 public static synchronized void saveProperties(String propsName) throws IOException
93
 {  
94
     try
95
     {	 
96
	  //ClassLoader loader = PropertyManager.class.getClassLoader();    	  
97
	  //InputStream input = loader.getResourceAsStream(propsName);    	      	
98
	   FileOutputStream output = new FileOutputStream(propsName);
99
	   Properties props = new Properties();
100
	   props.store(output, propsName);
101
	   output.close();            
102
     }
103
     catch(Exception e)
104
     {
105
     	System.err.println("\n[PropertyManager] ERROR - Failed to save properties file \""
106
                          + propsName + "\": "
107
                          + e.getMessage());       
108
     }
109
 }
110
*/
111
 
112
 
113
}
0 114

  
tags/org.gvsig.desktop-2.0.173/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/utils/EncodingXMLParser.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.utils;
25

  
26
import java.io.BufferedReader;
27
import java.io.File;
28
import java.io.FileInputStream;
29
import java.io.FileReader;
30
import java.io.IOException;
31
import java.io.StringReader;
32

  
33
import org.kxml2.io.KXmlParser;
34
import org.xmlpull.v1.XmlPullParserException;
35

  
36
/**
37
 * This class is a XML pull parser that discover and manage
38
 * the file encoding
39
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
40
 */
41
public class EncodingXMLParser extends KXmlParser{
42

  
43
	/**
44
	 * This method reads the first bytes of the file and
45
	 * try to discover the file encoding. It parses the file
46
	 * with retrieved encoding.
47
	 * @param file
48
	 * @throws XmlPullParserException 
49
	 * @throws IOException 
50
	 */
51
	public void setInput(File file) throws XmlPullParserException, IOException{
52
		FileReader reader = null;
53
		reader = new FileReader(file);
54
		BufferedReader br = new BufferedReader(reader);
55
		String encoding = "UTF-8";
56

  
57
		char[] buffer = new char[(int) file.length()];
58
		reader.read(buffer);
59
		String string = new String(buffer);
60

  
61
		// patch for ArcIMS + WMS connector > 9.0 bug
62
		int a = string.toLowerCase().indexOf("<?xml");
63
		if (a !=-1){
64
			string = string.substring(a, string.length());
65
		}
66
		// end patch
67

  
68
		StringBuffer st = new StringBuffer(string);
69
		String searchText = "encoding=\"";
70
		int index = st.indexOf(searchText);
71
		if (index>-1) {
72
			st.delete(0, index+searchText.length());
73
			encoding = st.substring(0, st.indexOf("\""));
74
		}			
75
		
76
		if (a > 0){
77
			// patch for ArcIMS + WMS connector > 9.0 bug
78
			super.setInput(new StringReader(string));
79
			// end patch
80
		}else{
81
			super.setInput( new FileInputStream(file), encoding);
82
		}
83
	}
84
}
85

  
0 86

  
tags/org.gvsig.desktop-2.0.173/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/utils/DumbXMLParser.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.utils;
25
import java.awt.geom.Rectangle2D;
26
import java.util.TreeMap;
27

  
28
/**
29
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
30
 */
31
public class DumbXMLParser {
32
	public Rectangle2D getBoundingBox(String l) {
33
		// System.out.println("l='"+l+"'");
34
		TreeMap pairs = getPairs(l);
35
		return getBoundingBox(pairs);
36
	}
37

  
38
	public Rectangle2D getBoundingBox(TreeMap pairs) {
39
		double minX = Double.parseDouble((String)pairs.get("minx"));
40
		double minY = Double.parseDouble((String)pairs.get("miny"));
41
		double maxX = Double.parseDouble((String)pairs.get("maxx"));
42
		double maxY = Double.parseDouble((String)pairs.get("maxy"));
43

  
44
		return new Rectangle2D.Double(minX, minY, maxX-minX, maxY-minY);
45
	}
46
	
47
	public TreeMap getPairs(String l) {
48
		TreeMap data = new TreeMap();
49
		int pos = l.indexOf("=");
50
		while (pos>0) {
51
			String cmd = l.substring(l.lastIndexOf(" ", pos)+1,
52
				l.indexOf("\"", pos+2)+1);
53
			//System.out.println(cmd);
54
			int comilla = cmd.indexOf("\"");
55
			if (comilla > 0) {
56
				String key = l.substring(l.lastIndexOf(" ", pos)+1, pos);
57
				String value = cmd.substring(comilla+1,cmd.length()-1);
58
				data.put(key.toLowerCase(), value);
59
			}
60
			pos = l.indexOf("=", pos+1);
61
		}
62
		return data;
63
	}
64
	
65
	/**
66
	 * saca un valor double de una linea del tipo 
67
	 * <westBoundLongitude>-180</westBoundLongitude>
68
	 * @param l
69
	 * @return
70
	 */
71
	public double getValueDouble(String l) {
72
		return Double.parseDouble(getValue(l));	
73
	}
74
	
75
	/**
76
	 * saca un valor double de una linea del tipo 
77
	 * <westBoundLongitude>-180</westBoundLongitude>
78
	 * @param l
79
	 * @return
80
	 */
81
	public String getValue(String l) {
82
		int pos = l.indexOf(">");
83
		return l.substring(pos+1, l.indexOf("<", pos));	
84
	}
85
	
86
	public String getToken(String l, int num) {
87
		int pos = l.indexOf("<");
88
		for (int i=0; i<num; i++)
89
			pos = l.indexOf("<", pos+1);
90
		return l.substring(pos+1, l.indexOf(">", pos));	
91
	}
92
	
93
	public int countTokens(String l) {
94
		int times = 0;
95
		int pos = l.indexOf("<");
96
		while (pos >= 0) {
97
			times ++; pos = l.indexOf("<", pos+1);
98
		}
99
		return times;
100
	}
101
}
0 102

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff