Author: sevein
Date: Wed Oct 12 18:01:12 2011
New Revision: 10057

Log:
Search file details into XML

Modified:
   trunk/plugins/qtSwordPlugin/lib/qtPackageExtractor.class.php

Modified: trunk/plugins/qtSwordPlugin/lib/qtPackageExtractor.class.php
==============================================================================
--- trunk/plugins/qtSwordPlugin/lib/qtPackageExtractor.class.php        Wed Oct 
12 16:53:12 2011        (r10056)
+++ trunk/plugins/qtSwordPlugin/lib/qtPackageExtractor.class.php        Wed Oct 
12 18:01:12 2011        (r10057)
@@ -137,7 +137,7 @@
 
       break;
     }
- 
+
     $this->document = new SimpleXMLElement($this->document);
   }
 
@@ -149,14 +149,19 @@
     $main = $this->getMainDmdSec();
     $this->processDmdSec($main, $this->informationObject);
 
-    // Look into objects directory
-    $files = $this->getFilesFromDirectory();
+    foreach ($this->getFilesFromDirectory() as $item)
+    {
+      $parts = pathinfo($item);
+      $filename = $parts['filename'];
+      $uuid = $this->getUUID($filename);
+
+      $fptr = $this->searchFptr($uuid);
 
-    var_dump($files);
-    die();
+      // Upload/save file
+    }
 
     $this->informationObject->save();
-  }
+}
 
   public function clean()
   {
@@ -174,6 +179,32 @@
     return $dmdSec['0'];
   }
 
+  protected function searchFptr($uuid, $node = null)
+  {
+    if (!isset($node))
+    {
+      $node = $this->document->xpath('/mets/structMap/div/div');
+      $node = $node[0];
+    }
+
+    foreach ($node->children() as $item)
+    {
+      $name = $item->getName();
+
+      if ('div' == $name)
+      {
+        $this->searchFptr($uuid, $item);
+      }
+      else if ('fptr' == $name)
+      {
+        if (false !== strstr($item['FILEID'], $uuid))
+        {
+          return $item;
+        }
+      }
+    }
+  }
+
   protected function getFilesFromDirectory($dir = null)
   {
     $files = array();
@@ -193,7 +224,7 @@
           {
             $dir2 = $dir.'/'.$file;
             $files[] = $this->getFilesFromDirectory($dir2);
-          } 
+          }
           else
           {
             $files[] = $dir.'/'.$file;
@@ -201,9 +232,16 @@
         }
       }
 
-      closedir($handle); 
+      closedir($handle);
     }
 
     return $files;
   }
+
+  protected function getUUID($subject)
+  {
+    
preg_match('/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/', 
$subject, $matches);
+
+    return @$matches[0];
+  }
 }

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to