File tree

3 files changed

+58
-27
lines changed

3 files changed

+58
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ protected Feed(org.w3c.dom.Node node) {
4444
if (nodeName.equals("description") || nodeName.equals("subtitle")){
4545
description = nodeValue;
4646
}
47-
if (nodeName.equals("where") || nodeName.equals("georss:where") ||
48-
nodeName.equals("point") || nodeName.equals("georss:point") ||
49-
nodeName.equals("line") || nodeName.equals("georss:line") ||
50-
nodeName.equals("polygon") || nodeName.equals("georss:polygon") ||
51-
nodeName.equals("box") || nodeName.equals("georss:box")){
52-
try{
53-
//geometry = new Parser(nodeValue).getGeometry();
5447

55-
Class classToLoad = Class.forName("javaxt.geospatial.coordinate.Parser");//, true, child);
56-
java.lang.reflect.Constructor constructor = classToLoad.getDeclaredConstructor(new Class[] {String.class});
57-
java.lang.reflect.Method method = classToLoad.getDeclaredMethod ("getGeometry");
58-
Object instance = constructor.newInstance();
59-
geometry = method.invoke(instance);
6048

49+
//Parse Location Information (GeoRSS)
50+
if (nodeName.equals("where") || nodeName.equals("georss:where")){
51+
NodeList nodes = node.getChildNodes();
52+
for (int j=0; j<nodes.getLength(); j++){
53+
if (nodes.item(j).getNodeType()==1){
54+
if (Item.isGeometryNode(nodes.item(j).getNodeName().toLowerCase())){
55+
geometry = Item.getGeometry(DOM.getNodeValue(nodes.item(j)).trim());
56+
if (geometry!=null) break;
57+
}
58+
}
6159
}
62-
catch(Exception e){}
60+
}
61+
if (Item.isGeometryNode(nodeName)){
62+
geometry = Item.getGeometry(nodeValue);
6363
}
6464

6565

Original file line numberDiff line numberDiff line change
@@ -75,20 +75,19 @@ protected Item(org.w3c.dom.Node node) {
7575

7676

7777
//Parse Location Information (GeoRSS)
78-
if (nodeName.equals("where") || nodeName.equals("georss:where") ||
79-
nodeName.equals("point") || nodeName.equals("georss:point") ||
80-
nodeName.equals("line") || nodeName.equals("georss:line") ||
81-
nodeName.equals("polygon") || nodeName.equals("georss:polygon") ||
82-
nodeName.equals("box") || nodeName.equals("georss:box")){
83-
try{
84-
//geometry = new Parser(nodeValue).getGeometry();
85-
Class classToLoad = Class.forName("javaxt.geospatial.coordinate.Parser");//, true, child);
86-
java.lang.reflect.Constructor constructor = classToLoad.getDeclaredConstructor(new Class[] {String.class});
87-
java.lang.reflect.Method method = classToLoad.getDeclaredMethod ("getGeometry");
88-
Object instance = constructor.newInstance();
89-
geometry = method.invoke(instance);
78+
if (nodeName.equals("where") || nodeName.equals("georss:where")){
79+
NodeList nodes = node.getChildNodes();
80+
for (int j=0; j<nodes.getLength(); j++){
81+
if (nodes.item(j).getNodeType()==1){
82+
if (isGeometryNode(nodes.item(j).getNodeName().toLowerCase())){
83+
geometry = getGeometry(DOM.getNodeValue(nodes.item(j)).trim());
84+
if (geometry!=null) break;
85+
}
86+
}
9087
}
91-
catch(Exception e){}
88+
}
89+
if (isGeometryNode(nodeName)){
90+
geometry = getGeometry(nodeValue);
9291
}
9392

9493

@@ -99,6 +98,39 @@ protected Item(org.w3c.dom.Node node) {
9998
}
10099

101100

101+
protected static boolean isGeometryNode(String nodeName){
102+
String namespace = null;
103+
if (nodeName.contains(":")){
104+
namespace = nodeName.substring(0, nodeName.lastIndexOf(":"));
105+
nodeName = nodeName.substring(nodeName.lastIndexOf(":")+1);
106+
}
107+
if (namespace==null || namespace.equals("gml") || namespace.equals("georss"))
108+
return
109+
(nodeName.equals("point") || nodeName.equals("multipoint") ||
110+
nodeName.equals("line") ||
111+
nodeName.equals("linestring") || nodeName.equals("multilinestring") ||
112+
nodeName.equals("polygon") || nodeName.equals("multipolygon") ||
113+
nodeName.equals("box") || nodeName.equals("envelope"));
114+
else return false;
115+
}
116+
117+
118+
protected static Object getGeometry(String nodeValue){
119+
try{
120+
//geometry = new Parser(nodeValue).getGeometry();
121+
Class classToLoad = Class.forName("javaxt.geospatial.coordinate.Parser");
122+
java.lang.reflect.Constructor constructor = classToLoad.getDeclaredConstructor(new Class[] {String.class});
123+
java.lang.reflect.Method method = classToLoad.getDeclaredMethod("getGeometry");
124+
Object instance = constructor.newInstance(new Object[] { nodeValue });
125+
return method.invoke(instance);
126+
}
127+
catch(Exception e){
128+
//e.printStackTrace();
129+
return null;
130+
}
131+
}
132+
133+
102134

103135

104136
public String getTitle(){ return title; }
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package javaxt.rss;
2-
32
import org.w3c.dom.*;
43
import javaxt.xml.DOM;
54

0 commit comments

Comments
 (0)