Refactored some code
This commit is contained in:
parent
84d331a57e
commit
bab710d701
1 changed files with 78 additions and 29 deletions
|
@ -40,68 +40,117 @@ import com.sun.syndication.io.ModuleParser;
|
||||||
*/
|
*/
|
||||||
public class SimpleParser implements ModuleParser {
|
public class SimpleParser implements ModuleParser {
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see com.sun.syndication.io.ModuleParser#getNamespaceUri()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public String getNamespaceUri() {
|
public String getNamespaceUri() {
|
||||||
return GeoRSSModule.GEORSS_GEORSS_URI;
|
return GeoRSSModule.GEORSS_GEORSS_URI;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PositionList parsePosList(final Element element) {
|
private static PositionList parsePosList(final Element element) {
|
||||||
final String coordinates = element.getText();
|
|
||||||
final String[] coord = Strings.trimToEmpty(coordinates).split(" ");
|
PositionList posList = null;
|
||||||
final PositionList posList = new PositionList();
|
|
||||||
for (int i = 0; i < coord.length; i += 2) {
|
final String coordinates = Strings.trimToNull(element.getText());
|
||||||
posList.add(Double.parseDouble(coord[i]), Double.parseDouble(coord[i + 1]));
|
if (coordinates != null) {
|
||||||
|
|
||||||
|
posList = new PositionList();
|
||||||
|
final String[] coord = coordinates.split(" ");
|
||||||
|
for (int i = 0; i < coord.length; i += 2) {
|
||||||
|
final double latitude = Double.parseDouble(coord[i]);
|
||||||
|
final double longitude = Double.parseDouble(coord[i + 1]);
|
||||||
|
posList.add(latitude, longitude);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return posList;
|
return posList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Module parse(final Element element, final Locale locale) {
|
public Module parse(final Element element, final Locale locale) {
|
||||||
final Module geoRssModule = parseSimple(element);
|
return parseSimple(element);
|
||||||
return geoRssModule;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Module parseSimple(final Element element) {
|
static Module parseSimple(final Element element) {
|
||||||
GeoRSSModule geoRSSModule = null;
|
|
||||||
|
|
||||||
final Element pointElement = element.getChild("point", GeoRSSModule.SIMPLE_NS);
|
final Element pointElement = element.getChild("point", GeoRSSModule.SIMPLE_NS);
|
||||||
final Element lineElement = element.getChild("line", GeoRSSModule.SIMPLE_NS);
|
final Element lineElement = element.getChild("line", GeoRSSModule.SIMPLE_NS);
|
||||||
final Element polygonElement = element.getChild("polygon", GeoRSSModule.SIMPLE_NS);
|
final Element polygonElement = element.getChild("polygon", GeoRSSModule.SIMPLE_NS);
|
||||||
final Element boxElement = element.getChild("box", GeoRSSModule.SIMPLE_NS);
|
final Element boxElement = element.getChild("box", GeoRSSModule.SIMPLE_NS);
|
||||||
final Element whereElement = element.getChild("where", GeoRSSModule.SIMPLE_NS);
|
final Element whereElement = element.getChild("where", GeoRSSModule.SIMPLE_NS);
|
||||||
|
|
||||||
|
GeoRSSModule geoRSSModule = null;
|
||||||
|
|
||||||
if (pointElement != null) {
|
if (pointElement != null) {
|
||||||
geoRSSModule = new SimpleModuleImpl();
|
|
||||||
final String coordinates = Strings.trimToEmpty(pointElement.getText());
|
final String coordinates = Strings.trimToNull(pointElement.getText());
|
||||||
if (!"".equals(coordinates)) {
|
if (coordinates != null) {
|
||||||
|
|
||||||
final String[] coord = coordinates.split(" ");
|
final String[] coord = coordinates.split(" ");
|
||||||
final Position pos = new Position(Double.parseDouble(coord[0]), Double.parseDouble(coord[1]));
|
final double latitude = Double.parseDouble(coord[0]);
|
||||||
geoRSSModule.setGeometry(new Point(pos));
|
final double longitude = Double.parseDouble(coord[1]);
|
||||||
|
|
||||||
|
final Position pos = new Position(latitude, longitude);
|
||||||
|
|
||||||
|
final Point point = new Point(pos);
|
||||||
|
|
||||||
|
geoRSSModule = new SimpleModuleImpl();
|
||||||
|
geoRSSModule.setGeometry(point);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (lineElement != null) {
|
} else if (lineElement != null) {
|
||||||
geoRSSModule = new SimpleModuleImpl();
|
|
||||||
final PositionList posList = parsePosList(lineElement);
|
final PositionList posList = parsePosList(lineElement);
|
||||||
geoRSSModule.setGeometry(new LineString(posList));
|
|
||||||
|
if (posList != null) {
|
||||||
|
|
||||||
|
final LineString lineString = new LineString(posList);
|
||||||
|
|
||||||
|
geoRSSModule = new SimpleModuleImpl();
|
||||||
|
geoRSSModule.setGeometry(lineString);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} else if (polygonElement != null) {
|
} else if (polygonElement != null) {
|
||||||
geoRSSModule = new SimpleModuleImpl();
|
|
||||||
final PositionList posList = parsePosList(polygonElement);
|
final PositionList posList = parsePosList(polygonElement);
|
||||||
final Polygon poly = new Polygon();
|
if (posList != null) {
|
||||||
poly.setExterior(new LinearRing(posList));
|
|
||||||
geoRSSModule.setGeometry(poly);
|
final LinearRing linearRing = new LinearRing(posList);
|
||||||
|
|
||||||
|
final Polygon poly = new Polygon();
|
||||||
|
poly.setExterior(linearRing);
|
||||||
|
|
||||||
|
geoRSSModule = new SimpleModuleImpl();
|
||||||
|
geoRSSModule.setGeometry(poly);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} else if (boxElement != null) {
|
} else if (boxElement != null) {
|
||||||
geoRSSModule = new SimpleModuleImpl();
|
|
||||||
final String coordinates = boxElement.getText();
|
final String coordinates = Strings.trimToNull(boxElement.getText());
|
||||||
final String[] coord = Strings.trimToEmpty(coordinates).split(" ");
|
if (coordinates != null) {
|
||||||
final Envelope envelope = new Envelope(Double.parseDouble(coord[0]), Double.parseDouble(coord[1]), Double.parseDouble(coord[2]),
|
|
||||||
Double.parseDouble(coord[3]));
|
final String[] coord = coordinates.split(" ");
|
||||||
geoRSSModule.setGeometry(envelope);
|
final double bottom = Double.parseDouble(coord[0]);
|
||||||
|
final double left = Double.parseDouble(coord[1]);
|
||||||
|
final double top = Double.parseDouble(coord[2]);
|
||||||
|
final double right = Double.parseDouble(coord[3]);
|
||||||
|
|
||||||
|
final Envelope envelope = new Envelope(bottom, left, top, right);
|
||||||
|
|
||||||
|
geoRSSModule = new SimpleModuleImpl();
|
||||||
|
geoRSSModule.setGeometry(envelope);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (whereElement != null) {
|
} else if (whereElement != null) {
|
||||||
|
|
||||||
geoRSSModule = (GeoRSSModule) GMLParser.parseGML(whereElement);
|
geoRSSModule = (GeoRSSModule) GMLParser.parseGML(whereElement);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return geoRSSModule;
|
return geoRSSModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue