Author: peter
Date: Fri Sep  4 18:07:20 2009
New Revision: 3176

Log:
update XML import to accomodate new way of saving language codes (in 
multi-value arrays stored in one dbase row). Convert three character ISO639-2 
codes to two/three character RFC4646 codes upon import. Reconvert to three 
character ISO639-2 codes upon export for EAD as per best practice for that 
standard.

Modified:
   trunk/apps/qubit/modules/informationobject/templates/exportEadSuccess.xml.php
   trunk/apps/qubit/modules/object/config/import/ead.yml
   trunk/lib/QubitXmlImport.class.php

Modified: 
trunk/apps/qubit/modules/informationobject/templates/exportEadSuccess.xml.php
==============================================================================
--- 
trunk/apps/qubit/modules/informationobject/templates/exportEadSuccess.xml.php   
    Fri Sep  4 17:10:22 2009        (r3175)
+++ 
trunk/apps/qubit/modules/informationobject/templates/exportEadSuccess.xml.php   
    Fri Sep  4 18:07:20 2009        (r3176)
@@ -49,9 +49,9 @@
 <profiledesc>
   <creation><date/></creation>
   <langusage>
-    <?php foreach 
($informationObject->getProperties('language_of_information_object_description')
 as $languageCode): ?>
-      <language langcode="<?php echo ($iso6392 = 
$iso639convertor->getID3($languageCode->getValue())) ? $iso6392 : 
strtoupper($languageCode->getValue()) ?>"><?php echo 
htmlentities(format_language($languageCode->getValue())) ?></language>
-    <?php endforeach; ?>
+  <?php foreach ($informationObject->languageOfDescription as $languageCode): 
?>
+    <language langcode="<?php echo ($iso6392 = 
$iso639convertor->getID3($languageCode)) ? strtolower($iso6392) : $languageCode 
?>"><?php echo htmlentities(format_language($languageCode)) ?></language>
+  <?php endforeach; ?>
   </langusage>
   <descrules><?php echo htmlentities($informationObject->getRules()) 
?></descrules>
 </profiledesc>
@@ -125,8 +125,8 @@
 </repository>
 
 <langmaterial>
-  <?php foreach 
($informationObject->getProperties('information_object_language') as 
$languageCode): ?>
-    <language langcode="<?php echo ($iso6392 = 
$iso639convertor->getID3($languageCode->getValue())) ? $iso6392 : 
strtoupper($languageCode->getValue()) ?>"><?php echo 
htmlentities(format_language($languageCode->getValue())) ?></language>
+  <?php foreach ($informationObject->language as $languageCode): ?>
+    <language langcode="<?php echo ($iso6392 = 
$iso639convertor->getID3($languageCode)) ? strtolower($iso6392) : $languageCode 
?>"><?php echo htmlentities(format_language($languageCode)) ?></language>
   <?php endforeach; ?>
 </langmaterial>
 
@@ -272,8 +272,8 @@
 </repository>
 
 <langmaterial>
-  <?php foreach ($descendant->getProperties('information_object_language') as 
$languageCode): ?>
-    <language langcode="<?php echo ($iso6392 = 
$iso639convertor->getID3($languageCode->getValue())) ? $iso6392 : 
strtoupper($languageCode->getValue()) ?>"><?php echo 
htmlentities(format_language($languageCode->getValue())) ?></language>
+  <?php foreach ($informationObject->language as $languageCode): ?>
+    <language langcode="<?php echo ($iso6392 = 
$iso639convertor->getID3($languageCode)) ? strtolower($iso6392) : $languageCode 
?>"><?php echo htmlentities(format_language($languageCode)) ?></language>
   <?php endforeach; ?>
 </langmaterial>
 

Modified: trunk/apps/qubit/modules/object/config/import/ead.yml
==============================================================================
--- trunk/apps/qubit/modules/object/config/import/ead.yml       Fri Sep  4 
17:10:22 2009        (r3175)
+++ trunk/apps/qubit/modules/object/config/import/ead.yml       Fri Sep  4 
18:07:20 2009        (r3176)
@@ -106,8 +106,7 @@
 
     languages:
       XPath:   "did/langmaterial/language/@langcode"
-      Method:  addProperty
-      Parameters: [$name = 'information_object_language', $nodeValue, 
"$options = array('scope' => 'languages', 'sourceCulture' => true)"]
+      Method:  setLangcode
 
     phystech:
       XPath:  "(phystech | descgrp/phystech)"

