Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extCatalog / src / org / gvsig / catalog / loaders / WCSLayerLoader.java @ 29625

History | View | Annotate | Download (4.03 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.catalog.loaders;
42

    
43
import java.io.IOException;
44
import java.util.Map;
45
import java.util.TreeMap;
46

    
47
import org.gvsig.catalog.schemas.Resource;
48
import org.gvsig.fmap.mapcontext.layers.FLayer;
49
import org.gvsig.i18n.Messages;
50
import org.gvsig.tools.extensionpoint.ExtensionPoint;
51
import org.gvsig.utils.extensionPointsOld.ExtensionPointsSingleton;
52

    
53

    
54
/**
55
 * This class is used to load a WCS  layer in gvSIG
56
 * 
57
 * @author Jorge Piera Llodra (piera_jor@gva.es)
58
 */
59
public class WCSLayerLoader extends GvSigLayerLoader{
60
        
61
        
62
        public WCSLayerLoader(Resource resource) {
63
                super(resource);
64
        }
65
        
66
        /**
67
         * This method loads a WSC layer from a full URL
68
         * @param link
69
         * @throws LayerLoaderException 
70
         */
71
        public void loadLayer() throws LayerLoaderException {
72
                String link = getResource().getLinkage();
73
                String name = getResource().getName();
74
                try {
75
                        FLayer flayer = createWCSLayer(link,name);
76
                        addLayerToView(flayer);
77
                } catch (IOException e) {
78
                        throw new LayerLoaderException(e.getMessage(),getWindowMessage());
79
                }         
80
        }           
81
        
82
        private FLayer createWCSLayer(String link,String name) throws IOException, LayerLoaderException {
83
                Map args = initFromQueryString(link,name);
84
                ExtensionPoint extensionPoint = (ExtensionPoint)ExtensionPointsSingleton.getInstance().get("CatalogLayers");
85
                try {
86
                        return (FLayer)extensionPoint.create("OGC:WCS", args  );
87
                } catch(Exception e) {
88
                        throw new LayerLoaderException(getErrorMessage(),getWindowMessage());
89
                }                
90
        }
91
        
92
        /**
93
         * Builds a coverage starting from a full GetCoverage URL.
94
         * (Using this is not a regular function)
95
         */
96
        private TreeMap initFromQueryString(String link,String name){
97
                String host = null;
98
                String queryString = null;
99
                if (link.compareTo("?")==0){
100
                        host = link.substring(0,link.indexOf('?'));
101
                        queryString = link.substring(link.indexOf('?')+1);
102
                }else{
103
                        host = link;
104
                        queryString = "";
105
                }
106
                queryString = link.substring(link.indexOf('?')+1);
107
                
108
                TreeMap map = new TreeMap(); 
109
                String[] params = queryString.split("&");
110
                for (int i = 0; i < params.length; i++) {
111
                        if (params[i]!= null){
112
                                String[] nameValue = params[i].split("=");
113
                                if (nameValue.length == 1){
114
                                        map.put(nameValue[0].toUpperCase(), "");
115
                                }else if(nameValue.length == 2){
116
                                        map.put(nameValue[0].toUpperCase(), nameValue[1]);
117
                                }
118
                        }
119
                }
120
                map.put("HOST",link);
121
                if ((name != null) && (!name.equals(""))){
122
                        map.put("COVERAGE",name);
123
                }
124
                return map;
125
        }        
126
        
127
        /*
128
         *  (non-Javadoc)
129
         * @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getErrorMessage()
130
         */
131
        protected String getErrorMessage() {
132
                return Messages.getText("wcsError") + ".\n" +
133
                Messages.getText("link") + ": " + 
134
                getResource().getLinkage();                
135
        }
136
        
137
        /*
138
         *  (non-Javadoc)
139
         * @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getWindowMessage()
140
         */
141
        protected String getWindowMessage() {
142
                return Messages.getText("wcsLoad");
143
        }
144
        
145
        
146
        
147
}