Revision 16013

View differences:

org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.165/org.gvsig.raster.wms.io/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.wms.io.DefaultWMSIOLibrary
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.165/org.gvsig.raster.wms.io/src/main/resources/org/gvsig/raster/wms/io/i18n/text.properties
1
error_connecting=Error conectando con el servidor
2
malformed_url=URL mal formada
0 3

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.165/org.gvsig.raster.wms.io/src/main/resources/org/gvsig/raster/wms/io/i18n/text_en.properties
1
error_connecting=Error connecting with the server
2
malformed_url=Malformed URL
0 3

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.165/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/DefaultWMSIOLibrary.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
package org.gvsig.raster.wms.io;
23

  
24
import org.gvsig.i18n.Messages;
25
import org.gvsig.raster.wms.io.time.DefaultDimension;
26
import org.gvsig.raster.wms.io.time.TimeDimension;
27
import org.gvsig.tools.library.AbstractLibrary;
28
import org.gvsig.tools.library.LibraryException;
29
/**
30
 *
31
 * @author Nacho Brodin (nachobrodin@gmail.com)
32
 */
33
public class DefaultWMSIOLibrary extends AbstractLibrary {
34

  
35
	/*public DefaultWMSIOLibrary() {
36
		super(DefaultWMSIOLibrary.class,Library.TYPE.IMPL);
37
		require(ToolsLibrary.class);
38
		require(DALLibrary.class);
39
		require(DALFileLibrary.class);
40
	}*/
41

  
42
	@Override
43
	protected void doInitialize() throws LibraryException {
44
		//RasterLibrary.wakeUp();
45
		WMSLayerNode.registerPersistent();
46
		RemoteWMSStyle.registerPersistent();
47
		DefaultDimension.registerPersistent();
48
		TimeDimension.registerPersistent();
49

  
50
		Messages.addResourceFamily("org.gvsig.raster.wms.io.i18n.text",
51
				DefaultWMSIOLibrary.class.getClassLoader(),
52
				DefaultWMSIOLibrary.class.getClass().getName());
53
	}
54

  
55
	@Override
56
	protected void doPostInitialize() throws LibraryException {
57
		WMSServerExplorerParameters.registerDynClass();
58
		WMSDataParametersImpl.registerDynClass();
59
		WMSProvider.register();
60
	}
61
}
0 62

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.165/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/WMSLayerNode.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
package org.gvsig.raster.wms.io;
23

  
24
import java.awt.Dimension;
25
import java.util.ArrayList;
26
import java.util.List;
27

  
28
import org.gvsig.raster.wms.io.time.DefaultDimension;
29
import org.gvsig.raster.wms.io.time.RemoteTimeDimension;
30
import org.gvsig.raster.wms.io.time.TimeDimension;
31
import org.gvsig.tools.ToolsLocator;
32
import org.gvsig.tools.dynobject.DynStruct;
33
import org.gvsig.tools.persistence.PersistenceManager;
34
import org.gvsig.tools.persistence.Persistent;
35
import org.gvsig.tools.persistence.PersistentState;
36
import org.gvsig.tools.persistence.exception.PersistenceException;
37

  
38
/**
39
 * Class defining the node of the layer tree of a common WMS service.
40
 * @author jaume
41
 */
