source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/FedoraServiceProxy.java@ 22306

Last change on this file since 22306 was 22306, checked in by ak19, 14 years ago
  1. AbstractBrowse's method extractExtraClassifierInfo() is now package access and static (it never used member variables anyway) so that the FedoraServiceProxy class can reuse it in entirety.
File size: 24.9 KB
Line 
1/*
2 * ServiceRack.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3.service;
20
21// greenstone classes
22import org.greenstone.gsdl3.util.*;
23import org.greenstone.gsdl3.core.*;
24
25// for fedora
26import org.greenstone.gs3client.dlservices.*;
27import org.greenstone.fedora.services.FedoraGS3Exception.CancelledException;
28
29// xml classes
30import org.w3c.dom.Node;
31import org.w3c.dom.NodeList;
32import org.w3c.dom.Element;
33import org.w3c.dom.Document;
34import org.xml.sax.InputSource;
35import javax.xml.parsers.*;
36import org.apache.xpath.XPathAPI;
37
38// general java classes
39import java.io.Reader;
40import java.io.StringReader;
41import java.io.File;
42import java.util.HashMap;
43import java.util.ResourceBundle;
44import java.util.Locale;
45import java.lang.reflect.Method;
46
47import org.apache.log4j.*;
48
49/**
50 * FedoraServiceProxy - communicates with the FedoraGS3 interface.
51 *
52 * @author Anupama Krishnan
53 */
54public class FedoraServiceProxy
55 extends ServiceRack
56{
57
58 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.FedoraServiceProxy.class.getName());
59
60 /** The handle to the fedora connection */
61 private DigitalLibraryServicesAPIA fedoraServicesAPIA;
62
63 private String prevLanguage = "";
64
65 public void cleanUp() {
66 super.cleanUp();
67 }
68
69 /** sets the message router */
70 public void setMessageRouter(MessageRouter m) {
71 this.router = m;
72 setLibraryName(m.getLibraryName());
73 }
74
75 /** the no-args constructor */
76 public FedoraServiceProxy() {
77 super();
78
79 this.converter = new XMLConverter();
80 this.doc = this.converter.newDOM();
81 this.short_service_info = this.doc.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
82 this.format_info_map = new HashMap();
83
84 }
85
86
87 /* configure the service module
88 *
89 * @param info the XML node <serviceRack name="XXX"/> with name equal
90 * to the class name (of the subclass)
91 *
92 * must configure short_service_info_ and service_info_map_
93 * @return true if configured ok
94 * must be implemented in subclasses
95 */
96 /*public boolean configure(Element info) {
97 return configure(info, null);
98 }*/
99
100 public boolean configure(Element info, Element extra_info) {
101 // set up the class loader
102
103 if (!super.configure(info, extra_info)){
104 return false;
105 }
106
107 // Try to instantiate a Fedora dl handle
108 try {
109 // The properties file containing the initial digital library connection
110 // settings which get displayed in the connection dialog fields
111 //final File propertiesFile = new File("gs3fedora.properties");
112 //fedoraServicesAPIA = new FedoraServicesAPIA(propertiesFile);
113
114 fedoraServicesAPIA = new FedoraServicesAPIA("http", "localhost", 8383, "fedoraIntCallUser", "changeme");//"fedoraAdmin", "pounamu"
115 } catch(org.greenstone.fedora.services.FedoraGS3Exception.CancelledException e) {
116 // The user pressed cancel in the fedora services instantiation dlg
117 return false;
118 } catch(Exception e) {
119 logger.error("Error instantiating the interface to the Fedora Repository:\n", e); // second parameter prints e's stacktrace
120 return false;
121 }
122
123
124 // Need to put the available services into short_service_info
125 // This is used by DefaultReceptionist.process() has an exception. But DefaultReceptionist.addExtraInfo()
126 // isn't helpful, and the problem actually already occurs in
127 // Receptionist.process() -> PageAction.process() -> MessageRouter.process()
128 // -> Collection/ServiceCluster.process() -> ServiceCluster.configureServiceRackList()
129 // -> ServiceRack.process() -> ServiceRack.processDescribe() -> ServiceRack.getServiceList().
130 // ServiceRack.getServiceList() requires this ServiceRack's services to be filled into the
131 // short_service_info Element which needs to be done in this FedoraServiceProxy.configure().
132
133 // get the display and format elements from the coll config file for
134 // the classifiers
135 AbstractBrowse.extractExtraClassifierInfo(info, extra_info);
136
137 // Copied from IViaProxy.java:
138 String collection = fedoraServicesAPIA.describeCollection(this.cluster_name);
139
140 Element collNode = getResponseAsDOM(collection);
141 Element serviceList = (Element)collNode.getElementsByTagName(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER).item(0);
142
143//this.short_service_info.appendChild(short_service_info.getOwnerDocument().importNode(serviceList, true));
144 // we want the individual service Elements, not the serviceList Element which will wrap it later
145 NodeList services = collNode.getElementsByTagName(GSXML.SERVICE_ELEM);
146 for(int i = 0; i < services.getLength(); i++) {
147 Node service = services.item(i);
148 this.short_service_info.appendChild(short_service_info.getOwnerDocument().importNode(service, true));
149 }
150
151 // add some format info to service map if there is any
152 String path = GSPath.appendLink(GSXML.SEARCH_ELEM, GSXML.FORMAT_ELEM);
153 Element search_format = (Element) GSXML.getNodeByPath(extra_info, path);
154 if (search_format != null) {
155 this.format_info_map.put("TextQuery", this.doc.importNode(search_format, true));
156 }
157
158 // look for document display format
159 path = GSPath.appendLink(GSXML.DISPLAY_ELEM, GSXML.FORMAT_ELEM);
160 Element display_format = (Element)GSXML.getNodeByPath(extra_info, path);
161 if (display_format != null) {
162 this.format_info_map.put("DocumentContentRetrieve", this.doc.importNode(display_format, true));
163 // should we make a copy?
164 }
165
166 // the format info
167 Element cb_format_info = this.doc.createElement(GSXML.FORMAT_ELEM);
168 boolean format_found = false;
169
170 // look for classifier <browse><format>
171 path = GSPath.appendLink(GSXML.BROWSE_ELEM, GSXML.FORMAT_ELEM);
172 Element browse_format = (Element)GSXML.getNodeByPath(extra_info, path);
173 if (browse_format != null) {
174 cb_format_info.appendChild(GSXML.duplicateWithNewName(this.doc, browse_format, GSXML.DEFAULT_ELEM, true));
175 format_found = true;
176 }
177
178 // add in to the description a simplified list of classifiers
179 Element browse = (Element)GSXML.getChildByTagName(extra_info, "browse"); // the <browse>
180 NodeList classifiers = browse.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
181 for(int i=0; i<classifiers.getLength(); i++) {
182 Element cl = (Element)classifiers.item(i);
183 Element new_cl = (Element)this.doc.importNode(cl, false); // just import this node, not the children
184
185 // get the format info out, and put inside a classifier element
186 Element format_cl = (Element)new_cl.cloneNode(false);
187 Element format = (Element)GSXML.getChildByTagName(cl, GSXML.FORMAT_ELEM);
188 if (format != null) {
189
190 //copy all the children
191 NodeList elems = format.getChildNodes();
192 for (int j=0; j<elems.getLength();j++) {
193 format_cl.appendChild(this.doc.importNode(elems.item(j), true));
194 }
195 cb_format_info.appendChild(format_cl);
196 format_found = true;
197 }
198
199 }
200
201 if (format_found) {
202 this.format_info_map.put("ClassifierBrowse", cb_format_info);
203 }
204
205 return true;
206 }
207
208
209 /* "DocumentContentRetrieve", "DocumentMetadataRetrieve", "DocumentStructureRetrieve",
210 "TextQuery", "FieldQuery", "ClassifierBrowse", "ClassifierBrowseMetadataRetrieve" */
211
212 protected Element processDocumentContentRetrieve(Element request) {
213 String[] docIDs = parseDocIDs(request, GSXML.DOC_NODE_ELEM);
214 if(docIDs == null) {
215 logger.error("DocumentContentRetrieve request specified no doc nodes.\n");
216 return this.doc.createElement(GSXML.RESPONSE_ELEM); // empty response
217 } else {
218 for(int i = 0; i < docIDs.length; i++) {
219 docIDs[i] = translateId(docIDs[i]);
220 }
221 }
222
223 // first param (the collection) is not used by Fedora
224 Element response = getResponseAsDOM(fedoraServicesAPIA.retrieveDocumentContent(this.cluster_name, docIDs));
225 return (Element)response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(0);
226 }
227
228 protected Element processDocumentStructureRetrieve(Element request) {
229 String[] docIDs = parseDocIDs(request, GSXML.DOC_NODE_ELEM);
230
231 if(docIDs == null) {
232 logger.error("DocumentStructureRetrieve request specified no doc nodes.\n");
233 return this.doc.createElement(GSXML.RESPONSE_ELEM); // empty response
234 } else {
235 for(int i = 0; i < docIDs.length; i++) {
236 docIDs[i] = translateId(docIDs[i]);
237 }
238 }
239
240 NodeList params = request.getElementsByTagName(GSXML.PARAM_ELEM);
241 String structure="";
242 String info="";
243 for(int i = 0; i < params.getLength(); i++) {
244 Element param = (Element)params.item(i);
245 if(param.getAttribute("name").equals("structure")) {
246 structure = structure + param.getAttribute("value") + "|";
247 } else if(param.getAttribute("name").equals("info")) {
248 info = info + param.getAttribute("value") + "|";
249 }
250 }
251
252 Element response = getResponseAsDOM(fedoraServicesAPIA.retrieveDocumentStructure(this.cluster_name, docIDs, new String[]{structure}, new String[]{info}));
253 return (Element)response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(0);
254 }
255
256 protected Element processDocumentMetadataRetrieve(Element request) {
257 String[] docIDs = parseDocIDs(request, GSXML.DOC_NODE_ELEM);
258 if(docIDs == null) {
259 logger.error("DocumentMetadataRetrieve request specified no doc nodes.\n");
260 return this.doc.createElement(GSXML.RESPONSE_ELEM); // empty response
261 } else {
262 for(int i = 0; i < docIDs.length; i++) {
263 docIDs[i] = translateId(docIDs[i]);
264 }
265 }
266
267 NodeList params = request.getElementsByTagName(GSXML.PARAM_ELEM);
268 String[] metafields = {};
269 if(params.getLength() > 0) {
270 metafields = new String[params.getLength()];
271 for(int i = 0; i < metafields.length; i++) {
272 Element param = (Element)params.item(i);
273 //if(param.hasAttribute(GSXML.NAME_ATT) && param.getAttribute(GSXML.NAME_ATT).equals("metadata") && param.hasAttribute(GSXML.VALUE_ATT)) {
274 if(param.hasAttribute(GSXML.VALUE_ATT)){
275 metafields[i] = param.getAttribute(GSXML.VALUE_ATT);
276 } else {
277 metafields[i] = "";
278 }
279 }
280 }
281
282 Element response = getResponseAsDOM(fedoraServicesAPIA.retrieveDocumentMetadata(this.cluster_name, docIDs, metafields));
283 //logger.info("**** FedoraServiceProxy - Response from documentmetaretrieve: " + GSXML.nodeToFormattedString(response));
284 return (Element)response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(0);
285 }
286
287 protected Element processClassifierBrowseMetadataRetrieve(Element request) {
288 String[] classIDs = parseDocIDs(request, GSXML.CLASS_NODE_ELEM);
289 if(classIDs == null) {
290 logger.error("ClassifierBrowseMetadataRetrieve request specified no classifier nodes.\n");
291 return this.doc.createElement(GSXML.RESPONSE_ELEM); // empty response
292 } else {
293 for(int i = 0; i < classIDs.length; i++) {
294 classIDs[i] = translateId(classIDs[i]);
295 }
296 }
297
298 NodeList params = request.getElementsByTagName(GSXML.PARAM_ELEM);
299 String[] metafields = {};
300 if(params.getLength() > 0) {
301 metafields = new String[params.getLength()];
302 for(int i = 0; i < metafields.length; i++) {
303 Element param = (Element)params.item(i);
304 if(param.hasAttribute(GSXML.VALUE_ATT)){
305 metafields[i] = param.getAttribute(GSXML.VALUE_ATT);
306 } else {
307 metafields[i] = "";
308 }
309 }
310 }
311
312 Element response
313 = getResponseAsDOM(fedoraServicesAPIA.retrieveBrowseMetadata(this.cluster_name,
314 "ClassifierBrowseMetadataRetrieve",
315 classIDs, metafields));
316 return (Element)response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(0);
317 }
318
319 protected Element processClassifierBrowse(Element request) {
320 String collection = this.cluster_name;
321 String lang = request.getAttribute(GSXML.LANG_ATT);
322 if(!lang.equals(prevLanguage)) {
323 prevLanguage = lang;
324 fedoraServicesAPIA.setLanguage(lang);
325 }
326
327 NodeList classNodes = request.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
328 if(classNodes == null || classNodes.getLength() <= 0) {
329 logger.error("ClassifierBrowse request specified no classifier IDs.\n");
330 return this.doc.createElement(GSXML.RESPONSE_ELEM); // empty response
331 }
332 String classifierIDs[] = new String[classNodes.getLength()];
333 for(int i = 0; i < classifierIDs.length; i++) {
334 Element e = (Element)classNodes.item(i);
335 classifierIDs[i] = e.getAttribute(GSXML.NODE_ID_ATT);
336 classifierIDs[i] = translateId(classifierIDs[i]);
337 }
338
339 NodeList params = request.getElementsByTagName(GSXML.PARAM_ELEM);
340 String structure="";
341 String info="";
342 for(int i = 0; i < params.getLength(); i++) {
343 Element param = (Element)params.item(i);
344 if(param.getAttribute("name").equals("structure")) {
345 structure = structure + param.getAttribute("value") + "|";
346 } else if(param.getAttribute("name").equals("info")) {
347 info = info + param.getAttribute("value") + "|";
348 }
349 }
350
351 Element response
352 = getResponseAsDOM(fedoraServicesAPIA.retrieveBrowseStructure(collection, "ClassifierBrowse", classifierIDs,
353 new String[] {structure}, new String[] {info}));
354
355 return (Element)response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(0);
356 }
357
358 protected Element processTextQuery(Element request) {
359 return processQuery(request, "TextQuery");
360 }
361
362 protected Element processFieldQuery(Element request) {
363 return processQuery(request, "FieldQuery");
364 }
365
366 protected Element processQuery(Element request, String querytype) {
367 String collection = this.cluster_name;
368
369 String lang = request.getAttribute(GSXML.LANG_ATT);
370 if(!lang.equals(prevLanguage)) {
371 prevLanguage = lang;
372 fedoraServicesAPIA.setLanguage(lang);
373 }
374
375 NodeList paramNodes = request.getElementsByTagName(GSXML.PARAM_ELEM);
376 if(paramNodes.getLength() > 0) {
377 HashMap params = new HashMap(paramNodes.getLength());
378 for(int i = 0; i < paramNodes.getLength(); i++) {
379 Element param = (Element)paramNodes.item(i);
380 params.put(param.getAttribute(GSXML.NAME_ATT), param.getAttribute(GSXML.VALUE_ATT));
381 }
382
383 Element response = getResponseAsDOM(fedoraServicesAPIA.query(collection, querytype, params));
384 return (Element)response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(0);
385 } else {
386 logger.error("TextQuery request specified no parameters.\n");
387 return this.doc.createElement(GSXML.RESPONSE_ELEM); // empty response
388 }
389 }
390
391 protected String[] parseDocIDs(Element request, String nodeType) {
392 String lang = request.getAttribute(GSXML.LANG_ATT);
393 if(!lang.equals(prevLanguage)) {
394 prevLanguage = lang;
395 fedoraServicesAPIA.setLanguage(lang);
396 }
397
398 String[] docIDs = null;
399
400 Element docList = (Element) GSXML.getChildByTagName(request, nodeType+GSXML.LIST_MODIFIER);
401 if (docList != null) {
402 NodeList docNodes = docList.getElementsByTagName(nodeType);
403 if(docNodes.getLength() > 0) {
404 docIDs = new String[docNodes.getLength()];
405 for(int i = 0; i < docIDs.length; i++) {
406 Element e = (Element)docNodes.item(i);
407 docIDs[i] = e.getAttribute(GSXML.NODE_ID_ATT);
408 }
409 }
410 }
411 return docIDs;
412 }
413
414 /** if id ends in .fc, .pc etc, then translate it to the correct id
415 * For now (for testing things work) the default implementation is to just remove the suffix */
416 protected String translateId(String id) {
417 if (OID.needsTranslating(id)) {
418 return translateOID(id);
419 }
420 return id;}
421
422 /** if an id is not a greenstone id (an external id) then translate
423 * it to a greenstone one
424 * default implementation: return the id */
425 protected String translateExternalId(String id) {
426 return id;
427 }
428
429 /** translates relative oids into proper oids:
430 * .pr (parent), .rt (root) .fc (first child), .lc (last child),
431 * .ns (next sibling), .ps (previous sibling)
432 * .np (next page), .pp (previous page) : links sections in the order that you'd read the document
433 * a suffix is expected to be present so test before using
434 */
435 public String translateOID(String oid) {
436 int p = oid.lastIndexOf('.');
437 if (p != oid.length()-3) {
438 logger.info("translateoid error: '.' is not the third to last char!!");
439 return oid;
440 }
441
442 String top = oid.substring(0, p);
443 String suff = oid.substring(p+1);
444
445 // just in case we have multiple extensions, we must translate
446 // we process inner ones first
447 if (OID.needsTranslating(top)) {
448 top = translateOID(top);
449 }
450 if (suff.equals("pr")) {
451 return OID.getParent(top);
452 }
453 if (suff.equals("rt")) {
454 return OID.getTop(top);
455 }
456 if (suff.equals("np")) {
457 // try first child
458
459 String node_id = translateOID(top+".fc");
460 if (!node_id.equals(top)) {
461 return node_id;
462 }
463
464 // try next sibling
465 node_id = translateOID(top+".ns");
466 if (!node_id.equals(top)) {
467 return node_id;
468 }
469 // otherwise we keep trying parents sibling
470 String child_id = top;
471 String parent_id = OID.getParent(child_id);
472 while(!parent_id.equals(child_id)) {
473 node_id = translateOID(parent_id+".ns");
474 if (!node_id.equals(parent_id)) {
475 return node_id;
476 }
477 child_id = parent_id;
478 parent_id = OID.getParent(child_id);
479 }
480 return top; // we couldn't get a next page, so just return the original
481 }
482 if (suff.equals("pp")) {
483 String prev_sib = translateOID(top+".ps");
484 if (prev_sib.equals(top)) {
485 // no previous sibling, so return the parent
486 return OID.getParent(top);
487 }
488 // there is a previous sibling, so its either this section, or the last child of the last child
489 String last_child = translateOID(prev_sib+".lc");
490 while (!last_child.equals(prev_sib)) {
491 prev_sib = last_child;
492 last_child = translateOID(prev_sib+".lc");
493 }
494 return last_child;
495 }
496
497 int sibling_num = 0;
498 if (suff.equals("ss")) {
499 // we have to remove the sib num before we get top
500 p = top.lastIndexOf('.');
501 sibling_num = Integer.parseInt(top.substring(p+1));
502 top = top.substring(0, p);
503 }
504
505 // need to get info out of Fedora
506 String doc_id = top;
507 if (suff.endsWith("s")) {
508 doc_id = OID.getParent(top);
509 if (doc_id.equals(top)) {
510 // i.e. we are already at the top
511 return top;
512 }
513 }
514
515 // send off request to get sibling etc. information from Fedora
516 Element response = null;
517 String[] children = null;
518 if(doc_id.startsWith("CL")) { // classifiernode
519 response = getResponseAsDOM(fedoraServicesAPIA.retrieveBrowseStructure(this.cluster_name, "ClassifierBrowse", new String[]{doc_id},
520 new String[]{"children"}, new String[]{"siblingPosition"}));
521 NodeList nl = response.getElementsByTagName(GSXML.NODE_STRUCTURE_ELEM);
522 if(nl.getLength() > 0) {
523 Element nodeStructure = (Element)nl.item(0);
524
525 if(nodeStructure != null) {
526 Element root = (Element) GSXML.getChildByTagName(nodeStructure, GSXML.CLASS_NODE_ELEM);
527 if(root != null) { // get children
528 NodeList classNodes = root.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
529 if(classNodes != null) {
530 children = new String[classNodes.getLength()];
531 for(int i = 0; i < children.length; i++) {
532 Element child = (Element)classNodes.item(i);
533 children[i] = child.getAttribute(GSXML.NODE_ID_ATT);
534 }
535 }
536 }
537 }
538 }
539 } else { // documentnode
540 response = getResponseAsDOM(fedoraServicesAPIA.retrieveDocumentStructure(this.cluster_name, new String[]{doc_id},
541 new String[]{"children"}, new String[]{"siblingPosition"}));
542 String path = GSPath.createPath(new String[]{GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER,
543 GSXML.DOC_NODE_ELEM, GSXML.NODE_STRUCTURE_ELEM, GSXML.DOC_NODE_ELEM});
544 Element parentDocNode = (Element) GSXML.getNodeByPath(response, path);
545
546 if (parentDocNode == null) {
547 return top;
548 } // else
549 NodeList docNodes = parentDocNode.getElementsByTagName(GSXML.DOC_NODE_ELEM); // only children should remain, since that's what we requested
550 if(docNodes.getLength() > 0) {
551 children = new String[docNodes.getLength()];
552
553 for(int i = 0; i < children.length; i++) {
554 Element e = (Element)docNodes.item(i);
555 children[i] = e.getAttribute(GSXML.NODE_ID_ATT);
556 }
557 } else { // return root node
558 children = new String[]{doc_id};
559 }
560 }
561
562 if (suff.equals("fc")) {
563 return children[0];
564 } else if (suff.equals("lc")) {
565 return children[children.length-1];
566 } else {
567 if (suff.equals("ss")) {
568 return children[sibling_num-1];
569 }
570 // find the position that we are at.
571 int i=0;
572 while(i<children.length) {
573 if (children[i].equals(top)) {
574 break;
575 }
576 i++;
577 }
578
579 if (suff.equals("ns")) {
580 if (i==children.length-1) {
581 return children[i];
582 }
583 return children[i+1];
584 } else if (suff.equals("ps")) {
585 if (i==0) {
586 return children[i];
587 }
588 return children[i-1];
589 }
590 }
591
592 return top;
593 }
594
595
596 protected Element getResponseAsDOM(String response) {
597 if(response == null) { // will not be the case, because an empty
598 return null; // response message will be sent instead
599 }
600
601 Element message = null;
602 try{
603 // turn the String xml response into a DOM tree:
604 DocumentBuilder builder
605 = DocumentBuilderFactory.newInstance().newDocumentBuilder();
606 Document doc
607 = builder.parse(new InputSource(new StringReader(response)));
608 message = doc.getDocumentElement();
609 } catch(Exception e){
610 if(response == null) {
611 response = "";
612 }
613 logger.error("An error occurred while trying to parse the response: ");
614 logger.error(response);
615 logger.error(e.getMessage());
616 }
617
618 // Error elements in message will be processed outside of here, just return the message
619 return message;
620 }
621
622 /* //process method for stylesheet requests
623 protected Element processFormat(Element request) {} */
624
625 /* returns the service list for the subclass */
626 /* protected Element getServiceList(String lang) {
627 // for now, it is static and has no language stuff
628 return (Element) this.short_service_info.cloneNode(true);
629 }*/
630
631 /** returns a specific service description */
632 protected Element getServiceDescription(String service, String lang, String subset) {
633 if(!lang.equals(prevLanguage)) {
634 prevLanguage = lang;
635 fedoraServicesAPIA.setLanguage(lang);
636 }
637 String serviceResponse = fedoraServicesAPIA.describeService(service);
638 Element response = getResponseAsDOM(serviceResponse);
639
640 // should be no chance of an npe, since FedoraGS3 lists the services, so will have descriptions for each
641 Element e = (Element)response.getElementsByTagName(GSXML.SERVICE_ELEM).item(0);
642 e = (Element)this.doc.importNode(e, true);
643 return e;
644 }
645
646 protected Element getServiceFormat(String service) {
647 Element format = (Element)((Element)this.format_info_map.get(service)).cloneNode(true);
648 return format;
649 }
650
651 /** overloaded version for no args case */
652 protected String getTextString(String key, String lang) {
653 return getTextString(key, lang, null, null);
654 }
655
656 protected String getTextString(String key, String lang, String dictionary) {
657 return getTextString(key, lang, dictionary, null);
658 }
659 protected String getTextString(String key, String lang, String [] args) {
660 return getTextString(key, lang, null, args);
661 }
662
663 /** getTextString - retrieves a language specific text string for the given
664key and locale, from the specified resource_bundle (dictionary)
665 */
666 protected String getTextString(String key, String lang, String dictionary, String[] args) {
667
668 // we want to use the collection class loader in case there are coll specific files
669 if (dictionary != null) {
670 // just try the one specified dictionary
671 Dictionary dict = new Dictionary(dictionary, lang, this.class_loader);
672 String result = dict.get(key, args);
673 if (result == null) { // not found
674 return "_"+key+"_";
675 }
676 return result;
677 }
678
679 // now we try class names for dictionary names
680 String class_name = this.getClass().getName();
681 class_name = class_name.substring(class_name.lastIndexOf('.')+1);
682 Dictionary dict = new Dictionary(class_name, lang, this.class_loader);
683 String result = dict.get(key, args);
684 if (result != null) {
685 return result;
686 }
687
688 // we have to try super classes
689 Class c = this.getClass().getSuperclass();
690 while (result == null && c != null) {
691 class_name = c.getName();
692 class_name = class_name.substring(class_name.lastIndexOf('.')+1);
693 if (class_name.equals("ServiceRack")) {
694 // this is as far as we go
695 break;
696 }
697 dict = new Dictionary(class_name, lang, this.class_loader);
698 result = dict.get(key, args);
699 c = c.getSuperclass();
700 }
701 if (result == null) {
702 return "_"+key+"_";
703 }
704 return result;
705
706 }
707
708 protected String getMetadataNameText(String key, String lang) {
709
710 String properties_name = "metadata_names";
711 Dictionary dict = new Dictionary(properties_name, lang);
712
713 String result = dict.get(key);
714 if (result == null) { // not found
715 return null;
716 }
717 return result;
718 }
719}
720
Note: See TracBrowser for help on using the repository browser.