location is populated with lat and lon if possible

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@248 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-10-08 18:50:52 +00:00
parent 19c9c269e2
commit 8797d02a4b
8 changed files with 66 additions and 43 deletions

View file

@ -34,10 +34,10 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory; import org.xmlpull.v1.XmlPullParserFactory;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.Connection; import de.schildbach.pte.dto.Connection;
import de.schildbach.pte.dto.Departure; import de.schildbach.pte.dto.Departure;
import de.schildbach.pte.dto.GetConnectionDetailsResult; import de.schildbach.pte.dto.GetConnectionDetailsResult;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType; import de.schildbach.pte.dto.LocationType;
import de.schildbach.pte.dto.NearbyStationsResult; import de.schildbach.pte.dto.NearbyStationsResult;
import de.schildbach.pte.dto.QueryConnectionsResult; import de.schildbach.pte.dto.QueryConnectionsResult;
@ -76,19 +76,17 @@ public abstract class AbstractEfaProvider implements NetworkProvider
XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvName"); XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvName");
final String nameState = pp.getAttributeValue(null, "state"); final String nameState = pp.getAttributeValue(null, "state");
if ("list".equals(nameState)) if ("list".equals(nameState))
processOdvNameElem(results, pp); while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
results.add(processOdvNameElem(pp));
// parse assigned stops // parse assigned stops
if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops")) if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops"))
{ {
while (XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvAssignedStop")) while (XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvAssignedStop"))
{ {
final int id = Integer.parseInt(pp.getAttributeValue(null, "stopID")); final Location location = processItdOdvAssignedStop(pp);
final String name = normalizeLocationName(pp.getAttributeValue(null, "nameWithPlace")); if (!results.contains(location))
results.add(location);
final Location autocomplete = new Location(LocationType.STATION, id, name);
if (!results.contains(autocomplete))
results.add(autocomplete);
XmlPullUtil.skipRestOfTree(pp); XmlPullUtil.skipRestOfTree(pp);
} }
@ -102,17 +100,33 @@ public abstract class AbstractEfaProvider implements NetworkProvider
} }
} }
private void processOdvNameElem(final List<Location> results, final XmlPullParser pp) throws XmlPullParserException, IOException private Location processOdvNameElem(final XmlPullParser pp) throws XmlPullParserException, IOException
{ {
while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem")) final String type = pp.getAttributeValue(null, "anyType");
int id = Integer.parseInt(pp.getAttributeValue(null, "id"));
if (id < 0)
id = 0;
int lat = 0, lon = 0;
if ("WGS84".equals(pp.getAttributeValue(null, "mapName")))
{ {
final String type = pp.getAttributeValue(null, "anyType"); lat = Integer.parseInt(pp.getAttributeValue(null, "y"));
int id = Integer.parseInt(pp.getAttributeValue(null, "id")); lon = Integer.parseInt(pp.getAttributeValue(null, "x"));
if (id < 0)
id = 0;
final String name = normalizeLocationName(pp.nextText());
results.add(new Location(type(type), id, name));
} }
final String name = normalizeLocationName(pp.nextText());
return new Location(type(type), id, lat, lon, name);
}
private Location processItdOdvAssignedStop(final XmlPullParser pp)
{
final int id = Integer.parseInt(pp.getAttributeValue(null, "stopID"));
int lat = 0, lon = 0;
if ("WGS84".equals(pp.getAttributeValue(null, "mapName")))
{
lat = Integer.parseInt(pp.getAttributeValue(null, "y"));
lon = Integer.parseInt(pp.getAttributeValue(null, "x"));
}
final String name = normalizeLocationName(pp.getAttributeValue(null, "nameWithPlace"));
return new Location(LocationType.STATION, id, lat, lon, name);
} }
private static LocationType type(final String type) private static LocationType type(final String type)
@ -651,7 +665,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
if ("list".equals(originState)) if ("list".equals(originState))
{ {
ambiguousFrom = new ArrayList<Location>(); ambiguousFrom = new ArrayList<Location>();
processOdvNameElem(ambiguousFrom, pp); while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
ambiguousFrom.add(processOdvNameElem(pp));
} }
else if ("identified".equals(originState)) else if ("identified".equals(originState))
{ {
@ -667,7 +682,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
if ("list".equals(destinationState)) if ("list".equals(destinationState))
{ {
ambiguousTo = new ArrayList<Location>(); ambiguousTo = new ArrayList<Location>();
processOdvNameElem(ambiguousTo, pp); while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
ambiguousTo.add(processOdvNameElem(pp));
} }
else if ("identified".equals(destinationState)) else if ("identified".equals(destinationState))
{ {
@ -683,7 +699,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
if ("list".equals(viaState)) if ("list".equals(viaState))
{ {
ambiguousVia = new ArrayList<Location>(); ambiguousVia = new ArrayList<Location>();
processOdvNameElem(ambiguousVia, pp); while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
ambiguousVia.add(processOdvNameElem(pp));
} }
else if ("identified".equals(viaState)) else if ("identified".equals(viaState))
{ {

View file

@ -75,13 +75,14 @@ public final class BahnProvider implements NetworkProvider
final Matcher mSingle = P_SINGLE_NAME.matcher(page); final Matcher mSingle = P_SINGLE_NAME.matcher(page);
if (mSingle.matches()) if (mSingle.matches())
{ {
results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), ParserUtils.resolveEntities(mSingle.group(1)))); results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), 0, 0, ParserUtils.resolveEntities(mSingle.group(1))));
} }
else else
{ {
final Matcher mMulti = P_MULTI_NAME.matcher(page); final Matcher mMulti = P_MULTI_NAME.matcher(page);
while (mMulti.find()) while (mMulti.find())
results.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), ParserUtils.resolveEntities(mMulti.group(2)))); results
.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), 0, 0, ParserUtils.resolveEntities(mMulti.group(2))));
} }
return results; return results;
@ -204,7 +205,7 @@ public final class BahnProvider implements NetworkProvider
{ {
final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim(); final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim();
if (!addresses.contains(address)) if (!addresses.contains(address))
addresses.add(new Location(LocationType.ANY, 0, address)); addresses.add(new Location(LocationType.ANY, 0, 0, 0, address));
} }
if (type.equals("REQ0JourneyStopsS0K")) if (type.equals("REQ0JourneyStopsS0K"))

