source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/CollectionGroups.java@ 38474

Last change on this file since 38474 was 38474, checked in by kjdon, 6 months ago

added in the missing backgroundImage metadata

File size: 22.4 KB
Line 
1package org.greenstone.gsdl3.service;
2
3import java.io.File;
4
5import org.apache.log4j.Logger;
6import org.greenstone.gsdl3.util.DisplayItemUtil;
7import org.greenstone.gsdl3.util.GSFile;
8import org.greenstone.gsdl3.util.GSXML;
9import org.greenstone.gsdl3.util.Request;
10import org.greenstone.gsdl3.util.UserContext;
11import org.greenstone.gsdl3.util.XMLConverter;
12import org.w3c.dom.Document;
13import org.w3c.dom.Element;
14import org.w3c.dom.Node;
15import org.w3c.dom.NodeList;
16
17import java.util.Set;
18
19import javax.xml.xpath.XPathConstants;
20import javax.xml.xpath.XPathExpression;
21import javax.xml.xpath.XPathExpressionException;
22import javax.xml.xpath.XPathFactory;
23
24import java.util.HashSet;
25import java.util.HashMap;
26import java.util.Iterator;
27
28public class CollectionGroups extends ServiceRack {
29
30 private Element hierarchy = null;
31 private Element groupDesc = null;
32 private HashMap<String, Element> group_descriptions_map = null; // new one for display items
33
34 public static final String GROUP_CONTENT_SERVICE = "GroupCurrentContent";
35 // not used??
36 public static final String UNIQUE_COLLECTIONS_SERVICE = "UniqueCollections";
37 // not used??
38 public static final String COLLECTIONS_HIERARCHY_SERVICE = "CollectionsHierarchy";
39// hack, should be getting this from library servlet
40 private static final String DEFAULT_LANG = "en";
41 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.CollectionGroups.class.getName());
42
43 @Override
44 protected Element getServiceDescription(Document doc, String service, String lang, String subset) {
45 // TODO Auto-generated method stub
46 return null;
47 }
48
49 String[] _services = { GROUP_CONTENT_SERVICE, UNIQUE_COLLECTIONS_SERVICE, COLLECTIONS_HIERARCHY_SERVICE };
50
51 public boolean configure(Element info, Element extra_info) {
52 if (!super.configure(info, extra_info)) {
53 return false;
54 }
55
56 group_descriptions_map = new HashMap<String, Element>();
57 logger.info("Configuring CollectionGroups...");
58 this.config_info = info;
59
60 for (int i = 0; i < _services.length; i++) {
61 Element service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
62 service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_GROUPINFO);
63 service.setAttribute(GSXML.NAME_ATT, _services[i]);
64 this.short_service_info.appendChild(service);
65 }
66 // Load group configuration from file
67 return readGroupConfiguration();
68 }
69
70 protected Element processGroupCurrentContent(Element request) {
71
72 Document doc = XMLConverter.newDOM();
73 UserContext userContext = new UserContext(request);
74
75 // Prepare basic response
76 Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO);
77
78 String lang = request.getAttribute(GSXML.LANG_ATT);
79 // Get param list from request
80 Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
81 // Set default group path (main page)
82 String groupPath = "";
83 // If param list not null and group param exists extract value and
84 // override groupPath variable
85 if (paramList != null) {
86 Element paramGroup = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.GROUP_ELEM);
87 if (paramGroup != null) {
88 groupPath = paramGroup.getAttribute(GSXML.VALUE_ATT);
89 }
90 }
91 //Remove leading, ending / and duplicated /
92 groupPath = groupPath.replaceAll("(/+)", "/");
93 groupPath = groupPath.replaceAll("(^/+)|(/+$)", "");
94
95 Element mrCollectionList = getAvailableCollectionList(userContext);
96 if (mrCollectionList == null){
97 result.appendChild(doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER));
98 return result;
99 }
100 //Get current groups and collections
101 Element groupContent = getRawCurrentContent(groupPath);
102
103 //Get ungrouped collection list
104 Element ungroupedCollections = getUngroupedCollections(mrCollectionList);
105
106 // If groupContent is empty return empty collection list
107 if (groupContent == null) {
108 result.appendChild(doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER));
109 return result;
110 }
111 NodeList currentContent = groupContent.getChildNodes();
112 if (currentContent != null && currentContent.getLength() > 0) {
113 // Create CollectionList element in response
114 Element result_collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
115 result.appendChild(result_collection_list);
116 Element result_group_list = doc.createElement(GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER);
117 result.appendChild(result_group_list);
118 // Iterate over collections from current view
119 // i represents current position in groupConfig.xml
120 int i;
121 for (i=0; i < currentContent.getLength(); i++) {
122 //logger.warn("NODE CuR Content" + GSXML.xmlNodeToString(currentContent.item(i)));
123
124 if (currentContent.item(i).getNodeName() == GSXML.COLLECTION_ELEM) {
125
126 Element collection = (Element) currentContent.item(i);
127 String collection_name = collection.getAttribute(GSXML.NAME_ATT);
128 // Check whether collection from current view exists in message router response
129 Element checkedCollection = GSXML.getNamedElement(mrCollectionList, GSXML.COLLECTION_ELEM,GSXML.NAME_ATT, collection_name);
130 if (checkedCollection != null) {
131 //Set position value
132 checkedCollection.setAttribute(GSXML.POSITION_ATT, String.valueOf(i));
133 // Add collection to response
134 result_collection_list.appendChild(doc.importNode(checkedCollection, true));
135 }
136
137 //Iterate over groups in current view
138 } else if (currentContent.item(i).getNodeName() == GSXML.GROUP_ELEM) {
139 Element currentGroup = (Element) currentContent.item(i);
140 String currentGroupName = currentGroup.getAttribute(GSXML.NAME_ATT);
141 Element groupDescription = getGroupDescription(doc, currentGroupName, lang);
142
143 groupDescription.setAttribute(GSXML.POSITION_ATT, String.valueOf(i));
144 result_group_list.appendChild(doc.importNode(groupDescription, true));
145 }
146
147 }
148 //Add ungrouped collections if groupPath /+ or "" or null
149 if (groupPath.isEmpty()) {
150
151 //Add each ungrouped collection to the collection list in loop
152 NodeList ungroupedCollectionNodes = GSXML.getChildrenByTagName(ungroupedCollections, GSXML.COLLECTION_ATT);
153 if (ungroupedCollectionNodes != null) {
154 for (int j = 0; j < ungroupedCollectionNodes.getLength(); j++) {
155 //logger.warn("UNGROUPED COLL ELEM" + GSXML.xmlNodeToString(ungroupedCollections).intern());
156 Element ungroupedCollection = (Element) doc.importNode(ungroupedCollectionNodes.item(j), true);
157 ungroupedCollection.setAttribute(GSXML.POSITION_ATT, String.valueOf(i++));
158 result_collection_list.appendChild(ungroupedCollection);
159 }
160 }
161
162 } else {
163 Element groupDescription = getPathInfo(groupPath, lang);
164 if (groupContent != null){
165 result.appendChild(doc.importNode(groupDescription, true));
166 }
167 }
168 }
169
170 return result;
171 }
172
173 protected Element processUniqueCollections(Element request) {
174 Document doc = XMLConverter.newDOM();
175 UserContext userContext = new UserContext(request);
176 // Prepare basic response
177 Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO);
178 Element resultCollections = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
179 result.appendChild(resultCollections);
180 Element mrCollectionList = getAvailableCollectionList(userContext);
181 //Collections from message router check
182 if (mrCollectionList == null){
183 logger.error("mrCollectionList is null!");
184 return result;
185 }
186 //paramList check
187 Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
188 if (paramList == null) {
189 logger.error("UniqueCollections request had no paramList.");
190 return result;
191 }
192 //Add collections from request
193 Set<String> uniq_colls = new HashSet<String>();
194 Element collParam = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.COLLECTION_ELEM);
195 if (collParam != null){
196 String colls = GSXML.getValue(collParam);
197 if (!colls.isEmpty())
198 {
199 String[] _colls = colls.split(",");
200 for (int i=0;i < _colls.length;i++){
201 uniq_colls.add(_colls[i]);
202 }
203 }
204 }
205 //groupParam check
206 Element groupParam = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.GROUP_ELEM);
207 if (groupParam == null) {
208 logger.error("UniqueCollections request had no groupParam.");
209 return result;
210 }
211 //Add collections from groups
212 String[] groups = null;
213 groups = GSXML.getValue(groupParam).split(",");
214 for (int i = 0; i < groups.length; i++) {
215 if (!groups[i].isEmpty()) {
216 Element groupContent = getRawCurrentContent(groups[i]);
217 // If group exists
218 if (groupContent != null) {
219 NodeList collectionNodes = groupContent.getElementsByTagName(GSXML.COLLECTION_ELEM);
220 for (int j = 0; j < collectionNodes.getLength(); j++) {
221 String collName = ((Element) collectionNodes.item(j)).getAttribute(GSXML.NAME_ATT);
222 uniq_colls.add(collName);
223 }
224 }
225 }
226
227 }
228 //Fill result collectionList
229 for (Iterator<String> iterator = uniq_colls.iterator(); iterator.hasNext();) {
230 String collectionName = (String) iterator.next();
231 Element checkedCollection = GSXML.getNamedElement(mrCollectionList, GSXML.COLLECTION_ELEM,GSXML.NAME_ATT, collectionName);
232 if (checkedCollection != null){
233 resultCollections.appendChild(doc.importNode(checkedCollection, true));
234 }
235 }
236 return result;
237
238 }
239
240 protected Element processCollectionsHierarchy(Element request){
241
242 Document doc = XMLConverter.newDOM();
243 UserContext userContext = new UserContext(request);
244 String lang = request.getAttribute(GSXML.LANG_ATT);
245 // Prepare basic response
246 Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO);
247 String currentPath = "";
248 Element currentContent = getRawCurrentContent(currentPath);
249 if (currentContent == null){
250 return result;
251 }
252 Element searchableCollectionList = getSearchableCollectionList(userContext);
253 if (searchableCollectionList == null){
254 return result;
255 }
256
257 //Get ungrouped collection list
258 sanitizeCurrentContent(currentContent, searchableCollectionList);
259 addGroupInfo(currentContent, currentPath, lang);
260 addUngroupedCollections(currentContent, searchableCollectionList);
261 addAllOption(currentContent);
262 result.appendChild(doc.importNode(currentContent, true));
263 return result;
264 }
265
266 private void addAllOption(Element currentContent) {
267 if (currentContent == null){
268 return;
269 }
270 Document doc = currentContent.getOwnerDocument();
271 Element allOption = doc.createElement(GSXML.COLLECTION_ELEM);
272 allOption.setAttribute(GSXML.NAME_ATT, "all");
273 if (currentContent.hasChildNodes()){
274 currentContent.insertBefore(allOption,currentContent.getFirstChild());
275 } else
276 currentContent.appendChild(allOption);
277
278
279 }
280
281 private void addGroupInfo(Element currentContent, String groupPath, String lang) {
282 NodeList groups = GSXML.getChildrenByTagName(currentContent,GSXML.GROUP_ELEM);
283 Document doc = currentContent.getOwnerDocument();
284 for (int i=0;i<groups.getLength();i++){
285 Element group = (Element) groups.item(i);
286 String name = group.getAttribute(GSXML.NAME_ATT);
287 String newPath = groupPath + "/" + name;
288 group.setAttribute(GSXML.PATH_ATT, newPath);
289 Element groupDescription = getGroupDescription(doc, name, lang);
290 Element titleEl = (Element) GSXML.getChildByTagName(groupDescription, GSXML.TITLE_ELEM);
291 String title;
292 if (titleEl != null) {
293 title = titleEl.getTextContent();
294 } else {
295 title = name;
296 }
297 group.setAttribute(GSXML.TITLE_ELEM, title );
298 addGroupInfo(group, newPath, lang);
299 }
300
301 }
302
303 private Element getRawCurrentContent(String path) {
304
305 if (path == null) {
306 path = "";
307 }
308
309 Document doc = XMLConverter.newDOM();
310 path = path.replaceAll("(/+)", "/");
311 path = path.replaceAll("(^/+)|(/+$)", "");
312
313 String[] pathSteps = path.split("/");
314
315
316 Element currentContent = (Element) hierarchy.cloneNode(true);
317 // Get the current view
318 for (int i = 0; i < pathSteps.length; i++) {
319 if (!pathSteps[i].isEmpty()) {
320 currentContent = GSXML.getNamedElement(currentContent, GSXML.GROUP_ELEM, GSXML.NAME_ATT, pathSteps[i]);
321 if (currentContent == null){
322 break;
323 }
324 }
325 }
326 if (currentContent == null || !currentContent.hasChildNodes()) {
327 // Return to the main page
328 return null;
329 }
330 return currentContent;
331 }
332
333 private void sanitizeCurrentContent(Element currentContent, Element checkedCollectionList){
334 if (currentContent == null){
335 return;
336 }
337 NodeList nodes = currentContent.getElementsByTagName(GSXML.COLLECTION_ELEM);
338 for (int i = 0; i < nodes.getLength(); i++) {
339 Element element = (Element) nodes.item(i);
340 String name = element.getAttribute(GSXML.NAME_ATT);
341 Element checkedCollection = GSXML.getNamedElement(checkedCollectionList, GSXML.COLLECTION_ELEM, GSXML.NAME_ATT, name);
342 if (checkedCollection == null) {
343 element.getParentNode().removeChild(element);
344 i--;
345 }
346 }
347 }
348
349 private void addUngroupedCollections(Element currentContent, Element availableCollections){
350 if (currentContent == null){
351 return;
352 }
353 Document doc = currentContent.getOwnerDocument();
354 NodeList collectionList = availableCollections.getElementsByTagName(GSXML.COLLECTION_ELEM);
355 for (int i = 0; i < collectionList.getLength();i++){
356 Element collection = (Element) collectionList.item(i);
357 String name = collection.getAttribute(GSXML.NAME_ATT);
358 NodeList foundCollection = GSXML.getNamedElements(currentContent, GSXML.COLLECTION_ELEM, GSXML.NAME_ATT, name);
359 if (foundCollection.getLength() == 0){
360 Element ungroupedCollection = doc.createElement(GSXML.COLLECTION_ELEM);
361 ungroupedCollection.setAttribute(GSXML.NAME_ATT, name);
362 currentContent.appendChild(ungroupedCollection);
363 }
364 }
365
366 }
367
368 private boolean readGroupConfiguration() {
369
370 File configFile = new File(GSFile.groupConfigFile(site_home));
371 //
372 if (!configFile.exists()) {
373 logger.info("Groups config file " + configFile.getPath() + " does not exist.");
374 return false;
375 }
376 Document doc;
377 Element content;
378 try {
379 doc = XMLConverter.getDOM(configFile);
380 content = doc.getDocumentElement();
381 } catch (Exception e) {
382 System.out.println(e.getClass());
383 e.printStackTrace();
384 return false;
385 }
386 // XPath to find empty text nodes.
387 try {
388 XPathFactory xpathFactory = XPathFactory.newInstance();
389 XPathExpression xpathExp = xpathFactory.newXPath().compile("//text()[normalize-space(.) = '']");
390 NodeList emptyTextNodes = (NodeList) xpathExp.evaluate(doc, XPathConstants.NODESET);
391 for (int i = 0; i < emptyTextNodes.getLength(); i++) {
392 Node emptyTextNode = emptyTextNodes.item(i);
393 emptyTextNode.getParentNode().removeChild(emptyTextNode);
394 }
395
396 } catch (XPathExpressionException e) {
397 logger.error("Error occurred while trying to remove emtpy nodes from groupConfig.xml");
398 e.printStackTrace();
399 return false;
400 }
401
402 hierarchy = (Element) GSXML.getChildByTagName(content, GSXML.HIERARCHY_ELEM);
403 groupDesc = (Element) GSXML.getChildByTagName(content, GSXML.GROUP_DESC_ELEM);
404 if (hierarchy == null){
405 logger.error("<groupConfig> has no <hierarchy> element, ignoring it.");
406 return false;
407 }
408 verifyGroupDescription(doc);
409 return true;
410 }
411
412 private void verifyGroupDescription(Document doc) {
413 if (groupDesc == null) {
414 // we set up one for ourselves
415 groupDesc = doc.createElement(GSXML.GROUP_DESC_ELEM);
416 }
417
418 // Document doc = groupDesc.getOwnerDocument();
419 NodeList groups = hierarchy.getElementsByTagName(GSXML.GROUP_ELEM);
420 for (int i = 0; i < groups.getLength(); i++) {
421 Element group = (Element) groups.item(i);
422 String name = group.getAttribute(GSXML.NAME_ATT);
423 Element foundDescription = GSXML.getNamedElement(groupDesc, GSXML.GROUP_ELEM, GSXML.NAME_ATT, name);
424 if (foundDescription == null){
425 Element defaultDescription = doc.createElement(GSXML.GROUP_ELEM);
426 defaultDescription.setAttribute(GSXML.NAME_ATT, name);
427 Element groupTitle = doc.createElement(GSXML.TITLE_ELEM);
428 groupTitle.setTextContent(name);
429 defaultDescription.appendChild(groupTitle);
430
431 Element titleDisplayItem = DisplayItemUtil.createDisplayItem(doc, GSXML.DISPLAY_TEXT_NAME, DEFAULT_LANG, name);
432 defaultDescription.appendChild(titleDisplayItem);
433 groupDesc.appendChild(defaultDescription);
434 }
435 Element this_di_list = doc.createElement("dummy");
436 DisplayItemUtil.storeDisplayItems(this_di_list, foundDescription);
437 group_descriptions_map.put(name, this_di_list);
438 }
439
440 }
441
442 private Element getGroupDescriptionOld(String name) {
443 Element description = (Element) GSXML.getNamedElement(groupDesc, GSXML.GROUP_ELEM, GSXML.NAME_ATT, name);
444 if (description == null) {
445 logger.error("GroupDescription is not defined. Check your groupConfig.xml");
446 }
447 return description;
448 }
449 private Element getGroupDescription(Document doc, String name, String lang) {
450 // get all the display items for group
451 Element all_di = group_descriptions_map.get(name);
452 Element new_di_list = doc.createElement(GSXML.GROUP_ELEM);
453 new_di_list.setAttribute(GSXML.NAME_ATT, name);
454 DisplayItemUtil.addLanguageSpecificDisplayItems(new_di_list, all_di, lang, DEFAULT_LANG, this.class_loader);
455
456 // now merge in the old style metadata - to be backwards compatible
457 Element old_style_desc = (Element) GSXML.getNamedElement(groupDesc, GSXML.GROUP_ELEM, GSXML.NAME_ATT, name);
458 if (old_style_desc != null) {
459 Element meta = (Element)GSXML.getChildByTagName(old_style_desc, "title");
460 if (meta != null) {
461 new_di_list.appendChild(doc.importNode(meta, true));
462 }
463 meta = (Element)GSXML.getChildByTagName(old_style_desc, "description");
464 if (meta != null) {
465 new_di_list.appendChild(doc.importNode(meta, true));
466 }
467 meta = (Element)GSXML.getChildByTagName(old_style_desc, "shortDescription");
468 if (meta != null) {
469 new_di_list.appendChild(doc.importNode(meta, true));
470 }
471
472 meta = (Element)GSXML.getChildByTagName(old_style_desc, "backgroundImage");
473 if (meta != null) {
474 new_di_list.appendChild(doc.importNode(meta, true));
475 }
476 }
477 return new_di_list;
478
479 }
480
481 private Element getUngroupedCollections(Element mr_collection_list) {
482
483 Document doc = XMLConverter.newDOM();
484 // Create Set
485 Set<String> hierarchy_unique_collections = new HashSet<String>();
486 // Element hierarchyCollections = doc.createElement("coll_list");
487 // Get collection nodes
488
489 NodeList hierarchy_all_collection_list = hierarchy.getElementsByTagName(GSXML.COLLECTION_ELEM);
490 // Save hierarchy collection names to Hashset
491 for (int i = 0; i < hierarchy_all_collection_list.getLength(); i++) {
492 Element collection_element = (Element) hierarchy_all_collection_list.item(i);
493 hierarchy_unique_collections.add(collection_element.getAttribute(GSXML.NAME_ATT));
494 }
495 // Save available by message router collection names to Hashset
496 Set<String> mr_collections = new HashSet<String>();
497 NodeList mr_coll_list = mr_collection_list.getElementsByTagName(GSXML.COLLECTION_ELEM);
498
499 for (int i = 0; i < mr_coll_list.getLength(); i++) {
500 Element collection_element = (Element) mr_coll_list.item(i);
501 mr_collections.add(collection_element.getAttribute(GSXML.NAME_ATT));
502 }
503 //Save collections available by message router and not existed in hierarchy to ungrouped collections set
504 Set<String> ungrouped_collections = new HashSet<String>();
505 for (String string : mr_collections) {
506 if (!hierarchy_unique_collections.contains(string)){
507 ungrouped_collections.add(string);
508 }
509 }
510 //Output
511 Element result = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
512 for (String name : ungrouped_collections) {
513 Element collection = doc.createElement(GSXML.COLLECTION_ELEM);
514 collection.setAttribute(GSXML.NAME_ATT, name);
515 result.appendChild(collection);
516 }
517 return result;
518
519 }
520 private Element getPathInfo(String path, String lang) {
521
522 Document doc = XMLConverter.newDOM();
523
524 if (path == null) {
525 path = "";
526 }
527 String[] pathSteps = path.split("/");
528
529 Element pathInfo = doc.createElement(GSXML.PATH_ELEM + GSXML.LIST_MODIFIER);
530
531 String currentPath = "";
532 boolean first = true;
533 for (int i = 0; i < pathSteps.length; i++) {
534 if (!pathSteps[i].isEmpty()) {
535 if (first) {
536 first = false;
537 } else {
538 currentPath += "/";
539 }
540 currentPath += pathSteps[i];
541 Element pathStepDescription = getGroupDescription(doc, pathSteps[i], lang);
542 if (pathStepDescription != null){
543 pathStepDescription.setAttribute(GSXML.POSITION_ATT, String.valueOf(i));
544 pathStepDescription.setAttribute(GSXML.PATH_ATT, currentPath);
545 }
546 pathInfo.appendChild(doc.importNode(pathStepDescription, true));
547 }
548 }
549
550 return pathInfo;
551 }
552 private Element getAvailableCollectionList(UserContext userContext){
553 Document doc = XMLConverter.newDOM();
554 // Get the message router info
555 Element inforesponseMessage = new Request(doc, userContext, router, GSXML.REQUEST_TYPE_DESCRIBE).send();
556 if (inforesponseMessage == null) {
557 logger.error(" couldn't query the message router!");
558 return null;
559 }
560 Element mr_info_response = (Element) GSXML.getChildByTagName(inforesponseMessage, GSXML.RESPONSE_ELEM);
561 if (mr_info_response == null) {
562 logger.error("Message router response is null!");
563 return null;
564 }
565
566 Element mr_collection_list = (Element) GSXML.getChildByTagName(mr_info_response, GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
567
568 return mr_collection_list;
569 }
570 private Element getSearchableCollectionList(UserContext userContext){
571 Document doc = XMLConverter.newDOM();
572 Element collectionList = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
573 // Get the message router info
574 Element mr_info_message = doc.createElement(GSXML.MESSAGE_ELEM);
575 Element mr_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "TextQuery" , userContext);
576 mr_info_message.appendChild(mr_request);
577 Element mr_info_response_message = (Element) this.router.process(mr_info_message);
578 if (mr_info_response_message == null) {
579 logger.error(" couldn't query the message router!");
580 return null;
581 }
582 NodeList options = mr_info_response_message.getElementsByTagName(GSXML.PARAM_OPTION_ELEM);
583 for (int i = 0; i < options.getLength(); i++) {
584 Element option = (Element) options.item(i);
585 String name = option.getAttribute(GSXML.NAME_ATT);
586 if (name.equals("all")){
587 continue;
588 }
589 Element collection = doc.createElement(GSXML.COLLECTION_ELEM);
590 collection.setAttribute(GSXML.NAME_ATT, name);
591 collectionList.appendChild(collection);
592 }
593 return collectionList;
594 }
595}
Note: See TracBrowser for help on using the repository browser.