Revision 11485

View differences:

trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/writer/features/FeatureAttributesWriter.java
1
package org.gvsig.gpe.kml.writer.features;
2

  
3
import java.io.IOException;
4

  
5
import org.gvsig.gpe.kml.KmlTags;
6
import org.gvsig.gpe.xml.writer.Writer;
7

  
8
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
9
 *
10
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
11
 *
12
 * This program is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU General Public License
14
 * as published by the Free Software Foundation; either version 2
15
 * of the License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
25
 *
26
 * For more information, contact:
27
 *
28
 *  Generalitat Valenciana
29
 *   Conselleria d'Infraestructures i Transport
30
 *   Av. Blasco Ib??ez, 50
31
 *   46010 VALENCIA
32
 *   SPAIN
33
 *
34
 *      +34 963862235
35
 *   gvsig@gva.es
36
 *      www.gvsig.gva.es
37
 *
38
 *    or
39
 *
40
 *   IVER T.I. S.A
41
 *   Salamanca 50
42
 *   46005 Valencia
43
 *   Spain
44
 *
45
 *   +34 963163400
46
 *   dac@iver.es
47
 */
48
/* CVS MESSAGES:
49
 *
50
 * $Id$
51
 * $Log$
52
 * Revision 1.1  2007-05-08 07:53:08  jorpiell
53
 * Add comments to the writers
54
 *
55
 * Revision 1.1  2007/04/20 08:38:59  jorpiell
56
 * Tests updating
57
 *
58
 *
59
 */
60
/**
61
 * This is an abstract element and cannot be used 
62
 * directly in a KML file. Document, Folder, NetworkLink,
63
 * Placemark, GroundOverLay and ScreenOverlay inherit from
64
 * it 
65
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
66
 */
67
public class FeatureAttributesWriter {
68
	
69
	/**
70
	 * It writes the init tag and the common attributes
71
	 * for a Document, Folder, NetworkLink, Placemark, 
72
	 * GroundOverLay or a ScreenOverlay.
73
	 * @param writer
74
	 * Writer to write the labels
75
	 * @param id
76
	 * Feature ID
77
	 * @param tagName
78
	 * Feature type
79
	 * @throws IOException
80
	 */
81
	public static void start(Writer writer,String id, String tagName) throws IOException{
82
		writer.write("\n");
83
		writer.write("<" + tagName);
84
		if (id != null){
85
			writer.write(" " + KmlTags.ID + "=\"" + id + "\"");
86
		}
87
		writer.write(">");
88
	}
89
	
90
	/**
91
	 * It writes the end tag of a Document, Folder, NetworkLink, 
92
	 * Placemark, GroundOverLay or a ScreenOverlay.
93
	 * @param writer
94
	 * Writer to write the labels
95
	 * @param tagName
96
	 * Feature type
97
	 * @throws IOException
98
	 */
99
	public static void end(Writer writer, String tagName) throws IOException{
100
		writer.write("\n");
101
		writer.write("</" + tagName + ">");
102
	}
103
}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/writer/features/FeatureWriter.java
1
package org.gvsig.gpe.kml.writer.features;
2

  
3
import java.io.IOException;
4

  
5
import org.gvsig.gpe.kml.KmlTags;
6
import org.gvsig.gpe.xml.writer.Writer;
7

  
8
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
9
 *
10
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
11
 *
12
 * This program is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU General Public License
14
 * as published by the Free Software Foundation; either version 2
15
 * of the License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
25
 *
26
 * For more information, contact:
27
 *
28
 *  Generalitat Valenciana
29
 *   Conselleria d'Infraestructures i Transport
30
 *   Av. Blasco Ib??ez, 50
31
 *   46010 VALENCIA
32
 *   SPAIN
33
 *
34
 *      +34 963862235
35
 *   gvsig@gva.es
36
 *      www.gvsig.gva.es
37
 *
38
 *    or
39
 *
40
 *   IVER T.I. S.A
41
 *   Salamanca 50
42
 *   46005 Valencia
43
 *   Spain
44
 *
45
 *   +34 963163400
46
 *   dac@iver.es
47
 */
48
/* CVS MESSAGES:
49
 *
50
 * $Id$
51
 * $Log$
52
 * Revision 1.1  2007-05-08 08:22:37  jorpiell
53
 * Add comments to create javadocs
54
 *
55
 * Revision 1.1  2007/05/08 07:53:08  jorpiell
56
 * Add comments to the writers
57
 *
58
 * Revision 1.1  2007/04/20 08:38:59  jorpiell
59
 * Tests updating
60
 *
61
 *
62
 */
63
/**
64
 * This is an abstract element and cannot be used 
65
 * directly in a KML file. Document, Folder, NetworkLink,
66
 * Placemark, GroundOverLay and ScreenOverlay inherit from
67
 * it. It writes the common attributes
68
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
69
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#feature
70
 */
71
public class FeatureWriter {
72
	
73
	/**
74
	 * It writes the init tag and the common attributes
75
	 * for a Document, Folder, NetworkLink, Placemark, 
76
	 * GroundOverLay or a ScreenOverlay.
77
	 * @param writer
78
	 * Writer to write the labels
79
	 * @param id
80
	 * Feature ID
81
	 * @param tagName
82
	 * Feature type
83
	 * @throws IOException
84
	 */
85
	public static void start(Writer writer,String id, String tagName) throws IOException{
86
		writer.write("\n");
87
		writer.write("<" + tagName);
88
		if (id != null){
89
			writer.write(" " + KmlTags.ID + "=\"" + id + "\"");
90
		}
91
		writer.write(">");
92
	}
93
	
94
	/**
95
	 * It writes the end tag of a Document, Folder, NetworkLink, 
96
	 * Placemark, GroundOverLay or a ScreenOverlay.
97
	 * @param writer
98
	 * Writer to write the labels
99
	 * @param tagName
100
	 * Feature type
101
	 * @throws IOException
102
	 */
103
	public static void end(Writer writer, String tagName) throws IOException{
104
		writer.write("\n");
105
		writer.write("</" + tagName + ">");
106
	}
107
}
0 108

  
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/writer/features/FolderWriter.java
49 49
 *
