[mapguide-commits] r1091 - in trunk/MgDev: Common/PlatformBase/Services Server/src/Common/Manager Server/src/Services/Resource

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sat Feb 3 19:42:09 EST 2007


Author: tonyfang
Date: 2007-02-03 19:42:08 -0500 (Sat, 03 Feb 2007)
New Revision: 1091

Modified:
   trunk/MgDev/Common/PlatformBase/Services/ResourceDefs.cpp
   trunk/MgDev/Common/PlatformBase/Services/ResourceDefs.h
   trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.cpp
   trunk/MgDev/Server/src/Common/Manager/UnmanagedDataManager.cpp
   trunk/MgDev/Server/src/Common/Manager/UnmanagedDataManager.h
   trunk/MgDev/Server/src/Services/Resource/ApplicationRepositoryManager.cpp
   trunk/MgDev/Server/src/Services/Resource/DataBindingInfo.cpp
   trunk/MgDev/Server/src/Services/Resource/DataBindingInfo.h
   trunk/MgDev/Server/src/Services/Resource/TagManager.cpp
   trunk/MgDev/Server/src/Services/Resource/TagManager.h
Log:
MapGuide RFC 12 - Unmanaged Data API Changes
- remove unmanaged data substitution from FdoConnectionManager
- add unmanaged data substitution to TagManager, format: %MG_[alias]%
- store unmanaged data mappings in UnmanagedDataManager

Modified: trunk/MgDev/Common/PlatformBase/Services/ResourceDefs.cpp
===================================================================
--- trunk/MgDev/Common/PlatformBase/Services/ResourceDefs.cpp	2007-02-03 01:06:39 UTC (rev 1090)
+++ trunk/MgDev/Common/PlatformBase/Services/ResourceDefs.cpp	2007-02-04 00:42:08 UTC (rev 1091)
@@ -63,6 +63,8 @@
 const STRING MgResourceTag::Username                = L"%MG_USERNAME%";
 const STRING MgResourceTag::Password                = L"%MG_PASSWORD%";
 const STRING MgResourceTag::DataFilePath            = L"%MG_DATA_FILE_PATH%";
+const STRING MgResourceTag::MappingBegin            = L"%MG_[";
+const STRING MgResourceTag::MappingEnd              = L"]%";
 
 
 ///////////////////////////////////////////////////////////////////////////////

Modified: trunk/MgDev/Common/PlatformBase/Services/ResourceDefs.h
===================================================================
--- trunk/MgDev/Common/PlatformBase/Services/ResourceDefs.h	2007-02-03 01:06:39 UTC (rev 1090)
+++ trunk/MgDev/Common/PlatformBase/Services/ResourceDefs.h	2007-02-04 00:42:08 UTC (rev 1091)
@@ -270,6 +270,20 @@
     /// given resource. The trailing "/" is included.
     ///
     static const STRING DataFilePath;   ///\if INTERNAL value("%MG_DATA_FILE_PATH%") \endif
+
+
+    ////////////////////////////////////////////////////////////////
+    /// \brief
+    /// This tag signifies beginning of unmanaged data mapping name.
+    ///
+    static const STRING MappingBegin;   ///\if INTERNAL value("%MG_[") \endif
+
+
+    ////////////////////////////////////////////////////////////////
+    /// \brief
+    /// This tag signifies end of unmanaged data mapping name.
+    ///
+    static const STRING MappingEnd;     ///\if INTERNAL value("]%") \endif
 };
 
 

Modified: trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.cpp
===================================================================
--- trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.cpp	2007-02-03 01:06:39 UTC (rev 1090)
+++ trunk/MgDev/Server/src/Common/Manager/FdoConnectionManager.cpp	2007-02-04 00:42:08 UTC (rev 1091)
@@ -21,7 +21,6 @@
 #include "ServiceManager.h"
 #include "LogManager.h"
 #include "LongTransactionManager.h"
-#include "UnmanagedDataManager.h"
 
 ACE_Recursive_Thread_Mutex MgFdoConnectionManager::sm_mutex;
 
