Example #1
0
void WAccount::fillStrings(QString &text, QString &html, const QDomElement &element, const QString &prefix)
{
	QString key = prefix + QLatin1Char('%');
	if (key != QLatin1String("%%")) {
		text.replace(key, element.text());
		html.replace(key, element.text().toHtmlEscaped());
		qDebug() << key;
	}
	key.chop(1);

	QDomNamedNodeMap attributes = element.attributes();
	for (int i = 0; i < attributes.count(); ++i) {
		QDomNode attribute = attributes.item(i);
		QString attributeKey = key
				% QLatin1Char('/')
				% attribute.nodeName()
				% QLatin1Char('%');
		qDebug() << attributeKey;
		text.replace(attributeKey, attribute.nodeValue());
		html.replace(attributeKey, attribute.nodeValue().toHtmlEscaped());
	}

	if (!key.endsWith(QLatin1Char('%')))
		key += QLatin1Char('/');
	QDomNodeList elementChildren = element.childNodes();
	for (int i = 0; i < elementChildren.count(); ++i) {
		QDomNode node = elementChildren.at(i);
		if (node.isElement())
			fillStrings(text, html, node.toElement(), key + node.nodeName());
	}
}
int QDomNamedNodeMapProto:: count()         const
{
  QDomNamedNodeMap *item = qscriptvalue_cast<QDomNamedNodeMap*>(thisObject());
  if (item)
    return item->count();
  return 0;
}
Example #3
0
void  XML::XMLToVariables(MOVector<Variable> & variables,QDomElement &element)
{
    variables.clear();

    QDomElement e;
    QDomNode n = element.firstChild();

    QString fieldName;
    int iField;

    while( !n.isNull() )
    {
        e = n.toElement();
        if( !e.isNull() && (e.tagName()=="Variable"))
        {
            Variable* newVar = new Variable();
            QDomNamedNodeMap attributes = e.attributes();
            for(int i=0;i<attributes.count();i++)
            {
                iField = newVar->getFieldIndex(attributes.item(i).toAttr().name());
                if(iField>-1)
                    newVar->setFieldValue(iField,QVariant(attributes.item(i).toAttr().value()));
            }
            variables.addItem(newVar);
        }
        n = n.nextSibling();
    }
}
Example #4
0
void cleanMathml(QDomElement pElement)
{
    // Clean up the current element
    // Note: the idea is to remove all the attributes that are not in the
    //       MathML namespace. Indeed, if we were to leave them in then the XSL
    //       transformation would either do nothing or, worst, crash OpenCOR...

    static const QString MathmlNamespace = "http://www.w3.org/1998/Math/MathML";

    QDomNamedNodeMap attributes = pElement.attributes();
    QList<QDomNode> nonMathmlAttributes = QList<QDomNode>();

    for (int i = 0, iMax = attributes.count(); i < iMax; ++i) {
        QDomNode attribute = attributes.item(i);

        if (attribute.namespaceURI().compare(MathmlNamespace))
            nonMathmlAttributes << attribute;
    }

    foreach (QDomNode nonMathmlAttribute, nonMathmlAttributes)
        pElement.removeAttributeNode(nonMathmlAttribute.toAttr());

    // Go through the element's child elements, if any, and clean them up

    for (QDomElement childElement = pElement.firstChildElement();
         !childElement.isNull(); childElement = childElement.nextSiblingElement()) {
        cleanMathml(childElement);
    }
}
//! [3]
QVariant DomModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (role != Qt::DisplayRole)
        return QVariant();

    DomItem *item = static_cast<DomItem*>(index.internalPointer());

    QDomNode node = item->node();