42
@SuppressWarnings("unchecked")
43
public class WMSLayerNode implements Persistent {
44
    private String                         _name              = null;
45
    private String                         _title             = null;
46
	private List<String>                   srs                = null;
47
    private boolean                        queryable;
48
    private boolean                        transparency;
49
    private String                         lAbstract          = null;
50
    private String                         latLonBox          = null;
51
    private int                            selectedStyleIndex = 0;
52
    private List<RemoteWMSStyle>           styles             = new ArrayList<RemoteWMSStyle>();
53
    private List<RemoteTimeDimension>      dimensions         = null;
54
    private List<String>                   keywords           = null;
55
    private List<WMSLayerNode>             children           = new ArrayList<WMSLayerNode>();
56
    private WMSLayerNode                   _parent            = null;
57
	private Dimension                      fixedSize          = null;
58
	
59
	public void loadFromState(PersistentState state) throws PersistenceException {
60
		this._name = state.getString("_name");
61
		this._title = state.getString("_title");
62
		this.srs = state.getList("srs");
63
		this.queryable = state.getBoolean("queryable");
64
		this.transparency = state.getBoolean("transparency");
65
		this.lAbstract = state.getString("lAbstract");
66
		this.latLonBox = state.getString("latLonBox");
67
		this.selectedStyleIndex = state.getInt("selectedStyleIndex");
68
		this.styles = state.getList("styles");
69
		this.dimensions = state.getList("dimensions");
70
		this.keywords = state.getList("keywords");
71
		this.children = state.getList("children");
72
		this._parent = (WMSLayerNode)state.get("_parent");
73
		this.fixedSize = (Dimension)state.get("fixedSize");
74
	}
75
	
76
	public void saveToState(PersistentState state) throws PersistenceException {
77
		state.set("_name", _name);
78
		state.set("_title", _title);
79
		state.set("srs", srs);
80
		state.set("queryable", queryable);
81
		state.set("transparency", transparency);
82
		state.set("lAbstract", lAbstract);
83
		state.set("latLonBox", latLonBox);
84
		state.set("selectedStyleIndex", selectedStyleIndex);
85
		state.set("styles", styles);
86
		state.set("dimensions", dimensions);
87
		state.set("keywords", keywords);
88
		state.set("children", children);
89
		state.set("_parent", _parent);
90
		state.set("fixedSize", fixedSize);
91
	}	
92
    
93
    public static void registerPersistent() {
94
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
95
		DynStruct definition = manager.getDefinition("WMSLayerNode_Persistent");
96
		if( definition == null ) {
97
			definition = manager.addDefinition(
98
					WMSLayerNode.class,
99
					"WMSLayerNode_Persistent",
100
					"WMSLayerNode Persistence",
101
					null, 
102
					null
103
			);
104
		}
105

  
106
		definition.addDynFieldString("_name").setMandatory(false);
107
		definition.addDynFieldString("_title").setMandatory(false);
108
		definition.addDynFieldList("srs").setClassOfItems(String.class).setMandatory(false);
109
		definition.addDynFieldBoolean("queryable").setMandatory(false);
110
		definition.addDynFieldBoolean("transparency").setMandatory(false);
111
		definition.addDynFieldString("lAbstract").setMandatory(false);
112
		definition.addDynFieldString("latLonBox").setMandatory(false);		
113
		definition.addDynFieldInt("selectedStyleIndex").setMandatory(false);
114
		definition.addDynFieldList("styles").setClassOfItems(RemoteWMSStyle.class).setMandatory(false);
115
		definition.addDynFieldList("dimensions").setClassOfItems(RemoteTimeDimension.class).setMandatory(false);
116
		definition.addDynFieldList("keywords").setClassOfItems(String.class).setMandatory(false);
117
		definition.addDynFieldList("children").setClassOfItems(WMSLayerNode.class).setMandatory(false);
118
		definition.addDynFieldObject("_parent").setClassOfValue(WMSLayerNode.class).setMandatory(false);
119
		definition.addDynFieldObject("fixedSize").setClassOfValue(Dimension.class).setMandatory(false);
120
	}
121

  
122
	/**
123
     * @return Returns the name.
124
     */
125
    public String getName() {
126
        return _name;
127
    }
128

  
129
    public List<WMSLayerNode> getChildren() {
130
        return children;
131
    }
132

  
133
    /**
134
     * @param name The name to set.
135
     */
136
    public void setName(String name) {
137
        this._name = name;
138
    }
139

  
140
    /**
141
     * @return Returns the namedStyles.
142
     */
143
    public List<RemoteWMSStyle> getStyles() {
144
        return styles;
145
    }
146

  
147
    public List<String> getKeywords() {
148
    	return keywords;
149
    }
150
   
151
    /**
152
     * @return Returns the queryable.
153
     */
154
    public boolean isQueryable() {
155
        return queryable;
156
    }
157

  
158
    /**
159
     * @param queryable The queryable to set.
160
     */
161
    public void setQueryable(boolean queryable) {
162
        this.queryable = queryable;
163
    }
164
    
165
    /**
166
     * @return Returns the srs.
167
     */
168
    public List<String> getAllSrs() {
169
        if ((srs.size() == 0) && _parent!=null)
170
            return _parent.getAllSrs();
171
        return srs;
172
    }
173

  
174
    /**
175
     * @param srs The srs to set.
176
     */
177
    public void setSrs(List<String> srs) {
178
        this.srs = srs;
179
    }
180

  
181
    /**
182
     * @return Returns the title.
183
     */
184
    public String getTitle() {
185
        return _title;
186
    }
187

  
188
    public void setTitle(String title) {
189
        this._title = title.trim();
190
    }
191

  
192
    /**
193
     * @return Returns the transparency.
194
     */
195
    public boolean isTransparent() {
196
        return transparency;
197
    }
198

  
199
    /**
200
     * @param transparency The transparency to set.
201
     */
202
    public void setTransparency(boolean transparency) {
203
        this.transparency = transparency;
204
    }
205

  
206
    /**
207
     * Sets the list of sons of this layer.
208
     * @param children
209
     */
210
    public void setChildren(List<WMSLayerNode> children) {
211
        this.children = children;
212
    }
213

  
214
    public WMSLayerNode getParent() {
215
        return _parent;
216
    }
217
    
218
    public void setParent(WMSLayerNode parentNode) {
219
        this._parent = parentNode;
220
    }
221

  
222
    public List<RemoteTimeDimension> getDimensions() {
223
        return dimensions;
224
    }
225

  
226
    /**
227
     * Gets the layer abstract.
228
     *
229
     * @return Returns the abstract.
230
     */
231
    public String getAbstract() {
232
        return lAbstract;
233
    }
234

  
235
    /**
236
     * Sets the layer abstract.
237
     *
238
     * @param abstract The abstract to set.
239
     */
240
    public void setAbstract(String _abstract) {
241
        lAbstract = _abstract;
242
    }
243

  
244
    /**
245
     * @param name
246
     * @param units
247
     * @param unitSymbol
248
     * @param dimensionExpression
249
     */
250
    public void addDimension(String name, String units, String unitSymbol, String dimExpression) {
251
    	if (dimensions == null)
252
    		dimensions = new ArrayList<RemoteTimeDimension>();
253
    	if (name.equalsIgnoreCase("time")) {
254
    		try {
255
    			dimensions.add(new TimeDimension(units, unitSymbol,
256
    					dimExpression));
257
    		} catch (IllegalArgumentException e) {
258
    			// The TIME class does not yet support this kind of time so it
259
    			// will be treated as a DefaultDimension
260
    			dimensions.add(new DefaultDimension(name.toUpperCase(),
261
    					units, unitSymbol, dimExpression));
262
    		}
263
    	} else if (name.equalsIgnoreCase("sequence")) {
264
    		// TODO Not yet implemented
265
    		return;
266
    	} else {
267
    		dimensions.add(new DefaultDimension(name.toUpperCase(), units,
268
    				unitSymbol, dimExpression));
269
    	}
270

  
271
    }
272

  
273
    
274
    public void setLatLonBox(String _latLonBox) {
275
        latLonBox = _latLonBox;
276
    }
277

  
278
    public String getLatLonBox() {
279
        return latLonBox;
280
    }
281

  
282
    /**
283
     * When a server cannot renderize images but just server them in constant size and
284
     * BBox, the layer must have this value set in order to correctly work.
285
     *
286
     * @param fixedWidth - the constant value for the image width
287
     * @param fixedHeight - the constant value for the image height
288
     */
289
    public void setFixedSize(int fixedWidth, int fixedHeight) {
290
		fixedSize = new Dimension(fixedWidth, fixedHeight);
291
	}
292

  
293
	public Dimension getFixedSize() {
294
		return fixedSize;
295
	}
296

  
297
	public boolean isSizeFixed() {
298
		return fixedSize            != null &&
299
		       fixedSize.getWidth()  > 0    &&
300
		       fixedSize.getHeight() > 0;
301
	}
302

  
303
    /**
304
     *
305
     * @param _name
306
     * @param _title
307
     * @param _abstract
308
     */
309
    public void addStyle(org.gvsig.remoteclient.wms.WMSStyle style) {
310
    	if (style.getName().equalsIgnoreCase("default"))
311
    		selectedStyleIndex = styles.size();
312
        if (styles == null)
313
            styles = new ArrayList<RemoteWMSStyle>();
314
        styles.add(new RemoteWMSStyle(style, this));
315

  
316
    }
317

  
318
    public RemoteWMSStyle getSelectedStyle() {
319
    	if (styles == null || selectedStyleIndex > styles.size() - 1 || selectedStyleIndex == -1)
320
    		return null;
321
    	return (RemoteWMSStyle) styles.get(selectedStyleIndex);
322
    }
323

  
324
    public void setSelectedStyleByIndex(int index) {
325
		selectedStyleIndex = index;
326
	}
327

  
328
	public void setSelectedStyleByName(String styName) {
329
		if (styName == null || styName.equals(""))
330
			setSelectedStyleByIndex(-1);
331
		for (int i = 0; i < styles.size(); i++) {
332
			RemoteWMSStyle sty = (RemoteWMSStyle) styles.get(i);
333
			if (sty.name.equalsIgnoreCase(styName)) {
334
				setSelectedStyleByIndex(i);
335
				return;
336
			}
337

  
338
		}
339
		setSelectedStyleByIndex(-1);
340
	}
341

  
342
	public void addKeyword(String keyword) {
343
		if (keywords == null)
344
			keywords = new ArrayList<String>();
345
		keywords.add(keyword);
346
	}
347

  
348
    public String toString(){
349
    	String str;
350
    	if (getName()==null)
351
    		str = getTitle();
352
    	else
353
    		str = "["+getName()+"] "+getTitle();
354
        return str;
355
    }
356

  
357
    public Object clone() throws CloneNotSupportedException {
358
        WMSLayerNode clone       = new WMSLayerNode();
359
        clone._name              = this._name;
360
        clone.queryable          = this.queryable;
361
        clone.srs                = this.srs;
362
        clone._title             = this._title;
363
        clone.transparency       = this.transparency;
364
        clone.styles             = new ArrayList<RemoteWMSStyle>();
365
        clone.lAbstract          = this.lAbstract;
366
        clone.latLonBox          = this.latLonBox;
367
        clone.selectedStyleIndex = this.selectedStyleIndex;
368

  
369
        if (keywords != null) {
370
        	clone.keywords = new ArrayList<String>(keywords.size());
371
        	for (int i = 0; i < keywords.size(); i++) {
372
				clone.keywords.add((String) keywords.get(i));
373
			}
374
        }
375
        if (styles != null)
376
        	for (int i=0; i<styles.size(); i++){
377
        		RemoteWMSStyle sty = (RemoteWMSStyle) this.styles.get(i).clone();
378
        		((RemoteWMSStyle)sty).parent = this;
379
        		clone.styles.add(sty);
380
        	}
381

  
382
        if (dimensions!=null)
383
        	for (int i = 0; i < dimensions.size(); i++) {
384
        		clone.dimensions = new ArrayList<RemoteTimeDimension>();
385
        		clone.dimensions.add((RemoteTimeDimension) this.dimensions.get(i));
386
        	}
387

  
388
        return clone;
389
    }
390

  
391
}
0 392

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.165/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/WMSServerExplorer.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.raster.wms.io;
29

  
30
import java.awt.geom.Rectangle2D;
31
import java.io.File;
32
import java.io.IOException;
33
import java.io.InputStream;
34
import java.net.MalformedURLException;
35
import java.net.URI;
36
import java.net.URISyntaxException;
37
import java.net.URL;
38
import java.net.URLConnection;
39
import java.util.ArrayList;
40
import java.util.Hashtable;
41
import java.util.List;
42
import java.util.Vector;
43

  
44
import org.gvsig.compat.net.ICancellable;
45
import org.gvsig.fmap.dal.DALLocator;
46
import org.gvsig.fmap.dal.DataManager;
47
import org.gvsig.fmap.dal.DataServerExplorerParameters;
48
import org.gvsig.fmap.dal.DataStoreParameters;
49
import org.gvsig.fmap.dal.NewDataStoreParameters;
50
import org.gvsig.fmap.dal.coverage.exception.ConnectException;
51
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
52
import org.gvsig.fmap.dal.coverage.store.RasterDataServerExplorer;
53
import org.gvsig.fmap.dal.exception.DataException;
54
import org.gvsig.fmap.dal.exception.InitializeException;
55
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
56
import org.gvsig.fmap.dal.spi.AbstractDataServerExplorer;
57
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider;
58
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
59
import org.gvsig.i18n.Messages;
60
import org.gvsig.remoteclient.utils.Utilities;
61
import org.gvsig.tools.task.Cancellable;
62

  
63
import org.slf4j.Logger;
64
import org.slf4j.LoggerFactory;
65

  
66
/**
67
 * Explorer for a WMS server
68
 * @author Nacho Brodin (nachobrodin@gmail.com)
69
 */
