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

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Apr 19 09:35:53 PDT 2017


Author: jng
Date: 2017-04-19 09:35:53 -0700 (Wed, 19 Apr 2017)
New Revision: 9158

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
Log:
- Add type maps and multi-element paths for the FeatureSchemaCollection-3.3.0.xsd and ClassDefinition-3.3.0.xsd schemas
- Implement JSON type mapping support for XML array nodes, ensuring the SpecificGeometryTypes/Types element values are written out as integers and not strings

Modified: sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.cpp
===================================================================
--- sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.cpp	2017-04-19 16:00:47 UTC (rev 9157)
+++ sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.cpp	2017-04-19 16:35:53 UTC (rev 9158)
@@ -237,6 +237,24 @@
     node->Element[index] = value;
 }
 
+void MgJsonDoc::SetArrayValue(int index, bool value)
+{
+    MgJsonNode *node = m_tree.top();
+    node->Element[index] = Json::Value(value);
+}
+
+void MgJsonDoc::SetArrayValue(int index, double value)
+{
+    MgJsonNode *node = m_tree.top();
+    node->Element[index] = Json::Value(value);
+}
+
+void MgJsonDoc::SetArrayValue(int index, INT32 value)
+{
+    MgJsonNode *node = m_tree.top();
+    node->Element[index] = Json::Value(value);
+}
+
 void MgJsonDoc::AppendArrayValue(const char *value)
 {
     MgJsonNode *node = m_tree.top();

Modified: sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.h
===================================================================
--- sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.h	2017-04-19 16:00:47 UTC (rev 9157)
+++ sandbox/jng/clean_json/Web/src/HttpHandler/JsonDoc.h	2017-04-19 16:35:53 UTC (rev 9158)
@@ -98,6 +98,9 @@
     void EndArray();
     void SetArrayValue(int index, const char *value);
     void SetArrayValue(int index, const string &value);
+    void SetArrayValue(int index, bool value);
+    void SetArrayValue(int index, double value);
+    void SetArrayValue(int index, INT32 value);
 
     void AppendArrayValue(const char *value);
     void AppendArrayValue(const string &value);

Modified: sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.cpp
===================================================================
--- sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.cpp	2017-04-19 16:00:47 UTC (rev 9157)
+++ sandbox/jng/clean_json/Web/src/HttpHandler/XmlJsonConvert.cpp	2017-04-19 16:35:53 UTC (rev 9158)
@@ -82,10 +82,10 @@
     if (node->hasAttributes())
     {
         DOMNamedNodeMap *attributes = node->getAttributes();
-        int attributeCount = attributes->getLength();
+        XMLSize_t attributeCount = attributes->getLength();
         DOMNode *attribute;
         string nodeValue;
-        for (int i = 0; i < attributeCount; i++)
+        for (XMLSize_t i = 0; i < attributeCount; i++)
         {
             attribute = attributes->item(i);
             MgUtil::WideCharToMultiByte(X2W(attribute->getNodeName()), nodeName);
@@ -414,10 +414,49 @@
                 if (childNode->getNodeType() == DOMNode::TEXT_NODE)
                 {
                     string textContent;
-                    MgUtil::WideCharToMultiByte(X2W(childNode->getTextContent()), textContent);
+                    STRING wTextContent = X2W(node->getTextContent());
+                    MgUtil::WideCharToMultiByte(wTextContent, textContent);
                     if (this->ValidateTextContent(textContent))
                     {
-                        m_jsonDoc.SetArrayValue(index, textContent);
+                        if (bClean)
+                        {
+                            int type;
+                            if (GetElementType(node, type))
+                            {
+                                switch (type)
+                                {
+                                case XML_DATA_TYPE_BOOLEAN:
+                                    {
+                                        bool b = MgUtil::StringToBoolean(wTextContent);
+                                        m_jsonDoc.SetArrayValue(index, b);
+                                    }
+                                    break;
+                                case XML_DATA_TYPE_NUM_INT:
+                                    {
+                                        INT32 i = MgUtil::StringToInt32(wTextContent);
+                                        m_jsonDoc.SetArrayValue(index, i);
+                                    }
+                                    break;
+                                case XML_DATA_TYPE_NUM_DOUBLE:
+                                    {
+                                        double d = MgUtil::StringToDouble(wTextContent);
+                                        m_jsonDoc.SetArrayValue(index, d);
+                                    }
+                                    break;
+                                default:
+                                    m_jsonDoc.SetArrayValue(index, textContent);
+                                    break;
+                                }
+                            }
+                            else //Type assumed to be string
+                            {
+                                m_jsonDoc.SetArrayValue(index, textContent);
+                            }
+                        }
+                        else
+                        {
+                            m_jsonDoc.SetArrayValue(index, textContent);
+                        }
                     }
                     return;
                 }
@@ -855,6 +894,42 @@
     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;
+    //FeatureSchemaCollection-3.3.0.xsd
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/IsAbstract"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/IsComputed"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/PropertyType"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/DataType"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/Length"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/Nullable"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/ReadOnly"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/IsAutoGenerated"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/IsIdentity"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/Precision"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/Scale"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/GeometryTypes"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/SpecificGeometryTypes/Type"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/HasElevation"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/HasMeasure"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/DefaultImageXSize"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/DefaultImageYSize"] = XML_DATA_TYPE_NUM_INT;
+    //ClassDefinition-3.3.0.xsd
+    s_elementPathTypeMap["/ClassDefinition/IsAbstract"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/ClassDefinition/IsComputed"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/PropertyType"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/DataType"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/Length"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/Nullable"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/ReadOnly"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/IsAutoGenerated"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/IsIdentity"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/Precision"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/Scale"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/GeometryTypes"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/SpecificGeometryTypes/Type"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/HasElevation"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/HasMeasure"] = XML_DATA_TYPE_BOOLEAN;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/DefaultImageXSize"] = XML_DATA_TYPE_NUM_INT;
+    s_elementPathTypeMap["/ClassDefinition/Properties/Property/DefaultImageYSize"] = XML_DATA_TYPE_NUM_INT;
     //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;
@@ -940,6 +1015,9 @@
     //BatchPropertyCollection-1.0.0.xsd
     s_multiElementPaths.insert("/BatchPropertyCollection/PropertyCollection");
     s_multiElementPaths.insert("/BatchPropertyCollection/PropertyCollection/Property");
+    //ClassDefinition-3.3.0.xsd
+    s_multiElementPaths.insert("/ClassDefinition/Properties/Property");
+    s_multiElementPaths.insert("/ClassDefinition/Properties/Property/SpecificGeometryTypes/Type");
     //DataStoreList-1.0.0.xsd
     s_multiElementPaths.insert("/DataStoreList/DataStore");
     //DrawingSectionList-1.0.0.xsd
@@ -972,6 +1050,11 @@
     s_multiElementPaths.insert("/FeatureProviderRegistry/FeatureProvider");
     s_multiElementPaths.insert("/FeatureProviderRegistry/FeatureProvider/ConnectionProperties/ConnectionProperty");
     s_multiElementPaths.insert("/FeatureProviderRegistry/FeatureProvider/ConnectionProperties/ConnectionProperty/Value");
+    //FeatureSchemaCollection-3.3.0.xsd
+    s_multiElementPaths.insert("/FeatureSchemaCollection/FeatureSchema");
+    s_multiElementPaths.insert("/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition");
+    s_multiElementPaths.insert("/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property");
+    s_multiElementPaths.insert("/FeatureSchemaCollection/FeatureSchema/Classes/ClassDefinition/Properties/Property/SpecificGeometryTypes/Type");
     //Group-1.0.0.xsd
     s_multiElementPaths.insert("/Group/Users/User");
     //GroupList-1.0.0.xsd



More information about the mapguide-commits mailing list