svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / utils / DumbXMLParser.java @ 40769
History | View | Annotate | Download (2.95 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.remoteclient.utils; |
25 |
import java.awt.geom.Rectangle2D; |
26 |
import java.util.TreeMap; |
27 |
|
28 |
/**
|
29 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
30 |
*/
|
31 |
public class DumbXMLParser { |
32 |
public Rectangle2D getBoundingBox(String l) { |
33 |
// System.out.println("l='"+l+"'");
|
34 |
TreeMap pairs = getPairs(l);
|
35 |
return getBoundingBox(pairs);
|
36 |
} |
37 |
|
38 |
public Rectangle2D getBoundingBox(TreeMap pairs) { |
39 |
double minX = Double.parseDouble((String)pairs.get("minx")); |
40 |
double minY = Double.parseDouble((String)pairs.get("miny")); |
41 |
double maxX = Double.parseDouble((String)pairs.get("maxx")); |
42 |
double maxY = Double.parseDouble((String)pairs.get("maxy")); |
43 |
|
44 |
return new Rectangle2D.Double(minX, minY, maxX-minX, maxY-minY); |
45 |
} |
46 |
|
47 |
public TreeMap getPairs(String l) { |
48 |
TreeMap data = new TreeMap(); |
49 |
int pos = l.indexOf("="); |
50 |
while (pos>0) { |
51 |
String cmd = l.substring(l.lastIndexOf(" ", pos)+1, |
52 |
l.indexOf("\"", pos+2)+1); |
53 |
//System.out.println(cmd);
|
54 |
int comilla = cmd.indexOf("\""); |
55 |
if (comilla > 0) { |
56 |
String key = l.substring(l.lastIndexOf(" ", pos)+1, pos); |
57 |
String value = cmd.substring(comilla+1,cmd.length()-1); |
58 |
data.put(key.toLowerCase(), value); |
59 |
} |
60 |
pos = l.indexOf("=", pos+1); |
61 |
} |
62 |
return data;
|
63 |
} |
64 |
|
65 |
/**
|
66 |
* saca un valor double de una linea del tipo
|
67 |
* <westBoundLongitude>-180</westBoundLongitude>
|
68 |
* @param l
|
69 |
* @return
|
70 |
*/
|
71 |
public double getValueDouble(String l) { |
72 |
return Double.parseDouble(getValue(l)); |
73 |
} |
74 |
|
75 |
/**
|
76 |
* saca un valor double de una linea del tipo
|
77 |
* <westBoundLongitude>-180</westBoundLongitude>
|
78 |
* @param l
|
79 |
* @return
|
80 |
*/
|
81 |
public String getValue(String l) { |
82 |
int pos = l.indexOf(">"); |
83 |
return l.substring(pos+1, l.indexOf("<", pos)); |
84 |
} |
85 |
|
86 |
public String getToken(String l, int num) { |
87 |
int pos = l.indexOf("<"); |
88 |
for (int i=0; i<num; i++) |
89 |
pos = l.indexOf("<", pos+1); |
90 |
return l.substring(pos+1, l.indexOf(">", pos)); |
91 |
} |
92 |
|
93 |
public int countTokens(String l) { |
94 |
int times = 0; |
95 |
int pos = l.indexOf("<"); |
96 |
while (pos >= 0) { |
97 |
times ++; pos = l.indexOf("<", pos+1); |
98 |
} |
99 |
return times;
|
100 |
} |
101 |
} |