70
public class WMSServerExplorer extends AbstractDataServerExplorer implements RasterDataServerExplorer, DataServerExplorerProvider {
71
	public static final String          NAME                     = WMSProvider.NAME;
72
	private WMSConnector                connector                = null;
73
//	private WMSServerExplorerParameters parameters               = null;
74
	private Logger                      log                      = LoggerFactory.getLogger(WMSServerExplorer.class);
75

  
76
	public WMSServerExplorer(
77
			WMSServerExplorerParameters parameters,
78
			DataServerExplorerProviderServices services)
79
			throws InitializeException {
80
                super(parameters, services);
81
//		this.parameters = parameters;
82
	}
83

  
84
	/**
85
	 * Gets the provider's name
86
	 * @return
87
	 */
88
	public String getDataStoreProviderName() {
89
		return WMSProvider.NAME;
90
	}
91

  
92
	public String getDescription() {
93
		return WMSProvider.DESCRIPTION;
94
	}
95

  
96
	public boolean add(String provider, NewDataStoreParameters parameters,
97
			boolean overwrite) throws DataException {
98
		return false;
99
	}
100

  
101
	public boolean canAdd() {
102
		return false;
103
	}
104

  
105
	public boolean canAdd(String storeName) throws DataException {
106
		return false;
107
	}
108

  
109
	public NewDataStoreParameters getAddParameters(String storeName)
110
			throws DataException {
111
		return null;
112
	}
113

  
114
	public List<String> getDataStoreProviderNames() {
115
		return null;
116
	}
117

  
118
	public WMSServerExplorerParameters getParameters() {
119
		return (WMSServerExplorerParameters) super.getParameters();
120
	}
121

  
122
	public List<DataStoreParameters> list() throws DataException {
123
		return null;
124
	}
125

  
126
	public List<DataStoreParameters> list(int mode) throws DataException {
127
		return null;
128
	}
129

  
130
	public void remove(DataStoreParameters parameters) throws DataException {
131

  
132
	}
133

  
134
	public String getProviderName() {
135
		return null;
136
	}
137

  
138
	//**********************************************
139
	//Connector
140
	//**********************************************
141

  
142
	public DataStoreParameters getStoredParameters() {
143
		DataManager manager = DALLocator.getDataManager();
144
		WMSDataParameters params = null;
145
		try {
146
			params = (WMSDataParameters) manager.createStoreParameters(this.getDataStoreProviderName());
147
			params.setURI(new URI(getParameters().getHost()));
148

  
149
			/*if(WMSProvider.TILED) {
150
				TileDataParameters tileParams = (TileDataParameters) manager.createStoreParameters("Tile Store");
151
				tileParams.setDataParameters(params);
152
				return tileParams;
153
			} */
154
		} catch (InitializeException e) {
155
			log.debug("Error initializating parameters", e);
156
		} catch (ProviderNotRegisteredException e) {
157
			log.debug("Error getting parameters", e);
158
		} catch (URISyntaxException e) {
159
            log.debug("Can't create URI from "+getParameters().getHost(), e);
160
        }
161

  
162
		return params;
163
	}
164

  
165
	public void connect(ICancellable cancellable) throws ConnectException {
166
		connect(cancellable, false);
167
	}
168

  
169
	/**
170
	 * Connects to the server and throws a getCapabilities. This loads
171
	 * the basic information to make requests.
172
	 * @throws RemoteServiceException
173
	 */
174
	public void connect(ICancellable cancellable, boolean updateCache) throws ConnectException {
175
		URL url = null;
176

  
177
		try {
178
			url = new URL(getParameters().getHost());
179
		} catch (Exception e) {
180
			throw new ConnectException(Messages.getText("malformed_url"), e);
181
		}
182
        try {
183
        	connector = WMSProvider.getConnectorFromURL(url, updateCache);
184
        	if (!connector.connect(this.getParameters(), updateCache, cancellable))
185
        		throw new ConnectException(Messages.getText("error_connecting"));
186
        } catch (IOException e) {
187
			throw new ConnectException(Messages.getText("error_connecting"), e);
188
		}
189

  
190
	}
191

  
192
	/**
193
	 * Checks if the network and host are reachable
194
	 * @param timeout for the host
195
	 * @return true if both are reachable and false if they are not
196
	 */
197
	public boolean isHostReachable(int timeout) {
198
		URL url = null;
199
		try {
200
			url = new URL(getParameters().getHost());
201
			File file = Utilities.downloadFile(url, "checkhost.dat", null);
202
		} catch (Exception e) {
203
			return false;
204
		}
205

  
206
		return true;
207
	}
208

  
209
	/**
210
	 * Checks if the network and host are reachable
211
	 * @return true if both are reachable and false if they are not
212
	 */
213
	public boolean isHostReachable() {
214
		int timeout = 10000;
215
		return isHostReachable(timeout);
216
	}
217

  
218
	/**
219
	 * Returns true if this provider is connected to the server
220
	 * @return
221
	 */
222
	public boolean isConnected() {
223
		if(connector != null)
224
			return true;
225
		return false;
226
	}
227

  
228
	/**
229
	 * Gets the description of this service
230
	 * @return
231
	 */
232
	public String getAbstract() {
233
		if(connector != null)
234
			return connector.getAbstract();
235
		return null;
236
	}
237

  
238
	/**
239
	 * Gets the list of raster formats supported by the server
240
	 * @return
241
	 */
242
	@SuppressWarnings("unchecked")
243
	public String[] getFormats() {
244
		if(connector != null) {
245
			Vector f = connector.getFormats();
246
			ArrayList formatos = new ArrayList();
247
			for (int i = 0; i < f.size(); i++) {
248
				formatos.add(f.elementAt(i));
249
			}
250
			return (String[]) formatos.toArray(new String[0]);
251
		}
252
		return null;
253
	}
254

  
255
	/**
256
	 * Gets the list of raster information formats supported by the server
257
	 * @return
258
	 */
259
	@SuppressWarnings("unchecked")
260
	public String[] getInfoFormats() {
261
		if(connector != null) {
262
			Vector f = connector.getInfoFormats();
263
			ArrayList formatos = new ArrayList();
264
			for (int i = 0; i < f.size(); i++) {
265
				formatos.add(f.elementAt(i));
266
			}
267
			return (String[]) formatos.toArray(new String[0]);
268
		}
269
		return null;
270
	}
271

  
272
	/**
273
	 * Gets a tree of nodes which represents the server information
274
	 * @return
275
	 */
276
	public WMSLayerNode getLayerTree() {
277
		if(connector != null) {
278
			return connector.getLayersTree();
279
		}
280
		return null;
281
	}
282

  
283
	/**
284
	 * Gets the server title
285
	 * @return
286
	 */
287
	public String getServerType() {
288
		if (getVersion() == null)
289
			return "WMS";
290
        return "WMS "+ getVersion();
291
	}
292

  
293
	/**
294
	 * Gets the online resources
295
	 * @return
296
	 */
297
	public Hashtable getOnlineResources() {
298
		if(connector != null) {
299
			return connector.getOnlineResources();
300
		}
301
		return null;
302
	}
303

  
304
	/**
305
	 * Gets the protocol supported by the server
306
	 * @return
307
	 */
308
	public String getVersion() {
309
		if(connector != null) {
310
			return (connector.getVersion() == null) ? "" : connector.getVersion();
311
		}
312
		return null;
313
	}
314

  
315
    public Rectangle2D getLayersExtent(String[] layerName, String srs) {
316
    	return connector.getLayersExtent(layerName, srs);
317
    }
318

  
319
    /**
320
	 * Gets a layer using its name
321
	 * @param layerName
322
	 * @return
323
	 */
324
    public WMSLayerNode getLayer(String layerName) {
325
    	return connector.getLayer(layerName);
326
    }
327

  
328
    /**
329
	 * Gets the host URI
330
	 * @return
331
	 */
332
	public String getHost() {
333
		return getParameters().getHost();
334
	}
335

  
336
	public Rectangle2D getBoundingBox(String[] layerNames, String srs) {
337
		return connector.getLayersExtent(layerNames, srs);
338
    }
339

  
340
	public boolean isQueryable() {
341
    	return connector.isQueryable();
342
    }
343

  
344
	/**
345
	 * Gets the title
346
	 * @return
347
	 */
348
	public String getTitle() {
349
		return null;
350
	}
351

  
352
    /**
353
     * @return The title of the service offered by the WMS server.
354
     */
355
    public String getServiceTitle() {
356
		return connector.getServiceTitle();
357
    }
358

  
359
	public DataServerExplorerProviderServices getServerExplorerProviderServices() {
360
		return null;
361
	}
362
}
0 363

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.165/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/downloader/TileDownloaderForWMS.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
package org.gvsig.raster.wms.io.downloader;
23

  
24
import java.awt.geom.Rectangle2D;
25
import java.io.File;
26
import java.io.IOException;
27
import java.util.List;
28
import java.util.Vector;
29

  
30
import org.cresques.cts.IProjection;
31
import org.gvsig.fmap.dal.coverage.RasterLocator;
32
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
33
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
34
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
35
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
36
import org.gvsig.fmap.dal.coverage.exception.QueryException;
37
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
38
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
39
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
40
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
41
import org.gvsig.fmap.dal.exception.InitializeException;
42
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
43
import org.gvsig.raster.cache.tile.Tile;
44
import org.gvsig.raster.cache.tile.exception.TileGettingException;
45
import org.gvsig.raster.impl.DefaultRasterManager;
46
import org.gvsig.raster.impl.provider.RasterProvider;
47
import org.gvsig.raster.impl.provider.tile.BaseTileDownloader;
48
import org.gvsig.raster.util.DefaultProviderServices;
49
import org.gvsig.raster.wms.io.RemoteWMSStyle;
50
import org.gvsig.raster.wms.io.WMSConnector;
51
import org.gvsig.raster.wms.io.WMSDataParameters;
52
import org.gvsig.raster.wms.io.WMSProvider;
53
import org.gvsig.remoteclient.utils.Utilities;
54
import org.gvsig.remoteclient.wms.WMSStatus;
55
import org.gvsig.tools.locator.LocatorException;
56

  
57
/** 
58
 * Tile getter 
59
 * @author Nacho Brodin (nachobrodin@gmail.com)
60
 */
