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

Last change on this file since 13994 was 13994, checked in by lh92, 17 years ago

Added code to read the pluginList from the collectConfig.xml. If tidy_html option is set then the tidy_option metadata is true

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