List of usage examples for java.util Calendar clear
public final void clear()
Calendar
undefined. From source file:de.csdev.ebus.command.datatypes.ext.EBusTypeDate.java
@Override public byte[] encodeInt(Object data) throws EBusTypeException { IEBusType<BigDecimal> bcdType = types.getType(EBusTypeBCD.TYPE_BCD); IEBusType<BigDecimal> wordType = types.getType(EBusTypeWord.TYPE_WORD); IEBusType<BigDecimal> charType = types.getType(EBusTypeChar.TYPE_CHAR); Calendar calendar = null; byte[] result = new byte[this.getTypeLength()]; if (data instanceof EBusDateTime) { calendar = ((EBusDateTime) data).getCalendar(); } else if (data instanceof Calendar) { calendar = (Calendar) data; }// w w w . j a v a 2s . com // set date to midnight calendar = (Calendar) calendar.clone(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); if (calendar != null) { if (StringUtils.equals(variant, DEFAULT)) { int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); dayOfWeek = dayOfWeek == 1 ? 7 : dayOfWeek - 1; result = new byte[] { bcdType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0], bcdType.encode(calendar.get(Calendar.MONTH) + 1)[0], bcdType.encode(dayOfWeek)[0], bcdType.encode(calendar.get(Calendar.YEAR) % 100)[0] }; } else if (StringUtils.equals(variant, SHORT)) { result = new byte[] { bcdType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0], bcdType.encode(calendar.get(Calendar.MONTH) + 1)[0], bcdType.encode(calendar.get(Calendar.YEAR) % 100)[0] }; } else if (StringUtils.equals(variant, HEX)) { int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); dayOfWeek = dayOfWeek == 1 ? 7 : dayOfWeek - 1; result = new byte[] { charType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0], charType.encode(calendar.get(Calendar.MONTH) + 1)[0], charType.encode(dayOfWeek)[0], charType.encode(calendar.get(Calendar.YEAR) % 100)[0] }; } else if (StringUtils.equals(variant, HEX_SHORT)) { result = new byte[] { charType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0], charType.encode(calendar.get(Calendar.MONTH) + 1)[0], charType.encode(calendar.get(Calendar.YEAR) % 100)[0] }; } else if (StringUtils.equals(variant, DAYS)) { long millis = calendar.getTimeInMillis(); calendar.clear(); calendar.set(1900, 0, 1, 0, 0); long millis1900 = calendar.getTimeInMillis(); BigDecimal days = new BigDecimal(millis - millis1900); days = days.divide(BigDecimal.valueOf(86400000), 0, RoundingMode.HALF_UP); result = wordType.encode(days); } } return result; }
From source file:de.schildbach.pte.AbstractHafasLegacyProvider.java
private long date(final LittleEndianDataInputStream is) throws IOException { final int days = is.readShortReverse(); final Calendar date = new GregorianCalendar(timeZone); date.clear(); date.set(Calendar.YEAR, 1980); date.set(Calendar.DAY_OF_YEAR, days); return date.getTimeInMillis(); }
From source file:com.square.core.service.implementations.PersonneServiceImplementation.java
/** * Rcupre que le jour du Calendar./*ww w . ja v a2s . com*/ * @param date la date */ private void nettoyerDate(Calendar date) { if (date != null) { final int jour = date.get(Calendar.DATE); final int mois = date.get(Calendar.MONTH); final int annee = date.get(Calendar.YEAR); date.clear(); date.set(annee, mois, jour); } }
From source file:de.schildbach.pte.AbstractHafasProvider.java
protected final QueryDeparturesResult xmlStationBoard(final String uri, final String stationId) throws IOException { final String normalizedStationId = normalizeStationId(stationId); StringReplaceReader reader = null;/* w w w. j ava 2 s . com*/ try { // work around unparsable XML reader = new StringReplaceReader( new InputStreamReader(httpClient.getInputStream(uri), Charsets.ISO_8859_1), " & ", " & "); reader.replace("<b>", " "); reader.replace("</b>", " "); reader.replace("<u>", " "); reader.replace("</u>", " "); reader.replace("<br />", " "); reader.replace(" ->", " →"); // right arrow reader.replace(" <-", " ←"); // left arrow reader.replace(" <> ", " ↔ "); // left-right arrow addCustomReplaces(reader); final XmlPullParserFactory factory = XmlPullParserFactory .newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); final XmlPullParser pp = factory.newPullParser(); pp.setInput(reader); pp.nextTag(); final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT); final QueryDeparturesResult result = new QueryDeparturesResult(header); if (XmlPullUtil.test(pp, "Err")) { final String code = XmlPullUtil.attr(pp, "code"); final String text = XmlPullUtil.attr(pp, "text"); if (code.equals("H730")) // Your input is not valid return new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION); if (code.equals("H890")) { result.stationDepartures .add(new StationDepartures(new Location(LocationType.STATION, normalizedStationId), Collections.<Departure>emptyList(), null)); return result; } throw new IllegalArgumentException("unknown error " + code + ", " + text); } String[] stationPlaceAndName = null; if (stationBoardHasStationTable) XmlPullUtil.enter(pp, "StationTable"); else checkState(!XmlPullUtil.test(pp, "StationTable")); if (stationBoardHasLocation) { XmlPullUtil.require(pp, "St"); final String evaId = XmlPullUtil.attr(pp, "evaId"); if (evaId != null) { if (!evaId.equals(normalizedStationId)) throw new IllegalStateException("stationId: " + normalizedStationId + ", evaId: " + evaId); final String name = XmlPullUtil.attr(pp, "name"); if (name != null) stationPlaceAndName = splitStationName(name.trim()); } XmlPullUtil.requireSkip(pp, "St"); } else { checkState(!XmlPullUtil.test(pp, "St")); } while (XmlPullUtil.test(pp, "Journey")) { final String fpTime = XmlPullUtil.attr(pp, "fpTime"); final String fpDate = XmlPullUtil.attr(pp, "fpDate"); final String delay = XmlPullUtil.attr(pp, "delay"); final String eDelay = XmlPullUtil.optAttr(pp, "e_delay", null); final String platform = XmlPullUtil.optAttr(pp, "platform", null); // TODO newpl final String targetLoc = XmlPullUtil.optAttr(pp, "targetLoc", null); // TODO hafasname final String dirnr = XmlPullUtil.optAttr(pp, "dirnr", null); final String prod = XmlPullUtil.attr(pp, "prod"); final String classStr = XmlPullUtil.optAttr(pp, "class", null); final String dir = XmlPullUtil.optAttr(pp, "dir", null); final String capacityStr = XmlPullUtil.optAttr(pp, "capacity", null); final String depStation = XmlPullUtil.optAttr(pp, "depStation", null); final String delayReason = XmlPullUtil.optAttr(pp, "delayReason", null); // TODO is_reachable // TODO disableTrainInfo if (!"cancel".equals(eDelay)) { final Calendar plannedTime = new GregorianCalendar(timeZone); plannedTime.clear(); ParserUtils.parseEuropeanTime(plannedTime, fpTime); if (fpDate.length() == 8) ParserUtils.parseGermanDate(plannedTime, fpDate); else if (fpDate.length() == 10) ParserUtils.parseIsoDate(plannedTime, fpDate); else throw new IllegalStateException("cannot parse: '" + fpDate + "'"); final Calendar predictedTime; if (eDelay != null) { predictedTime = new GregorianCalendar(timeZone); predictedTime.setTimeInMillis(plannedTime.getTimeInMillis()); predictedTime.add(Calendar.MINUTE, Integer.parseInt(eDelay)); } else if (delay != null) { final Matcher m = P_XML_STATION_BOARD_DELAY.matcher(delay); if (m.matches()) { if (m.group(1) != null) { predictedTime = new GregorianCalendar(timeZone); predictedTime.setTimeInMillis(plannedTime.getTimeInMillis()); predictedTime.add(Calendar.MINUTE, Integer.parseInt(m.group(1))); } else { predictedTime = null; } } else { throw new RuntimeException("cannot parse delay: '" + delay + "'"); } } else { predictedTime = null; } final Position position = parsePosition(ParserUtils.resolveEntities(platform)); final String destinationName; if (dir != null) destinationName = dir.trim(); else if (targetLoc != null) destinationName = targetLoc.trim(); else destinationName = null; final Location destination; if (dirnr != null) { final String[] destinationPlaceAndName = splitStationName(destinationName); destination = new Location(LocationType.STATION, dirnr, destinationPlaceAndName[0], destinationPlaceAndName[1]); } else { destination = new Location(LocationType.ANY, null, null, destinationName); } final Line prodLine = parseLineAndType(prod); final Line line; if (classStr != null) { final Product product = intToProduct(Integer.parseInt(classStr)); if (product == null) throw new IllegalArgumentException(); // could check for type consistency here final Set<Attr> attrs = prodLine.attrs; if (attrs != null) line = newLine(product, prodLine.label, null, attrs.toArray(new Line.Attr[0])); else line = newLine(product, prodLine.label, null); } else { line = prodLine; } final int[] capacity; if (capacityStr != null && !"0|0".equals(capacityStr)) { final String[] capacityParts = capacityStr.split("\\|"); capacity = new int[] { Integer.parseInt(capacityParts[0]), Integer.parseInt(capacityParts[1]) }; } else { capacity = null; } final String message; if (delayReason != null) { final String msg = delayReason.trim(); message = msg.length() > 0 ? msg : null; } else { message = null; } final Departure departure = new Departure(plannedTime.getTime(), predictedTime != null ? predictedTime.getTime() : null, line, position, destination, capacity, message); final Location location; if (!stationBoardCanDoEquivs || depStation == null) { location = new Location(LocationType.STATION, normalizedStationId, stationPlaceAndName != null ? stationPlaceAndName[0] : null, stationPlaceAndName != null ? stationPlaceAndName[1] : null); } else { final String[] depPlaceAndName = splitStationName(depStation); location = new Location(LocationType.STATION, null, depPlaceAndName[0], depPlaceAndName[1]); } StationDepartures stationDepartures = findStationDepartures(result.stationDepartures, location); if (stationDepartures == null) { stationDepartures = new StationDepartures(location, new ArrayList<Departure>(8), null); result.stationDepartures.add(stationDepartures); } stationDepartures.departures.add(departure); } XmlPullUtil.requireSkip(pp, "Journey"); } if (stationBoardHasStationTable) XmlPullUtil.exit(pp, "StationTable"); XmlPullUtil.requireEndDocument(pp); // sort departures for (final StationDepartures stationDepartures : result.stationDepartures) Collections.sort(stationDepartures.departures, Departure.TIME_COMPARATOR); return result; } catch (final XmlPullParserException x) { throw new RuntimeException(x); } finally { if (reader != null) reader.close(); } }
From source file:com.square.core.service.implementations.PersonneServiceImplementation.java
/** * Test si une relation est active ou pas la date du jour. * @param dateDebut date de dbut de la relation * @param dateFin date de fin de la relation * @return true si la relation est active, false sinon *//*from w w w . jav a 2s . com*/ private boolean isRelationActive(Calendar dateDebut, Calendar dateFin) { final Calendar dateDuJour = Calendar.getInstance(); final int jour = dateDuJour.get(Calendar.DATE); final int mois = dateDuJour.get(Calendar.MONTH); final int annee = dateDuJour.get(Calendar.YEAR); dateDuJour.clear(); dateDuJour.set(annee, mois, jour); return (dateDebut == null || dateDebut.before(dateDuJour) || dateDebut.equals(dateDuJour)) && (dateFin == null || dateFin.after(dateDuJour)); }
From source file:de.schildbach.pte.AbstractEfaProvider.java
private boolean processItdDateTime(final XmlPullParser pp, final Calendar calendar) throws XmlPullParserException, IOException { XmlPullUtil.enter(pp);//from ww w . j a va2 s . com calendar.clear(); final boolean success = processItdDate(pp, calendar); if (success) processItdTime(pp, calendar); XmlPullUtil.skipExit(pp); return success; }
From source file:de.schildbach.pte.AbstractHafasProvider.java
private QueryTripsResult queryTripsXml(final Context previousContext, final boolean later, final CharSequence conReq, final Location from, final @Nullable Location via, final Location to) throws IOException { final String request = wrapReqC(conReq, null); Reader reader = null;/*from w w w. j a v a 2 s .c o m*/ String firstChars = null; try { final String endpoint = extXmlEndpoint != null ? extXmlEndpoint : queryEndpoint; final InputStream is = httpClient.getInputStream(endpoint, request, null, null); firstChars = HttpClient.peekFirstChars(is); reader = new InputStreamReader(is, Charsets.ISO_8859_1); final XmlPullParserFactory factory = XmlPullParserFactory .newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); final XmlPullParser pp = factory.newPullParser(); pp.setInput(reader); XmlPullUtil.require(pp, "ResC"); final String product = XmlPullUtil.attr(pp, "prod").split(" ")[0]; final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT, product, 0, null); XmlPullUtil.enter(pp, "ResC"); if (XmlPullUtil.test(pp, "Err")) { final String code = XmlPullUtil.attr(pp, "code"); if (code.equals("I3")) // Input: date outside of the timetable period return new QueryTripsResult(header, QueryTripsResult.Status.INVALID_DATE); if (code.equals("F1")) // Spool: Error reading the spoolfile return new QueryTripsResult(header, QueryTripsResult.Status.SERVICE_DOWN); throw new IllegalStateException("error " + code + " " + XmlPullUtil.attr(pp, "text")); } XmlPullUtil.enter(pp, "ConRes"); if (XmlPullUtil.test(pp, "Err")) { final String code = XmlPullUtil.attr(pp, "code"); if (code.equals("K9260")) // Unknown departure station return new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_FROM); if (code.equals("K9280")) // Unknown intermediate station return new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_VIA); if (code.equals("K9300")) // Unknown arrival station return new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_TO); if (code.equals("K9360")) // Date outside of the timetable period return new QueryTripsResult(header, QueryTripsResult.Status.INVALID_DATE); if (code.equals("K9380")) // Dep./Arr./Intermed. or equivalent station defined more that once return new QueryTripsResult(header, QueryTripsResult.Status.TOO_CLOSE); if (code.equals("K895")) // Departure/Arrival are too near return new QueryTripsResult(header, QueryTripsResult.Status.TOO_CLOSE); if (code.equals("K9220")) // Nearby to the given address stations could not be found return new QueryTripsResult(header, QueryTripsResult.Status.UNRESOLVABLE_ADDRESS); if (code.equals("K9240")) // Internal error return new QueryTripsResult(header, QueryTripsResult.Status.SERVICE_DOWN); if (code.equals("K890")) // No connections found return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); if (code.equals("K891")) // No route found (try entering an intermediate station) return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); if (code.equals("K899")) // An error occurred return new QueryTripsResult(header, QueryTripsResult.Status.SERVICE_DOWN); if (code.equals("K1:890")) // Unsuccessful or incomplete search (direction: forward) return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); if (code.equals("K2:890")) // Unsuccessful or incomplete search (direction: backward) return new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS); throw new IllegalStateException("error " + code + " " + XmlPullUtil.attr(pp, "text")); } final String c = XmlPullUtil.optValueTag(pp, "ConResCtxt", null); final Context context; if (previousContext == null) context = new Context(c, c, 0); else if (later) context = new Context(c, previousContext.earlierContext, previousContext.sequence + 1); else context = new Context(previousContext.laterContext, c, previousContext.sequence + 1); XmlPullUtil.enter(pp, "ConnectionList"); final List<Trip> trips = new ArrayList<Trip>(); while (XmlPullUtil.test(pp, "Connection")) { final String id = context.sequence + "/" + XmlPullUtil.attr(pp, "id"); XmlPullUtil.enter(pp, "Connection"); while (pp.getName().equals("RtStateList")) XmlPullUtil.next(pp); XmlPullUtil.enter(pp, "Overview"); final Calendar currentDate = new GregorianCalendar(timeZone); currentDate.clear(); parseDate(currentDate, XmlPullUtil.valueTag(pp, "Date")); XmlPullUtil.enter(pp, "Departure"); XmlPullUtil.enter(pp, "BasicStop"); while (pp.getName().equals("StAttrList")) XmlPullUtil.next(pp); final Location departureLocation = parseLocation(pp); XmlPullUtil.enter(pp, "Dep"); XmlPullUtil.skipExit(pp, "Dep"); final int[] capacity; if (XmlPullUtil.test(pp, "StopPrognosis")) { XmlPullUtil.enter(pp, "StopPrognosis"); if (XmlPullUtil.test(pp, "Arr")) XmlPullUtil.next(pp); if (XmlPullUtil.test(pp, "Dep")) XmlPullUtil.next(pp); XmlPullUtil.enter(pp, "Status"); XmlPullUtil.skipExit(pp, "Status"); final int capacity1st = Integer.parseInt(XmlPullUtil.optValueTag(pp, "Capacity1st", "0")); final int capacity2nd = Integer.parseInt(XmlPullUtil.optValueTag(pp, "Capacity2nd", "0")); if (capacity1st > 0 || capacity2nd > 0) capacity = new int[] { capacity1st, capacity2nd }; else capacity = null; XmlPullUtil.skipExit(pp, "StopPrognosis"); } else { capacity = null; } XmlPullUtil.skipExit(pp, "BasicStop"); XmlPullUtil.skipExit(pp, "Departure"); XmlPullUtil.enter(pp, "Arrival"); XmlPullUtil.enter(pp, "BasicStop"); while (pp.getName().equals("StAttrList")) XmlPullUtil.next(pp); final Location arrivalLocation = parseLocation(pp); XmlPullUtil.skipExit(pp, "BasicStop"); XmlPullUtil.skipExit(pp, "Arrival"); final int numTransfers = Integer.parseInt(XmlPullUtil.valueTag(pp, "Transfers")); XmlPullUtil.skipExit(pp, "Overview"); final List<Trip.Leg> legs = new ArrayList<Trip.Leg>(4); XmlPullUtil.enter(pp, "ConSectionList"); final Calendar time = new GregorianCalendar(timeZone); while (XmlPullUtil.test(pp, "ConSection")) { XmlPullUtil.enter(pp, "ConSection"); // departure XmlPullUtil.enter(pp, "Departure"); XmlPullUtil.enter(pp, "BasicStop"); while (pp.getName().equals("StAttrList")) XmlPullUtil.next(pp); final Location sectionDepartureLocation = parseLocation(pp); if (XmlPullUtil.test(pp, "Arr")) { XmlPullUtil.enter(pp, "Arr"); XmlPullUtil.skipExit(pp, "Arr"); } XmlPullUtil.enter(pp, "Dep"); time.setTimeInMillis(currentDate.getTimeInMillis()); parseTime(time, XmlPullUtil.valueTag(pp, "Time")); final Date departureTime = time.getTime(); final Position departurePos = parsePlatform(pp); XmlPullUtil.skipExit(pp, "Dep"); XmlPullUtil.skipExit(pp, "BasicStop"); XmlPullUtil.skipExit(pp, "Departure"); // journey final Line line; Location destination = null; List<Stop> intermediateStops = null; final String tag = pp.getName(); if (tag.equals("Journey")) { XmlPullUtil.enter(pp, "Journey"); while (pp.getName().equals("JHandle")) XmlPullUtil.next(pp); XmlPullUtil.enter(pp, "JourneyAttributeList"); boolean wheelchairAccess = false; String name = null; String category = null; String shortCategory = null; while (XmlPullUtil.test(pp, "JourneyAttribute")) { XmlPullUtil.enter(pp, "JourneyAttribute"); XmlPullUtil.require(pp, "Attribute"); final String attrName = XmlPullUtil.attr(pp, "type"); final String code = XmlPullUtil.optAttr(pp, "code", null); XmlPullUtil.enter(pp, "Attribute"); final Map<String, String> attributeVariants = parseAttributeVariants(pp); XmlPullUtil.skipExit(pp, "Attribute"); XmlPullUtil.skipExit(pp, "JourneyAttribute"); if ("bf".equals(code)) { wheelchairAccess = true; } else if ("NAME".equals(attrName)) { name = attributeVariants.get("NORMAL"); } else if ("CATEGORY".equals(attrName)) { shortCategory = attributeVariants.get("SHORT"); category = attributeVariants.get("NORMAL"); // longCategory = attributeVariants.get("LONG"); } else if ("DIRECTION".equals(attrName)) { final String[] destinationPlaceAndName = splitStationName( attributeVariants.get("NORMAL")); destination = new Location(LocationType.ANY, null, destinationPlaceAndName[0], destinationPlaceAndName[1]); } } XmlPullUtil.skipExit(pp, "JourneyAttributeList"); if (XmlPullUtil.test(pp, "PassList")) { intermediateStops = new LinkedList<Stop>(); XmlPullUtil.enter(pp, "PassList"); while (XmlPullUtil.test(pp, "BasicStop")) { XmlPullUtil.enter(pp, "BasicStop"); while (XmlPullUtil.test(pp, "StAttrList")) XmlPullUtil.next(pp); final Location location = parseLocation(pp); if (location.id != sectionDepartureLocation.id) { Date stopArrivalTime = null; Date stopDepartureTime = null; Position stopArrivalPosition = null; Position stopDeparturePosition = null; if (XmlPullUtil.test(pp, "Arr")) { XmlPullUtil.enter(pp, "Arr"); time.setTimeInMillis(currentDate.getTimeInMillis()); parseTime(time, XmlPullUtil.valueTag(pp, "Time")); stopArrivalTime = time.getTime(); stopArrivalPosition = parsePlatform(pp); XmlPullUtil.skipExit(pp, "Arr"); } if (XmlPullUtil.test(pp, "Dep")) { XmlPullUtil.enter(pp, "Dep"); time.setTimeInMillis(currentDate.getTimeInMillis()); parseTime(time, XmlPullUtil.valueTag(pp, "Time")); stopDepartureTime = time.getTime(); stopDeparturePosition = parsePlatform(pp); XmlPullUtil.skipExit(pp, "Dep"); } intermediateStops.add(new Stop(location, stopArrivalTime, stopArrivalPosition, stopDepartureTime, stopDeparturePosition)); } XmlPullUtil.skipExit(pp, "BasicStop"); } XmlPullUtil.skipExit(pp, "PassList"); } XmlPullUtil.skipExit(pp, "Journey"); if (category == null) category = shortCategory; line = parseLine(category, name, wheelchairAccess); } else if (tag.equals("Walk") || tag.equals("Transfer") || tag.equals("GisRoute")) { XmlPullUtil.enter(pp); XmlPullUtil.enter(pp, "Duration"); XmlPullUtil.skipExit(pp, "Duration"); XmlPullUtil.skipExit(pp); line = null; } else { throw new IllegalStateException("cannot handle: " + pp.getName()); } // polyline final List<Point> path; if (XmlPullUtil.test(pp, "Polyline")) { path = new LinkedList<Point>(); XmlPullUtil.enter(pp, "Polyline"); while (XmlPullUtil.test(pp, "Point")) { final int x = XmlPullUtil.intAttr(pp, "x"); final int y = XmlPullUtil.intAttr(pp, "y"); path.add(new Point(y, x)); XmlPullUtil.next(pp); } XmlPullUtil.skipExit(pp, "Polyline"); } else { path = null; } // arrival XmlPullUtil.enter(pp, "Arrival"); XmlPullUtil.enter(pp, "BasicStop"); while (pp.getName().equals("StAttrList")) XmlPullUtil.next(pp); final Location sectionArrivalLocation = parseLocation(pp); XmlPullUtil.enter(pp, "Arr"); time.setTimeInMillis(currentDate.getTimeInMillis()); parseTime(time, XmlPullUtil.valueTag(pp, "Time")); final Date arrivalTime = time.getTime(); final Position arrivalPos = parsePlatform(pp); XmlPullUtil.skipExit(pp, "Arr"); XmlPullUtil.skipExit(pp, "BasicStop"); XmlPullUtil.skipExit(pp, "Arrival"); // remove last intermediate if (intermediateStops != null) if (!intermediateStops.isEmpty()) if (!intermediateStops.get(intermediateStops.size() - 1).location .equals(sectionArrivalLocation)) intermediateStops.remove(intermediateStops.size() - 1); XmlPullUtil.skipExit(pp, "ConSection"); if (line != null) { final Stop departure = new Stop(sectionDepartureLocation, true, departureTime, null, departurePos, null); final Stop arrival = new Stop(sectionArrivalLocation, false, arrivalTime, null, arrivalPos, null); legs.add(new Trip.Public(line, destination, departure, arrival, intermediateStops, path, null)); } else { if (legs.size() > 0 && legs.get(legs.size() - 1) instanceof Trip.Individual) { final Trip.Individual lastIndividualLeg = (Trip.Individual) legs .remove(legs.size() - 1); legs.add(new Trip.Individual(Trip.Individual.Type.WALK, lastIndividualLeg.departure, lastIndividualLeg.departureTime, sectionArrivalLocation, arrivalTime, null, 0)); } else { legs.add(new Trip.Individual(Trip.Individual.Type.WALK, sectionDepartureLocation, departureTime, sectionArrivalLocation, arrivalTime, null, 0)); } } } XmlPullUtil.skipExit(pp, "ConSectionList"); XmlPullUtil.skipExit(pp, "Connection"); trips.add(new Trip(id, departureLocation, arrivalLocation, legs, null, capacity, numTransfers)); } XmlPullUtil.skipExit(pp, "ConnectionList"); return new QueryTripsResult(header, null, from, via, to, context, trips); } catch (final XmlPullParserException x) { throw new ParserException("cannot parse xml: " + firstChars, x); } finally { if (reader != null) reader.close(); } }
From source file:de.schildbach.pte.AbstractEfaProvider.java
private void parseMobileSt(final XmlPullParser pp, final Calendar plannedDepartureTime, final Calendar predictedDepartureTime) throws XmlPullParserException, IOException { XmlPullUtil.enter(pp, "st"); plannedDepartureTime.clear(); ParserUtils.parseIsoDate(plannedDepartureTime, XmlPullUtil.valueTag(pp, "da")); ParserUtils.parseIsoTime(plannedDepartureTime, XmlPullUtil.valueTag(pp, "t")); predictedDepartureTime.clear();/*from www .j a va 2 s. co m*/ if (XmlPullUtil.test(pp, "rda")) { ParserUtils.parseIsoDate(predictedDepartureTime, XmlPullUtil.valueTag(pp, "rda")); ParserUtils.parseIsoTime(predictedDepartureTime, XmlPullUtil.valueTag(pp, "rt")); } XmlPullUtil.skipExit(pp, "st"); }
From source file:de.schildbach.pte.AbstractHafasLegacyProvider.java
protected final QueryDeparturesResult xmlStationBoard(final HttpUrl url, final String stationId) throws IOException { final String normalizedStationId = normalizeStationId(stationId); final AtomicReference<QueryDeparturesResult> result = new AtomicReference<>(); httpClient.getInputStream(new HttpClient.Callback() { @Override//from www . j a va 2 s .com public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException { StringReplaceReader reader = null; String firstChars = null; // work around unparsable XML reader = new StringReplaceReader(body.charStream(), " & ", " & "); reader.replace("<b>", " "); reader.replace("</b>", " "); reader.replace("<u>", " "); reader.replace("</u>", " "); reader.replace("<i>", " "); reader.replace("</i>", " "); reader.replace("<br />", " "); reader.replace(" ->", " →"); // right arrow reader.replace(" <-", " ←"); // left arrow reader.replace(" <> ", " ↔ "); // left-right arrow addCustomReplaces(reader); try { final XmlPullParserFactory factory = XmlPullParserFactory .newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); final XmlPullParser pp = factory.newPullParser(); pp.setInput(reader); pp.nextTag(); final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT); final QueryDeparturesResult r = new QueryDeparturesResult(header); if (XmlPullUtil.test(pp, "Err")) { final String code = XmlPullUtil.attr(pp, "code"); final String text = XmlPullUtil.attr(pp, "text"); if (code.equals("H730")) { result.set(new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION)); return; } if (code.equals("H890")) { r.stationDepartures.add( new StationDepartures(new Location(LocationType.STATION, normalizedStationId), Collections.<Departure>emptyList(), null)); result.set(r); return; } throw new IllegalArgumentException("unknown error " + code + ", " + text); } String[] stationPlaceAndName = null; if (stationBoardHasStationTable) XmlPullUtil.enter(pp, "StationTable"); else checkState(!XmlPullUtil.test(pp, "StationTable")); if (stationBoardHasLocation) { XmlPullUtil.require(pp, "St"); final String evaId = XmlPullUtil.attr(pp, "evaId"); if (evaId != null) { if (!evaId.equals(normalizedStationId)) throw new IllegalStateException( "stationId: " + normalizedStationId + ", evaId: " + evaId); final String name = XmlPullUtil.attr(pp, "name"); if (name != null) stationPlaceAndName = splitStationName(name.trim()); } XmlPullUtil.requireSkip(pp, "St"); } else { checkState(!XmlPullUtil.test(pp, "St")); } while (XmlPullUtil.test(pp, "Journey")) { final String fpTime = XmlPullUtil.attr(pp, "fpTime"); final String fpDate = XmlPullUtil.attr(pp, "fpDate"); final String delay = XmlPullUtil.attr(pp, "delay"); final String eDelay = XmlPullUtil.optAttr(pp, "e_delay", null); final String platform = XmlPullUtil.optAttr(pp, "platform", null); // TODO newpl final String targetLoc = XmlPullUtil.optAttr(pp, "targetLoc", null); // TODO hafasname final String dirnr = XmlPullUtil.optAttr(pp, "dirnr", null); final String prod = XmlPullUtil.attr(pp, "prod"); final String classStr = XmlPullUtil.optAttr(pp, "class", null); final String dir = XmlPullUtil.optAttr(pp, "dir", null); final String capacityStr = XmlPullUtil.optAttr(pp, "capacity", null); final String depStation = XmlPullUtil.optAttr(pp, "depStation", null); final String delayReason = XmlPullUtil.optAttr(pp, "delayReason", null); // TODO is_reachable // TODO disableTrainInfo // TODO lineFG/lineBG (ZVV) final String administration = normalizeLineAdministration( XmlPullUtil.optAttr(pp, "administration", null)); if (!"cancel".equals(delay) && !"cancel".equals(eDelay)) { final Calendar plannedTime = new GregorianCalendar(timeZone); plannedTime.clear(); parseXmlStationBoardDate(plannedTime, fpDate); parseXmlStationBoardTime(plannedTime, fpTime); final Calendar predictedTime; if (eDelay != null) { predictedTime = new GregorianCalendar(timeZone); predictedTime.setTimeInMillis(plannedTime.getTimeInMillis()); predictedTime.add(Calendar.MINUTE, Integer.parseInt(eDelay)); } else if (delay != null) { final Matcher m = P_XML_STATION_BOARD_DELAY.matcher(delay); if (m.matches()) { if (m.group(1) != null) { predictedTime = new GregorianCalendar(timeZone); predictedTime.setTimeInMillis(plannedTime.getTimeInMillis()); predictedTime.add(Calendar.MINUTE, Integer.parseInt(m.group(1))); } else { predictedTime = null; } } else { throw new RuntimeException("cannot parse delay: '" + delay + "'"); } } else { predictedTime = null; } final Position position = parsePosition(ParserUtils.resolveEntities(platform)); final String destinationName; if (dir != null) destinationName = dir.trim(); else if (targetLoc != null) destinationName = targetLoc.trim(); else destinationName = null; final Location destination; if (dirnr != null) { final String[] destinationPlaceAndName = splitStationName(destinationName); destination = new Location(LocationType.STATION, dirnr, destinationPlaceAndName[0], destinationPlaceAndName[1]); } else { destination = new Location(LocationType.ANY, null, null, destinationName); } final Line prodLine = parseLineAndType(prod); final Line line; if (classStr != null) { final Product product = intToProduct(Integer.parseInt(classStr)); if (product == null) throw new IllegalArgumentException(); // could check for type consistency here final Set<Attr> attrs = prodLine.attrs; if (attrs != null) line = newLine(administration, product, prodLine.label, null, attrs.toArray(new Line.Attr[0])); else line = newLine(administration, product, prodLine.label, null); } else { final Set<Attr> attrs = prodLine.attrs; if (attrs != null) line = newLine(administration, prodLine.product, prodLine.label, null, attrs.toArray(new Line.Attr[0])); else line = newLine(administration, prodLine.product, prodLine.label, null); } final int[] capacity; if (capacityStr != null && !"0|0".equals(capacityStr)) { final String[] capacityParts = capacityStr.split("\\|"); capacity = new int[] { Integer.parseInt(capacityParts[0]), Integer.parseInt(capacityParts[1]) }; } else { capacity = null; } final String message; if (delayReason != null) { final String msg = delayReason.trim(); message = msg.length() > 0 ? msg : null; } else { message = null; } final Departure departure = new Departure(plannedTime.getTime(), predictedTime != null ? predictedTime.getTime() : null, line, position, destination, capacity, message); final Location location; if (!stationBoardCanDoEquivs || depStation == null) { location = new Location(LocationType.STATION, normalizedStationId, stationPlaceAndName != null ? stationPlaceAndName[0] : null, stationPlaceAndName != null ? stationPlaceAndName[1] : null); } else { final String[] depPlaceAndName = splitStationName(depStation); location = new Location(LocationType.STATION, null, depPlaceAndName[0], depPlaceAndName[1]); } StationDepartures stationDepartures = findStationDepartures(r.stationDepartures, location); if (stationDepartures == null) { stationDepartures = new StationDepartures(location, new ArrayList<Departure>(8), null); r.stationDepartures.add(stationDepartures); } stationDepartures.departures.add(departure); } XmlPullUtil.requireSkip(pp, "Journey"); } if (stationBoardHasStationTable) XmlPullUtil.exit(pp, "StationTable"); XmlPullUtil.requireEndDocument(pp); // sort departures for (final StationDepartures stationDepartures : r.stationDepartures) Collections.sort(stationDepartures.departures, Departure.TIME_COMPARATOR); result.set(r); } catch (final XmlPullParserException x) { throw new ParserException("cannot parse xml: " + firstChars, x); } } }, url); return result.get(); }
From source file:de.schildbach.pte.AbstractHafasLegacyProvider.java
private QueryTripsResult queryTripsXml(final Context previousContext, final boolean later, final CharSequence conReq, final Location from, final @Nullable Location via, final Location to) throws IOException { final String request = wrapReqC(conReq, null); final HttpUrl endpoint = extXmlEndpoint != null ? extXmlEndpoint : queryEndpoint.newBuilder().addPathSegment(apiLanguage).build(); final AtomicReference<QueryTripsResult> result = new AtomicReference<>(); httpClient.getInputStream(new HttpClient.Callback() { @Override//from ww w.ja va 2 s.co m public void onSuccessful(final CharSequence bodyPeek, final ResponseBody body) throws IOException { try { final XmlPullParserFactory factory = XmlPullParserFactory .newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); final XmlPullParser pp = factory.newPullParser(); pp.setInput(body.charStream()); XmlPullUtil.require(pp, "ResC"); final String product = XmlPullUtil.attr(pp, "prod").split(" ")[0]; final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT, product, null, 0, null); XmlPullUtil.enter(pp, "ResC"); if (XmlPullUtil.test(pp, "Err")) { final String code = XmlPullUtil.attr(pp, "code"); if (code.equals("I3")) { result.set(new QueryTripsResult(header, QueryTripsResult.Status.INVALID_DATE)); return; } if (code.equals("F1")) { result.set(new QueryTripsResult(header, QueryTripsResult.Status.SERVICE_DOWN)); return; } throw new IllegalStateException("error " + code + " " + XmlPullUtil.attr(pp, "text")); } XmlPullUtil.enter(pp, "ConRes"); if (XmlPullUtil.test(pp, "Err")) { final String code = XmlPullUtil.attr(pp, "code"); log.debug("Hafas error: {}", code); if (code.equals("K9260")) { // Unknown departure station result.set(new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_FROM)); return; } if (code.equals("K9280")) { // Unknown intermediate station result.set(new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_VIA)); return; } if (code.equals("K9300")) { // Unknown arrival station result.set(new QueryTripsResult(header, QueryTripsResult.Status.UNKNOWN_TO)); return; } if (code.equals("K9360")) { // Date outside of the timetable period result.set(new QueryTripsResult(header, QueryTripsResult.Status.INVALID_DATE)); return; } if (code.equals("K9380")) { // Dep./Arr./Intermed. or equivalent station defined more than once result.set(new QueryTripsResult(header, QueryTripsResult.Status.TOO_CLOSE)); return; } if (code.equals("K895")) { // Departure/Arrival are too near result.set(new QueryTripsResult(header, QueryTripsResult.Status.TOO_CLOSE)); return; } if (code.equals("K9220")) { // Nearby to the given address stations could not be found result.set(new QueryTripsResult(header, QueryTripsResult.Status.UNRESOLVABLE_ADDRESS)); return; } if (code.equals("K9240")) { // Internal error result.set(new QueryTripsResult(header, QueryTripsResult.Status.SERVICE_DOWN)); return; } if (code.equals("K890")) { // No connections found result.set(new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS)); return; } if (code.equals("K891")) { // No route found (try entering an intermediate station) result.set(new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS)); return; } if (code.equals("K899")) { // An error occurred result.set(new QueryTripsResult(header, QueryTripsResult.Status.SERVICE_DOWN)); return; } if (code.equals("K1:890")) { // Unsuccessful or incomplete search (direction: forward) result.set(new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS)); return; } if (code.equals("K2:890")) { // Unsuccessful or incomplete search (direction: backward) result.set(new QueryTripsResult(header, QueryTripsResult.Status.NO_TRIPS)); return; } throw new IllegalStateException("error " + code + " " + XmlPullUtil.attr(pp, "text")); } // H9380 Dep./Arr./Intermed. or equivalent stations defined more than once // H9360 Error in data field // H9320 The input is incorrect or incomplete // H9300 Unknown arrival station // H9280 Unknown intermediate station // H9260 Unknown departure station // H9250 Part inquiry interrupted // H9240 Unsuccessful search // H9230 An internal error occurred // H9220 Nearby to the given address stations could not be found // H900 Unsuccessful or incomplete search (timetable change) // H892 Inquiry too complex (try entering less intermediate stations) // H891 No route found (try entering an intermediate station) // H890 Unsuccessful search. // H500 Because of too many trains the connection is not complete // H460 One or more stops are passed through multiple times. // H455 Prolonged stop // H410 Display may be incomplete due to change of timetable // H390 Departure/Arrival replaced by an equivalent station // H895 Departure/Arrival are too near // H899 Unsuccessful or incomplete search (timetable change final String c = XmlPullUtil.optValueTag(pp, "ConResCtxt", null); final Context context; if (previousContext == null) context = new Context(c, c, 0); else if (later) context = new Context(c, previousContext.earlierContext, previousContext.sequence + 1); else context = new Context(previousContext.laterContext, c, previousContext.sequence + 1); XmlPullUtil.enter(pp, "ConnectionList"); final List<Trip> trips = new ArrayList<>(); while (XmlPullUtil.test(pp, "Connection")) { final String id = context.sequence + "/" + XmlPullUtil.attr(pp, "id"); XmlPullUtil.enter(pp, "Connection"); while (pp.getName().equals("RtStateList")) XmlPullUtil.next(pp); XmlPullUtil.enter(pp, "Overview"); final Calendar currentDate = new GregorianCalendar(timeZone); currentDate.clear(); parseDate(currentDate, XmlPullUtil.valueTag(pp, "Date")); XmlPullUtil.enter(pp, "Departure"); XmlPullUtil.enter(pp, "BasicStop"); while (pp.getName().equals("StAttrList")) XmlPullUtil.next(pp); final Location departureLocation = parseLocation(pp); XmlPullUtil.enter(pp, "Dep"); XmlPullUtil.skipExit(pp, "Dep"); final int[] capacity; if (XmlPullUtil.test(pp, "StopPrognosis")) { XmlPullUtil.enter(pp, "StopPrognosis"); XmlPullUtil.optSkip(pp, "Arr"); XmlPullUtil.optSkip(pp, "Dep"); XmlPullUtil.enter(pp, "Status"); XmlPullUtil.skipExit(pp, "Status"); final int capacity1st = Integer .parseInt(XmlPullUtil.optValueTag(pp, "Capacity1st", "0")); final int capacity2nd = Integer .parseInt(XmlPullUtil.optValueTag(pp, "Capacity2nd", "0")); if (capacity1st > 0 || capacity2nd > 0) capacity = new int[] { capacity1st, capacity2nd }; else capacity = null; XmlPullUtil.skipExit(pp, "StopPrognosis"); } else { capacity = null; } XmlPullUtil.skipExit(pp, "BasicStop"); XmlPullUtil.skipExit(pp, "Departure"); XmlPullUtil.enter(pp, "Arrival"); XmlPullUtil.enter(pp, "BasicStop"); while (pp.getName().equals("StAttrList")) XmlPullUtil.next(pp); final Location arrivalLocation = parseLocation(pp); XmlPullUtil.skipExit(pp, "BasicStop"); XmlPullUtil.skipExit(pp, "Arrival"); final int numTransfers = Integer.parseInt(XmlPullUtil.valueTag(pp, "Transfers")); XmlPullUtil.skipExit(pp, "Overview"); final List<Trip.Leg> legs = new ArrayList<>(4); XmlPullUtil.enter(pp, "ConSectionList"); final Calendar time = new GregorianCalendar(timeZone); while (XmlPullUtil.test(pp, "ConSection")) { XmlPullUtil.enter(pp, "ConSection"); // departure XmlPullUtil.enter(pp, "Departure"); XmlPullUtil.enter(pp, "BasicStop"); while (pp.getName().equals("StAttrList")) XmlPullUtil.next(pp); final Location sectionDepartureLocation = parseLocation(pp); XmlPullUtil.optSkip(pp, "Arr"); XmlPullUtil.enter(pp, "Dep"); time.setTimeInMillis(currentDate.getTimeInMillis()); parseTime(time, XmlPullUtil.valueTag(pp, "Time")); final Date departureTime = time.getTime(); final Position departurePos = parsePlatform(pp); XmlPullUtil.skipExit(pp, "Dep"); XmlPullUtil.skipExit(pp, "BasicStop"); XmlPullUtil.skipExit(pp, "Departure"); // journey final Line line; Location destination = null; List<Stop> intermediateStops = null; final String tag = pp.getName(); if (tag.equals("Journey")) { XmlPullUtil.enter(pp, "Journey"); while (pp.getName().equals("JHandle")) XmlPullUtil.next(pp); XmlPullUtil.enter(pp, "JourneyAttributeList"); boolean wheelchairAccess = false; String name = null; String category = null; String shortCategory = null; while (XmlPullUtil.test(pp, "JourneyAttribute")) { XmlPullUtil.enter(pp, "JourneyAttribute"); XmlPullUtil.require(pp, "Attribute"); final String attrName = XmlPullUtil.attr(pp, "type"); final String code = XmlPullUtil.optAttr(pp, "code", null); XmlPullUtil.enter(pp, "Attribute"); final Map<String, String> attributeVariants = parseAttributeVariants(pp); XmlPullUtil.skipExit(pp, "Attribute"); XmlPullUtil.skipExit(pp, "JourneyAttribute"); if ("bf".equals(code)) { wheelchairAccess = true; } else if ("NAME".equals(attrName)) { name = attributeVariants.get("NORMAL"); } else if ("CATEGORY".equals(attrName)) { shortCategory = attributeVariants.get("SHORT"); category = attributeVariants.get("NORMAL"); // longCategory = attributeVariants.get("LONG"); } else if ("DIRECTION".equals(attrName)) { final String[] destinationPlaceAndName = splitStationName( attributeVariants.get("NORMAL")); destination = new Location(LocationType.ANY, null, destinationPlaceAndName[0], destinationPlaceAndName[1]); } } XmlPullUtil.skipExit(pp, "JourneyAttributeList"); if (XmlPullUtil.test(pp, "PassList")) { intermediateStops = new LinkedList<>(); XmlPullUtil.enter(pp, "PassList"); while (XmlPullUtil.test(pp, "BasicStop")) { XmlPullUtil.enter(pp, "BasicStop"); while (XmlPullUtil.test(pp, "StAttrList")) XmlPullUtil.next(pp); final Location location = parseLocation(pp); if (location.id != sectionDepartureLocation.id) { Date stopArrivalTime = null; Date stopDepartureTime = null; Position stopArrivalPosition = null; Position stopDeparturePosition = null; if (XmlPullUtil.test(pp, "Arr")) { XmlPullUtil.enter(pp, "Arr"); time.setTimeInMillis(currentDate.getTimeInMillis()); parseTime(time, XmlPullUtil.valueTag(pp, "Time")); stopArrivalTime = time.getTime(); stopArrivalPosition = parsePlatform(pp); XmlPullUtil.skipExit(pp, "Arr"); } if (XmlPullUtil.test(pp, "Dep")) { XmlPullUtil.enter(pp, "Dep"); time.setTimeInMillis(currentDate.getTimeInMillis()); parseTime(time, XmlPullUtil.valueTag(pp, "Time")); stopDepartureTime = time.getTime(); stopDeparturePosition = parsePlatform(pp); XmlPullUtil.skipExit(pp, "Dep"); } intermediateStops.add(new Stop(location, stopArrivalTime, stopArrivalPosition, stopDepartureTime, stopDeparturePosition)); } XmlPullUtil.skipExit(pp, "BasicStop"); } XmlPullUtil.skipExit(pp, "PassList"); } XmlPullUtil.skipExit(pp, "Journey"); if (category == null) category = shortCategory; line = parseLine(category, name, wheelchairAccess); } else if (tag.equals("Walk") || tag.equals("Transfer") || tag.equals("GisRoute")) { XmlPullUtil.enter(pp); XmlPullUtil.enter(pp, "Duration"); XmlPullUtil.skipExit(pp, "Duration"); XmlPullUtil.skipExit(pp); line = null; } else { throw new IllegalStateException("cannot handle: " + pp.getName()); } // polyline final List<Point> path; if (XmlPullUtil.test(pp, "Polyline")) { path = new LinkedList<>(); XmlPullUtil.enter(pp, "Polyline"); while (XmlPullUtil.test(pp, "Point")) { final int x = XmlPullUtil.intAttr(pp, "x"); final int y = XmlPullUtil.intAttr(pp, "y"); path.add(new Point(y, x)); XmlPullUtil.next(pp); } XmlPullUtil.skipExit(pp, "Polyline"); } else { path = null; } // arrival XmlPullUtil.enter(pp, "Arrival"); XmlPullUtil.enter(pp, "BasicStop"); while (pp.getName().equals("StAttrList")) XmlPullUtil.next(pp); final Location sectionArrivalLocation = parseLocation(pp); XmlPullUtil.enter(pp, "Arr"); time.setTimeInMillis(currentDate.getTimeInMillis()); parseTime(time, XmlPullUtil.valueTag(pp, "Time")); final Date arrivalTime = time.getTime(); final Position arrivalPos = parsePlatform(pp); XmlPullUtil.skipExit(pp, "Arr"); XmlPullUtil.skipExit(pp, "BasicStop"); XmlPullUtil.skipExit(pp, "Arrival"); // remove last intermediate if (intermediateStops != null) if (!intermediateStops.isEmpty()) if (!intermediateStops.get(intermediateStops.size() - 1).location .equals(sectionArrivalLocation)) intermediateStops.remove(intermediateStops.size() - 1); XmlPullUtil.skipExit(pp, "ConSection"); if (line != null) { final Stop departure = new Stop(sectionDepartureLocation, true, departureTime, null, departurePos, null); final Stop arrival = new Stop(sectionArrivalLocation, false, arrivalTime, null, arrivalPos, null); legs.add(new Trip.Public(line, destination, departure, arrival, intermediateStops, path, null)); } else { if (legs.size() > 0 && legs.get(legs.size() - 1) instanceof Trip.Individual) { final Trip.Individual lastIndividualLeg = (Trip.Individual) legs .remove(legs.size() - 1); legs.add(new Trip.Individual(Trip.Individual.Type.WALK, lastIndividualLeg.departure, lastIndividualLeg.departureTime, sectionArrivalLocation, arrivalTime, null, 0)); } else { legs.add( new Trip.Individual(Trip.Individual.Type.WALK, sectionDepartureLocation, departureTime, sectionArrivalLocation, arrivalTime, null, 0)); } } } XmlPullUtil.skipExit(pp, "ConSectionList"); XmlPullUtil.skipExit(pp, "Connection"); trips.add(new Trip(id, departureLocation, arrivalLocation, legs, null, capacity, numTransfers)); } XmlPullUtil.skipExit(pp, "ConnectionList"); result.set(new QueryTripsResult(header, null, from, via, to, context, trips)); } catch (final XmlPullParserException x) { throw new ParserException("cannot parse xml: " + bodyPeek, x); } } }, endpoint, request, "application/xml", null); return result.get(); }