bool PercussionMap::startElement(const QString& /*namespaceURI*/, const QString& /*localName*/, const QString& qName, const QXmlAttributes& atts) { if (qName.toLower() == "percussion-map") { m_data.clear(); } else if (qName.toLower() == "instrument") { m_xmlPitchIn = atts.value("pitch").toInt(); m_xmlPitchOut = m_xmlPitchIn; m_xmlNotehead = "normal"; m_xmlStemUp = true; } else if (qName.toLower() == "display") { if (atts.index("pitch") >= 0) { m_xmlPitchOut = atts.value("pitch").toInt(); } if (atts.index("notehead") >= 0) { m_xmlNotehead = atts.value("notehead").toStdString(); } if (atts.index("stem") >= 0) { m_xmlStemUp = (atts.value("stem") == "down") ? false : true; } } return true; }
bool ChordXmlHandler::startElement(const QString& /* namespaceURI */, const QString& /* localName */, const QString& qName, const QXmlAttributes& atts) { QString lcName = qName.toLower(); if (lcName == "chordset") { // start new chord set m_currentRoot = atts.value("root").trimmed(); } else if (lcName == "chord") { m_currentChord = Guitar::Chord(m_currentRoot); if (atts.index("ext") >= 0) m_currentChord.setExt(atts.value("ext").trimmed()); if (atts.index("user") >= 0) { QString userVal = atts.value("user").trimmed().toLower(); bool res = (userVal == "yes" || userVal == "1" || userVal == "true"); m_currentChord.setUserChord(res); } else { m_currentChord.setUserChord(false); } } else if (lcName == "fingering") { m_inFingering = true; } return true; }
bool QtSkin::convertAttributesToColor(const QString& aName, const QXmlAttributes& theAttributes, QColor& aColor) { int redIndex=theAttributes.index("red"); int greenIndex=theAttributes.index("green"); int blueIndex=theAttributes.index("blue"); if(redIndex<0 || greenIndex<0 || blueIndex<0) { setErrorMessage("Invalid attributes for color "+aName); return false; } else { int red, green, blue; if(!convertStringToInteger(theAttributes.value(redIndex), red)) { setErrorMessage("Invalid red: "+theAttributes.value(redIndex)+" for "+aName); return false; } if(!convertStringToInteger(theAttributes.value(greenIndex), green)) { setErrorMessage("Invalid green: "+theAttributes.value(greenIndex)+" for "+aName); return false; } if(!convertStringToInteger(theAttributes.value(blueIndex), blue)) { setErrorMessage("Invalid blue: "+theAttributes.value(blueIndex)+" for "+aName); return false; } aColor.setRgb(red, green, blue); } return true; }
bool LoadXmlContentHandler::startElement(const QString&, const QString&, const QString& name, const QXmlAttributes& attr) { if (name == "oldfilter") { // clear information about the current filter m_currentFilterPattern = ""; m_currentMinLevel = 0; m_currentMaxLevel = 0; return true; } if (name == "regex") { m_inRegex =true; return true; } if (name == "level") { int index; // first check for a min index = attr.index("min"); // if min attribute was found, use it if (index != -1) m_currentMinLevel = uint8_t(attr.value(index).toUShort()); // then check for a max index = attr.index("max"); // if max attribute was found, use it if (index != -1) m_currentMaxLevel = uint8_t(attr.value(index).toUShort()); // done return true; } if (name == "section") { int index = attr.index("name"); // section is only valid if a name is specified if (index == -1) return false; // get the current type for the name m_currentType = m_types.type(attr.value(index)); return true; } return true; }
bool HelperXmlHandler_EpubTOC::startElement(const QString &, const QString &localName, const QString &, const QXmlAttributes &atts) { // qDebug() << "startElement " << " " << localName; // for ( int i = 0; i < atts.count(); i++ ) // qDebug() << " " << atts.localName(i) << " " << atts.value(i); if ( localName == "navMap" ) { m_inNavMap = true; return true; } if ( !m_inNavMap ) return true; if ( localName == "navPoint" ) m_indent++; if ( localName == "text" ) m_inText = true; if ( localName == "content" ) { int idx = atts.index( "src" ); if ( idx == -1 ) return false; m_lastId = atts.value( idx ); checkNewTocEntry(); } return true; }
bool XmlParser::getAtt( const QString &name, double *value, bool required, const QString &elementName, const QXmlAttributes& attribute ) { // Find the attribute name int id; if ( ( id = attribute.index( name ) ) < 0 ) { if ( required ) { m_error = QString( "<%1> element is missing the required " "\"%2=\" attribute." ).arg( elementName ).arg( name ) ; } return( false ); } // Get and return its integer value bool ok; *value = attribute.value( id ).toDouble( &ok ); if ( ! ok ) { m_error = QString( "<%1 %2=\"%3\" > element must be a real number." ) .arg( elementName ).arg( name ).arg( attribute.value( id ) ); return( false ); } return( true ); }
bool XmlParser::getAtt( const QString &name, bool *value, bool required, const QString &elementName, const QXmlAttributes& attribute ) { // Find the attribute name int id; if ( ( id = attribute.index( name ) ) < 0 ) { if ( required ) { m_error = QString( "<%1> element is missing the required " "\"%2=\" attribute." ).arg( elementName ).arg( name ) ; } return( false ); } // Get and return its boolean value QString perm = attribute.value( id ); if ( perm.lower() == "true" ) { *value = true; } else if ( perm.lower() == "false" ) { *value = false; } else { m_error = QString( "<%1 %2=\"%3\" > element must be \"true\" or \"false\"." ) .arg( elementName ).arg( name ).arg( perm ); return( false ); } return( true ); }
int indexOf(const QXmlAttributes & attributes, const QString & name, const QString & type = "CDATA", const bool mandatory = true) { const int idx(attributes.index(name)); if (idx < 0 || idx > attributes.length()) { return -1; } if (attributes.type(idx) != type) { return -1; } if (mandatory && attributes.value(idx).isEmpty()) { return -1; } return idx; }
bool PropertyParser::handleProperty( const QString &elementName, const QXmlAttributes& attribute ) { int id; QString name, value; // "name" attribute is required if ( ( id = attribute.index( "name" ) ) < 0 ) { trError( "PropertyParser:missingName", elementName, "name" ); return( false ); } name = attribute.value( id ); // "value" attribute is required if ( ( id = attribute.index( "value" ) ) < 0 ) { trError( "PropertyParser:missingAttribute", elementName, name, "value" ); return( false ); } if ( ( value = attribute.value( id ) ) == "(null)" ) { value = ""; } // Find this property in the local Property directory and update it Property *property; if ( ( property = m_propDict->find( name ) ) > 0 ) { if ( ! m_propDict->update( name, value ) ) { trError( "PropertyParser:badValue", elementName, name, "value", value ); return( false ); } } // Report unknown <property> names here. else { trError( "PropertyParser:badValue", elementName, name, "name", name ); return( false ); } return( true ); }
bool QtSkin::convertAttributesToRectangle(const QString& aName, const QXmlAttributes& theAttributes, QRect& aRectangle) { int xIndex = theAttributes.index("x"); int yIndex = theAttributes.index("y"); int widthIndex = theAttributes.index("width"); int heightIndex = theAttributes.index("height"); if (xIndex<0 || yIndex<0 || widthIndex < 0 || heightIndex < 0) { setErrorMessage("Invalid rectangle attributes for "+aName); return false; } else { int x; if (!convertStringToInteger(theAttributes.value(xIndex), x)) { setErrorMessage("Invalid x " + theAttributes.value(xIndex)+ " for "+aName); return false; } int y; if (!convertStringToInteger(theAttributes.value(yIndex), y)) { setErrorMessage("Invalid y " + theAttributes.value(yIndex)+ " for "+aName); return false; } int width; if (!convertStringToInteger(theAttributes.value(widthIndex), width)) { setErrorMessage("Invalid witdh " + theAttributes.value(widthIndex)+ " for "+aName); return false; } int height; if (!convertStringToInteger(theAttributes.value(heightIndex), height)) { setErrorMessage("Invalid height " + theAttributes.value(heightIndex)+ " for "+aName); return false; } aRectangle.setRect(x, y, width, height); return true; } }
virtual bool startElement(const QString &, const QString &, const QString &qName, const QXmlAttributes &atts) { kdDebug(26001) << "CharacterDataSearcher::startElement, qName " << qName << endl; int pos = atts.index("id"); if(pos > -1 && atts.value(pos) == m_id) { m_foundCount++; m_tagFound = qName; } return true; }
QString GetValue(const QXmlAttributes &pProperties, QString pName, QString pDefault, QString pAlias) { //If not found return default value if was defined if (pProperties.index(pName) == -1 && pDefault != "") return pDefault; //Define some Variables if (pAlias == "") pAlias = pName; QStringList validValues = ValidValues(pAlias); QString value = pProperties.value(pName); int index = -1; //Return original value if not defined valid values if (validValues.size() == 0) return value; //Search most correct index of value in validValues array if (IsEncriptedProperty(pName)) //Get proposed index { index = value.toInt(); } else if (IsNumberProperty(pName)) //Get most proximal valid index to proposed value as number { //Temp float valueFloat = QVariant(value).toFloat(); float diference; float minimal = std::numeric_limits<float>::max(); //Find most proximal numeric value and it index QListIterator<QString> i(validValues); while (i.hasNext()) { diference = qAbs(valueFloat - i.next().toFloat()); if (minimal > diference) { minimal = diference; index++; } else break; } } else //Get index of value { index = validValues.indexOf(value); } //Return extreme value if index not match with valid one if (index < 0) return validValues.first(); //First else if (index > validValues.size() - 1) index = validValues.size() - 1; //Last //Return correct value return validValues.value(index); }
bool startElement( const QString & namespaceURI, const QString & localName, const QString & qName, const QXmlAttributes & atts ) { std::string id = localName.toUtf8().operator const char *(); auto actionData = std::unique_ptr< QtActionData >( new QtActionData ); auto index = atts.index( "text" ); if (index >= 0) { actionData->text_ = atts.value( index ).toUtf8().operator const char *(); } else { actionData->text_ = id; } index = atts.index( "icon" ); if (index >= 0) { actionData->icon_ = atts.value( index ).toUtf8().operator const char *(); } index = atts.index( "window" ); if (index >= 0) { actionData->windowId_ = atts.value( index ).toUtf8().operator const char *(); } index = atts.index( "path" ); if (index >= 0) { actionData->path_ = atts.value( index ).toUtf8().operator const char *(); } index = atts.index( "shortcut" ); if (index >= 0) { actionData->shortcut_ = atts.value( index ).toUtf8().operator const char *(); } actionManager_.registerActionData( id.c_str(), actionData ); return true; }
bool GpxParser::startElement( const QString&, const QString&, const QString& qName, const QXmlAttributes& qAttributes) { buffer.clear(); if(metadata) return true; if(qName == "metadata") { metadata = true; } else if(qName == "trkpt") { int i = qAttributes.index("lat"); if(i >= 0) { lat = qAttributes.value(i).toDouble(); } else { lat = lastLat; } i = qAttributes.index("lon"); if( i >= 0) { lon = qAttributes.value(i).toDouble(); } else { lon = lastLon; } } return true; }
bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts) { if(depth == 0) { Parser::Event *e = new Parser::Event; QXmlAttributes a; for(int n = 0; n < atts.length(); ++n) { QString uri = atts.uri(n); QString ln = atts.localName(n); if(a.index(uri, ln) == -1) a.append(atts.qName(n), uri, ln, atts.value(n)); } e->setDocumentOpen(namespaceURI, localName, qName, a, nsnames, nsvalues); nsnames.clear(); nsvalues.clear(); e->setActualString(in->lastString()); in->resetLastData(); eventList.append(e); in->pause(true); } else { QDomElement e = doc->createElementNS(namespaceURI, qName); for(int n = 0; n < atts.length(); ++n) { QString uri = atts.uri(n); QString ln = atts.localName(n); bool have; if(!uri.isEmpty()) { have = e.hasAttributeNS(uri, ln); if(qt_bug_have) have = !have; } else have = e.hasAttribute(ln); if(!have) e.setAttributeNS(uri, atts.qName(n), atts.value(n)); } if(depth == 1) { elem = e; current = e; } else { current.appendChild(e); current = e; } } ++depth; return true; }
bool XmlParser::getAtt( const QString &name, QString &value, bool required, const QString &elementName, const QXmlAttributes& attribute ) { // Find the attribute name int id; if ( ( id = attribute.index( name ) ) < 0 ) { if ( required ) { m_error = QString( "<%1> element is missing the required " "\"%2=\" attribute." ).arg( elementName ).arg( name ) ; } return( false ); } value = attribute.value( id ); return( true ); }
bool Remote::startElement(const QString &, const QString &, const QString &name, const QXmlAttributes &attributes) { if(name == "remote") theId = theName = attributes.value("id"); else if(name == "button") { curRB = new RemoteButton(); curRB->setId(attributes.value("id")); curRB->setClass(attributes.value("id")); if(attributes.index("class") > -1) curRB->setClass(attributes.value("class")); curRB->setParameter(attributes.value("parameter")); curRB->setName(attributes.value("id")); } charBuffer = ""; return true; }
bool XmlNotation::impl::startElement(const QString &namespaceURI, const QString &, const QString &qName, const QXmlAttributes &atts) { Log::Xml("<%s xmlns=\"%s\">", qName.toStdString().c_str(), namespaceURI.toStdString().c_str()); if (0 != namespaceURI.compare(fromU8Str(xmlns))) return false; if (0 == qName.compare(fromU8Str(eRoot))) { return true; } else if (0 == qName.compare(fromU8Str(eTurn))) { auto idx_white = atts.index(fromU8Str(aWhite)); auto idx_black = atts.index(fromU8Str(aBlack)); Turn t_white, t_black; if (-1 != idx_white) { t_white = Turn::from_string(atts.value(idx_white).toStdString()); //if (t_white.position.empty()) return false; } if (-1 != idx_black) { t_black = Turn::from_string(atts.value(idx_black).toStdString()); //if (t_black.position.empty()) return false; } moves->emplace_back(Moves { ++_seqnum, t_white, t_black }); return true; } return false; }
bool OPCodeXmlContentHandler::startElement(const QString&, const QString&, const QString& name, const QXmlAttributes& attr) { if (name == "opcode") { bool ok = false; // get the index of the id attribute int index = attr.index("id"); if (index == -1) { seqWarn("OPCodeXmlContentHandler::startElement(): opcode element without id!"); return false; // this is an error, something is wrong } // the id attribute is the opcode value uint16_t opcode = attr.value(index).toUShort(&ok, 16); #if 0 // ZBTEMP opcode += 2; #endif if (!ok) { seqWarn("OPCodeXmlContentHandler::startElement(): opcode '%s' failed to convert to uint16_t (result: %#04x)", attr.value(index).latin1(), opcode); return false; // this is an error } // get the index of the name attribute index = attr.index("name"); // if name attribute was found, set the opcode objects name if (index == -1) { seqWarn("OPCodeXmlContentHandler::startElement(): opcode %#04x missing name parameter!", opcode); return false; } // add/create the new opcode object m_currentOPCode = m_opcodeDB.add(opcode, attr.value(index)); if (!m_currentOPCode) { seqWarn("Failed to add opcode %04x", opcode); return false; } // get the index of the updated attribute index = attr.index("updated"); // if the updated attribute was found, set the objects updated field if (index != -1) m_currentOPCode->setUpdated(attr.value(index)); // get the index of the implicitlen attribute index = attr.index("implicitlen"); // if implicitlen attribute was found, set the objects implicitLen field if (index != -1) m_currentOPCode->setImplicitLen(attr.value(index).toUShort()); return true; } if ((name == "comment") && (m_currentOPCode)) { // clear any current comment m_currentComment = ""; m_inComment = true; return true; } if ((name == "payload") && (m_currentOPCode)) { // create a new payload object and make it the current one m_currentPayload = new EQPacketPayload(); // add the payload object to the opcode m_currentOPCode->append(m_currentPayload); // check for direction attribute int index = attr.index("dir"); // if an index attribute exists, then use it if (index != -1) { QString value = attr.value(index); if (value == "both") m_currentPayload->setDir(DIR_Client | DIR_Server); else if (value == "server") m_currentPayload->setDir(DIR_Server); else if (value == "client") m_currentPayload->setDir(DIR_Client); } // get the typename attribute index = attr.index("typename"); // if a typename attribute exist, then set the payload type if (index != -1) { QString value = attr.value(index); if (!value.isEmpty()) { if (!m_currentPayload->setType(m_typeDB, value)) seqWarn("Unknown payload typename '%s' for opcode '%04x'", value.latin1(), m_currentOPCode->opcode()); } } // attempt to retrieve the sizechecktype index = attr.index("sizechecktype"); // if a sizechecktype exists, then set the payload size check type if (index != -1) { QString value = attr.value(index); if (value.isEmpty() || (value == "none")) m_currentPayload->setSizeCheckType(SZC_None); else if (value == "match") m_currentPayload->setSizeCheckType(SZC_Match); else if (value == "modulus") m_currentPayload->setSizeCheckType(SZC_Modulus); } return true; } return true; }
bool XmlRoutinesHandler::startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts) { if( !isInRoot() && qName == "root" ) { m_inRoot = true; if( m_showOutput ) qDebug("Found XML root"); } else if( !isInPlan() && qName == "plan" ) { m_inPlan = true; m_currentPlan = new Plan(); m_currentPlan->setName(atts.value("name")); RoutineManager::instance().plans().append(m_currentPlan); if( m_showOutput ) qDebug("\tPlan: %s", m_currentPlan->name().toAscii().constData()); } else if( !isInLevel() && qName == "level" ) { m_inLevel = true; m_currentPlanLevel = new PlanLevel(); m_currentPlanLevel->setName(atts.value("name")); if( !m_currentPlan->hasBeginnerLevel() ) m_currentPlan->setBeginnerLevel(m_currentPlanLevel); else if( !m_currentPlan->hasIntermediateLevel() ) m_currentPlan->setIntermediateLevel(m_currentPlanLevel); else if( !m_currentPlan->hasAdvancedLevel() ) m_currentPlan->setAdvancedLevel(m_currentPlanLevel); if( m_showOutput ) qDebug("\t\tLevel: %s", m_currentPlanLevel->name().toAscii().constData()); } else if( !isInRoutine() && qName == "rutina" ) { m_inRoutine = true; m_currentRoutine = new Routine(); int id = m_currentPlanLevel->addRoutine(m_currentRoutine); m_currentRoutine->setId(id); if( m_showOutput ) qDebug("\t\t\tRoutine: %d", id); } else if( !isInExercise() && !isInExerciseComposition() && qName == "ejercicio" ) { m_inExercise = true; m_currentRoutineExercise = new RoutineExercise(); int id = m_currentRoutine->addExercise(m_currentRoutineExercise); m_currentRoutineExercise->setId(id); int i = -1; if( (i = atts.index("type")) >= 0 ) m_currentRoutineExercise->setExerciseId(atts.value(i).toInt()); if( (i = atts.index("time")) >= 0 ) m_currentRoutineExercise->setTime(atts.value(i).toInt()); if( (i = atts.index("distance")) >= 0 ) m_currentRoutineExercise->setDistance(atts.value(i).toInt()); if( (i = atts.index("special")) >= 0 ) m_currentRoutineExercise->setSpecial(atts.value(i).toInt()); if( (i = atts.index("series")) >= 0 ) m_currentRoutineExercise->setSeries(atts.value(i).toInt()); if( m_showOutput ) qDebug("\t\t\t\tEjercicio (%d) type:%d time:%d series:%d distance:%d special:%d", id, m_currentRoutineExercise->exerciseId(), m_currentRoutineExercise->time(), m_currentRoutineExercise->series(), m_currentRoutineExercise->distance(), m_currentRoutineExercise->special()); } else if( !isInExerciseComposition() && qName == "ejercicioCompuesto" ) { m_inExerciseComposition = true; m_currentRoutineExerciseComposition = new RoutineExerciseComposition(); int id = m_currentRoutine->addExercise(m_currentRoutineExerciseComposition); m_currentRoutineExerciseComposition->setId(id); m_currentRoutineExerciseComposition->setCount(atts.value("count").toInt()); if( m_showOutput ) qDebug("\t\t\t\tEjercicio Compuesto (%d) count:%d", id, m_currentRoutineExerciseComposition->count()); } else if( !isInExerciseWithinExerciseComposition() && qName == "ejercicio" ) { m_inExerciseWithinExerciseComposition = true; m_currentRoutineExerciseWithinExerciseComposition = new RoutineExercise(); int id = m_currentRoutineExerciseComposition->addExercise(m_currentRoutineExerciseWithinExerciseComposition); m_currentRoutineExerciseWithinExerciseComposition->setId(id); int i = -1; if( (i = atts.index("type")) >= 0 ) m_currentRoutineExerciseWithinExerciseComposition->setExerciseId(atts.value(i).toInt()); if( (i = atts.index("time")) >= 0 ) m_currentRoutineExerciseWithinExerciseComposition->setTime(atts.value(i).toInt()); if( (i = atts.index("distance")) >= 0 ) m_currentRoutineExerciseWithinExerciseComposition->setDistance(atts.value(i).toInt()); if( (i = atts.index("special")) >= 0 ) m_currentRoutineExerciseWithinExerciseComposition->setSpecial(atts.value(i).toInt()); if( (i = atts.index("series")) >= 0 ) m_currentRoutineExerciseWithinExerciseComposition->setSeries(atts.value(i).toInt()); if( m_showOutput ) qDebug("\t\t\t\t\tEjercicio (%d) type:%d time:%d series:%d disance:%d special:%d", id, m_currentRoutineExerciseWithinExerciseComposition->exerciseId(), m_currentRoutineExerciseWithinExerciseComposition->time(), m_currentRoutineExerciseWithinExerciseComposition->series(), m_currentRoutineExerciseWithinExerciseComposition->distance(), m_currentRoutineExerciseWithinExerciseComposition->special()); } return true; }
bool TypeRuleParser::startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts) { Q_UNUSED(namespaceURI); Q_UNUSED(qName); // Save current element so that we know where the characters() belong to QString name(localName.toLower()); // Is this a known element? if (!schema().knownElement(name)) { QStringList chdn = schema().children(_elems.top()); typeRuleErrorLoc(QString("Element \"%1\" is unknown. Allowed " "elements in this context are: %2") .arg(name) .arg(chdn.isEmpty() ? QString("(none)") : chdn.join(", "))); } // Is this an allowed children of this element? if (!schema().allowedChild(_elems.top(), name)) { QStringList chdn = schema().children(_elems.top()); typeRuleErrorLoc(QString("Element \"%1\" not allowed here. Allowed " "elements in this context are: %2") .arg(name) .arg(chdn.isEmpty() ? QString("(none)") : chdn.join(", "))); } const XmlElement& elem = schema().element(name); static const KeyValueStore osFilterAttr = OsFilter::supportedFilters(); OsFilter* osf = 0; QString attr; KeyValueStore attributes; // Check the element's attributes for (int i = 0; i < atts.count(); ++i) { // Compare attributes case-insensitive attr = atts.localName(i).toLower(); // Is the attribute known to OsFilter? if (osFilterAttr.contains(attr)) { // Create a new OS filter, if not yet done if (!osf) { // Are OS filters allowed here? if (!elem.optionalAttributes.contains(attr)) typeRuleErrorLoc(QString("Operating system filters are not " "allowed for element \"%1\".") .arg(name)); // Create new filter based on the stack top (if exists) osf = _osfStack.isEmpty() ? new OsFilter() : new OsFilter(*_osfStack.top().osf); _osfStack.push(OsFilterScope(name, osf)); } osf->parseOption(attr, atts.value(i)); } else if (!elem.optionalAttributes.contains(attr) && !elem.requiredAttributes.contains(attr)) { QStringList list(elem.requiredAttributes); list.append(elem.optionalAttributes); typeRuleErrorLoc(QString("Unknown attribute \"%1\" for element \"%2\". " "Allowed attributes are: %3") .arg(attr) .arg(name) .arg(list.isEmpty() ? QString("(none)") : list.join(", "))); } else { attributes[attr] = atts.value(i); if (attr == xml::priority) { bool ok; int prio = atts.value(i).toInt(&ok); if (!ok) typeRuleErrorLoc(QString("Not a valid integer number: %1") .arg(atts.value(i))); _priorities.push(PriorityScope(name, prio)); } } } // Did we find all required attributes? for (int i = 0; i < elem.requiredAttributes.size(); ++i) { if (atts.index(elem.requiredAttributes[i]) < 0) typeRuleErrorLoc(QString("Element \"%1\" requires attribute \"%2\" " "to be specified.") .arg(name) .arg(elem.requiredAttributes[i])); } // Check if the OS filter is same if (osf) { if (!osf->minVersion().isEmpty() && !osf->maxVersion().isEmpty() && OsFilter::compareVersions(osf->minVersion(), osf->maxVersion()) > 0) { typeRuleErrorLoc(QString("Within element \"%0\": min. OS version " "is larger than max. version: %1 > %2") .arg(name) .arg(osf->minVersion().join(".")) .arg(osf->maxVersion().join("."))); } } // Check if we have multiple elements of that name in current scope if (!elem.allowMultiple && _children.top().contains(name)) { typeRuleErrorLoc(QString("Only one element \"%1\" is allowed here.") .arg(name)); } // <typeknowledge> if (name == xml::typeknowledge) { // Parse the version bool ok; float ver = atts.value(xml::version).toFloat(&ok); if (!ok) typeRuleErrorLoc(QString("Non-numeric version specified: %1") .arg(atts.value(xml::version))); // Print a warning if version is newer than the current one if (ver > xml::currentVer) Console::warnMsg(QString("The rule file \"%1\" has version %2, our " "version is %3.") .arg(ShellUtil::shortFileName(_reader->currFile())) .arg(ver) .arg(xml::currentVer)); } // <rule> else if (name == xml::rule) { _rule = new TypeRule(); _rule->setSrcLine(_locator ? _locator->lineNumber() : -1); } // <filter> else if (name == xml::filter) _filter = new InstanceFilter(); // <action> else if (name == xml::action) { errorIfNull(_rule); TypeRuleAction::ActionType type = TypeRuleAction::strToActionType(attributes[xml::type]); TypeRuleAction* action = 0; switch (type) { case TypeRuleAction::atExpression: action = new ExpressionAction(); break; case TypeRuleAction::atFunction: if (!attributes.contains(xml::file)) { typeRuleErrorLoc(QString("Action type \"%1\" in attribute \"%2\" " "requires the file name to be specified " "in the additional attribute \"%3\" in " "element \"%4\".") .arg(attributes[xml::type]) .arg(xml::type) .arg(xml::file) .arg(name)); } action = new FuncCallScriptAction(); break; case TypeRuleAction::atInlineCode: action = new ProgramScriptAction(); break; default: { typeRuleErrorLoc(QString("Unknown action type '%1', must be one " "of: %2") .arg(attributes[xml::type]) .arg(TypeRuleAction::supportedActionTypes().join(", "))); } } action->setSrcLine(_locator ? _locator->lineNumber() : 0); _rule->setAction(action); } // Clear old data _cdata.clear(); // Push element and attributes onto stack _elems.push(name); _attributes.push(attributes); _children.top().insert(name); _children.push(QSet<QString>()); return true; }
bool XMLConfigurationFileHandler::startElement( const QString & , const QString & name, const QString & , const QXmlAttributes & attributes) { string stringName(toString(name)); XMLCFGLOGINIT; LTRACE << "start element " << stringName; // set the current module name and create its entry if necessary if (stringName == string("module")) { m_moduleName = attributes.value("name").toUtf8().constData(); LTRACE << "XMLConfigurationFileHandler::startElement module name is " << m_moduleName; if ((m_configuration. find(m_moduleName)) == (m_configuration. end())) { m_configuration.insert(make_pair(m_moduleName, ModuleConfigurationStructure(m_moduleName))); } } // set the current group name inside moduleName and creates its entry if necessary else if (stringName == "group") { m_groupName = toString(attributes.value("name")); LTRACE << "group name is " << m_groupName; int32_t indName=attributes.index("name"); // index for the attribute 'name' (not always the first) m_configuration.addGroupNamedForModuleNamed(m_groupName, m_moduleName); for (int32_t i=0;i<attributes.length();i++) { if (i==indName) { // if attribute 'name', ignored (already treated) continue; } string key=toString(attributes.localName(i)); string value=toString(attributes.value(i)); m_configuration.addAttributeForGroupInModule(key,value,m_groupName,m_moduleName); } } // creates a new parameter inside the current module and group else if (stringName == "param") { string key = toString(attributes.value("key")); string value = toString(attributes.value("value")); LTRACE << "param key is " << key; m_configuration.addParamValuePairForModuleAndGroup(key, value, m_moduleName, m_groupName); } else if (stringName == "list") { m_listName = toString(attributes.value("name")); LTRACE << "list name is " << m_listName; m_firstItem=true; m_itemWithAttributes=false; } else if (stringName == "item") { uint32_t nbAtt=attributes.length(); if (m_firstItem) { // decide if list is simple list or list of items with attributes if (nbAtt==1) { LTRACE << "add simple list "<< m_listName; m_configuration.addListNamedForModuleAndGroup(m_listName, m_moduleName, m_groupName); } else { LTRACE << "add list of items with attributes"<< m_listName; m_configuration.addListOfItemsForModuleAndGroup(m_listName, m_moduleName, m_groupName); m_itemWithAttributes=true; } m_firstItem=false; } else if (nbAtt>1 && !m_itemWithAttributes) { // was indeed in list of item with attributes => has to change m_configuration.changeListToListOfItems(m_listName,m_moduleName,m_groupName); m_itemWithAttributes=true; } if (m_itemWithAttributes) { string itemName=toString(attributes.value("value")); ItemWithAttributes item(itemName); for (uint32_t i=1; i<nbAtt; i++) { item.addAttribute(toString(attributes.localName(i)), toString(attributes.value(i))); } m_configuration.addItemInListOfItemsForModuleAndGroup(item, m_listName, m_moduleName, m_groupName); } else { string value = toString(attributes.value("value")); m_configuration.addItemInListNamedForModuleAndGroup(value, m_listName, m_moduleName, m_groupName); } } else if (stringName == "map") { m_mapName = toString(attributes.value("name")); LTRACE << "map name is " << m_mapName; m_firstItem=true; m_itemWithAttributes=false; } else if (stringName == "entry") { LTRACE << "entry in map"; uint32_t nbAtt=attributes.length(); if (m_firstItem) { // decide if map is simple map or map of entries with attributes if (nbAtt==2) { // name+value => simple map LTRACE << "add map list "<< m_mapName.c_str(); m_configuration.addMapNamedForModuleAndGroup(m_mapName,m_moduleName,m_groupName); } else { LTRACE << "add map of items with attributes "<< m_mapName; m_configuration.addMapOfItemsForModuleAndGroup(m_mapName,m_moduleName,m_groupName); m_itemWithAttributes=true; } m_firstItem=false; } else if (nbAtt>2 && !m_itemWithAttributes) { // was indeed in list of item with attributes => has to change m_configuration.changeMapToMapOfItems(m_mapName,m_moduleName,m_groupName); m_itemWithAttributes=true; } if (m_itemWithAttributes) { string key=toString(attributes.value("key")); string value=toString(attributes.value("value")); ItemWithAttributes item(value); for (uint32_t i=1; i<nbAtt; i++) { string attName=toString(attributes.localName(i)); if (attName != "key" && attName != "value") { item.addAttribute(attName, toString(attributes.value(i))); } } m_configuration.addEntryInMapOfItemsForModuleAndGroup(key,item,m_mapName,m_moduleName,m_groupName); } else { string key = toString(attributes.value("key")); string value = toString(attributes.value("value")); m_configuration.addEntryInMapNamedForModuleAndGroup(key,value,m_mapName,m_moduleName,m_groupName); } } return true; }
virtual bool startElement(const QString &namespaceURI, const QString &, const QString &qName, const QXmlAttributes &attrs) { kdDebug(26001) << "SVGFragmentSearcher::startElement, namespaceURI " << namespaceURI << ", qName " << qName << endl; bool parse = m_result; if(!parse) { int pos = attrs.index("id"); if(pos > -1 && attrs.value(pos) == m_id) parse = true; } if(parse) { DOM::Element impl = static_cast<DOM::Document *>(m_doc)->createElementNS(namespaceURI, qName); SVGElementImpl *newElement = SVGDocumentImpl::createElement(qName, impl, m_doc); newElement->setViewportElement(m_doc->rootElement()); if(m_currentNode) m_currentNode->appendChild(*newElement); else m_result = newElement; QXmlAttributes newAttrs; for(int i = 0; i < attrs.count(); i++) { QString name = attrs.localName(i); QString value = attrs.value(i); if(name == "id") { value = "@fragment@" + m_url.prettyURL() + "@" + value; m_idMap[value] = newElement; } else if(name == "href") { value.stripWhiteSpace(); if(value.startsWith("#")) { value.remove(0, 1); // Convert the id to its mangled version. QString id = "@fragment@" + m_url.prettyURL() + "@" + value; if(m_idMap.contains(id)) { // This is a local reference to an element within the fragment. // Just convert the href. value = id; } else { // This is a local reference to an id outside of the fragment. // Change it into an absolute href. value = m_url.prettyURL() + "#" + value; } } } newAttrs.append(attrs.qName(i), attrs.uri(i), attrs.localName(i), value); } newElement->setAttributes(newAttrs); m_currentNode = newElement; } return true; }