61
public class TileDownloaderForWMS extends BaseTileDownloader {
62
	private WMSConnector             connector  = null;
63
	private Extent                   lyrExtent  = null;
64

  
65
	
66
	
67
	public TileDownloaderForWMS(RasterDataStore store,
68
			int tilePxWidth,
69
			int tilePxHeight) throws RemoteServiceException {
70
		super(store, tilePxWidth, tilePxHeight);
71
		this.connector = ((WMSProvider)store.getProvider()).getConnector();
72
		lyrExtent = store.getExtent();
73
	}
74
	
75
	public synchronized Tile downloadTile(Tile tile) throws TileGettingException {
76
		try {
77
			Rectangle2D r = new Rectangle2D.Double(tile.getExtent().getMinX(), 
78
					tile.getExtent().getMinY() - tile.getExtent().getHeight(), 
79
					tile.getExtent().getWidth(), 
80
					tile.getExtent().getHeight());
81
			//Extent tileExtent = RasterLocator.getManager().getDataStructFactory().createExtent(r);
82
			WMSDataParameters p = (WMSDataParameters)store.getParameters();
83
			WMSStatus wmsStatus = new WMSStatus();
84
			wmsStatus.setLayerNames(Utilities.createVector(p.getLayerQuery(), ","));
85
			wmsStatus.setSrs(p.getSRSCode());
86
			wmsStatus.setFormat(p.getFormat());
87
			List<RemoteWMSStyle> listStyles = p.getStyles();
88
			Vector<?> v = listStyles != null ? new Vector<RemoteWMSStyle>(listStyles) : null;
89
			wmsStatus.setStyles(v);
90
			wmsStatus.setDimensions(p.getDimensions());
91
			wmsStatus.setTransparency(p.isWmsTransparent());
92
			wmsStatus.setOnlineResource((String) p.getOnlineResource().get("GetMap"));
93
			wmsStatus.setExtent(r);
94
			wmsStatus.setHeight(tile.getHeightPx());
95
			wmsStatus.setWidth(tile.getWidthPx());
96
			wmsStatus.setXyAxisOrder(p.isXyAxisOrder());
97

  
98
			IProjection proj = (IProjection)p.getSRS();
99
			if(proj != null)
100
				wmsStatus.setProjected(proj.isProjected());
101
			connector.getMap(wmsStatus, tile.getCancelled(), tile.getFile());
102

  
103
			//Si borramos el rmf no se puede leer la etiqueta Alpha. En caso de que se modifique jgdal para
104
			//poder guardar esta etiqueta deberiamos borrar el rmf para ahorrar ficheros
105
			//File rmf = new File(tile.getFile().getAbsolutePath() + ".rmf");
106
			//if(rmf.exists())
107
				//rmf.delete();
108
		} catch (RemoteServiceException e) {
109
			throw new TileGettingException(e);
110
		} 
111
		readTileFromDisk(tile);
112
		return tile;
113
	}
114
	
115
	@SuppressWarnings("unused")
116
	private void fuseFiles(Extent dstExtent, int dstWidth, int dstHeight, File src, File dst, double pixelSize) 
117
		throws RasterDriverException, ProcessInterruptedException, ProviderNotRegisteredException, InitializeException, LocatorException, NotSupportedExtensionException, IOException, QueryException {
118
		RasterProvider provider = DefaultProviderServices.loadProvider(src);
119
		
120
		RasterQuery q = RasterLocator.getManager().createQuery();
121
		Buffer bufInput = store.query(q);
122
		
123
		Buffer bufDst = DefaultRasterManager.getInstance().createMemoryBuffer(provider.getDataType()[0], dstWidth, dstHeight, provider.getBandCount(), true);
124
		String extension = RasterLocator.getManager().getFileUtils().getExtensionFromFileName(src.getAbsolutePath());
125
		RasterLocator.getManager().getRasterUtils().copyToBuffer(
126
				bufDst, 
127
				dstExtent, 
128
				bufInput, 
129
				lyrExtent, 
130
				pixelSize, 
131
				provider.getColorInterpretation().hasAlphaBand());
132
		RasterLocator.getManager().getProviderServices().exportBufferToFile(
133
				bufDst, 
134
				provider.getCellSize(), 
135
				extension, 
136
				provider.getColorInterpretation().hasAlphaBand(), 
137
				dst, 
138
				dstExtent, 
139
				provider.getColorInterpretation());
140
	}
141
	
142
}
0 143

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.165/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/downloader/WMSTileServer.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
package org.gvsig.raster.wms.io.downloader;
23

  
24
import org.cresques.cts.IProjection;
25
import org.gvsig.fmap.dal.coverage.RasterLibrary;
26
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
27
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
28
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
29
import org.gvsig.raster.cache.tile.TileCacheLibrary;
30
import org.gvsig.raster.cache.tile.TileCacheLocator;
31
import org.gvsig.raster.cache.tile.TileCacheManager;
32
import org.gvsig.raster.cache.tile.provider.CacheStruct;
33
import org.gvsig.raster.cache.tile.provider.Downloader;
34
import org.gvsig.raster.cache.tile.provider.TileServer;
35
import org.gvsig.raster.impl.provider.RasterProvider;
36
import org.gvsig.raster.wms.io.WMSProvider;
37
import org.slf4j.Logger;
38
import org.slf4j.LoggerFactory;
39

  
40
/**
41
* Data server for the tile cache in a WMSProvider
42
* @author Nacho Brodin (nachobrodin@gmail.com)
43
*/
44
public class WMSTileServer implements TileServer {
45
	private static Logger              logger               = LoggerFactory.getLogger(WMSTileServer.class);
46
	private CacheStruct                struct               = null;
47
	private Downloader                 downloader           = null;
48
	private RasterDataStore            store                = null;
49
	private String                     suffix               = ".tif";
50

  
51
	public WMSTileServer(RasterDataStore store) {
52
		this.store = store;
53
		this.suffix = ((RasterProvider)store.getProvider()).getFileSuffix();
54
	}
55

  
56
	public Downloader getDownloader() {
57
		if(downloader == null ||
58
		   ((TileDownloaderForWMS)downloader).getTileSize()[0] != TileCacheLibrary.ALTERNATIVE_TILESIZE ||
59
		   ((TileDownloaderForWMS)downloader).getTileSize()[1] != TileCacheLibrary.ALTERNATIVE_TILESIZE) {
60
			try {
61
				downloader = new TileDownloaderForWMS(
62
						store,
63
						TileCacheLibrary.ALTERNATIVE_TILESIZE,
64
						TileCacheLibrary.ALTERNATIVE_TILESIZE);
65
			} catch (RemoteServiceException e) {
66
				return null;
67
			}
68
		}
69
		return downloader;
70
	}
71

  
72
	public CacheStruct getStruct() {
73
		if(struct == null) {
74
			TileCacheManager  manager = TileCacheLocator.getManager();
75

  
76
			int coordinates = CacheStruct.FLAT;
77
			if(store.getProjection() != null)
78
				coordinates = (store.getProjection() != null && store.getProjection().isProjected()) ? CacheStruct.FLAT : CacheStruct.GEOGRAFIC;
79
			else {
80
				Extent e = store.getExtent();
81
				if(e.getULX() >= -180 && e.getULX() <= 180 && e.getLRX() >= -180 && e.getLRX() <= 180 &&
82
					e.getULY() >= -90 && e.getULY() <= 90 && e.getLRY() >= -90 && e.getLRY() <= 90) {
83
					coordinates = CacheStruct.GEOGRAFIC;
84
				}
85
			}
86

  
87
			String epsg = null;
88
			IProjection proj = store.getProjection();
89
			if(proj != null)
90
				epsg = proj.getAbrev();
91

  
92
			struct = manager.createCacheStructure(coordinates,
93
					TileCacheLibrary.DEFAULT_LEVELS,
94
					store.getExtent().toRectangle2D(),
95
					Double.POSITIVE_INFINITY,//provider.getCellSize(),
96
					TileCacheLibrary.ALTERNATIVE_TILESIZE,
97
					TileCacheLibrary.ALTERNATIVE_TILESIZE,
98
					((RasterProvider)store.getProvider()).getURIOfFirstProvider().getPath(),
99
					((WMSProvider)store.getProvider()).getParameters().getLayerQuery(),
100
					TileCacheLibrary.DEFAULT_STRUCTURE,
101
					RasterLibrary.pathTileCache,
102
					getFileSuffix(),
103
					epsg,
104
					0);
105
		}
106
		return struct;
107
	}
108

  
109
	public void setStruct(CacheStruct struct) {
110
		if(struct != null) {
111
			this.struct = struct;
112
			if(struct.getTileSizeByLevel(0) != null) {
113
				try {
114
					downloader = new TileDownloaderForWMS(store,
115
							struct.getTileSizeByLevel(0)[0],
116
							struct.getTileSizeByLevel(0)[1]);
117
				} catch (RemoteServiceException ex) {
118
					logger.error("Constructing TileDownloaderForWCS: " + ex.getMessage());
119
				}
120
			}
121
		}
122
	}
123

  
124
	public String getFileSuffix() {
125
		return suffix;
126
	}
127

  
128
	public void setFileSuffix(String extension) {
129
		this.suffix = extension;
130
	}
131
}
0 132

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.165/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.raster.wms.io package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>WMS provider</p>
11

  
12
</body>
13
</html>
0 14

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.165/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/time/RemoteTimeDimension.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
package org.gvsig.raster.wms.io.time;
23

  
24
import org.gvsig.tools.persistence.Persistent;
25

  
26

  
27
/**
28
 * 
29
 * @author jaume
30
 *
31
 */
