Mixe for Privacy and Anonymity in the Internet
Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
DOM_Output Class Reference

#include <DOM_Output.hpp>

Collaboration diagram for DOM_Output:
[legend]

List of all members.

Static Public Member Functions

static SINT32 dumpToMem (const DOMNode *node, UINT8 *buff, UINT32 *size)
 Dumps the node and all childs into buff.
static UINT8dumpToMem (const DOMNode *node, UINT32 *size)
 Dumps the Node an returns a pointer to the memory.
static UINT8dumpToString (const DOMNode *node, bool a_bAddNewLine)
 Dumps the Node an returns a pointer to a null terminated string.
static SINT32 makeCanonical (const DOMNode *node, UINT8 *buff, UINT32 *size)
 Dumps the node and all childs in a 'cannonical form' into buff.
static UINT8makeCanonical (const DOMNode *node, UINT32 *size)
 Dumps the Node in a cannonical form and returns a pointer to the memory.

Private Member Functions

 DOM_Output ()
 ~DOM_Output ()
SINT32 dumpNode (const DOMNode *toWrite, bool bCanonical)
 Dumps a Node of an XML Document.

Static Private Member Functions

static UINT8dumpToMem (const DOMNode *node, UINT32 *size, OUTPUT_FORMAT a_outputFormat)
 Dumps the Node an returns a pointer to the memory.

Private Attributes

XMLFormatter * m_pFormatter
MemFormatTargetm_pFormatTarget

Static Private Attributes

static const XMLCh m_XML [41]
static const XMLCh m_UTF8 [6]
static const XMLCh m_1_0 [4]

Detailed Description

Definition at line 149 of file DOM_Output.hpp.


Constructor & Destructor Documentation

DOM_Output::DOM_Output ( ) [inline, private]

Definition at line 237 of file DOM_Output.hpp.

References m_1_0, m_pFormatTarget, m_pFormatter, and m_UTF8.

        {
          m_pFormatTarget=new MemFormatTarget();
          #if (_XERCES_VERSION >= 20300) //XMl-Version since Xerces 2.3.0
            m_pFormatter=new XMLFormatter(m_UTF8,m_1_0, m_pFormatTarget,
                                            XMLFormatter::NoEscapes, XMLFormatter::UnRep_Fail);
          #else
            m_pFormatter=new XMLFormatter(m_UTF8, m_pFormatTarget,
                                            XMLFormatter::NoEscapes, XMLFormatter::UnRep_Fail);
          #endif
        }
DOM_Output::~DOM_Output ( ) [inline, private]

Definition at line 248 of file DOM_Output.hpp.

References m_pFormatTarget, and m_pFormatter.

        {
          delete m_pFormatTarget;
          m_pFormatTarget = NULL;
          delete m_pFormatter;
          m_pFormatter = NULL;
        }

Member Function Documentation

SINT32 DOM_Output::dumpNode ( const DOMNode *  toWrite,
bool  bCanonical 
) [private]

Dumps a Node of an XML Document.

Parameters:
toWriteNode which will be dumped
bCanonicalif true the dump is done in a 'canonical' way, e.g. white spaces are eliminated etc.
Return values:
E_SUCCESSif successful
E_UNKNOWNotherwise

Definition at line 80 of file DOM_Output.cpp.

References E_SUCCESS, E_UNKNOWN, m_pFormatter, and m_XML.

