00001
00002 #include <iostream>
00003
00004 #include "SDXContentPrinter.h"
00005
00006 using namespace std;
00007 using namespace SDX::Helpers;
00008
00009 ContentPrinter::ContentPrinter(ContentHandler* contentHandler) :
00010 m_contentHandler(contentHandler)
00011 {
00012 }
00013
00014 void ContentPrinter::setContentHandler(ContentHandler* contentHandler){
00015 m_contentHandler = contentHandler;
00016 }
00017
00018 void ContentPrinter::startDocument(){
00019 cout << "ContentPrinter::startDocument()" << endl;
00020 if(m_contentHandler)
00021 m_contentHandler->startDocument();
00022 }
00023
00024 void ContentPrinter::startNode(std::string name){
00025 cout << "ContentPrinter::startNode(" << name << ")" << endl;
00026
00027 m_openNodes.push_back(name);
00028 if(m_contentHandler)
00029 m_contentHandler->startNode(name);
00030 }
00031
00032 void ContentPrinter::writeAttribute(std::string name, std::string value){
00033 cout << "ContentPrinter::writeAttribute(" << name << ", " << value << ")" << endl;
00034 if(m_contentHandler)
00035 m_contentHandler->writeAttribute(name, value);
00036 }
00037
00038 void ContentPrinter::endNode(){
00039 cout << "ContentPrinter::endNode()" << endl;
00040
00041 if(!m_openNodes.empty())
00042 m_openNodes.pop_back();
00043 else
00044 cout << "ContentPrinter: endNode() called with insufficient calls to startNode(). This will result in undefined behaviour." << endl;
00045
00046 if(m_contentHandler)
00047 m_contentHandler->endNode();
00048 }
00049
00050 void ContentPrinter::endDocument(){
00051 cout << "ContentPrinter::endDocument()" << endl;
00052
00053 if(!m_openNodes.empty()){
00054 cout << "ContentPrinter: endDocument() called but the following nodes are still open: " << m_openNodes.front();
00055 for(int i = 1; i < m_openNodes.size(); ++i)
00056 cout << ", " << m_openNodes[i];
00057 cout << "." << endl;
00058 }
00059
00060 if(m_contentHandler)
00061 m_contentHandler->endDocument();
00062
00063 }