@@ -539,11 +538,6 @@
             // Property value can be null ( optional properties may not have values )
             if (!value.empty())
             {
-                // if it's a "File" property, check for unmanaged data alias
-                // and replace the alias with the mapped value
-                if (name.compare(L"File") == 0)
-                    MgUnmanagedDataManager::ConvertUnmanagedDataMappingName(value);
-
                 FdoString* propertyValue = value.c_str();
                 if (propertyValue != NULL)
                 {

Modified: trunk/MgDev/Server/src/Common/Manager/UnmanagedDataManager.cpp
===================================================================
--- trunk/MgDev/Server/src/Common/Manager/UnmanagedDataManager.cpp	2007-02-03 01:06:39 UTC (rev 1090)
+++ trunk/MgDev/Server/src/Common/Manager/UnmanagedDataManager.cpp	2007-02-04 00:42:08 UTC (rev 1091)
@@ -24,6 +24,8 @@
 // Process-wide MgUnmanagedDataManager
 Ptr<MgUnmanagedDataManager> MgUnmanagedDataManager::sm_unmanagedDataManager = (MgUnmanagedDataManager*)NULL;
 
+//Ptr<MgPropertyCollection> MgUnmanagedDataManager::m_unmanagedDataMappings = (MgPropertyCollection*)NULL;
+
 const STRING MgUnmanagedDataManager::Folders              = L"FOLDERS";
 const STRING MgUnmanagedDataManager::Files                = L"FILES";
 const STRING MgUnmanagedDataManager::Both                 = L"BOTH";
@@ -37,6 +39,7 @@
 ///
 MgUnmanagedDataManager::MgUnmanagedDataManager(void)
 {
+    Initialize();
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -59,6 +62,17 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 /// \brief
+/// Initialize the mappings
+///
+void MgUnmanagedDataManager::Initialize(void)
+{
+    MgConfiguration* config = MgConfiguration::GetInstance();
+    m_unmanagedDataMappings = config->GetProperties(MgConfigProperties::UnmanagedDataMappingsSection);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+/// \brief
 /// Parses the path into mappingName and subfolder
 /// The path must be in the form of:
 ///     "[mappingName]subfolder1/subfolder2"
@@ -369,50 +383,16 @@
     return MgUnmanagedDataManager::sm_unmanagedDataManager;
 }
 
+
 ///////////////////////////////////////////////////////////////////////////////
 /// \brief
-/// Converts mapped drive in path to its mapped value
+/// Returns unmanaged data mappings
 ///
-void MgUnmanagedDataManager::ConvertUnmanagedDataMappingName(REFSTRING path)
+MgPropertyCollection* MgUnmanagedDataManager::GetUnmanagedDataMappings()
 {
-    STRING mappingName, subpath;
-
-    if (MgUnmanagedDataManager::ParsePath(path, mappingName, subpath) 
-        && !mappingName.empty())
-    {
-        MgConfiguration* config = MgConfiguration::GetInstance();
-        Ptr<MgPropertyCollection> properties = config->GetProperties(MgConfigProperties::UnmanagedDataMappingsSection);
-       
-        if (properties != NULL)
-        {
-            STRING mappingDir;
-
-            // check to make sure it's a valid mapping name
-            // cycle thru mappings until we have a match
-            for (int i = 0; i < properties->GetCount(); i++)
-            {
-                Ptr<MgStringProperty> stringProp = (MgStringProperty*)properties->GetItem(i);
-                if (mappingName.compare(stringProp->GetName()) == 0)
-                {
-                    // we have a match!
-                    mappingDir = stringProp->GetValue();
-                    break;
-                }
-            }
-
-            if (!mappingDir.empty())
-            {
-                // replace the mappingName with the actual directory
-                if (!MgFileUtil::EndsWithSlash(mappingDir))
-                    MgFileUtil::AppendSlashToEndOfPath(mappingDir);
-
-                path = mappingDir + subpath;
-            }
-        }
-    }
+    return m_unmanagedDataMappings;
 }
 
-
 ///////////////////////////////////////////////////////////////////////////////
 /// \brief
 /// Returns unmanaged data 
@@ -425,10 +405,7 @@
 
     ACE_TRACE("MgUnmanagedDataManager::EnumerateUnmanagedData");
 
-    MgConfiguration* config = MgConfiguration::GetInstance();
-    Ptr<MgPropertyCollection> properties = config->GetProperties(MgConfigProperties::UnmanagedDataMappingsSection);
-   
-    if (properties != NULL)
+    if (m_unmanagedDataMappings != NULL)
     {
         // this XML follows the ResourceList-1.0.0.xsd schema
         string list = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
@@ -468,7 +445,6 @@
 
         ACE_ASSERT(storeFolders || storeFiles);
 
-
         // filter is ignored if select = "FOLDERS"
         // filter can be:
         //      ""
@@ -484,22 +460,16 @@
         // are we looking in a specific path?
         if (!mappingName.empty())
         {
-            STRING mappingDir = L"";
-
-            // check to make sure it's a valid mapping name
-            // cycle thru mappings until we have a match
-            for (int i = 0; i < properties->GetCount(); i++)
+            Ptr<MgStringProperty> stringProp = dynamic_cast<MgStringProperty*>(m_unmanagedDataMappings->FindItem(mappingName));
+            if (stringProp != NULL)
             {
-                Ptr<MgStringProperty> stringProp = (MgStringProperty*)properties->GetItem(i);
-                if (mappingName.compare(stringProp->GetName()) == 0)
-                {
-                    // we have a match!
-                    mappingDir = stringProp->GetValue();
-                    break;
-                }
-            }
+                // we have a match!
+                STRING mappingDir = stringProp->GetValue();
 
-            if (mappingDir.empty())
+                // get the files and/or folders from that folder and subfolder (recursive)
+                GetFilesAndFolders(list, mappingName, mappingDir, subfolder, &filters, storeFolders, storeFiles, recursive);
+            }
+            else
             {
                 MgStringCollection arguments;
                 arguments.Add(L"1");
@@ -508,19 +478,14 @@
                 throw new MgInvalidArgumentException(L"MgUnmanagedDataManager::EnumerateUnmanagedData",
                     __LINE__, __WFILE__, &arguments, L"", NULL);
             }
-            else
-            {
-                // get the files and/or folders from that folder and subfolder (recursive)
-                GetFilesAndFolders(list, mappingName, mappingDir, subfolder, &filters, storeFolders, storeFiles, recursive);
-            }
         }
         else
         {
             // getting files starting from virtual root (all mappings)
             // iterate thru mappings
-            for (int i = 0; i < properties->GetCount(); i++)
+            for (int i = 0; i < m_unmanagedDataMappings->GetCount(); i++)
             {
-                Ptr<MgStringProperty> stringProp = (MgStringProperty*)properties->GetItem(i);
+                Ptr<MgStringProperty> stringProp = dynamic_cast<MgStringProperty*>(m_unmanagedDataMappings->GetItem(i));
 
                 STRING mapName = stringProp->GetName();
                 STRING mapDir = stringProp->GetValue();

Modified: trunk/MgDev/Server/src/Common/Manager/UnmanagedDataManager.h
===================================================================
--- trunk/MgDev/Server/src/Common/Manager/UnmanagedDataManager.h	2007-02-03 01:06:39 UTC (rev 1090)
+++ trunk/MgDev/Server/src/Common/Manager/UnmanagedDataManager.h	2007-02-04 00:42:08 UTC (rev 1091)
@@ -55,7 +55,10 @@
 public:
 
     static MgUnmanagedDataManager* GetInstance();
-    static void ConvertUnmanagedDataMappingName(REFSTRING path);
+    MgPropertyCollection* GetUnmanagedDataMappings();
+//    static void ConvertUnmanagedDataMappingName(REFSTRING path); // TODO: remove
+    void Initialize();
+
     virtual void Dispose();
 
     MgByteReader* EnumerateUnmanagedData(CREFSTRING path, bool recursive, CREFSTRING select, CREFSTRING filter);
@@ -65,6 +68,7 @@
 private:
 
     static Ptr<MgUnmanagedDataManager> sm_unmanagedDataManager;
+    Ptr<MgPropertyCollection> m_unmanagedDataMappings;
 
     static const STRING Folders;
     static const STRING Files;

Modified: trunk/MgDev/Server/src/Services/Resource/ApplicationRepositoryManager.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/ApplicationRepositoryManager.cpp	2007-02-03 01:06:39 UTC (rev 1090)
+++ trunk/MgDev/Server/src/Services/Resource/ApplicationRepositoryManager.cpp	2007-02-04 00:42:08 UTC (rev 1091)
@@ -360,6 +360,12 @@
         dataBindingInfo.SetLoginUsername(m_currUserInfo->GetUserName());
         dataBindingInfo.SetLoginPassword(m_currUserInfo->GetPassword());
 
+        if (resource->IsResourceTypeOf(MgResourceType::FeatureSource))
+        {
+            // turn on substitute unmanaged data mappings
+            dataBindingInfo.SetSubstituteUnmanagedDataMappings(true);
+        }
+
         byteReader = resourceContentMan->GetResource(resource,
             &dataBindingInfo);
     }

Modified: trunk/MgDev/Server/src/Services/Resource/DataBindingInfo.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/DataBindingInfo.cpp	2007-02-03 01:06:39 UTC (rev 1090)
+++ trunk/MgDev/Server/src/Services/Resource/DataBindingInfo.cpp	2007-02-04 00:42:08 UTC (rev 1091)
@@ -85,6 +85,7 @@
         m_resourceDataFilePath = dataBindingInfo.m_resourceDataFilePath;
         m_loginUsername = dataBindingInfo.m_loginUsername;
         m_loginPassword = dataBindingInfo.m_loginPassword;
+        m_substituteUnmanagedDataMappings = dataBindingInfo.m_substituteUnmanagedDataMappings;
     }
 
     return *this;
@@ -133,3 +134,14 @@
 {
     m_loginPassword = loginPassword;
 }
+
+///----------------------------------------------------------------------------
+/// <summary>
+/// Enable unmanaged data mapping substitution
+/// </summary>
+///----------------------------------------------------------------------------
+
+void MgDataBindingInfo::SetSubstituteUnmanagedDataMappings(bool value)
+{
+    m_substituteUnmanagedDataMappings = value;
+}

Modified: trunk/MgDev/Server/src/Services/Resource/DataBindingInfo.h
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/DataBindingInfo.h	2007-02-03 01:06:39 UTC (rev 1090)
+++ trunk/MgDev/Server/src/Services/Resource/DataBindingInfo.h	2007-02-04 00:42:08 UTC (rev 1091)
@@ -38,11 +38,13 @@
         CREFSTRING GetResourceDataFilePath() const;
         CREFSTRING GetLoginUsername() const;
         CREFSTRING GetLoginPassword() const;
+        bool GetSubstituteUnmanagedDataMappings() const;
 
         void SetPreProcessTags(CREFSTRING preProcessTags);
         void SetResourceDataFilePath(CREFSTRING resourceDataFilePath);
         void SetLoginUsername(CREFSTRING loginUsername);
         void SetLoginPassword(CREFSTRING loginPassword);
+        void SetSubstituteUnmanagedDataMappings(bool value);
 
 /// Data Members
 
@@ -52,6 +54,7 @@
         STRING m_resourceDataFilePath;
         STRING m_loginUsername;
         STRING m_loginPassword;
+        bool m_substituteUnmanagedDataMappings;
 };
 
 /// Inline Methods
@@ -76,4 +79,9 @@
     return m_loginPassword;
 }
 
+inline bool MgDataBindingInfo::GetSubstituteUnmanagedDataMappings() const
+{
+    return m_substituteUnmanagedDataMappings;
+}
+
 #endif

Modified: trunk/MgDev/Server/src/Services/Resource/TagManager.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/TagManager.cpp	2007-02-03 01:06:39 UTC (rev 1090)
+++ trunk/MgDev/Server/src/Services/Resource/TagManager.cpp	2007-02-04 00:42:08 UTC (rev 1091)
@@ -18,6 +18,7 @@
 #include "ResourceServiceDefs.h"
 #include "TagManager.h"
 #include "CryptographyUtil.h"
+#include "UnmanagedDataManager.h"
 
 static const STRING MgTagReservedCharacterSet = L"\t\n";
 static const int MgTagMaxLength = 1024;
@@ -320,6 +321,14 @@
     count += SubstituteTag(MgResourceTag::LoginPassword,
         dataBindingInfo.GetLoginPassword(), doc);
 
+    if (dataBindingInfo.GetSubstituteUnmanagedDataMappings())
+    {
+        count += SubstituteMappingTag(
+            MgUtil::WideCharToMultiByte(MgResourceTag::MappingBegin), 
+            MgUtil::WideCharToMultiByte(MgResourceTag::MappingEnd), 
+            doc);
+    }
+
     CheckTagStrings(doc);
 
     return count;
@@ -359,6 +368,53 @@
     return SubstituteTag(tagName, tagValue, doc);
 }
 
