lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master e291935 1/2: Accommodate ancient third-party


From: Greg Chicares
Subject: [lmi-commits] [lmi] master e291935 1/2: Accommodate ancient third-party input files
Date: Sun, 15 Jul 2018 12:50:34 -0400 (EDT)

branch: master
commit e291935dad6853786e57b0594137b936c30fc493
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Accommodate ancient third-party input files
    
    This change restores some code that had been removed by commit 8a999834
    of 20180702T1447Z. For files that lack the "data_source" attribute that
    was added 20130428T1828Z, the restored code looks for obsolete element
    <InforceDataSource> that used to embody the same information.
---
 multiple_cell_document.cpp | 33 +++++++++++++++++++++++++++++----
 single_cell_document.cpp   | 27 +++++++++++++++++++++++----
 2 files changed, 52 insertions(+), 8 deletions(-)

diff --git a/multiple_cell_document.cpp b/multiple_cell_document.cpp
index 96ad1b4..64e68a5 100644
--- a/multiple_cell_document.cpp
+++ b/multiple_cell_document.cpp
@@ -391,13 +391,18 @@ void multiple_cell_document::parse_v0(xml_lmi::dom_parser 
const& parser)
 ///   "1" means lmi; and
 ///   each external system is assigned a higher integer.
 ///
-/// If the "data_source" attribute is not present, then presume that
-/// the source is external iff a "file_version" attribute is present
-/// and a schema for that version exists.
+/// Regrettably, some older external files defectively represent the
+/// data source only in obsolete <cell> element <InforceDataSource>,
+/// rather than in root attribute "data_source", so if that attribute
+/// is missing, it is necessary to look for the lower-level element
+/// (which uses the same values to represent the data source); if any
+/// cell is thus marked as external, then the entire file is treated
+/// as external.
 
 bool multiple_cell_document::data_source_is_external(xml::document const& d) 
const
 {
     xml::element const& root(d.get_root_node());
+
     int data_source = 0;
     if(xml_lmi::get_attr(root, "data_source", data_source))
         {
@@ -408,8 +413,28 @@ bool 
multiple_cell_document::data_source_is_external(xml::document const& d) con
         {
         int file_version = 0;
         xml_lmi::get_attr(root, "version", file_version);
-        return 7 <= file_version;
+        LMI_ASSERT(file_version <= 2);
         }
+
+    // Tag names vary: {"case_default", "class_defaults", "particular_cells"}.
+    xml::const_nodes_view const i_nodes(root.elements());
+    LMI_ASSERT(3 == i_nodes.size());
+    for(auto const& i : i_nodes)
+        {
+        for(auto const& j : i.elements("cell"))
+            {
+            for(auto const& k : j.elements("InforceDataSource"))
+                {
+                std::string s(xml_lmi::get_content(k));
+                if("0" != s && "1" != s)
+                    {
+                    return true;
+                    }
+                }
+            }
+        }
+
+    return false;
 }
 
 /// Coarsely validate file format with XSD schema.
diff --git a/single_cell_document.cpp b/single_cell_document.cpp
index fab5dce..044afb1 100644
--- a/single_cell_document.cpp
+++ b/single_cell_document.cpp
@@ -142,13 +142,16 @@ void single_cell_document::parse(xml_lmi::dom_parser 
const& parser)
 ///   "1" means lmi; and
 ///   each external system is assigned a higher integer.
 ///
-/// If the "data_source" attribute is not present, then presume that
-/// the source is external iff a "file_version" attribute is present
-/// and a schema for that version exists.
+/// Regrettably, some older external files defectively represent the
+/// data source only in obsolete <cell> element <InforceDataSource>,
+/// rather than in root attribute "data_source", so if that attribute
+/// is missing, it is necessary to look for the lower-level element
+/// (which uses the same values to represent the data source).
 
 bool single_cell_document::data_source_is_external(xml::document const& d) 
const
 {
     xml::element const& root(d.get_root_node());
+
     int data_source = 0;
     if(xml_lmi::get_attr(root, "data_source", data_source))
         {
@@ -159,8 +162,24 @@ bool 
single_cell_document::data_source_is_external(xml::document const& d) const
         {
         int file_version = 0;
         xml_lmi::get_attr(root, "version", file_version);
-        return 7 <= file_version;
+        LMI_ASSERT(file_version <= 2);
         }
+
+    xml::const_nodes_view const i_nodes(root.elements("cell"));
+    LMI_ASSERT(1 == i_nodes.size());
+    for(auto const& i : i_nodes)
+        {
+        for(auto const& j : i.elements("InforceDataSource"))
+            {
+            std::string s(xml_lmi::get_content(j));
+            if("0" != s && "1" != s)
+                {
+                return true;
+                }
+            }
+        }
+
+    return false;
 }
 
 /// Coarsely validate file format with XSD schema.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]