//! [3] //! [4]
    QStringList attributes;
    QDomNamedNodeMap attributeMap = node.attributes();

    switch (index.column()) {
        case 0:
            return node.nodeName();
        case 1:
            for (int i = 0; i < attributeMap.count(); ++i) {
                QDomNode attribute = attributeMap.item(i);
                attributes << attribute.nodeName() + "=\""
                              +attribute.nodeValue() + "\"";
            }
            return attributes.join(" ");
        case 2:
            return node.nodeValue().split("\n").join(" ");
        default:
            return QVariant();
    }
}
BorderDrawerInterface * BorderDrawersLoader::getDrawerFromSvg(QDomElement & drawerElement)
{
    QMap<QString,QString> properties;
    QDomNamedNodeMap attributes = drawerElement.attributes();
    for (int j = attributes.count()-1; j >= 0; --j)
    {
        QDomAttr attr = attributes.item(j).toAttr();
        if (attr.isNull())
            continue;
        properties.insert(attr.name(), attr.value());
    }
    QString drawerName = properties.take("name");
    if (!instance()->registeredDrawers().contains(drawerName))
        return 0;
    BorderDrawerInterface * drawer = getDrawerByName(drawerName);
    const QMetaObject * meta = drawer->metaObject();
    int count = meta->propertyCount();
    for (int i = 0; i < count; ++i)
    {
        QMetaProperty p = meta->property(i);
        QString value = properties.take(p.name());
        if (value.isEmpty())
            continue;
        p.write(drawer, QVariant(QByteArray::fromBase64(value.toAscii())));
    }
    return drawer;
}
Example #7
0
QString XmlProtocol::elementToString(const QDomElement &e, bool clip)
{
	if(elem.isNull())
		elem = elemDoc.importNode(docElement(), true).toElement();

	// Determine the appropriate 'fakeNS' to use
	QString ns;

	// first, check root namespace
	QString pre = e.prefix();
	if(pre.isNull())
		pre = "";
	if(pre == elem.prefix()) {
		ns = elem.namespaceURI();
	}
	else {
		// scan the root attributes for 'xmlns' (oh joyous hacks)
		QDomNamedNodeMap al = elem.attributes();
		int n;
		for(n = 0; n < al.count(); ++n) {
			QDomAttr a = al.item(n).toAttr();
			QString s = a.name();
			int x = s.indexOf(':');
			if(x != -1)
				s = s.mid(x+1);
			else
				s = "";
			if(pre == s) {
				ns = a.value();
				break;
			}
		}
		if(n >= al.count()) {
			// if we get here, then no appropriate ns was found.  use root then..
			ns = elem.namespaceURI();
		}
	}

	// build qName
	QString qn;
	if(!elem.prefix().isEmpty())
		qn = elem.prefix() + ':';
	qn += elem.localName();

	// make the string
	return sanitizeForStream(xmlToString(e, ns, qn, clip));
}
Example #8
0
QVariant XUPProjectModel::data( const QModelIndex& index, int role ) const
{
    if ( !index.isValid() ) {
        return QVariant();
    }
    
    XUPItem* item = static_cast<XUPItem*>( index.internalPointer() );

    switch ( role ) {
        case Qt::DecorationRole:
            return item->displayIcon();
        case Qt::DisplayRole:
            return item->displayText();
        case XUPProjectModel::TypeRole:
            return item->type();
        case Qt::ToolTipRole:
        {
            const QDomNode node = item->node();
            const QDomNamedNodeMap attributeMap = node.attributes();
            QStringList attributes;
            
            if ( item->type() == XUPItem::Project ) {
                attributes << QString( "Project: %1" ).arg( item->project()->fileName() );
            }
            
            for ( int i = 0; i < attributeMap.count(); i++ ) {
                const QDomNode attribute = attributeMap.item( i );
                const QString name = attribute.nodeName();
                const QString value = attribute.nodeValue();
                
                attributes << QString( "%1=\"%2\"" ).arg( name ).arg( value );
            }
            
            switch ( item->type() ) {
                case XUPItem::Value:
                    attributes << QString( "Value=\"%1\"" ).arg( item->content() );
                    break;
                case XUPItem::File:
                    attributes << QString( "File=\"%1\"" ).arg( item->content() );
                    break;
                case XUPItem::Path:
                    attributes << QString( "Path=\"%1\"" ).arg( item->content() );
                    break;
                default:
                    break;
            }
            
            return attributes.join( "\n" );
        }
        case Qt::SizeHintRole:
            return QSize( -1, 18 );
        default:
            break;
    }
    
    return QVariant();
}
Example #9
0
QDebug operator<<(QDebug dbg, const QDomElement &el)
{
    QDomNamedNodeMap map = el.attributes();

    QString args;
    for (int i=0; i<map.count(); ++i)
        args += " " + map.item(i).nodeName() + "='" + map.item(i).nodeValue() + "'";

    dbg.nospace() << QString("<%1%2>%3</%1>").arg(el.tagName()).arg(args).arg(el.text());
    return dbg.space();
}
MStriantMap MusicAbstractXml::readXmlAttributesByTagName(const QString &tagName) const
{
    QDomNodeList nodelist = m_ddom->elementsByTagName(tagName);
    QDomNamedNodeMap nodes = nodelist.at(0).toElement().attributes();
    MStriantMap maps;
    for(int i=0; i<nodes.count(); ++i)
    {
        QDomAttr attr = nodes.item(i).toAttr();
        maps[attr.name()] = attr.value();
    }
    return maps;
}
Example #11
0
QVariant DomModel::data(const QModelIndex &index, int role) const
{
	if (!index.isValid())
		return QVariant();
	
	//role to get full xml path of index
	if(role == XPathRole)
	{
		QString wholeXmlPath;
		DomItem *item = static_cast<DomItem*>(index.internalPointer());
		if (item==NULL)
			qFatal("can't convert domitem from datamodel");
		
		for(;item->parent()!=NULL;item=item->parent())
		{
			wholeXmlPath=item->node().nodeName()+"/"+wholeXmlPath;
		}
		
		wholeXmlPath="/"+wholeXmlPath;
		return wholeXmlPath;
	}	
	else if (role == Qt::DisplayRole)
	{
		DomItem *item = static_cast<DomItem*>(index.internalPointer());
		
		QDomNode node = item->node();
		QStringList attributes;
		QDomNamedNodeMap attributeMap = node.attributes();
		
		switch (index.column())
		{
			//name
			case 0:
				return node.nodeName();
			//attributes
			case 1:
				for (int i = 0; i < attributeMap.count(); ++i)
				{
					QDomNode attribute = attributeMap.item(i);
					attributes << attribute.nodeName() + "=\""  +attribute.nodeValue() + "\"";
				}
				return attributes.join(" ");
			//value
			case 2:
				return node.nodeValue().split("\n").join(" ");
			default:
				return QVariant();
		}
	}
	else
		return QVariant();
}
QString ConfiguratorHelper::elementString(QDomElement &el) {
    QString str;
    str += "<"%el.tagName()%" ";

    QDomNamedNodeMap attrs = el.attributes();
    int count = attrs.count();
    for (int i = 0; i < count; ++i) {
        str += attrs.item(i).toAttr().name()%"=\""%attrs.item(i).toAttr().value()%"\" ";
    }
    str += "/>";

    return str;
}
/*!
  Set of search parameters.
 */
