Commits

dloy  committed 61fcfab

get dc from non-qualifieddc
allow Long use for file size (bug)

  • Participants
  • Parent commits 92f3474

Comments (0)

Files changed (4)

File core/src/main/java/org/cdlib/mrt/core/DC.java

 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 import org.cdlib.mrt.utility.DOMParser;
             LinkedHashList<String, String> returnList = new LinkedHashList<String, String>();
             //extract all of the file elements
             NodeList list = null;
+            boolean isDC = isDC(root, logger);
             //to accommodate possibility that namespace is not default,
             //use xpath local-name for this whole section.
             list = DOMParser.getNodeList(root,
                     "/*[local-name()='mets']" +
                     "/*[local-name()='dmdSec']" +
-                    "/*[local-name()='mdWrap']" +
-                    "/*[local-name()='xmlData']",
+                    "/*[local-name()='mdWrap']",
                 logger);
             int size = list.getLength();
             Element fileNode = null;
                 throw new TException.INVALID_OR_MISSING_PARM(
                     MESSAGE + "METS does not contain dmdSec");
             }
-            
             for (int i=0; i<size; i++) {
                 fileNode = (Element)list.item(i);
-                NodeList listMODS = DOMParser.getNodeList(fileNode, "*[local-name()='mods']", logger);
+                isDC = isDC(fileNode, logger);
+                if (DEBUG) System.out.println("isDC=" + isDC);
+                NodeList listMODS = DOMParser.getNodeList(fileNode,
+                    "*[local-name()='xmlData']/*[local-name()='mods']", logger);
                 int modsSize = listMODS.getLength();
                 if (modsSize > 0) {
-                    return getDCFromModsMets(metsDoc, logger);
+                    getDCFromModsMets(returnList, metsDoc, logger);
+                    continue;
                 }
-                NodeList listDC = DOMParser.getNodeList(fileNode, "*[local-name()='qualifieddc']", logger);
+
+                NodeList listDC = DOMParser.getNodeList(fileNode, "*[local-name()='xmlData']/*[local-name()='qualifieddc']", logger);
                 int dcSize = listDC.getLength();
                 if (dcSize > 0) {
-                    return getMetsDC(metsDoc, logger);
+                    getMetsDC(returnList,metsDoc, logger);
+                    continue;
+
+                } else if (isDC) {
+                    NodeList nodeListXMLData = DOMParser.getNodeList(fileNode, "*[local-name()='xmlData']", logger);
+                    dcSize = nodeListXMLData.getLength();
+                    if (DEBUG) System.out.println("dcSize=" + dcSize);
+                    if (dcSize > 0) {
+                        Element xmlDataElement = (Element)nodeListXMLData.item(0);
+                        NodeList nodeList = xmlDataElement.getChildNodes();
+                        int xmlDataSize = nodeList.getLength();
+                        if (DEBUG) System.out.println("xmlDataSize=" + xmlDataSize);
+                        getMetsDC(returnList, nodeList, logger);
+                        continue;
+                    }
                 }
                 continue;
             }
         }
     }
 
+    public static boolean isDC(Element fileNode,
+            LoggerInf logger)
+        throws TException
+    {
+
+        try {
+            String mdType = fileNode.getAttribute("MDTYPE");
+            if (StringUtil.isEmpty(mdType)) return false;
+            mdType = mdType.toUpperCase();
+            if (mdType.equals("DC")) return true;
+            return false;
+
+        }  catch(Exception e)  {
+            if (logger != null)
+            {
+                logger.logError(
+                    "Main: Encountered exception:" + e, 0);
+                logger.logError(
+                        StringUtil.stackTrace(e), 10);
+            }
+            throw new TException(e);
+        }
+    }
     /**
      * Extract DC from METS
      * @param mets METS record
      * @return list of DC values
      * @throws TException
      */
