source: greenstone3/trunk/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java@ 14640

Last change on this file since 14640 was 14640, checked in by anna, 17 years ago

Added the buildType of a collection to its description, to generate ct param.

  • Property svn:keywords set to Author Date Id Revision
File size: 24.2 KB
Line 
1/*
2 * ServiceCluster.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 */
19// leave the package name as is for now - should be changed to something better
20// cluster? groups?
21package org.greenstone.gsdl3.collection;
22
23
24import org.greenstone.gsdl3.util.*;
25import org.greenstone.gsdl3.core.*;
26import org.greenstone.gsdl3.service.*;
27
28// java XML classes we're using
29import org.w3c.dom.Document;
30import org.w3c.dom.Node;
31import org.w3c.dom.Element;
32import org.w3c.dom.NodeList;
33
34import java.io.File;
35import java.util.HashMap;
36import java.util.Iterator;
37
38import org.apache.log4j.*;
39
40/* ServiceCluster - a groups of services that are related in some way
41 * Implements ModuleInterface. Contains a list of services provided by the cluster, along with metadata about the cluster itself.
42 * a collection is a special type of cluster
43 * @author <a href="mailto:[email protected]">Katherine Don</a>
44 * @version $Revision: 14640 $
45 * @see ModuleInterface
46 */
47public class ServiceCluster
48 implements ModuleInterface {
49
50 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.collection.ServiceCluster.class.getName());
51
52 protected static final String CONFIG_ENCODING = "utf-8";
53
54 protected static final String DEFAULT_LANG = "en"; // hack for now, should be read from the coll cfg file? or site cfg file for cluster
55
56 /** base directory for the site that this cluster belongs to*/
57 protected String site_home = null;
58 /** http address of the site that this cluster belongs to */
59 protected String site_http_address = null;
60 /** The name of the cluster - for a collection, this is the collection name*/
61 protected String cluster_name = null;
62 /** collection type : mg or mgpp */
63 protected String col_type = "";
64
65 /** a reference to the message router */
66 protected MessageRouter router = null;
67 /** The map of services.
68 *
69 * Maps Services to ServiceRack objects
70 * @see ServiceRack
71 *
72 */
73 protected HashMap service_map=null;
74 /** maps pseudo service names to real service names - needed if we have two services with the same name for one collection */
75 protected HashMap service_name_map=null;
76
77 /** XML converter for String to DOM and vice versa */
78 protected XMLConverter converter=null;
79
80 /** container doc for description elements */
81 protected Document doc = null;
82 /** list of services */
83 protected Element service_list = null;
84 /** list of metadata - all metadata, regardless of language goes in here */
85 protected Element metadata_list = null;
86 /** language specific stuff */
87 //protected Element lang_specific_metadata_list = null;
88 protected Element display_item_list = null;
89 /** the element that will have any descriptions passed back in */
90 protected Element description = null;
91
92 /** list of plugin */
93 protected Element plugin_item_list = null;
94
95 public void setSiteHome(String home) {
96 this.site_home = home;
97 }
98
99 public void setSiteAddress(String address) {
100 this.site_http_address = address;
101 }
102
103 public void cleanUp() {
104 Iterator i = this.service_map.values().iterator();
105 while (i.hasNext()) {
106 ServiceRack s = (ServiceRack)i.next();
107 s.cleanUp();
108 }
109 }
110 public void setClusterName(String name) {
111 this.cluster_name = name;
112 this.description.setAttribute(GSXML.NAME_ATT, name);
113 }
114
115 public void setMessageRouter(MessageRouter m) {
116 this.router = m;
117 }
118
119 public ServiceCluster() {
120 this.service_map = new HashMap();
121 this.service_name_map = new HashMap();
122 this.converter = new XMLConverter();
123 this.doc = this.converter.newDOM();
124 this.description = this.doc.createElement(GSXML.CLUSTER_ELEM);
125 this.display_item_list = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
126 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
127 this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
128 }
129
130 /**
131 * Configures the cluster.
132 *
133 * gsdlHome and clusterName must be set before configure is called.
134 *
135 * reads the site configuration file, and configures itself
136 * this calls configure(Element) with the XML element node from the config
137 * file.
138 * configure(Element) should be used if the config file has already been
139 * parsed. This method will work with any subclass.
140 *
141 * @return true if configure successful, false otherwise.
142 */
143 public boolean configure() {
144
145 if (this.site_home == null || this.cluster_name== null) {
146 logger.error("site_home and cluster_name must be set before configure called!");
147 return false;
148 }
149 logger.info("configuring service cluster");
150 // read the site configuration file
151 File config_file = new File(GSFile.siteConfigFile(this.site_home));
152
153 if (!config_file.exists()) {
154 logger.error("couldn't configure cluster: "+this.cluster_name +", "+config_file+" does not exist");
155 return false;
156 }
157
158 Document doc = this.converter.getDOM(config_file, CONFIG_ENCODING);
159 if (doc == null) {
160 logger.error("couldn't parse config file "+config_file.getPath());
161 return false;
162 }
163
164 // get the appropriate service cluster element
165 Element cluster_list = (Element)GSXML.getChildByTagName(doc.getDocumentElement(), GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);
166 Element sc = GSXML.getNamedElement(cluster_list, GSXML.CLUSTER_ELEM,
167 GSXML.NAME_ATT, this.cluster_name);
168
169 return this.configure(sc);
170 }
171
172
173 public boolean configure(Element service_cluster_info) {
174
175 // get the metadata - for now just add it to the list
176 Element meta_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
177 if (meta_list !=null) {
178 if (!addMetadata(meta_list)) {
179
180 logger.error(" couldn't configure the metadata");
181 }
182 }
183
184 // get the display info
185 Element display_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
186 if (display_list !=null) {
187 if (!addDisplayItems(display_list)) {
188
189 logger.error("couldn't configure the display items");
190 }
191 }
192
193 //get the plugin info
194 Element import_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.IMPORT_ELEM);
195 if (import_list != null)
196 {
197 Element plugin_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
198 if (plugin_list !=null) {
199 if (!addPlugins(plugin_list)) {
200
201 logger.error("couldn't configure the plugins");
202 }
203 }
204 }
205
206 // do the service racks
207 Element service_rack_list = (Element)GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
208 if (service_rack_list == null) {
209 // is this an error? could you ever have a service cluster
210 // without service racks???
211 logger.error("cluster has no service racks!!");
212 } else {
213
214 if (!configureServiceRack(service_rack_list, null)) {
215 logger.error("couldn't configure the service racks!!");
216 return false;
217 }
218 }
219
220 return true;
221 }
222
223 /** adds metadata from a metadataList into the metadata_list xml
224 */
225 protected boolean addMetadata(Element metadata_list) {
226 if (metadata_list == null) return false;
227 NodeList metanodes = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM);
228 if (metanodes.getLength()>0) {
229 for(int k=0; k<metanodes.getLength(); k++) {
230 this.metadata_list.appendChild(this.doc.importNode(metanodes.item(k), true));
231 }
232 }
233
234 return true;
235 }
236
237 protected boolean addDisplayItems(Element display_list) {
238
239 if (display_list==null) return false;
240 NodeList displaynodes = display_list.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
241 if (displaynodes.getLength()>0) {
242 for(int k=0; k<displaynodes.getLength(); k++) {
243 Element d = (Element) displaynodes.item(k);
244 String lang = d.getAttribute(GSXML.LANG_ATT);
245 if (lang==null||lang.equals("")) {
246 //set the lang to teh default
247 d.setAttribute(GSXML.LANG_ATT, DEFAULT_LANG);
248 }
249 String name = d.getAttribute(GSXML.NAME_ATT);
250 Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, name);
251 if (this_item==null) {
252 this_item = this.doc.createElement(GSXML.DISPLAY_TEXT_ELEM);
253 this_item.setAttribute(GSXML.NAME_ATT, name);
254 this.display_item_list.appendChild(this_item);
255 }
256
257 this_item.appendChild(this.doc.importNode(d, true));
258 }
259 }
260
261 return true;
262 }
263
264 protected boolean addPlugins(Element plugin_list) {
265 if (plugin_list == null) return false;
266 NodeList pluginNodes = plugin_list.getElementsByTagName(GSXML.PLUGIN_ELEM);
267 if (pluginNodes.getLength() > 0) {
268 for (int k = 0; k < pluginNodes.getLength(); k++)
269 {
270 this.plugin_item_list.appendChild(this.doc.importNode(pluginNodes.item(k), true));
271 }
272 }
273
274 return true;
275 }
276
277 /** creates and configures all the services - extra_info is some more xml
278that is passed to teh service - eg used for coll config files for Collection
279 */
280 protected boolean configureServiceRack(Element service_rack_list,
281 Element extra_info) {
282
283 // empty the service map in case this is a reconfigure
284 service_map.clear();
285 this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
286
287 // create all the services
288 NodeList nodes = service_rack_list.getElementsByTagName(GSXML.SERVICE_CLASS_ELEM);
289 if (nodes.getLength()==0) {
290 logger.error("ServiceCluster configuration error: cluster "+this.cluster_name+" has no service modules!");
291 return false;
292 }
293
294 for(int i=0; i<nodes.getLength(); i++) {
295
296 // the xml request to send to the serviceRack to query what
297 // services it provides
298 Element message = this.doc.createElement(GSXML.MESSAGE_ELEM);
299 Element request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", "", "");
300 message.appendChild(request);
301
302 Element n = (Element)nodes.item(i);
303 String servicetype = n.getAttribute(GSXML.NAME_ATT);
304
305 ServiceRack s = null;
306
307 try {
308 // try for a default service in standard package
309 s = (ServiceRack)Class.forName("org.greenstone.gsdl3.service."+servicetype).newInstance();
310
311 } catch (Exception e) {}
312 if (s == null) {
313 try {
314 // name as is, in case package is already specified
315 s = (ServiceRack)Class.forName(servicetype).newInstance();
316 } catch (Exception e) {}
317 }
318
319 if (s == null) {
320 logger.error("Couldn't get an instance of class "+servicetype+", or org.greenstone.gsdl3.service."+servicetype);
321 continue;
322 }
323
324
325 s.setSiteHome(this.site_home);
326 s.setSiteAddress(this.site_http_address);
327 s.setClusterName(this.cluster_name);
328 s.setMessageRouter(this.router);
329 // pass the xml node to the service for configuration
330 if (s.configure(n, extra_info)) {
331
332 // find out the supported service types for this service module
333 Node types = s.process(message);
334 NodeList typenodes = ((Element)types).getElementsByTagName(GSXML.SERVICE_ELEM);
335
336 for (int j=0; j<typenodes.getLength();j++) {
337 String service = ((Element) typenodes.item(j)).getAttribute(GSXML.NAME_ATT);
338 if (service_map.get(service)!=null) {
339 char extra = '0';
340 String new_service = service+extra;
341
342 while (service_map.get(new_service)!=null) {
343 extra++;
344 new_service = service+extra;
345 }
346 this.service_name_map.put(new_service, service);
347 service=new_service;
348 ((Element) typenodes.item(j)).setAttribute(GSXML.NAME_ATT, service);
349 }
350 this.service_map.put(service, s);
351 // also add info to the ServiceInfo XML element
352 this.service_list.appendChild(this.doc.importNode(typenodes.item(j), true));
353 }
354 }
355 }
356
357 return true;
358
359
360 }
361
362
363 /**
364 * Process an XML document - uses Strings
365 * just calls process(Node).
366 *
367 * @param in the Document to process - a string
368 * @return the resultant document as a string - contains any error messages
369 * @see String
370 */
371 public String process(String in) {
372
373 Document doc = this.converter.getDOM(in);
374 Element e = doc.getDocumentElement();
375
376 Element res = process(e);
377 return this.converter.getString(res);
378
379 }
380
381 /** process XML as Node
382 *
383 */
384 public Element process(Element message) {
385
386 NodeList requests = message.getElementsByTagName(GSXML.REQUEST_ELEM);
387 Document mess_doc = message.getOwnerDocument();
388 Element mainResult = this.doc.createElement(GSXML.MESSAGE_ELEM);
389 if (requests.getLength()==0) {
390 logger.error("no requests for cluster:"+this.cluster_name);
391 // no requests
392 return mainResult; // for now
393 }
394 for (int i=0; i<requests.getLength(); i++) {
395 Element request = (Element)requests.item(i);
396 String to = request.getAttribute(GSXML.TO_ATT);
397
398 // the cluster name should be first, check, then remove
399 String clustername = GSPath.getFirstLink(to);
400 if (!clustername.equals(this.cluster_name)){
401 logger.error("cluster name wrong! was "+clustername+" should have been "+this.cluster_name);
402 continue; // ignore this request
403 }
404 to = GSPath.removeFirstLink(to);
405 request.setAttribute(GSXML.TO_ATT, to);
406
407 if (to.equals("")) { // this command is for me
408 Element response = processMessage(request);
409 mainResult.appendChild(response);
410
411 } else { // the request is for one of my services
412 String service = GSPath.getFirstLink(to);
413
414 if (!this.service_map.containsKey(service)) {
415 logger.error("non-existant service, "+service+", specified!");
416 continue;
417 }
418 String real_service = service;
419 if (this.service_name_map.containsKey(service)) {
420 real_service = (String)this.service_name_map.get(service);
421 // need to change the to att in the request - give the real service name
422 to = request.getAttribute(GSXML.TO_ATT);
423 String old_to = to;
424 to = GSPath.replaceFirstLink(to, real_service);
425 request.setAttribute(GSXML.TO_ATT, to);
426 }
427 // have to pass the request to the service
428 Element single_message = mess_doc.createElement(GSXML.MESSAGE_ELEM);
429 single_message.appendChild(request);
430 Element response_message = ((ModuleInterface)this.service_map.get(service)).process(single_message);
431 if (response_message != null) {
432 Element response = (Element) GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM);
433 String from = response.getAttribute(GSXML.FROM_ATT);
434 if (!real_service.equals(service)) {
435 // replace the real service name with the pseudo service name
436 from = GSPath.replaceFirstLink(from, service);
437 // also need to do it in the service itself
438 // shoudl this be done here??
439 Element service_elem = (Element) GSXML.getChildByTagName(response, GSXML.SERVICE_ELEM);
440 if (service_elem!= null) {
441 service_elem.setAttribute(GSXML.NAME_ATT, service);
442 }
443 }
444 from = GSPath.prependLink(from, this.cluster_name);
445 response.setAttribute(GSXML.FROM_ATT, from);
446 mainResult.appendChild(this.doc.importNode(response, true));
447 }
448
449 } // else
450
451
452 } // for each request
453 return mainResult;
454 }
455
456 /** handles requests made to the ServiceCluster itself
457 *
458 * @param req - the request Element- <request>
459 * @return the result Element - should be <response>
460 */
461 protected Element processMessage(Element request) {
462
463 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
464 response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
465 String type = request.getAttribute(GSXML.TYPE_ATT);
466 String lang = request.getAttribute(GSXML.LANG_ATT);
467 response.setAttribute(GSXML.TYPE_ATT, type);
468
469 if (type.equals(GSXML.REQUEST_TYPE_DESCRIBE)) {
470 // create the collection element
471 Element description = (Element)this.description.cloneNode(false);
472 // set collection type : mg or mgpp
473 description.setAttribute(GSXML.TYPE_ATT, col_type);
474
475 response.appendChild(description);
476 // check the param list
477 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
478 if (param_list == null) {
479 addAllDisplayInfo(description, lang);
480 description.appendChild(this.service_list);
481 description.appendChild(this.metadata_list);
482 description.appendChild(this.plugin_item_list);
483 return response;
484 }
485
486 // go through the param list and see what components are wanted
487 NodeList params = param_list.getElementsByTagName(GSXML.PARAM_ELEM);
488 for (int i=0; i<params.getLength(); i++) {
489
490 Element param = (Element)params.item(i);
491 // Identify the structure information desired
492 if (param.getAttribute(GSXML.NAME_ATT).equals(GSXML.SUBSET_PARAM)) {
493 String info = param.getAttribute(GSXML.VALUE_ATT);
494 if (info.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
495 description.appendChild(this.service_list);
496 } else if (info.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
497 description.appendChild(metadata_list);
498 } else if (info.equals(GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER)) {
499 addAllDisplayInfo(description, lang);
500 } else if (info.equals(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER)) {
501 description.appendChild(plugin_item_list);
502 }
503 }
504 }
505 return response;
506 }
507
508 if (type.equals(GSXML.REQUEST_TYPE_SYSTEM)) {
509 response = processSystemRequest(request);
510 } else { // unknown type
511 logger.error("cant handle request of type "+ type);
512
513 }
514 return response;
515 }
516
517 protected Element processSystemRequest(Element request) {
518
519 Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
520 response.setAttribute(GSXML.FROM_ATT, this.cluster_name);
521 response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_SYSTEM);
522
523 // a list of system requests - should put any error messages
524 // or success messages into response
525 NodeList commands = request.getElementsByTagName(GSXML.SYSTEM_ELEM);
526 String message=null;
527 for (int i=0; i<commands.getLength(); i++) {
528 // all the commands should be Elements
529 Element elem = (Element)commands.item(i);
530 String action = elem.getAttribute(GSXML.TYPE_ATT);
531 if (action.equals(GSXML.SYSTEM_TYPE_CONFIGURE)) {
532 String subset = elem.getAttribute(GSXML.SYSTEM_SUBSET_ATT);
533 if (subset.equals("")) {
534 // need to reconfigure the service cluster
535
536 if (this.configure()) {
537 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " reconfigured");
538 response.appendChild(s);
539
540 } else {
541 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " could not be reconfigured");
542 response.appendChild(s);
543 }
544 } else if (this.configureSubset(subset)) {
545 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " "+subset+" reconfigured");
546 response.appendChild(s);
547 } else {
548 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, this.cluster_name + " "+subset + " could not be reconfigured");
549 response.appendChild(s);
550 }
551 continue;
552 } // configure action
553
554 String module_name = elem.getAttribute(GSXML.SYSTEM_MODULE_NAME_ATT);
555 String module_type = elem.getAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT);
556 if (action.equals(GSXML.SYSTEM_TYPE_ACTIVATE)) {
557 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, "activate action not yet implemented - does it even make sense in this context??");
558 response.appendChild(s);
559 } else if (action.equals(GSXML.SYSTEM_TYPE_DEACTIVATE)) {
560 if (module_type.equals(GSXML.SERVICE_ELEM)) {
561 // deactivate the service
562 // remove from service_map
563 this.service_map.remove(module_name);
564 Element service_elem = GSXML.getNamedElement(this.service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, module_name);
565 service_list.removeChild(service_elem);
566 message = module_type+": "+module_name+" deactivated";
567 } else {
568 message = "can't deactivate "+module_type+" type modules!";}
569 Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
570 response.appendChild(s);
571 } else {
572 logger.error("cant process system request, action "+action);
573 continue;
574 }
575 } // for each command
576 return response;
577 }
578
579 /**
580 * do a configure on only part of the collection
581 */
582 protected boolean configureSubset(String subset) {
583
584 File configFile = new File(GSFile.siteConfigFile(this.site_home));
585 if (!configFile.exists() ) {
586 logger.error("site config file: "+configFile.getPath()+" not found!");
587 // wont be able to do any of the requests
588 return false;
589
590 }
591
592 Document site_config_doc = this.converter.getDOM(configFile);
593 if (site_config_doc == null) {
594 logger.error("could not read in site config file: "+configFile.getPath());
595 return false;
596 }
597
598 Element site_config_elem = site_config_doc.getDocumentElement();
599 Element cluster_config_elem = GSXML.getNamedElement((Element)GSXML.getChildByTagName(site_config_elem, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER), GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, this.cluster_name);
600 if (cluster_config_elem == null) {
601 logger.error("site config file: "+configFile.getPath()+" has no element for cluster "+this.cluster_name);
602 // wont be able to do any of teh requests
603 return false;
604
605 }
606 if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
607 Element service_rack_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
608
609 return configureServiceRack(service_rack_list, null);
610 } else if (subset.equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
611 this.metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
612 Element metadata_list = (Element)GSXML.getChildByTagName(cluster_config_elem, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
613 return addMetadata(metadata_list);
614 } else if (subset.equals(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER)) {
615 this.plugin_item_list = this.doc.createElement(GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
616 Element import_list = (Element)GSXML.getChildByTagName(cluster_config_elem,GSXML.IMPORT_ELEM);
617 if (import_list != null)
618 {
619 Element plugin_item_list = (Element)GSXML.getChildByTagName(cluster_config_elem,GSXML.PLUGIN_ELEM+GSXML.LIST_MODIFIER);
620 return addPlugins(plugin_item_list);
621 }
622 else
623 return false;
624 } else {
625 logger.error("cannot process system request, configure "+subset);
626 return false;
627 }
628
629 }
630
631
632 protected boolean addAllDisplayInfo(Element description, String lang) {
633
634 NodeList items = this.display_item_list.getChildNodes();
635 for (int i=0; i<items.getLength(); i++) { // for each key
636 Element m = (Element) items.item(i);
637 // find the child with the correct language
638 Element new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang);
639 if (new_m==null && lang != DEFAULT_LANG) {
640 // use the default lang
641 new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG);
642 }
643 if (new_m==null) {
644 // just get the first one
645 new_m = (Element)GSXML.getChildByTagName(m, GSXML.DISPLAY_TEXT_ELEM);
646 }
647 description.appendChild(new_m.cloneNode(true));
648 }
649 return true;
650
651 }
652
653
654 protected Element getDisplayTextElement(String key, String lang) {
655
656 Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, key);
657 if (this_item == null) {
658 return null;
659 }
660
661 Element this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang);
662 if (this_lang == null && lang != DEFAULT_LANG) {
663 // try the default
664 this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG);
665 }
666 if (this_lang == null) {
667 // just return the first one
668 return GSXML.getFirstElementChild(this_item);//(Element)this_item.getFirstChild().cloneNode(true);
669 }
670 return (Element)this_lang.cloneNode(true);
671
672 }
673}
674
675
676
677
678
679
Note: See TracBrowser for help on using the repository browser.