QHash<QString,QString> TasTargetObject::searchParameters() const
{
    QHash<QString,QString> params;
    QDomNamedNodeMap attributes = mElement.attributes();
    for(int i = 0 ; i < attributes.count(); i++){
        QDomNode node = attributes.item(i);
        //strip special attrs
        if(node.nodeName() != "objectName" && node.nodeName() != "className" && node.nodeName() != "tasId"){
            params.insert(node.nodeName(), node.nodeValue());
        }
    }
    return params;
}
/* debug all item incomming in tree 2 level */
QString cssGroup( const QDomElement e )
{
    QStringList cssitem;
    QDomNamedNodeMap alist = e.attributes();
    for (int i=0; i<alist.count(); i++) {
        QDomNode nod = alist.item(i);
        cssitem.append(QString("%1:%2").arg(nod.nodeName().toLower()).arg(nod.nodeValue()));
    }
    QDomNode child = e.firstChild();
    while ( !child.isNull() ) {
        if ( child.isElement() ) {
            QDomNamedNodeMap list = child.attributes();
            for (int x=0; x<list.count(); x++) {
                QDomNode nod = list.item(x);
                cssitem.append(QString("%1:%2").arg(nod.nodeName().toLower()).arg(nod.nodeValue()));
            }
        }
        child = child.nextSibling();
    }

    return cssitem.join(";");
}
Example #15
0
/* loop  to find attribute name xx */
QString UnionXml::FilterAttribute(QDomElement element, QString attribute) {
    QString base = "-1";
    QDomNamedNodeMap attlist = element.attributes();
    int bigint = attlist.count();
    if (bigint > 0) {
        for (int i = 0; i < bigint; i++) {
            QDomNode nod = attlist.item(i);
            if (nod.nodeName() == attribute) {
                base = QString(nod.nodeValue());
                return base;
            }
        }
    }
    return base;
}
Example #16
0
OptObjectiveResult::OptObjectiveResult(QDomElement & domEl):OptObjective()
{
    QDomNamedNodeMap attributes = domEl.attributes();
    QString fieldName;
    QString fieldValue;

    for(int i=0;i<attributes.count();i++)
    {
        fieldName = attributes.item(i).toAttr().name();
        fieldName.replace(XMLTools::space()," ");
        fieldValue = attributes.item(i).toAttr().value();
        fieldValue.replace(XMLTools::space()," ");
        MOItem::setFieldValue(fieldName,QVariant(fieldValue));
    }
}
QDomElement addCorrectNS(const QDomElement &e)
{
	int x;

	// grab child nodes
	/*QDomDocumentFragment frag = e.ownerDocument().createDocumentFragment();
	QDomNodeList nl = e.childNodes();
	for(x = 0; x < nl.count(); ++x)
		frag.appendChild(nl.item(x).cloneNode());*/

	// find closest xmlns
	QDomNode n = e;
	while(!n.isNull() && !n.toElement().hasAttribute("xmlns") && n.toElement().namespaceURI() == "" )
		n = n.parentNode();
	QString ns;
	if(n.isNull() || !n.toElement().hasAttribute("xmlns")){
		if (n.toElement().namespaceURI () == ""){
			ns = "jabber:client";
		} else {
			ns = n.toElement().namespaceURI();
		}
	} else {
		ns = n.toElement().attribute("xmlns");
	}
	// make a new node
	QDomElement i = e.ownerDocument().createElementNS(ns, e.tagName());

	// copy attributes
	QDomNamedNodeMap al = e.attributes();
	for(x = 0; x < al.count(); ++x) {
		QDomAttr a = al.item(x).toAttr();
		if(a.name() != "xmlns")
			i.setAttributeNodeNS(a.cloneNode().toAttr());
	}

	// copy children
	QDomNodeList nl = e.childNodes();
	for(x = 0; x < nl.count(); ++x) {
		QDomNode n = nl.item(x);
		if(n.isElement())
			i.appendChild(addCorrectNS(n.toElement()));
		else
			i.appendChild(n.cloneNode());
	}

	//i.appendChild(frag);
	return i;
}
Example #18
0
/**
* Equivalent to MOItem::update() but here, we do not read field.
* Because if index changed (e.g. order is changed between two versions),
* there would be misunderstanding to keep index. Name is the field used to refer.
* @sa MOParameter::toXmlData()
* @sa MOItem::update(QDomElement & domEl)
*/
void MOParameter::update(QDomElement & domEl)
{
    QDomNamedNodeMap attributes = domEl.attributes();
    QString fieldName;
    QString fieldValue;
    int iField;
    for(int i=0;i<attributes.count();i++)
    {
        fieldName = attributes.item(i).toAttr().name();
        fieldName.replace(XMLTools::space()," ");
        fieldValue = attributes.item(i).toAttr().value();
        fieldValue.replace(XMLTools::space()," ");
        iField = getFieldIndex(fieldName,Qt::UserRole);
        setFieldValue(iField,QVariant(fieldValue));
    }
}
Example #19
0
// stripExtraNS
//
// This function removes namespace information from various nodes for
// display purposes only (the element is pretty much useless for processing
// after this).  We do this because QXml is a bit overzealous about outputting
// redundant namespaces.
static QDomElement stripExtraNS(const QDomElement &e)
{
	// find closest parent with a namespace
	QDomNode par = e.parentNode();
	while(!par.isNull() && par.namespaceURI().isNull())
		par = par.parentNode();
	bool noShowNS = false;
	if(!par.isNull() && par.namespaceURI() == e.namespaceURI())
		noShowNS = true;

	// build qName (prefix:localName)
	QString qName;
	if(!e.prefix().isEmpty())
		qName = e.prefix() + ':' + e.localName();
	else
		qName = e.tagName();

	QDomElement i;
	int x;
	if(noShowNS)
		i = e.ownerDocument().createElement(qName);
	else
		i = e.ownerDocument().createElementNS(e.namespaceURI(), qName);

	// copy attributes
	QDomNamedNodeMap al = e.attributes();
	for(x = 0; x < al.count(); ++x) {
		QDomAttr a = al.item(x).cloneNode().toAttr();

		// don't show xml namespace
		if(a.namespaceURI() == NS_XML)
			i.setAttribute(QString("xml:") + a.name(), a.value());
		else
			i.setAttributeNodeNS(a);
	}

	// copy children
	QDomNodeList nl = e.childNodes();
	for(x = 0; x < nl.count(); ++x) {
		QDomNode n = nl.item(x);
		if(n.isElement())
			i.appendChild(stripExtraNS(n.toElement()));
		else
			i.appendChild(n.cloneNode());
	}
	return i;
}
Example #20
0
void Definitions::loadXML( ParserContext *context, const QDomElement &element )
{
  setTargetNamespace( element.attribute( "targetNamespace" ) );
  mName = element.attribute( "name" );

  QDomNamedNodeMap attributes = element.attributes();
  for ( int i = 0; i < attributes.count(); ++i ) {
    QDomAttr attribute = attributes.item( i ).toAttr();
    if ( attribute.name().startsWith( "xmlns:" ) ) {
      QString prefix = attribute.name().mid( 6 );
      context->namespaceManager()->setPrefix( prefix, attribute.value() );
    }
  }

  QDomElement child = element.firstChildElement();
  while ( !child.isNull() ) {
    QName tagName = child.tagName();
    if ( tagName.localName() == "import" ) {
      Import import( mTargetNamespace );
      import.loadXML( context, child );
      mImports.append( import );
    } else if ( tagName.localName() == "types" ) {
      mType.loadXML( context, child );
    } else if ( tagName.localName() == "message" ) {
      Message message( mTargetNamespace );
      message.loadXML( context, child );
      mMessages.append( message );
    } else if ( tagName.localName() == "portType" ) {
      PortType portType( mTargetNamespace );
      portType.loadXML( context, child );
      mPortTypes.append( portType );
    } else if ( tagName.localName() == "binding" ) {
      Binding binding( mTargetNamespace );
      binding.loadXML( context, child );
      mBindings.append( binding );
    } else if ( tagName.localName() == "service" ) {
      mService.loadXML( context, &mBindings, child );
    } else if ( tagName.localName() == "documentation" ) {
      // ignore documentation for now
    } else {
      context->messageHandler()->warning( QString( "Definitions: unknown tag %1" ).arg( child.tagName() ) );
    }

    child = child.nextSiblingElement();
  }
}
Example #21
0
void NodeBrowser::itemClicked( QTreeWidgetItem *itm )
{
	d->browser.properties->clear();
	
	if( itm == 0) return;
	
	d->domPath = d->node->path("",itm);
	d->browser.path->setText(d->domPath);
	
	QDomNode node = SxDomUtils::getElement( d->doc.toElement(), d->domPath ); 
	if( !node.isNull() )
	{
		QDomNamedNodeMap map = node.attributes();
		int count = map.count();
		for( int idx = 0; idx < count; ++idx)
		d->browser.properties->addItem( map.item(idx).nodeName() );
	}
}
void FopLeader::RestoreOn( QDomElement appender )
{
	QDomDocument doc;
	
	if (ELoriginal.size() > 8 && doc.setContent(ELoriginal,false) ) {
		    QDomElement root_extern = doc.documentElement(); 
				QDomNamedNodeMap alist = root_extern.attributes();
		
			          QDomElement leader = appender.ownerDocument().createElement("fo:leader");
								for (int i=0; i<alist.count(); i++){
									QDomNode nod = alist.item(i);
									leader.setAttribute(nod.nodeName().toLower(),nod.nodeValue());
								}
								
								QDomNode child = root_extern.firstChild();
										while ( !child.isNull() ) {
											
											if ( child.isElement() ) {
											leader.appendChild(appender.ownerDocument().importNode(child,true).toElement());
											}
											
										child = child.nextSibling();            
										}
				appender.appendChild(leader);
										
	} else {
		
		/* rebuild it but not editable! now  */
		/*
		<fo:leader leader-pattern="rule"
                   rule-thickness="10cm"
                   leader-length="6cm"
                   space-before.optimum="12pt"
                   space-after.optimum="12pt"
                   start-indent="1.5cm"
                   end-indent="2cm"
                   background-color="blue"
                   color="yellow"/>
		*/
	}
	
	
}
Example #23
0
void QtSimpleXml::parse(QDomNode node)
{
 //   puts("parse");
    if (node.isNull())
        return;

    valid = true;
    n = node.nodeName();
    QDomElement element = node.toElement();

    QDomNamedNodeMap attrs = element.attributes();
    for (int i = 0; i < (int) attrs.count(); ++i) {
        QDomAttr attribute = attrs.item(i).toAttr();
        attr.insert(attribute.name(), attribute.value());
    }

    if (element.firstChild().isText()) {
  //      printf("Got text %s\n", element.text().stripWhiteSpace().latin1());
        s = element.text().trimmed();
        return;
    }

    if (node.hasChildNodes()) {

        // Skip to first element child
        QDomNode child = node.firstChild();
        while (!child.isNull() && !child.isElement())
            child = child.nextSibling();

        while (!child.isNull()) {
            QtSimpleXml *xmlNode = new QtSimpleXml;
            xmlNode->parse(child);
            children.insert(xmlNode->name(), xmlNode);

            node = node.nextSibling();

            do {
                child = child.nextSibling();
            } while (!child.isNull() && !child.isElement());
        }
    }
}
Example #24
0
void ComplexBaseInputField::setXMLData( const QDomElement &element )
{
  if ( mName != element.tagName() ) {
    qDebug( "ComplexBaseInputField: Wrong dom element passed: expected %s, got %s", qPrintable( mName ), qPrintable( element.tagName() ) );
    return;
  }

  // elements
  if ( mType->isArray() ) {
    InputField *field = childField( "item" );
    field->setXMLData( element );
  } else {
    QDomNode node = element.firstChild();
    while ( !node.isNull() ) {
      QDomElement child = node.toElement();
      if ( !child.isNull() ) {
        InputField *field = childField( child.tagName() );
        if ( !field ) {
          qDebug( "ComplexBaseInputField: Child field %s does not exists", qPrintable( child.tagName() ) );
        } else {
          field->setXMLData( child );
        }
      }

      node = node.nextSibling();
    }
  }

  // attributes
  QDomNamedNodeMap nodes = element.attributes();
  for ( int i = 0; i < nodes.count(); ++i ) {
    QDomNode node = nodes.item( i );
    QDomAttr attr = node.toAttr();

    InputField *field = childField( attr.name() );
    if ( !field ) {
      qDebug( "ComplexBaseInputField: Child field %s does not exists", qPrintable( attr.name() ) );
    } else {
      field->setData( attr.value() );
    }
  }
}
QByteArray FopLeader::SaveElement( const QDomElement e )
{
    QDomDocument em;
    QDomElement import = em.createElement(e.tagName().toLower());
    em.appendChild( import );
    QDomNamedNodeMap attlist = e.attributes();
    for (int i=0; i<attlist.count(); i++){
    QDomNode nod = attlist.item(i);
    import.setAttribute (nod.nodeName().toLower(),nod.nodeValue()); 
    }
                            QDomNode child = e.firstChild();
                               while ( !child.isNull() ) {
                                   if ( child.isElement() ) {
                                    import.appendChild(em.importNode(child,true).toElement());
                                   }
                                 child = child.nextSibling();            
                               }
															 
    return em.toByteArray(0);
}
Example #26
0
OptObjective::OptObjective(QDomElement & domEl)
{

    QList<int> protectedFields;
    protectedFields << OptObjective::NAME << OptObjective::DESCRIPTION << OptObjective::MODEL;
    setProtectedFields(protectedFields);
    _scanFunction = NONE;

    initOptExtremum();

    QDomNamedNodeMap attributes = domEl.attributes();
    QString fieldName;
    QString fieldValue;

    for(int i=0;i<attributes.count();i++)
    {
        fieldName = attributes.item(i).toAttr().name();
        fieldName.replace(XMLTools::space()," ");
        fieldValue = attributes.item(i).toAttr().value();
        fieldValue.replace(XMLTools::space()," ");
        MOItem::setFieldValue(fieldName,QVariant(fieldValue));
    }
}
QByteArray CatDomElement( const QDomElement e )
{
    if (e.isNull()) {
        return QByteArray();
    }
    QDomDocument doc;
    QDomElement Pbb = doc.createElement(e.tagName());
    QDomNamedNodeMap alist = e.attributes();
    for (int i=0; i<alist.count(); i++) {
        QDomNode nod = alist.item(i);
        Pbb.setAttribute(nod.nodeName().toLower(),nod.nodeValue());
    }
    doc.appendChild(Pbb);

    QDomNode child = e.firstChild();
    while ( !child.isNull() ) {
        if ( child.isElement() ) {
            Pbb.appendChild(doc.importNode(child,true).toElement());
        }
        child = child.nextSibling();
    }

    return doc.toByteArray(1);
}
Example #28
0
static QDomElement oldStyleNS(const QDomElement &e)
{
	// find closest parent with a namespace
	QDomNode par = e.parentNode();
	while(!par.isNull() && par.namespaceURI().isNull())
		par = par.parentNode();
	bool noShowNS = false;
	if(!par.isNull() && par.namespaceURI() == e.namespaceURI())
		noShowNS = true;

	QDomElement i;
	uint x;
	//if(noShowNS)
		i = e.ownerDocument().createElement(e.tagName());
	//else
	//	i = e.ownerDocument().createElementNS(e.namespaceURI(), e.tagName());

	// copy attributes
	QDomNamedNodeMap al = e.attributes();
	for(x = 0; x < al.count(); ++x)
		i.setAttributeNode(al.item(x).cloneNode().toAttr());

	if(!noShowNS)
		i.setAttribute("xmlns", e.namespaceURI());

	// copy children
	QDomNodeList nl = e.childNodes();
	for(x = 0; x < nl.count(); ++x) {
		QDomNode n = nl.item(x);
		if(n.isElement())
			i.appendChild(oldStyleNS(n.toElement()));
		else
			i.appendChild(n.cloneNode());
	}
	return i;
}
Example #29
0
bool KXMLGUIClient::mergeXML( QDomElement &base, const QDomElement &additive, KActionCollection *actionCollection )
{
  static const QString &tagAction = KGlobal::staticQString( "Action" );
  static const QString &tagMerge = KGlobal::staticQString( "Merge" );
  static const QString &tagSeparator = KGlobal::staticQString( "Separator" );
  static const QString &attrName = KGlobal::staticQString( "name" );
  static const QString &attrAppend = KGlobal::staticQString( "append" );
  static const QString &attrWeakSeparator = KGlobal::staticQString( "weakSeparator" );
  static const QString &tagMergeLocal = KGlobal::staticQString( "MergeLocal" );
  static const QString &tagText = KGlobal::staticQString( "text" );
  static const QString &attrAlreadyVisited = KGlobal::staticQString( "alreadyVisited" );
  static const QString &attrNoMerge = KGlobal::staticQString( "noMerge" );
  static const QString &attrOne = KGlobal::staticQString( "1" );

  // there is a possibility that we don't want to merge in the
  // additive.. rather, we might want to *replace* the base with the
  // additive.  this can be for any container.. either at a file wide
  // level or a simple container level.  we look for the 'noMerge'
  // tag, in any event and just replace the old with the new
  if ( additive.attribute(attrNoMerge) == attrOne ) // ### use toInt() instead? (Simon)
  {
    base.parentNode().replaceChild(additive, base);
    return true;
  }

  QString tag;

  // iterate over all elements in the container (of the global DOM tree)
  QDomNode n = base.firstChild();
  while ( !n.isNull() )
  {
    QDomElement e = n.toElement();
    n = n.nextSibling(); // Advance now so that we can safely delete e
    if (e.isNull())
       continue;

    tag = e.tagName();

    // if there's an action tag in the global tree and the action is
    // not implemented, then we remove the element
    if ( tag == tagAction )
    {
      QCString name =  e.attribute( attrName ).utf8(); // WABA
      if ( !actionCollection->action( name ) ||
           (kapp && !kapp->authorizeKAction(name)))
      {
        // remove this child as we aren't using it
        base.removeChild( e );
        continue;
      }
    }

    // if there's a separator defined in the global tree, then add an
    // attribute, specifying that this is a "weak" separator
    else if ( tag == tagSeparator )
    {
      e.setAttribute( attrWeakSeparator, (uint)1 );

      // okay, hack time. if the last item was a weak separator OR
      // this is the first item in a container, then we nuke the
      // current one
      QDomElement prev = e.previousSibling().toElement();
      if ( prev.isNull() ||
	 ( prev.tagName() == tagSeparator && !prev.attribute( attrWeakSeparator ).isNull() ) ||
	 ( prev.tagName() == tagText ) )
      {
        // the previous element was a weak separator or didn't exist
        base.removeChild( e );
        continue;
      }
    }

    // the MergeLocal tag lets us specify where non-standard elements
    // of the local tree shall be merged in.  After inserting the
    // elements we delete this element
    else if ( tag == tagMergeLocal )
    {
      QDomNode it = additive.firstChild();
      while ( !it.isNull() )
      {
        QDomElement newChild = it.toElement();
        it = it.nextSibling();
        if (newChild.isNull() )
          continue;

        if ( newChild.tagName() == tagText )
          continue;

        if ( newChild.attribute( attrAlreadyVisited ) == attrOne )
          continue;

        QString itAppend( newChild.attribute( attrAppend ) );
        QString elemName( e.attribute( attrName ) );

        if ( ( itAppend.isNull() && elemName.isEmpty() ) ||
             ( itAppend == elemName ) )
        {
          // first, see if this new element matches a standard one in
          // the global file.  if it does, then we skip it as it will
          // be merged in, later
          QDomElement matchingElement = findMatchingElement( newChild, base );
          if ( matchingElement.isNull() || newChild.tagName() == tagSeparator )
            base.insertBefore( newChild, e );
        }
      }

      base.removeChild( e );
      continue;
    }

    // in this last case we check for a separator tag and, if not, we
    // can be sure that its a container --> proceed with child nodes
    // recursively and delete the just proceeded container item in
    // case its empty (if the recursive call returns true)
    else if ( tag != tagMerge )
    {
      // handle the text tag
      if ( tag == tagText )
        continue;

      QDomElement matchingElement = findMatchingElement( e, additive );

      if ( !matchingElement.isNull() )
      {
        matchingElement.setAttribute( attrAlreadyVisited, (uint)1 );

        if ( mergeXML( e, matchingElement, actionCollection ) )
        {
          base.removeChild( e );
          continue;
        }

        // Merge attributes
        const QDomNamedNodeMap attribs = matchingElement.attributes();
        const uint attribcount = attribs.count();

        for(uint i = 0; i < attribcount; ++i)
        {
          const QDomNode node = attribs.item(i);
          e.setAttribute(node.nodeName(), node.nodeValue());
        }

        continue;
      }
      else
      {
        // this is an important case here! We reach this point if the
        // "local" tree does not contain a container definition for
        // this container. However we have to call mergeXML recursively
        // and make it check if there are actions implemented for this
        // container. *If* none, then we can remove this container now
        if ( mergeXML( e, QDomElement(), actionCollection ) )
          base.removeChild( e );
        continue;
      }
    }
  }

  //here we append all child elements which were not inserted
  //previously via the LocalMerge tag
  n = additive.firstChild();
  while ( !n.isNull() )
  {
    QDomElement e = n.toElement();
    n = n.nextSibling(); // Advance now so that we can safely delete e
    if (e.isNull())
       continue;

    QDomElement matchingElement = findMatchingElement( e, base );

    if ( matchingElement.isNull() )
    {
      base.appendChild( e );
    }
  }

  // do one quick check to make sure that the last element was not
  // a weak separator
  QDomElement last = base.lastChild().toElement();
  if ( (last.tagName() == tagSeparator) && (!last.attribute( attrWeakSeparator ).isNull()) )
  {
    base.removeChild( last );
  }

  // now we check if we are empty (in which case we return "true", to
  // indicate the caller that it can delete "us" (the base element
  // argument of "this" call)
  bool deleteMe = true;

  n = base.firstChild();
  while ( !n.isNull() )
  {
    QDomElement e = n.toElement();
    n = n.nextSibling(); // Advance now so that we can safely delete e
    if (e.isNull())
       continue;

    tag = e.tagName();

    if ( tag == tagAction )
    {
      // if base contains an implemented action, then we must not get
      // deleted (note that the actionCollection contains both,
      // "global" and "local" actions
      if ( actionCollection->action( e.attribute( attrName ).utf8() ) )
      {
        deleteMe = false;
        break;
      }
    }
    else if ( tag == tagSeparator )
    {
      // if we have a separator which has *not* the weak attribute
      // set, then it must be owned by the "local" tree in which case
      // we must not get deleted either
      QString weakAttr = e.attribute( attrWeakSeparator );
      if ( weakAttr.isEmpty() || weakAttr.toInt() != 1 )
      {
        deleteMe = false;
        break;
      }
    }

    // in case of a merge tag we have unlimited lives, too ;-)
    else if ( tag == tagMerge )
    {
//      deleteMe = false;
//      break;
        continue;
    }

    // a text tag is NOT enough to spare this container
    else if ( tag == tagText )
    {
      continue;
    }

    // what's left are non-empty containers! *don't* delete us in this
    // case (at this position we can be *sure* that the container is
    // *not* empty, as the recursive call for it was in the first loop
    // which deleted the element in case the call returned "true"
    else
    {
      deleteMe = false;
      break;
    }
  }

  return deleteMe;
}
Example #30
0
void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillParam, QColor& defaultFill, bool& hasOutlineParam, QColor& defaultOutline,
                                      bool& hasOutlineWidthParam, double& defaultOutlineWidth ) const
{
  if ( elem.isNull() )
  {
    return;
  }

  //we already have all the information, no need to go deeper
  if ( hasFillParam && hasOutlineParam && hasOutlineWidthParam )
  {
    return;
  }

  //check this elements attribute
  QDomNamedNodeMap attributes = elem.attributes();
  int nAttributes = attributes.count();

  QStringList valueSplit;
  for ( int i = 0; i < nAttributes; ++i )
  {
    QDomAttr attribute = attributes.item( i ).toAttr();
    if ( attribute.name().compare( "style", Qt::CaseInsensitive ) == 0 )
    {
      //entries separated by ';'
      QStringList entryList = attribute.value().split( ';' );
      QStringList::const_iterator entryIt = entryList.constBegin();
      for ( ; entryIt != entryList.constEnd(); ++entryIt )
      {
        QStringList keyValueSplit = entryIt->split( ':' );
        if ( keyValueSplit.size() < 2 )
        {
          continue;
        }
        QString key = keyValueSplit.at( 0 );
        QString value = keyValueSplit.at( 1 );
        valueSplit = value.split( " " );
        if ( !hasFillParam && value.startsWith( "param(fill)" ) )
        {
          hasFillParam = true;
          if ( valueSplit.size() > 1 )
          {
            defaultFill = QColor( valueSplit.at( 1 ) );
          }
        }
        else if ( !hasOutlineParam && value.startsWith( "param(outline)" ) )
        {
          hasOutlineParam = true;
          if ( valueSplit.size() > 1 )
          {
            defaultOutline = QColor( valueSplit.at( 1 ) );
          }
        }
        else if ( !hasOutlineWidthParam && value.startsWith( "param(outline-width)" ) )
        {
          hasOutlineWidthParam = true;
          if ( valueSplit.size() > 1 )
          {
            defaultOutlineWidth = valueSplit.at( 1 ).toDouble();
          }
        }
      }
    }
    else
    {
      QString value = attribute.value();
      valueSplit = value.split( " " );
      if ( !hasFillParam && value.startsWith( "param(fill)" ) )
      {
        hasFillParam = true;
        if ( valueSplit.size() > 1 )
        {
          defaultFill = QColor( valueSplit.at( 1 ) );
        }
      }
      else if ( !hasOutlineParam && value.startsWith( "param(outline)" ) )
      {
        hasOutlineParam = true;
        if ( valueSplit.size() > 1 )
        {
          defaultOutline = QColor( valueSplit.at( 1 ) );
        }
      }
      else if ( !hasOutlineWidthParam && value.startsWith( "param(outline-width)" ) )
      {
        hasOutlineWidthParam = true;
        if ( valueSplit.size() > 1 )
        {
          defaultOutlineWidth = valueSplit.at( 1 ).toDouble();
        }
      }
    }
  }

  //pass it further to child items
  QDomNodeList childList = elem.childNodes();
  int nChildren = childList.count();
  for ( int i = 0; i < nChildren; ++i )
  {
    QDomElement childElem = childList.at( i ).toElement();
    containsElemParams( childElem, hasFillParam, defaultFill, hasOutlineParam, defaultOutline, hasOutlineWidthParam, defaultOutlineWidth );
  }
}