+///////////////////////////////////////////////////////////////////////////////
+/// \brief
+/// Substitutes the mapping tag.
+///
+int MgTagManager::SubstituteMappingTag(const string& beginTag, const string& endTag, string& doc)
+{
+    int count = 0;
+    size_t startPos, endPos;
+    size_t len1 = beginTag.length();
+    size_t len2 = endTag.length();
+
+    while (string::npos != (startPos = doc.find(beginTag)))
+    {
+        // beginTag found, now look for endTag
+        while (string::npos != (endPos = doc.find(endTag)))
+        {
+            // extract out the mapping name
+            string mappingName = doc.substr(startPos + len1, endPos - startPos - len1);
+            size_t nameLen = mappingName.length();
+
+            // find the mapping name in the map, and then replace it
+            MgPropertyCollection* mappings = MgUnmanagedDataManager::GetInstance()->GetUnmanagedDataMappings();
+            if (mappings != NULL)
+            {
+                Ptr<MgStringProperty> stringProp = dynamic_cast<MgStringProperty*>(mappings->FindItem(MgUtil::MultiByteToWideChar(mappingName)));
+                if (stringProp != NULL)
+                {
+                    STRING mappingDir = stringProp->GetValue();
+
+                    // replace the mappingName with the actual directory
+                    if (!MgFileUtil::EndsWithSlash(mappingDir))
+                        MgFileUtil::AppendSlashToEndOfPath(mappingDir);
+
+                    size_t dirLen = mappingDir.length();
+
+                    doc.replace(startPos, len1 + nameLen + len2, MgUtil::WideCharToMultiByte(mappingDir), 0, dirLen);
+                    ++count;
+                    break;
+                }
+            }
+        }
+    }
+
+    return count;
+}
+
+
 ///----------------------------------------------------------------------------
 /// <summary>
 /// Gets the specified tag.

Modified: trunk/MgDev/Server/src/Services/Resource/TagManager.h
===================================================================
--- trunk/MgDev/Server/src/Services/Resource/TagManager.h	2007-02-03 01:06:39 UTC (rev 1090)
+++ trunk/MgDev/Server/src/Services/Resource/TagManager.h	2007-02-04 00:42:08 UTC (rev 1091)
@@ -58,6 +58,7 @@
 
     int SubstituteTag(const string& name, const string& value, string& doc);
     int SubstituteTag(CREFSTRING name, CREFSTRING value, string& doc);
+    int SubstituteMappingTag(const string& beginMapping, const string& endMapping, string& doc);
     void AddTag(CREFSTRING name, const MgTagInfo& tagInfo);
 
 private:



More information about the mapguide-commits mailing list