KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > oai > DSpaceRecordFactory


1 /*
2  * DSpaceRecordFactory.java
3  *
4  * Version: $Revision: 1.12 $
5  *
6  * Date: $Date: 2005/04/20 14:22:35 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40 package org.dspace.app.oai;
41
42 import java.util.Date JavaDoc;
43 import java.util.Iterator JavaDoc;
44 import java.util.LinkedList JavaDoc;
45 import java.util.List JavaDoc;
46 import java.util.Properties JavaDoc;
47
48 import org.apache.log4j.Logger;
49 import org.dspace.content.DCDate;
50 import org.dspace.search.HarvestedItemInfo;
51
52 import ORG.oclc.oai.server.catalog.RecordFactory;
53 import ORG.oclc.oai.server.verb.CannotDisseminateFormatException;
54
55 /**
56  * Implementation of the OAICat RecordFactory base class for DSpace items.
57  *
58  * @author Robert Tansley
59  * @version $Revision: 1.12 $
60  */

61 public class DSpaceRecordFactory extends RecordFactory
62 {
63     /** log4j category */
64     private static Logger log = Logger.getLogger(DSpaceRecordFactory.class);
65
66     public DSpaceRecordFactory(Properties JavaDoc properties)
67     {
68         // We don't use the OAICat properties; pass on up
69
super(properties);
70     }
71
72     public String JavaDoc fromOAIIdentifier(String JavaDoc identifier)
73     {
74         // Our local identifier is actually the same as the OAI one (the Handle)
75
return identifier;
76     }
77
78     public String JavaDoc quickCreate(Object JavaDoc nativeItem, String JavaDoc schemaURL,
79             String JavaDoc metadataPrefix) throws IllegalArgumentException JavaDoc,
80             CannotDisseminateFormatException
81     {
82         // Not supported
83
return null;
84     }
85
86     public String JavaDoc getOAIIdentifier(Object JavaDoc nativeItem)
87     {
88         String JavaDoc h = DSpaceOAICatalog.OAI_ID_PREFIX
89                 + ((HarvestedItemInfo) nativeItem).handle;
90
91         return h;
92     }
93
94     public String JavaDoc getDatestamp(Object JavaDoc nativeItem)
95     {
96         Date JavaDoc d = ((HarvestedItemInfo) nativeItem).datestamp;
97
98         // Return as ISO8601
99
return new DCDate(d).toString();
100     }
101
102     public Iterator JavaDoc getSetSpecs(Object JavaDoc nativeItem)
103     {
104         HarvestedItemInfo hii = (HarvestedItemInfo) nativeItem;
105         Iterator JavaDoc i = hii.collectionHandles.iterator();
106         List JavaDoc setSpecs = new LinkedList JavaDoc();
107
108         // Convert the DB Handle string 123.456/789 to the OAI-friendly
109
// hdl_123.456/789
110
while (i.hasNext())
111         {
112             String JavaDoc handle = "hdl_" + (String JavaDoc) i.next();
113             setSpecs.add(handle.replace('/', '_'));
114         }
115
116         return setSpecs.iterator();
117     }
118
119     public boolean isDeleted(Object JavaDoc nativeItem)
120     {
121         HarvestedItemInfo hii = (HarvestedItemInfo) nativeItem;
122
123         return hii.withdrawn;
124     }
125
126     public Iterator JavaDoc getAbouts(Object JavaDoc nativeItem)
127     {
128         // Nothing in the about section for now
129
return new LinkedList JavaDoc().iterator();
130     }
131 }
132
Popular Tags