00001
00002
00007 #ifndef __BEAUTIFIER_HANDLERS_H__
00008 #define __BEAUTIFIER_HANDLERS_H__
00009
00010 #include <memory>
00011 #include <string>
00012 #include <vector>
00013
00014 #include <xercesc/sax/HandlerBase.hpp>
00015
00016 #include "libepp_nicbr.H"
00017
00018 using std::auto_ptr;
00019 using std::string;
00020 using std::vector;
00021
00022 XERCES_CPP_NAMESPACE_USE
00023
00024 LIBEPP_NICBR_NS_BEGIN
00025
00027 struct UserData {
00028 string input_txt;
00029 string output_txt;
00030 };
00031
00033 class BeautifierHandlers : public XERCES_CPP_NAMESPACE_QUALIFIER HandlerBase
00034 {
00035 public:
00037
00040 BeautifierHandlers(UserData *pretty_data);
00041
00043 ~BeautifierHandlers();
00044
00046
00050 void startElement(const XMLCh* const name, AttributeList& attributes);
00051
00053
00057 void characters(const XMLCh* const chars, const unsigned int length);
00058
00060
00063 void endElement(const XMLCh* const chars);
00064
00066
00069 void warning(const SAXParseException& exc);
00070
00072
00075 void error(const SAXParseException& exc);
00076
00078
00081 void fatalError(const SAXParseException& exc);
00082
00083 private:
00086
00087
00088 void chars_handler();
00089
00091
00095 string str_transcode(const XMLCh *const to_transcode);
00096
00098
00102 string truncate(const string &line);
00103
00105
00108 string alltrim(const string& buffer);
00109
00111
00116 int split(const string& buffer, vector<string>& words);
00117
00119 enum eventType {
00120 NONE = 0,
00121 START = 1,
00122 CHARACTERS = 2,
00123 END = 3
00124 };
00125
00127 int _depth;
00128
00130 UserData *_user_data;
00131
00133 eventType _last_event;
00134
00136 eventType _last_non_chars_event;
00137
00139 string _to_be_printed;
00140
00142 int _left_margin;
00143
00145 string _element_name;
00146
00148 bool _truncated_txt;
00149
00151 string _tag_margin;
00152
00154 string _buffered_chars;
00155 };
00156
00157 LIBEPP_NICBR_NS_END
00158 #endif //__BEAUTIFIER_HANDLERS_H__