diff --git a/src/de/schildbach/pte/MvvProvider.java b/src/de/schildbach/pte/MvvProvider.java
index fb2e0b3d..2934c6e5 100644
--- a/src/de/schildbach/pte/MvvProvider.java
+++ b/src/de/schildbach/pte/MvvProvider.java
@@ -468,8 +468,8 @@ public class MvvProvider implements NetworkProvider
}
}
- private static final Pattern P_CONNECTION_DETAILS_HEAD = Pattern.compile(".*Detailansicht.*?" //
- + "Datum:[\\xa0\\s]+\\w{2}\\.,\\s(\\d+)\\.\\s(\\w{3,4})\\.[\\xa0\\s]+(\\d{4}).*", Pattern.DOTALL);
+ private static final Pattern P_CONNECTION_DETAILS_HEAD = Pattern.compile(".*?Detailansicht.*?" //
+ + "Datum:[\\xa0\\s]+\\w{2}\\.,\\s(\\d+)\\.\\s(\\w{3,4})\\.[\\xa0\\s]+(\\d{4}).*?", Pattern.DOTALL);
private static final Pattern P_CONNECTION_DETAILS_COARSE = Pattern.compile("" //
+ "
\r\\x0a(.+?)
.*?" //
+ "\r\\x0a(.+?)
.*?" //
@@ -477,15 +477,16 @@ public class MvvProvider implements NetworkProvider
static final Pattern P_CONNECTION_DETAILS_FINE = Pattern.compile("(?:" //
+ "ab (\\d{1,2}:\\d{2})\\s(.*?)\\s*<.*?" // departureTime, departure
+ "(?: .*?)?" // product
- + " | \\s*(.*?)\\s* Richtung\\s*(.*?)\\s* | .*?" //
- + "an (\\d{1,2}:\\d{2})\\s(.*?)\\s*<" //
+ + " | \\s*(.*?)\\s* Richtung\\s*(.*?)\\s* | .*?" // line, destination
+ + "an (\\d{1,2}:\\d{2})\\s(.*?)\\s*<" // arrivalTime, arrival
+ "|" //
+ " | ab (.*?)\\s*<.*?" // departure
- + "Fußweg[\\xa0\\s]+\\(ca\\.[\\xa0\\s]+(\\d+)[\\xa0\\s]+Minute.*?" //
- + " | an (.*?)\\s*<" //
+ + "Fußweg[\\xa0\\s]+\\(ca\\.[\\xa0\\s]+(\\d+)[\\xa0\\s]+Minute.*?" // min
+ + " | an (.*?)\\s*<" // arrival
+ + "|" //
+ + ".*? " //
+ ").*?", Pattern.DOTALL);
private static final Pattern P_CONNECTION_DETAILS_ERRORS = Pattern.compile("(session has expired)", Pattern.CASE_INSENSITIVE);
- private static final String SITZENBLEIBER = "Sitzenbleiber";
public GetConnectionDetailsResult getConnectionDetails(final String uri) throws IOException
{
@@ -513,70 +514,66 @@ public class MvvProvider implements NetworkProvider
throw new IllegalArgumentException("missed row? last:" + zebra);
else
oldZebra = zebra;
-
+
final String set = mDetCoarse.group(2) + mDetCoarse.group(3) + mDetCoarse.group(4);
- if (!set.contains(SITZENBLEIBER))
+ final Matcher mDetFine = P_CONNECTION_DETAILS_FINE.matcher(set);
+ if (mDetFine.matches())
{
- final Matcher mDetFine = P_CONNECTION_DETAILS_FINE.matcher(set);
- if (mDetFine.matches())
+ if (mDetFine.group(1) != null)
{
- if (mDetFine.group(8) == null)
+ final Date departureTime = upTime(lastTime, ParserUtils.joinDateTime(currentDate, ParserUtils.parseTime(mDetFine.group(1))));
+
+ final String departure = ParserUtils.resolveEntities(mDetFine.group(2));
+ if (departure != null && firstDeparture == null)
+ firstDeparture = departure;
+
+ final String product = ParserUtils.resolveEntities(mDetFine.group(3));
+
+ final String line = ParserUtils.resolveEntities(mDetFine.group(4));
+
+ final String destination = ParserUtils.resolveEntities(mDetFine.group(5));
+
+ final Date arrivalTime = upTime(lastTime, ParserUtils.joinDateTime(currentDate, ParserUtils.parseTime(mDetFine.group(6))));
+
+ final String arrival = ParserUtils.resolveEntities(mDetFine.group(7));
+
+ final String normalizedLine = normalizeLine(product, line);
+
+ parts.add(new Connection.Trip(normalizedLine, LINES.get(normalizedLine), destination, departureTime, null, 0, departure,
+ arrivalTime, null, 0, arrival));
+
+ if (firstDepartureTime == null)
+ firstDepartureTime = departureTime;
+
+ lastArrival = arrival;
+ lastArrivalTime = arrivalTime;
+ }
+ else if (mDetFine.group(8) != null)
+ {
+ final String departure = ParserUtils.resolveEntities(mDetFine.group(8));
+ if (departure != null && firstDeparture == null)
+ firstDeparture = departure;
+
+ final String min = mDetFine.group(9);
+
+ final String arrival = ParserUtils.resolveEntities(mDetFine.group(10));
+
+ if (parts.size() > 0 && parts.get(parts.size() - 1) instanceof Connection.Footway)
{
- final Date departureTime = upTime(lastTime, ParserUtils.joinDateTime(currentDate, ParserUtils
- .parseTime(mDetFine.group(1))));
-
- final String departure = ParserUtils.resolveEntities(mDetFine.group(2));
- if (departure != null && firstDeparture == null)
- firstDeparture = departure;
-
- final String product = ParserUtils.resolveEntities(mDetFine.group(3));
-
- final String line = ParserUtils.resolveEntities(mDetFine.group(4));
-
- final String destination = ParserUtils.resolveEntities(mDetFine.group(5));
-
- final Date arrivalTime = upTime(lastTime, ParserUtils.joinDateTime(currentDate, ParserUtils.parseTime(mDetFine.group(6))));
-
- final String arrival = ParserUtils.resolveEntities(mDetFine.group(7));
-
- final String normalizedLine = normalizeLine(product, line);
-
- parts.add(new Connection.Trip(normalizedLine, LINES.get(normalizedLine), destination, departureTime, null, 0, departure,
- arrivalTime, null, 0, arrival));
-
- if (firstDepartureTime == null)
- firstDepartureTime = departureTime;
-
- lastArrival = arrival;
- lastArrivalTime = arrivalTime;
+ final Connection.Footway lastFootway = (Connection.Footway) parts.remove(parts.size() - 1);
+ parts.add(new Connection.Footway(lastFootway.min + Integer.parseInt(min), 0, lastFootway.departure, 0, arrival));
}
else
{
- final String departure = ParserUtils.resolveEntities(mDetFine.group(8));
- if (departure != null && firstDeparture == null)
- firstDeparture = departure;
-
- final String min = mDetFine.group(9);
-
- final String arrival = ParserUtils.resolveEntities(mDetFine.group(10));
-
- if (parts.size() > 0 && parts.get(parts.size() - 1) instanceof Connection.Footway)
- {
- final Connection.Footway lastFootway = (Connection.Footway) parts.remove(parts.size() - 1);
- parts.add(new Connection.Footway(lastFootway.min + Integer.parseInt(min), 0, lastFootway.departure, 0, arrival));
- }
- else
- {
- parts.add(new Connection.Footway(Integer.parseInt(min), 0, departure, 0, arrival));
- }
-
- lastArrival = arrival;
+ parts.add(new Connection.Footway(Integer.parseInt(min), 0, departure, 0, arrival));
}
+
+ lastArrival = arrival;
}
- else
- {
- throw new IllegalArgumentException("cannot parse '" + set + "' on " + uri);
- }
+ }
+ else
+ {
+ throw new IllegalArgumentException("cannot parse '" + set + "' on " + uri);
}
}
diff --git a/test/de/schildbach/pte/MvvProviderTest.java b/test/de/schildbach/pte/MvvProviderTest.java
index 51e3f768..96c4c158 100644
--- a/test/de/schildbach/pte/MvvProviderTest.java
+++ b/test/de/schildbach/pte/MvvProviderTest.java
@@ -17,13 +17,12 @@
package de.schildbach.pte;
-import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import java.util.regex.Matcher;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -71,8 +70,7 @@ public class MvvProviderTest
}
@Test
- @Ignore("deactivated because there is no time")
- public void tripWithoutTime()
+ public void tripSitzenbleiber()
{
final Matcher m = assertFineConnectionDetails("" //
+ " | ab Neufahrn \n" //
@@ -87,8 +85,8 @@ public class MvvProviderTest
+ " | an Neufahrn \n" //
+ " | \n");
- assertNotNull(m.group(2)); // departure
- assertNotNull(m.group(3)); // product
+ assertNull(m.group(1));
+ assertNull(m.group(8));
}
@Test