Referenced by dumpToMem(), and makeCanonical().

  {
    if(toWrite==0)
      return E_UNKNOWN;
    // Get the name and value out for convenience
    const XMLCh*   pNodeName = toWrite->getNodeName();

    switch (toWrite->getNodeType())
      {
        case DOMNode::TEXT_NODE:
          {
            const XMLCh*   pNodeValue = toWrite->getNodeValue();
            if(!bCanonical)
              {
              m_pFormatter->formatBuf(pNodeValue,XMLString::stringLen(pNodeValue),XMLFormatter::CharEscapes);
              }
            else //strip whitespaces...
              {
                XMLCh* pText=XMLString::replicate(pNodeValue);
                XMLString::trim(pText);
                char* tmpStr=XMLString::transcode(pText);
                m_pFormatter->formatBuf(pText,XMLString::stringLen(pText),XMLFormatter::CharEscapes);
                XMLString::release(&pText);
                XMLString::release(&tmpStr);
              }
            break;
        }


 /*       case DOM_Node::PROCESSING_INSTRUCTION_NODE :
        {
            *gFormatter << XMLFormatter::NoEscapes << gStartPI  << nodeName;
            if (lent > 0)
            {
                *gFormatter << chSpace << nodeValue;
            }
            *gFormatter << XMLFormatter::NoEscapes << gEndPI;
            break;
        }
*/

       case DOMNode::DOCUMENT_NODE :
          *m_pFormatter<<XMLFormatter::NoEscapes<<m_XML;
       case DOMNode::DOCUMENT_FRAGMENT_NODE :
        {

            DOMNode* pChild = toWrite->getFirstChild();
            while( pChild != NULL)
            {
                dumpNode(pChild,bCanonical);
                // add linefeed in requested output encoding
                if(!bCanonical)
                  *m_pFormatter << chLF;
                pChild = pChild->getNextSibling();
            }
            break;
        }

  
        case DOMNode::ELEMENT_NODE :
        {
            // The name has to be representable without any escapes
            *m_pFormatter  << XMLFormatter::NoEscapes
                         << chOpenAngle << pNodeName;

            // Output the element start tag.

            // Output any attributes on this element in lexicograhpical order
            DOMNamedNodeMap* pAttributes = toWrite->getAttributes();
            UINT32 attrCount = pAttributes->getLength();
            const XMLCh** attr_names=NULL;
            UINT32* sort_indices=NULL;
            if(attrCount>0)
              {
                attr_names=new const XMLCh*[attrCount];
                sort_indices=new UINT32[attrCount];
                for(UINT32 i=0;i<attrCount;i++)
                  {
                    DOMNode*  pAttribute = pAttributes->item(i);
                    attr_names[i]=pAttribute->getNodeName();
                    sort_indices[i]=i;
                  }
                //now sort them
                if(attrCount>1)
                  {
                    for(UINT32 i=0;i<attrCount;i++)
                      {
                        const XMLCh *akt=attr_names[sort_indices[i]];
                        for(UINT32 j=i+1;j<attrCount;j++)
                          {
                            const XMLCh* tmp=attr_names[sort_indices[j]];
                            if(XMLString::compareString(akt,tmp)>0)
                              {
                                UINT32 t=sort_indices[i];
                                sort_indices[i]=sort_indices[j];
                                sort_indices[j]=t;
                                akt=tmp;
                              }
                          }
                      }
                  }
              }

            for (UINT32 i = 0; i < attrCount; i++)
            {
                //delete[] attr_names[i];
                DOMNode*  pAttribute = pAttributes->item(sort_indices[i]);
  
                //
                //  Again the name has to be completely representable. But the
                //  attribute can have refs and requires the attribute style
                //  escaping.
                //
                *m_pFormatter  << XMLFormatter::NoEscapes
                             << chSpace << pAttribute->getNodeName()
                             << chEqual << chDoubleQuote
                             << XMLFormatter::AttrEscapes
                             << pAttribute->getNodeValue()
                             << XMLFormatter::NoEscapes
                             << chDoubleQuote;
            }
            *m_pFormatter << XMLFormatter::NoEscapes << chCloseAngle;

            delete[] attr_names;
            attr_names = NULL;
            delete[] sort_indices;
            sort_indices = NULL;

            //
            //  Test for the presence of children, which includes both
            //  text content and nested elements.
            //
            DOMNode* pChild = toWrite->getFirstChild();
            while( pChild != NULL)
            {
                dumpNode(pChild,bCanonical);
                pChild = pChild->getNextSibling();
            }

            *m_pFormatter << XMLFormatter::NoEscapes << gEndElement
                        << pNodeName << chCloseAngle;
            break;
        }

/*
        case DOM_Node::ENTITY_REFERENCE_NODE:
            {
                DOM_Node child;
#if 0
                for (child = toWrite.getFirstChild();
                child != 0;
                child = child.getNextSibling())
                {
                    dumpNode(child);
                }
#else
                //
                // Instead of printing the refernece tree
                // we'd output the actual text as it appeared in the xml file.
                // This would be the case when -e option was chosen
                //
                    m_Formatter << XMLFormatter::NoEscapes << chAmpersand
                        << nodeName << chSemiColon;
#endif
                break;
            }


        case DOM_Node::CDATA_SECTION_NODE:
            {
            m_Formatter << XMLFormatter::NoEscapes << gStartCDATA
                        << nodeValue << gEndCDATA;
            break;
        }


        case DOM_Node::COMMENT_NODE:
        {
            m_Formatter << XMLFormatter::NoEscapes << gStartComment
                        << nodeValue << gEndComment;
            break;
        }


        case DOM_Node::DOCUMENT_TYPE_NODE:
        {
            DOM_DocumentType doctype = (DOM_DocumentType &)toWrite;;

            m_Formatter << XMLFormatter::NoEscapes  << gStartDoctype
                        << nodeName;

            DOMString id = doctype.getPublicId();
            if (id != 0)
            {
                m_Formatter << XMLFormatter::NoEscapes << chSpace << gPublic
                    << id << chDoubleQuote;
                id = doctype.getSystemId();
                if (id != 0)
                {
                    m_Formatter << XMLFormatter::NoEscapes << chSpace
                       << chDoubleQuote << id << chDoubleQuote;
                }
            }
            else
            {
                id = doctype.getSystemId();
                if (id != 0)
                {
                    m_Formatter << XMLFormatter::NoEscapes << chSpace << gSystem
                        << id << chDoubleQuote;
                }
            }

            id = doctype.getInternalSubset();
            if (id !=0)
                m_Formatter << XMLFormatter::NoEscapes << chOpenSquare
                            << id << chCloseSquare;

            m_Formatter << XMLFormatter::NoEscapes << chCloseAngle;
            break;
        }


        case DOM_Node::ENTITY_NODE:
        {
            m_Formatter << XMLFormatter::NoEscapes << gStartEntity
                        << nodeName;

            DOMString id = ((DOM_Entity &)toWrite).getPublicId();
            if (id != 0)
                m_Formatter << XMLFormatter::NoEscapes << gPublic
                            << id << chDoubleQuote;

            id = ((DOM_Entity &)toWrite).getSystemId();
            if (id != 0)
                m_Formatter << XMLFormatter::NoEscapes << gSystem
                            << id << chDoubleQuote;

            id = ((DOM_Entity &)toWrite).getNotationName();
            if (id != 0)
                m_Formatter << XMLFormatter::NoEscapes << gNotation
                            << id << chDoubleQuote;

            m_Formatter << XMLFormatter::NoEscapes << chCloseAngle << chLF;

            break;
        }


        case DOM_Node::XML_DECL_NODE:
        {
            DOMString  str;

            m_Formatter << gXMLDecl1 << ((DOM_XMLDecl &)toWrite).getVersion();

            m_Formatter << gXMLDecl2 << gEncodingName;

            str = ((DOM_XMLDecl &)toWrite).getStandalone();
            if (str != 0)
                m_Formatter << gXMLDecl3 << str;

            m_Formatter << gXMLDecl4;

            break;
        }

*/
      default:
        return E_UNKNOWN;
    }
  return E_SUCCESS;
}
static SINT32 DOM_Output::dumpToMem ( const DOMNode *  node,
UINT8 buff,
UINT32 size 
) [inline, static]

