void ParserHafasXml::getJourneyDetails(const QString &id) { if (currentRequestState != FahrplanNS::noneRequest) { return; } journeyDetailRequestData.id = ""; //Some hafasxml backend provide the detailsdata inline //if so our parser already stored them if (journeyDetailInlineData.count() > 0 ) { for (int i = 0; i < journeyDetailInlineData.count(); i++) { JourneyDetailResultList *item = journeyDetailInlineData.at(i); if (item->id() == id) { emit journeyDetailsResult(item); return; } } emit errorOccured(tr("Internal error occured: JourneyResultdata not present!")); return; } //It seams we don't have the detailsdata internaly stored, //So we fetch them remotly. if (lastJourneyResultList) { for (int i = 0; i < lastJourneyResultList->itemcount(); i++) { JourneyResultItem *item = lastJourneyResultList->getItem(i); if (item->id() == id) { currentRequestState = FahrplanNS::journeyDetailsRequest; journeyDetailRequestData.id = item->id(); journeyDetailRequestData.date = item->date(); journeyDetailRequestData.duration = item->duration(); sendHttpRequest(item->internalData1(), "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"); return; } } } else { emit errorOccured(tr("Internal error occured: JourneyResultdata not present!")); } }
void Parser131500ComAu::getJourneyDetails(const QString &id) { if (currentRequestState != FahrplanNS::noneRequest) { return; } //Some hafasxml backend provide the detailsdata inline //if so our parser already stored them if (lastJourneyResultList->itemcount() > 0 ) { for (int i = 0; i < lastJourneyResultList->itemcount(); i++) { JourneyResultItem *item = lastJourneyResultList->getItem(i); if (item->id() == id) { emit journeyDetailsResult(parseDetails(item)); return; } } } emit errorOccured(tr("Internal error occured: JourneyResultdata not present!")); return; }
void ParserHafasXml::parseSearchJourney(QNetworkReply *networkReply) { lastJourneyResultList = new JourneyResultList(); journeyDetailInlineData.clear(); QBuffer readBuffer; readBuffer.setData(networkReply->readAll()); readBuffer.open(QIODevice::ReadOnly); QXmlQuery query; query.bindVariable("path", &readBuffer); query.setQuery("doc($path)/ResC/Err//@text/string()"); QStringList errorResult; if (!query.evaluateTo(&errorResult)) { qDebug() << "parserHafasXml::ErrorTest - Query Failed"; } if (errorResult.count() > 0 ) { emit errorOccured(errorResult.join("").trimmed()); qWarning()<<"ParserHafasXml::parseSearchJourneyPart2:"<<errorResult.join(""); return; } //Query for station infos query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection/@id/string()"); QStringList resultIds; if (!query.evaluateTo(&resultIds)) { qDebug() << "parserHafasXml::getJourneyData 2 - Query Failed"; } if (resultIds.count() <= 0) { emit journeyResult(lastJourneyResultList); return; } for(int i = 0;i<resultIds.count(); i++) { //qDebug()<<"Connection:"<<resultIds[i]; query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Date/string()"); QStringList dateResult; if (!query.evaluateTo(&dateResult)) { qDebug() << "parserHafasXml::getJourneyData 3 - Query Failed"; } query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Transfers/string()"); QStringList transfersResult; if (!query.evaluateTo(&transfersResult)) { qDebug() << "parserHafasXml::getJourneyData 4 - Query Failed"; } query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Duration/Time/string()"); QStringList durationResult; if (!query.evaluateTo(&durationResult)) { qDebug() << "parserHafasXml::getJourneyData 5 - Query Failed"; } query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Products/Product/@cat/string()"); QStringList trainsResult; if (!query.evaluateTo(&trainsResult)) { qDebug() << "parserHafasXml::getJourneyData 6 - Query Failed"; } query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Departure/BasicStop/Station/@name/string()"); QStringList depResult; if (!query.evaluateTo(&depResult)) { qDebug() << "parserHafasXml::getJourneyData 7 - Query Failed"; } query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Arrival/BasicStop/Station/@name/string()"); QStringList arrResult; if (!query.evaluateTo(&arrResult)) { qDebug() << "parserHafasXml::getJourneyData 8 - Query Failed"; } query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Departure/BasicStop/Dep/Time/string()"); QStringList depTimeResult; if (!query.evaluateTo(&depTimeResult)) { qDebug() << "parserHafasXml::getJourneyData 9 - Query Failed"; } query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Departure/BasicStop/Dep/Platform/Text/string()"); QStringList depPlatResult; if (!query.evaluateTo(&depPlatResult)) { qDebug() << "parserHafasXml::getJourneyData 10 - Query Failed"; } query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Arrival/BasicStop/Arr/Time/string()"); QStringList arrTimeResult; if (!query.evaluateTo(&arrTimeResult)) { qDebug() << "parserHafasXml::getJourneyData 11 - Query Failed"; } query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/Arrival/BasicStop/Arr/Platform/Text/string()"); QStringList arrPlatResult; if (!query.evaluateTo(&arrPlatResult)) { qDebug() << "parserHafasXml::getJourneyData 12 - Query Failed"; } query.setQuery("doc($path)/ResC/ConRes/ConnectionList/Connection[@id='" + resultIds[i] + "']/Overview/XMLHandle/@url/string()"); QStringList xmlHandleResult; if (!query.evaluateTo(&xmlHandleResult)) { qDebug() << "parserHafasXml::getJourneyData 13 - Query Failed"; } QDate date = QDate::fromString(dateResult.join("").trimmed(), "yyyyMMdd"); for (int j = 0; j < trainsResult.count(); j++) { trainsResult[j] = trainsResult[j].trimmed(); } JourneyResultItem *item = new JourneyResultItem(); item->setDate(date); item->setId(resultIds[i]); item->setTransfers(transfersResult.join("").trimmed()); item->setDuration(cleanHafasDate(durationResult.join("").trimmed())); item->setMiscInfo(""); item->setTrainType(trainsResult.join(", ").trimmed()); item->setDepartureTime(cleanHafasDate(depTimeResult.join("").trimmed())); item->setArrivalTime(cleanHafasDate(arrTimeResult.join("").trimmed())); bool hasInline = false; QString internalData1 = xmlHandleResult.join("").trimmed(); if (internalData1.count() > 0 && internalData1.indexOf("extxml.exe")) { hasInline = true; } if (internalData1.count() > 0) { internalData1.remove(0, internalData1.indexOf("query.exe") + 9); internalData1.prepend(baseUrl); item->setInternalData1(internalData1); } else { hasInline = true; } if (hasInline){ journeyDetailRequestData.id = item->id(); journeyDetailRequestData.date = item->date(); journeyDetailRequestData.duration = item->duration(); QByteArray data = readBuffer.buffer(); JourneyDetailResultList *results = internalParseJourneyDetails(data); journeyDetailInlineData.append(results); } lastJourneyResultList->setDepartureStation(depResult.join("").trimmed()); lastJourneyResultList->setArrivalStation(arrResult.join("").trimmed()); lastJourneyResultList->setTimeInfo(date.toString()); lastJourneyResultList->appendItem(item); } //Query for next and prev stuff query.setQuery("doc($path)/ResC/ConRes/ConResCtxt/string()"); QStringList ConResCtxtResult; if (!query.evaluateTo(&ConResCtxtResult)) { qDebug() << "parserHafasXml::getJourneyData 14 - Query Failed"; } hafasContext.seqNr = ConResCtxtResult.join(""); emit journeyResult(lastJourneyResultList); }