/** Gets the station with the specified name, or null if no such station exists. */ public TransportStation getStation(final String name) throws IOException { // TODO: Remove this and the method itself once we remove the deprecated stuff final String query = HafasUtil.getFullStationName(name); final List<TransportStation> result = findStations(query, 1, null); if (result.size() == 0) { return null; } if (result.get(0).getName().equals(name)) { return result.get(0); } return null; }
/** Builds the request XML. */ private XElement buildRequest(final String token, final String query, final int maxResultsCount) { final XElement root = HafasUtil.createRequestRoot(token); final XElement container = root.addChild(REQUEST_CONTAINER) .setAttribute(REQUEST_CONTAINER_ID_ATTRIBUTE, REQUEST_ID) .setAttribute( REQUEST_CONTAINER_MAX_RESULTS_ATTRIBUTE, Integer.toString(maxResultsCount)); container .addChild(REQUEST_ELEMENT) .setAttribute(REQUEST_TYPE_ATTRIBUTE, REQUEST_TYPE) .setAttribute(REQUEST_QUERY_ATTRIBUTE, query + REQUEST_QUERY_WILDCARD_SUFFIX); return root; }
/** Parses the response XML. */ private static List<TransportStation> parseResponse(final String responseXml) { final XElement responseElem = XElement.parse(responseXml); // haven't seen it in the wild, but the XSD allows it if (responseElem.child(RESPONSE_ERROR_ELEMENT) != null) { return new ArrayList<>(); } final XElement containerElem = responseElem.child(RESPONSE_CONTAINER); if (containerElem.child(RESPONSE_ERROR_ELEMENT) != null) { return new ArrayList<>(); } final List<TransportStation> result = new ArrayList<>(); for (XElement stationElem : containerElem.children(RESPONSE_STATION_ELEMENT)) { result.add(HafasUtil.parseStation(stationElem)); } return result; }