Refactored some code
This commit is contained in:
parent
bab710d701
commit
358c9416e6
1 changed files with 20 additions and 15 deletions
|
@ -22,6 +22,7 @@ import org.jdom2.Element;
|
||||||
import org.rometools.feed.module.georss.geometries.Point;
|
import org.rometools.feed.module.georss.geometries.Point;
|
||||||
import org.rometools.feed.module.georss.geometries.Position;
|
import org.rometools.feed.module.georss.geometries.Position;
|
||||||
|
|
||||||
|
import com.rometools.utils.Strings;
|
||||||
import com.sun.syndication.feed.module.Module;
|
import com.sun.syndication.feed.module.Module;
|
||||||
import com.sun.syndication.io.ModuleParser;
|
import com.sun.syndication.io.ModuleParser;
|
||||||
|
|
||||||
|
@ -34,16 +35,13 @@ import com.sun.syndication.io.ModuleParser;
|
||||||
*/
|
*/
|
||||||
public class W3CGeoParser implements ModuleParser {
|
public class W3CGeoParser implements ModuleParser {
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see com.sun.syndication.io.ModuleParser#getNamespaceUri()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public String getNamespaceUri() {
|
public String getNamespaceUri() {
|
||||||
return GeoRSSModule.GEORSS_W3CGEO_URI;
|
return GeoRSSModule.GEORSS_W3CGEO_URI;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Module parseW3C(final Element element) {
|
static Module parseW3C(final Element element) {
|
||||||
|
|
||||||
GeoRSSModule geoRSSModule = null;
|
GeoRSSModule geoRSSModule = null;
|
||||||
|
|
||||||
// do we have an optional "Point" element ?
|
// do we have an optional "Point" element ?
|
||||||
|
@ -59,27 +57,34 @@ public class W3CGeoParser implements ModuleParser {
|
||||||
if (lng == null) {
|
if (lng == null) {
|
||||||
lng = pointElement.getChild("lon", GeoRSSModule.W3CGEO_NS);
|
lng = pointElement.getChild("lon", GeoRSSModule.W3CGEO_NS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lat != null && lng != null) {
|
if (lat != null && lng != null) {
|
||||||
|
|
||||||
geoRSSModule = new W3CGeoModuleImpl();
|
geoRSSModule = new W3CGeoModuleImpl();
|
||||||
final String latTxt = lat.getText();
|
|
||||||
final String lngTxt = lng.getText();
|
final String latTxt = Strings.trimToNull(lat.getText());
|
||||||
if (!"".equals(latTxt) && !"".equals(lngTxt)) {
|
final String lngTxt = Strings.trimToNull(lng.getText());
|
||||||
final Position pos = new Position(Double.parseDouble(lat.getText()), Double.parseDouble(lng.getText()));
|
|
||||||
geoRSSModule.setGeometry(new Point(pos));
|
if (latTxt != null && lngTxt != null) {
|
||||||
|
|
||||||
|
final double latitude = Double.parseDouble(lat.getText());
|
||||||
|
final double longitude = Double.parseDouble(lng.getText());
|
||||||
|
|
||||||
|
final Position position = new Position(latitude, longitude);
|
||||||
|
|
||||||
|
final Point point = new Point(position);
|
||||||
|
|
||||||
|
geoRSSModule.setGeometry(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return geoRSSModule;
|
return geoRSSModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Module parse(final Element element, final Locale locale) {
|
public Module parse(final Element element, final Locale locale) {
|
||||||
final Module geoRssModule = parseW3C(element);
|
return parseW3C(element);
|
||||||
return geoRssModule;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue