示例#1
0
bool TsHandler::startElement( const QString& /* namespaceURI */,
                              const QString& /* localName */,
                              const QString& qName,
                              const QXmlAttributes& atts )
{
    if ( qName == QString("byte") ) {
        for ( int i = 0; i < atts.length(); i++ ) {
            if ( atts.qName(i) == QString("value") ) {
                QString value = atts.value( i );
                int base = 10;
                if ( value.startsWith("x") ) {
                    base = 16;
                    value = value.mid( 1 );
                }
                int n = value.toUInt( 0, base );
                if ( n != 0 )
                    accum += QChar( n );
            }
        }
    } else {
        if ( qName == QString("TS") ) {
            m_language = atts.value(QLatin1String("language"));
        } else if ( qName == QString("context") ) {
            context.truncate( 0 );
            source.truncate( 0 );
            comment.truncate( 0 );
            m_translatorComment.truncate( 0 );
            translations.clear();
            contextIsUtf8 = encodingIsUtf8( atts );
        } else if ( qName == QString("message") ) {
            inMessage = true;
            type = MetaTranslatorMessage::Finished;
            source.truncate( 0 );
            comment.truncate( 0 );
            m_translatorComment.truncate( 0 );
            translations.clear();
            messageIsUtf8 = encodingIsUtf8( atts );
            m_isPlural = atts.value(QLatin1String("numerus")).compare(QLatin1String("yes")) == 0;
        } else if (qName == QString("location") && inMessage) {
            bool bOK;
            int lineNo = atts.value(QString("line")).toInt(&bOK);
            if (!bOK) lineNo = -1;
            m_fileName = atts.value(QString("filename"));
            m_lineNumber = lineNo;
        } else if ( qName == QString("translation") ) {
            for ( int i = 0; i < atts.length(); i++ ) {
                if ( atts.qName(i) == QString("type") ) {
                    if ( atts.value(i) == QString("unfinished") )
                        type = MetaTranslatorMessage::Unfinished;
                    else if ( atts.value(i) == QString("obsolete") )
                        type = MetaTranslatorMessage::Obsolete;
                    else
                        type = MetaTranslatorMessage::Finished;
                }
            }
        }
        accum.truncate( 0 );
    }
    return true;
}
bool StructureParser::startElement( const QString& namespaceURI,
                                    const QString& ,
                                    const QString& qName,
                                    const QXmlAttributes& attributes)
{
    QTreeWidgetItem * element;


    if (!stack.isEmpty())
    {
        QTreeWidgetItem *lastChild = stack.top().firstChild();

        if ( lastChild )
        {
            while ( lastChild->nextSibling() )
                lastChild = lastChild->nextSibling();
        }
        element = new QTreeWidgetItem( stack.top(), lastChild, qName, namespaceURI );
    }
    else
    {
        element = new QTreeWidgetItem( table, qName, namespaceURI );
    }

    stack.push( element );
    element->setOpen( TRUE );
    if ( attributes.length() > 0 ) {
        for ( int i = 0 ; i < attributes.length(); i++ ) {
            new QTreeWidgetItem( element, attributes.qName(i), attributes.uri(i) );
        }
    }
    return TRUE;
}
bool TsHandler::startElement( const QString& /* namespaceURI */, const QString& /* localName */, const QString& qName, const QXmlAttributes& atts )
{
	if ( qName == QString( "byte" ) )
	{
		for ( int i = 0; i < atts.length(); i++ )
		{
			if ( atts.qName( i ) == QString( "value" ) )
			{
				QString value = atts.value( i );
				int base = 10;
				if ( value.startsWith( "x" ) )
				{
					base = 16;
					value = value.mid( 1 );
				}
				int n = value.toUInt( 0, base );
				if ( n != 0 )
					accum += QChar( n );
			}
		}
	}
	else
	{
		if ( qName == QString( "context" ) )
		{
			context.truncate( 0 );
			source.truncate( 0 );
			comment.truncate( 0 );
			translation.truncate( 0 );
			contextIsUtf8 = encodingIsUtf8( atts );
		}
		else if ( qName == QString( "message" ) )
		{
			inMessage = TRUE;
			type = MetaTranslatorMessage::Finished;
			source.truncate( 0 );
			comment.truncate( 0 );
			translation.truncate( 0 );
			messageIsUtf8 = encodingIsUtf8( atts );
		}
		else if ( qName == QString( "translation" ) )
		{
			for ( int i = 0; i < atts.length(); i++ )
			{
				if ( atts.qName( i ) == QString( "type" ) )
				{
					if ( atts.value( i ) == QString( "unfinished" ) )
						type = MetaTranslatorMessage::Unfinished;
					else if ( atts.value( i ) == QString( "obsolete" ) )
						type = MetaTranslatorMessage::Obsolete;
					else
						type = MetaTranslatorMessage::Finished;
				}
			}
		}
		accum.truncate( 0 );
	}
	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;
		}
示例#5
0
bool XMLHandler::startElement(const QString &namespaceURI, const QString & /*localName*/, const QString &qName, const QXmlAttributes &atts)
{
    if(currentNode()->nodeType() == Node::TEXT_NODE)
        exitText();

    DOMString nsURI;
    if(!namespaceURI.isNull())
        nsURI = DOMString(namespaceURI);
    else
        // No namespace declared, default to the no namespace
        nsURI = DOMString("");
    ElementImpl *newElement = m_doc->createElementNS(nsURI, qName);
    if(!newElement)
        return false;
    int i;
    for(i = 0; i < atts.length(); i++)
    {
        int exceptioncode = 0;
        QString uriString = atts.uri(i);
        QString qnString = atts.qName(i);
        fixUpNSURI(uriString, qnString);
        DOMString uri(uriString);
        DOMString qn(qnString);
        DOMString val(atts.value(i));
        newElement->setAttributeNS(uri, qn, val, exceptioncode);
        if(exceptioncode) // exception setting attributes
            return false;
    }

    if(newElement->id() == ID_SCRIPT || newElement->id() == makeId(xhtmlNamespace, ID_SCRIPT))
        static_cast< HTMLScriptElementImpl * >(newElement)->setCreatedByParser(true);

    // this is tricky. in general the node doesn't have to attach to the one it's in. as far
    // as standards go this is wrong, but there's literally thousands of documents where
    // we see <p><ul>...</ul></p>. the following code is there for those cases.
    // when we can't attach to the currently holding us node we try to attach to its parent
    bool attached = false;
    for(NodeImpl *current = currentNode(); current; current = current->parent())
    {
        attached = current->addChild(newElement);
        if(attached)
            break;
    }
    if(attached)
    {
        if(m_view && !newElement->attached() && !m_doc->hasPendingSheets())
            newElement->attach();
        pushNode(newElement);
        return true;
    }
    else
    {
        delete newElement;
        return false;
    }

    // ### DOM spec states: "if there is no markup inside an element's content, the text is contained in a
    // single object implementing the Text interface that is the only child of the element."... do we
    // need to ensure that empty elements always have an empty text child?
}
bool XMLHandler::startElement( const QString& namespaceURI, const QString& /*localName*/, const QString& qName, const QXmlAttributes& atts )
{
    if (m_currentNode->nodeType() == Node::TEXT_NODE)
	exitText();

    ElementImpl *newElement;
    if (namespaceURI.isNull())
	newElement = m_doc->createElement(qName);
    else
	newElement = m_doc->createElementNS(namespaceURI,qName);

    // ### handle exceptions
    int i;
    for (i = 0; i < atts.length(); i++)
	newElement->setAttribute(atts.localName(i),atts.value(i));
    if (m_currentNode->addChild(newElement)) {
	if (m_view)
	    newElement->attach(m_view);
	m_currentNode = newElement;
	return TRUE;
    }
    else {
	delete newElement;
	return FALSE;
    }
}
bool SAXConfigurationHandler::startElement ( const QString & namespaceURI, 
        const QString & localName, const QString & qName, 
        const QXmlAttributes & atts ) {
    int idx = qName.find ( ':' );
    QString prefix = "";
    if ( idx > 0 ) {
        prefix = qName.left ( idx );
    }
    ConfigurationPtr c(new DefaultConfiguration( localName, 
            getLocationString(), namespaceURI, prefix ));

    // if processing the toplevel item simply push it, otherwise link it
    // with the parent
    if( d->configuration.isNull() ) {
        d->configuration = c;
    } else {
        ConfigurationPtr parent = d->elements.top();
        parent->addChild( c );
    }

    // process attributes
    for( int i = 0; i < atts.length(); i ++ ) {
        c->setAttribute( atts.localName( i ), atts.value( i ) );
    }

    // push currently built configuration to the stack
    d->elements.push( c );

    return true;
}
bool TemplateQueryHandler::startElement ( const QString & /*namespaceURI*/, const QString & /*localName*/, const QString & qName, const QXmlAttributes & atts )
{
  //qDebug() << "startElement: " << qName;
  if(!m_inTripleList && (qName.compare("triple_list")==0 ))
    {
      m_inTripleList = true;
      return true;
    }
  if(m_currentTriple)
    {
      if(qName.compare("subject") == 0 )
	{
	  // no need to check for element type, since subject are always URIs (when received)
	  m_component = ESubject;
	}
      else if(qName.compare("predicate") == 0 )
	{
	  // no need to check for element type, since predicates are always URIs 
	  m_component = EPredicate;
	}
      else if(qName.compare("object") == 0 && 
	      (atts.length() == 1) && 
	      (atts.qName(0).compare("type") == 0))
	{
	  //check elementtype for object, bNode is illegal when received.
	  QString attrvalue = atts.value(0);
	  m_component = EObject;
	  if( attrvalue.compare("literal", Qt::CaseInsensitive) == 0) 
	    m_elementType = TripleElement::ElementTypeLiteral;
	  else if (attrvalue.compare("URI", Qt::CaseInsensitive) == 0)
	    m_elementType = TripleElement::ElementTypeURI;
	  else
	    {
	      m_errorString = "Invalid object type: ";
	      m_errorString.append(attrvalue);
	      return false;
	    }
	  m_component = EObject;
	}
      else
	{
	  m_errorString = "Invalid element name for a triple: ";
	  m_errorString.append(qName);
	  return false;
	}
    }
  else
    {
      if(qName.compare("triple") == 0 )
	{
	  m_currentTriple = new Triple();
	}
      else
	{
	  m_errorString = "starting something other than triple element";
	  return false;
	}
    }
  return true;
}
示例#9
0
    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;
    }