View file

@ -93,13 +93,13 @@ public class MvvProvider extends AbstractEfaProvider
final int locationId = Integer.parseInt(mAutocompleteFine.group(3)); final int locationId = Integer.parseInt(mAutocompleteFine.group(3));
if (type.equals("stop")) if (type.equals("stop"))
results.add(new Location(LocationType.STATION, locationId, location)); results.add(new Location(LocationType.STATION, locationId, 0, 0, location));
else if (type.equals("street")) else if (type.equals("street"))
results.add(new Location(LocationType.ADDRESS, 0, location)); results.add(new Location(LocationType.ADDRESS, 0, 0, 0, location));
else if (type.equals("singlehouse")) else if (type.equals("singlehouse"))
results.add(new Location(LocationType.ADDRESS, 0, location)); results.add(new Location(LocationType.ADDRESS, 0, 0, 0, location));
else if (type.equals("poi")) else if (type.equals("poi"))
results.add(new Location(LocationType.POI, 0, location)); results.add(new Location(LocationType.POI, 0, 0, 0, location));
else else
throw new IllegalStateException("unknown type " + type + " on " + uri); throw new IllegalStateException("unknown type " + type + " on " + uri);
} }
@ -364,7 +364,7 @@ public class MvvProvider extends AbstractEfaProvider
{ {
final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim(); final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim();
if (!addresses.contains(address)) if (!addresses.contains(address))
addresses.add(new Location(LocationType.ANY, 0, address)); addresses.add(new Location(LocationType.ANY, 0, 0, 0, address));
} }
if (type.equals("name_origin")) if (type.equals("name_origin"))

View file

@ -94,7 +94,7 @@ public class OebbProvider extends AbstractHafasProvider
if (m.matches()) if (m.matches())
{ {
final int localId = Integer.parseInt(m.group(1)); final int localId = Integer.parseInt(m.group(1));
results.add(new Location(LocationType.STATION, localId, value)); results.add(new Location(LocationType.STATION, localId, 0, 0, value));
} }
else else
{ {
@ -103,11 +103,11 @@ public class OebbProvider extends AbstractHafasProvider
} }
else if (type == 2) // address else if (type == 2) // address
{ {
results.add(new Location(LocationType.ADDRESS, 0, value)); results.add(new Location(LocationType.ADDRESS, 0, 0, 0, value));
} }
else if (type == 4) // poi else if (type == 4) // poi
{ {
results.add(new Location(LocationType.ANY, 0, value)); results.add(new Location(LocationType.ANY, 0, 0, 0, value));
} }
else else
{ {
@ -264,7 +264,7 @@ public class OebbProvider extends AbstractHafasProvider
{ {
final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim(); final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim();
if (!addresses.contains(address)) if (!addresses.contains(address))
addresses.add(new Location(LocationType.ANY, 0, address)); addresses.add(new Location(LocationType.ANY, 0, 0, 0, address));
} }
if (type.equals("REQ0JourneyStopsS0K")) if (type.equals("REQ0JourneyStopsS0K"))

View file

@ -75,13 +75,14 @@ public class RmvProvider extends AbstractHafasProvider
final Matcher mSingle = P_SINGLE_NAME.matcher(page); final Matcher mSingle = P_SINGLE_NAME.matcher(page);
if (mSingle.matches()) if (mSingle.matches())
{ {
results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), ParserUtils.resolveEntities(mSingle.group(1)))); results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), 0, 0, ParserUtils.resolveEntities(mSingle.group(1))));
} }
else else
{ {
final Matcher mMulti = P_MULTI_NAME.matcher(page); final Matcher mMulti = P_MULTI_NAME.matcher(page);
while (mMulti.find()) while (mMulti.find())
results.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), ParserUtils.resolveEntities(mMulti.group(2)))); results
.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), 0, 0, ParserUtils.resolveEntities(mMulti.group(2))));
} }
return results; return results;
@ -202,7 +203,7 @@ public class RmvProvider extends AbstractHafasProvider
{ {
final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim(); final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim();
if (!addresses.contains(address)) if (!addresses.contains(address))
addresses.add(new Location(LocationType.ANY, 0, address)); addresses.add(new Location(LocationType.ANY, 0, 0, 0, address));
} }
if (type == null) if (type == null)

