void XmlUtil::readServerConfig ( const QString& xml, ServerConfig& conf ) { QXmlStreamReader reader ( xml ); while ( !reader.atEnd() ) { if ( reader.readNext() == QXmlStreamReader::StartElement ) break; } if ( reader.name() != CONFIG_ROOT_TAG ) throw InvalidXmlException("No config root tag found.", reader.lineNumber(), reader.columnNumber(), reader.characterOffset()); while ( !reader.atEnd() ) { if ( reader.readNext() == QXmlStreamReader::StartElement ) { if ( reader.name() == "port" ) { bool ok; conf.port = reader.readElementText().toInt(&ok); if ( !ok || conf.port > (1 << 16 - 1) ) throw InvalidXmlException("Invalid server port specified.", reader.lineNumber(), reader.columnNumber(), reader.characterOffset()); } else if ( reader.name() == "db" ) { conf.db_path = reader.readElementText(); } else if ( reader.name() == "stage_file" ) { conf.stage_files.push_back(reader.readElementText()); } else { //barf? } } } if ( reader.hasError() ) throw IllFormedXmlException(reader.errorString(), reader); }
static inline QString msgError(const QXmlStreamReader &reader, const QString &fileName, const QString &what) { return QString::fromLatin1("Error in %1 at line %2, column %3: %4"). arg(fileName).arg(reader.lineNumber()).arg(reader.columnNumber()).arg(what); }
QString composeMessage( const QXmlStreamReader& xml ) { QString errorstr( xml.errorString() ); errorstr += " at line " + QString::number(xml.lineNumber()); errorstr += " (column " + QString::number(xml.columnNumber()); errorstr += ")"; return errorstr; }
StorageParserException::StorageParserException( const QString &s, const QXmlStreamReader &xml ) : StorageException( s ), m_element( xml.name().toString() ), m_line( xml.lineNumber() ), m_column( xml.columnNumber() ), m_characterOffset( xml.characterOffset() ) { }
void xmlHasError(QXmlStreamReader &xml,QString filename){ QString ERROR=QObject::tr("Error in file:%4\n%1\nLine %2, column %3") .arg(xml.errorString()) .arg(xml.lineNumber()) .arg(xml.columnNumber()) .arg(filename); QMessageBox::information(0, QString(QObject::tr("Error")), ERROR, QMessageBox::Ok); }
QFile::FileError QLCFixtureDef::loadXML(const QString& fileName) { QFile::FileError error = QFile::NoError; if (fileName.isEmpty() == true) return QFile::OpenError; QXmlStreamReader *doc = QLCFile::getXMLReader(fileName); if (doc == NULL || doc->device() == NULL || doc->hasError()) { qWarning() << Q_FUNC_INFO << "Unable to read from" << fileName; return QFile::ReadError; } while (!doc->atEnd()) { if (doc->readNext() == QXmlStreamReader::DTD) break; } if (doc->hasError()) { QLCFile::releaseXMLReader(doc); return QFile::ResourceError; } if (doc->dtdName() == KXMLQLCFixtureDefDocument) { // qDebug() << Q_FUNC_INFO << "Loading " << fileName; if (loadXML(*doc) == true) error = QFile::NoError; else { qWarning() << fileName << QString("%1\nLine %2, column %3") .arg(doc->errorString()) .arg(doc->lineNumber()) .arg(doc->columnNumber()); error = QFile::ReadError; } } else { error = QFile::ReadError; qWarning() << Q_FUNC_INFO << fileName << "is not a fixture definition file"; } QLCFile::releaseXMLReader(doc); return error; }
void MetaInfoParser::errorHandling(QXmlStreamReader &reader, QFile &file) { if (!reader.hasError()) return; qDebug() << QString("Error at %1, %2:%3: %4") .arg(file.fileName()) .arg(reader.lineNumber()) .arg(reader.columnNumber()) .arg(reader.errorString()); file.reset(); QString fileString = file.readAll(); QString snippetString; int lineCount = 0; int position = reader.characterOffset(); while (position >= 0) { if (fileString[position] == '\n') { if (lineCount > 3) break; lineCount++; } snippetString.prepend(fileString[position]); position--; } lineCount = 0; position = reader.characterOffset(); while (position >= 0) { position++; if (fileString[position] == '\n') { if (lineCount > 1) break; lineCount++; } snippetString.append(fileString[position]); } qDebug() << snippetString; }
bool OsmAnd::MapStyle_P::parse( QXmlStreamReader& xmlReader ) { auto rulesetType = MapStyleRulesetType::Invalid; struct Lexeme { enum Type { Rule, Group, }; Lexeme(Type type_, MapStyle_P* style_) : type(type_) , style(style_) {} const Type type; MapStyle_P* const style; }; struct Rule : public Lexeme { Rule(std::shared_ptr<MapStyleRule> rule_, MapStyle_P* style_) : Lexeme(Lexeme::Rule, style_) , rule(rule_) {} const std::shared_ptr<MapStyleRule> rule; }; struct Group : public Lexeme { Group(MapStyle_P* const style_) : Lexeme(Lexeme::Group, style_) {} QHash< QString, QString > attributes; QList< std::shared_ptr<MapStyleRule> > children; QList< std::shared_ptr<Lexeme> > subgroups; void addGroupFilter(const std::shared_ptr<MapStyleRule>& rule) { for(auto itChild = children.cbegin(); itChild != children.cend(); ++itChild) { auto child = *itChild; child->_d->_ifChildren.push_back(rule); } for(auto itSubgroup = subgroups.cbegin(); itSubgroup != subgroups.cend(); ++itSubgroup) { auto subgroup = *itSubgroup; assert(subgroup->type == Lexeme::Group); std::static_pointer_cast<Group>(subgroup)->addGroupFilter(rule); } } bool registerGlobalRules(const MapStyleRulesetType type) { for(auto itChild = children.cbegin(); itChild != children.cend(); ++itChild) { auto child = *itChild; if(!style->registerRule(type, child)) return false; } for(auto itSubgroup = subgroups.cbegin(); itSubgroup != subgroups.cend(); ++itSubgroup) { auto subgroup = *itSubgroup; assert(subgroup->type == Lexeme::Group); if(!std::static_pointer_cast<Group>(subgroup)->registerGlobalRules(type)) return false; } return true; } }; QStack< std::shared_ptr<Lexeme> > stack; while (!xmlReader.atEnd() && !xmlReader.hasError()) { xmlReader.readNext(); const auto tagName = xmlReader.name(); if (xmlReader.isStartElement()) { if(tagName == QLatin1String("renderingStyle")) { // We have already parsed metadata and resolved dependencies, so here we don't need to do anything } else if(tagName == QLatin1String("renderingConstant")) { const auto& attribs = xmlReader.attributes(); auto name = attribs.value(QLatin1String("name")).toString(); auto value = attribs.value(QLatin1String("value")).toString(); _parsetimeConstants.insert(name, value); } else if(tagName == QLatin1String("renderingProperty")) { MapStyleConfigurableInputValue* inputValue = nullptr; const auto& attribs = xmlReader.attributes(); auto name = obtainValue(attribs.value(QLatin1String("attr")).toString()); auto type = obtainValue(attribs.value(QLatin1String("type")).toString()); auto title = obtainValue(attribs.value(QLatin1String("name")).toString()); auto description = attribs.value(QLatin1String("description")).toString(); auto encodedPossibleValues = attribs.value(QLatin1String("possibleValues")); QStringList possibleValues; if(!encodedPossibleValues.isEmpty()) possibleValues = encodedPossibleValues.toString().split(',', QString::SkipEmptyParts); for(auto itPossibleValue = possibleValues.begin(); itPossibleValue != possibleValues.end(); ++itPossibleValue) { auto& possibleValue = *itPossibleValue; possibleValue = obtainValue(possibleValue); } if(type == QLatin1String("string")) { inputValue = new MapStyleConfigurableInputValue( MapStyleValueDataType::String, name, title, description, possibleValues); } else if(type == QLatin1String("boolean")) { inputValue = new MapStyleConfigurableInputValue( MapStyleValueDataType::Boolean, name, title, description, possibleValues); } else // treat as integer { inputValue = new MapStyleConfigurableInputValue( MapStyleValueDataType::Integer, name, title, description, possibleValues); } registerValue(inputValue); } else if(tagName == QLatin1String("renderingAttribute")) { const auto& attribs = xmlReader.attributes(); auto name = obtainValue(attribs.value(QLatin1String("name")).toString()); std::shared_ptr<MapStyleRule> attribute(new MapStyleRule(owner, QHash< QString, QString >())); _attributes.insert(name, attribute); std::shared_ptr<Lexeme> selector(new Rule(attribute, this)); stack.push(qMove(selector)); } else if(tagName == QLatin1String("filter")) { QHash< QString, QString > ruleAttributes; if(!stack.isEmpty()) { auto lexeme = stack.top(); if(lexeme->type == Lexeme::Group) ruleAttributes.unite(std::static_pointer_cast<Group>(lexeme)->attributes); } const auto& attribs = xmlReader.attributes(); for(auto itXmlAttrib = attribs.cbegin(); itXmlAttrib != attribs.cend(); ++itXmlAttrib) { const auto& xmlAttrib = *itXmlAttrib; const auto tag = xmlAttrib.name().toString(); const auto value = obtainValue(xmlAttrib.value().toString()); ruleAttributes.insert(qMove(tag), qMove(value)); } const std::shared_ptr<MapStyleRule> rule(new MapStyleRule(owner, ruleAttributes)); if(!stack.isEmpty()) { auto lexeme = stack.top(); if(lexeme->type == Lexeme::Group) { std::static_pointer_cast<Group>(lexeme)->children.push_back(rule); } else if(lexeme->type == Lexeme::Rule) { std::static_pointer_cast<Rule>(lexeme)->rule->_d->_ifElseChildren.push_back(rule); } } else { if(!registerRule(rulesetType, rule)) return false; } stack.push(qMove(std::shared_ptr<Lexeme>(new Rule(rule, this)))); } else if(tagName == QLatin1String("groupFilter")) { QHash< QString, QString > attributes; const auto& attribs = xmlReader.attributes(); for(auto itXmlAttrib = attribs.cbegin(); itXmlAttrib != attribs.cend(); ++itXmlAttrib) { const auto& xmlAttrib = *itXmlAttrib; const auto tag = xmlAttrib.name().toString(); const auto value = obtainValue(xmlAttrib.value().toString()); attributes.insert(qMove(tag), qMove(value)); } std::shared_ptr<MapStyleRule> rule(new MapStyleRule(owner, attributes)); if(stack.isEmpty()) { OsmAnd::LogPrintf(OsmAnd::LogSeverityLevel::Error, "Group filter without parent"); return false; } auto lexeme = stack.top(); if(lexeme->type == Lexeme::Group) { std::static_pointer_cast<Group>(lexeme)->addGroupFilter(rule); } else if(lexeme->type == Lexeme::Rule) { std::static_pointer_cast<Rule>(lexeme)->rule->_d->_ifChildren.push_back(rule); } stack.push(qMove(std::shared_ptr<Lexeme>(new Rule(rule, this)))); } else if(tagName == QLatin1String("group")) { const auto group = new Group(this); if(!stack.isEmpty()) { auto lexeme = stack.top(); if(lexeme->type == Lexeme::Group) group->attributes.unite(std::static_pointer_cast<Group>(lexeme)->attributes); } const auto& attribs = xmlReader.attributes(); for(auto itXmlAttrib = attribs.cbegin(); itXmlAttrib != attribs.cend(); ++itXmlAttrib) { const auto& xmlAttrib = *itXmlAttrib; const auto tag = xmlAttrib.name().toString(); const auto value = obtainValue(xmlAttrib.value().toString()); group->attributes.insert(qMove(tag), qMove(value)); } stack.push(qMove(std::shared_ptr<Lexeme>(group))); } else if(tagName == QLatin1String("order")) { rulesetType = MapStyleRulesetType::Order; } else if(tagName == QLatin1String("text")) { rulesetType = MapStyleRulesetType::Text; } else if(tagName == QLatin1String("point")) { rulesetType = MapStyleRulesetType::Point; } else if(tagName == QLatin1String("line")) { rulesetType = MapStyleRulesetType::Polyline; } else if(tagName == QLatin1String("polygon")) { rulesetType = MapStyleRulesetType::Polygon; } } else if(xmlReader.isEndElement()) { if(tagName == QLatin1String("filter")) { stack.pop(); } else if(tagName == QLatin1String("group")) { const auto lexeme = stack.pop(); if (stack.isEmpty()) { assert(lexeme->type == Lexeme::Group); if(!std::static_pointer_cast<Group>(lexeme)->registerGlobalRules(rulesetType)) return false; } else { const auto group = stack.top(); if(group->type == Lexeme::Group) std::static_pointer_cast<Group>(group)->subgroups.push_back(qMove(lexeme)); } } else if(tagName == QLatin1String("groupFilter")) { stack.pop(); } else if(tagName == QLatin1String("renderingAttribute")) { stack.pop(); } } } if(xmlReader.hasError()) { std::cerr << qPrintable(xmlReader.errorString()) << "(" << xmlReader.lineNumber() << ", " << xmlReader.columnNumber() << ")" << std::endl; return false; } return true; }
bool OsmAnd::MapStylesPresetsCollection_P::deserializeFrom(QXmlStreamReader& xmlReader) { QList< std::shared_ptr<MapStylePreset> > order; QHash< QString, QHash< QString, std::shared_ptr<MapStylePreset> > > collection; std::shared_ptr<MapStylePreset> mapStylePreset; while(!xmlReader.atEnd() && !xmlReader.hasError()) { xmlReader.readNext(); const auto tagName = xmlReader.name(); if (xmlReader.isStartElement()) { if (tagName == QLatin1String("mapStylePreset")) { const auto type_ = xmlReader.attributes().value(QLatin1String("type")).toString(); auto type = MapStylePreset::Type::Custom; if (!type_.isEmpty()) { if (type_ == QLatin1String("general")) type = MapStylePreset::Type::General; else if (type_ == QLatin1String("pedestrian")) type = MapStylePreset::Type::Pedestrian; else if (type_ == QLatin1String("bicycle")) type = MapStylePreset::Type::Bicycle; else if (type_ == QLatin1String("car")) type = MapStylePreset::Type::Car; else if (type_ != QLatin1String("custom")) { LogPrintf(LogSeverityLevel::Warning, "Ignored map style preset with unknown type '%s'", qPrintable(type_)); continue; } } auto name = xmlReader.attributes().value(QLatin1String("name")).toString(); if (type != MapStylePreset::Type::Custom && name.isEmpty()) name = QLatin1String("type_") + type_; auto styleName = xmlReader.attributes().value(QLatin1String("style")).toString(); if (type == MapStylePreset::Type::Custom && name.isEmpty()) { LogPrintf(LogSeverityLevel::Warning, "Ignored map style preset with empty name and custom type"); continue; } if (styleName.isEmpty()) { LogPrintf(LogSeverityLevel::Warning, "Ignored orphaned map style preset with name '%s' and type '%s'", qPrintable(name), qPrintable(type_)); continue; } mapStylePreset.reset(new MapStylePreset(type, name, styleName)); } else if (tagName == QLatin1String("attribute")) { if (!mapStylePreset) continue; const auto name = xmlReader.attributes().value(QLatin1String("name")).toString(); const auto value = xmlReader.attributes().value(QLatin1String("value")).toString(); mapStylePreset->attributes.insert(name, value); } } else if (xmlReader.isEndElement()) { if (tagName == QLatin1String("mapStylePreset")) { auto& collectionForStyle = collection[mapStylePreset->styleName]; if (!collectionForStyle.contains(mapStylePreset->name)) { collectionForStyle.insert(mapStylePreset->name, mapStylePreset); order.push_back(mapStylePreset); } else LogPrintf(LogSeverityLevel::Warning, "Ignored duplicate map style preset with name '%s'", qPrintable(mapStylePreset->name)); mapStylePreset.reset(); } } } if (xmlReader.hasError()) { LogPrintf(LogSeverityLevel::Warning, "XML error: %s (%d, %d)", qPrintable(xmlReader.errorString()), xmlReader.lineNumber(), xmlReader.columnNumber()); return false; } _order = order; _collection = collection; return true; }
void cProfileSettings::load () { cProfileManager *pm = cProfileManager::self(); QString path = pm->profilePath (d->profileId); QDir dir = QDir (path); if (!dir.exists()) QDir::root().mkpath (dir.absolutePath()); QFile f (path + "/settings.xml"); if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { kWarning() << "No settings file - nothing to do." << endl; return; // no profiles - nothing to do } QXmlStreamReader *reader = new QXmlStreamReader (&f); reader->readNext (); // read the document start reader->readNext (); if (reader->isStartElement ()) if (reader->name() == "profile") if (reader->attributes().value ("version") == "1.0") { // okay, read the list while (!reader->atEnd()) { reader->readNext (); if (reader->isStartElement () && (reader->name() == "setting")) { QString type = reader->attributes().value ("type").toString(); QString name = reader->attributes().value ("name").toString(); QString value = reader->attributes().value ("value").toString(); if (type == "integer") setInt (name, value.toInt()); else if (type == "bool") setBool (name, (value == "true")); else if (type == "string") setString (name, value); else kDebug() << "Unrecognized setting type " << type << endl; } } } else reader->raiseError ("Unknown profile file version."); else reader->raiseError ("This is not a valid profile list file."); else reader->raiseError ("This file is corrupted."); if (reader->hasError()) { kWarning() << ("Error in settings.xml at line " + QString::number (reader->lineNumber()) + ", column " + QString::number (reader->columnNumber()) + QString (": ") + reader->errorString()) << endl; } // close the file f.close (); delete reader; }
static void raiseError(QXmlStreamReader &reader, const QString &error, Settings::ParseMode parseMode) { if (parseMode == Settings::StrictParseMode) { reader.raiseError(error); } else { QFile *xmlFile = qobject_cast<QFile*>(reader.device()); if (xmlFile) { qWarning().noquote().nospace() << "Ignoring following settings reader error in " << xmlFile->fileName() << ", line " << reader.lineNumber() << ", column " << reader.columnNumber() << ": " << error; } else { qWarning("Ignoring following settings reader error: %s", qPrintable(error)); } } }
bool OsmAnd::OnlineTileSources_P::deserializeFrom(QXmlStreamReader& xmlReader) { QHash< QString, std::shared_ptr<const Source> > collection; while(!xmlReader.atEnd() && !xmlReader.hasError()) { xmlReader.readNext(); if (!xmlReader.isStartElement()) continue; const auto tagName = xmlReader.name(); if (tagName == QLatin1String("tile_source")) { // Original format of the tile sources, used in the Android application if (xmlReader.attributes().hasAttribute("rule")) continue; // Rules are not supported const auto name = xmlReader.attributes().value(QLatin1String("name")).toString(); if (collection.contains(name)) { LogPrintf(LogSeverityLevel::Warning, "Ignored duplicate online tile source with name '%s'", qPrintable(name)); continue; } const auto originalUrlTemplate = xmlReader.attributes().value(QLatin1String("url_template")).toString(); auto urlPattern = originalUrlTemplate; urlPattern = urlPattern.replace(QLatin1String("{0}"), QLatin1String("${osm_zoom}")); urlPattern = urlPattern.replace(QLatin1String("{1}"), QLatin1String("${osm_x}")); urlPattern = urlPattern.replace(QLatin1String("{2}"), QLatin1String("${osm_y}")); const auto minZoom = static_cast<ZoomLevel>(xmlReader.attributes().value(QLatin1String("min_zoom")).toUInt()); const auto maxZoom = static_cast<ZoomLevel>(xmlReader.attributes().value(QLatin1String("max_zoom")).toUInt()); const auto tileSize = xmlReader.attributes().value(QLatin1String("tile_size")).toUInt(); std::shared_ptr<Source> newSource(new Source(name)); newSource->urlPattern = urlPattern; newSource->minZoom = minZoom; newSource->maxZoom = maxZoom; newSource->maxConcurrentDownloads = 1; newSource->tileSize = tileSize; newSource->alphaChannelData = AlphaChannelData::Undefined; collection.insert(name, newSource); } else if (tagName == QLatin1String("tileSource")) { //TODO: parse new format, but create it first :) } } if (xmlReader.hasError()) { LogPrintf(LogSeverityLevel::Warning, "XML error: %s (%d, %d)", qPrintable(xmlReader.errorString()), xmlReader.lineNumber(), xmlReader.columnNumber()); return false; } _collection = collection; return true; }
bool Syntax::load(QString file) { if(xmlSyntaxFileName==file) return true; else xmlSyntaxFileName=file; printf("[Syntax::load] Loading syntax\n"); QXmlStreamReader xml; QStack <QString> stack; QFile fileDevice(file); if (!fileDevice.open(QFile::ReadOnly | QFile::Text)) { printf("Error al abrir el archivo\n"); return false; } highlightingRules.clear(); highlightingBlockRules.clear(); highlightingBracketsRules.clear(); xml.setDevice(&fileDevice); QMap <QString,QString> values; QVector<QString> xmlMainItems; xmlMainItems << "item" << "block" << "bracket"; int ruleOrder=0; while (!xml.atEnd()) { QXmlStreamReader::TokenType tokenType=xml.readNext(); switch(tokenType) { case QXmlStreamReader::StartElement: if(xml.name()!="syntax") { if( xmlMainItems.contains(xml.name().toString()) ) stack.push(xml.name().toString()); else values[xml.name().toString()]=xml.readElementText().trimmed(); } break; case QXmlStreamReader::EndElement: if(stack.isEmpty()) break; QString name=stack.top(); if(name==xml.name()) stack.pop(); if(stack.isEmpty()) { QTextCharFormat format; if(values.contains("bold") && values["bold"]=="true") format.setFontWeight(QFont::Bold); if(values.contains("underline") && values["underline"]=="true") format.setFontUnderline(true); if(values.contains("italic") && values["italic"]=="true") format.setFontItalic(true); if(values.contains("foreground")) format.setForeground(QBrush(QColor(values["foreground"]))); if(values.contains("background")) format.setBackground(QBrush(QColor(values["background"]))); if(name=="item") { HighlightingRule rule; rule.format=format; rule.pattern=QRegExp(values["pattern"]); rule.ruleOrder=ruleOrder++; highlightingRules.append(rule); values.clear(); } else if(name=="block" || name=="bracket") { HighlightingBlockRule rule; rule.format=format; rule.startPattern=QRegExp(values["startPattern"]); rule.endPattern=QRegExp(values["endPattern"]); rule.ruleOrder=ruleOrder++; if(name=="block") highlightingBlockRules.append(rule); else highlightingBracketsRules.append(rule); //Bracket rule values.clear(); } } break; } } if (xml.hasError()) { // do error handling printf("Error %s: %ld:%ld %s\n", file.toLocal8Bit().data(), xml.lineNumber(), xml.columnNumber(), xml.errorString().toLocal8Bit().data() ); return false; } return true; }
bool OsmAnd::FavoriteLocationsGpxCollection_P::loadFrom(QXmlStreamReader& xmlReader) { std::shared_ptr< FavoriteLocation > newItem; QList< std::shared_ptr< FavoriteLocation > > newItems; while (!xmlReader.atEnd() && !xmlReader.hasError()) { xmlReader.readNext(); const auto tagName = xmlReader.name(); if (xmlReader.isStartElement()) { if (tagName == QLatin1String("wpt")) { if (newItem) { LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: unpaired <wpt>"); return false; } bool ok = true; const double lat = xmlReader.attributes().value(QLatin1String("lat")).toDouble(&ok); if (!ok) { LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: invalid latitude"); return false; } const double lon = xmlReader.attributes().value(QLatin1String("lon")).toDouble(&ok); if (!ok) { LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: invalid longitude"); return false; } newItem.reset(new FavoriteLocation(LatLon(lat, lon))); } else if (tagName == QLatin1String("name")) { if (!newItem) { LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: unpaired <name>"); return false; } newItem->setTitle(xmlReader.readElementText()); } else if (tagName == QLatin1String("category")) { if (!newItem) { LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: unpaired <category>"); return false; } const auto& group = xmlReader.readElementText(); if (!group.isEmpty()) newItem->setGroup(group); } else if (tagName == QLatin1String("color")) { if (!newItem) { LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: unpaired <color>"); return false; } bool ok = false; const auto color = Utilities::parseColor(xmlReader.readElementText(), ColorARGB(), &ok); if (!ok) { LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: invalid color"); continue; } newItem->setColor(static_cast<ColorRGB>(color)); } else if (tagName == QLatin1String("color")) { if (!newItem) { LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: unexpected <hidden/>"); return false; } newItem->setIsHidden(true); } } else if (xmlReader.isEndElement()) { if (tagName == QLatin1String("wpt")) { if (!newItem) { LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: unpaired </wpt>"); return false; } newItems.push_back(newItem); newItem.reset(); } } } if (xmlReader.hasError()) { LogPrintf( LogSeverityLevel::Warning, "XML error: %s (%" PRIi64 ", %" PRIi64 ")", qPrintable(xmlReader.errorString()), xmlReader.lineNumber(), xmlReader.columnNumber()); return false; } { QWriteLocker scopedLocker(&_collectionLock); doClearFavoriteLocations(); appendFrom(newItems); notifyCollectionChanged(); } return true; }
bool OsmAnd::MapStyle_P::parseMetadata( QXmlStreamReader& xmlReader ) { while (!xmlReader.atEnd() && !xmlReader.hasError()) { xmlReader.readNext(); const auto tagName = xmlReader.name(); if (xmlReader.isStartElement()) { if (tagName == QLatin1String("renderingStyle")) { _title = xmlReader.attributes().value(QLatin1String("name")).toString(); auto attrDepends = xmlReader.attributes().value(QLatin1String("depends")); if(!attrDepends.isNull()) _parentName = attrDepends.toString(); } } else if (xmlReader.isEndElement()) { } } if(xmlReader.hasError()) { std::cerr << qPrintable(xmlReader.errorString()) << "(" << xmlReader.lineNumber() << ", " << xmlReader.columnNumber() << ")" << std::endl; return false; } return true; }
[[noreturn]] void readError(QXmlStreamReader & reader) { std::cerr << inFilename << ':' << reader.lineNumber() << ':' << reader.columnNumber() << ": " << reader.errorString().toStdString() << std::endl; std::exit(4); }
HangingProtocol* HangingProtocolXMLReader::readFile(const QString &path) { QFile file(path); HangingProtocol *hangingProtocolLoaded = NULL; if (!file.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(0, tr("Hanging Protocol XML File"), tr("Unable to read file %1:\n%2.") .arg(path) .arg(file.errorString())); return NULL; } QXmlStreamReader *reader = new QXmlStreamReader(&file); if (reader->readNextStartElement()) { if (reader->name() == "hangingProtocol") { HangingProtocol *hangingProtocol = new HangingProtocol(); QStringList protocols; QList<HangingProtocolImageSet::Restriction> restrictionList; while (reader->readNextStartElement()) { if (reader->name() == "hangingProtocolName") { hangingProtocol->setName(reader->readElementText()); } else if (reader->name() == "numberScreens") { hangingProtocol->setNumberOfScreens(reader->readElementText().toInt()); } else if (reader->name() == "protocol") { protocols << reader->readElementText(); } else if (reader->name() == "institutions") { hangingProtocol->setInstitutionsRegularExpression(QRegExp(reader->readElementText(), Qt::CaseInsensitive)); } else if (reader->name() == "restriction") { restrictionList << readRestriction(reader); } else if (reader->name() == "imageSet") { HangingProtocolImageSet *imageSet = readImageSet(reader, restrictionList); hangingProtocol->addImageSet(imageSet); } else if (reader->name() == "displaySet") { HangingProtocolDisplaySet *displaySet = readDisplaySet(reader, hangingProtocol); hangingProtocol->addDisplaySet(displaySet); } else if (reader->name() == "strictness") { hangingProtocol->setStrictness(reader->readElementText().contains("yes")); } else if (reader->name() == "allDifferent") { hangingProtocol->setAllDiferent(reader->readElementText().contains("yes")); } else if (reader->name() == "iconType") { hangingProtocol->setIconType(reader->readElementText()); } else if (reader->name() == "hasPrevious") { hangingProtocol->setPrevious(reader->readElementText().contains("yes")); } else if (reader->name() == "priority") { hangingProtocol->setPriority(reader->readElementText().toDouble()); } else { reader->skipCurrentElement(); } } if (!reader->hasError()) { hangingProtocol->setProtocolsList(protocols); hangingProtocolLoaded = hangingProtocol; } else { delete hangingProtocol; } } } if (reader->hasError()) { DEBUG_LOG(QString("[Line: %1, Column:%2] Error in hanging protocol file %3: %4, error: %5").arg(reader->lineNumber()).arg(reader->columnNumber()).arg( path).arg(reader->errorString()).arg(reader->error())); ERROR_LOG(QString("[Line: %1, Column:%2] Error in hanging protocol file %3: %4, error: %5").arg(reader->lineNumber()).arg(reader->columnNumber()).arg( path).arg(reader->errorString()).arg(reader->error())); } delete reader; return hangingProtocolLoaded; }
bool Board::load(std::string cells_param) { ROS_DEBUG("Ready to read xml data of cells"); std::string xml_cells; if (ros::param::get(cells_param, xml_cells)) //reading the xml data from the parameter server { cells.clear(); //cleaning all previous cells QXmlStreamReader xml; xml.addData(QString::fromStdString(xml_cells)); //adding the xml content to the input stream while(!xml.atEnd() && !xml.hasError()) { /* Read next element.*/ QXmlStreamReader::TokenType token = xml.readNext(); ROS_DEBUG_STREAM("name=" << xml.name().toString().toStdString()); /* If token is just StartDocument, we'll go to next.*/ if(token == QXmlStreamReader::StartDocument) { continue; } /* If token is StartElement, we'll see if we can read it.*/ if(token == QXmlStreamReader::StartElement) { /* If it's named cell, we'll add a new cell to the board.*/ if(xml.name() == "cell") { cells.push_back(Cell()); continue; } /* If it's named vertex, we'll dig the information from there.*/ if(xml.name() == "vertex") { /* Let's get the attributes for vertex */ QXmlStreamAttributes attributes = xml.attributes(); /* Let's check that vertex has x and y attribute. */ if(attributes.hasAttribute("x") && attributes.hasAttribute("y")) { /* We'll add it to the cell */ cells.back().contours.push_back(cv::Point(attributes.value("x").toString().toInt(), attributes.value("y").toString().toInt())); } else xml.raiseError("Vertex corrupted: x and/or y value is missing"); } } } ROS_WARN_COND(xml.hasError(),"Error parsing xml data (l.%d, c.%d):%s", (int)xml.lineNumber(), (int)xml.columnNumber(), xml.errorString().toStdString().c_str()); ROS_INFO("Xml data successfully loaded. %i cells loaded.", (int)cells.size()); for (int i = 0; i < cells.size(); ++i) { ROS_INFO("Cell %i: %s",i,cells[i].toString().c_str()); } return true; } else { ROS_FATAL_STREAM("xml cell data not loaded!"); return false; } }