actually handles addresses

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@126 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-09-02 17:26:44 +00:00
parent 9bf136b568
commit a9533e32a2

View file

@ -171,7 +171,7 @@ public class MvvProvider implements NetworkProvider
uri.append("&locationServerActive=1"); uri.append("&locationServerActive=1");
uri.append("&useProxFootSearch=1"); // Take nearby stops into account and possibly use them instead uri.append("&useProxFootSearch=1"); // Take nearby stops into account and possibly use them instead
uri.append("&anySigWhenPerfectNoOtherMatches=1"); uri.append("&anySigWhenPerfectNoOtherMatches=1");
uri.append("&lineRestriction=403"); // uri.append("&lineRestriction=403");
if (fromType == LocationType.WGS84) if (fromType == LocationType.WGS84)
{ {
@ -195,6 +195,7 @@ public class MvvProvider implements NetworkProvider
uri.append("&reducedAnyTooManyObjFilter_origin=2"); uri.append("&reducedAnyTooManyObjFilter_origin=2");
uri.append("&type_origin=").append(locationType(fromType)); uri.append("&type_origin=").append(locationType(fromType));
uri.append("&name_origin=").append(ParserUtils.urlEncode(from, ENCODING)); // fine-grained location uri.append("&name_origin=").append(ParserUtils.urlEncode(from, ENCODING)); // fine-grained location
uri.append("&anyObjFilter_origin=").append(locationAnyObjFilter(fromType));
} }
if (toType == LocationType.WGS84) if (toType == LocationType.WGS84)
@ -219,6 +220,7 @@ public class MvvProvider implements NetworkProvider
uri.append("&reducedAnyTooManyObjFilter_destination=2"); uri.append("&reducedAnyTooManyObjFilter_destination=2");
uri.append("&type_destination=").append(locationType(toType)); uri.append("&type_destination=").append(locationType(toType));
uri.append("&name_destination=").append(ParserUtils.urlEncode(to, ENCODING)); // fine-grained location uri.append("&name_destination=").append(ParserUtils.urlEncode(to, ENCODING)); // fine-grained location
uri.append("&anyObjFilter_destination=").append(locationAnyObjFilter(toType));
} }
if (via != null) if (via != null)
@ -245,6 +247,7 @@ public class MvvProvider implements NetworkProvider
uri.append("&reducedAnyTooManyObjFilter_via=2"); uri.append("&reducedAnyTooManyObjFilter_via=2");
uri.append("&type_via=").append(locationType(viaType)); uri.append("&type_via=").append(locationType(viaType));
uri.append("&name_via=").append(ParserUtils.urlEncode(via, ENCODING)); uri.append("&name_via=").append(ParserUtils.urlEncode(via, ENCODING));
uri.append("&anyObjFilter_via=").append(locationAnyObjFilter(viaType));
} }
} }
@ -261,13 +264,25 @@ public class MvvProvider implements NetworkProvider
if (locationType == LocationType.STATION) if (locationType == LocationType.STATION)
return "stop"; return "stop";
if (locationType == LocationType.ADDRESS) if (locationType == LocationType.ADDRESS)
return "address"; return "any"; // strange, matches with anyObjFilter
if (locationType == LocationType.ANY) if (locationType == LocationType.ANY)
return "any"; return "any";
// TODO poi // TODO poi
throw new IllegalArgumentException(locationType.toString()); throw new IllegalArgumentException(locationType.toString());
} }
private static int locationAnyObjFilter(final LocationType locationType)
{
if (locationType == LocationType.STATION)
return 2;
if (locationType == LocationType.ADDRESS)
return 12;
if (locationType == LocationType.ANY)
return 0;
// TODO poi=32
throw new IllegalArgumentException(locationType.toString());
}
private static final Pattern P_PRE_ADDRESS = Pattern.compile("<select name=\"(name_origin|name_destination|name_via)\".*?>(.*?)</select>", private static final Pattern P_PRE_ADDRESS = Pattern.compile("<select name=\"(name_origin|name_destination|name_via)\".*?>(.*?)</select>",
Pattern.DOTALL); Pattern.DOTALL);
private static final Pattern P_ADDRESSES = Pattern.compile("<option.*?>\\s*(.*?)\\s*</option>", Pattern.DOTALL); private static final Pattern P_ADDRESSES = Pattern.compile("<option.*?>\\s*(.*?)\\s*</option>", Pattern.DOTALL);
@ -278,7 +293,6 @@ public class MvvProvider implements NetworkProvider
final LocationType toType, final String to, final Date date, final boolean dep) throws IOException final LocationType toType, final String to, final Date date, final boolean dep) throws IOException
{ {
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep); final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep);
final CharSequence page = ParserUtils.scrape(uri); final CharSequence page = ParserUtils.scrape(uri);
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page); final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);