1
2 /***
3 *Copyright (c) 2000-2002 OCLC Online Computer Library Center,
4 *Inc. and other contributors. All rights reserved. The contents of this file, as updated
5 *from time to time by the OCLC Office of Research, are subject to OCLC Research
6 *Public License Version 2.0 (the "License"); you may not use this file except in
7 *compliance with the License. You may obtain a current copy of the License at
8 *http://purl.oclc.org/oclc/research/ORPL/. Software distributed under the License is
9 *distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
10 *or implied. See the License for the specific language governing rights and limitations
11 *under the License. This software consists of voluntary contributions made by many
12 *individuals on behalf of OCLC Research. For more information on OCLC Research,
13 *please see http://www.oclc.org/oclc/research/.
14 *
15 *The Original Code is XMLFileRecordFactory.java.
16 *The Initial Developer of the Original Code is Jeff Young.
17 *Portions created by ______________________ are
18 *Copyright (C) _____ _______________________. All Rights Reserved.
19 *Contributor(s):______________________________________.
20 */
21
22 package astrogrid.registry.oai;
23
24 import ORG.oclc.oai.server.catalog.*;
25
26 import java.util.ArrayList;
27 import java.util.Date;
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Properties;
32 import java.util.StringTokenizer;
33 import ORG.oclc.oai.server.verb.BadArgumentException;
34
35 /***
36 * XMLFileRecordFactory converts native XML "items" to "record" Strings.
37 * This factory assumes the native XML item looks exactly like the <record>
38 * element of an OAI GetRecord response, with the possible exception that the
39 * <metadata> element contains multiple metadataFormats from which to choose.
40 */
41 public class XMLExistRecordFactory extends RecordFactory {
42
43
44 /***
45 * Construct an XMLFileRecordFactory capable of producing the Crosswalk(s)
46 * specified in the properties file.
47 * @param properties Contains information to configure the factory:
48 * specifically, the names of the crosswalk(s) supported
49 * @exception IllegalArgumentException Something is wrong with the argument.
50 */
51 public XMLExistRecordFactory(Properties properties)
52 throws IllegalArgumentException {
53 super(properties);
54
55
56
57
58 }
59
60 /***
61 * Utility method to parse the 'local identifier' from the OAI identifier
62 *
63 * @param identifier OAI identifier (e.g. oai:oaicat.oclc.org:ID/12345)
64 * @return local identifier (e.g. ID/12345).
65 */
66 protected String fromOAIIdentifier(String identifier) {
67 try {
68
69
70
71
72 return identifier;
73 } catch (Exception e) {
74 return null;
75 }
76 }
77
78 /***
79 * Construct an OAI identifier from the native item
80 *
81 * @param nativeItem native Item object
82 * @return OAI identifier
83 */
84 public String getOAIIdentifier(Object nativeItem) {
85 StringBuffer sb = new StringBuffer();
86
87
88
89 sb.append(getLocalIdentifier(nativeItem));
90 return sb.toString();
91 }
92
93 /***
94 * Extract the local identifier from the native item
95 *
96 * @param nativeItem native Item object
97 * @return local identifier
98 */
99 public String getLocalIdentifier(Object nativeItem) {
100 return (String)((HashMap)nativeItem).get("localIdentifier");
101 }
102
103 /***
104 * get the datestamp from the item
105 *
106 * @param nativeItem a native item presumably containing a datestamp somewhere
107 * @return a String containing the datestamp for the item
108 * @exception IllegalArgumentException Something is wrong with the argument.
109 */
110 public String getDatestamp(Object nativeItem)
111 throws IllegalArgumentException {
112 return (String)((HashMap)nativeItem).get("datestamp");
113 }
114
115 /***
116 * get the setspec from the item
117 *
118 * @param nativeItem a native item presumably containing a setspec somewhere
119 * @return a String containing the setspec for the item
120 * @exception IllegalArgumentException Something is wrong with the argument.
121 */
122 public Iterator getSetSpecs(Object nativeItem)
123 throws IllegalArgumentException {
124 List setSpecs = (List)((HashMap)nativeItem).get("setSpecs");
125 if (setSpecs != null)
126 return setSpecs.iterator();
127 else
128 return null;
129 }
130
131 /***
132 * Get the about elements from the item
133 *
134 * @param nativeItem a native item presumably containing about information somewhere
135 * @return a Iterator of Strings containing <about>s for the item
136 * @exception IllegalArgumentException Something is wrong with the argument.
137 */
138 public Iterator getAbouts(Object nativeItem) throws IllegalArgumentException {
139 return null;
140 }
141
142 /***
143 * Is the record deleted?
144 *
145 * @param nativeItem a native item presumably containing a possible delete indicator
146 * @return true if record is deleted, false if not
147 * @exception IllegalArgumentException Something is wrong with the argument.
148 */
149 public boolean isDeleted(Object nativeItem)
150 throws IllegalArgumentException {
151 return false;
152 }
153
154 /***
155 * Allows classes that implement RecordFactory to override the default create() method.
156 * This is useful, for example, if the entire <record> is already packaged as the native
157 * record. Return null if you want the default handler to create it by calling the methods
158 * above individually.
159 *
160 * @param nativeItem the native record
161 * @param schemaURL the schemaURL desired for the response
162 * @param the metadataPrefix from the request
163 * @return a String containing the OAI <record> or null if the default method should be
164 * used.
165 */
166 public String quickCreate(Object nativeItem, String schemaLocation, String metadataPrefix) {
167
168 return null;
169 }
170 }