Пример #1
0
void StyleReader::tabStop(const QXmlAttributes& attrs)
{
	if (currentStyle->target() == "paragraph")
	{
		gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(currentStyle);
		assert(pstyle != NULL);
		QString pos = NULL;
		QString type = NULL;
		for (int i = 0; i < attrs.count(); ++i)
		{
			if (attrs.localName(i) == "style:position")
				pos = attrs.value(i);
			else if (attrs.localName(i) == "style:type")
				type = attrs.value(i);
				
		}
		if (!pos.isNull())
		{
			if (type.isNull())
				type = "left";
			double posd = getSize(pos);
			if (type == "left")
				pstyle->setTabValue(posd, LEFT_T);
			else if (type == "right")
				pstyle->setTabValue(posd, RIGHT_T);
			else if (type == "center")
				pstyle->setTabValue(posd, CENTER_T);
			else
				pstyle->setTabValue(posd, CENTER_T);
		}
	}
}
Пример #2
0
bool KEYBMAPParser::startElement( const QString&, const QString&, const QString &name, const QXmlAttributes &attrs )
{
    QString desc = "";
    QString modifier="";
    int scancode,masterscancode,delay,x,y,w,h;
    View view=FRONTview;
    bool ok = false;

    scancode=masterscancode=delay=x=y=w=h=0;

    if( inKeyboard && name == "KEY" )
    {

        for( int i=0; i<attrs.count(); i++ )
        {
            if( attrs.localName( i ) == "description" )
                desc = attrs.value( i );
            else if( attrs.localName( i ) == "scancode" )
                scancode = attrs.value( i ).toInt(&ok,16);
            else if( attrs.localName( i ) == "left" )
                x = attrs.value( i ).toInt(&ok,10);
            else if( attrs.localName( i ) == "top" )
                y = attrs.value( i ).toInt(&ok,10);
            else if( attrs.localName( i ) == "width" )
                w = attrs.value( i ).toInt(&ok,10);
            else if( attrs.localName( i ) == "height" )
                h = attrs.value( i ).toInt(&ok,10);
            else if( attrs.localName( i ) == "masterscancode" )
                masterscancode = attrs.value( i ).toInt(&ok,16);
            else if( attrs.localName( i ) == "delay" ) {
                delay = attrs.value( i ).toInt(&ok,10);
                qWarning()<<"delay="<<delay;
            }
            else if( attrs.localName( i ) == "modifier" )
                modifier = attrs.value( i );
            else if( attrs.localName( i ) == "view" ) {
                if (attrs.value( i ) == "FRONT") view = FRONTview;
                if (attrs.value( i ) == "TOP") view = TOPview;
                if (attrs.value( i ) == "LEFT") view = LEFTview;
                if (attrs.value( i ) == "RIGHT") view = RIGHTview;
                if (attrs.value( i ) == "BACK") view = BACKview;
                if (attrs.value( i ) == "BOTTOM") view = BOTTOMview;
            }
        }
        Parent->Keys.append(CKey(scancode,desc,QRect(x,y,w,h),masterscancode,modifier,view,delay));
        AddLog(LOG_KEYBOARD,mainwindow->tr("XML Read key : %1, scan=0x%2 , Rect=(%3,%4,%5,%6), mscan=0x%7, mod=%8").
               arg(desc).
               arg(scancode,2,16,QChar('0')).
               arg(x).arg(y).arg(w).arg(h).
               arg(masterscancode,2,16,QChar('0')).
               arg(modifier));
    }
    else if( name == "Keyboard" )
        inKeyboard = true;

    return true;
}
Пример #3
0
		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 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;
    }
}
Пример #5
0
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;
}
Пример #6
0
bool ConfigHandler::startElement( const QString &, const QString &, const QString &name, const QXmlAttributes &attrs )
{
  if (inConf && name == "tab") {
    for(int i = 0; i < attrs.count(); i++) {
      if (attrs.localName(i) == "name")
        tName = attrs.value(i);
      else if (attrs.localName(i) == "dir")
        tDir = attrs.value(i);
      else if (attrs.localName(i) == "command")
        tCommand = attrs.value(i);
    }
  }
  else if ( name == "krails" ) {
    inConf = true;
  }

  return true;
}
Пример #7
0
QString FbXmlHandler::NodeHandler::Value(const QXmlAttributes &attributes, const QString &name)
{
    int count = attributes.count();
    for (int i = 0; i < count; ++i ) {
        if (attributes.localName(i).compare(name, Qt::CaseInsensitive) == 0) {
            return attributes.value(i);
        }
    }
    return QString();
}
Пример #8
0
QString ContentHandler::formatAttributes(const QXmlAttributes &atts)
{
    QString result;
    for (int i = 0, cnt = atts.count(); i < cnt; ++i) {
	if (i != 0) result += ", ";
	result += "{localName=\"" + escapeStr(atts.localName(i))
		    + "\", qName=\"" + escapeStr(atts.qName(i))
		    + "\", uri=\"" + escapeStr(atts.uri(i))
		    + "\", type=\"" + escapeStr(atts.type(i))
		    + "\", value=\"" + escapeStr(atts.value(i)) + "\"}";
    }
    return result;
}
Пример #9
0
bool nftrcreader::startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs) 
{
	if (name == "name")
		inName = true;
	else if (name == "file")
		inFile = true;
	else if (name == "tnail")
		inTNail = true;
	else if (name == "img")
		inImg = true;
	else if (name == "psize")
		inPSize = true;
	else if (name == "color") 
		inColor = true;
	else if (name == "descr")
		inDescr = true;
	else if (name == "usage")
		inUsage = true;
	else if (name == "scribus_version")
		inScribusVersion = true;
	else if (name == "date")
		inDate = true;
	else if (name == "author")
		inAuthor = true;
	else if (name == "email")
		inEmail = true;


	if (name == "template") { // new template starts here
		inTemplate = true;
		QString category;
		QString enCat;
		for (int i = 0; i < attrs.count(); i++)
		{
			if (attrs.localName(i) == "category")
			{
				category = getCategory(attrs.value(i));
				enCat = attrs.value(i);
			}
		}
		tmpTemplate = new nfttemplate(new QFile(currentFile), category); // create a new template
		tmpTemplate->enCategory = enCat;
	}

	if (name == "settings") 
		inSettings = true;

	return true;
}
Пример #10
0
void StyleReader::defaultStyle(const QXmlAttributes& attrs)
{
	currentStyle = NULL;
	for (int i = 0; i < attrs.count(); ++i)
		if (attrs.localName(i) == "style:family")
			if (attrs.value(i) == "paragraph")
			{
				gtParagraphStyle* pstyle = new gtParagraphStyle(*(writer->getDefaultStyle()));
				pstyle->setDefaultStyle(true);
				currentStyle = dynamic_cast<gtStyle*>(pstyle);
				currentStyle->setName("default-style");
				readProperties = true;
				defaultStyleCreated = true;
			}
}
Пример #11
0
bool MetaBundle::XmlLoader::startElement( const QString &, const QString &localName, const QString &, const QXmlAttributes &atts )
{
    if( localName == "item" )
    {
        m_bundle.clear();
        m_attributes.clear();
        for( int i = 0, n = atts.count(); i < n; ++i )
            newAttribute( atts.localName( i ), atts.value( i ) );

        m_currentElement = QString::null;
    }
    else
        m_currentElement = localName;

    return true;
}
Пример #12
0
void cElement::copyAttributes( const QXmlAttributes& attributes )
{
	freeAttributes();
	attrCount_ = attributes.count();

	if ( attrCount_ > 0 )
	{
		this->attributes = new stAttribute * [attrCount_];

		for ( unsigned int i = 0; i < attrCount_; ++i )
		{
			this->attributes[i] = new stAttribute;
			this->attributes[i]->name = attributes.localName( i );
			this->attributes[i]->value = attributes.value( i );
		}
	}
}
Пример #13
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 );
}
Пример #14
0
void FbReadHandler::TextHandler::Init(const QString &name, const QXmlAttributes &atts)
{
    Keyword key = toKeyword(name);
    writer().writeStartElement(m_tag);
    int count = atts.count();
    for (int i = 0; i < count; i++) {
        QString name = atts.qName(i);
        switch (key) {
            case Anchor: { if (atts.localName(i) == "href") name = "href"; break; }
            case Image:  { if (atts.localName(i) == "href") name = "src"; break; }
            default: ;
        }
        writer().writeAttribute(name, atts.value(i));
    }
    if (name == "empty-line") {
        writer().writeEmptyElement("br");
        m_empty = false;
    }
}
Пример #15
0
bool TrackReader::startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts)
{
    Q_UNUSED(qName)

    const QString eName  = myQName(namespaceURI, localName);
    d->currentElements << eName;
    rebuildElementPath();
    const QString& ePath = d->currentElementPath;

    if (ePath == QString::fromLatin1("gpx:gpx/gpx:trk/gpx:trkseg/gpx:trkpt"))
    {
        qreal lat    = 0.0;
        qreal lon    = 0.0;
        bool haveLat = false;
        bool haveLon = false;

        for (int i = 0; i < atts.count(); ++i)
        {
            const QString attName  = myQName(atts.uri(i), atts.localName(i));
            const QString attValue = atts.value(i);

            if (attName == QString::fromLatin1("lat"))
            {
                lat = attValue.toDouble(&haveLat);
            }
            else if (attName == QString::fromLatin1("lon"))
            {
                lon = attValue.toDouble(&haveLon);
            }
        }

        if (haveLat&&haveLon)
        {
            d->currentDataPoint.coordinates.setLatLon(lat, lon);
        }
    }
    else if (ePath == QString::fromLatin1("gpx:gpx"))
    {
        d->verifyFoundGPXElement = true;
    }

    return true;
}
Пример #16
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 );
}
Пример #17
0
bool W2parser::startElement(const QString &,
                            const QString &,
                            const QString &qName,
                            const QXmlAttributes &atts)
{
    if (qName.compare("item") == 0)
        line.clear();
    else if (qName.compare("ingredients_list") == 0)
        ingredients.clear();

    QString key;
    QString value;
    for (int i = 0; i < atts.count(); ++i) {
        key = atts.localName(i);
        value = atts.value(i);
        if (key.compare("name") == 0)
            line.append(value + ",");
        else if (key.compare("crafted_item") == 0)
            line.append(value + ",");
    }

    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;
}
Пример #19
0
void StyleReader::styleProperties(const QXmlAttributes& attrs)
{
	if ((currentStyle == NULL) || (!readProperties))
		return;
	gtParagraphStyle* pstyle = NULL;
	if (currentStyle->target() == "paragraph")
		pstyle = dynamic_cast<gtParagraphStyle*>(currentStyle);
	else
		pstyle = NULL;
	QString align = NULL;
	QString force = NULL;
	bool hasColorTag = false;
	for (int i = 0; i < attrs.count(); ++i)
	{
		if ((attrs.localName(i) == "style:font-name") && (!inList))
			currentStyle->getFont()->setName(getFont(attrs.value(i)));
		else if (attrs.localName(i) == "fo:font-size")
		{
			double size = 0;
			double psize = 0;
			if (parentStyle != NULL)
				psize = static_cast<double>(parentStyle->getFont()->getSize());
			else if (styles.contains("default-style"))
				psize = static_cast<double>(styles["default-style"]->getFont()->getSize());

			psize = psize / 10;
			size = getSize(attrs.value(i), psize);
			int nsize = static_cast<int>(size * 10);
			currentStyle->getFont()->setSize(nsize);
			if (pstyle)
				pstyle->setLineSpacing(writer->getPreferredLineSpacing(nsize));
		}
		else if ((attrs.localName(i) == "fo:line-height") && (parentStyle != NULL))
		{
			gtParagraphStyle* ppstyle;
			if (parentStyle->target() == "paragraph")
			{
				ppstyle = dynamic_cast<gtParagraphStyle*>(parentStyle);
				assert(ppstyle != NULL);
				ppstyle->setLineSpacing(getSize(attrs.value(i), writer->getPreferredLineSpacing(currentStyle->getFont()->getSize())));
			}
		}
		else if (attrs.localName(i) == "fo:color")
		{
			currentStyle->getFont()->setColor(attrs.value(i));
			hasColorTag = true;
		}
		else if ((attrs.localName(i) == "style:use-window-font-color") && (attrs.value(i) == "true"))
		{
			currentStyle->getFont()->setColor("Black");
			hasColorTag = true;
		}
		else if ((attrs.localName(i) == "fo:font-weight") && (attrs.value(i) == "bold"))
			currentStyle->getFont()->setWeight(BOLD);
		else if ((attrs.localName(i) == "fo:font-style") && (attrs.value(i) == "italic"))
			currentStyle->getFont()->setSlant(ITALIC);
		else if ((attrs.localName(i) == "style:text-underline-style") && (attrs.value(i) != "none"))
			currentStyle->getFont()->toggleEffect(UNDERLINE);
		else if ((attrs.localName(i) == "style:text-crossing-out") && (attrs.value(i) != "none"))
			currentStyle->getFont()->toggleEffect(STRIKETHROUGH);
		else if ((attrs.localName(i) == "fo:font-variant") && (attrs.value(i) == "small-caps"))
			currentStyle->getFont()->toggleEffect(SMALL_CAPS);
		else if ((attrs.localName(i) == "style:text-outline") && (attrs.value(i) == "true"))
		{
			currentStyle->getFont()->toggleEffect(OUTLINE);
			currentStyle->getFont()->setStrokeColor("Black");
			currentStyle->getFont()->setColor("White");
		}
		else if (attrs.localName(i) == "fo:letter-spacing")
			currentStyle->getFont()->setKerning(static_cast<int>(getSize(attrs.value(i), -1.0)));
		else if (attrs.localName(i) == "style:text-scale")
			currentStyle->getFont()->setHscale(static_cast<int>(getSize(attrs.value(i), -1.0)));
		else if ((attrs.localName(i) == "style:text-position") && 
				(((attrs.value(i)).indexOf("sub") != -1) || 
				(((attrs.value(i)).left(1) == "-") && ((attrs.value(i)).left(1) != "0"))))
			currentStyle->getFont()->toggleEffect(SUBSCRIPT);
		else if ((attrs.localName(i) == "style:text-position") && 
				(((attrs.value(i)).indexOf("super") != -1) || 
				(((attrs.value(i)).left(1) != "-") && ((attrs.value(i)).left(1) != "0"))))
			currentStyle->getFont()->toggleEffect(SUPERSCRIPT);
		else if ((attrs.localName(i) == "fo:margin-top") && (pstyle != NULL))
			pstyle->setSpaceAbove(getSize(attrs.value(i)));
		else if ((attrs.localName(i) == "fo:margin-bottom") && (pstyle != NULL))
			pstyle->setSpaceBelow(getSize(attrs.value(i)));
		else if ((attrs.localName(i) == "fo:margin-left") && (pstyle != NULL))
		{
			if (inList)
				pstyle->setIndent(pstyle->getIndent() + getSize(attrs.value(i)));
			else
				pstyle->setIndent(getSize(attrs.value(i)));	
		}
		else if ((attrs.localName(i) == "text:space-before") && (pstyle != NULL))
		{
			/*if (inList)
				pstyle->setIndent(pstyle->getIndent() + getSize(attrs.value(i)));
			else*/
				pstyle->setIndent(getSize(attrs.value(i)));
		}
		else if ((attrs.localName(i) == "fo:text-indent") && (pstyle != NULL))
			pstyle->setFirstLineIndent(getSize(attrs.value(i)));
		else if ((attrs.localName(i) == "fo:text-align") && (pstyle != NULL))
			align = attrs.value(i);
		else if ((attrs.localName(i) == "style:justify-single-word") && (pstyle != NULL))
			force = attrs.value(i);
	}
	// Qt4 NULL -> isNull()
	if (!align.isNull())
	{
		if (align == "end")
			pstyle->setAlignment(RIGHT);
		else if (align == "center")
			pstyle->setAlignment(CENTER);
		else if (align == "justify")
		{
			if (force == "false")
				pstyle->setAlignment(BLOCK);
			else
				pstyle->setAlignment(FORCED);
		}
	}
	if (!hasColorTag)
		currentStyle->getFont()->setColor("Black");
}
Пример #20
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;
        }
    }
}
Пример #21
0
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;
}
Пример #22
0
bool KalkatiParser::startElement(const QString &uri,const QString &local,const QString &name,const QXmlAttributes &attrs) {
	signed int i,l;

	if(isSynonym) {
		return(true);
	}

	if(name=="jp_database") {
	} else if(name=="Delivery") {
	} else if(name=="Language") {
	} else if(name=="Company") {
		QString sql;
		QSqlQuery query(db);
		unsigned int compid;
		QSqlField nameField;

		l=attrs.count();
		for(i=0;i<l;i++) {
			if(attrs.localName(i)=="CompanyId") compid=attrs.value(i).toInt();
			if(attrs.localName(i)=="Name") nameField.setValue(attrs.value(i));
		}

		QTextStream str(&sql);
		str << "INSERT INTO company (compid,name) VALUES (" << compid << ",";
		str << "'" << driver->formatValue(nameField,true) << "');";

		query.exec(sql);
	} else if(name=="Country") {
	} else if(name=="Timezone") {
	} else if(name=="Period") {

	} else if(name=="Station") {
		QString sql;
		QSqlQuery query(db);
		unsigned int statid,virt,type,cityid;
		QSqlField statname;
		unsigned int lat,lon;

		l=attrs.count();
		for(i=0;i<l;i++) {
			if(attrs.localName(i)=="StationId") statid=attrs.value(i).toInt();
			if(attrs.localName(i)=="Name") statname.setValue(attrs.value(i));
			if(attrs.localName(i)=="X") {
				lon=(attrs.value(i).toDouble()+180)*1000000+0.5;
				lon-=180*1000000;
			}
			if(attrs.localName(i)=="Y") {
				lat=(attrs.value(i).toDouble()+90)*1000000+0.5;
				lat-=90*1000000;
			}
			if(attrs.localName(i)=="isVirtual") virt=attrs.value(i).toInt();
			if(attrs.localName(i)=="Type") type=attrs.value(i).toInt();
			if(attrs.localName(i)=="city_id") cityid=attrs.value(i).toInt();
		}

		QTextStream str(&sql);
		str << "INSERT INTO station (statid,name,lat,lon,virt,type,cityid) VALUES (" << statid << ",";
		str << "'" << driver->formatValue(statname,true) << "',";
		str << lat << "," << lon << "," << virt << "," << type << ",";
		str << cityid << ");";

		query.exec(sql);

	} else if(name=="Trnsmode") {

	} else if(name=="Synonym") {
		isSynonym=true;

	} else if(name=="Footnote") {
		unsigned int y,m,d;
		unsigned int footid;
		signed int offset,days;
		QStringList dateParts;
		QDate firstDate;
		QString bits,bitsOut;

		l=attrs.count();
		for(i=0;i<l;i++) {
			if(attrs.localName(i)=="FootnoteId") footid=attrs.value(i).toInt();
			if(attrs.localName(i)=="Firstdate") {
				dateParts=attrs.value(i).split(QChar('-'));
				y=dateParts.at(0).toInt();
				m=dateParts.at(1).toInt();
				d=dateParts.at(2).toInt();
				firstDate=QDate(y,m,d);
			}

			if(attrs.localName(i)=="Vector") {
				bits=attrs.value(i);
				days=bits.length();
			}
		}

		offset=startDate.daysTo(firstDate);

		if(offset<=dayCount && offset+days>0) {
			bitsOut=blankBits;
			for(i=0;i<dayCount;i++) {
				if(i-offset>=0 && i-offset<days) {
					bitsOut[i]=bits[i-offset];
				}
			}
			if(bitsOut!=blankBits) {
				valid.insert(footid,bitsOut);
				qDebug() << footid << bitsOut << firstDate << days;
			}
		}

	} else if(name=="Timetbls") {

	} else if(name=="Service") {
		l=attrs.count();
		for(i=0;i<l;i++) {
			if(attrs.localName(i)=="ServiceId") servId=attrs.value(i).toInt();
		}
		servData.clear();
		servFirst=-1;
		servValid=-1;
	} else if(name=="ServiceNbr") {
		l=attrs.count();
		for(i=0;i<l;i++) {
			if(attrs.localName(i)=="CompanyId") servComp=attrs.value(i).toInt();
			if(attrs.localName(i)=="ServiceNbr") servLong=attrs.value(i);
			if(attrs.localName(i)=="Variant") servShort=attrs.value(i);
			if(attrs.localName(i)=="Name") servName=attrs.value(i);
		}
	} else if(name=="ServiceValidity") {
		l=attrs.count();
		for(i=0;i<l;i++) {
			if(attrs.localName(i)=="FootnoteId") {
				servValid=attrs.value(i).toInt();
				if(!valid.contains(servValid)) servValid=-1;
			}
		}
	} else if(name=="ServiceTrnsmode") {
		l=attrs.count();
		for(i=0;i<l;i++) {
			if(attrs.localName(i)=="TrnsmodeId") servMode=attrs.value(i).toInt();
		}
	} else if(name=="Stop") {
		if(servValid<0) return(true);

		QString id,t;

		l=attrs.count();
		for(i=0;i<l;i++) {
			if(attrs.localName(i)=="StationId") id=attrs.value(i);
			if(attrs.localName(i)=="Arrival") t=attrs.value(i);
		}
		if(servFirst<0) servFirst=t.toInt();
		servData.append(id);
		servData.append(t);
	} else {
		qDebug() << name;
	}

	return(true);
}
Пример #23
0
	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;
	}
