root / branches / v2_0_0_prep / libraries / libGPE-KML / src / org / gvsig / gpe / kml / utils / KMLUtilsParser.java @ 28113
History | View | Annotate | Download (4.96 KB)
1 |
package org.gvsig.gpe.kml.utils; |
---|---|
2 |
|
3 |
import java.util.Hashtable; |
4 |
|
5 |
import javax.xml.namespace.QName; |
6 |
|
7 |
import org.gvsig.compat.CompatLocator; |
8 |
import org.gvsig.gpe.GPELocator; |
9 |
import org.gvsig.gpe.GPEManager; |
10 |
import org.gvsig.gpe.xml.XmlProperties; |
11 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
12 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
13 |
|
14 |
|
15 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
16 |
*
|
17 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
18 |
*
|
19 |
* This program is free software; you can redistribute it and/or
|
20 |
* modify it under the terms of the GNU General Public License
|
21 |
* as published by the Free Software Foundation; either version 2
|
22 |
* of the License, or (at your option) any later version.
|
23 |
*
|
24 |
* This program is distributed in the hope that it will be useful,
|
25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27 |
* GNU General Public License for more details.
|
28 |
*
|
29 |
* You should have received a copy of the GNU General Public License
|
30 |
* along with this program; if not, write to the Free Software
|
31 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
32 |
*
|
33 |
* For more information, contact:
|
34 |
*
|
35 |
* Generalitat Valenciana
|
36 |
* Conselleria d'Infraestructures i Transport
|
37 |
* Av. Blasco Ib??ez, 50
|
38 |
* 46010 VALENCIA
|
39 |
* SPAIN
|
40 |
*
|
41 |
* +34 963862235
|
42 |
* gvsig@gva.es
|
43 |
* www.gvsig.gva.es
|
44 |
*
|
45 |
* or
|
46 |
*
|
47 |
* IVER T.I. S.A
|
48 |
* Salamanca 50
|
49 |
* 46005 Valencia
|
50 |
* Spain
|
51 |
*
|
52 |
* +34 963163400
|
53 |
* dac@iver.es
|
54 |
*/
|
55 |
/* CVS MESSAGES:
|
56 |
*
|
57 |
* $Id: GMLUtilsParser.java 189 2007-11-21 12:45:56Z csanchez $
|
58 |
* $Log$
|
59 |
* Revision 1.8 2007/06/28 13:05:09 jorpiell
|
60 |
* The Qname has been updated to the 1.5 JVM machine. The schema validation is made in the GPEWriterHandlerImplementor class
|
61 |
*
|
62 |
* Revision 1.7 2007/05/18 10:41:01 csanchez
|
63 |
* Actualizaci?n libGPE-GML eliminaci?n de clases inecesarias
|
64 |
*
|
65 |
* Revision 1.6 2007/05/16 13:00:48 csanchez
|
66 |
* Actualizaci?n de libGPE-GML
|
67 |
*
|
68 |
* Revision 1.5 2007/05/16 09:29:12 jorpiell
|
69 |
* The polygons has to be closed
|
70 |
*
|
71 |
* Revision 1.4 2007/05/15 10:14:45 jorpiell
|
72 |
* The element and the feature is managed like a Stack
|
73 |
*
|
74 |
* Revision 1.3 2007/05/15 09:35:09 jorpiell
|
75 |
* the tag names cant have blanc spaces
|
76 |
*
|
77 |
* Revision 1.2 2007/05/07 12:58:42 jorpiell
|
78 |
* Add some methods to manage the multigeometries
|
79 |
*
|
80 |
* Revision 1.1 2007/02/28 11:48:31 csanchez
|
81 |
* *** empty log message ***
|
82 |
*
|
83 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell
|
84 |
* A?adidos los proyectos de kml y gml antiguos
|
85 |
*
|
86 |
* Revision 1.3 2007/01/15 13:11:00 csanchez
|
87 |
* Sistema de Warnings y Excepciones adaptado a BasicException
|
88 |
*
|
89 |
* Revision 1.2 2006/12/22 11:25:44 csanchez
|
90 |
* Nuevo parser GML 2.x para gml's sin esquema
|
91 |
*
|
92 |
* Revision 1.1 2006/08/10 12:00:49 jorpiell
|
93 |
* Primer commit del driver de Gml
|
94 |
*
|
95 |
*
|
96 |
*/
|
97 |
/**
|
98 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
99 |
* @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
|
100 |
*/
|
101 |
public class KMLUtilsParser { |
102 |
private static GPEManager gpeManager = GPELocator.getGPEManager(); |
103 |
|
104 |
/**
|
105 |
* It returns a HashTable with the XML attributes. It has been
|
106 |
* created because the parser doesn't has a getAttribiute(AttributeName)
|
107 |
* method.
|
108 |
|
109 |
* @param parser
|
110 |
* @return
|
111 |
* @throws XmlStreamException
|
112 |
*/
|
113 |
public static Hashtable getAttributes(IXmlStreamReader parser) throws XmlStreamException{ |
114 |
Hashtable hash = new Hashtable(); |
115 |
int num_atributos = parser.getAttributeCount();
|
116 |
for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
117 |
QName atributo = parser.getAttributeName(i);
|
118 |
String valor=parser.getAttributeValue(i);
|
119 |
if (valor!=null) |
120 |
hash.put(atributo, valor); |
121 |
} |
122 |
return hash;
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* Remove the blanc symbol from a tag
|
127 |
* @param tag
|
128 |
* Tag name
|
129 |
* @return
|
130 |
* The tag without blancs
|
131 |
*/
|
132 |
public static String removeBlancSymbol(QName tag){ |
133 |
if (tag == null){ |
134 |
return null; |
135 |
} |
136 |
String blancSpace = gpeManager.getStringProperty(XmlProperties.DEFAULT_BLANC_SPACE);
|
137 |
if (blancSpace == null){ |
138 |
blancSpace = Kml2_1_Tags.DEFAULT_BLANC_SPACE; |
139 |
} |
140 |
// PROBLEM WITH COMPATIBILITY OF "replaceAll()" WITH IBM J9 JAVA MICROEDITION
|
141 |
return CompatLocator.getStringUtils().replaceAll(tag.getLocalPart(), blancSpace, " "); |
142 |
//return StringUtils.replaceAllString(tag.getLocalPart(), blancSpace, " ");
|
143 |
// return tag.replaceAll(blancSpace," ");
|
144 |
} |
145 |
|
146 |
/**
|
147 |
* Replace the blancs of a tag with the
|
148 |
* deafult blanc symbol
|
149 |
* @param name
|
150 |
* @return
|
151 |
* A tag with blancs
|
152 |
*/
|
153 |
public static String addBlancSymbol(QName name){ |
154 |
if (name == null){ |
155 |
return null; |
156 |
} |
157 |
String blancSpace = gpeManager.getStringProperty(XmlProperties.DEFAULT_BLANC_SPACE);
|
158 |
if (blancSpace == null){ |
159 |
blancSpace = Kml2_1_Tags.DEFAULT_BLANC_SPACE; |
160 |
} |
161 |
// PROBLEM WITH COMPATIBILITY OF "replaceAll()" WITH IBM J9 JAVA MICROEDITION
|
162 |
return CompatLocator.getStringUtils().replaceAll(name.getLocalPart()," ", blancSpace); |
163 |
//return StringUtils.replaceAllString(name.getLocalPart()," ",blancSpace);
|
164 |
//return tag.replaceAll(" ",blancSpace);
|
165 |
} |
166 |
} |
167 |
|