Dumps the node and all childs into buff.

Note that the string is NOT null-terminated.

Parameters:
nodeNode to dump
buffbuffer in which to copy the XML-chars
sizecontains the size of buff, on return contains the number of XML-CHars copied
Returns:
E_SUCCESS if successful
E_SPACE if buff is to small
E_UNKNOWN if an error occurs

Definition at line 161 of file DOM_Output.hpp.

References MemFormatTarget::dumpMem(), dumpNode(), E_SUCCESS, E_UNKNOWN, and m_pFormatTarget.

Referenced by CAFirstMix::doUserLogin_internal(), dumpToMem(), dumpToString(), encryptXMLElement(), CAInfoService::getCascadeHeloXMLAsString(), CAASymCipher::getPublicKeyAsXML(), CAAccountingInstance::handleAccountCertificate_internal(), CAMiddleMix::processKeyExchange(), CALastMix::processKeyExchange(), CAFirstMix::processKeyExchange(), CACmdLnOptions::saveToFile(), CAAccountingInstance::sendAILoginConfirmation(), CAAccountingInstance::sendCCRequest(), CAAccountingInstance::sendInitialCCRequest(), CAAbstractControlChannel::sendXMLMessage(), CACmdLnOptions::setPrevMix(), CAAccountingBIInterface::settleAll(), CAXMLErrorMessage::setValues(), CAMultiSignature::signXML(), CAXMLPriceCert::toXMLString(), CAAbstractXMLEncodable::toXmlString(), CAXMLCostConfirmation::toXMLString(), and CAInfoService::xmlDocToStringWithSignature().

        {
          DOM_Output out;
          if( out.dumpNode(node,false)!=E_SUCCESS)
            return E_UNKNOWN;
          return out.m_pFormatTarget->dumpMem(buff,size);
        }

