Statistics
| Revision:

root / trunk / extensions / extWFS2 / src-test / com / iver / cit / gvsig / fmap / layers / gml / GMLParseTest.java @ 8529

History | View | Annotate | Download (4.99 KB)

1
package com.iver.cit.gvsig.fmap.layers.gml;
2
import java.awt.geom.Rectangle2D;
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.InputStream;
6
import java.net.URI;
7
import java.net.URL;
8
import java.util.ArrayList;
9
import java.util.Iterator;
10

    
11
import junit.framework.TestCase;
12

    
13
import org.gvsig.remoteClient.gml.GMLReader;
14
import org.gvsig.remoteClient.gml.IGMLFeaturesIterator;
15
import org.gvsig.remoteClient.gml.factories.GeometriesFactory;
16
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory;
17
import org.gvsig.remoteClient.gml.factories.XMLElementsFactory;
18
import org.gvsig.remoteClient.gml.factories.XMLSchemasFactory;
19
import org.gvsig.remoteClient.gml.factories.XMLTypesFactory;
20
import org.gvsig.remoteClient.gml.v2.GMLSimpleFeature_v2;
21
import org.gvsig.remoteClient.utils.Utilities;
22

    
23
import sun.java2d.pipe.AATextRenderer;
24

    
25
import com.hardcode.gdbms.engine.values.ComplexValue;
26
import com.hardcode.gdbms.engine.values.Value;
27
import com.iver.cit.gvsig.fmap.drivers.gml.FMAPGeometryFactory;
28
import com.iver.cit.gvsig.fmap.drivers.gml.FMAPGeometryFactory.FeatureWithAttributes;
29

    
30
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
31
 *
32
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
33
 *
34
 * This program is free software; you can redistribute it and/or
35
 * modify it under the terms of the GNU General Public License
36
 * as published by the Free Software Foundation; either version 2
37
 * of the License, or (at your option) any later version.
38
 *
39
 * This program is distributed in the hope that it will be useful,
40
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
 * GNU General Public License for more details.
43
 *
44
 * You should have received a copy of the GNU General Public License
45
 * along with this program; if not, write to the Free Software
46
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
47
 *
48
 * For more information, contact:
49
 *
50
 *  Generalitat Valenciana
51
 *   Conselleria d'Infraestructures i Transport
52
 *   Av. Blasco Ib??ez, 50
53
 *   46010 VALENCIA
54
 *   SPAIN
55
 *
56
 *      +34 963862235
57
 *   gvsig@gva.es
58
 *      www.gvsig.gva.es
59
 *
60
 *    or
61
 *
62
 *   IVER T.I. S.A
63
 *   Salamanca 50
64
 *   46005 Valencia
65
 *   Spain
66
 *
67
 *   +34 963163400
68
 *   dac@iver.es
69
 */
70
/* CVS MESSAGES:
71
 *
72
 * $Id: GMLParseTest.java 8529 2006-11-06 13:10:34Z jorpiell $
73
 * $Log$
74
 * Revision 1.5  2006-11-06 13:10:34  jorpiell
75
 * Ha cambiado el constructor del GML Reader
76
 *
77
 * Revision 1.4  2006/10/11 08:31:20  jorpiell
78
 * Se ha creadu un panel para visualizar las features complejas
79
 *
80
 * Revision 1.3  2006/10/02 09:09:45  jorpiell
81
 * Cambios del 10 copiados al head
82
 *
83
 * Revision 1.1.2.1  2006/09/19 12:27:35  jorpiell
84
 * Ya no se depende de geotools
85
 *
86
 * Revision 1.2  2006/09/18 12:07:31  jorpiell
87
 * Se ha sustituido geotools por el driver de remoteservices
88
 *
89
 * Revision 1.1  2006/07/24 07:30:33  jorpiell
90
 * Se han eliminado las partes duplicadas y se est? usando el parser de GML de FMAP.
91
 *
92
 *
93
 */
94
/**
95
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
96
 */
97
public class GMLParseTest extends TestCase {
98
        private static String gmlComplex = "http://161.111.161.171/cgi-bin/AtlasAves.exe?REQUEST=GetFeature&SERVICE=WFS&TYPENAME=Blyr&PROPERTYNAME=msGeometry&VERSION=1.0.0&EXCEPTIONS=XML&MAXFEATURES=1000";
99
        private IGeometriesFactory factory = new FMAPGeometryFactory();
100
        
101
        public void testWFSDuplicados() throws Exception{
102
                parseFile(gmlComplex);        
103
        }        
104
        
105
        public void parseFile(String sUrl) throws Exception{
106
                URL url = new URL(sUrl);
107
                File file = Utilities.downloadFile(url,"wfs_capabilities.xml", null);
108
                GMLReader reader = new GMLReader(file,factory,true);                
109
                Rectangle2D extent = reader.getExtent();
110
        
111
                IGMLFeaturesIterator iterator = reader.getFeaturesIterator();
112
                
113
                XMLElementsFactory.printEntities();
114
                XMLTypesFactory.printTypes();
115
                XMLSchemasFactory.printSchemas();
116
                                
117
                int i=0;
118
                while (iterator.hasNext()){
119
                        System.out.println("*********  FEATURE NUMBER " + i + " ***********+");
120
                        FeatureWithAttributes feature = (FeatureWithAttributes) iterator.next();
121
                        for (int j=0 ; j<feature.getAttributeName().size() ; j++){
122
                                if (feature.getAttributeValue()[j] instanceof ComplexValue){
123
                                        printComplexType((String)feature.getAttributeName().get(j),(ComplexValue)feature.getAttributeValue()[j],1);
124
                                }else{
125
                                        System.out.print((String)feature.getAttributeName().get(j) + ":" + feature.getAttributeValue()[j]  + "\n");
126
                                }                                
127
                        }
128
                        i++;
129
                }
130
                assertEquals(i,199);
131
        }
132
        
133
        private void printComplexType(String attributeName, ComplexValue value,int level){
134
                String tab = "";
135
                for (int i=0 ; i<level ; i++){
136
                        tab = tab + "\t";
137
                }
138
                level++;
139
                System.out.print(attributeName + ":\n");
140
                for (int j=0 ; j<value.size() ; j++){
141
                        Iterator it = value.keySet().iterator();
142
                        while(it.hasNext()){
143
                                String paramName = (String)it.next();
144
                                Value nextValue = (Value)value.get(paramName);
145
                                if (nextValue instanceof ComplexValue){
146
                                        printComplexType(paramName,(ComplexValue)nextValue,level);
147
                                }else{
148
                                        System.out.print(tab + paramName + ": " + nextValue  + "\n");
149
                                }
150
                        }
151
                }
152
        }
153
}