[mapguide-commits] r6857 - in branches/2.4/MgDev/Desktop: MgDesktop MgDesktop/Services MgDesktop/System UnitTest
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Thu Jul 5 22:57:15 PDT 2012
Author: jng
Date: 2012-07-05 22:57:15 -0700 (Thu, 05 Jul 2012)
New Revision: 6857
Modified:
branches/2.4/MgDev/Desktop/MgDesktop/MgDesktop.vcproj
branches/2.4/MgDev/Desktop/MgDesktop/Platform.ini
branches/2.4/MgDev/Desktop/MgDesktop/Services/ResourceService.cpp
branches/2.4/MgDev/Desktop/MgDesktop/Services/ResourceService.h
branches/2.4/MgDev/Desktop/MgDesktop/Services/ServiceFactory.cpp
branches/2.4/MgDev/Desktop/MgDesktop/Services/ServiceFactory.h
branches/2.4/MgDev/Desktop/MgDesktop/System/PlatformInit.cpp
branches/2.4/MgDev/Desktop/UnitTest/TestResourceService.cpp
branches/2.4/MgDev/Desktop/UnitTest/TestResourceService.h
Log:
#2056: Use the existing Xerces library to parse and validate any XML content passed to our implementation of MgResourceService::SetResource()
Modified: branches/2.4/MgDev/Desktop/MgDesktop/MgDesktop.vcproj
===================================================================
--- branches/2.4/MgDev/Desktop/MgDesktop/MgDesktop.vcproj 2012-07-06 05:15:11 UTC (rev 6856)
+++ branches/2.4/MgDev/Desktop/MgDesktop/MgDesktop.vcproj 2012-07-06 05:57:15 UTC (rev 6857)
@@ -241,7 +241,7 @@
OutputFile="$(OutDir)\$(ProjectName).dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\Oem\ACE\ACE_wrappers\lib;..\..\Oem\FDO\Lib;..\..\Oem\DWFTK7.1\develop\global\lib\static\release\vc8.0;"..\..\Oem\dbxml\xerces-c-src\Build\Win32\VC9\Release";..\..\Common\lib\release;..\..\Server\lib\release"
- DelayLoadDLLs="MgMdfParser.dll;MgGeometry.dll;MgGwsCommon.dll;MgGwsResource.dll;xerces-c_3_1mg.dll;FDO.dll;FDOCommon.dll;MgStylization.dll;FDOGeometry.dll;ExpressionEngine.dll"
+ DelayLoadDLLs="MgMdfParser.dll;MgGeometry.dll;MgGwsCommon.dll;MgGwsResource.dll;FDO.dll;FDOCommon.dll;MgStylization.dll;FDOGeometry.dll;ExpressionEngine.dll"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
@@ -323,7 +323,7 @@
OutputFile="$(OutDir)\$(ProjectName).dll"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\Oem\ACE\ACE_wrappers\lib64;..\..\Oem\FDO\Lib64;..\..\Oem\DWFTK7.1\develop\global\lib\static\release64\vc8.0;"..\..\Oem\dbxml\xerces-c-src\Build\x64\VC9\Release";..\..\Common\lib\release64;..\..\Server\lib\release64"
- DelayLoadDLLs="MgMdfParser.dll;MgGeometry.dll;MgGwsCommon.dll;MgGwsResource.dll;xerces-c_3_1mg.dll;FDO.dll;FDOCommon.dll;MgStylization.dll;FDOGeometry.dll;ExpressionEngine.dll"
+ DelayLoadDLLs="MgMdfParser.dll;MgGeometry.dll;MgGwsCommon.dll;MgGwsResource.dll;FDO.dll;FDOCommon.dll;MgStylization.dll;FDOGeometry.dll;ExpressionEngine.dll"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
Modified: branches/2.4/MgDev/Desktop/MgDesktop/Platform.ini
===================================================================
(Binary files differ)
Modified: branches/2.4/MgDev/Desktop/MgDesktop/Services/ResourceService.cpp
===================================================================
--- branches/2.4/MgDev/Desktop/MgDesktop/Services/ResourceService.cpp 2012-07-06 05:15:11 UTC (rev 6856)
+++ branches/2.4/MgDev/Desktop/MgDesktop/Services/ResourceService.cpp 2012-07-06 05:57:15 UTC (rev 6857)
@@ -19,13 +19,14 @@
}
//INTERNAL_API:
-MgdResourceService::MgdResourceService(CREFSTRING libraryContentRoot, CREFSTRING libraryDataRoot, CREFSTRING sessionContentRoot, CREFSTRING sessionDataRoot)
+MgdResourceService::MgdResourceService(CREFSTRING libraryContentRoot, CREFSTRING libraryDataRoot, CREFSTRING sessionContentRoot, CREFSTRING sessionDataRoot, CREFSTRING schemaPath)
: MgResourceService()
{
m_libraryContentPath = libraryContentRoot;
m_libraryDataPath = libraryDataRoot;
m_sessionContentPath = sessionContentRoot;
m_sessionDataPath = sessionDataRoot;
+ m_schemaPath = schemaPath;
}
MgdResourceService::~MgdResourceService() { }
@@ -298,7 +299,66 @@
if (NULL != content)
{
Ptr<MgByteSink> sink = new MgByteSink(content);
- sink->ToFile(path);
+
+ std::string xml;
+ sink->ToStringUtf8(xml);
+
+ XercesDOMParser parser;
+ parser.setExternalSchemaLocation(m_schemaPath.c_str());
+ parser.setValidationScheme(XercesDOMParser::Val_Always);
+ DefaultHandler handler;
+ parser.setErrorHandler(&handler);
+ try
+ {
+ MemBufInputSource source((const XMLByte*)xml.c_str(), xml.size(), "MgdResourceService.Class", false);
+ parser.parse(source);
+ }
+ catch (const SAXParseException& e)
+ {
+ STRING msg = e.getMessage();
+ XMLFileLoc lineNum = e.getLineNumber();
+ XMLFileLoc colNum = e.getColumnNumber();
+
+ const XMLCh* pubId = e.getPublicId();
+ const XMLCh* sysId = e.getSystemId();
+
+ STRING pubIdStr;
+ if (NULL != pubId)
+ pubIdStr = pubId;
+ STRING sysIdStr;
+ if (NULL != sysId)
+ sysIdStr = sysId;
+
+ STRING lineNumStr;
+ STRING colNumStr;
+ MgUtil::Int64ToString(lineNum, lineNumStr);
+ MgUtil::Int64ToString(colNum, colNumStr);
+
+ MgStringCollection args;
+ args.Add(msg);
+ args.Add(lineNumStr);
+ args.Add(colNumStr);
+ args.Add(pubIdStr);
+ args.Add(sysIdStr);
+ throw new MgXmlParserException(L"MgdResourceService::SetResource", __LINE__, __WFILE__, &args, L"", NULL);
+ }
+
+ //Can't rewind a byte sink. So make another one
+ if (content->IsRewindable())
+ {
+ content->Rewind();
+ Ptr<MgByteSink> sink2 = new MgByteSink(content);
+ sink2->ToFile(path);
+ }
+ else
+ {
+ //Make a new byte source/reader/sink from the checked out xml string
+ Ptr<MgByteSource> bs = new MgByteSource((BYTE_ARRAY_IN)xml.c_str(), (INT32)xml.length());
+ Ptr<MgByteReader> rdr = bs->GetReader();
+ Ptr<MgByteSink> sink2 = new MgByteSink(rdr);
+ sink2->ToFile(path);
+ }
+
ReleasePotentialLocks(resource);
}
Modified: branches/2.4/MgDev/Desktop/MgDesktop/Services/ResourceService.h
===================================================================
--- branches/2.4/MgDev/Desktop/MgDesktop/Services/ResourceService.h 2012-07-06 05:15:11 UTC (rev 6856)
+++ branches/2.4/MgDev/Desktop/MgDesktop/Services/ResourceService.h 2012-07-06 05:57:15 UTC (rev 6857)
@@ -8,7 +8,7 @@
DECLARE_CLASSNAME(MgdResourceService)
INTERNAL_API:
- MgdResourceService(CREFSTRING libraryContentRoot, CREFSTRING libraryDataRoot, CREFSTRING sessionContentRoot, CREFSTRING sessionDataRoot);
+ MgdResourceService(CREFSTRING libraryContentRoot, CREFSTRING libraryDataRoot, CREFSTRING sessionContentRoot, CREFSTRING sessionDataRoot, CREFSTRING schemaPath);
virtual MgByteReader* EnumerateRepositories(CREFSTRING repositoryType);
Modified: branches/2.4/MgDev/Desktop/MgDesktop/Services/ServiceFactory.cpp
===================================================================
--- branches/2.4/MgDev/Desktop/MgDesktop/Services/ServiceFactory.cpp 2012-07-06 05:15:11 UTC (rev 6856)
+++ branches/2.4/MgDev/Desktop/MgDesktop/Services/ServiceFactory.cpp 2012-07-06 05:57:15 UTC (rev 6857)
@@ -11,6 +11,7 @@
STRING MgServiceFactory::sm_libDataPath = L"";
STRING MgServiceFactory::sm_sesContentPath = L"";
STRING MgServiceFactory::sm_sesDataPath = L"";
+STRING MgServiceFactory::sm_schemaPath = L"";
MG_IMPL_DYNCREATE(MgServiceFactory);
@@ -42,6 +43,11 @@
sm_sesDataPath,
MgConfigProperties::DefaultResourceServicePropertySessionResourceDataFilePath);
+ conf->GetStringValue(MgConfigProperties::ResourceServicePropertiesSection,
+ MgConfigProperties::ResourceServicePropertyResourceSchemaFilePath,
+ sm_schemaPath,
+ MgConfigProperties::DefaultResourceServicePropertyResourceSchemaFilePath);
+
//Create these paths if they don't exist
if (!MgFileUtil::IsDirectory(sm_libContentPath))
MgFileUtil::CreateDirectory(sm_libContentPath, false, true);
@@ -51,6 +57,12 @@
MgFileUtil::CreateDirectory(sm_sesContentPath, false, true);
if (!MgFileUtil::IsDirectory(sm_sesDataPath))
MgFileUtil::CreateDirectory(sm_sesDataPath, false, true);
+ if (!MgFileUtil::IsDirectory(sm_schemaPath))
+ {
+ MgStringCollection args;
+ args.Add(sm_schemaPath);
+ throw new MgDirectoryNotFoundException(L"MgServiceFactory::Initialize", __LINE__, __WFILE__, &args, L"", NULL);
+ }
}
MgService* MgServiceFactory::CreateService(INT32 serviceType)
@@ -71,7 +83,8 @@
return new MgdResourceService(sm_libContentPath,
sm_libDataPath,
sm_sesContentPath,
- sm_sesDataPath);
+ sm_sesDataPath,
+ sm_schemaPath);
case MgServiceType::TileService:
return new MgdTileService();
}
Modified: branches/2.4/MgDev/Desktop/MgDesktop/Services/ServiceFactory.h
===================================================================
--- branches/2.4/MgDev/Desktop/MgDesktop/Services/ServiceFactory.h 2012-07-06 05:15:11 UTC (rev 6856)
+++ branches/2.4/MgDev/Desktop/MgDesktop/Services/ServiceFactory.h 2012-07-06 05:57:15 UTC (rev 6857)
@@ -34,6 +34,7 @@
static STRING sm_libDataPath;
static STRING sm_sesContentPath;
static STRING sm_sesDataPath;
+ static STRING sm_schemaPath;
};
#endif
\ No newline at end of file
Modified: branches/2.4/MgDev/Desktop/MgDesktop/System/PlatformInit.cpp
===================================================================
--- branches/2.4/MgDev/Desktop/MgDesktop/System/PlatformInit.cpp 2012-07-06 05:15:11 UTC (rev 6856)
+++ branches/2.4/MgDev/Desktop/MgDesktop/System/PlatformInit.cpp 2012-07-06 05:57:15 UTC (rev 6857)
@@ -14,6 +14,7 @@
return;
ACE::init();
+ XMLPlatformUtils::Initialize();
MgConfiguration* pConfiguration = MgConfiguration::GetInstance();
pConfiguration->LoadConfiguration(configFile);
@@ -179,6 +180,7 @@
Ptr<MgdResourceService> resSvc = dynamic_cast<MgdResourceService*>(fact->CreateService(MgServiceType::ResourceService));
resSvc->DeleteSessionFiles();
+ XMLPlatformUtils::Terminate();
ACE::fini();
MG_CATCH_AND_RELEASE()
Modified: branches/2.4/MgDev/Desktop/UnitTest/TestResourceService.cpp
===================================================================
--- branches/2.4/MgDev/Desktop/UnitTest/TestResourceService.cpp 2012-07-06 05:15:11 UTC (rev 6856)
+++ branches/2.4/MgDev/Desktop/UnitTest/TestResourceService.cpp 2012-07-06 05:57:15 UTC (rev 6857)
@@ -429,6 +429,38 @@
}
}
+void TestResourceService::TestCase_SetResourceInvalid()
+{
+ try
+ {
+ Ptr<MgServiceFactory> fact = new MgServiceFactory();
+ Ptr<MgResourceService> pService = dynamic_cast<MgResourceService*>(fact->CreateService(MgServiceType::ResourceService));
+ if (pService == 0)
+ {
+ throw new MgServiceNotAvailableException(L"TestResourceService.TestCase_MoveResource", __LINE__, __WFILE__, NULL, L"", NULL);
+ }
+
+ std::string notXml = "Not XML content";
+ std::string malformedXml = "<Foo></Bar>";
+
+ Ptr<MgByteSource> bs1 = new MgByteSource((BYTE_ARRAY_IN)notXml.c_str(), (INT32)notXml.length());
+ Ptr<MgByteSource> bs2 = new MgByteSource((BYTE_ARRAY_IN)malformedXml.c_str(), (INT32)malformedXml.length());
+
+ Ptr<MgByteReader> r1 = bs1->GetReader();
+ Ptr<MgByteReader> r2 = bs2->GetReader();
+ Ptr<MgResourceIdentifier> resId = new MgResourceIdentifier(L"Library://UnitTests/NotGettingSaved.FeatureSource");
+
+ CPPUNIT_ASSERT_THROW_MG(pService->SetResource(resId, r1, NULL), MgXmlParserException*);
+ CPPUNIT_ASSERT_THROW_MG(pService->SetResource(resId, r2, NULL), MgXmlParserException*);
+ }
+ catch(MgException* e)
+ {
+ STRING message = e->GetDetails(TEST_LOCALE);
+ SAFE_RELEASE(e);
+ CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+ }
+}
+
///----------------------------------------------------------------------------
/// Test Case Description:
///
Modified: branches/2.4/MgDev/Desktop/UnitTest/TestResourceService.h
===================================================================
--- branches/2.4/MgDev/Desktop/UnitTest/TestResourceService.h 2012-07-06 05:15:11 UTC (rev 6856)
+++ branches/2.4/MgDev/Desktop/UnitTest/TestResourceService.h 2012-07-06 05:57:15 UTC (rev 6857)
@@ -36,6 +36,7 @@
CPPUNIT_TEST(TestCase_ResourceExists);
CPPUNIT_TEST(TestCase_EnumerateResources);
CPPUNIT_TEST(TestCase_SetResource);
+ CPPUNIT_TEST(TestCase_SetResourceInvalid);
CPPUNIT_TEST(TestCase_MoveResource);
CPPUNIT_TEST(TestCase_CopyResource);
CPPUNIT_TEST(TestCase_GetResourceContent);
@@ -78,6 +79,7 @@
void TestCase_ResourceExists();
void TestCase_EnumerateResources();
void TestCase_SetResource();
+ void TestCase_SetResourceInvalid();
void TestCase_MoveResource();
void TestCase_CopyResource();
void TestCase_GetResourceContent();
More information about the mapguide-commits
mailing list