Here is the call graph for this function:

static UINT8* DOM_Output::dumpToMem ( const DOMNode *  node,
UINT32 size 
) [inline, static]

Dumps the Node an returns a pointer to the memory.

Note that the string is NOT null-terminated.

Parameters:
nodeNode to dump
sizeon return contains the number of XML-Chars copied
Returns:
a pointer to a newls allocated buff, which must be delete[] by the caller
NULL if an error occurs

Definition at line 177 of file DOM_Output.hpp.

References dumpToMem(), and OF_DEFAULT.

        {
          return dumpToMem(node, size, OF_DEFAULT);
        }

Here is the call graph for this function:

static UINT8* DOM_Output::dumpToMem ( const DOMNode *  node,
UINT32 size,
OUTPUT_FORMAT  a_outputFormat 
) [inline, static, private]

Dumps the Node an returns a pointer to the memory.

Parameters:
nodeNode to dump
sizeon return contains the number of XML-Chars copied
a_outputFormatthe output format of the string, e.g. with null termination
Returns:
a pointer to a newls allocated buff, which must be delete[] by the caller
NULL if an error occurs

Definition at line 264 of file DOM_Output.hpp.

References MemFormatTarget::dumpMem(), dumpNode(), E_SUCCESS, and m_pFormatTarget.

        {
          DOM_Output out;
          if( out.dumpNode(node,false)!=E_SUCCESS)
            return NULL;
          return out.m_pFormatTarget->dumpMem(size, a_outputFormat);
        }

Here is the call graph for this function:

static UINT8* DOM_Output::dumpToString ( const DOMNode *  node,
bool  a_bAddNewLine 
) [inline, static]

Dumps the Node an returns a pointer to a null terminated string.

Parameters:
nodeNode to dump
a_bAddNewLinetrue if a new line should be added to the end of the string; false otherwise
Returns:
a pointer to a newls allocated buff, which must be delete[] by the caller
NULL if an error occurs

Definition at line 191 of file DOM_Output.hpp.

References dumpToMem(), OF_NEWLINE, and OF_NULL_TERMINATED.