View file

@ -72,13 +72,14 @@ public class SbbProvider extends AbstractHafasProvider
final Matcher mSingle = P_SINGLE_NAME.matcher(page); final Matcher mSingle = P_SINGLE_NAME.matcher(page);
if (mSingle.matches()) if (mSingle.matches())
{ {
results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), ParserUtils.resolveEntities(mSingle.group(1)))); results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), 0, 0, ParserUtils.resolveEntities(mSingle.group(1))));
} }
else else
{ {
final Matcher mMulti = P_MULTI_NAME.matcher(page); final Matcher mMulti = P_MULTI_NAME.matcher(page);
while (mMulti.find()) while (mMulti.find())
results.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), ParserUtils.resolveEntities(mMulti.group(2)))); results
.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), 0, 0, ParserUtils.resolveEntities(mMulti.group(2))));
} }
return results; return results;
@ -179,7 +180,7 @@ public class SbbProvider extends AbstractHafasProvider
{ {
final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim(); final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim();
if (!addresses.contains(address)) if (!addresses.contains(address))
addresses.add(new Location(LocationType.ANY, 0, address)); addresses.add(new Location(LocationType.ANY, 0, 0, 0, address));
} }
if (type.equals("REQ0JourneyStopsS0K")) if (type.equals("REQ0JourneyStopsS0K"))

View file

@ -83,7 +83,7 @@ public final class VbbProvider implements NetworkProvider
final Matcher mSingle = P_SINGLE_MASTID.matcher(page); final Matcher mSingle = P_SINGLE_MASTID.matcher(page);
if (mSingle.matches()) if (mSingle.matches())
{ {
results.add(new Location(LocationType.ANY, 0 /* TODO */, ParserUtils.resolveEntities(mSingle.group(1)))); results.add(new Location(LocationType.ANY, 0, 0, 0, ParserUtils.resolveEntities(mSingle.group(1))));
} }
} }
else else
@ -93,14 +93,14 @@ public final class VbbProvider implements NetworkProvider
final Matcher mSingle = P_SINGLE_NAME.matcher(page); final Matcher mSingle = P_SINGLE_NAME.matcher(page);
if (mSingle.matches()) if (mSingle.matches())
{ {
results.add(new Location(LocationType.ANY, 0 /* TODO */, ParserUtils.resolveEntities(mSingle.group(1)))); results.add(new Location(LocationType.ANY, 0, 0, 0, ParserUtils.resolveEntities(mSingle.group(1))));
} }
else else
{ {
final Matcher mMulti = P_MULTI_NAME.matcher(page); final Matcher mMulti = P_MULTI_NAME.matcher(page);
while (mMulti.find()) while (mMulti.find())
results.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), ParserUtils results.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), 0, 0, ParserUtils.resolveEntities(mMulti
.resolveEntities(mMulti.group(2)))); .group(2))));
} }
} }
@ -244,7 +244,7 @@ public final class VbbProvider implements NetworkProvider
{ {
final String address = ParserUtils.resolveEntities(mAddress.group(1)); final String address = ParserUtils.resolveEntities(mAddress.group(1));
if (!addresses.contains(address)) if (!addresses.contains(address))
addresses.add(new Location(LocationType.ANY, 0, address)); addresses.add(new Location(LocationType.ANY, 0, 0, 0, address));
} }
if (addresses.isEmpty()) if (addresses.isEmpty())

View file

@ -23,12 +23,15 @@ public final class Location
{ {
public final LocationType type; public final LocationType type;
public final int id; public final int id;
public final int lat, lon;
public final String name; public final String name;
public Location(final LocationType type, final int id, final String name) public Location(final LocationType type, final int id, final int lat, final int lon, final String name)
{ {
this.type = type; this.type = type;
this.id = id; this.id = id;
this.lat = lat;
this.lon = lon;
this.name = name; this.name = name;
} }