50 50
 * $Id$
51 51
 * $Log$
52
 * Revision 1.3  2007-05-08 07:53:08  jorpiell
52
 * Revision 1.4  2007-05-08 08:22:37  jorpiell
53
 * Add comments to create javadocs
54
 *
55
 * Revision 1.3  2007/05/08 07:53:08  jorpiell
53 56
 * Add comments to the writers
54 57
 *
55 58
 * Revision 1.2  2007/04/20 08:38:59  jorpiell
......
95 98
	 * @throws IOException
96 99
	 */
97 100
	public static void start(Writer writer,String id, String name, String description) throws IOException{
98
		FeatureAttributesWriter.start(writer, id, KmlTags.FOLDER);
101
		FeatureWriter.start(writer, id, KmlTags.FOLDER);
99 102
		if (name != null){
100 103
			NameWriter.write(writer, name);
101 104
		}
......
111 114
	 * @throws IOException
112 115
	 */
113 116
	public static void end(Writer writer) throws IOException{
114
		FeatureAttributesWriter.end(writer, KmlTags.FOLDER);
117
		FeatureWriter.end(writer, KmlTags.FOLDER);
115 118
	}
116 119
}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/writer/features/DocumentWriter.java
49 49
 *
50 50
 * $Id$
51 51
 * $Log$
52
 * Revision 1.3  2007-05-08 07:53:08  jorpiell
52
 * Revision 1.4  2007-05-08 08:22:37  jorpiell
53
 * Add comments to create javadocs
54
 *
55
 * Revision 1.3  2007/05/08 07:53:08  jorpiell
53 56
 * Add comments to the writers
54 57
 *
55 58
 * Revision 1.2  2007/04/20 08:38:59  jorpiell
......
95 98
	 * @throws IOException
96 99
	 */
97 100
	public static void start(Writer writer,String id, String name, String description) throws IOException{
98
		FeatureAttributesWriter.start(writer, id, KmlTags.DOCUMENT);
101
		FeatureWriter.start(writer, id, KmlTags.DOCUMENT);
99 102
		if (name != null){
100 103
			NameWriter.write(writer, name);
101 104
		}
......
111 114
	 * @throws IOException
112 115
	 */
113 116
	public static void end(Writer writer) throws IOException{
114
		FeatureAttributesWriter.end(writer, KmlTags.DOCUMENT);
117
		FeatureWriter.end(writer, KmlTags.DOCUMENT);
115 118
	}
116 119
}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/writer/features/PlaceMarkWriter.java
49 49
 *
50 50
 * $Id$
51 51
 * $Log$
52
 * Revision 1.3  2007-05-08 07:53:08  jorpiell
52
 * Revision 1.4  2007-05-08 08:22:37  jorpiell
53
 * Add comments to create javadocs
54
 *
55
 * Revision 1.3  2007/05/08 07:53:08  jorpiell
53 56
 * Add comments to the writers
54 57
 *
55 58
 * Revision 1.2  2007/04/20 08:38:59  jorpiell
......
61 64
 *
62 65
 */
63 66
/**
67
 * This class writes a PlaceMark kml tag. Example:
68
 * <p>
69
 * <pre>
70
 * <code>
71
 * &lt;Placemark&gt;
72
 * &lt;name&gt;CDATA example&lt;/name&gt;
73
 * &lt;description&gt;Description example&lt;/description&gt;
74
 * &lt;Point&gt;
75
 * &lt;oordinates&gt;102.595626,14.996729&lt;/coordinates&gt;
76
 * &lt;/Point&gt;
77
 * &lt;/Placemark&gt;
78
 * </code>
79
 * </pre>
80
 * </p>
64 81
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
82
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#placemark
65 83
 */
66 84
public class PlaceMarkWriter {
67 85
	
68
	public static void start(Writer writer,String name, String id) throws IOException{
69
		FeatureAttributesWriter.start(writer, id, KmlTags.PLACEMARK);
86
	/**
87
	 * Writes a PlaceMark init tag and its attributes
88
	 * @param writer
89
	 * Writer to write the labels
90
	 * @param id
91
	 * PlaceMark id
92
	 * @param name
93
	 * PlaceMark name
94
	 * 
95
	 * @throws IOException
96
	 */
97
	public static void start(Writer writer, String id, String name) throws IOException{
98
		FeatureWriter.start(writer, id, KmlTags.PLACEMARK);
70 99
		if (id != null){
71 100
			writer.write(" id=\"" + id + "\"");
72 101
		}
......
76 105
		}	
77 106
	}
78 107
	
108
	/**
109
	 * It writes the end PlaceMark tag
110
	 * @param writer
111
	 * Writer to write the labels
112
	 * @throws IOException
113
	 */
79 114
	public static void end(Writer writer) throws IOException{
80
		FeatureAttributesWriter.end(writer, KmlTags.PLACEMARK);
115
		FeatureWriter.end(writer, KmlTags.PLACEMARK);
81 116
	}
82 117
}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/writer/GPEKmlWriterHandler.java
75 75
 *
76 76
 * $Id$
77 77
 * $Log$
78
 * Revision 1.8  2007-05-07 07:07:18  jorpiell
78
 * Revision 1.9  2007-05-08 08:22:37  jorpiell
79
 * Add comments to create javadocs
80
 *
81
 * Revision 1.8  2007/05/07 07:07:18  jorpiell
79 82
 * Add a constructor with the name and the description fields
80 83
 *
81 84
 * Revision 1.7  2007/05/02 11:46:50  jorpiell
......
209 212
	 */
