Changeset 32860 for gs3-extensions
- Timestamp:
- 2019-03-05T15:30:27+13:00 (5 years ago)
- Location:
- gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/IIIFServerBridge.java
r32842 r32860 91 91 public void init(String site_name) throws UnavailableException, Exception 92 92 { 93 //org.greenstone.util.GlobalProperties.loadGlobalProperties(""); 93 ////GlobalProperties.loadGlobalProperties(config.getServletContext().getRealPath("")); 94 95 org.greenstone.util.GlobalProperties.loadGlobalProperties(""); 94 96 //org.greenstone.util.GlobalProperties.loadGlobalProperties(config.getServletContext().getRealPath("")); 95 org.greenstone.util.GlobalProperties.loadGlobalProperties("/home/osboxes/research/code/greenstone3-svn/web");97 //org.greenstone.util.GlobalProperties.loadGlobalProperties("/home/osboxes/research/code/greenstone3-svn/web"); 96 98 java.io.InputStream in = Class.forName("org.greenstone.util.GlobalProperties").getClassLoader().getResourceAsStream("global.properties"); 97 99 -
gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/collection/IIIFCollection.java
r32843 r32860 55 55 public class IIIFCollection extends Collection 56 56 { 57 58 57 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.IIIFCollection.class.getName()); 59 58 60 59 /** does this collection provide the IIIF service */ 61 60 protected boolean has_iiif = false; 62 63 /** earliest datestamp of an OAI collection. Also used to work out the earliest datetimestamp of the entire OAI repository */64 /*65 protected long earliestOAIDatestamp = 0;66 */67 61 68 62 /** a reference to the IIIFPMH service rack */ … … 116 110 } 117 111 118 // NOTE:119 // Calling cleanUp() on IIIFPMH object iiif_service_rack will120 // close any open dbs handles on module deactivation by121 // MESSAGEROUTER (no deactivate yet called by122 // IIIFMessageRouter)123 124 // But the IIIFPMH object's cleanUp() is already called by125 // superclass ServiceCluster, which goes around calling126 // cleanUp() on all services/ServiceRacks.127 128 112 /** 129 113 * whether this collection has IIIFPMH services … … 134 118 } 135 119 136 /**137 * The earliesttimestamp entry in the oai-inf.db representing when the collection was created.138 * Used by the OAIReceptionist139 */140 /*141 public long getEarliestOAIDatestamp()142 {143 return earliestOAIDatestamp;144 }145 */146 120 147 121 /** add any extra info for collection from IIIFConfig.xml */ … … 154 128 protected boolean configureServiceRackList(Element service_rack_list, Element extra_info) 155 129 { 156 130 //logger.info("*** Away to call getNamedElement() for service_rack_list = " + XMLConverter.getPrettyString(service_rack_list)); 131 157 132 // find the IIIFPMH service 158 133 Element iiif_service_xml = GSXML.getNamedElement(service_rack_list, GSXML.SERVICE_CLASS_ELEM, GSXML.NAME_ATT, "IIIFPMH"); … … 181 156 182 157 if (this.iiif_service_rack.configure(iiif_service_xml, extra_info)) { 183 184 /* 185 // once we've configured the IIIFPMH service, we can use the OAIPMH service to 186 // retrieve the earliest timestamp of this OAI collection from the oai-inf db 187 long earliestTimestamp = this.oai_service_rack.getEarliestTimestamp(); 188 if(earliestTimestamp == -1) { 189 this.earliestOAIDatestamp = -1; 190 logger.warn("No OAI timestamp for collection " + this.cluster_name); 191 } else { 192 this.earliestOAIDatestamp = earliestTimestamp; // milliseconds 193 } 194 */ 195 158 196 159 // find out the supported service types for this service module 197 160 Node types = this.iiif_service_rack.process(message); … … 224 187 } 225 188 226 227 189 return false; 228 190 } 229 230 191 } -
gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/core/IIIFMessageRouter.java
r32842 r32860 154 154 Element e = doc.createElement(GSXML.COLLECTION_ELEM); 155 155 e.setAttribute(GSXML.NAME_ATT, col_name); 156 /* 157 e.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified()); 158 e.setAttribute(OAIXML.EARLIEST_DATESTAMP, "" + c.getEarliestDatestamp()); 159 e.setAttribute(OAIXML.EARLIEST_OAI_DATESTAMP, "" + c.getEarliestOAIDatestamp()); 160 */ 156 161 157 this.collection_list.appendChild(e); 162 158 return true; 163 159 164 160 } 165 166 167 168 //*****************************************************************169 // auxiliary process methods170 //*****************************************************************171 172 /**173 * handles requests made to the MessageRouter itself174 *175 * @param req176 * - the request Element- <request>177 * @return the result Element - should be <response>178 */179 /*180 protected Element processMessage(Element req) {181 Document doc = XMLConverter.newDOM();182 String type = req.getAttribute(GSXML.TYPE_ATT);183 Element response = doc.createElement(GSXML.RESPONSE_ELEM);184 response.setAttribute(GSXML.FROM_ATT, "");185 186 if (type.equals(OAIXML.OAI_SET_LIST))187 {188 logger.info("oaiSetList request received");189 //this is the oai receptionist asking for a list of oai-support collections190 response.setAttribute(GSXML.TYPE_ATT, OAIXML.OAI_SET_LIST);191 response.appendChild(doc.importNode(this.collection_list, true));192 return response;193 }194 return super.processMessage(req);195 }196 197 */198 161 } -
gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/core/IIIFReceptionist.java
r32842 r32860 45 45 /** Instead of a config_params object, only a site_name is needed by iiif receptionist. */ 46 46 protected String site_name = null; 47 /** The unique repository identifier */48 /*49 protected String repository_id = null;50 */51 47 52 48 /** the configure file of this receptionist passed from the iiif restlet. */ … … 56 52 protected ModuleInterface mr = null; 57 53 58 // Some of the data/responses will not change while the servlet is running, so59 // we can cache them60 61 /** A list of all the collections available to this IIIF image server */62 protected Element collection_list = null;63 /** a vector of the names, for convenience */64 protected Vector<String> collection_name_list = null;65 /** If this is true, then there are no OAI enabled collections, so can always return66 noRecordsMatch (after validating the request params) */67 protected boolean noRecordsMatch = false;68 69 /** A set of all known 'sets' */70 protected HashSet<String> set_set = null;71 72 protected boolean has_super_colls = false;73 /** a hash of super set-> collection list */74 protected HashMap<String, Vector<String>> super_coll_map = null;75 /** store the super coll elements for convenience */76 HashMap<String, Element> super_coll_data = null;77 /** store the metadata formats ??????*/78 /** The identify response */79 protected Element identify_response = null;80 /** The list set response */81 protected Element listsets_response = null;82 /** the list metadata formats response */83 protected Element listmetadataformats_response = null;84 54 85 55 public IIIFReceptionist() { … … 97 67 this.site_name = site_name; 98 68 } 69 99 70 /** sets the message router - it should already be created and 100 71 * configured in the init() of a servlet/restlet (IIIFServerBridge, for example) before being passed to the receptionist*/ … … 115 86 } 116 87 iiif_config = config; 117 118 /*119 repository_id = getRepositoryIdentifier();120 */121 122 /*123 if (!configureSetInfo()) {124 // there are no sets125 logger.error("No sets (collections) available for IIIF");126 return false;127 }128 */129 88 130 89 return true; 131 90 } 132 91 133 /*134 private boolean configureSetInfo() {135 this.set_set = new HashSet<String>();136 137 // First, we get a list of all the OAI enabled collections138 // We get this by sending a listSets request to the MR139 Document doc = XMLConverter.newDOM();140 Element message = doc.createElement(GSXML.MESSAGE_ELEM);141 142 Element request = GSXML.createBasicRequest(doc, OAIXML.OAI_SET_LIST, "", null);143 message.appendChild(request);144 Node msg_node = mr.process(message);145 146 if (msg_node == null) {147 logger.error("returned msg_node from mr is null");148 return false;149 }150 Element resp = (Element)GSXML.getChildByTagName(msg_node, GSXML.RESPONSE_ELEM);151 Element coll_list = (Element)GSXML.getChildByTagName(resp, GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);152 if (coll_list == null) {153 logger.error("coll_list is null");154 return false;155 }156 157 this.collection_list = (Element)doc.importNode(coll_list, true);158 159 // go through and store a list of collection names for convenience160 // also create a 'to' attribute for the next request to the MR, which161 // is a ListSets request to each collection162 Node child = this.collection_list.getFirstChild();163 if (child == null) {164 logger.error("collection list has no children");165 noRecordsMatch = true;166 return false;167 }168 169 this.collection_name_list = new Vector<String>();170 StringBuffer to = new StringBuffer();171 boolean first = true;172 while (child != null) {173 if (child.getNodeName().equals(GSXML.COLLECTION_ELEM)) {174 String coll_id =((Element) child).getAttribute(GSXML.NAME_ATT);175 this.collection_name_list.add(coll_id);176 if (!first) {177 to.append(',');178 }179 first = false;180 to.append(coll_id+"/"+OAIXML.LIST_SETS);181 }182 child = child.getNextSibling();183 }184 if (first) {185 // we haven't found any collections186 logger.error("found no collection elements in collectionList");187 noRecordsMatch = true;188 return false;189 }190 Document listsets_doc = XMLConverter.newDOM();191 Element listsets_element = listsets_doc.createElement(OAIXML.LIST_SETS);192 this.listsets_response = getMessage(listsets_doc, listsets_element);193 194 // Now, for each collection, get a list of all its sets195 // might include subsets (classifiers) or super colls196 // We'll reuse the first message, changing its type and to atts197 request.setAttribute(GSXML.TYPE_ATT, "");198 request.setAttribute(GSXML.TO_ATT, to.toString());199 // send to MR200 msg_node = mr.process(message);201 //logger.info("*** " + XMLConverter.getPrettyString(msg_node));202 NodeList response_list = ((Element)msg_node).getElementsByTagName(GSXML.RESPONSE_ELEM);203 for (int c=0; c<response_list.getLength(); c++) {204 // for each collection's response205 Element response = (Element)response_list.item(c);206 String coll_name = GSPath.getFirstLink(response.getAttribute(GSXML.FROM_ATT));207 logger.info("*** coll from response "+coll_name);208 NodeList set_list = response.getElementsByTagName(OAIXML.SET);209 for (int j=0; j<set_list.getLength(); j++) {210 // now check if it a super collection211 Element set = (Element)set_list.item(j);212 String set_spec = GSXML.getNodeText((Element)GSXML.getChildByTagName(set, OAIXML.SET_SPEC));213 logger.info("*** set spec = "+set_spec);214 // this may change if we add site name back in215 // setSpecs will be collname or collname:subset or supercollname216 if (set_spec.indexOf(":")==-1 && ! set_spec.equals(coll_name)) {217 // it must be a super coll spec218 logger.info("*** found super coll, "+set_spec);219 // check that it is a valid one from config220 if (this.has_super_colls == true && this.super_coll_data.containsKey(set_spec)) {221 Vector <String> subcolls = this.super_coll_map.get(set_spec);222 if (subcolls == null) {223 logger.info("*** its new!!");224 // not in there yet225 subcolls = new Vector<String>();226 this.set_set.add(set_spec);227 this.super_coll_map.put(set_spec, subcolls);228 // the first time a supercoll is mentioned, add into the set list229 logger.info("*** finding the set info "+XMLConverter.getPrettyString(this.super_coll_data.get(set_spec)));230 listsets_element.appendChild(GSXML.duplicateWithNewName(listsets_doc, this.super_coll_data.get(set_spec), OAIXML.SET, true));231 }232 // add this collection to the list for the super coll233 subcolls.add(coll_name);234 }235 } else { // its either the coll itself or a subcoll236 // add in the set237 listsets_element.appendChild(listsets_doc.importNode(set, true));238 this.set_set.add(set_spec);239 }240 } // for each set in the collection241 } // for each OAI enabled collection242 return true;243 }244 */245 92 246 93 protected void resetMessageRouter() { … … 311 158 //The only thing that the oai receptionist can be sure is that these verbs are valid, nothing else. 312 159 String verb = request.getAttribute(GSXML.TO_ATT); 313 /*314 if (verb.equals(OAIXML.IDENTIFY)) {315 return doIdentify();316 }*/317 160 318 161 if (verb.equals(OAIXML.GET_RECORD)) { … … 324 167 325 168 } 326 327 /*328 private String getRepositoryIdentifier() {329 Element ri = (Element)GSXML.getChildByTagName(iiif_config, OAIXML.REPOSITORY_IDENTIFIER);330 if (ri != null) {331 return GSXML.getNodeText(ri);332 }333 return "";334 }335 */336 337 private void copyNamedElementfromConfig(Element to_elem, String element_name) {338 Element original_element = (Element)GSXML.getChildByTagName(iiif_config, element_name);339 if(original_element != null) {340 GSXML.copyNode(to_elem, original_element);341 }342 }343 344 /*345 private Element doIdentify() {346 //The validation for this verb has been done in OAIServer.validate(). So no bother here.347 logger.info("");348 if (this.identify_response != null) {349 // we have already created it350 return getMessage(this.identify_response.getOwnerDocument(), this.identify_response);351 }352 Document doc = XMLConverter.newDOM();353 Element identify = doc.createElement(OAIXML.IDENTIFY);354 //do the repository name355 copyNamedElementfromConfig(identify, OAIXML.REPOSITORY_NAME);356 //do the baseurl357 copyNamedElementfromConfig(identify, OAIXML.BASE_URL);358 //do the protocol version359 copyNamedElementfromConfig(identify, OAIXML.PROTOCOL_VERSION);360 361 //There can be more than one admin email according to the OAI specification362 NodeList admin_emails = GSXML.getChildrenByTagName(iiif_config, OAIXML.ADMIN_EMAIL);363 int num_admin = 0;364 Element from_admin_email = null;365 if (admin_emails != null) {366 num_admin = admin_emails.getLength();367 }368 for (int i=0; i<num_admin; i++) {369 GSXML.copyNode(identify, admin_emails.item(i));370 }371 372 // IIIF does not have the equivalent of oai earliestDatestamp373 374 // output the oai identifier375 Element description = doc.createElement(OAIXML.DESCRIPTION);376 identify.appendChild(description);377 // TODO, make this a valid id378 Element oaiIdentifier = OAIXML.createOAIIdentifierXML(doc, repository_id, "lucene-jdbm-demo", "ec159e");379 description.appendChild(oaiIdentifier);380 381 // if there are any oaiInfo metadata, add them in too.382 Element info = (Element)GSXML.getChildByTagName(iiif_config, OAIXML.OAI_INFO);383 if (info != null) {384 NodeList meta = GSXML.getChildrenByTagName(info, OAIXML.METADATA);385 if (meta != null && meta.getLength() > 0) {386 Element gsdl = OAIXML.createGSDLElement(doc);387 description.appendChild(gsdl);388 for (int m = 0; m<meta.getLength(); m++) {389 GSXML.copyNode(gsdl, meta.item(m));390 }391 392 }393 }394 this.identify_response = identify;395 return getMessage(doc, identify);396 }397 */398 169 399 170 private Element doGetRecord(Element req){ 400 logger.info(""); 401 /** arguments: 402 identifier: required 403 metadataPrefix: required 404 * Exceptions: badArgument; cannotDisseminateFormat; idDoesNotExist 405 */ 171 logger.info(""); 172 406 173 Document doc = XMLConverter.newDOM(); 407 174 Element get_record = doc.createElement(IIIFXML.GET_RECORD); … … 424 191 return OAIXML.createErrorMessage(OAIXML.ID_DOES_NOT_EXIST, ""); 425 192 } 426 //String name_of_site = strs[0];427 193 String coll_name = strs[0]; 428 194 String oid = strs[1]; … … 445 211 return GSXML.nodeToElement(result_node); 446 212 } 447 448 449 213 } 450 214 -
gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/service/IIIFPMH.java
r32842 r32860 61 61 62 62 protected SimpleCollectionDatabase coll_db = null; 63 //protected SimpleCollectionDatabase oaiinf_db = null;64 63 65 64 protected String site_name = ""; … … 79 78 /** constructor */ 80 79 public IIIFPMH() { 81 82 80 } 83 81 … … 89 87 this.coll_db = null; 90 88 } 91 /*92 if (this.oaiinf_db != null){93 this.oaiinf_db.closeDatabase();94 }*/95 89 } 96 90 … … 115 109 Element metadata_list = (Element) GSXML.getChildByTagName(extra_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 116 110 111 // Is indexStem needed for IIIF // **** 117 112 if (metadata_list != null) { 118 113 119 114 Element index_stem_elem = (Element) GSXML.getNamedElement(metadata_list, GSXML.METADATA_ELEM, GSXML.NAME_ATT, "indexStem"); 120 115 … … 137 132 } 138 133 139 /*140 // Work out what sets this collection has.141 //142 // Will usually contain the collection itself, optional super143 // collection, and maybe subcolls if appropriate classifiers are144 // present.145 146 configureSetInfo();*/147 148 // the short_service_info is used by the message router to find the method names,149 /*150 Element list_records = this.desc_doc.createElement(GSXML.SERVICE_ELEM);151 list_records.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_RECORDS);152 list_records.setAttribute(GSXML.TYPE_ATT, "oai");153 this.short_service_info.appendChild(list_records);154 155 Element list_identifiers = this.desc_doc.createElement(GSXML.SERVICE_ELEM);156 list_identifiers.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_IDENTIFIERS);157 list_identifiers.setAttribute(GSXML.TYPE_ATT, "oai");158 this.short_service_info.appendChild(list_identifiers);159 160 Element list_sets = this.desc_doc.createElement(GSXML.SERVICE_ELEM);161 list_sets.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_SETS);162 list_sets.setAttribute(GSXML.TYPE_ATT, "oai");163 this.short_service_info.appendChild(list_sets);164 165 Element list_metadata_formats = this.desc_doc.createElement(GSXML.SERVICE_ELEM);166 list_metadata_formats.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_METADATA_FORMATS);167 list_metadata_formats.setAttribute(GSXML.TYPE_ATT, "oai");168 this.short_service_info.appendChild(list_metadata_formats);169 */170 134 Element get_record = this.desc_doc.createElement(GSXML.SERVICE_ELEM); 171 135 get_record.setAttribute(GSXML.NAME_ATT, IIIFXML.GET_RECORD); … … 177 141 178 142 public boolean configureIIIF(Element iiif_config_elem) { 179 /*180 this.meta_formats_definition = this.desc_doc.createElement(OAIXML.LIST_METADATA_FORMATS);181 this.format_response_map = new HashMap<String, Element>();182 this.format_elements_map = new HashMap<String, HashSet<String>>();183 this.format_meta_elem_map = new HashMap<String, Element>();184 185 // for now, all we want is the metadata prefix description and the mapping list186 Element main_lmf_elem = (Element) GSXML.getChildByTagName(oai_config_elem, OAIXML.LIST_METADATA_FORMATS);187 if (main_lmf_elem == null) {188 logger.error("No listMetadataFormats element found in OAIConfig.xml");189 return false;190 }191 NodeList meta_formats_list = this.config_info.getElementsByTagName(OAIXML.METADATA_FORMAT);192 if (meta_formats_list.getLength() == 0) {193 logger.error("no metadataFormat elements found in OAIPMH serviceRack element");194 return false;195 }196 143 197 boolean found_meta_format = false; 198 for(int i=0; i<meta_formats_list.getLength(); i++) { 199 Element mf = (Element) meta_formats_list.item(i); 200 String prefix = mf.getAttribute(OAIXML.METADATA_PREFIX); 201 if (prefix.equals("")) { 202 logger.error("metadataFormat element had no metadataPrefix attribute"); 203 continue; 204 } 205 // get the right format from OAICOnfig 206 Element meta_format = findNamedMetadataFormat(main_lmf_elem, prefix); 207 if (meta_format == null) { 208 logger.error("Couldn't find metadataFormat named "+prefix+" in OAIConfig.xml"); 209 continue; 210 } 211 212 // copy the format definition into our stored Element 213 Element collection_version_format = (Element) this.desc_doc.importNode(meta_format, true); 214 collection_version_format.setAttribute(GSXML.NAME_ATT, prefix); // for convenience 215 this.meta_formats_definition.appendChild(collection_version_format); 216 // set up the response element for this format 217 format_response_map.put(prefix, OAIXML.getMetadataFormatShort(this.desc_doc, collection_version_format)); 218 // add in collection specific mappings 219 addCollectionMappings(collection_version_format, mf); 220 // now set up a list of all collection elements for reverse lookup of the mapping 221 format_elements_map.put(prefix, getAllCollectionElements(collection_version_format)); 222 format_meta_elem_map.put(prefix, OAIXML.getMetadataPrefixElement(this.desc_doc, prefix, collection_version_format)); 223 224 } // end for 225 */ 226 227 // Open the coll db db databases and store handles to them 144 // Open the coll db db databases and store handles to them 228 145 coll_db = new SimpleCollectionDatabase(infodb_type); 229 146 if (!coll_db.databaseOK()) { … … 231 148 return false; 232 149 } 233 /*234 oaiinf_db = new SimpleCollectionDatabase(infodb_type);235 if (!oaiinf_db.databaseOK()) {236 logger.error("Couldn't create the oai-inf database of type "+infodb_type);237 return false;238 }239 */240 150 241 151 // Open databases for querying … … 245 155 return false; 246 156 } 247 /*248 // the oaiinf_db is called oai-inf.<infodb_type_extension>249 String oaiinf_db_file = GSFile.OAIInfoDatabaseFile(this.site_home, this.cluster_name, "oai-inf", infodb_type);250 File oaiinfFile = new File(oaiinf_db_file);251 252 if(!oaiinfFile.exists()) {253 logger.warn("oai-inf database for collection + " + this.cluster_name + " does not exist.");254 oaiinf_db = null;255 } else if (!this.oaiinf_db.openDatabase(oaiinf_db_file, SimpleCollectionDatabase.READ)) {256 logger.warn("Could not open oai-inf database for collection + " + this.cluster_name + "!");257 oaiinf_db = null;258 }259 */260 157 261 158 return true; 262 159 } 263 160 264 /**265 * @return the associated OAICollection's OAI_EARLIEST_TIMESTAMP_OID record's266 * OAI_INF_TIMESTAMP field from the collection's oai-inf.db IN MILLISECONDS267 */268 /*269 public long getEarliestTimestamp() {270 long timestamp = -1;271 272 DBInfo oai_info = null;273 if(oaiinf_db != null) {274 // get internal record containing the earliest timestamp of the collection275 oai_info = this.oaiinf_db.getInfo(OAIXML.OAI_EARLIEST_TIMESTAMP_OID);276 if (oai_info == null) {277 logger.warn("Can't get collection " + this.cluster_name + "'s earliest timestamp from oai-inf db. No entry for 'OID' " + OAIXML.OAI_EARLIEST_TIMESTAMP_OID + " in the db.");278 } else {279 timestamp = Long.parseLong(oai_info.getInfo(OAIXML.OAI_INF_TIMESTAMP)) * 1000; // stored in seconds, so x1000 to convert to milliseconds280 //logger.info("@@@ found earliest OAI timestamp for collection " + this.coll_name + ": " + timestamp + " (ms)");281 }282 }283 return timestamp;284 }285 */286 287 /*288 protected Element findNamedMetadataFormat(Element list_meta_formats, String prefix) {289 NodeList formats = list_meta_formats.getElementsByTagName(OAIXML.METADATA_FORMAT);290 for (int i=0; i<formats.getLength(); i++) {291 Element format = (Element)formats.item(i);292 String meta_name = GSXML.getNodeText((Element)GSXML.getChildByTagName(format, OAIXML.METADATA_PREFIX));293 if (prefix.equals(meta_name)) {294 return format;295 }296 }297 return null;298 }299 */300 301 /** goes through the mappings from the collection one, and replaces existing ones in the main one */302 /*303 protected void addCollectionMappings(Element main_meta_format, Element coll_meta_format) {304 305 Element element_list = (Element)GSXML.getChildByTagName(main_meta_format, OAIXML.ELEMENT+GSXML.LIST_MODIFIER);306 Document doc = element_list.getOwnerDocument();307 NodeList coll_elements = coll_meta_format.getElementsByTagName(OAIXML.ELEMENT);308 if (coll_elements.getLength()==0) {309 // no mappings to include310 return;311 }312 for (int i=0; i<coll_elements.getLength(); i++) {313 Element e = (Element)coll_elements.item(i);314 String elem_name = e.getAttribute(GSXML.NAME_ATT);315 Element main_elem = GSXML.getNamedElement(element_list, OAIXML.ELEMENT, GSXML.NAME_ATT, elem_name);316 if (main_elem == null) {317 logger.error(elem_name+" not found in meta format, not using it");318 } else {319 element_list.replaceChild(doc.importNode(e, true),main_elem );320 }321 }322 }323 */324 325 /** goes through all the mappings and makes a set of all collection326 metadata names that could become an oai meta element - acts as327 a reverse lookup for the mappings */328 /*329 protected HashSet<String> getAllCollectionElements(Element meta_format) {330 HashSet<String> meta_name_set = new HashSet<String>();331 NodeList elements = meta_format.getElementsByTagName(OAIXML.ELEMENT);332 for (int i=0; i<elements.getLength(); i++) {333 Element e = (Element)elements.item(i);334 Element map = (Element)GSXML.getChildByTagName(e, OAIXML.MAPPING);335 if (map == null) {336 // there is no mapping, just use the element name337 meta_name_set.add(e.getAttribute(GSXML.NAME_ATT));338 } else {339 String list_of_names = map.getAttribute(OAIXML.ELEMENTS);340 String[] name_array = list_of_names.split(",");341 for (int j=0; j<name_array.length; j++) {342 meta_name_set.add(name_array[j]);343 }344 }345 }346 return meta_name_set;347 }348 */349 350 161 /** returns a specific service description */ 351 162 public Element getServiceDescription(Document doc, String service_id, String lang, String subset) { 352 353 /*354 if (service_id.equals(OAIXML.LIST_RECORDS)) {355 Element list_records = doc.createElement(GSXML.SERVICE_ELEM);356 list_records.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_RECORDS);357 list_records.setAttribute(GSXML.TYPE_ATT, "oai");358 return list_records;359 }360 361 if (service_id.equals(OAIXML.LIST_IDENTIFIERS)) {362 Element list_identifiers = doc.createElement(GSXML.SERVICE_ELEM);363 list_identifiers.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_IDENTIFIERS);364 list_identifiers.setAttribute(GSXML.TYPE_ATT, "oai");365 return list_identifiers;366 }367 if (service_id.equals(OAIXML.LIST_SETS)) {368 Element list_sets = doc.createElement(GSXML.SERVICE_ELEM);369 list_sets.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_SETS);370 list_sets.setAttribute(GSXML.TYPE_ATT, "oai");371 return list_sets;372 }373 if (service_id.equals(OAIXML.LIST_METADATA_FORMATS)) {374 Element list_metadata_formats = doc.createElement(GSXML.SERVICE_ELEM);375 list_metadata_formats.setAttribute(GSXML.NAME_ATT, OAIXML.LIST_METADATA_FORMATS);376 list_metadata_formats.setAttribute(GSXML.TYPE_ATT, "oai");377 return list_metadata_formats;378 }379 */380 163 381 164 if (service_id.equals(IIIFXML.GET_RECORD)) { … … 388 171 return null; 389 172 } 390 391 /** The list sets service returns all the sets that this collection is/is part of/contains. This is gathered by Receptionist from all collections to answer the OAI ListSets request. */392 /*393 protected Element processListSets(Element req) {394 return list_sets_response;395 }396 */397 173 398 174 /** returns the actual record element used in the OAI GetRecord response */ … … 422 198 423 199 String oid = param_map.get(IIIFXML.OID); // TODO should this be identifier??? 424 425 /*426 boolean OID_is_deleted = false;427 long millis = -1;428 429 DBInfo oai_info = null;430 if(oaiinf_db != null) {431 oai_info = this.oaiinf_db.getInfo(oid);432 if (oai_info == null) {433 logger.warn("OID: " + oid + " is not present in the collection's oai-inf database.");434 } else {435 436 // indexdb doesn't have info on deleted docs, only oaiinf db does.437 // So only oaiinfdb has timestamps for deleted docs438 // For non-deleted doc ids: also obtain timestamp from oaiinf db,439 // but if the oaiinf db doesn't exist, resort to oailastmodified fields of indexdb.440 String timestamp = oai_info.getInfo(OAIXML.OAI_INF_TIMESTAMP); // stored in seconds, like oailastmodified in the collection index db441 millis = Long.parseLong(timestamp)*1000; // in milliseconds442 443 String oaiinf_status = oai_info.getInfo(OAIXML.OAI_INF_STATUS);444 if(oaiinf_status != null && oaiinf_status.equals(OAIXML.OAI_INF_DELETED)) {445 OID_is_deleted = true;446 }447 }448 }449 */450 200 451 201 //get a DBInfo object of the identifier; if this identifier is not present in the database, … … 459 209 } 460 210 461 /* 462 else if (millis == -1) { // so couldn't get doc lastmod from oaiinf db, get oailastmodified from collection's index db 463 millis = getDateStampMillis(info); 464 } 465 String oailastmodified = (millis == -1) ? "" : OAIXML.getTime(millis); 466 */ 467 211 212 // **** 468 213 Element get_record_response = doc.createElement(GSXML.RESPONSE_ELEM); 469 214 Element get_record = doc.createElement(IIIFXML.GET_RECORD); … … 472 217 //compose the header element 473 218 record.appendChild(createHeaderElement(doc, oid)); 474 //if(!OID_is_deleted) { // **** 475 //compose the metadata element 476 record.appendChild(createMetadataElement(doc, prefix, info)); 477 // } // **** 219 //compose the metadata element 220 record.appendChild(createMetadataElement(doc, prefix, info)); 478 221 get_record.appendChild(record); 479 222 return get_record_response; 480 223 } 481 224 482 /** return a list of records in specified set, containing metadata from specified prefix*/483 /*484 protected Element processListRecords(Element req) {485 return processListIdentifiersOrRecords(req, OAIXML.LIST_RECORDS, true);486 }487 */488 /** return a list of identifiers in specified set that contain metadata belonging to specified prefix. */489 /*490 protected Element processListIdentifiers(Element req) {491 return processListIdentifiersOrRecords(req, OAIXML.LIST_IDENTIFIERS, false);492 }493 */494 495 // Get a list of records/identifiers that match the parameters.496 497 //protected Element processListIdentifiersOrRecords(Element req, String response_name, boolean include_metadata) {498 /** arguments:499 metadataPrefix: required500 * from: optional501 * until: optional502 * set: optional503 * resumptionToken: exclusive and optional (ignored as it has been handled by OAIReceptionist)504 * Exceptions: badArgument; cannotDisseminateFormat; idDoesNotExist505 */506 /*507 NodeList params = GSXML.getChildrenByTagName(req, GSXML.PARAM_ELEM);508 509 if(params.getLength() == 0) {510 logger.error("must at least have the metadataPrefix parameter, can't be none");511 return OAIXML.createErrorResponse(OAIXML.BAD_ARGUMENT, "");512 }513 514 HashMap<String, String> param_map = GSXML.getParamMap(params);515 516 String prefix = "";517 Date from_date = null;518 Date until_date = null;519 520 if(param_map.containsKey(OAIXML.METADATA_PREFIX) == false) {521 //Just a double-check522 logger.error("A param element containing the metadataPrefix is not present.");523 return OAIXML.createErrorResponse(OAIXML.CANNOT_DISSEMINATE_FORMAT, "");524 }525 prefix = param_map.get(OAIXML.METADATA_PREFIX);526 if (prefix == null || prefix.equals("")) {527 //Just a double-check528 logger.error("the value of metadataPrefix att is not present in the request.");529 return OAIXML.createErrorResponse(OAIXML.CANNOT_DISSEMINATE_FORMAT, "");530 }531 532 if(param_map.containsKey(OAIXML.FROM)) {533 String from = param_map.get(OAIXML.FROM);534 from_date = OAIXML.getDate(from);535 }536 if(param_map.containsKey(OAIXML.UNTIL)) {537 String until = param_map.get(OAIXML.UNTIL);538 until_date = OAIXML.getDate(until);539 }540 541 if (!format_response_map.containsKey(prefix)) {542 logger.error(prefix + " metadata prefix is not supported for collection "+this.coll_name);543 return OAIXML.createErrorResponse(OAIXML.CANNOT_DISSEMINATE_FORMAT, "");544 }545 546 // get list of oids547 ArrayList<String> oid_list = null;548 if(oaiinf_db != null) { // try getting the OIDs from the oaiinf_db549 oid_list = new ArrayList<String>(oaiinf_db.getAllKeys());550 551 if(oid_list == null) { // try getting the OIDs from the oai entries in the index db552 logger.warn("@@@@@@@@@@@@@ NO OIDs in oai-inf db for " + this.cluster_name);553 oid_list = getChildrenIds(OAIXML.BROWSELIST);554 }555 }556 557 if (oid_list == null) {558 logger.error("No matched records found in collection: oai-inf and index db's browselist are empty");559 return OAIXML.createErrorResponse(OAIXML.NO_RECORDS_MATCH, "");560 }561 // all validation is done562 563 // get the list of elements that are in this metadata prefix564 HashSet<String> set_of_elems = format_elements_map.get(prefix);565 566 Document doc = XMLConverter.newDOM();567 Element list_items_response = doc.createElement(GSXML.RESPONSE_ELEM);568 Element list_items = doc.createElement(response_name);569 list_items_response.appendChild(list_items);570 571 for(int i=0; i<oid_list.size(); i++) {572 String oid = oid_list.get(i);573 574 if(oid.equals(OAIXML.OAI_EARLIEST_TIMESTAMP_OID)) { // internal id not doc id, so skip575 continue;576 }577 578 boolean OID_is_deleted = false;579 long millis = -1;580 581 DBInfo oai_info = null;582 if(oaiinf_db != null) {583 oai_info = this.oaiinf_db.getInfo(oid);584 if (oai_info == null) {585 logger.warn("OID: " + oid + " is not present in the collection's oai-inf database.");586 } else {587 588 // indexdb doesn't have info on deleted docs, only oaiinf db does.589 // So only oaiinfdb has timestamps for deleted docs590 // For non-deleted doc ids: also obtain timestamp from oaiinf db,591 // but if the oaiinf db doesn't exist, resort to oailastmodified fields of indexdb.592 String timestamp = oai_info.getInfo(OAIXML.OAI_INF_TIMESTAMP); // stored in seconds like oailastmodified in the collection index db593 millis = Long.parseLong(timestamp)*1000; // in milliseconds594 595 String oaiinf_status = oai_info.getInfo(OAIXML.OAI_INF_STATUS);596 if(oaiinf_status != null && oaiinf_status.equals(OAIXML.OAI_INF_DELETED)) {597 OID_is_deleted = true;598 }599 }600 }601 DBInfo info = this.coll_db.getInfo(oid);602 if (info == null) { // can happen if oid was deleted, in which case only oai_info keeps a record of the oid603 if(!OID_is_deleted) { // we don't expect to find entries for deleted docs in index db.604 logger.error("Collection database does not contain information about oid: " +oid);605 }606 }607 else if (millis == -1) { // so couldn't get doc lastmod from oaiinf db, get oailastmodified from collection's index db608 609 millis = getDateStampMillis(info);610 }611 612 Date this_date = null;613 String oailastmodified = (millis == -1) ? "" : OAIXML.getTime(millis);614 615 if (millis == -1) {616 if (from_date != null || until_date !=null) {617 continue; // if this doc doesn't have a date for some reason, and618 // we are doing a date range, then don't include it.619 }620 } else {621 this_date = new Date(millis);622 if (from_date != null) {623 if(this_date.before(from_date)) {624 continue;625 }626 }627 if (until_date != null) {628 if (this_date.after(until_date)) {629 continue;630 }631 }632 }633 634 //compose the header element, which we'll be appending no matter what635 Element header = createHeaderElement(doc, oid, oailastmodified, OID_is_deleted);636 637 if (include_metadata) { // doing ListRecords638 // compose a record for adding header and metadata639 Element record = doc.createElement(OAIXML.RECORD);640 list_items.appendChild(record);641 //insert the header element642 record.appendChild(header);643 //Now check that this id has metadata for the required prefix.644 if (info != null && documentContainsMetadata(info, set_of_elems)) {645 // YES, it does have some metadata for this prefix646 //compose the metadata element647 record.appendChild(createMetadataElement(doc, prefix, info));648 } // otherwise the oid was 'deleted' and only in the oai-inf db and not in the info (collection index) db649 } else { // doing ListIdentifiers650 //append the header element651 list_items.appendChild(header);652 }653 654 }//end of for(int i=0; i<oid_list.size(); i++) of doing thru each record655 656 return list_items_response;657 658 }659 */660 661 // have implemented setDescription as an element, instead of a container containing metadata662 /*663 private boolean configureSetInfo() {664 665 Document doc = XMLConverter.newDOM();666 this.list_sets_response = doc.createElement(GSXML.RESPONSE_ELEM);667 Element list_sets_elem = doc.createElement(OAIXML.LIST_SETS);668 this.list_sets_response.appendChild(list_sets_elem);669 String set_name = this.coll_name;670 String set_description = null;671 Element name_elem = (Element)GSXML.getChildByTagName(this.config_info, OAIXML.SET_NAME);672 if (name_elem!=null) {673 set_name = GSXML.getNodeText(name_elem);674 if (set_name.equals("")) {675 set_name = this.coll_name; // default to coll name if can't find one676 }677 }678 Element description_elem = (Element)GSXML.getChildByTagName(this.config_info, OAIXML.SET_DESCRIPTION);679 if (description_elem!=null) {680 set_description = GSXML.getNodeText(description_elem);681 if (set_description.equals("")) {682 set_description = null;683 }684 }685 Element coll_set = OAIXML.createSet(doc, this.coll_name, set_name, set_description);686 list_sets_elem.appendChild(coll_set);687 688 // are we part of any super sets?689 NodeList super_set_list = GSXML.getChildrenByTagName(this.config_info, OAIXML.OAI_SUPER_SET);690 for (int i=0; i<super_set_list.getLength(); i++) {691 String super_name = ((Element)super_set_list.item(i)).getAttribute(GSXML.NAME_ATT);692 if (super_name != null && !super_name.equals("")) {693 list_sets_elem.appendChild(OAIXML.createSet(doc, super_name, super_name, null));694 }695 }696 return true;697 }698 */699 225 700 226 /** create the metadata element used when processing ListRecords/GetRecord requests … … 804 330 Element header = doc.createElement(OAIXML.HEADER); 805 331 806 // if deleted, get the date and change oailastmodified to timestamp in oaiinfo807 /*808 if(deleted) {809 header.setAttribute(OAIXML.OAI_INF_STATUS, OAIXML.HEADER_STATUS_ATTR_DELETED); // set the header status to deleted810 // then the timestamp for deletion will be from oai-inf database811 }812 */813 332 Element identifier = doc.createElement(IIIFXML.IDENTIFIER); 814 333 GSXML.setNodeText(identifier, coll_name + ":" + oid); 815 334 header.appendChild(identifier); 816 /* 817 Element set_spec = doc.createElement(OAIXML.SET_SPEC); 818 GSXML.setNodeText(set_spec, coll_name); 819 header.appendChild(set_spec); 820 Element datestamp = doc.createElement(OAIXML.DATESTAMP); 821 GSXML.setNodeText(datestamp, oailastmodified); 822 header.appendChild(datestamp); 823 */ 335 824 336 return header; 825 337 } 826 338 827 828 /** return the metadata information */829 /*830 protected Element processListMetadataFormats(Element req) {831 // the request sent here must contain an OID. see doListMetadataFormats() in OAIReceptionist832 Element param = GSXML.getNamedElement(req, GSXML.PARAM_ELEM, GSXML.NAME_ATT, OAIXML.OID);833 if (param == null) {834 logger.error("An element containing the OID attribute not is present.");835 return OAIXML.createErrorResponse(OAIXML.ID_DOES_NOT_EXIST, "");836 }837 String oid = param.getAttribute(GSXML.VALUE_ATT);838 if (oid == null || oid.equals("")) {839 logger.error("No OID is present in the request.");840 return OAIXML.createErrorResponse(OAIXML.ID_DOES_NOT_EXIST, "");841 }842 */843 /*844 ArrayList<String> oid_list = null;845 if(oaiinf_db != null) { // try getting the OIDs from the oaiinf_db846 oid_list = new ArrayList<String>(oaiinf_db.getAllKeys());847 848 if(oid_list == null) { // try getting the OIDs from the oai entries in the index db849 oid_list = getChildrenIds(OAIXML.BROWSELIST);850 }851 }852 */853 /*854 // assume meta formats are only for OIDs that have not been deleted855 // so don't need to check oai-inf db, and can just check collection's index db for list of OIDs856 ArrayList<String> oid_list = getChildrenIds(OAIXML.BROWSELIST);857 if (oid_list == null || oid_list.contains(oid) == false) {858 logger.error("OID: " + oid + " is not present in the database.");859 Element e= OAIXML.createErrorResponse(OAIXML.ID_DOES_NOT_EXIST, "");860 // logger.error((new XMLConverter()).getPrettyString (e));861 return e;862 }863 864 DBInfo info = null;865 info = this.coll_db.getInfo(oid);866 if (info == null) { //just double check867 return OAIXML.createErrorResponse(OAIXML.OAI_SERVICE_UNAVAILABLE, "");868 }869 870 Document doc = XMLConverter.newDOM();871 Element list_metadata_formats_response = doc.createElement(GSXML.RESPONSE_ELEM);872 873 Element list_metadata_formats = doc.createElement(OAIXML.LIST_METADATA_FORMATS);874 list_metadata_formats_response.appendChild(list_metadata_formats);875 boolean has_meta_format = false;876 877 // for each format in format_elements_map878 Iterator<String> it = format_elements_map.keySet().iterator();879 while (it.hasNext()) {880 String format = it.next();881 HashSet<String> set_of_elems = format_elements_map.get(format);882 if (documentContainsMetadata(info, set_of_elems)) {883 // add this format into the response884 has_meta_format = true;885 list_metadata_formats.appendChild(doc.importNode(format_response_map.get(format), true));886 }887 }888 889 if (has_meta_format == false) {890 logger.error("Specified metadata names are not contained in the database.");891 return OAIXML.createErrorResponse(OAIXML.NO_METADATA_FORMATS, "");892 } else {893 return list_metadata_formats_response;894 }895 }896 */897 /*898 protected boolean documentContainsMetadata(DBInfo info, HashSet<String> set_of_elems) {899 if (set_of_elems.size() == 0) {900 return false;901 }902 Iterator<String> i = set_of_elems.iterator();903 while (i.hasNext()) {904 if (!info.getInfo(i.next()).equals("")) {905 return true;906 }907 }908 return false;909 }910 */911 912 /** returns a list of the child ids in order, null if no children */913 /*914 protected ArrayList<String> getChildrenIds(String node_id) {915 DBInfo info = this.coll_db.getInfo(node_id);916 if (info == null) {917 return null;918 }919 920 String contains = info.getInfo("contains");921 if (contains.equals("")) {922 return null;923 }924 ArrayList<String> children = new ArrayList<String>();925 StringTokenizer st = new StringTokenizer(contains, ";");926 while (st.hasMoreTokens()) {927 String child_id = st.nextToken().replaceAll("\"", node_id);928 children.add(child_id);929 }930 return children;931 }932 */933 934 /**method to check whether any of the 'metadata_names' is contained in the 'info'.935 * The name may be in the form: <name>,<mapped name>, in which the mapped name is936 * optional. The mapped name is looked up in the DBInfo; if not present, use the first937 * name which is mandatory.938 */939 /*940 protected boolean containsMetadata(DBInfo info, String[] metadata_names) {941 if (metadata_names == null) return false;942 logger.info("checking metadata names in db.");943 for(int i=0; i<metadata_names.length; i++) {944 int index = metadata_names[i].indexOf(",");945 String meta_name = (index == -1) ? metadata_names[i] :946 metadata_names[i].substring(index + 1);947 948 if(info.getInfo(meta_name).equals("") == false) {949 return true;950 }951 }952 return false;953 }954 */955 /*956 protected long getDateStampMillis(DBInfo info) {957 // gs.OAIDateStamp is in YYYY-MM-DD958 String time_stamp = info.getInfo(OAIXML.GS_OAI_DATE_STAMP);959 long millis = -1;960 if (!time_stamp.equals("")) {961 millis = OAIXML.getTime(time_stamp);962 }963 if (millis == -1) {964 // oailastmodified is in seconds965 time_stamp = info.getInfo(OAIXML.OAI_LASTMODIFIED);966 if (!time_stamp.equals("")) {967 millis = Long.parseLong(time_stamp)*1000;968 }969 }970 return millis;971 972 973 }974 */975 339 } 976 340 -
gs3-extensions/iiif-servlet/trunk/src/gsdl-src/java/org/greenstone/gsdl3/util/IIIFXML.java
r32842 r32860 44 44 public static final int ACTIVATION = 1; 45 45 46 // six valid oai verbs46 // one valid iiif verb // **** 47 47 public static final String GET_RECORD = "GetRecord"; 48 /* 49 public static final String LIST_RECORDS = "ListRecords"; 50 public static final String LIST_IDENTIFIERS = "ListIdentifiers"; 51 public static final String LIST_SETS = "ListSets"; 52 public static final String LIST_METADATA_FORMATS = "ListMetadataFormats"; 53 public static final String IDENTIFY = "Identify"; 54 */ 55 56 57 // oai request parameters 48 49 // iiif request parameters 58 50 public static final String IDENTIFIER = "identifier"; 59 /*60 public static final String METADATA_PREFIX = "metadataPrefix";61 public static final String FROM = "from";62 public static final String UNTIL = "until";63 public static final String SET = "set";64 public static final String RESUMPTION_TOKEN = "resumptionToken";65 public static final String IDENTIFIER = "identifier";66 */67 51 68 52 // Error element and code att … … 70 54 public static final String CODE = "code"; 71 55 72 // OAI error codes 73 public static final String ID_DOES_NOT_EXIST = "idDoesNotExist"; 74 /* 75 public static final String BAD_ARGUMENT = "badArgument"; 76 public static final String BAD_RESUMPTION_TOKEN = "badResumptionToken"; 77 public static final String BAD_VERB = "badVerb"; 78 public static final String CANNOT_DISSEMINATE_FORMAT = "cannotDisseminateFormat"; 79 public static final String NO_METADATA_FORMATS = "noMetadataFormats"; 80 public static final String NO_RECORDS_MATCH = "noRecordsMatch"; 81 public static final String NO_SET_HIERARCHY = "noSetHierarchy"; 82 */ 83 84 // words used to compose oai responses 85 // many of these used in OAIConfig too 56 // IIIF error codes 57 public static final String ID_DOES_NOT_EXIST = "idDoesNotExist"; 86 58 87 59 // General 88 89 public static final String RESPONSE_DATE = "responseDate";60 public static final String IIIF_PMH = "IIIF-PMH"; // **** 61 public static final String RESPONSE_DATE = "responseDate"; // **** 90 62 public static final String REQUEST = "request"; 91 92 // internal "OID" identifiers in the oai-inf db93 /** represents the timestamp of the OAI collection (when its oai-inf db was first created) */94 /*95 public static final String OAI_EARLIEST_TIMESTAMP_OID = "_earliesttimestamp";96 */97 63 98 64 // Identify data 99 // OAI replacing => IIIF, maybe want baseURL and oai-identifier 100 public static final String BASE_URL = "baseURL"; 101 /* 102 public static final String ADMIN_EMAIL = "adminEmail"; 65 // OAI replacing => IIIF, maybe want baseURL and oai-identifier 103 66 public static final String BASE_URL = "baseURL"; 104 public static final String COMPRESSION = "compression";105 public static final String DELETED_RECORD = "deletedRecord";106 public static final String DESCRIPTION = "description";107 public static final String EARLIEST_DATESTAMP = "earliestDatestamp"; // taken from buildconfig used as publishing date by RSS service108 public static final String EARLIEST_OAI_DATESTAMP = "earliestOAIDatestamp"; // earliest timestamp of an OAI collection stored in oai-inf db109 public static final String GRANULARITY = "granularity";110 public static final String LAST_MODIFIED = "lastmodified";111 public static final String PROTOCOL_VERSION = "protocolVersion";112 public static final String REPOSITORY_NAME = "repositoryName";113 public static final String OAI_IDENTIFIER = "oai-identifier";114 public static final String SCHEME = "scheme";115 public static final String REPOSITORY_IDENTIFIER = "repositoryIdentifier";116 public static final String DELIMITER = "delimiter";117 public static final String SAMPLE_IDENTIFIER = "sampleIdentifier";118 */119 120 /*121 // metadata formats122 public static final String METADATA_FORMAT = "metadataFormat";123 public static final String SCHEMA = "schema";124 public static final String METADATA_NAMESPACE = "metadataNamespace";125 public static final String META_FORMAT_DC = "oai_dc";126 */127 128 67 129 68 // record response data 130 69 // SET_SPEC 131 70 public static final String RECORD = "record"; 132 /* 133 public static final String HEADER = "header"; 134 public static final String DATESTAMP = "datestamp"; 135 public static final String METADATA = "metadata"; 136 */ 137 138 /* 139 // list sets 140 // SET, 141 public static final String SET_NAME = "setName"; 142 public static final String SET_SPEC = "setSpec"; 143 public static final String SET_DESCRIPTION = "setDescription"; 144 */ 145 146 /* 147 // resumption token element 148 public static final String RESUMPTION_TOKEN_ELEM = "resumptionToken"; 149 public static final String EXPIRATION_DATE = "expirationDate"; 150 public static final String COMPLETE_LIST_SIZE = "completeListSize"; 151 public static final String CURSOR = "cursor"; 152 */ 153 154 // extra elements/attributes from OAIConfig 155 /* 156 public static final String OAI_INFO = "oaiInfo"; 157 public static final String USE_STYLESHEET = "useOAIStylesheet"; 158 public static final String STYLESHEET = "OAIStylesheet"; 159 public static final String RESUME_AFTER = "resumeAfter"; 160 public static final String RESUMPTION_TOKEN_EXPIRATION = "resumptionTokenExpiration"; 161 public static final String OAI_SUPER_SET = "oaiSuperSet"; 162 public static final String ELEMENT = "element"; 163 public static final String ELEMENTS = "elements"; 164 public static final String MAPPING = "mapping"; 165 public static final String SELECT = "select"; 166 public static final String SELECT_SINGLE_VALUE = "firstvalue"; 167 public static final String SELECT_FIRST_VALID_META = "firstvalidmetadata"; 168 public static final String SELECT_ALL_VALUES = "allvalues"; 169 // code constants 170 public static final String GS_OAI_DATE_STAMP = "gs.OAIDateStamp"; 171 public static final String GS_OAI_RESOURCE_URL = "gs.OAIResourceURL"; 172 public static final String GSF_LINK_PREFIX = "gsflink."; 173 public static final String LINK_TYPE_DOCUMENT = "document"; 174 public static final String LINK_TYPE_SOURCE = "source"; 175 public static final String ILLEGAL_OAI_VERB = "Illegal OAI verb"; 176 public static final String LASTMODIFIED = "lastmodified"; 177 // // The node id in the collection database, which contains all the OIDs in the database 178 public static final String BROWSELIST = "browselist"; 179 public static final String OAI_LASTMODIFIED = "oailastmodified"; 180 */ 181 public static final String OAIPMH = "OAIPMH"; 71 72 public static final String OAIPMH = "OAIPMH"; // **** 182 73 183 74 //public static final String OAI_SET_LIST = "oaiSetList"; // **** 184 public static final String OAI_SERVICE_UNAVAILABLE = "OAI service unavailable"; 185 public static final String OID = "OID"; 186 /* 187 // The node id in the oai-inf database of the collection, which should contain all the OIDs in the db 188 public static final String OAI_INF_STATUS = "status"; // D = Deleted; E = Existing (PD = Provisionally Deleted but PD should not be present at this stage in the oai-inf database) 189 public static final String OAI_INF_TIMESTAMP = "timestamp"; // the time of deletion/last (re)indexing of doc 190 public static final String OAI_INF_DATESTAMP = "datestamp"; // date version of timestamp 191 // oai-inf db values for OAI_INF_STATUS 192 public static final String OAI_INF_DELETED = "D"; 193 public static final String OAI_INF_EXISTS = "E"; 194 public static final String OAI_INF_PROVISIONALLY_DELETED = "PD"; 195 // header values for ListRecords/GetRecord and listIdentifiers 196 public static final String HEADER_STATUS_ATTR_DELETED = "deleted"; 197 */ 75 //public static final String OAI_SERVICE_UNAVAILABLE = "OAI service unavailable"; 76 public static final String OID = "OID"; // **** 198 77 199 78 public static final String IIIF_SERVICE_RACK = "IIIFPMH"; 200 79 //system-dependent file separator, maybe '/' or '\' 201 public static final String FILE_SEPARATOR = File.separator;80 //public static final String FILE_SEPARATOR = File.separator; 202 81 //public static final String OAI_VERSION1 = "1.0"; 203 public static final String IIIF_VERSION2 = "2.1";82 public static final String IIIF_VERSION2 = "2.1"; // **** 204 83 /*************************above are final values****************************/ 205 84 … … 208 87 public static Element iiif_config_elem = null; 209 88 210 //stores the date format "yyyy-MM-ddTHH:mm:ssZ" 211 // this is the granularity for datestamps 212 /* 213 public static String granularity = ""; 214 */ 215 216 // http://www.openarchives.org/OAI/openarchivesprotocol.html#DatestampsRequests 217 // specifies that all repositories must support YYYY-MM-DD (yyyy-MM-dd in Java) 218 // this would be in addition to the other (optional) granularity of above that 219 // a repository may additionally choose to support. 220 /* 221 public static final String default_granularity = "yyyy-MM-dd"; 222 */ 223 224 //public static long token_expiration = 7200; 225 /** which version of oai that this oaiserver supports; default is 2.0 226 * initialized in getOAIConfigXML() 227 */ 228 public static final String iiif_version = "2.1"; 89 public static final String iiif_version = "2.1"; // **** 229 90 public static String baseURL = ""; 230 91 … … 273 134 return null; 274 135 } 275 276 //initialize oai_version 277 /* 278 Element protocol_version = (Element)GSXML.getChildByTagName(iiif_config_elem, PROTOCOL_VERSION); 279 iiif_version = GSXML.getNodeText(protocol_version).trim(); 280 */ 281 136 282 137 // initialize baseURL 283 138 Element base_url_elem = (Element)GSXML.getChildByTagName(iiif_config_elem, BASE_URL); 284 139 baseURL = GSXML.getNodeText(base_url_elem); 285 140 286 /*287 //initialize token_expiration288 Element expiration = (Element)GSXML.getChildByTagName(iiif_config_elem, RESUMPTION_TOKEN_EXPIRATION);289 String expire_str = GSXML.getNodeText(expiration).trim();290 if (expiration != null && !expire_str.equals("")) {291 token_expiration = Long.parseLong(expire_str);292 }293 */294 /*295 // read granularity from the config file296 Element granu_elem = (Element)GSXML.getChildByTagName(iiif_config_elem, GRANULARITY);297 //initialize the granu_str which might be used by other methods (eg, getDate())298 granularity = GSXML.getNodeText(granu_elem).trim();299 300 //change "yyyy-MM-ddTHH:mm:ssZ" to "yyyy-MM-dd'T'HH:mm:ss'Z'"301 granularity = granularity.replaceAll("T", "'T'");302 granularity = granularity.replaceAll("Z", "'Z'");303 granularity = granularity.replaceAll("YYYY", "yyyy").replaceAll("DD", "dd").replaceAll("hh", "HH");304 */305 306 141 return iiif_config_elem; 307 142 } 308 143 309 /*310 public static String[] getMetadataMapping(Element metadata_format) {311 312 if (metadata_format == null) {313 return null;314 }315 NodeList mappings = metadata_format.getElementsByTagName(MAPPING);316 int size = mappings.getLength();317 if (size == 0) {318 logger.info("No metadata mappings are provided in IIIFConfig.xml.");319 return null;320 }321 String[] names = new String[size];322 for (int i=0; i<size; i++) {323 names[i] = GSXML.getNodeText((Element)mappings.item(i)).trim();324 }325 return names;326 327 }328 329 public static String[] getGlobalMetadataMapping(String prefix) {330 Element list_meta_formats = (Element)GSXML.getChildByTagName(iiif_config_elem, LIST_METADATA_FORMATS);331 if(list_meta_formats == null) {332 return null;333 }334 Element metadata_format = GSXML.getNamedElement(list_meta_formats, METADATA_FORMAT, METADATA_PREFIX, prefix);335 if(metadata_format == null) {336 return null;337 }338 return getMetadataMapping(metadata_format);339 }340 */341 342 /** Copies out the main info from a metadataFormat element, leaving behind the mapping stuff. This gets the bit needed for OAI response */343 /*344 public static Element getMetadataFormatShort(Document doc, Element meta_format_long) {345 Element meta_fmt = doc.createElement(OAIXML.METADATA_FORMAT);346 // Copy in the elements that we want, and ignore the rest347 meta_fmt.appendChild(doc.importNode(GSXML.getChildByTagName(meta_format_long, OAIXML.METADATA_PREFIX), true));348 meta_fmt.appendChild(doc.importNode(GSXML.getChildByTagName(meta_format_long, OAIXML.SCHEMA), true));349 meta_fmt.appendChild(doc.importNode(GSXML.getChildByTagName(meta_format_long, OAIXML.METADATA_NAMESPACE), true));350 351 return meta_fmt;352 }353 */354 355 /*356 public static long getTokenExpiration() {357 return token_expiration*1000; // in milliseconds358 }359 */360 144 361 145 /** TODO: returns a basic response for appropriate oai version 362 146 * 363 147 */ 364 public static Element createBasicResponse(Document doc, String verb, String[] pairs) {148 public static Element createBasicResponse(Document doc, String verb, String[] pairs) { // **** 365 149 366 150 Element response = createResponseHeader(doc, verb); … … 385 169 386 170 Node resp_date = GSXML.getChildByTagName(response, RESPONSE_DATE); // **** 387 /*388 if (resp_date != null) {389 GSXML.setNodeText((Element)resp_date, getCurrentUTCTime());390 }391 */392 171 393 172 return response; 394 173 } 174 395 175 /** @param error_code the value of the code attribute 396 176 * @param error_text the node text of the error element … … 497 277 * escaped sequences (eg, '%3A'). 498 278 */ 499 public static String oaiEncode(String original_str) {279 public static String oaiEncode(String original_str) { // **** 500 280 logger.info("oaiEncode() " + original_str); 501 281 for (int i=0; i<special_char.length; i++) { … … 506 286 return original_str; 507 287 } 508 /** convert YYYY-MM_DDThh:mm:ssZ to yyyy-MM-ddTHH:mm:ssZ 509 */ 510 /* 511 public static String convertToJava(String oai_format) { 512 oai_format = oai_format.replaceAll("YYYY", "yyyy").replaceAll("DD", "dd").replaceAll("hh", "HH"); 513 return oai_format; 514 } 515 */ 516 /** convert yyyy-MM-ddTHH:mm:ssZ to YYYY-MM_DDThh:mm:ssZ 517 */ 518 /* 519 public static String convertToOAI(String java_format) { 520 java_format = java_format.replaceAll("yyyy", "YYYY").replaceAll("dd", "DD").replaceAll("HH", "hh"); 521 return java_format; 522 } 523 public static String getCurrentUTCTime() { 524 Date current_utc = new Date(System.currentTimeMillis()); 525 //granularity is in the form: yyyy-MM-dd'T'HH:mm:ss'Z ' 526 DateFormat formatter = new SimpleDateFormat(granularity); 527 return formatter.format(current_utc); 528 } 529 */ 530 /** get a Date object from a Date format pattern string 531 * 532 * @param pattern - in the form: 2007-06-14T16:48:25Z, for example. 533 * @return a Date object - null if the pattern is not in the specified form 534 */ 535 /* 536 public static Date getDate(String pattern) { 537 if (pattern == null || pattern.equals("")) { 538 return null; 539 } 540 Date date = null; 541 // String str = pattern.replaceAll("T", " "); 542 // str = str.replaceAll("Z", ""); 543 SimpleDateFormat sdf = null; 544 try { 545 sdf = new SimpleDateFormat(granularity); 546 date = sdf.parse(pattern); 547 } catch(Exception e) { 548 if(!default_granularity.equals(granularity)) { // try validating against default granularity 549 try { 550 date = null; 551 sdf = null; 552 sdf = new SimpleDateFormat(default_granularity); 553 date = sdf.parse(pattern); 554 } catch(Exception ex) { 555 logger.error("invalid date format: " + pattern); 556 return null; 557 } 558 } else { 559 logger.error("invalid date format: " + pattern); 560 return null; 561 } 562 } 563 return date; 564 } 565 */ 566 /** get the million second value from a string representing time in a pattern 567 * (eg, 2007-06-14T16:48:25Z) 568 */ 569 /* 570 public static long getTime(String pattern) { 571 if (pattern == null || pattern.equals("")) { 572 return -1; 573 } 574 Date date = null; 575 SimpleDateFormat sdf = null; 576 try { 577 //granularity is a global variable in the form: yyyy-MM-ddTHH:mm:ssZ 578 sdf = new SimpleDateFormat(granularity); 579 date = sdf.parse(pattern); 580 } catch(Exception e) { 581 if(!default_granularity.equals(granularity)) { // try validating against default granularity 582 try { 583 date = null; 584 sdf = null; 585 sdf = new SimpleDateFormat(default_granularity); 586 date = sdf.parse(pattern); 587 } catch(Exception ex) { 588 logger.error("invalid date format: " + pattern); 589 return -1; 590 } 591 } else { 592 logger.error("invalid date format: " + pattern); 593 return -1; 594 } 595 } 596 return date.getTime(); 597 } 598 */ 599 /** get the string representation of a time from a long value(long type) 600 */ 601 /* 602 public static String getTime(long milliseconds) { 603 Date date = new Date(milliseconds); 604 SimpleDateFormat sdf = new SimpleDateFormat(granularity); 605 return sdf.format(date); 606 } 607 */ 288 608 289 public static Element createResponseHeader(Document response_doc, String verb) { 609 290 String tag_name = (iiif_version.equals(IIIF_VERSION2))? IIIF_PMH : verb; // **** 610 291 Element oai = response_doc.createElement(tag_name); 611 Element resp_date = response_doc.createElement(RESPONSE_DATE); 292 Element resp_date = response_doc.createElement(RESPONSE_DATE); // **** 612 293 Element req = response_doc.createElement(REQUEST); 613 294 oai.appendChild(resp_date); … … 626 307 } 627 308 628 /*629 public static Element getMetadataPrefixElement(Document doc, String prefix, Element meta_format) {630 631 Element ns_elem = (Element)GSXML.getChildByTagName(meta_format, METADATA_NAMESPACE);632 String namespace = null;633 if (ns_elem != null) {634 namespace = GSXML.getNodeText(ns_elem);635 }636 if (namespace == null || namespace.equals("")) {637 logger.error("No namespace URI found in metadataFormat elemnt for "+prefix);638 logger.error(XMLConverter.getPrettyString(meta_format));639 return null;640 }641 642 Element sc_elem = (Element)GSXML.getChildByTagName(meta_format, SCHEMA);643 String schema = null;644 if (sc_elem != null) {645 schema = GSXML.getNodeText(sc_elem);646 }647 if (schema == null || schema.equals("")) {648 logger.error("No schema found in metadataFormat element for "+prefix);649 logger.error(XMLConverter.getPrettyString(meta_format));650 return null;651 }652 653 String tag_name = getMetadataTagName(prefix, oai_version);654 Element oai = doc.createElement(tag_name);655 oai.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");656 657 if (oai_version.equals(OAI_VERSION2)) {658 oai.setAttribute("xmlns:"+prefix, namespace);659 if (prefix.equals(META_FORMAT_DC)) {660 // there seems to be an extra one for dc661 oai.setAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/");662 }663 oai.setAttribute("xsi:schemaLocation", namespace+" \n "+schema);664 } else {665 oai.setAttribute("xmlns", "http://www.openarchives.com/OAI/1.1/");666 if (prefix.equals(META_FORMAT_DC)) {667 oai.setAttribute("xsi:schemaLocation", "http://www.openarchives.org/OAI/1.1/" + tag_name + ".xsd");668 } else {669 oai.setAttribute("xsi:schemaLocation", schema);670 }671 }672 673 return oai;674 675 }676 677 public static String getMetadataTagName(String prefix, String oai_version) {678 if (prefix.equals(META_FORMAT_DC)) {679 if (oai_version.equals(OAI_VERSION2)) {680 return "oai_dc:dc";681 }682 return "dc";683 }684 return prefix;685 }686 687 public static HashMap<String, Node> getChildrenMapByTagName(Node n, String tag_name) {688 689 HashMap<String, Node> map= new HashMap<String, Node>();690 Node child = n.getFirstChild();691 while (child!=null) {692 String name = child.getNodeName();693 if(name.equals(tag_name)) {694 map.put(name, child);695 }696 child = child.getNextSibling();697 }698 return map;699 }700 */701 309 702 310 public static Element createOAIIdentifierXML(Document doc, String repository_id, String sample_collection, String sample_doc_id) { … … 712 320 String xml = "<gsdl xmlns=\"http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo\n http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo.xsd\"></gsdl>"; 713 321 Document xml_doc = converter.getDOM(xml); 714 return (Element)doc.importNode(xml_doc.getDocumentElement(), true); 715 716 717 } 718 /* 719 public static Element createSet(Document doc, String spec, String name, String description) { 720 721 Element set_elem = doc.createElement(SET); 722 Element set_spec = doc.createElement(SET_SPEC); 723 GSXML.setNodeText(set_spec, spec); 724 set_elem.appendChild(set_spec); 725 Element set_name = doc.createElement(SET_NAME); 726 GSXML.setNodeText(set_name, name); 727 set_elem.appendChild(set_name); 728 if (description != null) { 729 Element set_description = doc.createElement(SET_DESCRIPTION); 730 GSXML.setNodeText(set_description, description); 731 set_elem.appendChild(set_description); 732 } 733 return set_elem; 734 735 } 736 */ 737 738 /** returns the resumptionToken element to go into an OAI response */ 739 /* 740 public static Element createResumptionTokenElement(Document doc, String token_name, int total_size, int cursor, long expiration_time) { 741 Element token = doc.createElement(OAIXML.RESUMPTION_TOKEN); 742 if (total_size != -1) { 743 token.setAttribute(OAIXML.COMPLETE_LIST_SIZE, "" + total_size); 744 } 745 if (cursor != -1) { 746 token.setAttribute(OAIXML.CURSOR, "" + cursor); 747 } 748 if(expiration_time !=-1) { 749 token.setAttribute(OAIXML.EXPIRATION_DATE, getTime(expiration_time)); 750 } 751 752 if (token != null) { 753 GSXML.setNodeText(token, token_name); 754 } 755 return token; 756 } 757 */ 322 return (Element)doc.importNode(xml_doc.getDocumentElement(), true); 323 } 758 324 } 759 325
Note:
See TracChangeset
for help on using the changeset viewer.