[fusion-commits] r2659 - in trunk: text widgets/Redline/classes

svn_fusion at osgeo.org svn_fusion at osgeo.org
Fri Mar 8 05:45:51 PST 2013


Author: jng
Date: 2013-03-08 05:45:51 -0800 (Fri, 08 Mar 2013)
New Revision: 2659

Modified:
   trunk/text/en
   trunk/widgets/Redline/classes/markupeditor.php
   trunk/widgets/Redline/classes/markupmanager.php
Log:
#551: Add support for uploading SHP-based redlines. These must be uploaded as zip files containing all the required parts. Also do a schema validation check as part of uploading to ensure the Feature Source schematically looks like something created by this widget.

Modified: trunk/text/en
===================================================================
--- trunk/text/en	2013-03-08 12:33:00 UTC (rev 2658)
+++ trunk/text/en	2013-03-08 13:45:51 UTC (rev 2659)
@@ -330,6 +330,8 @@
 REDLINEUPLOADREQUIRED   = Redline Data File not specified
 REDLINEUPLOADTEXT       = Upload
 REDLINEUPLOADCLOSE      = Close
+REDLINEUPLOADSHPZIPERROR = Error uploading zip file. File is either:<ul><li>Not a zip file</li><li>A corrupted zip file</li><li>Does not contain a .shp file</li></ul>
+REDLINEUPLOADINVALIDSCHEMA = The uploaded redline data file has an invalid schema. This widget expects the following properties in the class definition:<ul><li>The class definition is named 'Markup'</li><li>It has an auto-generated numeric identity property (ID or FeatId)</li><li>It has a geometry property (Geometry)</li><li>It has a string property (Text)</li></ul><br>Redline data files created by this widget satisfy this schema requirements.
 
 # HtmlViewerAbout
 HTMLABOUTTITLE          = About %s

Modified: trunk/widgets/Redline/classes/markupeditor.php
===================================================================
--- trunk/widgets/Redline/classes/markupeditor.php	2013-03-08 12:33:00 UTC (rev 2658)
+++ trunk/widgets/Redline/classes/markupeditor.php	2013-03-08 13:45:51 UTC (rev 2659)
@@ -278,7 +278,7 @@
         $markupLayer = $map->GetLayers()->GetItem('_' . $this->GetMarkupName());
 
         $selection = new MgSelection($map);
-        $selection->AddFeatureIdInt32($markupLayer, 'MarkupSchema:Markup', (int) $this->args['MARKUPFEATURE']);
+        $selection->AddFeatureIdInt32($markupLayer, $markupLayer->GetFeatureClassName(), (int) $this->args['MARKUPFEATURE']);
 
         return $selection->ToXML();
     }

Modified: trunk/widgets/Redline/classes/markupmanager.php
===================================================================
--- trunk/widgets/Redline/classes/markupmanager.php	2013-03-08 12:33:00 UTC (rev 2658)
+++ trunk/widgets/Redline/classes/markupmanager.php	2013-03-08 13:45:51 UTC (rev 2659)
@@ -543,7 +543,7 @@
             }
         } else { //Single file, make things easier!
             $dataName = $markupLayerResId->GetName().$extension;
-            $byteReader = $resourceService->GetResourceData($markupFsId, $zipName);
+            $byteReader = $resourceService->GetResourceData($markupFsId, $dataName);
             $len = $byteReader->GetLength();
 
             $outputBuffer = '';
@@ -569,8 +569,8 @@
             return "OSGeo.SQLite";
         } else if ( substr( $extNorm, strlen( $extNorm ) - strlen( "db" ) ) == "db" ) {
             return "OSGeo.SQLite";
-        //} else if ( substr( $extNorm, strlen( $extNorm ) - strlen( "zip" ) ) == "zip" ) { //SHP file uploads will be zipped
-        //    return "OSGeo.SHP";
+        } else if ( substr( $extNorm, strlen( $extNorm ) - strlen( "zip" ) ) == "zip" ) { //SHP file uploads will be zipped
+            return "OSGeo.SHP";
         } else {
             return null;
         }
@@ -603,8 +603,29 @@
         //Set up feature source document
         $dataName = $baseName . "." . $ext;
         $fileParam = "File";
+        $shpFileParts = array();
         if (strcmp($fdoProvider, "OSGeo.SHP") == 0) {
+            $dataName = null;
             $fileParam = "DefaultFileLocation";
+            $zip = new ZipArchive();
+            if ($zip->open($_FILES["UPLOADFILE"]["tmp_name"]) === TRUE) {
+                for ($i = 0; $i < $zip->numFiles; $i++) {
+                    $stat = $zip->statIndex($i);
+                    $filePath = tempnam(sys_get_temp_dir(), "upload");
+                    //Dump to temp file
+                    file_put_contents($filePath, $zip->getFromIndex($i));
+                    //Stash for later upload and cleanup
+                    $entry = $stat["name"];
+                    $shpFileParts[$entry] = $filePath;
+                    if (substr( $entry, strlen( $entry ) - strlen( ".shp" ) ) == ".shp")
+                        $dataName = $entry;
+                }
+                //Abort if we can't find a .shp file. This is not a valid zip file
+                if ($dataName == null)
+                    throw new Exception(GetLocalizedString("REDLINEUPLOADSHPZIPERROR", $locale));
+            } else {
+                throw new Exception(GetLocalizedString("REDLINEUPLOADSHPZIPERROR", $locale));
+            }
         }
         $extraXml = "";
         if (strcmp($fdoProvider, "OSGeo.SDF") == 0) { //Need to set ReadOnly = false for SDF
@@ -613,7 +634,16 @@
         $fsXml = sprintf(file_get_contents("templates/markupfeaturesource.xml"), $fdoProvider, $fileParam, $dataName, $extraXml);
         $bs2 = new MgByteSource($fsXml, strlen($fsXml));
         $resourceService->SetResource($markupFsId, $bs2->GetReader(), null);
-        $resourceService->SetResourceData($markupFsId, $dataName, "File", $bs->GetReader());
+        if (count($shpFileParts) > 0) {
+            foreach ($shpFileParts as $name => $path) {
+                $bs3 = new MgByteSource($path);
+                $resourceService->SetResourceData($markupFsId, $name, "File", $bs3->GetReader());
+                //Cleanup
+                unlink($path);
+            }
+        } else { //Not a SHP file
+            $resourceService->SetResourceData($markupFsId, $dataName, "File", $bs->GetReader());
+        }
 
         //Query the geometry types
         $schemas = $featureService->DescribeSchema($markupFsId, "", null);
@@ -627,8 +657,23 @@
         if ($clsProps->IndexOf($geomProp) >= 0) {
             $geom = $clsProps->GetItem($geomProp);
             $geomTypes = $geom->GetGeometryTypes();
+            //Since we're here. Validate the schema requirements. If this was created by this widget previously
+            //it will be valid
+            $idProps = $klass->GetIdentityProperties();
+            if ($idProps->GetCount() != 1) {
+                throw new Exception(GetLocalizedString("REDLINEUPLOADINVALIDSCHEMA", $locale));
+            } else {
+                //Must be auto-generated (implying numerical as well)
+                $keyProp = $idProps->GetItem(0);
+                if (!$keyProp->IsAutoGenerated()) {
+                    throw new Exception(GetLocalizedString("REDLINEUPLOADINVALIDSCHEMA", $locale));
+                }
+            }
+            if ($clsProps->IndexOf("Text") < 0) {
+                throw new Exception(GetLocalizedString("REDLINEUPLOADINVALIDSCHEMA", $locale));
+            }
         } else {
-            throw new Exception(GetLocalizedString("REDLINEUPLOADNOGEOMETRY", $locale));
+            throw new Exception(GetLocalizedString("REDLINEUPLOADINVALIDSCHEMA", $locale));
         }
 
         //Set up default style args



More information about the fusion-commits mailing list