29 #include "ParserEventGeneratorKit.h" 
   39 extern SGMLApplication::OpenEntityPtr 
entity_ptr;
 
   40 extern SGMLApplication::Position 
position;
 
   59     curr_container_element = NULL;
 
   60     is_data_element = 
false;
 
   61     libofx_context = p_libofx_context;
 
   76     message_out(
PARSER, 
"startElement event received from OpenSP for element " + identifier);
 
   80     switch (event.contentType)
 
   82     case StartElementEvent::empty:
 
   85     case StartElementEvent::cdata:
 
   88     case StartElementEvent::rcdata:
 
   91     case StartElementEvent::mixed:
 
   93       is_data_element = 
true;
 
   95     case StartElementEvent::element:
 
   97       is_data_element = 
false;
 
  100       message_out(
ERROR, 
"Unknow SGML content type?!?!?!? OpenSP interface changed?");
 
  103     if (is_data_element == 
false)
 
  107       if (identifier == 
"OFX")
 
  110         MainContainer = 
new OfxMainContainer (libofx_context, curr_container_element, identifier);
 
  111         curr_container_element = MainContainer;
 
  113       else if (identifier == 
"STATUS")
 
  116         curr_container_element = 
new OfxStatusContainer (libofx_context, curr_container_element, identifier);
 
  118       else if (identifier == 
"STMTRS" ||
 
  119                identifier == 
"CCSTMTRS" ||
 
  120                identifier == 
"INVSTMTRS")
 
  123         curr_container_element = 
new OfxStatementContainer (libofx_context, curr_container_element, identifier);
 
  125       else if (identifier == 
"BANKTRANLIST")
 
  129         if (curr_container_element->type != 
"STATEMENT")
 
  131           message_out(
ERROR, 
"Element " + identifier + 
" found while not inside a STATEMENT container");
 
  135           curr_container_element = 
new OfxPushUpContainer (libofx_context, curr_container_element, identifier);
 
  138       else if (identifier == 
"STMTTRN")
 
  143       else if (identifier == 
"BUYDEBT" ||
 
  144                identifier == 
"BUYMF" ||
 
  145                identifier == 
"BUYOPT" ||
 
  146                identifier == 
"BUYOTHER" ||
 
  147                identifier == 
"BUYSTOCK" ||
 
  148                identifier == 
"CLOSUREOPT" ||
 
  149                identifier == 
"INCOME" ||
 
  150                identifier == 
"INVEXPENSE" ||
 
  151                identifier == 
"JRNLFUND" ||
 
  152                identifier == 
"JRNLSEC" ||
 
  153                identifier == 
"MARGININTEREST" ||
 
  154                identifier == 
"REINVEST" ||
 
  155                identifier == 
"RETOFCAP" ||
 
  156                identifier == 
"SELLDEBT" ||
 
  157                identifier == 
"SELLMF" ||
 
  158                identifier == 
"SELLOPT" ||
 
  159                identifier == 
"SELLOTHER" ||
 
  160                identifier == 
"SELLSTOCK" ||
 
  161                identifier == 
"SPLIT" ||
 
  162                identifier == 
"TRANSFER" )
 
  168       else if (identifier == 
"INVBUY" ||
 
  169                identifier == 
"INVSELL" ||
 
  170                identifier == 
"INVTRAN" ||
 
  171                identifier == 
"SECID")
 
  174         curr_container_element = 
new OfxPushUpContainer (libofx_context, curr_container_element, identifier);
 
  178       else if (identifier == 
"BANKACCTFROM" || identifier == 
"CCACCTFROM" || identifier == 
"INVACCTFROM")
 
  181         curr_container_element = 
new OfxAccountContainer (libofx_context, curr_container_element, identifier);
 
  183       else if (identifier == 
"SECINFO")
 
  186         curr_container_element = 
new OfxSecurityContainer (libofx_context, curr_container_element, identifier);
 
  189       else if (identifier == 
"LEDGERBAL" || identifier == 
"AVAILBAL")
 
  192         curr_container_element = 
new OfxBalanceContainer (libofx_context, curr_container_element, identifier);
 
  197         curr_container_element = 
new OfxDummyContainer(libofx_context, curr_container_element, identifier);
 
  205       if (incoming_data != 
"")
 
  207         message_out (
ERROR, 
"startElement: incoming_data should be empty! You are probably using OpenSP <= 1.3.4.  The folowing data was lost: " + incoming_data );
 
  208         incoming_data.assign (
"");
 
  220     bool end_element_for_data_element;
 
  223     end_element_for_data_element = is_data_element;
 
  224     message_out(
PARSER, 
"endElement event received from OpenSP for element " + identifier);
 
  227     if (curr_container_element == NULL)
 
  229       message_out (
ERROR, 
"Tried to close a " + identifier + 
" without a open element (NULL pointer)");
 
  230       incoming_data.assign (
"");
 
  234       if (end_element_for_data_element == 
true)
 
  238         curr_container_element->add_attribute (identifier, incoming_data);
 
  239         message_out (
PARSER, 
"endElement: Added data '" + incoming_data + 
"' from " + identifier + 
" to " + curr_container_element->type + 
" container_element");
 
  240         incoming_data.assign (
"");
 
  241         is_data_element = 
