Statistics
| Revision:

root / branches / CatalogYNomenclator_v1_1_0_1005 / extensions / extCatalogYNomenclator / src / es / gva / cit / gvsig / catalogClient / loaders / WCSLayerLoader.java @ 12733

History | View | Annotate | Download (4.21 KB)

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