source: tags/ant-install-branch-merged-1/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractBrowse.java@ 9873

Last change on this file since 9873 was 9873, checked in by (none), 19 years ago

This commit was manufactured by cvs2svn to create tag
'ant-install-branch-merged-1'.

  • Property svn:keywords set to Author Date Id Revision
File size: 25.6 KB
Line 
1/*
2 * AbstractBrowse.java
3 * Copyright (C) 2005 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
22// Greenstone classes
23import org.greenstone.gsdl3.util.GSXML;
24import org.greenstone.gsdl3.util.GSPath;
25import org.greenstone.gsdl3.util.MacroResolver;
26
27// XML classes
28import org.w3c.dom.Document;
29import org.w3c.dom.Element;
30import org.w3c.dom.NodeList;
31
32// General Java classes
33import java.util.ArrayList;
34
35/** Partially implements a generic classifier service
36 *
37 * @author <a href="mailto:[email protected]">Katherine Don</a>
38 */
39
40public abstract class AbstractBrowse
41 extends ServiceRack {
42
43 // the browsing services
44 private static final String CLASSIFIER_SERVICE = "ClassifierBrowse";
45 private static final String CLASSIFIER_METADATA_SERVICE = "ClassifierBrowseMetadataRetrieve";
46
47 // do we want to keep info request?
48
49 protected static final String STRUCT_PARAM = "structure";
50 protected static final String INFO_PARAM = "info";
51
52 protected static final String STRUCT_ANCESTORS = "ancestors";
53 protected static final String STRUCT_PARENT = "parent";
54 protected static final String STRUCT_SIBS = "siblings";
55 protected static final String STRUCT_CHILDREN = "children";
56 protected static final String STRUCT_DESCENDS = "descendants";
57 protected static final String STRUCT_ENTIRE = "entire";
58
59 protected static final String INFO_NUM_SIBS = "numSiblings";
60 protected static final String INFO_NUM_CHILDREN = "numChildren";
61 protected static final String INFO_SIB_POS = "siblingPosition";
62
63 protected Element config_info = null; // the xml from the config file
64
65 protected MacroResolver macro_resolver = null;
66
67 protected String default_document_type = null;
68 /** constructor */
69 protected AbstractBrowse()
70 {
71 }
72
73
74 /** configure this service */
75 public boolean configure(Element info, Element extra_info)
76 {
77 System.out.println("Configuring AbstractBrowse...");
78 this.config_info = info;
79
80 if (macro_resolver != null) {
81 // set up the macro resolver
82 Element replacement_elem = (Element)GSXML.getChildByTagName(extra_info, "replaceList");
83 if (replacement_elem != null) {
84 macro_resolver.addMacros(replacement_elem);
85 }
86
87 }
88
89
90 // check that there are classifiers specified
91 Element class_list = (Element)GSXML.getChildByTagName(info, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
92 if (class_list == null) {
93 // no classifiers specified
94 return false;
95 }
96
97 // get the display and format elements from the coll config file for
98 // the classifiers
99 extractExtraClassifierInfo(info, extra_info);
100
101 // short_service_info_ - the browse one
102 Element cb_service = this.doc.createElement(GSXML.SERVICE_ELEM);
103 cb_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BROWSE);
104 cb_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE);
105 this.short_service_info.appendChild(cb_service);
106
107 // metadata retrieval for the browsing
108 Element cbmr_service = this.doc.createElement(GSXML.SERVICE_ELEM);
109 cbmr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
110 cbmr_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_METADATA_SERVICE);
111 this.short_service_info.appendChild(cbmr_service);
112
113 // the format info
114 Element cb_format_info = this.doc.createElement(GSXML.FORMAT_ELEM);
115 boolean format_found = false;
116
117 // try the default format first
118 Element def_format = (Element) GSXML.getChildByTagName(info, GSXML.FORMAT_ELEM);
119 if (def_format != null) {
120 cb_format_info.appendChild(GSXML.duplicateWithNewName(this.doc, def_format, GSXML.DEFAULT_ELEM, true));
121 format_found = true;
122 }
123
124 // add in to the description a simplified list of classifiers
125 NodeList classifiers = class_list.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
126 for(int i=0; i<classifiers.getLength(); i++) {
127 Element cl = (Element)classifiers.item(i);
128 Element new_cl = (Element)this.doc.importNode(cl, false); // just import this node, not the children
129
130 // get the format info out, and put inside a classifier element
131 Element format_cl = (Element)new_cl.cloneNode(false);
132 Element format = (Element)GSXML.getChildByTagName(cl, GSXML.FORMAT_ELEM);
133 if (format != null) {
134
135 //copy all the children
136 NodeList elems = format.getChildNodes();
137 for (int j=0; j<elems.getLength();j++) {
138 format_cl.appendChild(this.doc.importNode(elems.item(j), true));
139 }
140 cb_format_info.appendChild(format_cl);
141 format_found = true;
142 }
143
144 }
145
146 if (format_found) {
147 this.format_info_map.put(CLASSIFIER_SERVICE, cb_format_info);
148 }
149
150 // look for document display format - is there a default doc type??
151 String path = GSPath.appendLink(GSXML.DISPLAY_ELEM, GSXML.FORMAT_ELEM);
152 Element display_format = (Element)GSXML.getNodeByPath(extra_info, path);
153 if (display_format != null) {
154 // check for docType option.
155 Element doc_type_opt = GSXML.getNamedElement(display_format, "gsf:option", GSXML.NAME_ATT, "documentType");
156 if (doc_type_opt != null) {
157 String value = doc_type_opt.getAttribute(GSXML.VALUE_ATT);
158 if (!value.equals("")) {
159 this.default_document_type = value;
160 }
161 }
162 }
163
164 return true;
165 }
166
167 protected Element getServiceDescription(String service_id, String lang, String subset) {
168
169 if (service_id.equals(CLASSIFIER_SERVICE)) {
170
171 Element class_list = (Element)GSXML.getChildByTagName(this.config_info, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
172 if (class_list == null) {
173 // no classifiers specified
174 return null;
175 }
176
177 Element cb_service = this.doc.createElement(GSXML.SERVICE_ELEM);
178 cb_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BROWSE);
179 cb_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE);
180 cb_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME, getTextString(CLASSIFIER_SERVICE+".name", lang)));
181 cb_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION, getTextString(CLASSIFIER_SERVICE+".description", lang)));
182
183 Element cl_list = this.doc.createElement(GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
184 cb_service.appendChild(cl_list);
185 NodeList classifiers = class_list.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
186 for(int i=0; i<classifiers.getLength(); i++) {
187 Element cl = (Element)classifiers.item(i);
188 Element new_cl = (Element)this.doc.importNode(cl, false); // just import this node, not the children
189 String content = cl.getAttribute(GSXML.CLASSIFIER_CONTENT_ATT);
190 cl_list.appendChild(new_cl);
191 String text = GSXML.getDisplayText(cl,
192 GSXML.DISPLAY_TEXT_NAME,
193 lang, "en");
194 if (text == null || text.equals("")) {
195 // no display element was specified, use the metadata name
196 // for now this looks in the class properties file
197 // this needs to use a general metadata thing instead
198 text = getMetadataNameText(content+".buttonname", lang);
199 }
200 if (text == null) {
201 text = content;
202 }
203
204 Element cl_name = GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME, text);
205 new_cl.appendChild(cl_name);
206
207 // description
208
209 String meta_name = getMetadataNameText(content, lang);
210 if (meta_name==null) {
211 meta_name = content;
212 }
213 String [] array = {meta_name};
214 String description = getTextString("ClassifierBrowse.classifier_help", lang, array);
215 Element cl_desc = GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION, description);
216 new_cl.appendChild(cl_desc);
217
218 }
219 return cb_service;
220 }
221
222 // these ones are probably never called, but put them here just in case
223
224 if (service_id.equals(CLASSIFIER_METADATA_SERVICE)) {
225
226 Element cbmr_service = this.doc.createElement(GSXML.SERVICE_ELEM);
227 cbmr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
228 cbmr_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_METADATA_SERVICE);
229 return cbmr_service;
230 }
231
232 return null;
233 }
234
235 /** this looks for any classifier specific display or format info from extra_info and adds it in to the correct place in info */
236 protected boolean extractExtraClassifierInfo(Element info, Element extra_info) {
237
238 if (extra_info == null) {
239 return false;
240 }
241
242 Document owner = info.getOwnerDocument();
243 // so far we have display and format elements that we need for classifiers
244 NodeList classifiers = info.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
245 Element config_browse = (Element)GSXML.getChildByTagName(extra_info, GSXML.BROWSE_ELEM);
246
247 for (int i=0; i<classifiers.getLength();i++) {
248 Element cl = (Element)classifiers.item(i);
249 String name = cl.getAttribute(GSXML.NAME_ATT);
250 Element node_extra = GSXML.getNamedElement(config_browse,
251 GSXML.CLASSIFIER_ELEM,
252 GSXML.NAME_ATT,
253 name);
254 if (node_extra == null) {
255 System.err.println("GS2REtrieve: haven't found extra info for classifier named "+name);
256 continue;
257 }
258
259 // get the display elements if any - displayName
260 NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
261 if (display_names !=null) {
262 Element display = owner.createElement(GSXML.DISPLAY_ELEM);
263 for (int j=0; j<display_names.getLength(); j++) {
264 Element e = (Element)display_names.item(j);
265 cl.appendChild(owner.importNode(e, true));
266
267 }
268 }
269
270 // get the format element if any
271 Element format = (Element)GSXML.getChildByTagName(node_extra, GSXML.FORMAT_ELEM);
272 if (format==null) { // try a generic one that applies to all classifiers
273 format = (Element)GSXML.getChildByTagName(extra_info,
274 GSXML.FORMAT_ELEM);
275 }
276 if (format!=null) { // append to index info
277 cl.appendChild(owner.importNode(format, true));
278 }
279 } // for each classifier
280
281 // now check for default format info
282 Element default_format = (Element)GSXML.getChildByTagName(config_browse, GSXML.FORMAT_ELEM);
283 if (default_format!=null) { // append to info
284 info.appendChild(owner.importNode(default_format, true));
285 }
286
287 return true;
288 }
289
290 protected Element processClassifierBrowse(Element request) {
291
292 // Create a new (empty) result message
293 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
294 result.setAttribute(GSXML.FROM_ATT, CLASSIFIER_SERVICE);
295 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
296
297 String lang = request.getAttribute(GSXML.LANG_ATT);
298 Element query_node_list = (Element) GSXML.getChildByTagName(request, GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER);
299 if (query_node_list == null) {
300 System.err.println("AbstractBrowse Error: ClassifierBrowse request specified no doc nodes.\n");
301 return result;
302 }
303
304 // Get the parameters of the request
305 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
306 if (param_list == null) {
307 System.err.println("AbstractBrowse Error: ClassifierBrowse request had no paramList.");
308 return result; // Return the empty result
309 }
310
311 // the type of info required
312 boolean want_structure = false;
313 boolean want_info = false;
314
315 ArrayList info_types=new ArrayList();
316 // The document structure information desired
317 boolean want_ancestors = false;
318 boolean want_parent = false;
319 boolean want_siblings = false;
320 boolean want_children = false;
321 boolean want_descendants = false;
322
323 boolean want_entire_structure = false;
324 // Process the request parameters
325 NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
326 for (int i=0; i<params.getLength();i++) {
327
328 Element param = (Element)params.item(i);
329 String p_name = param.getAttribute(GSXML.NAME_ATT);
330 String p_value = GSXML.getValue(param);
331 // Identify the structure information desired
332 if (p_name.equals(STRUCT_PARAM)) {
333 want_structure = true;
334
335 // This is NOT locale sensitive
336 if (p_value.equals(STRUCT_ANCESTORS))
337 want_ancestors = true;
338 else if (p_value.equals(STRUCT_PARENT))
339 want_parent = true;
340 else if (p_value.equals(STRUCT_SIBS))
341 want_siblings = true;
342 else if (p_value.equals(STRUCT_CHILDREN))
343 want_children = true;
344 else if (p_value.equals(STRUCT_DESCENDS))
345 want_descendants = true;
346 else if (p_value.equals(STRUCT_ENTIRE))
347 want_entire_structure = true;
348 else
349 System.err.println("AbstractDocumentRetrieve Warning: Unknown value \"" + p_value + "\".");
350 } else if (p_name.equals(INFO_PARAM)) {
351 want_info = true;
352 info_types.add(p_value);
353 }
354 }
355
356 // Make sure there is no repeated information
357 if (want_ancestors)
358 want_parent = false;
359 if (want_descendants)
360 want_children = false;
361
362 // the node list to hold the results
363 Element node_list = this.doc.createElement(GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER);
364 result.appendChild(node_list);
365
366 // Get the nodes
367 String[] node_ids = GSXML.getAttributeValuesFromList(query_node_list,
368 GSXML.NODE_ID_ATT);
369 for (int i = 0; i < node_ids.length; i++) {
370 // Add the document to the list
371 Element node = this.doc.createElement(GSXML.CLASS_NODE_ELEM);
372 node_list.appendChild(node);
373
374 String node_id = node_ids[i];
375 node.setAttribute(GSXML.NODE_ID_ATT, node_id);
376
377 if (idNeedsTranslating(node_id)) {
378 node_id = translateId(node_id);
379 if (node_id == null) {
380 continue;
381 }
382 node.setAttribute(GSXML.NODE_ID_ATT, node_id);
383 }
384
385 if (want_info) {
386
387 Element node_info_elem = this.doc.createElement("nodeStructureInfo");
388 node.appendChild(node_info_elem);
389
390 for (int j=0; j<info_types.size(); j++) {
391 String info_type = (String)info_types.get(j);
392 String info_value = getStructureInfo(node_id, info_type);
393 if (info_value != null) {
394 Element info_elem = this.doc.createElement("info");
395 info_elem.setAttribute(GSXML.NAME_ATT, info_type);
396 info_elem.setAttribute(GSXML.VALUE_ATT, info_value);
397 node_info_elem.appendChild(info_elem);
398 }
399 }
400 }
401
402 if (want_structure) {
403 // all structure info goes into a nodeStructure elem
404 Element structure_elem = this.doc.createElement(GSXML.NODE_STRUCTURE_ELEM);
405 node.appendChild(structure_elem);
406
407 if (want_entire_structure) {
408 String root_id = getRootId(node_id);
409 Element root_node = createClassifierNode(root_id); //, true, false);
410 addDescendants(root_node, root_id, true);
411 structure_elem.appendChild(root_node);
412 continue; // with the next document, we dont need to do any more here
413 }
414
415 // Add the requested structure information
416 Element base_node = createClassifierNode(node_id); //, false, false);
417
418 //Ancestors: continually add parent nodes until the root is reached
419 Element top_node = base_node; // the top node so far
420 if (want_ancestors) {
421 String current_id = node_id;
422 while (true) {
423 String parent_id = getParentId(current_id);
424 //Element parent = getParent(current_id);
425 if (parent_id == null)
426 break; // no parent
427 Element parent_node = createClassifierNode(parent_id);
428 parent_node.appendChild(top_node);
429 current_id = parent_id;//.getAttribute(GSXML.NODE_ID_ATT);
430 top_node = parent_node;
431 }
432 }
433 // Parent: get the parent of the selected node
434 else if (want_parent) {
435 String parent_id = getParentId(node_id);
436 if (parent_id != null) {
437 Element parent_node = createClassifierNode(parent_id);
438 parent_node.appendChild(base_node);
439 top_node = parent_node;
440 }
441 }
442
443 // now the top node is the root of the structure
444 structure_elem.appendChild(top_node);
445
446 //Siblings: get the other descendants of the selected node's parent
447 if (want_siblings) {
448
449 Element parent_node = (Element)base_node.getParentNode(); // this may be the structure element if there has been no request for parents or ancestors
450 String parent_id = getParentId(node_id);
451 // add siblings, - returns a pointer to the new current node
452 base_node = addSiblings(parent_node, parent_id, node_id);
453 }
454
455 // Children: get the descendants, but only one level deep
456 if (want_children) {
457 addDescendants(base_node, node_id, false);
458 }
459 // Descendants: recursively get every descendant
460 else if (want_descendants) {
461 addDescendants(base_node, node_id, true);
462 }
463 } // if want structure
464 } // for each doc
465 return result;
466 }
467
468
469 protected Element processClassifierBrowseMetadataRetrieve(Element request) {
470
471 // Create a new (empty) result message
472 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
473
474 String lang = request.getAttribute(GSXML.LANG_ATT);
475 result.setAttribute(GSXML.FROM_ATT, CLASSIFIER_METADATA_SERVICE);
476 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
477
478 // Get the parameters of the request
479 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
480 if (param_list == null) {
481 System.err.println("AbstractBrowse, ClassifierBrowseMetadataRetrieve Error: missing paramList.\n");
482 return result; // Return the empty result
483 }
484
485 // The metadata information required
486 ArrayList metadata_names_list = new ArrayList();
487 boolean all_metadata = false;
488 // Process the request parameters
489 Element param = (Element) param_list.getFirstChild();
490 while (param != null) {
491 // Identify the metadata information desired
492 if (param.getAttribute(GSXML.NAME_ATT).equals("metadata")) {
493 String metadata = GSXML.getValue(param);
494 if (metadata.equals("all")) {
495 all_metadata = true;
496 break;
497 }
498 metadata_names_list.add(metadata);
499 }
500 param = (Element) param.getNextSibling();
501 }
502
503 Element node_list = this.doc.createElement(GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER);
504 result.appendChild(node_list);
505
506 // Get the nodes
507 Element request_node_list = (Element) GSXML.getChildByTagName(request, GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER);
508 if (request_node_list == null) {
509 System.err.println("AbstractBrowse Error: ClassifierBrowseMetadataRetrieve request had no "+GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER);
510 return result;
511 }
512
513 NodeList request_nodes = request_node_list.getChildNodes();
514 for (int i = 0; i < request_nodes.getLength(); i++) {
515 Element request_node = (Element) request_nodes.item(i);
516 String node_id = request_node.getAttribute(GSXML.NODE_ID_ATT);
517
518 // Add the document to the results list
519 Element new_node = (Element)this.doc.importNode(request_node, false);
520 node_list.appendChild(new_node);
521
522 if (idNeedsTranslating(node_id)) {
523 node_id = translateId(node_id);
524 }
525 if (node_id == null) {
526 continue;
527 }
528
529 Element metadata_list = getMetadataList(node_id, all_metadata, metadata_names_list);
530 new_node.appendChild(metadata_list);
531 }
532
533 return result;
534 }
535
536
537 /** Creates a classifier node */
538 protected Element createClassifierNode(String node_id)
539 {
540 Element node = this.doc.createElement(GSXML.CLASS_NODE_ELEM);
541 node.setAttribute(GSXML.NODE_ID_ATT, node_id);
542 return node;
543 }
544
545 /** create an element to go into the structure. A node element
546 * has the form
547 * <docNode nodeId='xxx' nodeType='leaf' docType='hierarchy'/>
548 */
549 protected Element createDocNode(String node_id) {
550 Element node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
551 node.setAttribute(GSXML.NODE_ID_ATT, node_id);
552
553 String doc_type = null;
554 if (default_document_type != null) {
555 doc_type = default_document_type;
556 } else {
557 doc_type = getDocType(node_id);
558 }
559 node.setAttribute(GSXML.DOC_TYPE_ATT, doc_type);
560 String node_type = getNodeType(node_id, doc_type);
561 node.setAttribute(GSXML.NODE_TYPE_ATT, node_type);
562 return node;
563 }
564
565 /** returns the node type of the specified node.
566 should be one of
567 GSXML.NODE_TYPE_LEAF,
568 GSXML.NODE_TYPE_INTERNAL,
569 GSXML.NODE_TYPE_ROOT
570 */
571 protected String getNodeType(String node_id, String doc_type) {
572 if (doc_type.equals(GSXML.DOC_TYPE_SIMPLE)) {
573 return GSXML.NODE_TYPE_LEAF;
574 }
575
576 if (getParentId(node_id)==null) {
577 return GSXML.NODE_TYPE_ROOT;
578 }
579 if (doc_type.equals(GSXML.DOC_TYPE_PAGED)) {
580 return GSXML.NODE_TYPE_LEAF;
581 }
582 if (getChildrenIds(node_id)==null) {
583 return GSXML.NODE_TYPE_LEAF;
584 }
585 return GSXML.NODE_TYPE_INTERNAL;
586
587 }
588
589 /** adds all the children of doc_id the the doc element,
590 * and if recursive=true, adds all their children as well*/
591 protected void addDescendants(Element node, String node_id,
592 boolean recursive)
593 {
594 ArrayList child_ids = getChildrenIds(node_id);
595 if (child_ids==null) return;
596 for (int i=0; i< child_ids.size(); i++) {
597 String child_id = (String)child_ids.get(i);
598 Element child_elem;
599 if (isDocumentId(child_id)) {
600 child_elem = createDocNode(child_id);
601 } else {
602 child_elem = createClassifierNode(child_id);
603 }
604 node.appendChild(child_elem);
605 if (recursive) {
606 addDescendants(child_elem, child_id, recursive);
607 }
608 }
609 }
610
611 /** adds all the siblings of current_id to the parent element.
612 returns the new current element*/
613 protected Element addSiblings(Element parent_node, String parent_id,
614 String current_id) {
615 Element current_node = (Element)parent_node.getFirstChild();
616 if (current_node == null) {
617 // create a sensible error message
618 System.err.println("AbstractBrowse Error: there should be a first child.");
619 return null;
620 }
621 // remove the current child,- will add it in later in its correct place
622 parent_node.removeChild(current_node);
623
624 // add in all the siblings,
625 addDescendants(parent_node, parent_id, false);
626
627 // find the node that is now the current node
628 // this assumes that the new node that was created is the same as
629 // the old one that was removed - we may want to replace the new one
630 // with the old one.
631 Element new_current = GSXML.getNamedElement(parent_node, current_node.getNodeName(), GSXML.NODE_ID_ATT, current_id);
632 return new_current;
633 }
634
635 /** returns true if oid ends in
636 .fc (firstchild),
637 .lc (lastchild),
638 .pr (parent),
639 .ns (next sibling),
640 .ps (prev sibling),
641 .rt (root)
642 .ss (specified sibling),
643 false otherwise
644 */
645 protected boolean idNeedsTranslating(String node_id) {
646 String tail = node_id.substring(node_id.length()-3);
647 return (tail.equals(".fc") || tail.equals(".lc") ||
648 tail.equals(".pr") || tail.equals(".ns") ||
649 tail.equals(".ps") || tail.equals(".rt") ||
650 tail.equals(".ss"));
651
652 }
653
654 /** returns the list of sibling ids, including the specified node_id */
655 protected ArrayList getSiblingIds(String node_id) {
656 String parent_id = getParentId(node_id);
657 if (parent_id == null) {
658 return null;
659 }
660 return getChildrenIds(parent_id);
661
662 }
663
664 /** if id ends in .fc, .pc etc, then translate it to the correct id */
665 abstract protected String translateId(String node_id);
666
667 /** returns the document type of the doc that the specified node
668 belongs to. should be one of
669 GSXML.DOC_TYPE_SIMPLE,
670 GSXML.DOC_TYPE_PAGED,
671 GSXML.DOC_TYPE_HIERARCHY
672 */
673 abstract protected String getDocType(String node_id);
674
675 /** returns the id of the root node of the document containing node node_id. . may be the same as node_id */
676 abstract protected String getRootId(String node_id);
677 /** returns a list of the child ids in order, null if no children */
678 abstract protected ArrayList getChildrenIds(String node_id);
679 /** returns the node id of the parent node, null if no parent */
680 abstract protected String getParentId(String node_id);
681
682 /** returns true if the id refers to a document (rather than
683 * a classifier node)
684 */
685 abstract protected boolean isDocumentId(String node_id);
686
687 /** get the metadata for the classifier node node_id
688 * returns a metadataList element:
689 * <metadataList><metadata name="xxx">value</metadata></metadataList>
690 * if all_metadata is true, returns all available metadata, otherwise just
691 * returns requested metadata
692 */
693 abstract protected Element getMetadataList(String node_id,
694 boolean all_metadata,
695 ArrayList metadata_names);
696
697 /** returns the structural information asked for.
698 * info_type may be one of
699 * INFO_NUM_SIBS, INFO_NUM_CHILDREN, INFO_SIB_POS
700 */
701 abstract protected String getStructureInfo(String node_id, String info_type);
702// /** needs to get info from gdbm database - if the calling code gets it already it may pay to pass it in instead */
703// protected String resolveTextMacros(String doc_content, String doc_id, String lang)
704// {
705// DBInfo info = null;
706// if (doc_content.indexOf("_httpdocimg_")!=-1) {
707// String top_doc_id = OID.getTop(doc_id);
708// info = this.gdbm_src.getInfo(top_doc_id);
709// if (info == null) {
710// // perhaps we had per.iods in the ids - just try the current id
711// top_doc_id = doc_id;
712// info = this.gdbm_src.getInfo(top_doc_id);
713// }
714// if (info != null) {
715// String archivedir = info.getInfo("archivedir");
716// String image_dir = this.site_http_address + "/collect/"+this.cluster_name+"/index/assoc/"+archivedir;
717
718// // Resolve all "_httpdocimg_"s
719// doc_content = doc_content.replaceAll("_httpdocimg_", image_dir);
720// }
721// }
722// // resolve any collection specific macros
723// doc_content = macro_resolver.resolve(doc_content, lang, GS2MacroResolver.SCOPE_TEXT, doc_id, info);
724// return doc_content;
725// }
726
727
728}
Note: See TracBrowser for help on using the repository browser.