mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 05:58:46 +00:00
autocomplete whereever possible
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@599 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
7223f80dc0
commit
2087a04b3d
18 changed files with 76 additions and 43 deletions
|
@ -144,7 +144,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
|||
throw new IllegalStateException("cannot handle: " + type);
|
||||
}
|
||||
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
public List<Location> xmlLocValReq(final CharSequence constraint) throws IOException
|
||||
{
|
||||
final String request = "<LocValReq id=\"req\" maxNr=\"20\"><ReqLoc match=\"" + constraint + "\" type=\"ALLTYPE\"/></LocValReq>";
|
||||
|
||||
|
|
|
@ -66,7 +66,6 @@ public final class BahnProvider extends AbstractHafasProvider
|
|||
private static final String AUTOCOMPLETE_URI = API_BASE + "ajax-getstop.exe/dn?getstop=1&REQ0JourneyStopsS0A=255&S=%s?&js=true&";
|
||||
private static final String ENCODING = "ISO-8859-1";
|
||||
|
||||
@Override
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
final String uri = String.format(AUTOCOMPLETE_URI, ParserUtils.urlEncode(constraint.toString(), ENCODING));
|
||||
|
|
|
@ -64,7 +64,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
|||
|
||||
public BvgProvider(final String additionalQueryParameter)
|
||||
{
|
||||
super(null, null);
|
||||
super(API_BASE + "query.bin/dn", null);
|
||||
|
||||
this.additionalQueryParameter = additionalQueryParameter;
|
||||
}
|
||||
|
@ -83,35 +83,9 @@ public final class BvgProvider extends AbstractHafasProvider
|
|||
return true;
|
||||
}
|
||||
|
||||
private static final Pattern P_SINGLE_NAME = Pattern.compile(".*?Haltestelleninfo.*?<strong>(.*?)</strong>.*?input=(\\d+)&.*?", Pattern.DOTALL);
|
||||
private static final Pattern P_MULTI_NAME = Pattern.compile("<a href=\\\"/Fahrinfo/bin/stboard\\.bin/dox.*?input=(\\d+)&.*?\">\\s*(.*?)\\s*</a>",
|
||||
Pattern.DOTALL);
|
||||
|
||||
@Override
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
final StringBuilder uri = new StringBuilder(API_BASE).append("stboard.bin/dox/dox");
|
||||
uri.append("?input=").append(ParserUtils.urlEncode(constraint.toString()));
|
||||
if (additionalQueryParameter != null)
|
||||
uri.append('&').append(additionalQueryParameter);
|
||||
|
||||
final CharSequence page = ParserUtils.scrape(uri.toString());
|
||||
|
||||
final List<Location> results = new ArrayList<Location>();
|
||||
|
||||
final Matcher mSingle = P_SINGLE_NAME.matcher(page);
|
||||
if (mSingle.matches())
|
||||
{
|
||||
results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), null, 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)), null, ParserUtils.resolveEntities(mMulti.group(2))));
|
||||
}
|
||||
|
||||
return results;
|
||||
return xmlMLcReq(constraint);
|
||||
}
|
||||
|
||||
private final String NEARBY_URI = API_BASE + "stboard.bin/dn?distance=50&near&input=%s";
|
||||
|
|
|
@ -52,13 +52,11 @@ public class DsbProvider extends AbstractHafasProvider
|
|||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private static final String AUTOCOMPLETE_URI = API_BASE + "ajax-getstop.exe/dn?getstop=1&REQ0JourneyStopsS0A=255&S=%s?&js=true&";
|
||||
private static final String ENCODING = "ISO-8859-1";
|
||||
|
||||
@Override
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
final String uri = String.format(AUTOCOMPLETE_URI, ParserUtils.urlEncode(constraint.toString(), ENCODING));
|
||||
|
|
|
@ -68,6 +68,11 @@ public class InvgProvider extends AbstractHafasProvider
|
|||
|
||||
}
|
||||
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
return xmlMLcReq(constraint);
|
||||
}
|
||||
|
||||
private static final String[] PLACES = { "Ingolstadt", "München" };
|
||||
|
||||
@Override
|
||||
|
|
|
@ -54,7 +54,6 @@ public class LuProvider extends AbstractHafasProvider
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
return xmlMLcReq(constraint);
|
||||
|
|
|
@ -50,7 +50,7 @@ public class NasaProvider extends AbstractHafasProvider
|
|||
|
||||
public NasaProvider()
|
||||
{
|
||||
super(null, null);
|
||||
super(API_BASE + "query.exe/dn", null);
|
||||
}
|
||||
|
||||
public NetworkId id()
|
||||
|
@ -67,10 +67,9 @@ public class NasaProvider extends AbstractHafasProvider
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Location> autocompleteStations(CharSequence constraint) throws IOException
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
return xmlMLcReq(constraint);
|
||||
}
|
||||
|
||||
private final String NEARBY_URI = API_BASE
|
||||
|
|
|
@ -63,6 +63,11 @@ public class NsProvider extends AbstractHafasProvider
|
|||
return false;
|
||||
}
|
||||
|
||||
public List<Location> autocompleteStations(CharSequence constraint) throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private final String NEARBY_URI = "http://hari.b-rail.be/HAFAS/bin/stboard.exe/en?input=%s&distance=50&near=Anzeigen";
|
||||
|
||||
@Override
|
||||
|
|
|
@ -77,7 +77,6 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
+ "ajax-getstop.exe/dny?start=1&tpl=suggest2json&REQ0JourneyStopsS0A=255&REQ0JourneyStopsB=12&S=%s?&js=true&";
|
||||
private static final String ENCODING = "ISO-8859-1";
|
||||
|
||||
@Override
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
final String uri = String.format(AUTOCOMPLETE_URI, ParserUtils.urlEncode(constraint.toString(), ENCODING));
|
||||
|
|
|
@ -89,7 +89,6 @@ public class RmvProvider extends AbstractHafasProvider
|
|||
private static final Pattern P_MULTI_NAME = Pattern.compile("<a href=\"/auskunft/bin/jp/stboard.exe/dox.*?input=(\\d+)&.*?\">\\s*(.*?)\\s*</a>",
|
||||
Pattern.DOTALL);
|
||||
|
||||
@Override
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
final CharSequence page = ParserUtils.scrape(NAME_URL + ParserUtils.urlEncode(constraint.toString()));
|
||||
|
|
|
@ -65,6 +65,11 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
return false;
|
||||
}
|
||||
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
return xmlMLcReq(constraint);
|
||||
}
|
||||
|
||||
private final static String NEARBY_URI = API_BASE + "bhftafel.exe/dn?input=%s&distance=50&near=Anzeigen";
|
||||
|
||||
@Override
|
||||
|
|
|
@ -75,7 +75,6 @@ public class SeptaProvider extends AbstractHafasProvider
|
|||
+ "ajax-getstop.exe/dny?start=1&tpl=suggest2json&REQ0JourneyStopsS0A=255&REQ0JourneyStopsB=12&S=%s?&js=true&";
|
||||
private static final String ENCODING = "ISO-8859-1";
|
||||
|
||||
@Override
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
final String uri = String.format(AUTOCOMPLETE_URI, ParserUtils.urlEncode(constraint.toString(), ENCODING));
|
||||
|
|
|
@ -68,7 +68,6 @@ public class SncbProvider extends AbstractHafasProvider
|
|||
+ "ajax-getstop.exe/dny?start=1&tpl=suggest2json&REQ0JourneyStopsS0A=255&REQ0JourneyStopsB=12&S=%s?&js=true&";
|
||||
private static final String ENCODING = "ISO-8859-1";
|
||||
|
||||
@Override
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
final String uri = String.format(AUTOCOMPLETE_URI, ParserUtils.urlEncode(constraint.toString(), ENCODING));
|
||||
|
|
|
@ -70,7 +70,6 @@ public class VgsProvider extends AbstractHafasProvider
|
|||
+ "ajax-getstop.exe/eny?start=1&tpl=suggest2json&REQ0JourneyStopsS0A=1&getstop=1&noSession=yes&REQ0JourneyStopsB=12&REQ0JourneyStopsS0G=%s?&js=true&";
|
||||
private static final String ENCODING = "ISO-8859-1";
|
||||
|
||||
@Override
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
final String uri = String.format(AUTOCOMPLETE_URI, ParserUtils.urlEncode(constraint.toString(), ENCODING));
|
||||
|
|
|
@ -54,7 +54,6 @@ public class ZvvProvider extends AbstractHafasProvider
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||
{
|
||||
return xmlMLcReq(constraint);
|
||||
|
|
|
@ -17,9 +17,12 @@
|
|||
|
||||
package de.schildbach.pte.live;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.schildbach.pte.InvgProvider;
|
||||
import de.schildbach.pte.dto.Location;
|
||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||
|
||||
|
@ -30,6 +33,22 @@ public class InvgProviderLiveTest
|
|||
{
|
||||
private final InvgProvider provider = new InvgProvider();
|
||||
|
||||
@Test
|
||||
public void autocomplete() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Flughafen");
|
||||
|
||||
list(autocompletes);
|
||||
}
|
||||
|
||||
private void list(final List<Location> autocompletes)
|
||||
{
|
||||
System.out.print(autocompletes.size() + " ");
|
||||
for (final Location autocomplete : autocompletes)
|
||||
System.out.print(autocomplete.toDebugString() + " ");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyStation() throws Exception
|
||||
{
|
||||
|
|
|
@ -17,9 +17,12 @@
|
|||
|
||||
package de.schildbach.pte.live;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.schildbach.pte.NasaProvider;
|
||||
import de.schildbach.pte.dto.Location;
|
||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||
|
||||
|
@ -30,6 +33,22 @@ public class NasaProviderLiveTest
|
|||
{
|
||||
private final NasaProvider provider = new NasaProvider();
|
||||
|
||||
@Test
|
||||
public void autocomplete() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Flughafen");
|
||||
|
||||
list(autocompletes);
|
||||
}
|
||||
|
||||
private void list(final List<Location> autocompletes)
|
||||
{
|
||||
System.out.print(autocompletes.size() + " ");
|
||||
for (final Location autocomplete : autocompletes)
|
||||
System.out.print(autocomplete.toDebugString() + " ");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyStation() throws Exception
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package de.schildbach.pte.live;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -38,6 +39,22 @@ public class RmvProviderLiveTest
|
|||
private final RmvProvider provider = new RmvProvider();
|
||||
protected static final String ALL_PRODUCTS = "IRSUTBFC";
|
||||
|
||||
@Test
|
||||
public void autocomplete() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Flughafen");
|
||||
|
||||
list(autocompletes);
|
||||
}
|
||||
|
||||
private void list(final List<Location> autocompletes)
|
||||
{
|
||||
System.out.print(autocompletes.size() + " ");
|
||||
for (final Location autocomplete : autocompletes)
|
||||
System.out.print(autocomplete.toDebugString() + " ");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyStation() throws Exception
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue