diff --git a/enabler/src/de/schildbach/pte/NetworkId.java b/enabler/src/de/schildbach/pte/NetworkId.java index 57996e3e..af9fc781 100644 --- a/enabler/src/de/schildbach/pte/NetworkId.java +++ b/enabler/src/de/schildbach/pte/NetworkId.java @@ -28,7 +28,7 @@ public enum NetworkId { DB, BVG, VBB, NVV, BAYERN, MVV, INVG, AVV, VGN, VVM, VMV, HVV, SH, GVH, BSVAG, VBN, NASA, VVO, VMS, VGS, VRR, VRS, MVG, NPH, VRN, VVS, DING, KVV, VAGFR, NVBW, VVV, // Austria - OEBB, VAO, VOR, WIEN, LINZ, VVT, IVB, STV, + OEBB, VAO, VOR, WIEN, LINZ, VVT, IVB, STV, VMOBIL, // Switzerland SBB, BVB, VBL, ZVV, diff --git a/enabler/src/de/schildbach/pte/VmobilProvider.java b/enabler/src/de/schildbach/pte/VmobilProvider.java new file mode 100644 index 00000000..0aad290b --- /dev/null +++ b/enabler/src/de/schildbach/pte/VmobilProvider.java @@ -0,0 +1,126 @@ +/* + * Copyright 2015 the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.schildbach.pte; + +import java.io.IOException; +import java.util.Date; +import java.util.EnumSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.annotation.Nullable; + +import com.google.common.base.Charsets; + +import de.schildbach.pte.dto.Location; +import de.schildbach.pte.dto.LocationType; +import de.schildbach.pte.dto.NearbyLocationsResult; +import de.schildbach.pte.dto.Product; +import de.schildbach.pte.dto.QueryDeparturesResult; +import de.schildbach.pte.dto.QueryTripsContext; +import de.schildbach.pte.dto.QueryTripsResult; +import de.schildbach.pte.dto.SuggestLocationsResult; + +/** + * @author Andreas Schildbach + */ +public class VmobilProvider extends AbstractHafasProvider { + private static final String API_BASE = "http://fahrplan.vmobil.at/bin/"; + private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.SUBURBAN_TRAIN, Product.SUBWAY, + null, Product.TRAM, Product.REGIONAL_TRAIN, Product.BUS, Product.BUS, Product.TRAM, Product.FERRY, + Product.ON_DEMAND, Product.BUS, Product.REGIONAL_TRAIN, null, null, null }; + + public VmobilProvider(final String jsonApiAuthorization) { + super(NetworkId.VMOBIL, API_BASE, "dn", PRODUCTS_MAP); + + setJsonApiVersion("1.11"); + setJsonApiClient("{\"id\":\"VAO\",\"l\":\"vs_vvv\",\"type\":\"AND\"}"); + setJsonApiAuthorization(jsonApiAuthorization); + setJsonNearbyLocationsEncoding(Charsets.UTF_8); + } + + @Override + public Set defaultProducts() { + return Product.ALL; + } + + private static final Pattern P_SPLIT_NAME_ONE_COMMA = Pattern.compile("([^,]*), ([^,]{3,64})"); + + @Override + protected String[] splitStationName(final String name) { + final Matcher m = P_SPLIT_NAME_ONE_COMMA.matcher(name); + if (m.matches()) + return new String[] { m.group(2), m.group(1) }; + + return super.splitStationName(name); + } + + @Override + protected String[] splitPOI(final String poi) { + final Matcher m = P_SPLIT_NAME_ONE_COMMA.matcher(poi); + if (m.matches()) + return new String[] { m.group(2), m.group(1) }; + + return super.splitPOI(poi); + } + + @Override + protected String[] splitAddress(final String address) { + final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address); + if (m.matches()) + return new String[] { m.group(1), m.group(2) }; + + return super.splitAddress(address); + } + + @Override + public NearbyLocationsResult queryNearbyLocations(final EnumSet types, final Location location, + final int maxDistance, final int maxLocations) throws IOException { + if (location.hasLocation()) + return jsonLocGeoPos(types, location.lat, location.lon); + else + throw new IllegalArgumentException("cannot handle: " + location); + } + + @Override + public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time, + final int maxDepartures, final boolean equivs) throws IOException { + return jsonStationBoard(stationId, time, maxDepartures, equivs); + } + + @Override + public SuggestLocationsResult suggestLocations(final CharSequence constraint) throws IOException { + return jsonLocMatch(constraint); + } + + @Override + public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to, + final Date date, final boolean dep, final @Nullable Set products, + final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed, + final @Nullable Accessibility accessibility, final @Nullable Set