29 #include "ParserEventGeneratorKit.h" 39 extern SGMLApplication::OpenEntityPtr
entity_ptr;
40 extern SGMLApplication::Position
position;
57 curr_container_element = NULL;
58 is_data_element =
false;
59 libofx_context = p_libofx_context;
70 message_out(
PARSER,
"startElement event received from OpenSP for element " + identifier);
74 switch (event.contentType)
76 case StartElementEvent::empty:
79 case StartElementEvent::cdata:
82 case StartElementEvent::rcdata:
85 case StartElementEvent::mixed:
87 is_data_element =
true;
89 case StartElementEvent::element:
91 is_data_element =
false;
94 message_out(
ERROR,
"Unknown SGML content type?!?!?!? OpenSP interface changed?");
97 if (is_data_element ==
false)
101 if (identifier ==
"OFC")
104 MainContainer =
new OfxMainContainer (libofx_context, curr_container_element, identifier);
105 curr_container_element = MainContainer;
107 else if (identifier ==
"STATUS")
110 curr_container_element =
new OfxStatusContainer (libofx_context, curr_container_element, identifier);
112 else if (identifier ==
"ACCTSTMT")
115 curr_container_element =
new OfxStatementContainer (libofx_context, curr_container_element, identifier);
117 else if (identifier ==
"STMTRS")
121 if (curr_container_element->
type !=
"STATEMENT")
123 message_out(
ERROR,
"Element " + identifier +
" found while not inside a STATEMENT container");
127 curr_container_element =
new OfxPushUpContainer (libofx_context, curr_container_element, identifier);
130 else if (identifier ==
"GENTRN" ||
131 identifier ==
"STMTTRN")
136 else if (identifier ==
"BUYDEBT" ||
137 identifier ==
"BUYMF" ||
138 identifier ==
"BUYOPT" ||
139 identifier ==
"BUYOTHER" ||
140 identifier ==
"BUYSTOCK" ||
141 identifier ==
"CLOSUREOPT" ||
142 identifier ==
"INCOME" ||
143 identifier ==
"INVEXPENSE" ||
144 identifier ==
"JRNLFUND" ||
145 identifier ==
"JRNLSEC" ||
146 identifier ==
"MARGININTEREST" ||
147 identifier ==
"REINVEST" ||
148 identifier ==
"RETOFCAP" ||
149 identifier ==
"SELLDEBT" ||
150 identifier ==
"SELLMF" ||
151 identifier ==
"SELLOPT" ||
152 identifier ==
"SELLOTHER" ||
153 identifier ==
"SELLSTOCK" ||
154 identifier ==
"SPLIT" ||
155 identifier ==
"TRANSFER" )
161 else if (identifier ==
"INVBUY" ||
162 identifier ==
"INVSELL" ||
163 identifier ==
"INVTRAN" ||
164 identifier ==
"SECID")
167 curr_container_element =
new OfxPushUpContainer (libofx_context, curr_container_element, identifier);
171 else if (identifier ==
"ACCOUNT" ||
172 identifier ==
"ACCTFROM" )
175 curr_container_element =
new OfxAccountContainer (libofx_context, curr_container_element, identifier);
177 else if (identifier ==
"SECINFO")
180 curr_container_element =
new OfxSecurityContainer (libofx_context, curr_container_element, identifier);
183 else if (identifier ==
"LEDGERBAL" || identifier ==
"AVAILBAL")
186 curr_container_element =
new OfxBalanceContainer (libofx_context, curr_container_element, identifier);
191 curr_container_element =
new OfxDummyContainer(libofx_context, curr_container_element, identifier);
199 if (incoming_data !=
"")
201 message_out (
ERROR,
"startElement: incoming_data should be empty! You are probably using OpenSP <= 1.3.4. The following data was lost: " + incoming_data );
202 incoming_data.assign (
"");
214 bool end_element_for_data_element;
217 end_element_for_data_element = is_data_element;
218 message_out(
PARSER,
"endElement event received from OpenSP for element " + identifier);
221 if (curr_container_element == NULL)
223 message_out (
ERROR,
"Tried to close a " + identifier +
" without a open element (NULL pointer)");
224 incoming_data.assign (
"");
228 if (end_element_for_data_element ==
true)
232 curr_container_element->
add_attribute (identifier, incoming_data);
233 message_out (
PARSER,
"endElement: Added data '" + incoming_data +
"' from " + identifier +
" to " + curr_container_element->
type +
" container_element");
234 incoming_data.assign (
"");
235 is_data_element =
false;
241 if (incoming_data !=
"")
243 message_out(
ERROR,
"End tag for non data element " + identifier +
", incoming data should be empty but contains: " + incoming_data +
" DATA HAS BEEN LOST SOMEWHERE!");
246 if (identifier ==
"OFX")
249 tmp_container_element = curr_container_element;
250 curr_container_element = curr_container_element->
getparent ();
252 delete MainContainer;
253 MainContainer = NULL;
254 message_out (
DEBUG,
"Element " + identifier +
" closed, MainContainer destroyed");
258 tmp_container_element = curr_container_element;
259 curr_container_element = curr_container_element->
getparent ();
260 if (MainContainer != NULL)
263 message_out (
PARSER,
"Element " + identifier +
" closed, object added to MainContainer");
267 message_out (
ERROR,
"MainContainer is NULL trying to add element " + identifier);
273 message_out (
ERROR,
"Tried to close a " + identifier +
" but a " + curr_container_element->
type +
" is currently open.");
283 void data (
const DataEvent & event)
288 message_out(
PARSER,
"data event received from OpenSP, incoming_data is now: " + incoming_data);
295 void error (
const ErrorEvent & event)
302 message = message +
"OpenSP parser: ";
305 case SGMLApplication::ErrorEvent::quantity:
306 message = message +
"quantity (Exceeding a quantity limit):";
309 case SGMLApplication::ErrorEvent::idref:
310 message = message +
"idref (An IDREF to a non-existent ID):";
313 case SGMLApplication::ErrorEvent::capacity:
314 message = message +
"capacity (Exceeding a capacity limit):";
317 case SGMLApplication::ErrorEvent::otherError:
318 message = message +
"otherError (misc parse error):";
321 case SGMLApplication::ErrorEvent::warning:
322 message = message +
"warning (Not actually an error.):";
325 case SGMLApplication::ErrorEvent::info:
326 message = message +
"info (An informationnal message. Not actually an error):";
330 message = message +
"OpenSP sent an unknown error to LibOFX (You probably have a newer version of OpenSP):";
361 ParserEventGeneratorKit parserKit;
362 parserKit.setOption (ParserEventGeneratorKit::showOpenEntities);
363 EventGenerator *egp = parserKit.makeEventGenerator (argc, argv);
364 egp->inhibitMessages (
true);
366 unsigned nErrors = egp->run (*app);
This object is driven by OpenSP as it parses the SGML from the ofx file(s)
Represents a security, such as a stock or bond.
OfxGenericContainer * getparent()
Returns the parent container object (the one representing the containing OFX SGML element) ...
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
string CharStringtostring(const SGMLApplication::CharString source, string &dest)
Convert OpenSP CharString to a C++ STL string.
Various simple functions for type conversion & al.
virtual void add_attribute(const string identifier, const string value)
Add data to a container object.
string strip_whitespace(const string para_string)
Sanitize a string coming from OpenSP.
SGMLApplication::OpenEntityPtr entity_ptr
void endElement(const EndElementEvent &event)
Callback: End of an OFX element.
int message_out(OfxMsgType error_type, const string message)
Message output function.
OFX/SGML parsing functionnality.
void openEntityChange(const OpenEntityPtr ¶_entity_ptr)
Callback: Receive internal OpenSP state.
string AppendCharStringtostring(const SGMLApplication::CharString source, string &dest)
Append an OpenSP CharString to an existing C++ STL string.
LibOFX internal object code.
void data(const DataEvent &event)
Callback: Data from an OFX element.
void startElement(const StartElementEvent &event)
Callback: Start of an OFX element.
Represents a statement for either a bank account or a credit card account.
Message IO functionality.
virtual int add_to_main_tree()
Add this container to the main tree.
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...
SGMLApplication::Position position
void error(const ErrorEvent &event)
Callback: SGML parse error.
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.
A container to hold OFX SGML elements that LibOFX knows nothing about.
Represents the <BALANCE>, <INVBAL> or <INV401KBAL> OFX SGML entity.
int ofc_proc_sgml(LibofxContext *libofx_context, int argc, char *const *argv)
Parses a DTD and OFX file(s)
Represents the <STATUS> OFX SGML entity.