Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Public Member Functions | Private Member Functions | Private Attributes
SaxXML Class Reference

#include <saxXML.h>

Inheritance diagram for SaxXML:
Inheritance graph
[legend]
Collaboration diagram for SaxXML:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SaxXML (std::ostream &file, bool pretty=false)
 SaxXML (const char *filename, bool pretty=false)
 ~SaxXML ()
void beginDoc ()
void endDoc ()
void begin (const Xml_string &tag, Xml_attr attr)
void end (const Xml_string &tag)
void chars (const Xml_string &text)
void beginEnd (const Xml_string &tag, Xml_attr attr)

Private Member Functions

void finalizePendingEmptyTag ()

Private Attributes

std::ofstream m_file
std::ostream & m_stream
bool m_pretty
int m_indentLevel
bool m_manyAttributes
bool pendingEmptyTag

Detailed Description

Definition at line 18 of file saxXML.h.


Constructor & Destructor Documentation

SaxXML::SaxXML ( std::ostream &  file,
bool  pretty = false 
)

Definition at line 16 of file saxXML.cpp.

                                            : m_stream(file), 
     m_pretty(pretty), m_indentLevel(0), pendingEmptyTag(false) {} 
SaxXML::SaxXML ( const char *  filename,
bool  pretty = false 
)

Definition at line 19 of file saxXML.cpp.

                                                : m_file(filename, ios::out | ios::binary), m_stream(m_file), 
     m_pretty(pretty), m_indentLevel(0), pendingEmptyTag(false) {}

Definition at line 22 of file saxXML.cpp.

{ m_stream.flush(); m_file.close(); }

Member Function Documentation

void SaxXML::begin ( const Xml_string tag,
Xml_attr  attr 
) [virtual]

Implements SaxHandler.

Definition at line 53 of file saxXML.cpp.

{
       finalizePendingEmptyTag();
       assert( !tag.isNull() );
       if (m_pretty)
       {
              // indent tag
              m_stream << "\n";
              for (int k=0; k < m_indentLevel*4; ++k)
                     m_stream << " ";
       }
       m_stream << "<" << tag;
       Xml_attr::iterator it;
       m_manyAttributes = false;
       uint i = 0;
       for (it=attr.begin(); it != attr.end(); ++it) {
              // newline and indent every 4 attributes
              if (i > 0 && (i%4)==0 && m_pretty)
              {
                     m_stream << "\n";
                     for (uint k=0; k < m_indentLevel*4 + 1 + tag.length(); ++k)
                            m_stream << " ";
                     m_manyAttributes = true;
              }
              ++i;
              if (Xml_data(it).isNull())
                     m_stream << " " << Xml_key(it) << "=\"\"";
              else 
                     m_stream << " " << Xml_key(it) << "=\"" << Xml_data(it) << "\"";
       }
       pendingEmptyTag = true;
       ++m_indentLevel;
}

Here is the call graph for this function:

void SaxXML::beginDoc ( ) [virtual]

Implements SaxHandler.

Definition at line 24 of file saxXML.cpp.

{
       m_stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
}
void SaxHandler::beginEnd ( const Xml_string tag,
Xml_attr  attr 
) [inline, inherited]

Definition at line 32 of file saxhandler.h.

{
       begin(tag, attr);
       end(tag);
}

Here is the call graph for this function:

void SaxXML::chars ( const Xml_string text) [virtual]

Implements SaxHandler.

Definition at line 113 of file saxXML.cpp.

{
       finalizePendingEmptyTag();
       QString txt(text);
       txt.replace("&", "&amp;");
       txt.replace("<", "&lt;");
       txt.replace(">", "&gt;");
       m_stream << txt.utf8();
}

Here is the call graph for this function:

void SaxXML::end ( const Xml_string tag) [virtual]

Implements SaxHandler.

Definition at line 88 of file saxXML.cpp.

{
       --m_indentLevel;
       if (pendingEmptyTag) {
              if (m_pretty && m_manyAttributes)
              {
                     m_stream << "\n";
                     for (int k=0; k < m_indentLevel*4; ++k)
                            m_stream << " ";
              }
              m_stream << " />"; 
              pendingEmptyTag = false;
       }
       else {
              if (m_pretty)
              {
                     m_stream << "\n";
                     for (int k=0; k < m_indentLevel*4; ++k)
                            m_stream << " ";
              }
              m_stream << "</" << tag << ">";
       }
}
void SaxXML::endDoc ( ) [virtual]

Implements SaxHandler.

Definition at line 30 of file saxXML.cpp.

{
       m_stream << "\n";
       m_stream.flush(); m_file.close();
}
void SaxXML::finalizePendingEmptyTag ( ) [private]

Definition at line 37 of file saxXML.cpp.

{
       if (pendingEmptyTag) {
              if (m_pretty && m_manyAttributes)
              {
                     m_stream << "\n";
                     for (int k=0; k < m_indentLevel*4; ++k)
                            m_stream << " ";
                     m_stream << ">";
              }
              else
                     m_stream << " >";
              pendingEmptyTag = false;
       }
}

Here is the caller graph for this function:


Member Data Documentation

std::ofstream SaxXML::m_file [private]

Definition at line 31 of file saxXML.h.

Definition at line 34 of file saxXML.h.

Definition at line 35 of file saxXML.h.

Definition at line 33 of file saxXML.h.

std::ostream& SaxXML::m_stream [private]

Definition at line 32 of file saxXML.h.

Definition at line 36 of file saxXML.h.


The documentation for this class was generated from the following files: