Esempio n. 1
0
Param BaseWithParamList::addParam()
{
    AddParam *command = new AddParam();
    command->setData(m_DomElement);
    xmlData()->commandList()->add(command);
    return Param(command->result(), xmlData());
}
Esempio n. 2
0
QString XSLTransformer::transform(const QString &xml, QHash<QString, QString> const &params) const
{
    // Read XML data intro an xmlDoc.
    QByteArray xmlData(xml.toUtf8());
    QScopedPointer<xmlDoc, XmlDocDeleter> doc(
        xmlReadMemory(xmlData.constData(), xmlData.size(), 0, 0, 0));

    if (!doc)
        throw std::runtime_error("XSLTransformer::transform: Could not open XML data");

    // Hmpf, data conversions.
    char const **cParams = new char const *[params.size() * 2 + 1];
    int i = 0;
    for (QHash<QString, QString>::const_iterator iter = params.constBegin();
        iter != params.constEnd(); ++iter)
    {
        QByteArray keyData(iter.key().toUtf8());
        QByteArray valueData(iter.value().toUtf8());

        char const *cKey = strdup(keyData.constData());
        char const *cValue = strdup(valueData.constData());

        cParams[i] = cKey;
        cParams[i + 1] = cValue;

        i += 2;
    }

    cParams[params.size() * 2] = 0; // Terminator

    QScopedPointer<xsltTransformContext, XsltTransformContextDeleter> ctx(
        xsltNewTransformContext(d_xslPtr.data(), doc.data()));
    xsltSetCtxtParseOptions(ctx.data(), XSLT_PARSE_OPTIONS);

    // Transform...
    QScopedPointer<xmlDoc, XmlDocDeleter> res(
        xsltApplyStylesheetUser(d_xslPtr.data(), doc.data(), cParams, NULL, NULL, ctx.data()));

    if (!res)
        throw std::runtime_error("XSLTransformer::transform: Could not apply transformation!");
    else if (ctx->state != XSLT_STATE_OK)
        throw std::runtime_error("XSLTransformer::transform: Transformation error, check your query!");

    xmlChar *outputBare = 0;
    int outputLen = -1;
    xsltSaveResultToString(&outputBare, &outputLen, res.data(), d_xslPtr.data());
    QScopedPointer<xmlChar, XmlDeleter> output(outputBare);

    if (!output)
        throw std::runtime_error("Could not apply stylesheet!");

    QString result(QString::fromUtf8(reinterpret_cast<char const *>(output.data())));

    // Deallocate parameter memory
    for (int i = 0; i < params.size() * 2; ++i)
        free(const_cast<char *>(cParams[i]));
    delete[] cParams;

    return result;
}
Esempio n. 3
0
void Configuration::getConfigDocument(std::string pathConfigFile)
{
    std::basic_ifstream< char > xmlFile(pathConfigFile.c_str());

    if (!xmlFile.fail())
    {
        xmlFile.seekg(0, std::ios::end);
        unsigned int size = (unsigned int) xmlFile.tellg();
        xmlFile.seekg(0);

        std::vector< char > xmlData(size + 1);
        xmlData[size] = 0;

        xmlFile.read(&xmlData.front(), (std::streamsize) size);
        xmlFile.close();
        m_strConfigData = std::string(xmlData.data());

        try
        {
            m_xmlDoc.parse< 0 >((char *) m_strConfigData.c_str());
            m_loaded = true;
        }
        catch (rapidxml::parse_error &e)
        {
            OC_LOG(ERROR, CONTAINER_TAG, "xml parsing failed !!");
            OC_LOG_V(ERROR, CONTAINER_TAG, "Exception (%s)", e.what());
        }
    }
    else
    {
        OC_LOG(ERROR, CONTAINER_TAG, "Configuration File load failed !!");
    }
}
Esempio n. 4
0
void NMTaskStat::run()
{
	NMModuleInterface *interface = (NMModuleManager::self()->getModule( plugin()))->findPluginInterface( testId());
	if( !interface) {
		//TODO Tractament d'errors amb la Gui
		cerr << "NMTaskStat run failed: " << plugin()  << " " <<  testId() << " interface don't exsist" << endl;
		return;
	}
	interface->status(xmlData());
}
Esempio n. 5
0
list<Param> BaseWithParamList::paramList() const
{
    if(isNull()) return list<Param>();
    list<Param> result;
    list<DomElement> elementList = m_DomElement.elementsByTagName(Param::NAME);
    for(list<DomElement>::iterator i = elementList.begin(); i != elementList.end(); i++)
    {
        result.push_back(Param(*i, xmlData()));
    }
    return result;
}
Esempio n. 6
0
int processManifestXML() {
    QFile xmlManifest(vManifestXML);
    QFile xmlData(vDatafileXML);
    QFile sqlInsertsFile(vSqlInsertsFile);

    //Open the manifest file and put the contents in a DOM document
    if (!xmlManifest.open(QIODevice::ReadOnly))
        return 1;

    if (!manifestDoc.setContent(&xmlManifest)) {
        xmlManifest.close();
        return 1;
    }

    xmlManifest.close();

    //Open the xml data file and put the contents in a DOM document
    if (!xmlData.open(QIODevice::ReadOnly))
        return 1;

    if (!dataDoc.setContent(&xmlData)) {
        xmlData.close();
        return 1;
    }

    xmlData.close();

    //Open text file for writing
    if (!sqlInsertsFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
        return 1;
    }
    QTextStream out(&sqlInsertsFile);

    //Get the list of table nodes from the manifest
    tableNodesList = manifestDoc.elementsByTagName("table");

    //Get nodes list for the data
    dataNodesList = dataDoc.elementsByTagName(vDatafileBaseNode);

    //Start the data processing
    processTables(tableNodesList.item(0), dataNodesList.item(0));

    //Write the string to the file and close the file
    out << str;
    sqlInsertsFile.close();

    return 0;

}
Esempio n. 7
0
void IconManager::readIconConfigFiles()
{
	QString baseIconDir(ScPaths::instance().iconDir());
	QStringList locations;
	locations<<baseIconDir;
	QStringList configNames;
	for ( QStringList::Iterator it = locations.begin(); it != locations.end(); ++it )
	{
		QFileInfo iconDir(*it);
		if (!iconDir.exists())
			continue;
		QDir id(*it, "*.xml", QDir::Name, QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files | QDir::NoSymLinks);
		if (!id.exists() || (id.count() == 0))
			continue;
		for (uint i = 0; i < id.count(); ++i)
		{
			QFileInfo file(*it + id[i]);
			//qDebug()<<file.absoluteFilePath();
			QFile dataFile(file.absoluteFilePath());
			if (!dataFile.exists())
				continue;
			dataFile.open(QIODevice::ReadOnly);
			QTextStream ts(&dataFile);
			ts.setCodec(QTextCodec::codecForName("UTF-8"));
			QString errorMsg;
			int eline;
			int ecol;
			QDomDocument xmlData( QString(file.baseName()));
			QString data(ts.readAll());
			dataFile.close();
			if ( !xmlData.setContent( data, &errorMsg, &eline, &ecol ))
			{
				qDebug()<<data<<errorMsg<<eline<<ecol;
				if (data.toLower().contains("404 not found"))
					qDebug()<<"File not found on server";
				else
					qDebug()<<"Could not open file"<<dataFile.fileName();
				continue;
			}
			QDomElement docElem = xmlData.documentElement();
			QDomNode n = docElem.firstChild();
			ScIconSetData isd;
			while( !n.isNull() )
			{
				QDomElement e = n.toElement();
				if( !e.isNull() )
				{
					//qDebug()<<e.tagName()<<e.text();
					if (e.tagName()=="path")
					{
						isd.path=e.text();
					}
					else
					if (e.tagName()=="author")
					{
						isd.author=e.text();
					}
					else
					if (e.tagName()=="license")
					{
						isd.license=e.text();
					}
					else
					if (e.tagName()=="activeversion")
					{
						isd.activeversion=e.text();
					}
					else
					if (e.tagName()=="nametext")
					{
						if (e.hasAttribute("lang"))
						{
							isd.nameTranslations.insert(e.attribute("lang"),e.text());
							if (e.attribute("lang")=="en_US")
								isd.baseName=e.text();
						}
					}
				}
				n = n.nextSibling();
			}
			//just in case there's no en_US basename
			if (!isd.baseName.isEmpty())
			{

				m_iconSets.insert(isd.baseName, isd);
				if(!isd.activeversion.isEmpty())
				{
					int av_major, av_minor, av_patch, curr_major, curr_minor, curr_patch, ver_major, ver_minor, ver_patch;
					av_major=isd.activeversion.section(".",0,0).toInt();
					av_minor=isd.activeversion.section(".",1,1).toInt();
					av_patch=isd.activeversion.section(".",2,2).toInt();
					curr_major=m_activeSetVersion.section(".",0,0).toInt();
					curr_minor=m_activeSetVersion.section(".",1,1).toInt();
					curr_patch=m_activeSetVersion.section(".",2,2).toInt();
					ver_major=QString(VERSION).section(".",0,0).toInt();
					ver_minor=QString(VERSION).section(".",1,1).toInt();
					ver_patch=QString(VERSION).section(".",2,2).toInt();
					//If iconset version <= app version, and iconset version >= current active iconset version
					if (av_major<=ver_major &&
						av_minor<=ver_minor &&
						av_patch<=ver_patch &&
						(
						av_major>=curr_major ||
						(av_major==curr_major && av_minor>=curr_minor) ||
						(av_major==curr_major && av_minor==curr_minor && av_patch>=curr_patch)
						)
						)
					{
						m_backupSetBasename=m_activeSetBasename;
						m_backupSetVersion=m_backupSetVersion;
						m_activeSetBasename=isd.baseName;
						m_activeSetVersion=isd.activeversion;
						//qDebug()<<"backupSetBasename"<<m_backupSetBasename<<"activeSetBasename"<<m_activeSetBasename;
					}
				}
			}
		}
	}
}
Esempio n. 8
0
void RemoteArchiveModel::replyFinished(QNetworkReply *reply)
{
    d_corpora.clear();
    emit layoutChanged();
    
    QNetworkReply::NetworkError error = reply->error();
    if (error != QNetworkReply::NoError)
    {
        QString errorValue(networkErrorToString(error));
        
        emit networkError(errorValue);
        
        reply->deleteLater();
        
        return;
    }
    
    QByteArray xmlData(reply->readAll());
    QScopedPointer<xmlDoc, XmlDocDeleter> xmlDoc(
        xmlReadMemory(xmlData.constData(), xmlData.size(), 0, 0, 0));
    if (xmlDoc == 0) {
        emit processingError("could not parse the corpus archive index.");
        return;
    }
    
    xmlNodePtr root = xmlDocGetRootElement(xmlDoc.data());
    if (QString::fromUtf8(reinterpret_cast<char const *>(root->name)) !=
        QString("corpusarchive")) {
        emit processingError("the corpus archive index has an incorrect root node.");
        return;
    }
    
    for (xmlNodePtr child = root->children; child != 0; child = child->next)
    {
        if (QString::fromUtf8(reinterpret_cast<char const *>(child->name)) !=
            QString("corpus"))
            continue;
        
        QString name(childValue(xmlDoc.data(), child->children, reinterpret_cast<xmlChar const *>("filename")));

        if (name.isNull())
            continue;
        
        // Chop the extension, we do not want to bother users.
        if (name.endsWith(DOWNLOAD_EXTENSION))
            name.chop(DOWNLOAD_EXTENSION.length());
        
        // Retrieve and verify file size.
        QString fileSizeStr = childValue(xmlDoc.data(), child->children, reinterpret_cast<xmlChar const *>("filesize"));
        if (fileSizeStr.isNull())
            continue;

        // Attempt to convert the size to a number.
        bool ok = true;
        size_t fileSize = fileSizeStr.toULong(&ok);
        if (!ok)
            continue;
        
        double fileSizeMB = fileSize / (1024 * 1024);
        
        RemoteArchiveEntry corpus;
        corpus.name = name;
        corpus.sentences = childValue(xmlDoc.data(), child->children, reinterpret_cast<xmlChar const *>("sentences")).toULong();
        corpus.size = fileSizeMB;
        corpus.description = childValue(xmlDoc.data(), child->children, reinterpret_cast<xmlChar const *>("shortdesc"));
        corpus.longDescription = childValue(xmlDoc.data(), child->children, reinterpret_cast<xmlChar const *>("desc")).trimmed();
        corpus.checksum = childValue(xmlDoc.data(), child->children, reinterpret_cast<xmlChar const *>("sha1"));
        
        d_corpora.push_back(corpus);        
    }

    emit layoutChanged();
    
    emit retrievalFinished();

    reply->deleteLater();
}
bool DBusObjectManager::onIntrospectableInterfaceDBusMessage(const DBusMessage& dbusMessage) {
    std::shared_ptr<DBusProxyConnection> dbusConnection = dbusConnection_.lock();

    if (!dbusConnection || !dbusMessage.isMethodCallType() || !dbusMessage.hasMemberName("Introspect")) {
        return false;
    }

    bool foundRegisteredObjects = false;
    std::stringstream xmlData(std::ios_base::out);

    xmlData << "<!DOCTYPE node PUBLIC \"" DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER "\"\n\""
                    DBUS_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER"\">\n"
                    "<node name=\"" << dbusMessage.getObjectPath() << "\">\n"
                        "<interface name=\"org.freedesktop.DBus.Introspectable\">\n"
                            "<method name=\"Introspect\">\n"
                                "<arg type=\"s\" name=\"xml_data\" direction=\"out\"/>\n"
                            "</method>\n"
                        "</interface>\n";

    std::unordered_set<std::string> nodeSet;
    for (auto& registeredObjectsIterator : dbusRegisteredObjectsTable_) {
        const DBusInterfaceHandlerPath& handlerPath = registeredObjectsIterator.first;
        const std::string& dbusObjectPath = handlerPath.first;
        const std::string& dbusInterfaceName = handlerPath.second;
        std::shared_ptr<DBusInterfaceHandler> dbusStubAdapterBase = registeredObjectsIterator.second;
        std::vector<std::string> elems = CommonAPI::split(dbusObjectPath, '/');

        if (dbusMessage.hasObjectPath(dbusObjectPath)) {
            foundRegisteredObjects = true;

            xmlData << "<interface name=\"" << dbusInterfaceName << "\">\n"
                            << dbusStubAdapterBase->getMethodsDBusIntrospectionXmlData() << "\n"
                            "</interface>\n";
            nodeSet.insert(elems.back());
        } else {
            if (dbusMessage.hasObjectPath("/") && elems.size() > 1) {
                if (nodeSet.find(elems[1]) == nodeSet.end()) {
                    if (nodeSet.size() == 0) {
                        xmlData.str("");
                        xmlData << "<!DOCTYPE node PUBLIC \"" DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER "\"\n\""
                        DBUS_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER"\">\n"
                        "<node>\n";
                    }
                    xmlData << "    <node name=\"" << elems[1] << "\"/>\n";
                    nodeSet.insert(elems[1]);
                    foundRegisteredObjects = true;
                }
            } else {
                for (unsigned int i = 1; i < elems.size() - 1; i++) {
                    std::string build;
                    for (unsigned int j = 1; j <= i; j++) {
                        build = build + "/" + elems[j];
                        if (dbusMessage.hasObjectPath(build)) {
                            if (nodeSet.find(elems[j + 1]) == nodeSet.end()) {
                                if (nodeSet.size() == 0) {
                                    xmlData.str("");
                                    xmlData << "<!DOCTYPE node PUBLIC \"" DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER "\"\n\""
                                            DBUS_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER"\">\n"
                                            "<node>\n";
                                }
                                xmlData << "    <node name=\"" << elems[j + 1] << "\"/>\n";
                                nodeSet.insert(elems[j + 1]);
                                foundRegisteredObjects = true;
                            }
                            break;
                        }
                    }
                }
            }
        }
    }

    if (foundRegisteredObjects) {
        DBusMessage dbusMessageReply = dbusMessage.createMethodReturn("s");
        DBusOutputStream dbusOutputStream(dbusMessageReply);

        xmlData << "</node>"
                        "";

        dbusOutputStream << xmlData.str();
        dbusOutputStream.flush();

        return dbusConnection->sendDBusMessage(dbusMessageReply);
    }

    return false;
}
Esempio n. 10
0
Param BaseWithParamList::paramAt(int index) const
{
    return Param(m_DomElement.elementByTagNameAndIndex(Param::NAME, index), xmlData());
}
Esempio n. 11
0
void SessionSaver::Save_Session()
{

    QFile xmlFile2(filename_);

    // We use template file to create the final xml.
    QFile xmlFile("UDP_session_template.xml");
    xmlFile.open(QIODevice::ReadWrite);

    // Make dom document from the template
    QByteArray xmlData(xmlFile.readAll());
    QDomDocument doc;
    doc.setContent(xmlData);

    QDomElement root = doc.documentElement();
    QDomElement sess_var_node = root.firstChildElement("RUGE_SESSION_VARIABLES");
    QList<rugeVariable>* sessionVariables = session_->getVariables();

    // Add the session variables to the RUGE_SESSION_VARIABLES
    for(int i = 0; i < sessionVariables->size(); i++){
       QDomElement ui = doc.createElement("RUGE_SESSION_VARIABLE ");
       ui.setAttribute("MAX", sessionVariables->at(i).max);
       ui.setAttribute("MIN", sessionVariables->at(i).min);
       ui.setAttribute("TYPE",sessionVariables->at(i).type);
       ui.setAttribute("LOOP_INCREMENT",sessionVariables->at(i).loopIncrement);
       ui.setAttribute("DEFAULT",sessionVariables->at(i).value);
       ui.setAttribute("INCREMENT",sessionVariables->at(i).increment);
       ui.setAttribute("SIZE",sessionVariables->at(i).size);
       ui.setAttribute("VARIABLE",sessionVariables->at(i).name);
       sess_var_node.appendChild(ui);
    }

    QDomElement sess_cont_msgs = root.firstChildElement("RUGE_SESSION_CONTROL_MESSAGES");
    QDomElement sess_cont_mes = sess_cont_msgs.firstChildElement("RUGE_SESSION_CONTROL_MESSAGE");

    // Save the ip version and protocol
    QDomElement sess_cont_mesg_head_stk = sess_cont_mes.firstChildElement("RUGE_SESSION_CONTROL_MESSAGE_HEADERS_STACK");
    sess_cont_mesg_head_stk.setAttribute("Protocol_1",session_->getipVersion());
    sess_cont_mesg_head_stk.setAttribute("Protocol_2",session_->getProtocol());

    // Save the RUGE_SESSION_CONTROL_MESSAGE_HEADER_VARIABLES
    for(int i = 0; i < sessionVariables->size(); i++){
        QDomElement ui = doc.createElement("RUGE_SESSION_CONTROL_MESSAGE_HEADER_VARIABLES");
        ui.setAttribute("OFFSET", sessionVariables->at(i).offset);
        ui.setAttribute("VARIABLE", sessionVariables->at(i).name);
        sess_cont_mes.appendChild(ui);
    }


    // Save the payload.
    QDomElement ref_data = sess_cont_mes.firstChildElement("RUGE_SESSION_CONTROL_MESSAGE_HEADER_REFERENCE_DATA");
    QString s=ref_data.attribute("VALUE");
    QString value = s + QString::fromLatin1(session_->getPayload().toLatin1().toHex());
    ref_data.setAttribute("LENGTH",value.length());
    ref_data.setAttribute("VALUE",  value);

    QDomElement sess_interfaces = root.firstChildElement("RUGE_SESSION_INTERFACES");
    QDomElement sess_interface = sess_interfaces.firstChildElement("RUGE_SESSION_INTERFACE");

    // Save this file to the filename.
    xmlFile2.open(QIODevice::ReadWrite);
    xmlFile2.resize(0);
    QTextStream stream;
    stream.setDevice(&xmlFile2);
    doc.save(stream, 4);
    xmlFile.close();
    xmlFile2.close();
}