query first page of connection results only once

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@52 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-08-08 12:14:04 +00:00
parent 3a9ea3f93f
commit 515dbf7b13
9 changed files with 132 additions and 118 deletions

View file

@ -174,24 +174,24 @@ public class MvvProvider implements NetworkProvider
private static final Pattern P_CHECK_CONNECTIONS_ERROR = Pattern.compile("(?:(xxxzudichtxxx)|(konnte keine Verbindung gefunden werden))",
Pattern.CASE_INSENSITIVE);
public CheckConnectionsQueryResult checkConnectionsQuery(final String from, final String via, final String to, final Date date, final boolean dep)
public QueryConnectionsResult queryConnections(final String from, final String via, final String to, final Date date, final boolean dep)
throws IOException
{
final String queryUri = connectionsQueryUri(from, via, to, date, dep);
CharSequence page = ParserUtils.scrape(queryUri);
final String uri = connectionsQueryUri(from, via, to, date, dep);
CharSequence page = ParserUtils.scrape(uri);
while (page.length() == 0)
{
System.out.println("Got empty page, retrying...");
page = ParserUtils.scrape(queryUri);
page = ParserUtils.scrape(uri);
}
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
if (mError.find())
{
if (mError.group(1) != null)
return CheckConnectionsQueryResult.TOO_CLOSE;
return QueryConnectionsResult.TOO_CLOSE;
if (mError.group(2) != null)
return CheckConnectionsQueryResult.NO_CONNECTIONS;
return QueryConnectionsResult.NO_CONNECTIONS;
}
List<String> fromAddresses = null;
@ -224,9 +224,21 @@ public class MvvProvider implements NetworkProvider
}
if (fromAddresses != null || viaAddresses != null || toAddresses != null)
return new CheckConnectionsQueryResult(CheckConnectionsQueryResult.Status.AMBIGUOUS, queryUri, fromAddresses, viaAddresses, toAddresses);
return new QueryConnectionsResult(QueryConnectionsResult.Status.AMBIGUOUS, fromAddresses, viaAddresses, toAddresses);
else
return new CheckConnectionsQueryResult(CheckConnectionsQueryResult.Status.OK, queryUri, null, null, null);
return queryConnections(uri, page);
}
public QueryConnectionsResult queryMoreConnections(final String uri) throws IOException
{
CharSequence page = ParserUtils.scrape(uri);
while (page.length() == 0)
{
System.out.println("Got empty page, retrying...");
page = ParserUtils.scrape(uri);
}
return queryConnections(uri, page);
}
private static final Pattern P_CONNECTIONS_HEAD = Pattern.compile(".*<b>Von:[\\xa0\\s]+</b>(.+?)<br />[\\xa0\\s]+"
@ -244,15 +256,8 @@ public class MvvProvider implements NetworkProvider
+ "|" + "Fußweg.*?Dauer:[\\xa0\\s]+(\\d+):(\\d+)" //
+ ").*?", Pattern.DOTALL);
public QueryConnectionsResult queryConnections(final String uri) throws IOException
private QueryConnectionsResult queryConnections(final String uri, final CharSequence page) throws IOException
{
CharSequence page = ParserUtils.scrape(uri);
while (page.length() == 0)
{
System.out.println("Got empty page, retrying...");
page = ParserUtils.scrape(uri);
}
final Matcher mHead = P_CONNECTIONS_HEAD.matcher(page);
if (mHead.matches())
{
@ -318,7 +323,7 @@ public class MvvProvider implements NetworkProvider
}
}
return new QueryConnectionsResult(from, to, currentDate, linkEarlier, linkLater, connections);
return new QueryConnectionsResult(uri, from, to, currentDate, linkEarlier, linkLater, connections);
}
else
{