mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 22:58:49 +00:00
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:
parent
19c9c269e2
commit
8797d02a4b
8 changed files with 66 additions and 43 deletions
|
@ -34,10 +34,10 @@ import org.xmlpull.v1.XmlPullParser;
|
|||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
|
||||
import de.schildbach.pte.dto.Location;
|
||||
import de.schildbach.pte.dto.Connection;
|
||||
import de.schildbach.pte.dto.Departure;
|
||||
import de.schildbach.pte.dto.GetConnectionDetailsResult;
|
||||
import de.schildbach.pte.dto.Location;
|
||||
import de.schildbach.pte.dto.LocationType;
|
||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||
import de.schildbach.pte.dto.QueryConnectionsResult;
|
||||
|
@ -76,19 +76,17 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvName");
|
||||
final String nameState = pp.getAttributeValue(null, "state");
|
||||
if ("list".equals(nameState))
|
||||
processOdvNameElem(results, pp);
|
||||
while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
|
||||
results.add(processOdvNameElem(pp));
|
||||
|
||||
// parse assigned stops
|
||||
if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops"))
|
||||
{
|
||||
while (XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvAssignedStop"))
|
||||
{
|
||||
final int id = Integer.parseInt(pp.getAttributeValue(null, "stopID"));
|
||||
final String name = normalizeLocationName(pp.getAttributeValue(null, "nameWithPlace"));
|
||||
|
||||
final Location autocomplete = new Location(LocationType.STATION, id, name);
|
||||
if (!results.contains(autocomplete))
|
||||
results.add(autocomplete);
|
||||
final Location location = processItdOdvAssignedStop(pp);
|
||||
if (!results.contains(location))
|
||||
results.add(location);
|
||||
|
||||
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");
|
||||
int id = Integer.parseInt(pp.getAttributeValue(null, "id"));
|
||||
if (id < 0)
|
||||
id = 0;
|
||||
final String name = normalizeLocationName(pp.nextText());
|
||||
results.add(new Location(type(type), id, name));
|
||||
lat = Integer.parseInt(pp.getAttributeValue(null, "y"));
|
||||
lon = Integer.parseInt(pp.getAttributeValue(null, "x"));
|
||||
}
|
||||
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)
|
||||
|
@ -651,7 +665,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
if ("list".equals(originState))
|
||||
{
|
||||
ambiguousFrom = new ArrayList<Location>();
|
||||
processOdvNameElem(ambiguousFrom, pp);
|
||||
while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
|
||||
ambiguousFrom.add(processOdvNameElem(pp));
|
||||
}
|
||||
else if ("identified".equals(originState))
|
||||
{
|
||||
|
@ -667,7 +682,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
if ("list".equals(destinationState))
|
||||
{
|
||||
ambiguousTo = new ArrayList<Location>();
|
||||
processOdvNameElem(ambiguousTo, pp);
|
||||
while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
|
||||
ambiguousTo.add(processOdvNameElem(pp));
|
||||
}
|
||||
else if ("identified".equals(destinationState))
|
||||
{
|
||||
|
@ -683,7 +699,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
if ("list".equals(viaState))
|
||||
{
|
||||
ambiguousVia = new ArrayList<Location>();
|
||||
processOdvNameElem(ambiguousVia, pp);
|
||||
while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
|
||||
ambiguousVia.add(processOdvNameElem(pp));
|
||||
}
|
||||
else if ("identified".equals(viaState))
|
||||
{
|
||||
|
|
|
@ -75,13 +75,14 @@ public final class BahnProvider implements NetworkProvider
|
|||
final Matcher mSingle = P_SINGLE_NAME.matcher(page);
|
||||
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
|
||||
{
|
||||
final Matcher mMulti = P_MULTI_NAME.matcher(page);
|
||||
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;
|
||||
|
@ -204,7 +205,7 @@ public final class BahnProvider implements NetworkProvider
|
|||
{
|
||||
final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim();
|
||||
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"))
|
||||
|
|
|
@ -93,13 +93,13 @@ public class MvvProvider extends AbstractEfaProvider
|
|||
final int locationId = Integer.parseInt(mAutocompleteFine.group(3));
|
||||
|
||||
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"))
|
||||
results.add(new Location(LocationType.ADDRESS, 0, location));
|
||||
results.add(new Location(LocationType.ADDRESS, 0, 0, 0, location));
|
||||
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"))
|
||||
results.add(new Location(LocationType.POI, 0, location));
|
||||
results.add(new Location(LocationType.POI, 0, 0, 0, location));
|
||||
else
|
||||
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();
|
||||
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"))
|
||||
|
|
|
@ -94,7 +94,7 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
if (m.matches())
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@ -103,11 +103,11 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
}
|
||||
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
|
||||
{
|
||||
results.add(new Location(LocationType.ANY, 0, value));
|
||||
results.add(new Location(LocationType.ANY, 0, 0, 0, value));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -264,7 +264,7 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
{
|
||||
final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim();
|
||||
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"))
|
||||
|
|
|
@ -75,13 +75,14 @@ public class RmvProvider extends AbstractHafasProvider
|
|||
final Matcher mSingle = P_SINGLE_NAME.matcher(page);
|
||||
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
|
||||
{
|
||||
final Matcher mMulti = P_MULTI_NAME.matcher(page);
|
||||
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;
|
||||
|
@ -202,7 +203,7 @@ public class RmvProvider extends AbstractHafasProvider
|
|||
{
|
||||
final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim();
|
||||
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)
|
||||
|
|
|
@ -72,13 +72,14 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
final Matcher mSingle = P_SINGLE_NAME.matcher(page);
|
||||
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
|
||||
{
|
||||
final Matcher mMulti = P_MULTI_NAME.matcher(page);
|
||||
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;
|
||||
|
@ -179,7 +180,7 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
{
|
||||
final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim();
|
||||
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"))
|
||||
|
|
|
@ -83,7 +83,7 @@ public final class VbbProvider implements NetworkProvider
|
|||
final Matcher mSingle = P_SINGLE_MASTID.matcher(page);
|
||||
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
|
||||
|
@ -93,14 +93,14 @@ public final class VbbProvider implements NetworkProvider
|
|||
final Matcher mSingle = P_SINGLE_NAME.matcher(page);
|
||||
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
|
||||
{
|
||||
final Matcher mMulti = P_MULTI_NAME.matcher(page);
|
||||
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))));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ public final class VbbProvider implements NetworkProvider
|
|||
{
|
||||
final String address = ParserUtils.resolveEntities(mAddress.group(1));
|
||||
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())
|
||||
|
|
|
@ -23,12 +23,15 @@ public final class Location
|
|||
{
|
||||
public final LocationType type;
|
||||
public final int id;
|
||||
public final int lat, lon;
|
||||
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.id = id;
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue