Esempio n. 1
0
bool							XMLParser::openFile(std::string filename)
{
  std::string				path;
  path = PATH;
  path += filename;
  std::cout << path << "\n";
  QDomDocument				doc(stdStringToQString(path));
  QFile					xmldoc(stdStringToQString(path));
  QString				error;
  int					errorLine;
  int					errorColumn;

  if (!xmldoc.open(QIODevice::ReadOnly))
    {
      print_error(" Xml Open file ");
      return (false);
    }
  _doc = doc;
  if (!_doc.setContent(&xmldoc, false, &error, &errorLine, &errorColumn))
    {
      xmldoc.close();
      print_error(" Link Xml file to DOM file ");
      std::cerr << error.toStdString() << "on line " << errorLine << " and column " << errorColumn << std::endl;
      return (false);
    }
  xmldoc.close();
  return (true);
}
Esempio n. 2
0
  boost::shared_ptr<XmlDoc> Protocol::create_doc ()
  {
    boost::shared_ptr<XmlDoc> xmldoc ( new XmlDoc("1.0", "UTF-8") );
    XmlDoc& doc = *xmldoc.get();

    // add root node
    XmlNode root = doc.add_node( Tags::node_doc() );

    root.set_attribute("version", "1.0");
    root.set_attribute("type", "message");

    return xmldoc;
  }
QString ExportHelper::generateXML(QString qtext, QString tableElemName, ParameterList &params, QString &errmsg, int xsltmapid)
{
  if (DEBUG)
    qDebug("ExportHelper::generateXML(%s..., %s, %d params, errmsg, %d) entered",
           qPrintable(qtext.left(80)), qPrintable(tableElemName),
           params.size(), xsltmapid);
  if (DEBUG)
  {
    QStringList plist;
    for (int i = 0; i < params.size(); i++)
      plist.append("\t" + params.name(i) + ":\t" + params.value(i).toString());
    qDebug("generateXML parameters:\n%s", qPrintable(plist.join("\n")));
  }

  QDomDocument xmldoc("xtupleimport");
  QDomElement rootelem = xmldoc.createElement("xtupleimport");
  xmldoc.appendChild(rootelem);

  if (! qtext.isEmpty())
  {
    MetaSQLQuery mql(qtext);
    XSqlQuery qry = mql.toQuery(params);
    if (qry.first())
    {
      do {
        QDomElement tableElem = xmldoc.createElement(tableElemName);

        if (DEBUG)
          qDebug("generateXML starting %s", qPrintable(tableElemName));
        for (int i = 0; i < qry.record().count(); i++)
        {
          QDomElement fieldElem = xmldoc.createElement(qry.record().fieldName(i));
          if (qry.record().value(i).isNull())
            fieldElem.appendChild(xmldoc.createTextNode("[NULL]"));
          else
            fieldElem.appendChild(xmldoc.createTextNode(qry.record().value(i).toString()));
          tableElem.appendChild(fieldElem);
        }
        rootelem.appendChild(tableElem);
      } while (qry.next());
    }
    if (qry.lastError().type() != QSqlError::NoError)
      errmsg = qry.lastError().text();
  }

  if (xsltmapid < 0)
    return xmldoc.toString();
  else
    return XSLTConvertString(xmldoc.toString(), xsltmapid, errmsg);
}
Esempio n. 4
0
QDomDocument ArchiveMan::archiveDocumentXml( KraftDoc *doc, const QString& archId )
{
    QDomDocument xmldoc( "kraftdocument" );
    QDomElement root = xmldoc.createElement( "kraftdocument" );
    // Fixme:
    xmldoc.appendChild( root );
    QDomElement cust = xmldoc.createElement( "client" );
    root.appendChild( cust );
    cust.appendChild( xmlTextElement( xmldoc, "address", doc->address() ) );
    cust.appendChild( xmlTextElement( xmldoc, "clientId", doc->addressUid() ) );

    QDomElement docElem = xmldoc.createElement( "docframe" );
    root.appendChild( docElem );
    docElem.appendChild( xmlTextElement( xmldoc, "docType", doc->docType() ) );
    docElem.appendChild( xmlTextElement( xmldoc, "docDesc", doc->whiteboard() ) );
    docElem.appendChild( xmlTextElement( xmldoc, "ident", doc->ident() ) );
    docElem.appendChild( xmlTextElement( xmldoc, "preText", doc->preText() ) );
    docElem.appendChild( xmlTextElement( xmldoc, "postText", doc->postText() ) );
    docElem.appendChild( xmlTextElement( xmldoc, "projectLabel", doc->projectLabel() ) );
    docElem.appendChild( xmlTextElement( xmldoc, "salut", doc->salut() ) );
    docElem.appendChild( xmlTextElement( xmldoc, "goodbye", doc->goodbye() ) );

    docElem.appendChild( xmlTextElement( xmldoc, "date",
                                         doc->locale()->formatDate( doc->date() ) ) );

    root.appendChild( doc->positions().domElement( xmldoc ) );

    QString xml = xmldoc.toString();
    // kDebug() << "Resulting XML: " << xml << endl;

    QString outputDir = ArchiveMan::self()->xmlBaseDir();
    QString filename = ArchiveMan::self()->archiveFileName( doc->ident(), archId, "xml" );

    QString xmlFile = QString( "%1/%2" ).arg( outputDir ).arg( filename );

    kDebug() << "Storing XML to " << xmlFile << endl;

    if ( KraftSettings::self()->doXmlArchive() ) {
        QFile file( xmlFile );
        if ( file.open( QIODevice::WriteOnly ) ) {
            QTextStream stream( &file );
            stream << xml << "\n";
            file.close();
        } else {
            kDebug() << "Saving failed" << endl;
        }
    }
    return xmldoc ;
}
Esempio n. 5
0
QString xTupleDesigner::name()
{
  QDomDocument xmldoc("UIFile");
  _source->reset();
  xmldoc.setContent(_source);
  QDomNode classnode = xmldoc.documentElement().firstChildElement("class");
  if (classnode.isNull())
  {
    qWarning("xTupleDesigner::name() classnode is null");
    return QString();
  }

  if (classnode.toElement().tagName() != "class")
  {
    qWarning("xTupleDesigner::name() first child %s, not a class element",
           qPrintable(classnode.toElement().tagName() ));
    return QString();
  }

  return classnode.toElement().text();
}
QString ExportHelper::generateXML(const int qryheadid, ParameterList &params, QString &errmsg, int xsltmapid)
{
  if (DEBUG)
    qDebug("ExportHelper::generateXML(%d, %d params, errmsg, %d) entered",
           qryheadid, params.size(), xsltmapid);
  if (DEBUG)
  {
    QStringList plist;
    for (int i = 0; i < params.size(); i++)
      plist.append("\t" + params.name(i) + ":\t" + params.value(i).toString());
    qDebug("generateXML parameters:\n%s", qPrintable(plist.join("\n")));
  }

  QDomDocument xmldoc("xtupleimport");
  QDomElement rootelem = xmldoc.createElement("xtupleimport");
  xmldoc.appendChild(rootelem);

  XSqlQuery itemq;
  QString tableElemName;
  QString schemaName;
  itemq.prepare("SELECT * FROM qryitem WHERE qryitem_qryhead_id=:id ORDER BY qryitem_order;");
  itemq.bindValue(":id", qryheadid);
  itemq.exec();
  while (itemq.next())
  {
    QString qtext;
    tableElemName = itemq.value("qryitem_name").toString();
    if (itemq.value("qryitem_src").toString() == "REL")
    {
      schemaName = itemq.value("qryitem_group").toString();
      qtext = "SELECT * FROM " +
              (schemaName.isEmpty() ? QString("") : schemaName + QString(".")) +
              itemq.value("qryitem_detail").toString();
    }
    else if (itemq.value("qryitem_src").toString() == "MQL")
    {
      QString tmpmsg;
      bool valid;
      qtext = MQLUtil::mqlLoad(itemq.value("qryitem_group").toString(),
                               itemq.value("qryitem_detail").toString(),
                               tmpmsg, &valid);
      if (! valid)
        errmsg = tmpmsg;
    }
    else if (itemq.value("qryitem_src").toString() == "CUSTOM")
      qtext = itemq.value("qryitem_detail").toString();

    if (! qtext.isEmpty())
    {
      MetaSQLQuery mql(qtext);
      XSqlQuery qry = mql.toQuery(params);
      if (qry.first())
      {
        do {
          QDomElement tableElem = xmldoc.createElement(tableElemName);

          if (DEBUG)
            qDebug("exportXML starting %s", qPrintable(tableElemName));
          if (! schemaName.isEmpty())
            tableElem.setAttribute("schema", schemaName);
          for (int i = 0; i < qry.record().count(); i++)
          {
            QDomElement fieldElem = xmldoc.createElement(qry.record().fieldName(i));
            if (qry.record().value(i).isNull())
              fieldElem.appendChild(xmldoc.createTextNode("[NULL]"));
            else
              fieldElem.appendChild(xmldoc.createTextNode(qry.record().value(i).toString()));
            tableElem.appendChild(fieldElem);
          }
          rootelem.appendChild(tableElem);
        } while (qry.next());
      }
      if (qry.lastError().type() != QSqlError::NoError)
        errmsg = qry.lastError().text();
    }
  }
  if (itemq.lastError().type() != QSqlError::NoError)
    errmsg = itemq.lastError().text();

  if (xsltmapid < 0)
    return xmldoc.toString();
  else
    return XSLTConvertString(xmldoc.toString(), xsltmapid, errmsg);
}