示例#10
0
bool LastFMStatusParser::startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &attributes)
{
	if (attributes.length() > 0)
	{
		if (attributes.value(0) == "manual-updates")
		{
			m_found = true;
		}
	}

	return QXmlDefaultHandler::startElement(namespaceURI, localName, qName, attributes);
}
static bool encodingIsUtf8( const QXmlAttributes& atts )
{
    for ( int i = 0; i < atts.length(); i++ ) {
	// utf8="true" is a pre-3.0 syntax
	if ( atts.qName(i) == QString("utf8") ) {
	    return ( atts.value(i) == QString("true") );
	} else if ( atts.qName(i) == QString("encoding") ) {
	    return ( atts.value(i) == QString("UTF-8") );
	}
    }
    return FALSE;
}
示例#12
0
文件: myhandler.cpp 项目: jabouzi/qt
bool MyHandler::startElement( const QString&, /* We have omitted the names of the parameters that we don't use. This prevents the compiler from issuing "unused parameter" warnings. */
                              const QString&, const QString& qName,
                              const QXmlAttributes& atts) {
    QString str = QString("\n%1\\%2").arg(indent).arg(qName);
    cout << str;
    if (atts.length()>0) {
        QString fieldName = atts.qName(0);
        QString fieldValue = atts.value(0);
        cout << QString("(%2=%3)").arg(fieldName).arg(fieldValue);
    }
    cout << "{";
    indent += "    ";
    return TRUE;
}
示例#13
0
/*!
    Start parsing an element called \a qName, which can be be broken up
    into \a namespaceURI and \a localName.  The attribute list is \a atts.
*/
bool QWbXmlToXmlContentHandler::startElement( const QString& , const QString& , const QString& qName, const QXmlAttributes& atts )
{
    if ( d->lastWasTag ) {
        d->result += "\n";
        addIndent();
    }
    ++(d->indent);
    d->result += "<" + qName;
    for( int index = 0; index < atts.length(); ++index ) {
        d->result += " " + atts.qName( index ) + "=\"";
        addQuoted( atts.value( index ) );
        d->result += "\"";
    }
    d->result += ">";
    d->lastWasTag = true;
    return true;
}
示例#14
0
bool PropertyParser::startElement( const QString & /* namespaceUrl */,
    const QString & /* localName */, const QString& elementName,
    const QXmlAttributes& attribute )
{
    // If debugging, print each element and its attributes as encountered.
    m_indent += "    ";
    if ( m_debug )
    {
        std::cout << m_indent << "<" << elementName;
        for ( int id = 0;
              id < attribute.length();
              id++ )
        {
            std::cout << " " << attribute.localName(id) << "=\""
              << attribute.value(id) << "\"";
        }
        std::cout << " >" << std::endl;
    }
    // Skip all elements until <BehavePlus> is found.
    if ( ! m_elements )
    {
        if ( elementName == "BehavePlus" )
        {
            push( elementName );
            return( true );
        }
        trError( "PropertyParser:unknownDocument" );
        return( false );
    }
    // <property> elements
    if ( elementName == "property" )
    {
        push( elementName );
        if ( ! handleProperty( elementName, attribute ) )
        {
            return( false );
        }
    }
    // Ignore all other tags
    else
    {
        trError( "PropertyParser:unknownElement", elementName );
        return( false );
    }
    return( true );
}
示例#15
0
bool XmlParser::startElement( const QString & /* namespaceUri */,
    const QString & /* localName */, const QString& elementName,
    const QXmlAttributes& attribute )
{
    // If debugging, print each element and its attributes as encountered.
    m_indent += "    ";
    if ( m_debug )
    {
        std::cout << m_indent << "<" << elementName;
        for ( int id = 0;
              id < attribute.length();
              id++ )
        {
            std::cout << " " << attribute.localName(id) << "=\""
              << attribute.value(id) << "\"";
        }
        std::cout << " >" << std::endl;
    }
    return( true );
}
bool
MMLContentHandler::startElement(const QString &/*namespaceURI*/,
        const QString & localName, const QString &/*qName*/,
        const QXmlAttributes &atts ) {
    if (debug) qDebug("startElement '%s'", (const char*)localName.toUtf8());
    // the root element must be a 'math' element, it this is absent,
    // we create one
    if (cur == doc && localName != "math") {
        MMLElement *e = doc->createElement("math");
        cur->appendChild(e);
        cur = e;
    }
    bool ok = false;
    MMLElement *e = doc->createElement(domstring(localName));
    if (e) {
        cur->appendChild(e);
        for (int i=0; e->attributesValid() && i<atts.length(); ++i) {
            QString v = atts.value(i).simplified();
            e->setAttribute(atts.localName(i).toUtf8(),
            domstring(v));
        }
        if (e->attributesValid()) {
            cur = e;
            ok = true;
        } else {
            err = qstring(e->errorMsg());
            cur = NULL;
        }
    } else {
        err = qstring(doc->errorMsg());
        qDebug("error: %s", (const char*)err.toUtf8());
        // read failed: clear all
        cur = NULL;
    }
    return ok;
}
bool PlannerParser::startElement( const QString&, const QString&, const QString& qName, const QXmlAttributes& att )
{
    kDebug() << "entering function";
    QString taskName;
    int     taskComplete=0;
    
    // only <task>s within <tasks> are processed
    if (qName == QString::fromLatin1("tasks")) withInTasks=true;
    if ((qName == QString::fromLatin1("task")) && (withInTasks))
    {
        // find out name and percent-complete
        for (int i=0; i<att.length(); i++)
        {
            if (att.qName(i) == QString::fromLatin1("name")) taskName=att.value(i);
            if (att.qName(i)==QString::fromLatin1("percent-complete")) taskComplete=att.value(i).toInt();
        }
    
        // at the moment, task is still the old task or the old father task (if an endElement occurred) or not existing (if the
        // new task is a top-level-task). Make task the parenttask, if existing.
        DesktopList dl;
        if (level++>0)
        {
            parentTask=task;
            task = new Task(taskName, 0, 0, dl, parentTask);
            task->setUid(_taskView->storage()->addTask(task, parentTask));
        }
        else
        {
            task = new Task(taskName, 0, 0, dl, _taskView);
            kDebug() <<"added" << taskName;
            task->setUid(_taskView->storage()->addTask(task, 0));
        }
        task->setPercentComplete(taskComplete, _taskView->storage());
    }
    return true;
}
示例#18
0
bool NotesFileParser::startElement(const QString &, const QString &, const QString &qName, const QXmlAttributes &attr)
{
    if (qName == "config")
    {
        inConfig = true;
    }
    else if (qName == "backup" && inConfig)
    {
        emit backupLoaded(attr.value("save") == "yes" ? true : false, attr.value("location"));
    }
    else if (qName == "notes" && inConfig)
    {
        emit notesShowReminderAtStartUpLoaded(attr.value("showreminder") == "no" ? false : true);
    }
    else if (qName == "security" && inConfig)
    {
        emit securityPasswdLoaded(attr.value("passwd"));
    }
    else if (qName == "entry")
    {
        entryName = attr.value("name");
        entry = new Entry(entryName);
	entry->setDefaultPic(attr.value("defaultpic"));
    }
    else if (qName == "property" && entry)
    {
        PropertyStruct *ps = new PropertyStruct(attr.value("name"),
                                                attr.value("type") == "oneLine" ? PropertyStruct::ONE_LINE : PropertyStruct::MULTI_LINE);
        entry->addProperty(ps);
    }
    else if (qName == "note")
    {
        QList<QString> *data = new QList<QString>;
        Strokes *strokes = new Strokes;
        QString en, n, per, day, month, year, hour, min, pic = "",
            rday, rmonth, ryear, rhour, rmin;
        int startIdx = 2, prio = 0;
        QDateTime dt, rem;

        n = attr.value("name");
        per = attr.value("percentage");

        // It's task
        if (per.length())
        {
            prio = attr.value("priority").toInt();
            startIdx += 2;
        }

        day = attr.value("day");
        // It's event
        if (day.length())
        {
            month = attr.value("month");
            year = attr.value("year");
            startIdx += 3;

            dt.setDate(QDate(year.toInt(), month.toInt(), day.toInt()));

            hour = attr.value("hour");
            if (hour.length())
            {
                min = attr.value("min");
                startIdx += 2;

                dt.setTime(QTime(hour.toInt(), min.toInt()));
            }
            else
                dt.setTime(QTime(25, 61));

        }
        
        rday = attr.value("rday");
        // has reminder
        if (rday.length())
        {
            rmonth = attr.value("rmonth");
            ryear = attr.value("ryear");
            startIdx += 3;

            rem.setDate(QDate(ryear.toInt(), rmonth.toInt(), rday.toInt()));

            rhour = attr.value("rhour");
            if (rhour.length())
            {
                rmin = attr.value("rmin");
                startIdx += 2;

                rem.setTime(QTime(rhour.toInt(), rmin.toInt()));
            }
            else
                rem.setTime(QTime(25, 61));

        }

        // Has pic
        pic = attr.value("pic");
        if (pic.length())
        {
            startIdx += 1;
        }

        // Text note
        if ((en = attr.value("type")) == "Text")
        {
            delete strokes;

            en = "";
            data->append(new QString(attr.value("data0")));

            emit noteLoaded(n, data, en, per, prio, dt, pic, rem);
        }
        // Sketch note
        else if (en == "Sketch")
        {
            delete data;

            for (int i = startIdx; i < attr.length(); i++)
            {
                strokes->addStroke(attr.value(i));
            }

            emit noteLoaded(n, strokes, en, per, prio, dt, pic, rem);
        }
        // Defined note
        else
        {
            delete strokes;

            for (int i = startIdx; i < attr.length(); i++)
            {
                data->append(new QString(attr.value(i)));
            }

            emit noteLoaded(n, data, en, per, prio, dt, pic, rem);
        }
    }

    return true;
}
示例#19
0
void QWbXmlReader::parseElementBody()
{
    QString name;
    QXmlAttributes attrs;
    bool hasAttrs;
    bool hasContent;

    while ( d->tokenType != QWbXmlToken_EOF) {
        switch ( d->tokenType ) {

            case QWbXmlToken_Tag:
            {
                name = d->tokenValue;
                hasAttrs = !d->tagMode;
                hasContent = d->hasContent;
                nextToken();
                attrs.clear();
                if ( hasAttrs )
                    parseAttributes( attrs );
                d->contentHandler->startElement
                    ( QString(), name, name, attrs );
                if ( hasContent )
                    parseElementBody();
                d->contentHandler->endElement( QString(), name, name );
            }
            break;

            case QWbXmlToken_EndTag:
            {
                nextToken();
                return;
            }
            // Not reached.

            case QWbXmlToken_PI:
            {
                nextToken();
                attrs.clear();
                parseAttributes( attrs );
                if ( attrs.length() > 0 ) {
                    d->contentHandler->processingInstruction
                        ( attrs.localName(0), attrs.value(0) );
                }
            }
            break;

            case QWbXmlToken_String:
            {
                d->contentHandler->characters( d->tokenValue );
                nextToken();
            }
            break;

            default:
            {
                nextToken();
            }
            break;
        }
    }
}
示例#20
0
bool MappingsHandler::startElement(const QString& /* namespaceURI */,
	const QString& localName,
	const QString& /* qName */,
	const QXmlAttributes& attr)
{
	if(localName == "define"){
		/* 変数初期化 */
		m_code = 0;
		m_mask = 0;
		m_mapcode = 0;
		m_unicode = 0;
		m_mapmodifiers.clear();
		m_mapunicodes.clear();
		for(int i=0; i<attr.length(); i++){
			if(attr.localName(i).lower() == "key"){
				/* keyname */
				m_code = KeyNames::getCode(attr.value(i));
			} else if(attr.localName(i).lower() == "code"){
				/* keycode */
				m_code = KHUtil::hex2int(attr.value(i).lower());
			}
		}
	} else if(localName == "modifier"){
		/* modifier keys */
		for(int i=0; i<attr.length(); i++){
			if(attr.value(i).lower() == "on"){
				m_mask |= m_pModifiers->getMask(attr.localName(i));
			}
		}
	} else if(localName == "map"){
		/* mapping key */
		for(int i=0; i<attr.length(); i++){
			if(attr.localName(i).lower() == "key"){
				/* keyname */
				m_mapcode = KeyNames::getCode(attr.value(i));
			} else if(attr.localName(i).lower() == "code"){
				/* keycode */
				m_mapcode = KHUtil::hex2int(attr.value(i).lower());
			}
		}
	} else if(localName == "map_modifier"){
		/* mapping modifiers */
		for(int i=0; i<attr.length(); i++){
			m_mapmodifiers[attr.localName(i)] = attr.value(i);
		}
	} else if(localName == "map_unicode"){
		/* mapping unicodes */
		for(int i=0; i<attr.length(); i++){
			if(attr.localName(i).lower() == "char"){
				/* unicode char */
				m_unicode = attr.value(i)[0].unicode();
			} else if(attr.localName(i).lower() == "code"){
				/* unicode code */
				m_unicode = KHUtil::hex2int(attr.value(i).lower());
			} else {
				m_mapunicodes[attr.localName(i)] = attr.value(i);
			}
		}
	}
	return(true);
}
示例#21
0
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;
}