Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Classes | Functions
desaxe_test.cpp File Reference
#include <iostream.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qdom.h>
#include "digester.h"
#include "actions.h"
#include "simple_actions.h"

Go to the source code of this file.

Classes

class  ELEM

Functions

void dummyDoc (desaxe::Digester &dig)
bool loadRawText (const QString &filename, QCString &buf)
 Replacement version of loadText that returns a QCString as an out parameter.
int main (int argc, char **argv)

Function Documentation

void dummyDoc ( desaxe::Digester dig)

Definition at line 70 of file desaxe_test.cpp.

{
       dig.reset();
       
       Xml_attr attr;
       dig.begin("doc", attr);
       attr["level"] = "1";
       dig.chars("aha.");
       dig.begin("elem", attr);
       attr["level"] = "2";
       dig.chars("soso.");
       dig.begin("elem", attr);
       attr["level"] = "3";
       dig.chars("alpha ");
       dig.end("elem");
       dig.chars("bravo ");
       dig.end("elem");
       dig.chars("charly ");
       attr["level"] = "2";
       attr["test"] = "bingo";
       dig.begin("elem", attr);
       dig.chars("delta ");
                      attr["level"] = "3";
                dig.begin("elem", attr);
                   dig.chars("echo ");
                            dig.end("elem");
                            dig.chars("foxtrott ");     
                            dig.end("elem");
                            attr["test"] = "naja";
                            dig.chars("golf ");
                            attr["level"] = "2";
                            dig.begin("elem", attr);
                            dig.chars("hotel ");
                            attr["level"] = "3";
                            dig.begin("elem", attr);
                            dig.chars("india ");
                            dig.end("elem");
                            dig.chars("juliet ");
                            dig.end("elem");
                            dig.chars("kilo ");
                            dig.end("doc");
}                           

Here is the call graph for this function:

Here is the caller graph for this function:

bool loadRawText ( const QString &  filename,
QCString &  buf 
)

Replacement version of loadText that returns a QCString as an out parameter.

The QCString is filled with the contents of the specified file. The return byte string is of unknown encoding; the caller must handle encoding issues. There is no need to preallocate the buffer, and the new data replaces any old contents.

Definition at line 113 of file desaxe_test.cpp.

{
       bool ret = false;
       QFile f(filename);
       QFileInfo fi(f);
       if (fi.exists())
       {
              QCString tempBuf(f.size() + 1);
              if (f.open(IO_ReadOnly))
              {
                     unsigned int bytesRead = f.readBlock(tempBuf.data(), f.size());
                     tempBuf[bytesRead] = '\0';
                     ret = bytesRead == f.size();
                     if (ret)
                            buf = tempBuf; // sharing makes this efficient
              }
       }
       if (f.isOpen())
              f.close();
       return ret;
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 136 of file desaxe_test.cpp.

{
       using namespace desaxe;
       
       Digester dig;
       Action fac = FactoryWithName<ELEM>();
       Action s_attr = SetAttributes<ELEM>( & ELEM::setAttribute );
       Action res = Result<ELEM>();
       Action set  = SetterP<ELEM, ELEM>( & ELEM::addElem );
       Action txt = AddText<ELEM>( & ELEM::addText );
       
       dig.addRule("*",fac);
       dig.addRule("*",s_attr);
       dig.addRule("*",txt);
       dig.addRule("/*",res);
       dig.addRule("*/*", set);
       
       if (argc < 2) {
              dummyDoc(dig);
              dig.result<ELEM>()->print();
       }
       else {
              const char* file = argc == 2? "Dokument-1.xml" : argv[2];
              switch (QString(argv[1]).toInt()) {
                     case 1:
                            dig.parseFile(file);
                            break;
                     case 2:
                     {
                            QCString docBytes("");
                            loadRawText(file, docBytes);
                            QDomDocument docu("scridoc");
                            return docu.setContent(QString(docBytes));
                     }
                     default:
                            dig.parseFile(file);
                            dig.result<ELEM>()->print();
              }
       }      
}

Here is the call graph for this function: