예제 #1
0
QList<QDomElement> XmlUtils::FetchElementsFromDocument(QDomDocument xmls)
{
    QList<QDomElement> results;
    int index = 0;
    while (index < xmls.childNodes().count())
    {
        QDomNode node = xmls.childNodes().at(index++);
        RecursiveFetch(node, &results);
    }
    return results;
}
예제 #2
0
QDomNodeList QDomDocumentProto::childNodes() const
{
    QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject());
    if (item)
        return item->childNodes();
    return QDomNodeList();
}
예제 #3
0
void InterpreterElementImpl::init(QRectF &contents, PortFactoryInterface const &portFactory
		, QList<PortInterface *> &ports, LabelFactoryInterface &labelFactory
		, QList<LabelInterface *> &labels, SdfRendererInterface *renderer, ElementRepoInterface *elementRepo)
{
	Q_UNUSED(elementRepo);
	if (mId.element() == "MetaEntityNode") {
		mGraphics.setContent(mEditorRepoApi->stringProperty(mId, "shape"));
		QDomDocument classDoc;
		QDomElement sdfElement = mGraphics.firstChildElement("graphics").firstChildElement("picture");
		classDoc.appendChild(classDoc.importNode(sdfElement, true));
		if (!classDoc.childNodes().isEmpty()) {
			mRenderer = renderer;
			mRenderer->load(classDoc);
		}

		int width = 0;
		int height = 0;
		if (!sdfElement.isNull()) {
			width = sdfElement.attribute("sizex").toInt();
			height = sdfElement.attribute("sizey").toInt();
		}

		initPointPorts(portFactory, ports, width, height);
		initLinePorts(portFactory, ports, width, height);

		contents.setWidth(width);
		contents.setHeight(height);
		initLabels(width, height, labelFactory, labels);
	}
}
void SxeSession::initializeDocument(const QDomDocument &doc) {
    importing_ = true;

    // reset the document
    doc_ = QDomDocument();
    foreach(SxeRecord* meta, recordByNodeId_.values())
        meta->deleteLater();
    // recordByNode_.clear();
    recordByNodeId_.clear();
    queuedIncomingEdits_.clear();
    queuedOutgoingEdits_.clear();


    // import prolog
    doc_.setContent(parseProlog(doc));

    // import other nodes
    // create all nodes recursibely from root
    QDomNodeList children = doc.childNodes();
    for(int i = 0; i < children.size(); i++) {
        // skip the XML declaration <?xml ...?> because it isn't a processing instruction
        if(!(children.at(i).isProcessingInstruction() && children.at(i).toProcessingInstruction().target().toLower() == "xml"))
            generateNewNode(children.at(i), QString(), i);
    }

    importing_ = false;
}
예제 #5
0
void UpdateForm::OnTick()
{
    if (!this->qData->IsProcessed())
    {
        return;
    }

    QDomDocument r;
    r.setContent(this->qData->Result->Data);
    QDomNodeList l = r.elementsByTagName("obsolete");
    if (l.count() == 0)
    {
        // there is no new version of huggle
        this->qData->UnregisterConsumer("updater");
        this->t->stop();
        return;
    } else
    {
        QString version = l.at(0).toElement().text();
        /// \todo LOCALIZE ME
        QString info = "New version of huggle is available: version " + version;
        l = r.elementsByTagName("info");
        if (l.count() > 0)
        {
            // we don't know how to update o.O
            info = l.at(0).toElement().text();
            this->ui->pushButton->setEnabled(false);
            info = info.replace("$LATESTHUGGLE", version);
            this->ui->label->setText(info);
            this->show();
            this->qData->UnregisterConsumer("updater");
            this->t->stop();
            return;
        } else
        {
            // get the instructions
            l = r.childNodes();
            int id = 0;
            while (id < l.count())
            {
                QDomElement element = l.at(0).toElement();
                id++;
                if (element.tagName() == "download")
                {
                    if (!element.attributes().contains("target"))
                    {
                        Syslog::HuggleLogs->Log("WARNING: Invalid updater instruction: download is missing target, ingoring the update");
                        this->qData->UnregisterConsumer("updater");
                        this->t->stop();
                        return;
                    }
                    this->Instructions.append("download " + element.text() + " " + element.attribute("target"));
                }
                if (element.tagName() == "exec")
                {
                    bool root = false;
                    if (element.attributes().contains("root"))
                    {
                        if (element.attribute("root") == "true")
                        {
                            root = true;
                        }
                    }
                    if (root)
                    {
                        this->Instructions.append("roexec " + element.text());
                    } else
                    {
                        this->Instructions.append("exec " + element.text());
                    }
                }
            }
        }
        this->ui->label->setText(info);
        this->show();
    }

    this->qData->UnregisterConsumer("updater");
    this->t->stop();
}
예제 #6
0
TestResult::Status TestBaseLine::verify(const QString &serializedInput) const
{
    switch(m_type)
    {
        case SchemaIsValid:
        /* Fall through. */
        case Text:
        {
            if(serializedInput == details())
                return TestResult::Pass;
            else
                return TestResult::Fail;
        }
        case Fragment:
        /* Fall through. */
        case XML:
        {
            /* Read the baseline and the serialized input into two QDomDocuments, and compare
             * them deeply. We wrap fragments in a root node such that it is well-formed XML.
             */

            QDomDocument output;
            {
                /* The reason we put things into a QByteArray and then parse it through QXmlSimpleReader, is that
                 * QDomDocument does whitespace stripping when calling setContent(QString). In other words,
                 * this workarounds a bug. */

                QXmlInputSource source;
                source.setData((m_type == XML ? serializedInput : QLatin1String("<r>") +
                                                                  serializedInput +
                                                                  QLatin1String("</r>")).toUtf8());

                QString outputReadingError;

                QXmlSimpleReader reader;
                reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true);

                const bool success = output.setContent(&source,
                                                       &reader,
                                                       &outputReadingError);

                if(!success)
                    return TestResult::Fail;

                Q_ASSERT(success);
            }

            QDomDocument baseline;
            {
                QXmlInputSource source;
                source.setData((m_type == XML ? details() : QLatin1String("<r>") +
                                                            details() +
                                                            QLatin1String("</r>")).toUtf8());
                QString baselineReadingError;

                QXmlSimpleReader reader;
                reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true);

                const bool success = baseline.setContent(&source,
                                                         &reader,
                                                         &baselineReadingError);

                if(!success)
                    return TestResult::Fail;

                /* This piece of code workaround a bug in QDom, which treats XML prologs as processing
                 * instructions and make them available in the tree as so. */
                if(m_type == XML)
                {
                    /* $doc/r/node() */
                    const QDomNodeList children(baseline.childNodes());
                    const int len = children.length();

                    for(int i = 0; i < len; ++i)
                    {
                        const QDomNode &child = children.at(i);
                        if(child.isProcessingInstruction() && child.nodeName() == QLatin1String("xml"))
                        {
                            baseline.removeChild(child);
                            break;
                        }
                    }
                }

                Q_ASSERT_X(baselineReadingError.isNull(), Q_FUNC_INFO,
                           qPrintable((QLatin1String("Reading the baseline failed: ") + baselineReadingError)));
            }

            if(isDeepEqual(output, baseline))
                return TestResult::Pass;
            else
            {
                pDebug() << "FAILURE:" << output.toString() << "is NOT IDENTICAL to(baseline):" << baseline.toString();
                return TestResult::Fail;
            }
        }
        case Ignore:
            return TestResult::Pass;
        case Inspect:
            return TestResult::NotTested;
        case ExpectedError:
        {
            /* This function is only called for Text/XML/Fragment tests. */
            return TestResult::Fail;
        }
    }
    Q_ASSERT(false);
    return TestResult::Fail;
}
예제 #7
0
파일: qnapiconfig.cpp 프로젝트: Fisiu/qnapi
void QNapiConfig::setShowDockIcon(bool show)
{
    QString infoPlistPath = QFileInfo(QApplication::applicationDirPath() + "/../Info.plist").canonicalFilePath();
    
    QFile plistFile(infoPlistPath);
    
    QDomDocument doc;
    if(!doc.setContent(&plistFile) || !doc.hasChildNodes())
        return;
    
    QDomNodeList nodes = doc.childNodes();
    
    QDomNode node;
    int i;
    for(i = 0; i < nodes.size(); ++i)
    {
        node = nodes.at(i);
        if(node.nodeName() == "plist")
            break;
    }
    
    if((i == nodes.size()) || !node.hasChildNodes())
        return;
    
    nodes = node.childNodes();
    
    for(i = 0; i < nodes.size(); ++i)
    {
        node = nodes.at(i);
        if(node.nodeName() == "dict")
            break;
    }
    
    if((i == nodes.size()) || !node.hasChildNodes())
        return;
    
    nodes = node.childNodes();
    
    for(i = 0; i < nodes.size(); ++i)
    {
        node = nodes.at(i);
        
        QString subText;
        
        if(node.hasChildNodes())
        {
            subText = node.childNodes().at(0).toText().data();
        }
        
        if(subText == "LSUIElement")
            break;
    }
    
    if(i >= nodes.size())
        return;
    
    node = node.nextSibling();
    
    node.toElement().setTagName(show ? "false" : "true");

    QString modifiedContent = doc.toString(4);

    plistFile.close();
    
    if(!plistFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
        return;

    QTextStream plistStream(&plistFile);
    
    plistStream << modifiedContent;
    
    plistFile.close();
    
}
예제 #8
0
파일: qnapiconfig.cpp 프로젝트: Fisiu/qnapi
bool QNapiConfig::showDockIcon()
{
    const bool show_default = true;
    
    QString infoPlistPath = QFileInfo(QApplication::applicationDirPath() + "/../Info.plist").canonicalFilePath();

    QFile plistFile(infoPlistPath);
    
    QDomDocument doc;
    if(!doc.setContent(&plistFile))
        return show_default;

    if(!doc.hasChildNodes())
        return show_default;

    QDomNodeList nodes = doc.childNodes();
    
    QDomNode node;
    int i;
    for(i = 0; i < nodes.size(); ++i)
    {
        node = nodes.at(i);
        if(node.nodeName() == "plist")
            break;
    }
    
    if(i == nodes.size())
        return show_default;

    if(!node.hasChildNodes())
        return show_default;

    nodes = node.childNodes();
    
    for(i = 0; i < nodes.size(); ++i)
    {
        node = nodes.at(i);
        if(node.nodeName() == "dict")
            break;
    }

    if(i == nodes.size())
        return show_default;
    
    if(!node.hasChildNodes())
        return show_default;
    
    nodes = node.childNodes();

    for(i = 0; i < nodes.size(); ++i)
    {
        node = nodes.at(i);

        QString subText;

        if(node.hasChildNodes())
        {
            subText = node.childNodes().at(0).toText().data();
        }

        if(subText == "LSUIElement")
            break;
    }

    if(i < nodes.size())
    {
        node = node.nextSibling();
        return (node.nodeName() != "true");
    }

    return show_default;
    
}