[fdo-commits] r783 - in branches/3.2.1/Fdo: UnitTest Unmanaged/Src/Fdo/Xml

svn_fdo at osgeo.org svn_fdo at osgeo.org
Fri Feb 16 14:21:49 EST 2007


Author: brentrobinson
Date: 2007-02-16 14:21:49 -0500 (Fri, 16 Feb 2007)
New Revision: 783

Modified:
   branches/3.2.1/Fdo/UnitTest/SpatialContextTest.cpp
   branches/3.2.1/Fdo/UnitTest/SpatialContextTest.h
   branches/3.2.1/Fdo/Unmanaged/Src/Fdo/Xml/SCReadHandler.cpp
   branches/3.2.1/Fdo/Unmanaged/Src/Fdo/Xml/SCReadHandler.h
   branches/3.2.1/Fdo/Unmanaged/Src/Fdo/Xml/SpatialContextReader.cpp
Log:
FdoXmlSpatialContextReader: Prevent ':' encoding


Modified: branches/3.2.1/Fdo/UnitTest/SpatialContextTest.cpp
===================================================================
--- branches/3.2.1/Fdo/UnitTest/SpatialContextTest.cpp	2007-02-15 20:00:00 UTC (rev 782)
+++ branches/3.2.1/Fdo/UnitTest/SpatialContextTest.cpp	2007-02-16 19:21:49 UTC (rev 783)
@@ -103,7 +103,7 @@
             bFailed = true;
         }
         if ( !bFailed ) 
-            CPPUNIT_FAIL( "Writing nameless spatial context should have failed." );
+            CPPUNIT_FAIL( "Writing extentless spatial context should have failed." );
 
         // now for the happy tests.
 
@@ -332,6 +332,59 @@
     }
 }
 
+void SpatialContextTest::testXmlDotColon()
+{
+    try {
+        FdoInt32 pass;
+
+        // pass 0 writes SC without WKT, pass1 writes it with WKT.
+        for ( pass = 0; pass < 2; pass++ ) {
+            FdoIoMemoryStreamP stream = FdoIoMemoryStream::Create();
+            FdoIoMemoryStreamP stream2 = FdoIoMemoryStream::Create();
+            FdoXmlWriterP xmlWriter = FdoXmlWriter::Create(stream);
+
+            FdoXmlSpatialContextWriterP writer = FdoXmlSpatialContextWriter::Create( 
+                xmlWriter
+            );
+
+            writer->SetName( L"EPSG:123.4" );
+            writer->SetDescription( L". and : test" );
+            writer->SetCoordinateSystem( L"EPSG:1234" );
+            if ( pass == 1 ) 
+                writer->SetCoordinateSystemWkt( L"LOCAL_CS [ \"Non-Earth (Meter)\", LOCAL_DATUM [\"Local Datum\", 0], UNIT [\"Meter\", 1.0], AXIS [\"X\", EAST], AXIS[\"Y\", NORTH]]" );
+            FdoPtr<FdoByteArray> extent = SerializeExtent( 0, 0, 15000, 10000 );
+            writer->SetExtent( extent );
+            writer->SetExtentType( FdoSpatialContextExtentType_Dynamic );
+            writer->SetXYTolerance( 0.1 );
+            writer->SetZTolerance( 0.01 );
+
+            writer->WriteSpatialContext();
+
+            writer = NULL;
+            xmlWriter = NULL;
+            stream->Reset();
+
+            FdoXmlSpatialContextReaderP reader =
+                FdoXmlSpatialContextReader::Create(
+                    FdoXmlReaderP( FdoXmlReader::Create(stream) ),
+                    FdoXmlSpatialContextFlagsP(
+                        FdoXmlSpatialContextFlags::Create( NULL, FdoXmlFlags::ErrorLevel_High ) 
+                    )
+                );
+
+            FDO_CPPUNIT_ASSERT( reader->ReadNext() );
+            FDO_CPPUNIT_ASSERT( wcscmp(reader->GetName(), L"EPSG:123.4") == 0 );
+            FDO_CPPUNIT_ASSERT( wcscmp(reader->GetCoordinateSystem(), L"EPSG:1234") == 0 );
+            FDO_CPPUNIT_ASSERT( wcscmp(reader->GetDescription(), L". and : test") == 0 );
+         
+            FDO_CPPUNIT_ASSERT( !reader->ReadNext() );
+        }
+    }
+    catch ( FdoException* e ) {
+		UnitTestUtil::FailOnException( e );
+    }
+}
+
 FdoByteArray* SpatialContextTest::SerializeExtent( double minX, double minY, double maxX, double maxY )
 {
     // Create a byte array 

Modified: branches/3.2.1/Fdo/UnitTest/SpatialContextTest.h
===================================================================
--- branches/3.2.1/Fdo/UnitTest/SpatialContextTest.h	2007-02-15 20:00:00 UTC (rev 782)
+++ branches/3.2.1/Fdo/UnitTest/SpatialContextTest.h	2007-02-16 19:21:49 UTC (rev 783)
@@ -27,6 +27,7 @@
     FDO_CPPUNIT_DEFINE(testXmlV2);
     FDO_CPPUNIT_DEFINE(testXmlError);
     FDO_CPPUNIT_DEFINE(testXmlNesting);
+    FDO_CPPUNIT_DEFINE(testXmlDotColon);
 
     CPPUNIT_TEST_SUITE(SpatialContextTest);
 
@@ -35,6 +36,7 @@
     CPPUNIT_TEST(testXmlV2);
     CPPUNIT_TEST(testXmlError);
     CPPUNIT_TEST(testXmlNesting);
+    CPPUNIT_TEST(testXmlDotColon);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -57,6 +59,9 @@
     // root element.
     void testXmlNesting();
 
+    // Test round-tripping spatial contexts with dots and/or colons in name and coordsys name,
+    void testXmlDotColon();
+
     // Convert extents from doubles to byte array
     FdoByteArray* SerializeExtent( double minX, double minY, double maxX, double maxY );
     // Deserialize spatial contexts from inStream and serialize them to outStream

Modified: branches/3.2.1/Fdo/Unmanaged/Src/Fdo/Xml/SCReadHandler.cpp
===================================================================
--- branches/3.2.1/Fdo/Unmanaged/Src/Fdo/Xml/SCReadHandler.cpp	2007-02-15 20:00:00 UTC (rev 782)
+++ branches/3.2.1/Fdo/Unmanaged/Src/Fdo/Xml/SCReadHandler.cpp	2007-02-16 19:21:49 UTC (rev 783)
@@ -146,6 +146,22 @@
     mElementPrefix = L"";
 }
 
