root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / utils / DumbXMLParser.java @ 3323
History | View | Annotate | Download (2.04 KB)
1 |
/*
|
---|---|
2 |
* Created on 07-sep-2005
|
3 |
*/
|
4 |
package org.gvsig.remoteClient.utils; |
5 |
import java.awt.geom.Rectangle2D; |
6 |
import java.util.TreeMap; |
7 |
|
8 |
/**
|
9 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
10 |
*/
|
11 |
public class DumbXMLParser { |
12 |
public Rectangle2D getBoundingBox(String l) { |
13 |
// System.out.println("l='"+l+"'");
|
14 |
TreeMap pairs = getPairs(l);
|
15 |
return getBoundingBox(pairs);
|
16 |
} |
17 |
|
18 |
public Rectangle2D getBoundingBox(TreeMap pairs) { |
19 |
double minX = Double.parseDouble((String)pairs.get("minx")); |
20 |
double minY = Double.parseDouble((String)pairs.get("miny")); |
21 |
double maxX = Double.parseDouble((String)pairs.get("maxx")); |
22 |
double maxY = Double.parseDouble((String)pairs.get("maxy")); |
23 |
|
24 |
return new Rectangle2D.Double(minX, minY, maxX-minX, maxY-minY); |
25 |
} |
26 |
|
27 |
public TreeMap getPairs(String l) { |
28 |
TreeMap data = new TreeMap(); |
29 |
int pos = l.indexOf("="); |
30 |
while (pos>0) { |
31 |
String cmd = l.substring(l.lastIndexOf(" ", pos)+1, |
32 |
l.indexOf("\"", pos+2)+1); |
33 |
//System.out.println(cmd);
|
34 |
int comilla = cmd.indexOf("\""); |
35 |
if (comilla > 0) { |
36 |
String key = l.substring(l.lastIndexOf(" ", pos)+1, pos); |
37 |
String value = cmd.substring(comilla+1,cmd.length()-1); |
38 |
data.put(key.toLowerCase(), value); |
39 |
} |
40 |
pos = l.indexOf("=", pos+1); |
41 |
} |
42 |
return data;
|
43 |
} |
44 |
|
45 |
/**
|
46 |
* saca un valor double de una linea del tipo
|
47 |
* <westBoundLongitude>-180</westBoundLongitude>
|
48 |
* @param l
|
49 |
* @return
|
50 |
*/
|
51 |
public double getValueDouble(String l) { |
52 |
return Double.parseDouble(getValue(l)); |
53 |
} |
54 |
|
55 |
/**
|
56 |
* saca un valor double de una linea del tipo
|
57 |
* <westBoundLongitude>-180</westBoundLongitude>
|
58 |
* @param l
|
59 |
* @return
|
60 |
*/
|
61 |
public String getValue(String l) { |
62 |
int pos = l.indexOf(">"); |
63 |
return l.substring(pos+1, l.indexOf("<", pos)); |
64 |
} |
65 |
|
66 |
public String getToken(String l, int num) { |
67 |
int pos = l.indexOf("<"); |
68 |
for (int i=0; i<num; i++) |
69 |
pos = l.indexOf("<", pos+1); |
70 |
return l.substring(pos+1, l.indexOf(">", pos)); |
71 |
} |
72 |
|
73 |
public int countTokens(String l) { |
74 |
int times = 0; |
75 |
int pos = l.indexOf("<"); |
76 |
while (pos >= 0) { |
77 |
times ++; pos = l.indexOf("<", pos+1); |
78 |
} |
79 |
return times;
|
80 |
} |
81 |
} |