false;
 
  245         if (identifier == curr_container_element->tag_identifier)
 
  247           if (incoming_data != 
"")
 
  249             message_out(
ERROR, 
"End tag for non data element " + identifier + 
", incoming data should be empty but contains: " + incoming_data + 
" DATA HAS BEEN LOST SOMEWHERE!");
 
  252           if (identifier == 
"OFX")
 
  255             tmp_container_element = curr_container_element;
 
  256             curr_container_element = curr_container_element->getparent ();
 
  257             if (curr_container_element == NULL)
 
  260               curr_container_element = tmp_container_element;
 
  262             if (MainContainer != NULL)
 
  265               delete MainContainer;
 
  266               MainContainer = NULL;
 
  267               curr_container_element = NULL;
 
  268               message_out (
DEBUG, 
"Element " + identifier + 
" closed, MainContainer destroyed");
 
  272               message_out (
DEBUG, 
"Element " + identifier + 
" closed, but there was no MainContainer to destroy (probably a malformed file)!");
 
  277             tmp_container_element = curr_container_element;
 
  278             curr_container_element = curr_container_element->getparent ();
 
  279             if (MainContainer != NULL)
 
  281               tmp_container_element->add_to_main_tree();
 
  282               message_out (
PARSER, 
"Element " + identifier + 
" closed, object added to MainContainer");
 
  286               message_out (
ERROR, 
"MainContainer is NULL trying to add element " + identifier);
 
  292           message_out (
ERROR, 
"Tried to close a " + identifier + 
" but a " + curr_container_element->type + 
" is currently open.");
 
  302   void data (
const DataEvent & event)
 
  307     message_out(
PARSER, 
"data event received from OpenSP, incoming_data is now: " + incoming_data);
 
  314   void error (
const ErrorEvent & event)
 
  321     message = message + 
"OpenSP parser: ";
 
  324     case SGMLApplication::ErrorEvent::quantity:
 
  325       message = message + 
"quantity (Exceeding a quantity limit):";
 
  328     case SGMLApplication::ErrorEvent::idref:
 
  329       message = message + 
"idref (An IDREF to a non-existent ID):";
 
  332     case SGMLApplication::ErrorEvent::capacity:
 
  333       message = message + 
"capacity (Exceeding a capacity limit):";
 
  336     case SGMLApplication::ErrorEvent::otherError:
 
  337       message = message + 
"otherError (misc parse error):";
 
  340     case SGMLApplication::ErrorEvent::warning:
 
  341       message = message + 
"warning (Not actually an error.):";
 
  344     case SGMLApplication::ErrorEvent::info:
 
  345       message =  message + 
"info (An informationnal message.  Not actually an error):";
 
  349       message = message + 
"OpenSP sent an unknown error to LibOFX (You probably have a newer version of OpenSP):";
 
  380   ParserEventGeneratorKit parserKit;
 
  381   parserKit.setOption (ParserEventGeneratorKit::showOpenEntities);
 
  382   EventGenerator *egp = parserKit.makeEventGenerator (argc, argv);
 
  383   egp->inhibitMessages (
true);  
 
  385   unsigned nErrors = egp->run (*app); 
 
Represents a security, such as a stock or bond. 
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer. 
void openEntityChange(const OpenEntityPtr ¶_entity_ptr)
Callback: Receive internal OpenSP state. 
SGMLApplication::Position position
string AppendCharStringtostring(const SGMLApplication::CharString source, string &dest)
Append an OpenSP CharString to an existing C++ STL string. 
void error(const ErrorEvent &event)
Callback: SGML parse error. 
void data(const DataEvent &event)
Callback: Data from an OFX element. 
int message_out(OfxMsgType error_type, const string message)
Message output function. 
OFX/SGML parsing functionnality. 
string CharStringtostring(const SGMLApplication::CharString source, string &dest)
Convert OpenSP CharString to a C++ STL string. 
Various simple functions for type conversion & al. 
int ofx_proc_sgml(LibofxContext *libofx_context, int argc, char *const *argv)
Parses a DTD and OFX file(s) 
Represents a statement for either a bank account or a credit card account. 
Represents a bank or credid card transaction. 
A container to hold a OFX SGML element for which you want the parent to process it's data elements...
void startElement(const StartElementEvent &event)
Callback: Start of an OFX element. 
SGMLApplication::OpenEntityPtr entity_ptr
string strip_whitespace(const string para_string)
Sanitize a string coming from OpenSP. 
LibOFX internal object code. 
Message IO functionality. 
Represents a bank or credid card transaction. 
Represents a bank account or a credit card account. 
The root container. Created by the <OFX> OFX element or by the export functions. 
int gen_event()
Generate libofx.h events. 
This object is driven by OpenSP as it parses the SGML from the ofx file(s) 
void endElement(const EndElementEvent &event)
Callback: End of an OFX element. 
A container to holds OFX SGML elements that LibOFX knows nothing about. 
Represents the <BALANCE> OFX SGML entity. 
Represents the <STATUS> OFX SGML entity.