Replaced GeoRSSUtils#trimWhitespace by Strings#trimToEmpty

This commit is contained in:
Patrick Gotthard 2014-04-18 18:38:16 +02:00
parent 6c676c8c60
commit 84d331a57e
3 changed files with 9 additions and 46 deletions

View file

@ -29,6 +29,7 @@ import org.rometools.feed.module.georss.geometries.Polygon;
import org.rometools.feed.module.georss.geometries.Position;
import org.rometools.feed.module.georss.geometries.PositionList;
import com.rometools.utils.Strings;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.io.ModuleParser;
@ -41,19 +42,11 @@ import com.sun.syndication.io.ModuleParser;
*/
public class GMLParser implements ModuleParser {
/*
* (non-Javadoc)
* @see com.sun.syndication.io.ModuleParser#getNamespaceUri()
*/
@Override
public String getNamespaceUri() {
return GeoRSSModule.GEORSS_GEORSS_URI;
}
/*
* (non-Javadoc)
* @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element)
*/
@Override
public Module parse(final Element element, final Locale locale) {
final Module geoRssModule = parseGML(element);
@ -62,7 +55,7 @@ public class GMLParser implements ModuleParser {
private static PositionList parsePosList(final Element element) {
final String coordinates = element.getText();
final String[] coord = GeoRSSUtils.trimWhitespace(coordinates).split(" ");
final String[] coord = Strings.trimToEmpty(coordinates).split(" ");
final PositionList posList = new PositionList();
for (int i = 0; i < coord.length; i += 2) {
posList.add(Double.parseDouble(coord[i]), Double.parseDouble(coord[i + 1]));
@ -82,7 +75,7 @@ public class GMLParser implements ModuleParser {
if (posElement != null) {
geoRSSModule = new GMLModuleImpl();
final String coordinates = posElement.getText();
final String[] coord = GeoRSSUtils.trimWhitespace(coordinates).split(" ");
final String[] coord = Strings.trimToEmpty(coordinates).split(" ");
final Position pos = new Position(Double.parseDouble(coord[0]), Double.parseDouble(coord[1]));
geoRSSModule.setGeometry(new Point(pos));
}
@ -140,9 +133,9 @@ public class GMLParser implements ModuleParser {
if (lowerElement != null && upperElement != null) {
geoRSSModule = new GMLModuleImpl();
final String lowerCoordinates = lowerElement.getText();
final String[] lowerCoord = GeoRSSUtils.trimWhitespace(lowerCoordinates).split(" ");
final String[] lowerCoord = Strings.trimToEmpty(lowerCoordinates).split(" ");
final String upperCoordinates = upperElement.getText();
final String[] upperCoord = GeoRSSUtils.trimWhitespace(upperCoordinates).split(" ");
final String[] upperCoord = Strings.trimToEmpty(upperCoordinates).split(" ");
final Envelope envelope = new Envelope(Double.parseDouble(lowerCoord[0]), Double.parseDouble(lowerCoord[1]), Double.parseDouble(upperCoord[0]),
Double.parseDouble(upperCoord[1]));
geoRSSModule.setGeometry(envelope);

View file

@ -28,33 +28,6 @@ import com.sun.syndication.feed.synd.SyndFeed;
*/
public class GeoRSSUtils {
static String trimWhitespace(final String in) {
if (in == null) {
return "";
}
final StringBuffer strbuf = new StringBuffer();
int i = 0;
for (; i < in.length() && Character.isWhitespace(in.charAt(i)); ++i) {
;
}
boolean wasWhite = false;
for (; i < in.length(); ++i) {
final char ch = in.charAt(i);
if (Character.isWhitespace(ch)) {
wasWhite = true;
} else {
if (wasWhite) {
strbuf.append(' ');
}
strbuf.append(ch);
wasWhite = false;
}
}
return strbuf.toString();
}
/**
* This convenience method checks whether there is any geoRss Element and will return it (georss simple or W3GGeo).
*

View file

@ -27,6 +27,7 @@ import org.rometools.feed.module.georss.geometries.Polygon;
import org.rometools.feed.module.georss.geometries.Position;
import org.rometools.feed.module.georss.geometries.PositionList;
import com.rometools.utils.Strings;
import com.sun.syndication.feed.module.Module;
import com.sun.syndication.io.ModuleParser;
@ -50,7 +51,7 @@ public class SimpleParser implements ModuleParser {
private static PositionList parsePosList(final Element element) {
final String coordinates = element.getText();
final String[] coord = GeoRSSUtils.trimWhitespace(coordinates).split(" ");
final String[] coord = Strings.trimToEmpty(coordinates).split(" ");
final PositionList posList = new PositionList();
for (int i = 0; i < coord.length; i += 2) {
posList.add(Double.parseDouble(coord[i]), Double.parseDouble(coord[i + 1]));
@ -58,10 +59,6 @@ public class SimpleParser implements ModuleParser {
return posList;
}
/*
* (non-Javadoc)
* @see com.sun.syndication.io.ModuleParser#parse(org.jdom2.Element)
*/
@Override
public Module parse(final Element element, final Locale locale) {
final Module geoRssModule = parseSimple(element);
@ -78,7 +75,7 @@ public class SimpleParser implements ModuleParser {
final Element whereElement = element.getChild("where", GeoRSSModule.SIMPLE_NS);
if (pointElement != null) {
geoRSSModule = new SimpleModuleImpl();
final String coordinates = GeoRSSUtils.trimWhitespace(pointElement.getText());
final String coordinates = Strings.trimToEmpty(pointElement.getText());
if (!"".equals(coordinates)) {
final String[] coord = coordinates.split(" ");
final Position pos = new Position(Double.parseDouble(coord[0]), Double.parseDouble(coord[1]));
@ -97,7 +94,7 @@ public class SimpleParser implements ModuleParser {
} else if (boxElement != null) {
geoRSSModule = new SimpleModuleImpl();
final String coordinates = boxElement.getText();
final String[] coord = GeoRSSUtils.trimWhitespace(coordinates).split(" ");
final String[] coord = Strings.trimToEmpty(coordinates).split(" ");
final Envelope envelope = new Envelope(Double.parseDouble(coord[0]), Double.parseDouble(coord[1]), Double.parseDouble(coord[2]),
Double.parseDouble(coord[3]));
geoRSSModule.setGeometry(envelope);