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

Last change on this file since 22307 was 22307, checked in by ak19, 14 years ago

Added a commented line of code for testing browse structure for siblings.

File size: 25.0 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 return (Element)response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(0);
284 }
285
286 protected Element processClassifierBrowseMetadataRetrieve(Element request) {
287 String[] classIDs = parseDocIDs(request, GSXML.CLASS_NODE_ELEM);
288 if(classIDs == null) {
289 logger.error("ClassifierBrowseMetadataRetrieve request specified no classifier nodes.\n");
290 return this.doc.createElement(GSXML.RESPONSE_ELEM); // empty response
291 } else {
292 for(int i = 0; i < classIDs.length; i++) {
293 classIDs[i] = translateId(classIDs[i]);
294 }
295 }
296
297 NodeList params = request.getElementsByTagName(GSXML.PARAM_ELEM);
298 String[] metafields = {};
299 if(params.getLength() > 0) {
300 metafields = new String[params.getLength()];
301 for(int i = 0; i < metafields.length; i++) {
302 Element param = (Element)params.item(i);
303 if(param.hasAttribute(GSXML.VALUE_ATT)){
304 metafields[i] = param.getAttribute(GSXML.VALUE_ATT);
305 } else {
306 metafields[i] = "";
307 }
308 }
309 }
310
311 Element response
312 = getResponseAsDOM(fedoraServicesAPIA.retrieveBrowseMetadata(this.cluster_name,
313 "ClassifierBrowseMetadataRetrieve",
314 classIDs, metafields));
315 return (Element)response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(0);
316 }
317
318 protected Element processClassifierBrowse(Element request) {
319 String collection = this.cluster_name;
320 String lang = request.getAttribute(GSXML.LANG_ATT);
321 if(!lang.equals(prevLanguage)) {
322 prevLanguage = lang;
323 fedoraServicesAPIA.setLanguage(lang);
324 }
325
326 NodeList classNodes = request.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
327 if(classNodes == null || classNodes.getLength() <= 0) {
328 logger.error("ClassifierBrowse request specified no classifier IDs.\n");
329 return this.doc.createElement(GSXML.RESPONSE_ELEM); // empty response
330 }
331 String classifierIDs[] = new String[classNodes.getLength()];
332 for(int i = 0; i < classifierIDs.length; i++) {
333 Element e = (Element)classNodes.item(i);
334 classifierIDs[i] = e.getAttribute(GSXML.NODE_ID_ATT);
335 classifierIDs[i] = translateId(classifierIDs[i]);
336 }
337
338 NodeList params = request.getElementsByTagName(GSXML.PARAM_ELEM);
339 String structure="";
340 String info="";
341 for(int i = 0; i < params.getLength(); i++) {
342 Element param = (Element)params.item(i);
343 if(param.getAttribute("name").equals("structure")) {
344 structure = structure + param.getAttribute("value") + "|";
345 } else if(param.getAttribute("name").equals("info")) {
346 info = info + param.getAttribute("value") + "|";
347 }
348 }
349 ///structure = structure + "siblings"; //test for getting with classifier browse structure: siblings
350
351 Element response
352 = getResponseAsDOM(fedoraServicesAPIA.retrieveBrowseStructure(collection, "ClassifierBrowse", classifierIDs,
353 new String[] {structure}, new String[] {info}));
354 ///logger.error("**** FedoraServiceProxy - Response from retrieveBrowseStructure: " + GSXML.nodeToFormattedString(response));
355
356 return (Element)response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(0);
357 }
358
359 protected Element processTextQuery(Element request) {
360 return processQuery(request, "TextQuery");
361 }
362
363 protected Element processFieldQuery(Element request) {
364 return processQuery(request, "FieldQuery");
365 }
366
367 protected Element processQuery(Element request, String querytype) {
368 String collection = this.cluster_name;
369
370 String lang = request.getAttribute(GSXML.LANG_ATT);
371 if(!lang.equals(prevLanguage)) {
372 prevLanguage = lang;
373 fedoraServicesAPIA.setLanguage(lang);
374 }
375
376 NodeList paramNodes = request.getElementsByTagName(GSXML.PARAM_ELEM);
377 if(paramNodes.getLength() > 0) {
378 HashMap params = new HashMap(paramNodes.getLength());
379 for(int i = 0; i < paramNodes.getLength(); i++) {
380 Element param = (Element)paramNodes.item(i);
381 params.put(param.getAttribute(GSXML.NAME_ATT), param.getAttribute(GSXML.VALUE_ATT));
382 }
383
384 Element response = getResponseAsDOM(fedoraServicesAPIA.query(collection, querytype, params));
385 return (Element)response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(0);
386 } else {
387 logger.error("TextQuery request specified no parameters.\n");
388 return this.doc.createElement(GSXML.RESPONSE_ELEM); // empty response
389 }
390 }
391
392 protected String[] parseDocIDs(Element request, String nodeType) {
393 String lang = request.getAttribute(GSXML.LANG_ATT);
394 if(!lang.equals(prevLanguage)) {
395 prevLanguage = lang;
396 fedoraServicesAPIA.setLanguage(lang);
397 }
398
399 String[] docIDs = null;
400
401 Element docList = (Element) GSXML.getChildByTagName(request, nodeType+GSXML.LIST_MODIFIER);
402 if (docList != null) {
403 NodeList docNodes = docList.getElementsByTagName(nodeType);
404 if(docNodes.getLength() > 0) {
405 docIDs = new String[docNodes.getLength()];
406 for(int i = 0; i < docIDs.length; i++) {
407 Element e = (Element)docNodes.item(i);
408 docIDs[i] = e.getAttribute(GSXML.NODE_ID_ATT);
409 }
410 }
411 }
412 return docIDs;
413 }
414
415 /** if id ends in .fc, .pc etc, then translate it to the correct id
416 * For now (for testing things work) the default implementation is to just remove the suffix */
417 protected String translateId(String id) {
418 if (OID.needsTranslating(id)) {
419 return translateOID(id);
420 }
421 return id;}
422
423 /** if an id is not a greenstone id (an external id) then translate
424 * it to a greenstone one
425 * default implementation: return the id */
426 protected String translateExternalId(String id) {
427 return id;
428 }
429
430 /** translates relative oids into proper oids:
431 * .pr (parent), .rt (root) .fc (first child), .lc (last child),
432 * .ns (next sibling), .ps (previous sibling)
433 * .np (next page), .pp (previous page) : links sections in the order that you'd read the document
434 * a suffix is expected to be present so test before using
435 */
436 public String translateOID(String oid) {
437 int p = oid.lastIndexOf('.');
438 if (p != oid.length()-3) {
439 logger.info("translateoid error: '.' is not the third to last char!!");
440 return oid;
441 }
442
443 String top = oid.substring(0, p);
444 String suff = oid.substring(p+1);
445
446 // just in case we have multiple extensions, we must translate
447 // we process inner ones first
448 if (OID.needsTranslating(top)) {
449 top = translateOID(top);
450 }
451 if (suff.equals("pr")) {
452 return OID.getParent(top);
453 }
454 if (suff.equals("rt")) {
455 return OID.getTop(top);
456 }
457 if (suff.equals("np")) {
458 // try first child
459
460 String node_id = translateOID(top+".fc");
461 if (!node_id.equals(top)) {
462 return node_id;
463 }
464
465 // try next sibling
466 node_id = translateOID(top+".ns");
467 if (!node_id.equals(top)) {
468 return node_id;
469 }
470 // otherwise we keep trying parents sibling
471 String child_id = top;
472 String parent_id = OID.getParent(child_id);
473 while(!parent_id.equals(child_id)) {
474 node_id = translateOID(parent_id+".ns");
475 if (!node_id.equals(parent_id)) {
476 return node_id;
477 }
478 child_id = parent_id;
479 parent_id = OID.getParent(child_id);
480 }
481 return top; // we couldn't get a next page, so just return the original
482 }
483 if (suff.equals("pp")) {
484 String prev_sib = translateOID(top+".ps");
485 if (prev_sib.equals(top)) {
486 // no previous sibling, so return the parent
487 return OID.getParent(top);
488 }
489 // there is a previous sibling, so its either this section, or the last child of the last child
490 String last_child = translateOID(prev_sib+".lc");
491 while (!last_child.equals(prev_sib)) {
492 prev_sib = last_child;
493 last_child = translateOID(prev_sib+".lc");
494 }
495 return last_child;
496 }
497
498 int sibling_num = 0;
499 if (suff.equals("ss")) {
500 // we have to remove the sib num before we get top
501 p = top.lastIndexOf('.');
502 sibling_num = Integer.parseInt(top.substring(p+1));
503 top = top.substring(0, p);
504 }
505
506 // need to get info out of Fedora
507 String doc_id = top;
508 if (suff.endsWith("s")) {
509 doc_id = OID.getParent(top);
510 if (doc_id.equals(top)) {
511 // i.e. we are already at the top
512 return top;
513 }
514 }
515
516 // send off request to get sibling etc. information from Fedora
517 Element response = null;
518 String[] children = null;
519 if(doc_id.startsWith("CL")) { // classifiernode
520 response = getResponseAsDOM(fedoraServicesAPIA.retrieveBrowseStructure(this.cluster_name, "ClassifierBrowse", new String[]{doc_id},
521 new String[]{"children"}, new String[]{"siblingPosition"}));
522 NodeList nl = response.getElementsByTagName(GSXML.NODE_STRUCTURE_ELEM);
523 if(nl.getLength() > 0) {
524 Element nodeStructure = (Element)nl.item(0);
525
526 if(nodeStructure != null) {
527 Element root = (Element) GSXML.getChildByTagName(nodeStructure, GSXML.CLASS_NODE_ELEM);
528 if(root != null) { // get children
529 NodeList classNodes = root.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
530 if(classNodes != null) {
531 children = new String[classNodes.getLength()];
532 for(int i = 0; i < children.length; i++) {
533 Element child = (Element)classNodes.item(i);
534 children[i] = child.getAttribute(GSXML.NODE_ID_ATT);
535 }
536 }
537 }
538 }
539 }
540 } else { // documentnode
541 response = getResponseAsDOM(fedoraServicesAPIA.retrieveDocumentStructure(this.cluster_name, new String[]{doc_id},
542 new String[]{"children"}, new String[]{"siblingPosition"}));
543 String path = GSPath.createPath(new String[]{GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER,
544 GSXML.DOC_NODE_ELEM, GSXML.NODE_STRUCTURE_ELEM, GSXML.DOC_NODE_ELEM});
545 Element parentDocNode = (Element) GSXML.getNodeByPath(response, path);
546
547 if (parentDocNode == null) {
548 return top;
549 } // else
550 NodeList docNodes = parentDocNode.getElementsByTagName(GSXML.DOC_NODE_ELEM); // only children should remain, since that's what we requested
551 if(docNodes.getLength() > 0) {
552 children = new String[docNodes.getLength()];
553
554 for(int i = 0; i < children.length; i++) {
555 Element e = (Element)docNodes.item(i);
556 children[i] = e.getAttribute(GSXML.NODE_ID_ATT);
557 }
558 } else { // return root node
559 children = new String[]{doc_id};
560 }
561 }
562
563 if (suff.equals("fc")) {
564 return children[0];
565 } else if (suff.equals("lc")) {
566 return children[children.length-1];
567 } else {
568 if (suff.equals("ss")) {
569 return children[sibling_num-1];
570 }
571 // find the position that we are at.
572 int i=0;
573 while(i<children.length) {
574 if (children[i].equals(top)) {
575 break;
576 }
577 i++;
578 }
579
580 if (suff.equals("ns")) {
581 if (i==children.length-1) {
582 return children[i];
583 }
584 return children[i+1];
585 } else if (suff.equals("ps")) {
586 if (i==0) {
587 return children[i];
588 }
589 return children[i-1];
590 }
591 }
592
593 return top;
594 }
595
596
597 protected Element getResponseAsDOM(String response) {
598 if(response == null) { // will not be the case, because an empty
599 return null; // response message will be sent instead
600 }
601
602 Element message = null;
603 try{
604 // turn the String xml response into a DOM tree:
605 DocumentBuilder builder
606 = DocumentBuilderFactory.newInstance().newDocumentBuilder();
607 Document doc
608 = builder.parse(new InputSource(new StringReader(response)));
609 message = doc.getDocumentElement();
610 } catch(Exception e){
611 if(response == null) {
612 response = "";
613 }
614 logger.error("An error occurred while trying to parse the response: ");
615 logger.error(response);
616 logger.error(e.getMessage());
617 }
618
619 // Error elements in message will be processed outside of here, just return the message
620 return message;
621 }
622
623 /* //process method for stylesheet requests
624 protected Element processFormat(Element request) {} */
625
626 /* returns the service list for the subclass */
627 /* protected Element getServiceList(String lang) {
628 // for now, it is static and has no language stuff
629 return (Element) this.short_service_info.cloneNode(true);
630 }*/
631
632 /** returns a specific service description */
633 protected Element getServiceDescription(String service, String lang, String subset) {
634 if(!lang.equals(prevLanguage)) {
635 prevLanguage = lang;
636 fedoraServicesAPIA.setLanguage(lang);
637 }
638 String serviceResponse = fedoraServicesAPIA.describeService(service);
639 Element response = getResponseAsDOM(serviceResponse);
640
641 // should be no chance of an npe, since FedoraGS3 lists the services, so will have descriptions for each
642 Element e = (Element)response.getElementsByTagName(GSXML.SERVICE_ELEM).item(0);
643 e = (Element)this.doc.importNode(e, true);
644 return e;
645 }
646
647 protected Element getServiceFormat(String service) {
648 Element format = (Element)((Element)this.format_info_map.get(service)).cloneNode(true);
649 return format;
650 }
651
652 /** overloaded version for no args case */
653 protected String getTextString(String key, String lang) {
654 return getTextString(key, lang, null, null);
655 }
656
657 protected String getTextString(String key, String lang, String dictionary) {
658 return getTextString(key, lang, dictionary, null);
659 }
660 protected String getTextString(String key, String lang, String [] args) {
661 return getTextString(key, lang, null, args);
662 }
663
664 /** getTextString - retrieves a language specific text string for the given
665key and locale, from the specified resource_bundle (dictionary)
666 */
667 protected String getTextString(String key, String lang, String dictionary, String[] args) {
668
669 // we want to use the collection class loader in case there are coll specific files
670 if (dictionary != null) {
671 // just try the one specified dictionary
672 Dictionary dict = new Dictionary(dictionary, lang, this.class_loader);
673 String result = dict.get(key, args);
674 if (result == null) { // not found
675 return "_"+key+"_";
676 }
677 return result;
678 }
679
680 // now we try class names for dictionary names
681 String class_name = this.getClass().getName();
682 class_name = class_name.substring(class_name.lastIndexOf('.')+1);
683 Dictionary dict = new Dictionary(class_name, lang, this.class_loader);
684 String result = dict.get(key, args);
685 if (result != null) {
686 return result;
687 }
688
689 // we have to try super classes
690 Class c = this.getClass().getSuperclass();
691 while (result == null && c != null) {
692 class_name = c.getName();
693 class_name = class_name.substring(class_name.lastIndexOf('.')+1);
694 if (class_name.equals("ServiceRack")) {
695 // this is as far as we go
696 break;
697 }
698 dict = new Dictionary(class_name, lang, this.class_loader);
699 result = dict.get(key, args);
700 c = c.getSuperclass();
701 }
702 if (result == null) {
703 return "_"+key+"_";
704 }
705 return result;
706
707 }
708
709 protected String getMetadataNameText(String key, String lang) {
710
711 String properties_name = "metadata_names";
712 Dictionary dict = new Dictionary(properties_name, lang);
713
714 String result = dict.get(key);
715 if (result == null) { // not found
716 return null;
717 }
718 return result;
719 }
720}
721
Note: See TracBrowser for help on using the repository browser.