-    public static LinkedHashList getMetsDC (
+    public static void getMetsDC (
+            LinkedHashList<String, String> returnList,
             Document mets,
             LoggerInf logger)
         throws TException
         try {
 
             Element root = mets.getDocumentElement();
-            LinkedHashList<String, String> returnList = new LinkedHashList<String, String>();
             //extract all of the file elements
             NodeList list = null;
             //to accommodate possibility that namespace is not default,
                     "/*[local-name()='xmlData']" +
                     "/*[local-name()='qualifieddc']/*",
                 logger);
+            getMetsDC(returnList, list, logger);
+
+        } catch (TException fe) {
+            throw fe;
+
+        }  catch(Exception e)  {
+            if (logger != null)
+            {
+                logger.logError(
+                    "Main: Encountered exception:" + e, 0);
+                logger.logError(
+                        StringUtil.stackTrace(e), 10);
+            }
+            throw new TException(e);
+        }
+    }
+    /**
+     * Extract DC from METS
+     * @param mets METS record
+     * @param logger file logger
+     * @return list of DC values
+     * @throws TException
+     */
+    public static void getMetsDC (
+            LinkedHashList<String, String> returnList,
+            NodeList list,
+            LoggerInf logger)
+        throws TException
+    {
+
+        try {
+
+            
             int size = list.getLength();
             Element fileNode = null;
             if (DEBUG) System.out.println("***size=" + size);
                     MESSAGE + "METS does not contain dmdSec");
             }
             for (int i=0; i<size; i++) {
+                if (list.item(i).getNodeType() != Node.ELEMENT_NODE) continue;
                 fileNode = (Element)list.item(i);
                 String name = fileNode.getLocalName();
                 String content = DOMParser.getSimpleElementText(fileNode, logger);
                 content = XMLUtil.decode(content);
                 returnList.put(name, content);
             }