210 213
	public void startFeature(String id, String name) {
211 214
		try{
212
			PlaceMarkWriter.start(writer, name, id);
215
			PlaceMarkWriter.start(writer, id, name);
213 216
		} catch (IOException e) {
214 217
			getErrorHandler().addError(e);
215 218
		}	
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/bindings/AFeatureBinding.java
1
package org.gvsig.gpe.kml.bindings;
2

  
3
import org.gvsig.gpe.kml.GPEKmlParser;
4
import org.gvsig.gpe.kml.KmlTags;
5
import org.xmlpull.v1.XmlPullParser;
6

  
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
/* CVS MESSAGES:
48
 *
49
 * $Id$
50
 * $Log$
51
 * Revision 1.1  2007-04-20 08:38:59  jorpiell
52
 * Tests updating
53
 *
54
 *
55
 */
56
/**
57
 * This is an abstract element and cannot be used 
58
 * directly in a KML file. Document, Folder, NetworkLink,
59
 * Placemark, GroundOverLay and ScreenOverlay inherit from
60
 * it. This class has methods to implement all the 
61
 * common methods to parse them
62
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
63
 */
64
public class AFeatureBinding {
65
	
66
	/**
67
	 * It returns the KML id attribute value
68
	 * @param parser
69
	 * @param handler
70
	 * @return
71
	 */
72
	public static String getID(XmlPullParser parser,GPEKmlParser handler){
73
		String id = null;
74
		for (int i=0 ; i<parser.getAttributeCount() ; i++){
75
			if (parser.getAttributeName(i).compareTo(KmlTags.ID) == 0){
76
				id = parser.getAttributeValue(i);
77
			}
78
		}
79
		return id;	
80
	}
81
}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/bindings/DocumentBinding.java
53 53
 *
54 54
 * $Id$
55 55
 * $Log$
56
 * Revision 1.4  2007-05-02 11:46:50  jorpiell
56
 * Revision 1.5  2007-05-08 08:22:37  jorpiell
57
 * Add comments to create javadocs
58
 *
59
 * Revision 1.4  2007/05/02 11:46:50  jorpiell
57 60
 * Writing tests updated
58 61
 *
59 62
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
......
68 71
 *
69 72
 */
70 73
/**
74
 * This class parsers a Document tag. Example:
75
 * <p>
76
 * <pre>
77
 * <code>
78
 * &lt;Document&gt;
79
 * &lt;Placemark&gt;
80
 * &lt;name&gt;CDATA example&lt;/name&gt;
81
 * &lt;description&gt;Description example&lt;/description&gt;
82
 * &lt;Point&gt;
83
 * &lt;oordinates&gt;102.595626,14.996729&lt;/coordinates&gt;
84
 * &lt;/Point&gt;
85
 * &lt;/Placemark&gt;
86
 * &lt;/Document&gt;
87
 * </code>
88
 * </pre>
89
 * </p>
71 90
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
91
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#document
72 92
 */
73 93
public class DocumentBinding {
74 94
	
75 95
	/**
76
	 * Parse a Document KML tag
96
	 * It parses the Document tag
77 97
	 * @param parser
98
	 * The XML parser
78 99
	 * @param handler
100
	 * The GPE parser that contains the content handler and
101
	 * the error handler
79 102
	 * @return
80
	 * An application layer
81
	 * @throws KmlBodyParseException
103
	 * A Layer
104
	 * @throws XmlPullParserException 
105
	 * @throws IOException 
82 106
	 */
83
	public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws KmlBodyParseException {
107
	public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException {
84 108
		boolean endFeature = false;
85 109
		int currentTag;		
86
		
87
		String id = AFeatureBinding.getID(parser, handler);
110

  
111
		String id = FeatureBinding.getID(parser, handler);
88 112
		Object layer = handler.getContentHandler().startLayer(id, null, null, null, null, null);
89
		
90
		try {
91
			String tag = parser.getName();
92
			currentTag = parser.getEventType();
93
			
94
			while (!endFeature){
95
				switch(currentTag){
96
				case KXmlParser.START_TAG:
97
					if (tag.compareTo(KmlTags.OPEN) == 0){
98
						parser.next();
99
						String open = parser.getText();						
100
					}else if (tag.compareTo(KmlTags.NAME) == 0){
101
						parser.next();
102
						handler.getContentHandler().addNameToLayer(parser.getText(),layer);
103
					}if (tag.compareTo(KmlTags.DESCRIPTION) == 0){
104
						parser.next();
105
						handler.getContentHandler().addDescriptionToLayer(parser.getText(),layer);
106
					}else if (tag.compareTo(KmlTags.STYLE) == 0){
107
						StyleBinding.parse(parser, handler);
108
					}else if (tag.compareTo(KmlTags.FOLDER) == 0){
109
						FolderBinding.parse(parser, handler, layer);
110
					}else if (tag.compareTo(KmlTags.PLACEMARK) == 0){
111
						Object feature = PlaceMarketBinding.parse(parser, handler);
112
						handler.getContentHandler().addFeatureToLayer(feature, layer);
113
					}
114
					break;
115
				case KXmlParser.END_TAG:
116
					if (tag.compareTo(KmlTags.DOCUMENT) == 0){
117
						endFeature = true;
118
						handler.getContentHandler().endLayer(layer);
119
					}
120
					break;
121
				case KXmlParser.TEXT:					
122
					
123
					break;
113

  
114
		String tag = parser.getName();
115
		currentTag = parser.getEventType();
116

  
117
		while (!endFeature){
118
			switch(currentTag){
119
			case KXmlParser.START_TAG:
120
				if (tag.compareTo(KmlTags.OPEN) == 0){
121
					parser.next();
122
					String open = parser.getText();						
123
				}else if (tag.compareTo(KmlTags.NAME) == 0){
124
					parser.next();
125
					handler.getContentHandler().addNameToLayer(parser.getText(),layer);
126
				}if (tag.compareTo(KmlTags.DESCRIPTION) == 0){
127
					parser.next();
128
					handler.getContentHandler().addDescriptionToLayer(parser.getText(),layer);
129
				}else if (tag.compareTo(KmlTags.STYLE) == 0){
130
					StyleBinding.parse(parser, handler);
131
				}else if (tag.compareTo(KmlTags.FOLDER) == 0){
132
					FolderBinding.parse(parser, handler, layer);
133
				}else if (tag.compareTo(KmlTags.PLACEMARK) == 0){
134
					Object feature = PlaceMarketBinding.parse(parser, handler);
135
					handler.getContentHandler().addFeatureToLayer(feature, layer);
124 136
				}
125
				if (!endFeature){					
126
					currentTag = parser.next();
127
					tag = parser.getName();
137
				break;
138
			case KXmlParser.END_TAG:
139
				if (tag.compareTo(KmlTags.DOCUMENT) == 0){
140
					endFeature = true;
141
					handler.getContentHandler().endLayer(layer);
128 142
				}
129
			}			
130
		} catch (XmlPullParserException e) {
131
			throw new KmlBodyParseException(e);
132
		} catch (IOException e) {
133
			throw new KmlBodyParseException(e);
134
		}	
143
				break;
144
			case KXmlParser.TEXT:					
145

  
146
				break;
147
			}
148
			if (!endFeature){					
149
				currentTag = parser.next();
150
				tag = parser.getName();
151
			}
152
		}			
153

  
135 154
		return layer;
136 155
	}
137 156
}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/bindings/StyleBinding.java
53 53
 *
54 54
 * $Id$
55 55
 * $Log$
56
 * Revision 1.1  2007-04-13 13:16:21  jorpiell
56
 * Revision 1.2  2007-05-08 08:22:37  jorpiell
57
 * Add comments to create javadocs
58
 *
59
 * Revision 1.1  2007/04/13 13:16:21  jorpiell
57 60
 * Add KML reading support
58 61
 *
59 62
 *
60 63
 */
61 64
/**
65
 * This class parses a Style tag. Example:
66
 * <p>
67
 * <pre>
68
 * <code>
69
 * &lt;Style id="globeIcon"&gt;
70
 * &lt;IconStyle&gt;
71
 * &lt;Icon&gt;
72
 * &lt;href&gt;http://maps.google.com/mapfiles/kml/pal3/icon19.png&lt;/href&gt;
73
 * &lt;/Icon&gt;
74
 * &lt;/IconStyle&gt;
75
 * &lt;LineStyle&gt;
76
 * &lt;width&gt;2&lt;/width&gt;
77
 * &lt;/LineStyle&gt;
78
 * &lt;/Style&gt;
79
 * </code>
80
 * </pre>
81
 * </p>
62 82
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
83
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#style
63 84
 */
64 85
public class StyleBinding {
65
	
66
	public static void parse(XmlPullParser parser,GPEKmlParser handler) throws KmlBodyParseException {
86

  
87
	/**
88
	 * It parses the Style tag
89
	 * @param parser
90
	 * The XML parser
91
	 * @param handler
92
	 * The GPE parser that contains the content handler and
93
	 * the error handler
94
	 * @throws IOException 
95
	 * @throws XmlPullParserException 
96
	 * @throws XmlPullParserException
97
	 * @throws IOException
98
	 */
99
	public static void parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException{
67 100
		boolean endFeature = false;
68
		int currentTag;		
69
			
70
		try {
71
			String tag = parser.getName();
72
			currentTag = parser.getEventType();
73
			
74
			while (!endFeature){
75
				switch(currentTag){
76
				case XmlPullParser.START_TAG:
77
					
78
					break;
79
				case KXmlParser.END_TAG:
80
					if (tag.compareTo(KmlTags.STYLE) == 0){
81
						endFeature = true;
82
					}
83
					break;
84
				case KXmlParser.TEXT:					
85
					
86
					break;
101
		int currentTag;				
102

  
103
		String tag = parser.getName();
104
		currentTag = parser.getEventType();
105

  
106
		while (!endFeature){
107
			switch(currentTag){
108
			case XmlPullParser.START_TAG:
109

  
110
				break;
111
			case KXmlParser.END_TAG:
112
				if (tag.compareTo(KmlTags.STYLE) == 0){
113
					endFeature = true;
87 114
				}
88
				if (!endFeature){					
89
					currentTag = parser.next();
90
					tag = parser.getName();
91
				}
92
			}			
93
		} catch (XmlPullParserException e) {
94
			throw new KmlBodyParseException(e);
95
		} catch (IOException e) {
96
			throw new KmlBodyParseException(e);
97
		}		
115
				break;
116
			case KXmlParser.TEXT:					
117

  
118
				break;
119
			}
120
			if (!endFeature){					
121
				currentTag = parser.next();
122
				tag = parser.getName();
123
			}
124
		}			
98 125
	}
99 126
}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/bindings/PlaceMarketBinding.java
56 56
 *
57 57
 * $Id$
58 58
 * $Log$
59
 * Revision 1.3  2007-04-20 08:38:59  jorpiell
59
 * Revision 1.4  2007-05-08 08:22:37  jorpiell
60
 * Add comments to create javadocs
61
 *
62
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
60 63
 * Tests updating
61 64
 *
62 65
 * Revision 1.2  2007/04/13 13:16:21  jorpiell
......
77 80
 *
78 81
 */
79 82
/**
80
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
83
 * This class parses a PlaceMark tag. Example:
84
 * <p>
85
 * <pre>
86
 * <code>
87
 * &lt;Placemark&gt;
88
 * &lt;name&gt;CDATA example&lt;/name&gt;
89
 * &lt;description&gt;Description example&lt;/description&gt;
90
 * &lt;Point&gt;
91
 * &lt;oordinates&gt;102.595626,14.996729&lt;/coordinates&gt;
92
 * &lt;/Point&gt;
93
 * &lt;/Placemark&gt;
94
 * </code>
95
 * </pre>
96
 * </p>
97
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
98
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#placemark
81 99
 */
82 100
public class PlaceMarketBinding {
83 101

  
84 102
	/**
85
	 * Parse a KML PalceMarketBinding tag
103
	 * It parses the PlaceMark tag
86 104
	 * @param parser
105
	 * The XML parser
87 106
	 * @param handler
107
	 * The GPE parser that contains the content handler and
108
	 * the error handler
88 109
	 * @return
89
	 * A application feature
90
	 * @throws KmlBodyParseException
110
	 * A Feature
111
	 * @throws IOException 
112
	 * @throws XmlPullParserException 
113
	 * @throws XmlPullParserException 
114
	 * @throws IOException 
91 115
	 */
92
	public static Object parse(XmlPullParser parser,GPEKmlParser handler)  throws KmlBodyParseException {
116
	public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException{
93 117
		boolean endFeature = false;
94 118
		int currentTag;		
95
			
96
		String id = AFeatureBinding.getID(parser, handler);
119

  
120
		String id = FeatureBinding.getID(parser, handler);
97 121
		Object feature = handler.getContentHandler().startFeature(id, null, null);
98
		
99
		try {
100
			String tag = parser.getName();
101
			currentTag = parser.getEventType();
102
			
103
			while (!endFeature){
104
				switch(currentTag){
105
				case KXmlParser.START_TAG:
106
					if (tag.compareTo(KmlTags.NAME) == 0){
107
						parser.next();
108
						handler.getContentHandler().addNameToFeature(parser.getText(), feature);
109
					}else if (tag.compareTo(KmlTags.DESCRIPTION) == 0){
110
						parser.next();
111
						String description = parser.getText();
112
					}else if (tag.compareTo(KmlTags.VISIBILITY) == 0){
113
						parser.next();
114
						String visibility = parser.getText();
115
					}else if (tag.compareTo(KmlTags.LOOKAT) == 0){
116
						LookAtBinding.parse(parser, handler);
117
					}else if (tag.compareTo(KmlTags.STYLEURL) == 0){
118
						parser.next();
119
						String styleURL = parser.getText();
120
					}else if (tag.compareTo(KmlTags.POINT) == 0){
121
						Object point = PointTypeBinding.parse(parser, handler);
122
						handler.getContentHandler().addGeometryToFeature(point, feature);
123
					}else if (tag.compareTo(KmlTags.LINESTRING) == 0){
124
						Object lineString = LineStringTypeBinding.parse(parser, handler);
125
						handler.getContentHandler().addGeometryToFeature(lineString, feature);
126
					}else if (tag.compareTo(KmlTags.POLYGON) == 0){
127
						Object polygon = PolygonTypeBinding.parse(parser, handler);
128
						handler.getContentHandler().addGeometryToFeature(polygon, feature);
129
					}
130
					break;
131
				case KXmlParser.END_TAG:
132
					if (tag.compareTo(KmlTags.PLACEMARK) == 0){						
133
						endFeature = true;
134
						handler.getContentHandler().endFeature(feature);
135
					}
136
					break;
137
				case KXmlParser.TEXT:					
138
					
139
					break;
122

  
123

  
124
		String tag = parser.getName();
125
		currentTag = parser.getEventType();
126

  
127
		while (!endFeature){
128
			switch(currentTag){
129
			case KXmlParser.START_TAG:
130
				if (tag.compareTo(KmlTags.NAME) == 0){
131
					parser.next();
132
					handler.getContentHandler().addNameToFeature(parser.getText(), feature);
133
				}else if (tag.compareTo(KmlTags.DESCRIPTION) == 0){
134
					parser.next();
135
					String description = parser.getText();
136
				}else if (tag.compareTo(KmlTags.VISIBILITY) == 0){
137
					parser.next();
138
					String visibility = parser.getText();
139
				}else if (tag.compareTo(KmlTags.LOOKAT) == 0){
140
					LookAtBinding.parse(parser, handler);
141
				}else if (tag.compareTo(KmlTags.STYLEURL) == 0){
142
					parser.next();
143
					String styleURL = parser.getText();
144
				}else if (tag.compareTo(KmlTags.POINT) == 0){
145
					Object point = PointTypeBinding.parse(parser, handler);
146
					handler.getContentHandler().addGeometryToFeature(point, feature);
147
				}else if (tag.compareTo(KmlTags.LINESTRING) == 0){
148
					Object lineString = LineStringTypeBinding.parse(parser, handler);
149
					handler.getContentHandler().addGeometryToFeature(lineString, feature);
150
				}else if (tag.compareTo(KmlTags.POLYGON) == 0){
151
					Object polygon = PolygonTypeBinding.parse(parser, handler);
152
					handler.getContentHandler().addGeometryToFeature(polygon, feature);
140 153
				}
141
				if (!endFeature){					
142
					currentTag = parser.next();
143
					tag = parser.getName();
154
				break;
155
			case KXmlParser.END_TAG:
156
				if (tag.compareTo(KmlTags.PLACEMARK) == 0){						
157
					endFeature = true;
158
					handler.getContentHandler().endFeature(feature);
144 159
				}
145
			}			
146
		} catch (XmlPullParserException e) {
147
			throw new KmlBodyParseException(e);
148
		} catch (IOException e) {
149
			throw new KmlBodyParseException(e);
150
		}	
160
				break;
161
			case KXmlParser.TEXT:					
162

  
163
				break;
164
			}
165
			if (!endFeature){					
166
				currentTag = parser.next();
167
				tag = parser.getName();
168
			}
169
		}			
170

  
151 171
		return feature;
152 172
	}
153 173
}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/bindings/geometries/AGeometryTypeBinding.java
1
package org.gvsig.gpe.kml.bindings.geometries;
2

  
3
import org.gvsig.gpe.kml.GPEKmlParser;
4
import org.gvsig.gpe.kml.KmlTags;
5
import org.xmlpull.v1.XmlPullParser;
6

  
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
/* CVS MESSAGES:
48
 *
49
 * $Id$
50
 * $Log$
51
 * Revision 1.1  2007-05-02 11:46:50  jorpiell
52
 * Writing tests updated
53
 *
54
 *
55
 */
56
/**
57
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
58
 */
59
public class AGeometryTypeBinding {
60
	
61
	/**
62
	 * It returns the KML geometry id attribute value
63
	 * @param parser
64
	 * @param handler
65
	 * @return
66
	 */
67
	public static String getID(XmlPullParser parser,GPEKmlParser handler){
68
		String id = null;
69
		for (int i=0 ; i<parser.getAttributeCount() ; i++){
70
			if (parser.getAttributeName(i).compareTo(KmlTags.GEOMETRY_ID) == 0){
71
				id = parser.getAttributeValue(i);
72
			}
73
		}
74
		return id;	
75
	}
76
}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/bindings/geometries/OuterBoundaryIsBinding.java
53 53
 *
54 54
 * $Id$
55 55
 * $Log$
56
 * Revision 1.2  2007-04-14 16:08:07  jorpiell
56
 * Revision 1.3  2007-05-08 08:22:37  jorpiell
57
 * Add comments to create javadocs
58
 *
59
 * Revision 1.2  2007/04/14 16:08:07  jorpiell
57 60
 * Kml writing support added
58 61
 *
59 62
 * Revision 1.1  2007/04/13 13:16:21  jorpiell
......
62 65
 *
63 66
 */
64 67
/**
68
 * It parses the outerBoundary tag. Example:
69
 * <p>
70
 * <pre>
71
 * <code>
72
 * &lt;outerBoundaryIs&gt;
73
 * &lt;LinearRing&gt;
74
 * &lt;coordinates&gt;10.0,10.0 10.0,40.0 40.0,40.0 40.0,10.0 10.0,10.0&lt;/coordinates&gt;
75
 * &lt;/LinearRing&gt;
76
 * &lt;/outerBoundaryIs&gt;
77
 * </code>
78
 * </pre>
79
 * </p> 
65 80
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
81
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#outerboundaryis
66 82
 */
67 83
public class OuterBoundaryIsBinding {
68
	
69
	public static double[][] parse(XmlPullParser parser,GPEKmlParser handler) throws KmlBodyParseException {
84

  
85
	/**
86
	 * It parses the outerBoundaryIs tag
87
	 * @param parser
88
	 * The XML parser
89
	 * @param handler
90
	 * The GPE parser that contains the content handler and
91
	 * the error handler
92
	 * @return
93
	 * It retuns a matrix of doubles with 3 columns (x,y,z) and
94
	 * one row for each coordinate.
95
	 * @throws IOException 
96
	 * @throws XmlPullParserException 
97
	 * @throws XmlPullParserException
98
	 * @throws IOException
99
	 */
100
	public static double[][] parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException {
70 101
		boolean endFeature = false;
71 102
		int currentTag;
72
			
103

  
73 104
		double[][] coordinates = null;
74
		
75
		try {
76
			String tag = parser.getName();
77
			currentTag = parser.getEventType();
78
			
79
			while (!endFeature){
80
				switch(currentTag){
81
				case KXmlParser.START_TAG:
82
					if (tag.compareTo(KmlTags.LINEARRING) == 0){
83
						coordinates = LinearRingBinding.parse(parser, handler);
84
					}
85
					break;
86
				case KXmlParser.END_TAG:
87
					if (tag.compareTo(KmlTags.OUTERBOUNDARYIS) == 0){						
88
						endFeature = true;
89
					}
90
					break;
91
				case KXmlParser.TEXT:					
92
					
93
					break;
105

  
106
		String tag = parser.getName();
107
		currentTag = parser.getEventType();
108

  
109
		while (!endFeature){
110
			switch(currentTag){
111
			case KXmlParser.START_TAG:
112
				if (tag.compareTo(KmlTags.LINEARRING) == 0){
113
					coordinates = LinearRingBinding.parse(parser, handler);
94 114
				}
95
				if (!endFeature){					
96
					currentTag = parser.next();
97
					tag = parser.getName();
115
				break;
116
			case KXmlParser.END_TAG:
117
				if (tag.compareTo(KmlTags.OUTERBOUNDARYIS) == 0){						
118
					endFeature = true;
98 119
				}
99
			}			
100
		} catch (XmlPullParserException e) {
101
			throw new KmlBodyParseException(e);
102
		} catch (IOException e) {
103
			throw new KmlBodyParseException(e);
104
		}
120
				break;
121
			case KXmlParser.TEXT:					
122

  
123
				break;
124
			}
125
			if (!endFeature){					
126
				currentTag = parser.next();
127
				tag = parser.getName();
128
			}
129
		}	
105 130
		return coordinates;
106 131
	}
107 132
}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/bindings/geometries/LineStringTypeBinding.java
53 53
 *
54 54
 * $Id$
55 55
 * $Log$
56
 * Revision 1.3  2007-05-02 11:46:50  jorpiell
56
 * Revision 1.4  2007-05-08 08:22:37  jorpiell
57
 * Add comments to create javadocs
58
 *
59
 * Revision 1.3  2007/05/02 11:46:50  jorpiell
57 60
 * Writing tests updated
58 61
 *
59 62
 * Revision 1.2  2007/04/20 08:38:59  jorpiell
......
77 80
 *
78 81
 */
79 82
/**
83
 * It parses the LineString tag. Example:
84
 * <p>
85
 * <pre>
86
 * <code>
87
 * &lt;LineString&gt;
88
 * &lt;coord&gt;&lt;X&gt;56.1&lt;/X&gt;&lt;Y&gt;0.45&lt;/Y&gt;&lt;/coord&gt;
89
 * &lt;coord&gt;&lt;X&gt;67.23&lt;/X&gt;&lt;Y&gt;0.98&lt;/Y&gt;&lt;/coord&gt;
90
 * &lt;/LineString&gt;
91
 * </code>
92
 * </pre>
93
 * </p> 
80 94
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
95
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#linestring
81 96
 */
82 97
public class LineStringTypeBinding {
83 98

  
84
	public static Object parse(XmlPullParser parser,GPEKmlParser handler)throws KmlBodyParseException {
99
	/**
100
	 * It parses the LineString tag
101
	 * @param parser
102
	 * The XML parser
103
	 * @param handler
104
	 * The GPE parser that contains the content handler and
105
	 * the error handler
106
	 * @return
107
	 * A line string
108
	 * @throws IOException 
109
	 * @throws XmlPullParserException 
110
	 * @throws XmlPullParserException
111
	 * @throws IOException
112
	 */
113
	public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException {
85 114
		boolean endFeature = false;
86 115
		int currentTag;
87 116
		Object lineString = null;
88
			
89
		String id = AGeometryTypeBinding.getID(parser, handler);
90
		
91
		try {
92
			String tag = parser.getName();
93
			currentTag = parser.getEventType();
94
			
95
			while (!endFeature){
96
				switch(currentTag){
97
				case KXmlParser.START_TAG:
98
					if (tag.compareTo(KmlTags.COORDINATES) == 0){
99
						double[][] coordinates = CoordinatesTypeBinding.parse(parser, handler);
100
						lineString = handler.getContentHandler().startLineString(id,
101
								coordinates[0],
102
								coordinates[1],
103
								coordinates[2],								
104
								KmlTags.DEFAULT_SRS);						
105
					}
106
					break;
107
				case KXmlParser.END_TAG:
108
					if (tag.compareTo(KmlTags.LINESTRING) == 0){						
109
						endFeature = true;
110
						handler.getContentHandler().endLineString(lineString);
111
					}
112
					break;
113
				case KXmlParser.TEXT:					
114
					
115
					break;
117

  
118
		String id = GeometryBinding.getID(parser, handler);
119

  
120
		String tag = parser.getName();
121
		currentTag = parser.getEventType();
122

  
123
		while (!endFeature){
124
			switch(currentTag){
125
			case KXmlParser.START_TAG:
126
				if (tag.compareTo(KmlTags.COORDINATES) == 0){
127
					double[][] coordinates = CoordinatesTypeBinding.parse(parser, handler);
128
					lineString = handler.getContentHandler().startLineString(id,
129
							coordinates[0],
130
							coordinates[1],
131
							coordinates[2],								
132
							KmlTags.DEFAULT_SRS);						
116 133
				}
117
				if (!endFeature){					
118
					currentTag = parser.next();
119
					tag = parser.getName();
134
				break;
135
			case KXmlParser.END_TAG:
136
				if (tag.compareTo(KmlTags.LINESTRING) == 0){						
137
					endFeature = true;
138
					handler.getContentHandler().endLineString(lineString);
120 139
				}
121
			}			
122
		} catch (XmlPullParserException e) {
123
			throw new KmlBodyParseException(e);
124
		} catch (IOException e) {
125
			throw new KmlBodyParseException(e);
126
		}
140
				break;
141
			case KXmlParser.TEXT:					
142

  
143
				break;
144
			}
145
			if (!endFeature){					
146
				currentTag = parser.next();
147
				tag = parser.getName();
148
			}
149
		}			
127 150
		return lineString;	
128 151
	}
129 152
}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/bindings/geometries/PolygonTypeBinding.java
53 53
 *
54 54
 * $Id$
55 55
 * $Log$
56
 * Revision 1.4  2007-05-02 11:46:50  jorpiell
56
 * Revision 1.5  2007-05-08 08:22:37  jorpiell
57
 * Add comments to create javadocs
58
 *
59
 * Revision 1.4  2007/05/02 11:46:50  jorpiell
57 60
 * Writing tests updated
58 61
 *
59 62
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
......
80 83
 *
81 84
 */
82 85
/**
83
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
86
 * It writes a Polygon tag. Example:
87
 * <p>
88
 * <pre>
89
 * <code>
90
 * &lt;Polygon gid="_877789"&gt;
91
 * &lt;outerBoundaryIs&gt;
92
 * &lt;LinearRing&gt;
93
 * &lt;coordinates&gt;0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0&lt;/coordinates&gt;
94
 * &lt;/LinearRing&gt;
95
 * &lt;/outerBoundaryIs&gt;
96
 * &lt;/Polygon&gt;
97
 * </code>
98
 * </pre>
99
 * </p> 
100
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
101
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#polygon
84 102
 */
85 103
public class PolygonTypeBinding {
86 104

  
87
	public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws KmlBodyParseException {
105
	/**
106
	 * It parses the Polygon tag
107
	 * @param parser
108
	 * The XML parser
109
	 * @param handler
110
	 * The GPE parser that contains the content handler and
111
	 * the error handler
112
	 * @return
113
	 * A polygon
114
	 * @throws IOException 
115
	 * @throws XmlPullParserException 
116
	 * @throws XmlPullParserException
117
	 * @throws IOException
118
	 */
119
	public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException {
88 120
		boolean endFeature = false;
89 121
		int currentTag;			
90 122
		Object polygon = null;
91
		
92
		String id = AGeometryTypeBinding.getID(parser, handler);
93
		
94
		try {
95
			String tag = parser.getName();
96
			currentTag = parser.getEventType();
97
			
98
			while (!endFeature){
99
				switch(currentTag){
100
				case KXmlParser.START_TAG:
101
					if (tag.compareTo(KmlTags.OUTERBOUNDARYIS) == 0){
102
						double[][] coordinates = OuterBoundaryIsBinding.parse(parser, handler);
103
						polygon = handler.getContentHandler().startPolygon(id,
104
								coordinates[0],
105
								coordinates[1],
106
								coordinates[2],
107
								KmlTags.DEFAULT_SRS);
108
					}else if (tag.compareTo(KmlTags.INNERBOUNDARYIS) == 0){
109
						double[][] coordinates = InnerBoundaryIsBinding.parse(parser, handler);
110
						Object innerPolygon = handler.getContentHandler().startInnerPolygon(null,
111
								coordinates[0],
112
								coordinates[1],
113
								coordinates[2],
114
								KmlTags.DEFAULT_SRS);
115
						handler.getContentHandler().endInnerPolygon(innerPolygon);
116
						handler.getContentHandler().addInnerPolygonToPolygon(innerPolygon,polygon);
117
					}
118
					break;
119
				case KXmlParser.END_TAG:
120
					if (tag.compareTo(KmlTags.POLYGON) == 0){						
121
						endFeature = true;
122
						handler.getContentHandler().endPolygon(polygon);
123
					}
124
					break;
125
				case KXmlParser.TEXT:					
126
					
127
					break;
123

  
124
		String id = GeometryBinding.getID(parser, handler);		
125

  
126
		String tag = parser.getName();
127
		currentTag = parser.getEventType();
128

  
129
		while (!endFeature){
130
			switch(currentTag){
131
			case KXmlParser.START_TAG:
132
				if (tag.compareTo(KmlTags.OUTERBOUNDARYIS) == 0){
133
					double[][] coordinates = OuterBoundaryIsBinding.parse(parser, handler);
134
					polygon = handler.getContentHandler().startPolygon(id,
135
							coordinates[0],
136
							coordinates[1],
137
							coordinates[2],
138
							KmlTags.DEFAULT_SRS);
139
				}else if (tag.compareTo(KmlTags.INNERBOUNDARYIS) == 0){
140
					double[][] coordinates = InnerBoundaryIsBinding.parse(parser, handler);
141
					Object innerPolygon = handler.getContentHandler().startInnerPolygon(null,
142
							coordinates[0],
143
							coordinates[1],
144
							coordinates[2],
145
							KmlTags.DEFAULT_SRS);
146
					handler.getContentHandler().endInnerPolygon(innerPolygon);
147
					handler.getContentHandler().addInnerPolygonToPolygon(innerPolygon,polygon);
128 148
				}
129
				if (!endFeature){					
130
					currentTag = parser.next();
131
					tag = parser.getName();
149
				break;
150
			case KXmlParser.END_TAG:
151
				if (tag.compareTo(KmlTags.POLYGON) == 0){						
152
					endFeature = true;
153
					handler.getContentHandler().endPolygon(polygon);
132 154
				}
133
			}			
134
		} catch (XmlPullParserException e) {
135
			throw new KmlBodyParseException(e);
136
		} catch (IOException e) {
137
			throw new KmlBodyParseException(e);
155
				break;
156
			case KXmlParser.TEXT:					
157

  
158
				break;
159
			}
160
			if (!endFeature){					
161
				currentTag = parser.next();
162
				tag = parser.getName();
163
			}
138 164
		}	
165

  
139 166
		return polygon;
140 167
	}
141 168
}
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/bindings/geometries/LinearRingBinding.java
53 53
 *
54 54
 * $Id$
55 55
 * $Log$
56
 * Revision 1.2  2007-04-14 16:08:07  jorpiell
56
 * Revision 1.3  2007-05-08 08:22:37  jorpiell
57
 * Add comments to create javadocs
58
 *
59
 * Revision 1.2  2007/04/14 16:08:07  jorpiell
57 60
 * Kml writing support added
58 61
 *
59 62
 * Revision 1.1  2007/04/13 13:16:21  jorpiell
......
62 65
 *
63 66
 */
64 67
/**
68
 * It parses the linearRing KML tag. Example:
69
 * <p>
70
 * <pre>
71
 * <code>
72
 * &lt;LinearRing&gt;
73
 * &lt;coordinates&gt;0.0,0.0 100.0,0.0 50.0,100.0 0.0,0.0&lt;/coordinates&gt;
74
 * &lt;/LinearRing&gt;
75
 * </code>
76
 * </pre>
77
 * </p> 
65 78
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
79
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#linearring
66 80
 */
67 81
public class LinearRingBinding {
68
	
69
	public static double[][] parse(XmlPullParser parser,GPEKmlParser handler) throws KmlBodyParseException {
82

  
83
	/**
84
	 * It parses the linearRing tag
85
	 * @param parser
86
	 * The XML parser
87
	 * @param handler
88
	 * The GPE parser that contains the content handler and
89
	 * the error handler
90
	 * @return
91
	 * It retuns a matrix of doubles with 3 columns (x,y,z) and
92
	 * one row for each coordinate.
93
	 * @throws IOException 
94
	 * @throws XmlPullParserException 
95
	 * @throws XmlPullParserException
96
	 * @throws IOException
97
	 */
98
	public static double[][] parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException {
70 99
		boolean endFeature = false;
71 100
		int currentTag;
72 101
		double[][] coordinates = null;
73
				
74
		try {
75
			String tag = parser.getName();
76
			currentTag = parser.getEventType();
77
			
78
			while (!endFeature){
79
				switch(currentTag){
80
				case KXmlParser.START_TAG:
81
					if (tag.compareTo(KmlTags.COORDINATES) == 0){
82
						coordinates = CoordinatesTypeBinding.parse(parser, handler);
83
					}
84
					break;
85
				case KXmlParser.END_TAG:
86
					if (tag.compareTo(KmlTags.LINEARRING) == 0){						
87
						endFeature = true;
88
					}
89
					break;
90
				case KXmlParser.TEXT:					
91
					
92
					break;
102

  
103
		String tag = parser.getName();
104
		currentTag = parser.getEventType();
105

  
106
		while (!endFeature){
107
			switch(currentTag){
108
			case KXmlParser.START_TAG:
109
				if (tag.compareTo(KmlTags.COORDINATES) == 0){
110
					coordinates = CoordinatesTypeBinding.parse(parser, handler);
93 111
				}
94
				if (!endFeature){					
95
					currentTag = parser.next();
96
					tag = parser.getName();
112
				break;
113
			case KXmlParser.END_TAG:
114
				if (tag.compareTo(KmlTags.LINEARRING) == 0){						
115
					endFeature = true;
97 116
				}
98
			}			
99
		} catch (XmlPullParserException e) {
100
			throw new KmlBodyParseException(e);
101
		} catch (IOException e) {
102
			throw new KmlBodyParseException(e);
103
		}
117
				break;
118
			case KXmlParser.TEXT:					
119

  
120
				break;
121
			}
122
			if (!endFeature){					
123
				currentTag = parser.next();
124
				tag = parser.getName();
125
			}
126
		}			
104 127
		return coordinates;
105 128
	}
106 129
}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff