Author: sevein
Date: Wed Oct 12 15:47:16 2011
New Revision: 10043
Log:
Walk objects tree in Archivematica package
Modified:
trunk/plugins/qtSwordPlugin/lib/qtPackageExtractor.class.php
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/actions/depositAction.class.php
Modified: trunk/plugins/qtSwordPlugin/lib/qtPackageExtractor.class.php
==============================================================================
--- trunk/plugins/qtSwordPlugin/lib/qtPackageExtractor.class.php Wed Oct
12 15:46:27 2011 (r10042)
+++ trunk/plugins/qtSwordPlugin/lib/qtPackageExtractor.class.php Wed Oct
12 15:47:16 2011 (r10043)
@@ -26,6 +26,9 @@
$format = null,
$type = null;
+ public
+ $informationObject;
+
public function __construct($filename, array $options = array())
{
$this->filename = $filename;
@@ -39,49 +42,50 @@
{
$this->type = $options['type'];
}
-
- $this->extract();
-
- $this->document = new SimpleXMLElement($this->document);
-
- $this->getMainDmdSec();
}
- protected function processDmdSec($item)
+ protected function processDmdSec($xml, $informationObject = null)
{
- foreach ($item->xpath('mdWrap/xmlData/dublincore/dcterms:*') as $item)
+ if (!isset($informationObject))
+ {
+ $informationObject = new QubitInformationObject;
+ }
+
+ foreach ($xml->xpath('mdWrap/xmlData/dublincore/dcterms:*') as $item)
{
switch($item->getName())
{
- case 'title'
+ case 'title':
+ $informationObject->title = $item;
break;
- case 'creator'
+ case 'creator':
break;
- case 'subject'
+ case 'subject':
break;
- case 'description'
+ case 'description':
+ $informationObject->scopeAndContent = $item;
break;
- case 'publisher'
+ case 'publisher':
break;
- case 'contributor'
+ case 'contributor':
break;
- case 'date'
+ case 'date':
break;
- case 'type'
+ case 'type':
break;
@@ -114,9 +118,11 @@
break;
}
}
+
+ return $informationObject;
}
- protected function extract()
+ public function extract()
{
switch ($this->type)
{
@@ -131,6 +137,30 @@
break;
}
+
+ $this->document = new SimpleXMLElement($this->document);
+ }
+
+ public function process()
+ {
+ $this->informationObject = new QubitInformationObject;
+
+ // Main object
+ $main = $this->getMainDmdSec();
+ $this->processDmdSec($main, $this->informationObject);
+
+ // Look into objects directory
+ $files = $this->getFilesFromDirectory();
+
+ var_dump($files);
+ die();
+
+ $this->informationObject->save();
+ }
+
+ public function clean()
+ {
+ // unlink()...
}
protected function getMainDmdSec()
@@ -143,4 +173,37 @@
return $dmdSec['0'];
}
+
+ protected function getFilesFromDirectory($dir = null)
+ {
+ $files = array();
+
+ if (!isset($dir))
+ {
+ $dir = $this->directory.'/objects';
+ }
+
+ if ($handle = opendir($dir))
+ {
+ while (false !== ($file = readdir($handle)))
+ {
+ if ($file != "." && $file != "..")
+ {
+ if (is_dir($dir.'/'.$file))
+ {
+ $dir2 = $dir.'/'.$file;
+ $files[] = $this->getFilesFromDirectory($dir2);
+ }
+ else
+ {
+ $files[] = $dir.'/'.$file;
+ }
+ }
+ }
+
+ closedir($handle);
+ }
+
+ return $files;
+ }
}
Modified:
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/actions/depositAction.class.php
==============================================================================
---
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/actions/depositAction.class.php
Wed Oct 12 15:46:27 2011 (r10042)
+++
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/actions/depositAction.class.php
Wed Oct 12 15:47:16 2011 (r10043)
@@ -92,13 +92,24 @@
}
// Open the file, parse xml, get objects
- $extractor = new qtPackageExtractor($filename, array('format' =>
$this->packageFormat, 'type' => $this->packageContentType));
+ $extractor = new qtPackageExtractor($filename, array(
+ 'format' => $this->packageFormat,
+ 'type' => $this->packageContentType));
+
+ // Open package and XML document
+ $extractor->extract();
+
+ // Parse and create objects
+ $extractor->process();
+
+ $this->informationObject = $extractor->informationObject;
+
+ // Remove temporary files
+ $extractor->clean();
// Location
// $this->response->setHttpHeader('Location', '...');
- unlink($filename);
-
return $this->generateResponse(201, 'deposit');
}
else if ($request->isMethod('put') || $request->isMethod('delete'))
--
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.