Referenced by CAXMLErrorMessage::setValues().

        {
          UINT32 dummy;
          if (a_bAddNewLine)
          {
            return dumpToMem(node, &dummy, OF_NEWLINE);
          }
          else
          {
            return dumpToMem(node, &dummy, OF_NULL_TERMINATED);
          }
        }

Here is the call graph for this function:

static SINT32 DOM_Output::makeCanonical ( const DOMNode *  node,
UINT8 buff,
UINT32 size 
) [inline, static]

Dumps the node and all childs in a 'cannonical form' into buff.

Parameters:
nodeNode to dump
buffbuffer in which to copy the XML-chars
sizecontains the size of buff, on return contains the number of XML-CHars copied
Returns:
E_SUCCESS if successful
E_SPACE if buff is to small
E_UNKNOWN if an error occurs

Definition at line 213 of file DOM_Output.hpp.

References MemFormatTarget::dumpMem(), dumpNode(), E_SUCCESS, E_UNKNOWN, and m_pFormatTarget.

Referenced by CAAccountingInstance::prepareCCRequest(), CAMultiSignature::signXML(), CAMultiSignature::verifyXML(), and CASignature::verifyXML().

        {
          DOM_Output out;
          if( out.dumpNode(node,true)!=E_SUCCESS)
            return E_UNKNOWN;
          return out.m_pFormatTarget->dumpMem(buff,size);
        }

Here is the call graph for this function:

static UINT8* DOM_Output::makeCanonical ( const DOMNode *  node,
UINT32 size 
) [inline, static]

Dumps the Node in a cannonical form and returns a pointer to the memory.

Parameters:
nodeNode to dump
sizeon return contains the number of XML-Chars copied
Returns:
a pointer to a newly allocated buff, which must be delete[] by the caller
NULL if an error occurs

Definition at line 228 of file DOM_Output.hpp.

References MemFormatTarget::dumpMem(), dumpNode(), E_SUCCESS, m_pFormatTarget, and OF_DEFAULT.

        {
          DOM_Output out;
          if( out.dumpNode(node,true)!=E_SUCCESS)
            return NULL;
          return out.m_pFormatTarget->dumpMem(size, OF_DEFAULT);
        }

Here is the call graph for this function:


Member Data Documentation

const XMLCh DOM_Output::m_1_0 [static, private]
Initial value:
  {
    chDigit_1,chPeriod,chDigit_0, chNull
  }

Definition at line 278 of file DOM_Output.hpp.

Referenced by DOM_Output().

Definition at line 275 of file DOM_Output.hpp.

Referenced by DOM_Output(), dumpToMem(), makeCanonical(), and ~DOM_Output().

XMLFormatter* DOM_Output::m_pFormatter [private]

Definition at line 274 of file DOM_Output.hpp.

Referenced by DOM_Output(), dumpNode(), and ~DOM_Output().

const XMLCh DOM_Output::m_UTF8 [static, private]
Initial value:
  {
    chLatin_U, chLatin_T,chLatin_F, chDash,chDigit_8, chNull
  }

Definition at line 277 of file DOM_Output.hpp.

Referenced by DOM_Output().

const XMLCh DOM_Output::m_XML [static, private]
Initial value:
{
    chOpenAngle,chQuestion,chLatin_x,chLatin_m,chLatin_l,chSpace, 
    chLatin_v,chLatin_e,chLatin_r,chLatin_s,chLatin_i,chLatin_o,chLatin_n,chEqual, 
    chDoubleQuote,chDigit_1,chPeriod,chDigit_0,chDoubleQuote,chSpace,  
    chLatin_e,chLatin_n,chLatin_c,chLatin_o,chLatin_d,chLatin_i,chLatin_n,chLatin_g,chEqual, 
    chDoubleQuote,chLatin_U, chLatin_T,chLatin_F, chDash,chDigit_8, chDoubleQuote, 
    chQuestion,chCloseAngle,chCR,chLF,chNull
}

Definition at line 276 of file DOM_Output.hpp.

Referenced by dumpNode().


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