svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / utils / DumbXMLParser.java @ 40559
History | View | Annotate | Download (2.98 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 |
/*
|
25 |
* Created on 07-sep-2005
|
26 |
*/
|
27 |
package org.gvsig.remoteclient.utils; |
28 |
import java.awt.geom.Rectangle2D; |
29 |
import java.util.TreeMap; |
30 |
|
31 |
/**
|
32 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
33 |
*/
|
34 |
public class DumbXMLParser { |
35 |
public Rectangle2D getBoundingBox(String l) { |
36 |
// System.out.println("l='"+l+"'");
|
37 |
TreeMap pairs = getPairs(l);
|
38 |
return getBoundingBox(pairs);
|
39 |
} |
40 |
|
41 |
public Rectangle2D getBoundingBox(TreeMap pairs) { |
42 |
double minX = Double.parseDouble((String)pairs.get("minx")); |
43 |
double minY = Double.parseDouble((String)pairs.get("miny")); |
44 |
double maxX = Double.parseDouble((String)pairs.get("maxx")); |
45 |
double maxY = Double.parseDouble((String)pairs.get("maxy")); |
46 |
|
47 |
return new Rectangle2D.Double(minX, minY, maxX-minX, maxY-minY); |
48 |
} |
49 |
|
50 |
public TreeMap getPairs(String l) { |
51 |
TreeMap data = new TreeMap(); |
52 |
int pos = l.indexOf("="); |
53 |
while (pos>0) { |
54 |
String cmd = l.substring(l.lastIndexOf(" ", pos)+1, |
55 |
l.indexOf("\"", pos+2)+1); |
56 |
//System.out.println(cmd);
|
57 |
int comilla = cmd.indexOf("\""); |
58 |
if (comilla > 0) { |
59 |
String key = l.substring(l.lastIndexOf(" ", pos)+1, pos); |
60 |
String value = cmd.substring(comilla+1,cmd.length()-1); |
61 |
data.put(key.toLowerCase(), value); |
62 |
} |
63 |
pos = l.indexOf("=", pos+1); |
64 |
} |
65 |
return data;
|
66 |
} |
67 |
|
68 |
/**
|
69 |
* saca un valor double de una linea del tipo
|
70 |
* <westBoundLongitude>-180</westBoundLongitude>
|
71 |
* @param l
|
72 |
* @return
|
73 |
*/
|
74 |
public double getValueDouble(String l) { |
75 |
return Double.parseDouble(getValue(l)); |
76 |
} |
77 |
|
78 |
/**
|
79 |
* saca un valor double de una linea del tipo
|
80 |
* <westBoundLongitude>-180</westBoundLongitude>
|
81 |
* @param l
|
82 |
* @return
|
83 |
*/
|
84 |
public String getValue(String l) { |
85 |
int pos = l.indexOf(">"); |
86 |
return l.substring(pos+1, l.indexOf("<", pos)); |
87 |
} |
88 |
|
89 |
public String getToken(String l, int num) { |
90 |
int pos = l.indexOf("<"); |
91 |
for (int i=0; i<num; i++) |
92 |
pos = l.indexOf("<", pos+1); |
93 |
return l.substring(pos+1, l.indexOf(">", pos)); |
94 |
} |
95 |
|
96 |
public int countTokens(String l) { |
97 |
int times = 0; |
98 |
int pos = l.indexOf("<"); |
99 |
while (pos >= 0) { |
100 |
times ++; pos = l.indexOf("<", pos+1); |
101 |
} |
102 |
return times;
|
103 |
} |
104 |
} |