Browse files

Merge pull request #1 from alan-wu/master

Provide a workaround to the problem where FieldMLDOM may not read data source correctly.
  • Loading branch information...
2 parents b40ce82 + cbb0835 commit cbb182cd6ba3d89f39c173937418e97d346f9982 @alan-wu alan-wu committed Mar 26, 2012
Showing with 43 additions and 7 deletions.
  1. +43 −7 core/src/FieldmlDOM.cpp
View
50 core/src/FieldmlDOM.cpp
@@ -533,7 +533,7 @@ class DataResourceParser :
int err = textStringParser.parseNode( stringDescription, state );
if( err != 0 )
{
- xmlFree(const_cast<char *>(name));
+ xmlFree(const_cast<char *>(name));
return err;
}
}
@@ -549,10 +549,10 @@ class DataResourceParser :
int err = processChildren( node, ARRAY_DATA_SOURCE_TAG, state, arrayDataSourceParser );
if( err != 0 )
{
- xmlFree(const_cast<char *>(name));
+ xmlFree(const_cast<char *>(name));
return err;
}
- xmlFree(const_cast<char *>(name));
+ xmlFree(const_cast<char *>(name));
return 0;
}
};
@@ -1362,7 +1362,6 @@ class ParameterEvaluatorParser :
}
};
-
static int parseObjectNode( xmlNodePtr objectNode, ParseState &state )
{
if( FmlUtil::contains( state.parseStack, objectNode ) )
@@ -1372,7 +1371,7 @@ static int parseObjectNode( xmlNodePtr objectNode, ParseState &state )
xmlFree(const_cast<char *>(name));
return 1;
}
-
+
state.parseStack.push_back( objectNode );
int err = 0;
@@ -1424,16 +1423,44 @@ static int parseObjectNode( xmlNodePtr objectNode, ParseState &state )
{
err = ParameterEvaluatorParser().parseNode( objectNode, state );
}
-
+
state.parseStack.pop_back();
-
+
vector<xmlNodePtr>::iterator loc = find( state.unparsedNodes.begin(), state.unparsedNodes.end(), objectNode );
state.unparsedNodes.erase( loc );
return err;
}
+// Work around of the current bug that data resource need to be defined beofre parameter evaluator uses it
+static int parseDataNode( xmlNodePtr objectNode, ParseState &state )
+{
+ if( FmlUtil::contains( state.parseStack, objectNode ) )
+ {
+ const char *name = getStringAttribute( objectNode, NAME_ATTRIB );
+ state.errorHandler->logError( "Recursive object definition", name );
+ xmlFree(const_cast<char *>(name));
+ return 1;
+ }
+
+ int err = 0;
+ if( checkName( objectNode, DATA_RESOURCE_TAG ) )
+ {
+ state.parseStack.push_back( objectNode );
+
+ err = DataResourceParser().parseNode( objectNode, state );
+
+ state.parseStack.pop_back();
+
+ vector<xmlNodePtr>::iterator loc = find( state.unparsedNodes.begin(), state.unparsedNodes.end(), objectNode );
+
+ state.unparsedNodes.erase( loc );
+
+ }
+
+ return err;
+}
static int parseDoc( xmlDocPtr doc, ParseState &state )
{
@@ -1461,6 +1488,15 @@ static int parseDoc( xmlDocPtr doc, ParseState &state )
cur = xmlNextElementSibling( cur );
}
+ // To be improved: Required the following "for" loop to loop through all the top level elements and
+ // parse the data resources before anything using them.
+ for( vector<xmlNodePtr>::iterator j = state.unparsedNodes.begin(); j != state.unparsedNodes.end();)
+ {
+ xmlNodePtr temp_node = *j;
+ j++;
+ parseDataNode( temp_node, state );
+ }
+
while( state.unparsedNodes.size() != 0 )
{
parseObjectNode( state.unparsedNodes.back(), state );

0 comments on commit cbb182c

Please sign in to comment.