Statistics
| Revision:

root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / fmap / layers / FLyrWFSFactory.java @ 37969

History | View | Annotate | Download (4.8 KB)

1
package com.iver.cit.gvsig.fmap.layers;
2

    
3
import java.awt.Component;
4
import java.net.URL;
5

    
6
import javax.swing.JOptionPane;
7

    
8
import org.apache.log4j.Logger;
9
import org.cresques.cts.IProjection;
10

    
11
import com.iver.andami.PluginServices;
12
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
13
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
14
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver;
15
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
16

    
17
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
18
 *
19
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
20
 *
21
 * This program is free software; you can redistribute it and/or
22
 * modify it under the terms of the GNU General Public License
23
 * as published by the Free Software Foundation; either version 2
24
 * of the License, or (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
34
 *
35
 * For more information, contact:
36
 *
37
 *  Generalitat Valenciana
38
 *   Conselleria d'Infraestructures i Transport
39
 *   Av. Blasco Ib??ez, 50
40
 *   46010 VALENCIA
41
 *   SPAIN
42
 *
43
 *      +34 963862235
44
 *   gvsig@gva.es
45
 *      www.gvsig.gva.es
46
 *
47
 *    or
48
 *
49
 *   IVER T.I. S.A
50
 *   Salamanca 50
51
 *   46005 Valencia
52
 *   Spain
53
 *
54
 *   +34 963163400
55
 *   dac@iver.es
56
 */
57
/* CVS MESSAGES:
58
 *
59
 * $Id: FLyrWFSFactory.java 13632 2007-09-11 16:00:50Z jorpiell $
60
 * $Log$
61
 * Revision 1.2.2.6  2007-09-11 16:00:50  jorpiell
62
 * If the SRS is not supported by gvSIG, an information message is showed
63
 *
64
 * Revision 1.2.2.5  2007/04/03 10:24:25  jorpiell
65
 * La transformaci?n de coordenadas que se usa para reproyactar no debe ponerse en la capa a pi?on fijo.
66
 *
67
 * Revision 1.2.2.4  2007/01/04 10:06:25  jcampos
68
 * Upgrade new version
69
 *
70
 * Revision 1.2.2.3  2006/11/17 11:28:45  ppiqueras
71
 * Corregidos bugs y a?adida nueva funcionalidad.
72
 *
73
 * Revision 1.3  2006/11/16 16:57:05  jorpiell
74
 * Se inserta en adapter
75
 *
76
 * Revision 1.2  2006/11/06 13:58:03  jorpiell
77
 * Al crear una nueva capa se declara como activa. De esa forma se pueden aplicar tantos filtros como queramos
78
 *
79
 * Revision 1.1  2006/10/31 09:38:15  jorpiell
80
 * Se ha creado una factoria para crear la capa. De ese modo no se repite c?digo desde le panel de propiedades y desde el panel de la capa
81
 *
82
 *
83
 */
84
/**
85
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
86
 */
87
public class FLyrWFSFactory {
88

    
89
        /**
90
         * 
91
         * @param layer
92
         * @param host
93
         * @param onlineResource
94
         * @param driver
95
         * @param loadLayer
96
         * If the layer has to be loaded
97
         * @param firstLoad
98
         * If is the first time that the layer is loaded
99
         * @return
100
         */
101
        public FLyrWFS getFLyrWFS(FLayer layer, 
102
                        URL host,
103
                        String onlineResource,
104
                        FMapWFSDriver driver,
105
                        boolean loadLayer,
106
                        boolean firstLoad){
107
                FLyrWFS wfsLayer = (FLyrWFS)layer;
108
                wfsLayer.setHost(host);
109
                wfsLayer.setWfsDriver(driver);
110
//                Sets the WFS adapter
111
                WFSAdapter adapter = new WFSAdapter();
112
            adapter.setDriver((VectorialDriver) driver);
113
            wfsLayer.setSource(adapter);
114
                wfsLayer.setOnlineResource(onlineResource);
115
                //The SRS original
116
                IProjection projection = CRSFactory.getCRS(getSRS(wfsLayer.getSrs()));
117
                wfsLayer.setProjection(projection);
118
                if (loadLayer){
119
                        try {
120
                                if ((projection == null) && (firstLoad)){
121
                                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
122
                                                        PluginServices.getText(this,"wfs_srs_unknown"));        
123
                                }
124
                                wfsLayer.load();
125
                                if (wfsLayer.getNumfeatures() == wfsLayer.getWfsDriver().getRowCount()) {
126
                                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
127
                                                        PluginServices.getText(this,"maxFeatures_aviso"));        
128
                                }
129
                        } catch (Exception e) {
130
                                // TODO Auto-generated catch block
131
                                Logger.getLogger(getClass().getName()).error(e.getMessage());
132
                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
133
                                                PluginServices.getText(this,"cantLoad"));
134
                                return null;
135
                        }
136
                }
137
                wfsLayer.setActive(true);
138
                return wfsLayer;
139
        }
140
        
141
        /**
142
         * Removing the URN prefix
143
         * @param srs
144
         * @return
145
         */
146
        private String getSRS(String srs){
147
                if (srs == null){
148
                        return null;
149
                }
150
                if ((srs.startsWith("urn:x-ogc:def:crs:")) || srs.startsWith("urn:ogc:def:crs:")){
151
                        String newString = srs.substring(srs.lastIndexOf(":") + 1, srs.length());
152
                        if (srs.indexOf("EPSG") > 0){
153
                                if (newString.indexOf("EPSG") < 0){
154
                                        newString = "EPSG:" + newString;
155
                                }
156
                        }
157
                        return newString;                        
158
                }
159
                if (srs.toLowerCase().startsWith("crs:")){
160
                        return srs.substring(4, srs.length());
161
                }
162
                return srs;
163
        }
164

    
165
}