+FdoStringP FdoXmlSCReadHandler::DecodeName ( FdoStringP name, FdoXmlReader* reader )
+{
+    FdoStringP outName = name;
+    
+    if ( mXmlFlags->GetNameAdjust() ) {
+        //Workaround: '.' and ':' are not allowed in schema element names so DecodeName replaces
+        //them with '-dot-' and '-colon'. However '.' and ':' are allowed in spatial context names
+        //so change them back.
+        //The ideal fix is to move the '.' and ':' replacement up from FdoXmlReader to the 
+        //Fdo/Schema level but this would be a bit riskier and should be done in a later version.
+        outName = reader->DecodeName(name).Replace( L"-colon-", L":" ).Replace( L"-dot-", L"." );
+    }
+
+    return outName;
+}
+
 FdoXmlSaxHandler* FdoXmlSCReadHandler::doTransition( 
     FdoBoolean isStart, 
     FdoXmlSaxContext* context, 
@@ -337,9 +353,7 @@
         attr = atts->FindItem( FdoXml::mGmlUri + L":id" );
 
         if ( attr ) {
-            mID = mXmlFlags->GetNameAdjust() ?
-                (FdoString*) reader->DecodeName(attr->GetValue()) :
-                attr->GetValue();
+            mID = DecodeName( attr->GetValue(), reader );
         }
 
         break;
@@ -479,7 +493,7 @@
                     );
                 }
                 else {
-                    mCoordSysName = tokens->GetString(1);
+                    mCoordSysName = DecodeName( tokens->GetString(1), reader );
                 }
             }
         }
@@ -714,9 +728,7 @@
         attr = atts->FindItem( FdoXml::mGmlUri + L":id" );
 
         if ( attr ) {
-            mCsysID = mXmlFlags->GetNameAdjust() ?
-                (FdoString*) reader->DecodeName(attr->GetValue()) :
-                attr->GetValue();
+            mCsysID = DecodeName( attr->GetValue(), reader );
         }
 
         break;

Modified: branches/3.2.1/Fdo/Unmanaged/Src/Fdo/Xml/SCReadHandler.h
===================================================================
--- branches/3.2.1/Fdo/Unmanaged/Src/Fdo/Xml/SCReadHandler.h	2007-02-15 20:00:00 UTC (rev 782)
+++ branches/3.2.1/Fdo/Unmanaged/Src/Fdo/Xml/SCReadHandler.h	2007-02-16 19:21:49 UTC (rev 783)
@@ -44,6 +44,8 @@
     // Initializes the handler. Must be called before reading each spatial context.
     void Setup( FdoXmlFlags* pXmlFlags );
 
+    // Decodes any escaped characters in Spatial Context and Coordinate System names. 
+    FdoStringP DecodeName ( FdoStringP name, FdoXmlReader* reader );
 
 protected:
     FdoXmlSCReadHandler() {}

Modified: branches/3.2.1/Fdo/Unmanaged/Src/Fdo/Xml/SpatialContextReader.cpp
===================================================================
--- branches/3.2.1/Fdo/Unmanaged/Src/Fdo/Xml/SpatialContextReader.cpp	2007-02-15 20:00:00 UTC (rev 782)
+++ branches/3.2.1/Fdo/Unmanaged/Src/Fdo/Xml/SpatialContextReader.cpp	2007-02-16 19:21:49 UTC (rev 783)
@@ -160,10 +160,6 @@
         mExtent =  gf->GetFgf(geom);
         mSCHandler->mFirst = false;
 
-        // Decode the coordinate system name.
-        if ( mXmlFlags->GetNameAdjust() ) {
-            mSCHandler->mCoordSysName = mXmlReader->DecodeName( mSCHandler->mCoordSysName );
-        }
         return true;
     }
     else {



More information about the fdo-commits mailing list