32
public interface RemoteTimeDimension extends Persistent {
33
	public static int SINGLE_VALUE = 0;
34
	public static int MULTIPLE_VALUE = 1;
35
	public static int INTERVAL = 2;
36
    /**
37
     * Return the dimension's name. This value is the value that will be used in
38
     * a GetMap request.
39
     * 
40
     * @return String containing the name of this dimension.
41
     */
42
    public String getName();
43
    /**
44
     * Return the unit used by this dimension.
45
     * @return
46
     */
47
    public String getUnit();
48
    /**
49
     * Returns the unit symbol (i.e. 'm', 's', or 'l' for meters, seconds, or liters respectively) 
50
     * @return
51
     */
52
    public String getUnitSymbol();
53
    
54
    
55
    /**
56
     * This method returns the <b>lowest</b> value of this dimension if this dimension is
57
     * specified as an interval or as a set of values, or the value specified if it
58
     * was a single value. 
59
     * @return String containing the coded value.
60
     */
61
    public String getLowLimit();
62

  
63
    /**
64
     * This method returns the <b>highest</b> value of this dimension if this dimension is
65
     * specified as an interval or as a set of values, or the value specified if it
66
     * was a single value. 
67
     * @return String containing the coded value.
68
     */
69
    public String getHighLimit();
70
    
71
    /**
72
     * This method returns the resolution supported by this dimension. This
73
     * means the step lenght between two consecutive points along the
74
     * dimension's axis. 
75
     * @return String containing the coded value, or null if no value for resolution.
76
     * @deprecated
77
     */
78
    public String getResolution();
79
    
80
    /**
81
     * Checks if the value represented as string is a valid value by checking
82
     * if the dimensions supports it. It should be true if one of the following is
83
     * true:
84
     * <p>
85
     * <ol> 
86
     * <li>
87
     *  The dimension <b>supports nearest values</b> and <b>the value is greather
88
     *  or  equal than the low limit</b> and <b>less or equal than the high limit</b>.  
89
     *  </li>
90
     *  <li>
91
     *  The value matches in one of the points defined by the low and high limits, and
92
     *  the resolution value.
93
     *  </li>
94
     * </ol>
95
     * </p>
96
     * @param value
97
     * @return
98
     */
99
    public boolean isValidValue(String value);
100
    
101
    /**
102
     * Return the value of the String passed in the dimension's unit-natural type.
103
     * @param value
104
     * @return
105
     */
106
    public Object valueOf(String value) throws IllegalArgumentException;
107
    
108
    /**
109
     * Returns the value that would be at the position passed as argument.
110
     * @param pos
111
     * @return
112
     * @throws ArrayIndexOutOfBoundsException
113
     */
114
    public String valueAt(int pos) throws ArrayIndexOutOfBoundsException;
115
    
116
    /**
117
     * The amount of positions that this dimension contains. 
118
     * @return -1 if the dimension is not recognized, the amount otherwise
119
     */
120
    public int valueCount();
121
    
122
    /**
123
     * Returns the expression describing this WMS Dimension
124
     */
125
    public String getExpression();
126
    
127
    /**
128
     * Sets the expression describing this WMS Dimension
129
     * @throws IllegalArgumentException
130
     */
131
    public void setExpression(String expr);
132
    
133
    /**
134
	 * Returns the type of the dimension expression.<br>
135
	 * Possible values are:
136
	 * <ol>
137
	 * 	<li>
138
	 * 		<b>IFMapWMSDimension.SINGLE_VALUE</b>
139
	 * 		<b>IFMapWMSDimension.MULTIPLE_VALUE</b>
140
	 * 		<b>IFMapWMSDimension.INTERVAL</b>
141
	 * 	</li>
142
	 * </ol>
143
	 * @return int
144
	 */
145
    public int getType();
146
    
147
    /**
148
     * Analyzes and establishes the starting values for this dimension. No operation of this
149
     * dimension can be called before the dimension has been compiled.
150
     * 
151
     * @throws IllegalArgumentException
152
     */
153
    public void compile() throws IllegalArgumentException;
154
}
0 155

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.165/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/time/TimeDimension.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
package org.gvsig.raster.wms.io.time;
23

  
24
import java.util.ArrayList;
25
import java.util.Calendar;
26
import java.util.GregorianCalendar;
27
import java.util.List;
28

  
29
import org.gvsig.tools.ToolsLocator;
30
import org.gvsig.tools.dynobject.DynStruct;
31
import org.gvsig.tools.persistence.PersistenceManager;
32
import org.gvsig.tools.persistence.PersistentState;
33
import org.gvsig.tools.persistence.exception.PersistenceException;
34

  
35
/**
36
 * Class for WMS TIME dimension from a WMS. It allows you to handle the correct
37
 * values for this kind of dimension.
38
 * <br>
39
 * <p>
40
 * At the moment this class was written the WMS TIME dimension is defined as the
41
 * ISO8601 standard for expressing times.
42
 * </p>
43
 * <br>
44
 * <p>
45
 * As far as this class implements IFMapWMSDimension it uses the same interface
46
 * and documentation.
47
 * </p>
48
 *
49
 * @author jaume dominguez faus - jaume.dominguez@iver.es
50
 */