Modified: trunk/lib/QubitXmlImport.class.php
==============================================================================
--- trunk/lib/QubitXmlImport.class.php  Fri Sep  4 17:10:22 2009        (r3175)
+++ trunk/lib/QubitXmlImport.class.php  Fri Sep  4 18:07:20 2009        (r3176)
@@ -231,56 +231,77 @@
 
           if (is_object($nodeList2))
           {
-            foreach ($nodeList2 as $domNode2)
-            {
-              // normalize the node text (trim whitespace manually); NB: this 
will strip any child elements, eg. HTML tags
-              $nodeValue = trim(preg_replace('/[\n\r\s]+/', ' ', 
$domNode2->nodeValue));
-
-              // if you want the full XML from the node, use this
-              $nodeXML = $domNode2->ownerDocument->saveXML($domNode2);
 
-              // set the parameters for the method call
-              if (empty($methodMap['Parameters']))
-              {
-                $parameters = array($nodeValue);
-              }
-              else
-              {
-                $parameters = array();
-                foreach ((array) $methodMap['Parameters'] as $parameter)
+            switch($name)
+            {
+              // hack: some multi-value elements (e.g. 'languages') need to 
get passed as one array instead of individual nodes values
+              case 'languages':
+                $langCodeConvertor = new fbISO639_Map;
+                $value = array();
+                foreach ($nodeList2 as $nodeee)
                 {
-                  // if the parameter begins with %, evaluate it as an XPath 
expression relative to the current node
-                  if ('%' == substr($parameter, 0, 1))
+                  if ($twoCharCode = 
$langCodeConvertor->getID2($nodeee->nodeValue))
+                  {
+                    $value[] = strtolower($twoCharCode);
+                  }
+                  else
                   {
-                    // evaluate the XPath expression
-                    $xPath = substr($parameter, 1);
-                    $result = $importDOM->xpath->query($xPath, $domNode2);
+                    $value[] = $nodeee->nodeValue;
+                  }
+                }
+                $currentObject->language = $value;
+                break;
+              default:
+                foreach ($nodeList2 as $domNode2)
+                {
+                  // normalize the node text (trim whitespace manually); NB: 
this will strip any child elements, eg. HTML tags
+                  $nodeValue = trim(preg_replace('/[\n\r\s]+/', ' ', 
$domNode2->nodeValue));
 
-                    if ($result->length > 1)
+                  // if you want the full XML from the node, use this
+                  $nodeXML = $domNode2->ownerDocument->saveXML($domNode2);
+                  // set the parameters for the method call
+                  if (empty($methodMap['Parameters']))
+                  {
+                    $parameters = array($nodeValue);
+                  }
+                  else
+                  {
+                    $parameters = array();
+                    foreach ((array) $methodMap['Parameters'] as $parameter)
                     {
-                      // convert nodelist into an array
-                      foreach ($result as $element)
+                      // if the parameter begins with %, evaluate it as an 
XPath expression relative to the current node
+                      if ('%' == substr($parameter, 0, 1))
                       {
-                        $resultArray[] = $element->nodeValue;
+                        // evaluate the XPath expression
+                        $xPath = substr($parameter, 1);
+                        $result = $importDOM->xpath->query($xPath, $domNode2);
+
+                        if ($result->length > 1)
+                        {
+                          // convert nodelist into an array
+                          foreach ($result as $element)
+                          {
+                            $resultArray[] = $element->nodeValue;
+                          }
+                          $parameters[] = $resultArray;
+                        }
+                        else
+                        {
+                          // pass the node value unaltered; this provides an 
alternative to $nodeValue above
+                          $parameters[] = $result->item(0)->nodeValue;
+                        }
+                      }
+                      else
+                      {
+                        // NB: this will throw warnings when DOM is accessed 
directly from mapping and returns null objects
+                        eval('$parameters[] = '.$parameter.';');
                       }
-                      $parameters[] = $resultArray;
-                    }
-                    else
-                    {
-                      // pass the node value unaltered; this provides an 
alternative to $nodeValue above
-                      $parameters[] = $result->item(0)->nodeValue;
                     }
                   }
-                  else
-                  {
-                    // NB: this will throw warnings when DOM is accessed 
directly from mapping and returns null objects
-                    eval('$parameters[] = '.$parameter.';');
-                  }
-                }
-              }
 
-              // invoke the object and method defined in the schema map
-              call_user_func_array(array( & $currentObject, 
$methodMap['Method']), $parameters);
+                  // invoke the object and method defined in the schema map
+                  call_user_func_array(array( & $currentObject, 
$methodMap['Method']), $parameters);
+                }
             }
 
             unset($nodeList2);

--~--~---------~--~----~------------~-------~--~----~
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.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to