Statistics
| Revision:

root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / bindings / geometries / MultiLineStrinsTypeBinding.java @ 11475

History | View | Annotate | Download (3.97 KB)

1
package org.gvsig.gpe.gml.bindings.geometries;
2

    
3
import java.io.IOException;
4
import java.util.Hashtable;
5

    
6
import org.gvsig.gpe.gml.GMLTags;
7
import org.gvsig.gpe.gml.GPEGmlParser;
8
import org.gvsig.gpe.gml.utils.GMLUtilsParser;
9
import org.kxml2.io.KXmlParser;
10
import org.xmlpull.v1.XmlPullParser;
11
import org.xmlpull.v1.XmlPullParserException;
12

    
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
/* CVS MESSAGES:
54
 *
55
 * $Id: MultiLineStrinsTypeBinding.java 11475 2007-05-07 12:58:42Z jorpiell $
56
 * $Log$
57
 * Revision 1.1  2007-05-07 12:58:42  jorpiell
58
 * Add some methods to manage the multigeometries
59
 *
60
 *
61
 */
62
/**
63
 * It parses a gml:MultiLineStringType object. Example:
64
 * <p>
65
 * <pre>
66
 * <code>
67
 * &lt;MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#4326"&gt;
68
 * &lt;lineStringMember&gt;
69
 * &lt;LineString&gt;
70
 * &lt;coord&gt;&lt;X&gt;56.1&lt;/X&gt;&lt;Y&gt;0.45&lt;/Y&gt;&lt;/coord&gt;
71
 * &lt;coord&gt;&lt;X&gt;67.23&lt;/X&gt;&lt;Y&gt;0.98&lt;/Y&gt;&lt;/coord&gt;
72
 * &lt;/LineString&gt;
73
 * &lt;/lineStringMember&gt;
74
 * &lt;lineStringMember&gt;
75
 * &lt;LineString&gt;
76
 * &lt;coord&gt;&lt;X&gt;46.71&lt;/X&gt;&lt;Y&gt;9.25&lt;/Y&gt;&lt;/coord&gt;
77
 * &lt;coord&gt;&lt;X&gt;56.88&lt;/X&gt;&lt;Y&gt;10.44&lt;/Y&gt;&lt;/coord&gt;
78
 * &lt;/LineString&gt;
79
 * &lt;/lineStringMember&gt;
80
 * &lt;/MultiLineString&gt;
81
 * </code>
82
 * </pre>
83
 * </p> 
84
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
85
 */
86
public class MultiLineStrinsTypeBinding {
87
        
88
        /**
89
         * It parses the gml:MultiLineString tag
90
         * @param parser
91
         * The XML parser
92
         * @param handler
93
         * The GPE parser that contains the content handler and
94
         * the error handler
95
         * @return
96
         * A multilinestring
97
         * @throws XmlPullParserException
98
         */
99
        public static Object parse(XmlPullParser parser,GPEGmlParser handler) throws XmlPullParserException, IOException {
100
                boolean endFeature = false;
101
                int currentTag;
102
                Object multiLineString = null;                
103
                
104
                Hashtable attributes = GMLUtilsParser.getAttributes(parser);                
105
                String srsName = GeometryAttributesBinding.getSrs(attributes);
106
                String id = GeometryAttributesBinding.getID(attributes);
107
                
108
                handler.getContentHandler().startMultiLineString(id, srsName);
109
                
110
                String tag = parser.getName();
111
                currentTag = parser.getEventType();
112

    
113
                while (!endFeature){
114
                        switch(currentTag){
115
                        case KXmlParser.START_TAG:
116
                                        if (tag.compareTo(GMLTags.GML_LINESTRINGMEMBER) == 0){
117
                                                Object lineString = LineStringMemberTypeBinding.parse(parser, handler);
118
                                                handler.getContentHandler().addLineStringToMultiLineString(lineString, multiLineString);
119
                                        }
120
                                        break;
121
                                case KXmlParser.END_TAG:
122
                                        if (tag.compareTo(GMLTags.GML_MULTILINESTRING) == 0){                                                
123
                                                endFeature = true;        
124
                                                handler.getContentHandler().endMultiLineString(multiLineString);
125
                                        }
126
                                        break;
127
                                case KXmlParser.TEXT:                                        
128
                                        
129
                                        break;
130
                                }
131
                                if (!endFeature){                                        
132
                                        currentTag = parser.next();
133
                                        tag = parser.getName();
134
                                }
135
                        }                        
136
                return multiLineString;        
137
        }
138
}