51
public class TimeDimension implements RemoteTimeDimension {
52
	static private final byte   YEAR_FORMAT           = 1;
53
	static private final byte   YEAR_TO_MONTH_FORMAT  = 2;
54
	static private final byte   YEAR_TO_DAY_FORMAT    = 3;
55
	static private final byte   FULL_FORMAT           = 4;
56

  
57
    static private final long   millisXsec            = 1000;
58
    static private final long   millisXminute         = 60 * millisXsec;
59
    static private final long   millisXhour           = 60 * millisXminute;
60
    static private final long   millisXday            = 24 * millisXhour;
61
    static private final long   millisXmonth          = 30 * millisXday;
62
    //(1 year = 365 days 6 hours 9 minutes 9,7 seconds)
63
    static private final long   millisXyear           = (365*millisXday) + (6*millisXhour) + (9*millisXminute) + 9700;
64

  
65
    static private final String digit                 = "[0-9]";
66
    static private final String nonZeroDigit          = "[1-9]";
67
    static private final String seconds               = "([0-5]" + digit + "((\\.|,)" + digit + digit+ "?" + digit + "?" + ")?)";
68
    static private final String minutes               = "([0-5]" + digit + ")";
69
    static private final String hours                 = "(0" + digit + "|1" + digit + "|2[0-3])";
70
    static private final String time                  = hours + ":" + minutes + "(:" + seconds + ")?";
71
    static private final String days                  = "(0?" + nonZeroDigit + "|1" + digit + "|2" + digit + "|30|31)";
72
    static private final String months                = "(0?" + nonZeroDigit + "|10|11|12)";
73
    static private final String year                  = "(" + digit + digit + ")";
74
    static private final String century               = "(" + digit + digit + ")";
75
    static private final String floatingPointNumber   = "(" + digit + "+(\\." + digit + "+)?)";
76

  
77
    private String              unit;
78
	private String              unitSymbol;
79
	private List<GregorianCalendar>   
80
	                            valueList;
81
	private boolean             compiled;
82
	private boolean             isGeologic;
83
	private String              expression;
84
	private int                 type;
85
	private byte                format               = 0;
86

  
87
    static private final String regexDateExtendedForBCE1 = "B?"+century+year;
88
    static private final String regexDateExtendedForBCE2 = "B?"+century+year+"-"+months;
89
    static private final String regexDateExtendedForBCE3 = "B?"+century+year+"-"+months+"-"+days;
90
    static private final String regexDateExtendedForBCE4 = "B?"+century+year+"-"+months+"-"+days+"(T| )"+time+"Z";
91
    // Note: in WMS 1.1.0 the suffix Z is optional
92

  
93
    static private final String regexDateExtendedForBCE =
94
        "(" +  regexDateExtendedForBCE1  + "|"
95
            +  regexDateExtendedForBCE2  + "|"
96
            +  regexDateExtendedForBCE3  + "|"
97
            +  regexDateExtendedForBCE4  +      ")";
98

  
99
    static private final String periodMagnitude = "(Y|M|D)";
100
    static private final String p1 = "(("+digit+")+"+periodMagnitude+")";
101

  
102
    static private final String timeMagnitude = "(H|M|S)";
103
    static private final String p2 = "("+floatingPointNumber+timeMagnitude+")";
104
    static private final String regexPeriod = "P(("+p1+"+"+"(T"+p2+")*)|("+p1+"*"+"(T"+p2+")+))";
105

  
106
    static private final String regexIntervalTimeDimension =
107
        "("+regexDateExtendedForBCE+")/("+regexDateExtendedForBCE+")/("+regexPeriod+")";
108

  
109
    static private final String geologicDatasets = "(K|M|G)";
110
    static private final String regexDateForGeologicDatasets = geologicDatasets+floatingPointNumber;
111

  
112
	@SuppressWarnings("unchecked")
113
	public void loadFromState(PersistentState state) throws PersistenceException {
114
		this.unit = state.getString("unit");
115
		this.unitSymbol = state.getString("unitSymbol");
116
		
117
		List<String> list = (List<String>)state.getList("valueList");
118
		valueList = convertStringListToGregorianCalendarList(list);
119
		
120
		this.compiled = state.getBoolean("compiled");
121
		this.isGeologic = state.getBoolean("isGeologic");
122
		this.expression = state.getString("expression");
123
		this.type = state.getInt("type");
124
		this.format = (byte)state.getInt("format");
125
	}
126
	
127
	public void saveToState(PersistentState state) throws PersistenceException {
128
		state.set("unit", unit);
129
		state.set("unitSymbol", unitSymbol);
130
		state.set("valueList", convertGregorianCalendarListToStringList(valueList));
131
		state.set("compiled", compiled);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff