Exemplo n.º 1
0
void DialogEditNodeTable::LoadContent()
{
    //Load the element value
    m_pValueLine->setText(m_node.toElement().text());

    //Get all the attributes
    QDomNamedNodeMap attributes = m_node.attributes();

    m_pTable->setRowCount(attributes.size());

    QTableWidgetItem* item = 0;

    //Add each attribute in to the table
    for(int indexRow=0; indexRow < attributes.size(); ++indexRow)
    {
        int columnIndex = 0;

        QDomAttr attributeNode = attributes.item(indexRow).toAttr();

        item = new QTableWidgetItem(attributeNode.nodeName());// << attribute name
        item->setToolTip(attributeNode.nodeName());
        m_pTable->setItem(indexRow, columnIndex, item);
        columnIndex++;

        item = new QTableWidgetItem(attributeNode.nodeValue());// << value
        item->setToolTip(attributeNode.nodeValue());
        m_pTable->setItem(indexRow, columnIndex, item);
        columnIndex++;
    }

}
Exemplo n.º 2
0
QString ServiceDefinition::argumentType(const QString &serviceName,
                                        const QString &argument) const {
  QDomNode node = d->mInputArguments[serviceName][argument];

  if (node.hasAttributes()) {
    QDomAttr attr = d->getAttributeFromNode(node, "type");
    return attr.nodeValue();
  }

  return "";
}
Exemplo n.º 3
0
uint ServiceDefinition::requestType(const QString &name) const {
  QDomNode node = d->definitionsOfServiceName(name)["input"];
  QDomAttr attr = d->getAttributeFromNode(node, "type");

  QString value = attr.nodeValue();

  if (value.toLower() == "get") {
    return 0;
  }

  if (value.toLower() == "post") {
    return 1;
  }

  return -1;
}
Exemplo n.º 4
0
void Layer7::LoadSlot(QNetworkReply *reply) {

    switch (op) {

    case lsoStart:

        emit UpdateSignal("Loading started...");
        Logger::ins.Header() << "Loading registry data from " << http.Url() << "data/ started...\r\n";
        http.Propfind(http.Url() + "data/");
        op = lsoListDomains;

        break;

    case lsoListDomains:

        if (reply->error() == QNetworkReply::NoError) {

            QString replyString(reply->readAll());
            sl::log << "lsoListDomains: " << SQ(replyString) << sl::end;

            Propfinds elements = http.ParsePropfindReply(replyString);
            for (Propfinds::iterator e = elements.begin(); e != elements.end(); ++e)
                if (e->href != http.Url()) {
                    domains.push_back(GtDomain(SQ(e->href), SQ(e->name)));
                    Logger::ins.Info() << "Service domain: " << e->name << "\r\n";
                    emit UpdateSignal("Service Domain: " + e->name);
                }

            if (SelectFirstDomain()) {

                loaded = true;

                // check if all domains match domains from the db

                for (unsigned int d = 0; d < domains.size(); ++d)
                    if (!sdoms.contains(QS(domains[d].name))) {
                        loaded = false;
                        Logger::ins.Error() << "Repository does not contain service domain named " << QS(domains[d].name) << "\r\n";
                        emit DoneSignal("Repository does not contain service domain named " + QS(domains[d].name));
                    }

                if (loaded) {
                    op = lsoListServices;
                    http.Propfind(QS(SelectedDomain().href) + "web/");
                }
            }
        }
        else
            emit UpdateSignal(reply->errorString());

        break;

    case lsoListServices:

        if (reply->error() == QNetworkReply::NoError) {

            QString replyString(reply->readAll());
            sl::log << "lsoListServices: " << SQ(replyString) << sl::end;

            Propfinds elements = http.ParsePropfindReply(replyString);
            for (Propfinds::iterator e = elements.begin(); e != elements.end(); ++e)
                if (e->href != http.Url() && e->name != "OLD" && e->name != "REMOVED") {

                    endpoints.push_back(GtEndpoint(item++ * 100 + REPO_TB_IDX, SelectedDomain().name, SQ(e->href), SQ(e->name)));
                    Logger::ins.Info() << "Service: " << e->name << "\r\n";
                    emit UpdateSignal("Service: " + e->name);
                }
        }
        else
            emit UpdateSignal(reply->errorString());

        if (SelectNextDomain())
            http.Propfind(QS(SelectedDomain().href) + "web/");
        else if (SelectFirstEndpoint()) {
            Logger::ins.Info() << "Parsing index files...\r\n";
            emit UpdateSignal("Parsing index files...");
            op = lsoGetIndexXml;
            Logger::ins.Info() << "Parsing " << QS(SelectedEndpoint().urlRegistryFolder) << "index.xml...\r\n";
            http.Get(QS(SelectedEndpoint().urlRegistryFolder) + "index.xml");
        }

        break;

    case lsoGetIndexXml:

        if (reply->error() == QNetworkReply::NoError) {

            QString replyString(reply->readAll());
            sl::log << "lsoGetIndexXml: " << SQ(replyString) << sl::end;

            QDomDocument doc;
            doc.setContent(replyString);

            for (QDomElement r = doc.firstChildElement(); !r.isNull(); r = r.nextSiblingElement()) {

                if (r.nodeName() == "service") {

                    for (QDomElement e = r.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {

                        if (e.nodeName() == "files") {

                            for (QDomElement f = e.firstChildElement(); !f.isNull(); f = f.nextSiblingElement()) {

                                QDomAttr r = f.attributeNode("root"), t = f.attributeNode("type");
                                if (!r.isNull() && r.nodeValue() == "true" && !t.isNull() && t.value() == "WSDL")
                                    SelectedEndpoint().urlWSDL = SQ(f.text());
                            }
                        }
                        else if (e.nodeName() == "name")
                            SelectedEndpoint().intGivenName = SQ(e.text());
                        else if (e.nodeName() == "version")
                            SelectedEndpoint().intGivenVersion = SQ(e.text());
                        else if (e.nodeName() == "policyVersion")
                            SelectedEndpoint().policyVersion = SQ(e.text());
                        else if (e.nodeName() == "enabled")
                            SelectedEndpoint().enabled = SQ(e.text());
                        else if (e.nodeName() == "soap")
                            SelectedEndpoint().soap = SQ(e.text());
                        else if (e.nodeName() == "resolutionPath")
                            SelectedEndpoint().resolutionPath = SQ(e.text());
                        else if (e.nodeName() == "id")
                            SelectedEndpoint().intGivenId = SQ(e.text());
                        else if (e.nodeName() == "protectedEndpoint")
                            SelectedEndpoint().protectedEndpoint = SQ(e.text());
                    }

                    break;
                }
            }

            if (SelectedEndpoint().urlWSDL == "") {
                Logger::ins.Warning() << "WSDL file url not found for endpoint '" << QS(SelectedEndpoint().intGivenName) << "'\r\n";
                emit UpdateSignal("WSDL file url not found for endpoint '" + QS(SelectedEndpoint().intGivenName) + "'");
                SelectedEndpoint().serviceName = SelectedEndpoint().intGivenName;
            }

            if (SelectedEndpoint().protectedEndpoint == "") {
                Logger::ins.Warning() << "Ignoring non-protected endpoint '" << QS(SelectedEndpoint().intGivenName) << "'\r\n";
                emit UpdateSignal("Ignoring non-protected endpoint '" + QS(SelectedEndpoint().intGivenName) + "'");
                RemoveSelectedEndpoint();
            }
        }
        else {
            Logger::ins.Error() << reply->errorString() << "\r\n";
            emit UpdateSignal(reply->errorString());
        }

        if (SelectNextEndpoint()) {
            Logger::ins.Info() << "Parsing " << QS(SelectedEndpoint().urlRegistryFolder) << "index.xml...\r\n";
            http.Get(QS(SelectedEndpoint().urlRegistryFolder) + "index.xml");
        }
        else if (SelectFirstEndpoint()) {
            Logger::ins.Info() << "Parsing WSDL files...\r\n";
            emit UpdateSignal("Parsing WSDL files...");
            op = lsoGetWsdl;
            Logger::ins.Info() << "Parsing " << QS(SelectedEndpoint().urlRegistryFolder + SelectedEndpoint().urlWSDL) << "\r\n";
            http.Get(QS(SelectedEndpoint().urlRegistryFolder + SelectedEndpoint().urlWSDL));
        }

        break;

    case lsoGetWsdl:

        if (reply->error() == QNetworkReply::NoError) {

            QString replyString(reply->readAll());
            sl::log << "lsoGetWsdl: " << SQ(replyString) << sl::end;

            QDomDocument doc;
            doc.setContent(replyString);

            for (QDomElement r = doc.firstChildElement(); !r.isNull(); r = r.nextSiblingElement()) {
                if (r.nodeName() == "definitions" || r.nodeName() == "wsdl:definitions") {

                    QDomAttr n = r.attributeNode("targetNamespace");
                    if (!n.isNull())
                        SelectedEndpoint().targetNamespace = SQ(n.nodeValue());

                    n = r.attributeNode("name");
                    if (!n.isNull())
                        SelectedEndpoint().definitionName = SQ(n.nodeValue());

                    // find all service names

                    std::vector<std::string> serviceNames;
                    for (QDomElement e = r.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {

                        if (e.nodeName() == "service" || e.nodeName() == "wsdl:service") {
                            QDomAttr a = e.attributeNode("name");
                            if (!a.isNull())
                                serviceNames.push_back(SQ(a.nodeValue()));
                        }
                    }

                    // assign service name

                    if (serviceNames.size() == 1)
                        SelectedEndpoint().serviceName = serviceNames[0];
                    else if (serviceNames.size() > 1) {

                        // search service node name with best fit to protected endpoint string

                        std::map<int, std::string> m;
                        for (std::vector<std::string>::iterator s = serviceNames.begin(); s != serviceNames.end(); ++s)
                            m.insert(std::pair<int, std::string>(LevenshteinDistance(SelectedEndpoint().protectedEndpoint, *s, true), *s));

                        SelectedEndpoint().serviceName = m.begin()->second;
                    }
                    else {
                        Logger::ins.Warning() << "Service name not found for endpoint '" << QS(SelectedEndpoint().intGivenName) + "'\r\n";
                        emit UpdateSignal("Service name not found for endpoint '" + QS(SelectedEndpoint().intGivenName) + "'");
                        SelectedEndpoint().serviceName = SelectedEndpoint().intGivenName;
                    }

                    break;
                }
            }
        }
        else {
            Logger::ins.Error() << reply->errorString() << "\r\n";
            emit UpdateSignal(reply->errorString());
        }

        if (SelectNextEndpoint()) {
            Logger::ins.Info() << "Parsing " << QS(SelectedEndpoint().urlRegistryFolder + SelectedEndpoint().urlWSDL) << "\r\n";
            http.Get(QS(SelectedEndpoint().urlRegistryFolder + SelectedEndpoint().urlWSDL));
        }
        else {
            Logger::ins.Info() << "Finished loading registry.\r\n";
            emit DoneSignal("Finished loading.");
        }

        break;

    default:
        ;
    }
}
Exemplo n.º 5
0
/*
  This will go through and modify some of the ENML tags and turn
  them into HTML tags.  Things like en-media & en-crypt have no
  HTML values, so we turn them into HTML.
  */
void NoteFormatter::modifyTags(QDomDocument &doc) {
    QLOG_TRACE() << "Entering NeverNote.modifyTags";
    tempFiles.clear();
    QDomElement docElem = doc.documentElement();

    // Modify en-media tags
    QDomNodeList anchors = docElem.elementsByTagName("en-media");
    qint32 enMediaCount = anchors.length();
    for (qint32 i=enMediaCount-1; i>=0; --i) {
            QDomElement enmedia = anchors.at(i).toElement();
            if (enmedia.hasAttribute("type")) {
                    QDomAttr attr = enmedia.attributeNode("type");
                    QDomAttr hash = enmedia.attributeNode("hash");
                    QStringList type = attr.nodeValue().split("/");
                    if (type.size() >= 2) {
                        QString appl = type[1];
                        if (type[0] == "image")
                            modifyImageTags(doc, docElem, enmedia, hash);
                        else
                            modifyApplicationTags(doc, docElem, enmedia, hash, appl);
                    }
            }
    }

    // Modify todo tags
    anchors = docElem.elementsByTagName("en-todo");
    qint32 enTodoCount = anchors.length();
    for (qint32 i=enTodoCount-1; i>=0; i--) {
            QDomElement enmedia = anchors.at(i).toElement();
            modifyTodoTags(enmedia);
    }

    anchors = docElem.elementsByTagName("en-crypt");
    qint32 enCryptLen = anchors.length();
    for (qint32 i=enCryptLen-1; i>=0; i--) {
            QDomElement enmedia(anchors.at(i).toElement());
            enmedia.setAttribute("contentEditable","false");
            enmedia.setAttribute("src", QString("file://")+global.fileManager.getImageDirPath("encrypt.png"));
            enmedia.setAttribute("en-tag","en-crypt");
            enmedia.setAttribute("alt", enmedia.text());
            global.cryptCounter++;
            enmedia.setAttribute("id", "crypt"+QString().number(global.cryptCounter));
            QString encryptedText = enmedia.text();

            // If the encryption string contains crlf at the end, remove them because they mess up the javascript.
            if (encryptedText.endsWith("\n"))
                    encryptedText.truncate(encryptedText.length()-1);
            if (encryptedText.endsWith("\r"))
                    encryptedText.truncate(encryptedText.length()-1);

            // Add the commands
            QString hint = enmedia.attribute("hint");
            hint = hint.replace("'","&apos;");
            enmedia.setAttribute("onClick", "window.jsbridge.decryptText('crypt"+QString().number(global.cryptCounter)+"', '"+encryptedText+"', '"+hint+"');");
            enmedia.setAttribute("onMouseOver", "style.cursor='hand'");
            enmedia.setTagName("img");
            enmedia.removeChild(enmedia.firstChild());   // Remove the actual encrypted text
    }


    // Modify link tags
    anchors = docElem.elementsByTagName("a");
    enCryptLen = anchors.length();
    for (unsigned int i=0; i<anchors.length(); i++) {
            QDomElement element = anchors.at(i).toElement();
            if (!element.attribute("href").toLower().startsWith("latex://"))
                    element.setAttribute("title", element.attribute("href"));
            else {
                    element.setAttribute("title", element.attribute("title").toLower().replace("http://latex.codecogs.com/gif.latex?",""));
            }
    }

    QLOG_TRACE() << "Leaving NeverNote.modifyTags";
}