-            return returnList;
 
         } catch (TException fe) {
             throw fe;
      * @throws TException process exception
      */
     public static LinkedHashList<String, String> getOAIDC (
+            LinkedHashList<String, String> returnList,
             String dc,
             LoggerInf logger)
         throws TException
             ByteArrayInputStream bas = new ByteArrayInputStream(dc.getBytes("utf-8"));
             Document doc = DOMParser.doParse(bas, logger);
             Element root = doc.getDocumentElement();
-            LinkedHashList<String, String> returnList = new LinkedHashList<String, String>();
             //extract all of the file elements
             NodeList list = null;
             //to accommodate possibility that namespace is not default,
      * @return list of DC values
      * @throws TException
      */
-    public static LinkedHashList<String, String>  getDCFromModsMets (
+    public static void  getDCFromModsMets (
+            LinkedHashList<String, String> returnList,
             Document mets,
             LoggerInf logger)
         throws TException
             String mods = DC.getMetsMods(mets, logger);
             if (DEBUG) System.out.println("getDCFromModsMets MODS:" + mods);
             String dc = DC.mods2dc(mods, logger);
-            LinkedHashList<String, String> list = getOAIDC(dc, logger);
-            return list;
+            getOAIDC(returnList, dc, logger);
 
         } catch (TException fe) {
             throw fe;

File core/src/main/java/org/cdlib/mrt/core/FileComponent.java

         }
 
         try {
-            setSize(Integer.parseInt(sizeS));
+            setSize(Long.parseLong(sizeS));
 
         } catch (Exception ex) {
             throw new TException.INVALID_DATA_FORMAT(

File core/src/test/java/org/cdlib/mrt/core/DCTest.java

         throws TException
     {
         try {
+            boolean dumpMets = false;
             LinkedHashList<String, String> retList = null;
-            retList = testMets("mets-dc.xml");
+            retList = testMets(dumpMets, "mets-dc.xml");
             assertTrue(retList.size() > 5);
-            retList = testMets("mets-mods.xml");
+            retList = testMets(dumpMets, "mets-mods.xml");
             assertTrue(retList.size() > 5);
-            retList = testMets("mets-mods2.xml");
+            retList = testMets(dumpMets, "mets-mods2.xml");
+            assertTrue(retList.size() > 5);
+            retList = testMets(dumpMets, "mets-dc-no-qualifieddc.xml");
             assertTrue(retList.size() > 5);
             assertTrue(true);
 
     }
 
     public LinkedHashList<String, String> testMets(
+            boolean dumpMets,
             String resourceName
             )
         throws TException
 
             InputStream metsStream = getResource(resourceName);
             String metsS = StringUtil.streamToString(metsStream, "utf-8");
-            System.out.println("METS:" + metsS);
+            if (dumpMets) System.out.println("METS:" + metsS);
             metsStream = getResource(resourceName);
             Document mets = getDocument(metsStream, logger);
             LinkedHashList<String, String> list = DC.getDC (mets, logger);
             System.out.println("METS:" + metsS);
             metsStream = getResource("mets-mods.xml");
             Document mets = getDocument(metsStream, logger);
-            LinkedHashList<String, String> list = DC.getDCFromModsMets (mets, logger);
+            LinkedHashList<String, String> list = new LinkedHashList<String, String>();
+            DC.getDCFromModsMets (list, mets, logger);
             dumpList("*****TestMods*****", list);
-            assertTrue(true);
+            assertTrue(list.size() > 0);
 
 
         } catch (Exception ex) {
             System.out.println("METS:" + metsS);
             metsStream = getResource("mets-dc.xml");
             Document mets = getDocument(metsStream, logger);
-            LinkedHashList<String, String> list = DC.getMetsDC (mets, logger);
+            LinkedHashList<String, String> list = new LinkedHashList<String, String>();
+            DC.getMetsDC (list, mets, logger);
             dumpList("*****TestDC*****", list);
-            assertTrue(true);
+            assertTrue(list.size() > 0);
+
+
+        } catch (Exception ex) {
+            System.out.println("Exception:" + ex);
+            ex.printStackTrace();
+            assertFalse("TestIT exception:" + ex, true);
+        }
+    }
+
+    //@Test
+    public void testDCNoQualified()
+        throws TException
+    {
+        try {
+
+            LoggerInf logger = new TFileLogger(NAME, 50, 50);
+
+            InputStream metsStream = getResource("mets-dc-noqualifieddc.xml");
+            String metsS = StringUtil.streamToString(metsStream, "utf-8");
+            System.out.println("METS:" + metsS);
+            metsStream = getResource("mets-dc.xml");
+            Document mets = getDocument(metsStream, logger);
+            
+            LinkedHashList<String, String> list = new LinkedHashList<String, String>();
+            DC.getMetsDC (list, mets, logger);
+            dumpList("*****TestDC NOQUALIFIEDDC*****", list);
+            assertTrue(list.size() > 0);
 
 
         } catch (Exception ex) {

File core/src/test/resources/testresources/mets-dc-no-qualifieddc.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<mets:mets xmlns:dc="http://purl.org/dc/elements/1.1/"
+           xmlns:xs="http://www.w3.org/2001/XMLSchema"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xmlns:xlink="http://www.w3.org/1999/xlink"
+           xmlns:mets="http://www.loc.gov/METS/"
+           xsi:schemaLocation="http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd"
+           OBJID="ark:/13030/c89p2zph"
+           LABEL="Liberty Loan Train during World War I Registration Day event in Banning, California"
+           TYPE="image"
+           PROFILE="http://www.loc.gov/mets/profiles/00000010.xml">
+   <mets:metsHdr CREATEDATE="2011-07-13T12:41:05.003-07:00"
+                 LASTMODDATE="2011-07-13T12:41:05.003-07:00"
+                 RECORDSTATUS="NEW"
+                 ID="METSHDRID-1.162">
+      <mets:agent ROLE="EDITOR" TYPE="ORGANIZATION">
+         <mets:name>California Digital Library</mets:name>
+         <mets:note>Record created by conversion of CONTENTdm XML metadata</mets:note>
+         <mets:note>Created using 7train</mets:note>
+      </mets:agent>
+      <mets:altRecordID>CBAN_066</mets:altRecordID>
+   </mets:metsHdr>
+   <mets:dmdSec ID="DC" CREATED="2011-07-13T12:41:05.003-07:00">
+      <mets:mdWrap MIMETYPE="text/xml" MDTYPE="DC" LABEL="DC">
+         <mets:xmlData>
+            <dc:identifier>CBAN_066</dc:identifier>
+            <dc:title>Liberty Loan Train during World War I Registration Day event in Banning, California</dc:title>
+            <dc:creator>Unknown</dc:creator>
+            <dcterms:created xmlns:dcterms="http://purl.org/dc/terms/">6366</dcterms:created>
+            <dc:description>Exterior photograph of World War I Registration Day event in Banning, California showing the Liberty Loan Train as it arrived in Banning.</dc:description>
+            <dc:type>Image</dc:type>
+            <dc:format>1 sepia tone photograph; 6.7 x 9.2 cm.</dc:format>
+            <dc:publisher>Banning Library District</dc:publisher>
+            <dc:relation>http://www.oac.cdlib.org/findaid/ark:/13030/kt6779r9df</dc:relation>
+            <dc:rights>Copyright status unknown</dc:rights>
+            <dc:rights>Copyright status unknown. Some materials in these collections may be protected by the U.S. Copyright Law (Title 17, U.S.C.). In addition, the reproduction of some materials may be restricted by terms of gift or purchase agreements, donor restrictions, privacy and publicity rights, licensing and trademarks. Transmission or reproduction of materials protected by copyright beyond that allowed by fair use requires the written permission of the copyright owners. Works not in the public domain cannot be commercially exploited without permission of the copyright owner. Responsibility for any use rests exclusively with the user.</dc:rights>
+            <dc:language>eng</dc:language>
+            <dc:coverage>Banning (Calif.)</dc:coverage>
+            <dc:subject>Events-California-Banning</dc:subject>
+            <dc:subject>World War I-California-Banning</dc:subject>
+            <dc:subject>Trains-California-Banning</dc:subject>
+            <dc:type>Photographs</dc:type>
+            <dc:identifier>86-02-05-03</dc:identifier>
+            <dc:contributor>Barker, C. O.</dc:contributor>
+         </mets:xmlData>
+      </mets:mdWrap>
+   </mets:dmdSec>
+   <mets:dmdSec ID="ead">
+      <mets:mdRef LOCTYPE="URL" MDTYPE="EAD" ID="kt6779r9df"
+                  LABEL="Banning Library District Local History Collection"
+                  xlink:href="http://www.oac.cdlib.org/findaid/ark:/13030/kt6779r9df"/>
+   </mets:dmdSec>
+   <mets:dmdSec ID="repo">
+      <mets:mdWrap MIMETYPE="text/xml" MDTYPE="DC" LABEL="Repository">
+         <mets:xmlData>
+            <dc:title>Banning Library District</dc:title>
+            <dc:identifier>ark:/13030/kt7q2nf6fv</dc:identifier>
+            <dc:identifier/>
+         </mets:xmlData>
+      </mets:mdWrap>
+   </mets:dmdSec>
+   <mets:fileSec ID="FILESECID-1.162">
+      <mets:fileGrp USE="thumbnail image">
+         <mets:file ID="FILEID-1.162.41">
+            <mets:FLocat LOCTYPE="URL"
+                         xlink:href="http://contentdm.califa.org/cgi-bin/thumbnail.exe?CISOROOT=/cban&amp;CISOPTR=176"
+                         xlink:role="thumbnail"/>
+         </mets:file>
+      </mets:fileGrp>
+      <mets:fileGrp USE="reference image">
+         <mets:file ID="FILEID-1.162.43">
+            <mets:FLocat LOCTYPE="URL"
+                         xlink:href="http://contentdm.califa.org/cgi-bin/getimage.exe?CISOROOT=/cban&amp;CISOPTR=176&amp;DMWIDTH=100000&amp;DMHEIGHT=100000&amp;DMSCALE=100"
+                         xlink:role="access"/>
+         </mets:file>
+      </mets:fileGrp>
+      <mets:fileGrp USE="archive image">
+         <mets:file ID="FILEID-1.162.34" MIMETYPE="image/jpeg">
+            <mets:FLocat LOCTYPE="URL" xlink:role="access"
+                         xlink:href="http://cdl-mredar-2.ad.ucop.edu/lsta/cban/jpeg/cban_066.jpg"/>
+         </mets:file>
+         <mets:file ID="FILEID-1.162.33" MIMETYPE="image/tiff">
+            <mets:FLocat LOCTYPE="URL"
+                         xlink:href="http://cdl-mredar-2.ad.ucop.edu/lsta/cban/tiff/cban_066.tif"
+                         xlink:role="master"/>
+         </mets:file>
+      </mets:fileGrp>
+   </mets:fileSec>
+   <mets:structMap>
+      <mets:div ID="DIVID-1.162" DMDID="DC"
+                LABEL="Liberty Loan Train during World War I Registration Day event in Banning, California">
+         <mets:div ID="DIVID-1.162.41" TYPE="thumbnail image">
+            <mets:fptr ID="FPTRID-1.162.41" FILEID="FILEID-1.162.41"/>
+         </mets:div>
+         <mets:div ID="DIVID-1.162.43" TYPE="reference image">
+            <mets:fptr ID="FPTRID-1.162.43" FILEID="FILEID-1.162.43"/>
+         </mets:div>
+         <mets:div ID="DIVID-AI-1-1.162.33" TYPE="archive image">
+            <mets:fptr ID="FPTRID-AI-1-1.162.33" FILEID="FILEID-1.162.34"/>
+         </mets:div>
+         <mets:div ID="DIVID-AI-2-1.162.33" TYPE="archive image">
+            <mets:fptr ID="FPTRID-AI-2-1.162.33" FILEID="FILEID-1.162.33"/>
+         </mets:div>
+      </mets:div>
+   </mets:structMap>
+</mets:mets>