[mapguide-commits] r9151 - sandbox/jng/clean_json/Web/src/HttpHandler

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Apr 19 06:25:28 PDT 2017


Author: jng
Date: 2017-04-19 06:25:28 -0700 (Wed, 19 Apr 2017)
New Revision: 9151

Modified:
   sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.cpp
   sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.h
   sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.cpp
   sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.h
Log:
Ensure that attribute elements also refer to the static element path map and have their types fixed appropriately.

Also add typed/multi paths for TileProviderList-3.0.0.xsd

Modified: sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.cpp
===================================================================
--- sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.cpp	2017-04-19 13:24:03 UTC (rev 9150)
+++ sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.cpp	2017-04-19 13:25:28 UTC (rev 9151)
@@ -166,6 +166,26 @@
     this->Add("@" + name, value);
 }
 
+void MgJsonDoc::AddAttribute(const char* name, double value)
+{
+    this->Add("@" + string(name), value);
+}
+
+void MgJsonDoc::AddAttribute(const string &name, double value)
+{
+    this->Add("@" + name, value);
+}
+
+void MgJsonDoc::AddAttribute(const char* name, INT32 value)
+{
+    this->Add("@" + string(name), value);
+}
+
+void MgJsonDoc::AddAttribute(const string &name, INT32 value)
+{
+    this->Add("@" + name, value);
+}
+
 void MgJsonDoc::BeginArray(const char *name)
 {
     Value element(Json::arrayValue);

Modified: sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.h
===================================================================
--- sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.h	2017-04-19 13:24:03 UTC (rev 9150)
+++ sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.h	2017-04-19 13:25:28 UTC (rev 9151)
@@ -87,6 +87,10 @@
     void AddAttribute(const string &name, const string &value);
     void AddAttribute(const char *name, bool value);
     void AddAttribute(const string &name, bool value);
+    void AddAttribute(const char* name, double value);
+    void AddAttribute(const string &name, double value);
+    void AddAttribute(const char* name, INT32 value);
+    void AddAttribute(const string &name, INT32 value);
 
     void BeginArray(const char *name);
     void BeginArray(int size, const char *name);

Modified: sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.cpp
===================================================================
--- sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.cpp	2017-04-19 13:24:03 UTC (rev 9150)
+++ sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.cpp	2017-04-19 13:25:28 UTC (rev 9151)
@@ -89,11 +89,43 @@
         {
             attribute = attributes->item(i);
             MgUtil::WideCharToMultiByte(X2W(attribute->getNodeName()), nodeName);
-            MgUtil::WideCharToMultiByte(X2W(attribute->getNodeValue()), nodeValue);
+            STRING wNodeValue = X2W(attribute->getNodeValue());
+            MgUtil::WideCharToMultiByte(wNodeValue, nodeValue);
 
             if (bClean)
             {
-                m_jsonDoc.AddAttribute(nodeName, nodeValue);
+                int type;
+                if (GetAttributeType(attribute, node, type))
+                {
+                    switch (type)
+                    {
+                    case XML_DATA_TYPE_BOOLEAN:
+                        {
+                            bool b = MgUtil::StringToBoolean(wNodeValue);
+                            m_jsonDoc.AddAttribute(nodeName, b);
+                        }
+                        break;
+                    case XML_DATA_TYPE_NUM_INT:
+                        {
+                            INT32 i = MgUtil::StringToInt32(wNodeValue);
+                            m_jsonDoc.AddAttribute(nodeName, i);
+                        }
+                        break;
+                    case XML_DATA_TYPE_NUM_DOUBLE:
+                        {
+                            double d = MgUtil::StringToDouble(wNodeValue);
+                            m_jsonDoc.AddAttribute(nodeName, d);
+                        }
+                        break;
+                    default:
+                        m_jsonDoc.AddAttribute(nodeName, nodeValue);
+                        break;
+                    }
+                }
+                else //Type assumed to be string
+                {
+                    m_jsonDoc.AddAttribute(nodeName, nodeValue);
+                }
             }
             else
             {
@@ -401,11 +433,46 @@
     m_jsonDoc.EndArrayObject();
 }
 
+bool MgXmlJsonConvert::GetAttributePath(DOMNode * attribute, DOMNode * parent, string & path, const XMLCh * suffix)
+{
+    if (NULL != attribute)
+    {
+        STRING elPath = L"/@";
+        elPath += attribute->getNodeName();
+        elPath += suffix;
+        DOMNode* currentNode = parent;
+        while (NULL != currentNode)
+        {
+            DOMNode::NodeType nt = currentNode->getNodeType();
+            if (nt == DOMNode::ELEMENT_NODE)
+            {
+                STRING pathPart = L"/";
+                pathPart += currentNode->getNodeName();
+                elPath = pathPart + elPath;
+                currentNode = currentNode->getParentNode();
+                if (NULL == currentNode)
+                    break;
+            }
+            else
+            {
+                break;
+            }
+        }
+        path = MgUtil::WideCharToMultiByte(elPath);
+        return true;
+    }
+    return false;
+}
+
 bool MgXmlJsonConvert::GetElementPath(DOMNode * node, string & path, const XMLCh * suffix)
 {
     if (NULL != node)
     {
         STRING elPath = L"/";
+        if (node->getNodeType() == DOMNode::ATTRIBUTE_NODE)
+        {
+            elPath += L"@";
+        }
         elPath += node->getNodeName();
         elPath += suffix;
         DOMNode* currentNode = node->getParentNode();
@@ -432,6 +499,21 @@
     return false;
 }
 
+bool MgXmlJsonConvert::GetAttributeType(DOMNode * attribute, DOMNode * parent, int & type, const XMLCh * suffix)
+{
+    string path;
+    if (GetAttributePath(attribute, parent, path))
+    {
+        if (s_elementPathTypeMap.find(path) != s_elementPathTypeMap.end())
+        {
+            type = s_elementPathTypeMap[path];
+            return true;
+        }
+    }
+    return false;
+}
+
+
 bool MgXmlJsonConvert::GetElementType(DOMNode * node, int & type, const XMLCh * suffix)
 {
     string path;
@@ -731,7 +813,6 @@
     //UnmanagedDataList-1.0.0.xsd
     s_elementPathTypeMap["/UnmanagedDataList/UnmanagedDataFolder/NumberOfFolders"] = XML_DATA_TYPE_NUM_INT;
     s_elementPathTypeMap["/UnmanagedDataList/UnmanagedDataFolder/NumberOfFiles"] = XML_DATA_TYPE_NUM_INT;
-    s_elementPathTypeMap["/UnmanagedDataList/UnmanagedDataFolder/NumberOfFolders"] = XML_DATA_TYPE_NUM_INT;
     s_elementPathTypeMap["/UnmanagedDataList/UnmanagedDataFile/Size"] = XML_DATA_TYPE_NUM_INT;
     //WebLayout-2.6.0.xsd
     s_elementPathTypeMap["/WebLayout/PointSelectionBuffer"] = XML_DATA_TYPE_NUM_INT;
@@ -770,10 +851,18 @@
     s_elementPathTypeMap["/TileSetDefinition/BaseMapLayerGroup/BaseMapLayer/Selectable"] = XML_DATA_TYPE_BOOLEAN;
     s_elementPathTypeMap["/TileSetDefinition/BaseMapLayerGroup/BaseMapLayer/ShowInLegend"] = XML_DATA_TYPE_BOOLEAN;
     s_elementPathTypeMap["/TileSetDefinition/BaseMapLayerGroup/BaseMapLayer/ExpandInLegend"] = XML_DATA_TYPE_BOOLEAN;
+    //TileProviderList-3.0.0.xsd
+    s_elementPathTypeMap["/TileProviderList/TileProvider/ConnectionProperties/ConnectionProperty/@Required"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/TileProviderList/TileProvider/ConnectionProperties/ConnectionProperty/@Protected"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/TileProviderList/TileProvider/ConnectionProperties/ConnectionProperty/@Enumerable"] = XML_DATA_TYPE_BOOLEAN;
     //Miscellaneous MapGuide response types that don't have a formal schema
     s_elementPathTypeMap["/SessionTimeout/Value"] = XML_DATA_TYPE_NUM_INT;
     s_elementPathTypeMap["/FeatureInformation/SelectedFeatures/SelectedLayer/LayerMetadata/Property/Type"] = XML_DATA_TYPE_NUM_INT;
 
+    // ====================================================================================================================
+    // Element paths below basically correspond to XML Schema elements that have minOccurs="1|0" and maxOccurs="unbounded"
+    // ====================================================================================================================
+
     //FeatureSource-1.0.0.xsd
     s_multiElementPaths.insert("/FeatureSource/Parameter");
     s_multiElementPaths.insert("/FeatureSource/SupplementalSpatialContextInfo");
@@ -838,7 +927,6 @@
     s_multiElementPaths.insert("/ApplicationDefinition/WidgetSet/Container");
     s_multiElementPaths.insert("/ApplicationDefinition/WidgetSet/Container/Item");
     s_multiElementPaths.insert("/ApplicationDefinition/WidgetSet/Container/Item/Item");
-    //s_multiElementPaths.insert("/ApplicationDefinition/WidgetSet/Widget" => "abcd1234",
     s_multiElementPaths.insert("/ApplicationDefinition/MapSet/MapGroup");
     s_multiElementPaths.insert("/ApplicationDefinition/MapSet/MapGroup/Map");
     //ApplicationDefinitionInfo-1.0.0.xsd
@@ -935,6 +1023,10 @@
     s_multiElementPaths.insert("/TileSetDefinition/TileStoreParameters/Parameter");
     s_multiElementPaths.insert("/TileSetDefinition/BaseMapLayerGroup");
     s_multiElementPaths.insert("/TileSetDefinition/BaseMapLayerGroup/BaseMapLayer");
+    //TileProviderList-1.0.0.xsd
+    s_multiElementPaths.insert("/TileProviderList/TileProvider");
+    s_multiElementPaths.insert("/TileProviderList/TileProvider/ConnectionProperties/ConnectionProperty");
+    s_multiElementPaths.insert("/TileProviderList/TileProvider/ConnectionProperties/ConnectionProperty/Value");
     //UnmanagedDataList-1.0.0.xsd
     s_multiElementPaths.insert("/UnmanagedDataList/UnmanagedDataFolder");
     s_multiElementPaths.insert("/UnmanagedDataList/UnmanagedDataFile");

Modified: sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.h
===================================================================
--- sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.h	2017-04-19 13:24:03 UTC (rev 9150)
+++ sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.h	2017-04-19 13:25:28 UTC (rev 9151)
@@ -50,6 +50,9 @@
     void ProcessObjectNode(DOMNode *node, bool bClean);
     void ProcessArrayNode(int index, DOMNode *node, bool bClean);
 
+    static bool GetAttributePath(DOMNode* attribute, DOMNode* parent, string& path, const XMLCh* suffix = L"");
+    static bool GetAttributeType(DOMNode* attribute, DOMNode* parent, int& type, const XMLCh* suffix = L"");
+
     static bool GetElementPath(DOMNode* node, string& path, const XMLCh* suffix = L"");
     static bool GetElementType(DOMNode* node, int& type, const XMLCh* suffix = L"");
     static bool IsMultiple(DOMNode* node, bool& isMultiple, const XMLCh* suffix = L"");



More information about the mapguide-commits mailing list