Пример #24
0
void StyleReader::styleStyle(const QXmlAttributes& attrs)
{
	QString name = "";
	QString listName = NULL;
	bool setDefaultStyle = false;
	bool isParaStyle = false;
	bool create = true;

	if (!defaultStyleCreated)
	{
		gtParagraphStyle* pstyle = new gtParagraphStyle(*(writer->getDefaultStyle()));
		pstyle->setDefaultStyle(true);
		currentStyle = dynamic_cast<gtStyle*>(pstyle);
		currentStyle->setName("default-style");
		setDefaultStyle     = true;
		defaultStyleCreated = true;
		parentStyle  = currentStyle;
	}

	for (int i = 0; i < attrs.count(); ++i)
	{
		if (attrs.localName(i) == "style:family")
		{
			if (attrs.value(i) == "paragraph")
			{
				isParaStyle = true;
				readProperties = true;
			}
			else if (attrs.value(i) == "text")
			{
				isParaStyle = false;
				readProperties = true;
			}
			else
			{
				readProperties = false;
				return;
			}
		}
		else if (attrs.localName(i) == "style:name")
			name = attrs.value(i);
		else if (attrs.localName(i) == "style:parent-style-name")
		{
			if (styles.contains(attrs.value(i)))
				parentStyle = styles[attrs.value(i)];
			else
				parentStyle = NULL;
		}
		else if (attrs.localName(i) == "style:list-style-name")
			listName = attrs.value(i);
	}
	if ((parentStyle == NULL) && (styles.contains("default-style")))
		parentStyle = styles["default-style"];

	if (create)
	{
		if (parentStyle == NULL)
		{
			parentStyle = new gtStyle("tmp-parent");
		}
		if (isParaStyle)
		{
			gtParagraphStyle *tmpP;
			if (parentStyle->target() == "paragraph")
			{
				tmpP = dynamic_cast<gtParagraphStyle*>(parentStyle);
				assert(tmpP != NULL);
				gtParagraphStyle* tmp = new gtParagraphStyle(*tmpP);
	// 				tmp->setAutoLineSpacing(true);
				currentStyle = tmp;
			}
			else
			{
				gtParagraphStyle* tmp = new gtParagraphStyle(*parentStyle);
	// 				tmp->setAutoLineSpacing(true);
				currentStyle = tmp;
			}
			if (!listName.isNull())
			{
				listParents[listName] = currentStyle;
			}
		}
		else
			currentStyle = new gtStyle(*parentStyle);

		currentStyle->setName(name);
		if (setDefaultStyle)
		{
			gtParagraphStyle* tmp = dynamic_cast<gtParagraphStyle*>(currentStyle);
			if (tmp)
				tmp->setDefaultStyle(true);
		}
	}
	else
		currentStyle = NULL;
}
Пример #25
0
bool ContentReader::startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs) 
{
	if ((name == "text:p") || (name == "text:h"))
	{
		++append;
		QString name = "";
		for (int i = 0; i < attrs.count(); ++i)
		{
			if (attrs.localName(i) == "text:style-name")
			{
				name = attrs.value(i);
				styleNames.push_back(attrs.value(i));
			}
		}
		if (!inList)
		{
			pstyle = sreader->getStyle(name);
			currentStyle = pstyle;
		}
		else
		{
			gtStyle *tmp = sreader->getStyle(getName());
			if ((tmp->getName()).indexOf("default-style") != -1)
				getStyle();
			else
				currentStyle = tmp;
		}
	}
	else if (name == "text:span")
	{
		inSpan = true;
		QString styleName = "";
		for (int i = 0; i < attrs.count(); ++i)
		{
			if (attrs.localName(i) == "text:style-name")
			{
				currentStyle = sreader->getStyle(attrs.value(i));
				styleName = attrs.value(i);
				styleNames.push_back(styleName);
			}
		}
		gtStyle *tmp = sreader->getStyle(getName());
		if ((tmp->getName()).indexOf("default-style") != -1)
			getStyle();
		else
			currentStyle = tmp;
	}
	else if ((name == "text:unordered-list") || (name == "text:ordered-list"))
	{
		inList = true;
		++listLevel;
		if (static_cast<int>(listIndex2.size()) < listLevel)
			listIndex2.push_back(0);
		for (int i = 0; i < attrs.count(); ++i)
		{
			if (attrs.localName(i) == "text:style-name")
				currentList = attrs.value(i);
		}
		currentStyle = sreader->getStyle(QString(currentList + "_%1").arg(listLevel));
		styleNames.clear();
		styleNames.push_back(QString(currentList + "_%1").arg(listLevel));
		if (name == "text:ordered-list")
		{
			isOrdered = true;
			isOrdered2.push_back(true);
		}
		else
		{
			isOrdered = false;
			isOrdered2.push_back(false);
		}
	}
	else if (name == "text:list-item")
	{
		if (isOrdered2[listLevel - 1])
		{
			++listIndex;
			++listIndex2[listLevel - 1];
			if (listLevel == 1)
				write(QString("%1. ").arg(listIndex2[listLevel - 1]));
			else
				write(QString("%1. ").arg(listIndex2[listLevel - 1]));
		}
		else
			write("- ");
	}
	else if (name == "text:note")
		inNote = true;
	else if (name == "text:note-body")
		inNoteBody = true;
	else if (name == "style:style")
	{
		QString sname = "";
		bool isTextStyle = false;
		for (int i = 0; i < attrs.count(); ++i)
		{
			if (attrs.localName(i) == "style:name")
				sname = attrs.value(i);
			else if ((attrs.localName(i) == "style:family") && (attrs.value(i) == "text"))
				isTextStyle = true;
		}
		if (isTextStyle)
		{
			tName = sname;
			inT = true;
		}
	}
	else if ((name == "style:properties") && (inT))
	{
		Properties p;
		for (int i = 0; i < attrs.count(); ++i)
		{
			std::pair<QString, QString> pair(attrs.localName(i), attrs.value(i));
			p.push_back(pair);
		}
		tmap[tName] = p;
	}
	else if (name == "text:s")
	{
		int count = 1;
		for (int i = 0; i < attrs.count(); ++i)
		{
			if (attrs.localName(i) == "text:c")
			{
				bool ok = false;
				int tmpcount = (attrs.value(i)).toInt(&ok);
				if (ok)
					count = tmpcount;
			}
		}
		for (int i = 0; i < count; ++i)
			write(" ");
	}
	return true;
}
Пример #26
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);
}
Пример #27
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;
}
Пример #28
0
bool StyleReader::startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs) 
{
	if (name == "style:default-style")
		defaultStyle(attrs);
	else if (name == "style:paragraph-properties" ||
	         name == "style:text-properties" || 
	         name == "style:list-level-properties")
		styleProperties(attrs);
	else if (name == "style:style")
		styleStyle(attrs);
	else if (name == "style:tab-stop")
		tabStop(attrs);
	else if (name == "text:list-style")
	{
		for (int i = 0; i < attrs.count(); ++i)
			if (attrs.localName(i) == "style:name")
				currentList = attrs.value(i);
		currentListStyle = new ListStyle(currentList);
		inList = true;
	}
	else if (((name == "text:list-level-style-bullet") ||
	          (name == "text:list-level-style-number") ||
	          (name == "text:list-level-style-image")) && (inList))
	{
		BulletType bstyle = Bullet;
		QString prefix = "";
		QString suffix = "";
		QString bullet = "-";
		uint ulevel = 0;
		uint displayLevels = 1;
		uint startAt = 0;
		QString level = "";
		for (int i = 0; i < attrs.count(); ++i)
		{
			if (attrs.localName(i) == "text:level")
			{
				ulevel = QString(attrs.value(i)).toUInt();
				gtStyle *plist;
				if (attrs.value(i) == "1")
				{
					plist = listParents[currentList];
				}
				else
				{
					int level = (attrs.value(i)).toInt();
					--level;
					plist = styles[QString(currentList + "_%1").arg(level)]; 
				}
				gtParagraphStyle *pstyle;
				if (plist == NULL)
				{
					if (styles.contains("default-style"))
						plist = new gtStyle(*(styles["default-style"]));
					else
					{
						gtParagraphStyle* pstyle = new gtParagraphStyle(*(writer->getDefaultStyle()));
						pstyle->setDefaultStyle(true);
						plist = dynamic_cast<gtStyle*>(pstyle);
					}
				}

				if (plist->target() == "paragraph")
				{
					pstyle = dynamic_cast<gtParagraphStyle*>(plist);
					assert(pstyle != NULL);
					gtParagraphStyle* tmp = new gtParagraphStyle(*pstyle);
					currentStyle = tmp;
				}
				else
				{
					gtParagraphStyle* tmp = new gtParagraphStyle(*plist);
					currentStyle = tmp;
				}
				currentStyle->setName(currentList + "_" + attrs.value(i));
			}
			else if (attrs.localName(i) == "style:num-prefix")
				prefix = attrs.value(i);
			else if (attrs.localName(i) == "style:num-suffix")
				suffix = attrs.value(i);
			else if (attrs.localName(i) == "text:bullet-char")
				bullet = attrs.value(i);
			else if (attrs.localName(i) == "style:num-format") {
				QString tmp = attrs.value(i);
				if (tmp == "i")
					bstyle = LowerRoman;
				else if (tmp == "I")
					bstyle = UpperRoman;
				else if (tmp == "a")
					bstyle = LowerAlpha;
				else if (tmp == "A")
					bstyle = UpperAlpha;
				else if (tmp == "1")
					bstyle = Number;
			}
			else if (attrs.localName(i) == "text:start-value") {
				startAt = QString(attrs.value(i)).toUInt();
				if (startAt > 0)
					--startAt;
			}
			else if (attrs.localName(i) == "text:display-levels") {
				displayLevels = QString(attrs.value(i)).toUInt();
				if (displayLevels == 0)
					displayLevels = 1;
			}
		}
		if (bstyle == Bullet) {
			prefix = "";
			suffix = "";
		}
		ListLevel *llevel = new ListLevel(ulevel, bstyle, prefix, suffix, bullet, displayLevels, startAt);
		currentListStyle->addLevel(ulevel, llevel);
		readProperties = true;

		gtParagraphStyle* s = dynamic_cast<gtParagraphStyle*>(currentStyle);
		assert(s != NULL);
		if (bstyle == Bullet || bstyle == Graphic)
		{
			s->setBullet(true, bullet);
		}
		else
		{
			Q_ASSERT(((int) bstyle > 0) && ((int) bstyle < 6));
			s->setNum(true, (int) bstyle -1, ulevel, startAt+1, prefix, suffix);
		}
	}
	else if ((name == "style:drop-cap") && (readProperties))
	{
		if (currentStyle->target() == "paragraph")
		{
			for (int i = 0; i < attrs.count(); ++i)
			{
				if (attrs.localName(i) == "style:lines")
				{
					bool ok = false;
					QString sd = attrs.value(i);
					int dh = sd.toInt(&ok);
					if (ok)
					{
						gtParagraphStyle* s = dynamic_cast<gtParagraphStyle*>(currentStyle);
						assert(s != NULL);
						s->setDropCapHeight(dh);
						s->setDropCap(true);
					}
				}
			}
		}
	}
	else if (name == "style:font-face")
	{
		QString key = "";
		QString family = "";
		QString style = "";
		for (int i = 0; i < attrs.count(); ++i)
		{
			if (attrs.localName(i) == "style:name")
				key = attrs.value(i);
			else if (attrs.localName(i) == "svg:font-family")
			{
				family = attrs.value(i);
				family = family.remove("'");
			}
			else if (attrs.localName(i) == "style:font-style-name")
				style += attrs.value(i) + " ";
		}
		QString name = family + " " + style;
		name = name.simplified();
		fonts[key] = name;
	}
	return true;
}