source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java@ 25859

Last change on this file since 25859 was 25859, checked in by sjm84, 12 years ago

Adding in some useful constants

  • Property svn:keywords set to Author Date Id Revision
File size: 42.5 KB
Line 
1/*
2 * GSXML.java
3 * Copyright (C) 2008 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.util;
20
21import org.w3c.dom.NamedNodeMap;
22import org.w3c.dom.Node;
23import org.w3c.dom.Element;
24import org.w3c.dom.NodeList;
25import org.w3c.dom.Document;
26import org.w3c.dom.Text;
27
28import javax.xml.transform.TransformerFactory;
29import javax.xml.transform.Transformer;
30
31import java.io.Serializable;
32import java.io.StringWriter;
33import javax.xml.transform.stream.StreamResult;
34import javax.xml.transform.dom.DOMSource;
35import javax.xml.transform.OutputKeys;
36
37import java.util.Map;
38import java.util.Set;
39import java.util.HashMap;
40import java.util.Vector;
41import java.util.Iterator;
42import java.util.ArrayList;
43
44//import java.util.Locale;
45
46import org.apache.log4j.*;
47
48/** various functions for extracting info out of GS XML */
49public class GSXML
50{
51
52 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.GSXML.class.getName());
53
54 // greenstone message xml elements
55 public static final String MESSAGE_ELEM = "message";
56 public static final String REQUEST_ELEM = "request";
57 public static final String RESPONSE_ELEM = "response";
58 public static final String COLLECTION_ELEM = "collection";
59 public static final String SERVICE_ELEM = "service";
60 public static final String CLUSTER_ELEM = "serviceCluster";
61 public static final String SITE_ELEM = "site";
62 public static final String PARAM_ELEM = "param";
63 public static final String PARAM_OPTION_ELEM = "option";
64 public static final String CONTENT_ELEM = "content";
65 public static final String RESOURCE_ELEM = "resource";
66 public static final String DOCUMENT_ELEM = "document";
67 public static final String METADATA_ELEM = "metadata";
68 public static final String SERVICE_CLASS_ELEM = "serviceRack";
69 public static final String CLASSIFIER_ELEM = "classifier";
70 public static final String APPLET_ELEM = "applet";
71 public static final String APPLET_DATA_ELEM = "appletData";
72 public static final String CONFIGURE_ELEM = "configure";
73 public static final String STATUS_ELEM = "status";
74 public static final String ERROR_ELEM = "error";
75 public static final String DEFAULT_ELEM = "default";
76 public static final String STYLESHEET_ELEM = "format";//"stylesheet"; // any additional stylesheet stuff is carried in the message inside this elem
77 public static final String FORMAT_ELEM = "format"; // config files use format - should we use this instead of stylesheet??
78 public static final String TERM_ELEM = "term";
79 public static final String STOPWORD_ELEM = "stopword";
80 public static final String FACET_ELEM = "facet";
81 public static final String COUNT_ELEM = "count";
82 public static final String SYSTEM_ELEM = "system";
83 public static final String FORMAT_STRING_ELEM = "formatString";
84
85 //config file elems
86 public static final String COLLECTION_CONFIG_ELEM = "collectionConfig";
87 public static final String COLLECTION_BUILD_ELEM = "buildConfig";
88 public static final String COLLECTION_INIT_ELEM = "collectionInit";
89 public static final String RECOGNISE_ELEM = "recognise";
90 public static final String DOC_TYPE_ELEM = "docType";
91 public static final String SEARCH_ELEM = "search";
92 public static final String INFODB_ELEM = "infodb";
93 public static final String INDEX_ELEM = "index";
94 public static final String INDEX_STEM_ELEM = "indexStem";
95 public static final String INDEX_OPTION_ELEM = "indexOption";
96 public static final String BROWSE_ELEM = "browse";
97 public static final String DISPLAY_ELEM = "display";
98 public static final String LEVEL_ELEM = "level";
99 public static final String REPLACE_ELEM = "replace";
100
101 public static final String DBINFO_ELEM = "dbInfo";
102 public static final String DBNAME_ATT = "dbname";
103 public static final String DBPATH_ATT = "dbpath";
104 public static final String SQLSTATE_ATT = "sqlstate";
105 public static final String DATABASE_TYPE_ELEM = "databaseType";
106 public static final String SHORTNAME_ATT = "shortname";
107 public static final String NOTIFY_ELEM = "notify";
108 public static final String NOTIFY_HOST_ATT = "host";
109
110 //doc.xml file elems
111 public static final String DOCXML_SECTION_ELEM = "Section";
112 public static final String DOCXML_DESCRIPTION_ELEM = "Description";
113 public static final String DOCXML_METADATA_ELEM = "Metadata";
114 public static final String DOCXML_CONTENT_ELEM = "Content";
115
116 // elems for the pages to be processed by xslt
117 public final static String PAGE_ELEM = "page";
118 public final static String CONFIGURATION_ELEM = "config";
119 public final static String PAGE_REQUEST_ELEM = "pageRequest";
120 public final static String PAGE_RESPONSE_ELEM = "pageResponse";
121 public final static String PAGE_EXTRA_ELEM = "pageExtra";
122
123 //public final static String DESCRIPTION_ELEM = "description";
124
125 public static final String ACTION_ELEM = "action";
126 public static final String SUBACTION_ELEM = "subaction";
127
128 // add on to another elem type to get a list of that type
129 public static final String LIST_MODIFIER = "List";
130 // used to refer back to another element type
131 public static final String REF_MODIFIER = "Ref";
132 // greenstone xml attributes
133 public static final String COLLECTION_ATT = "collection";
134 public static final String NAME_ATT = "name";
135 public static final String TO_ATT = "to";
136 public static final String USER_ID_ATT = "uid";
137 public static final String FROM_ATT = "from";
138 public static final String LANG_ATT = "lang";
139 public static final String TYPE_ATT = "type";
140 public static final String DB_TYPE_ATT = "dbType";
141 public static final String VALUE_ATT = "value";
142 public static final String DEFAULT_ATT = "default";
143 public static final String INFO_ATT = "info";
144 public static final String ACTION_ATT = "action";
145 public static final String SUBACTION_ATT = "subaction";
146 public static final String OUTPUT_ATT = "output";
147 public static final String ADDRESS_ATT = "address";
148 public static final String LOCAL_SITE_ATT = "localSite";
149 public static final String LOCAL_SITE_NAME_ATT = "localSiteName";
150 public static final String STATUS_ERROR_CODE_ATT = "code";
151 public static final String STATUS_PROCESS_ID_ATT = "pid";
152 public static final String PARAM_SHORTNAME_ATT = "shortname";
153 public static final String PARAM_IGNORE_POS_ATT = "ignore";
154 public static final String CLASSIFIER_CONTENT_ATT = "content";
155 public static final String ERROR_TYPE_ATT = "type";
156 public static final String COLLECT_TYPE_ATT = "ct";
157 public static final String HIDDEN_ATT = "hidden";
158 public static final String FACET_ATT = "facet";
159
160 // document stuff
161 public static final String DOC_TYPE_ATT = "docType";
162 public static final String DOC_NODE_ELEM = "documentNode";
163 public static final String NODE_CONTENT_ELEM = "nodeContent";
164 public static final String NODE_STRUCTURE_ELEM = "nodeStructure";
165 public static final String NODE_ID_ATT = "nodeID";
166 public static final String HREF_ID_ATT = "hrefId"; // for ids that need translating
167 public static final String ID_MOD_ATT = "idMod"; // might hold .rt etc for hrefIds
168 public static final String NODE_OID = "oid";
169 public static final String NODE_NAME_ATT = "nodeName";
170 public static final String NODE_TYPE_ATT = "nodeType";
171 public static final String NODE_RANK_ATT = "rank";
172 public static final String NODE_TYPE_ROOT = "root";
173 public static final String NODE_TYPE_INTERNAL = "internal";
174 public static final String NODE_TYPE_LEAF = "leaf";
175
176 public static final String DOC_TYPE_SIMPLE = "simple";
177 public static final String DOC_TYPE_PAGED = "paged";
178 public static final String DOC_TYPE_HIERARCHY = "hierarchy";
179
180 public static final String SESSION_EXPIRATION = "session_expiration";
181 public static final String USER_SESSION_CACHE_ATT = "user_session_cache";
182
183 // classifier stuff
184 public static final String CLASS_NODE_ELEM = "classifierNode";
185 public static final String CLASS_NODE_ORIENTATION_ATT = "orientation";
186
187 // parameter types
188 public static final String PARAM_TYPE_INTEGER = "integer";
189 public static final String PARAM_TYPE_BOOLEAN = "boolean";
190 public static final String PARAM_TYPE_ENUM_START = "enum";
191 public static final String PARAM_TYPE_ENUM_SINGLE = "enum_single";
192 public static final String PARAM_TYPE_ENUM_MULTI = "enum_multi";
193 public static final String PARAM_TYPE_STRING = "string";
194 public static final String PARAM_TYPE_TEXT = "text";
195 public static final String PARAM_TYPE_MULTI = "multi";
196 public static final String PARAM_TYPE_FILE = "file";
197 public static final String PARAM_TYPE_INVISIBLE = "invisible";
198 public static final String PARAM_TYPE_CHECKBOX_LIST = "checkbox_list";
199 // stuff for text strings
200 public static final String DISPLAY_TEXT_ELEM = "displayItem";
201 // the following are used for the name attributes
202 public static final String DISPLAY_TEXT_NAME = "name";
203 public static final String DISPLAY_TEXT_SUBMIT = "submit";
204 public static final String DISPLAY_TEXT_DESCRIPTION = "description";
205
206 // request types
207 // get the module description
208 public static final String REQUEST_TYPE_DESCRIBE = "describe";
209 // startup a process
210 public static final String REQUEST_TYPE_PROCESS = "process";
211 // get the status of an ongoing process
212 public static final String REQUEST_TYPE_STATUS = "status";
213 // system type request - eg reload a collection
214 public static final String REQUEST_TYPE_SYSTEM = "system";
215 // page requests to the Receptionist/Actions
216 public static final String REQUEST_TYPE_PAGE = "page"; // used to be cgi
217 // get any format info for a service
218 public static final String REQUEST_TYPE_FORMAT = "format";
219 // modify the requests
220 public static final String REQUEST_TYPE_MESSAGING = "messaging";
221 // save the format string
222 public static final String REQUEST_TYPE_FORMAT_STRING = "formatString";
223 // check credentials
224 public static final String REQUEST_TYPE_SECURITY = "security";
225
226 // service types
227 public static final String SERVICE_TYPE_QUERY = "query";
228 public static final String SERVICE_TYPE_RETRIEVE = "retrieve";
229 public static final String SERVICE_TYPE_BROWSE = "browse";
230 public static final String SERVICE_TYPE_APPLET = "applet";
231 public static final String SERVICE_TYPE_PROCESS = "process";
232 public static final String SERVICE_TYPE_ENRICH = "enrich";
233 public static final String SERVICE_TYPE_OAI = "oai";
234 public static final String FLAX_PAGE = "flaxPage";
235 public static final String FLAX_PAGE_GENERATION = "FlaxPageGeneration";
236
237 // system command types and attributes
238 public static final String SYSTEM_TYPE_CONFIGURE = "configure";
239 public static final String SYSTEM_TYPE_ACTIVATE = "activate";
240 public static final String SYSTEM_TYPE_DEACTIVATE = "deactivate";
241 public static final String SYSTEM_TYPE_PING = "ping";
242 //public static final String SYSTEM_TYPE_ISPERSISTENT = "is-persistent";
243
244 public static final String SYSTEM_SUBSET_ATT = "subset";
245 public static final String SYSTEM_MODULE_TYPE_ATT = "moduleType";
246 public static final String SYSTEM_MODULE_NAME_ATT = "moduleName";
247
248 // communicator types
249 public static final String COMM_TYPE_SOAP_JAVA = "soap";
250
251 // error types
252 public static final String ERROR_TYPE_SYNTAX = "syntax";
253 public static final String ERROR_TYPE_SYSTEM = "system";
254 public static final String ERROR_TYPE_INVALID_ID = "invalid_id";
255 public static final String ERROR_TYPE_OTHER = "other";
256
257 // some system wide param names
258 public static final String SUBSET_PARAM = "subset";
259
260 //for plugin
261 public static final String PLUGIN_ELEM = "plugin";
262 public static final String IMPORT_ELEM = "import";
263
264 //for authentication
265 public static final String AUTHEN_NODE_ELEM = "authenticationNode";
266 public static final String USER_NODE_ELEM = "userNode";
267
268 //for configure action results
269 public static final String SUCCESS = "success";
270 public static final String ERROR = "error";
271
272 //security tags and attributes
273 public static final String SECURITY_ELEM = "security";
274 public static final String SCOPE_ATT = "scope";
275 public static final String DEFAULT_ACCESS_ATT = "default_access";
276 public static final String EXCEPTION_ELEM = "exception";
277 public static final String DOCUMENT_SET_ELEM = "documentSet";
278 public static final String GROUP_ELEM = "group";
279 public static final String MATCH_ELEM = "match";
280 public static final String FIELD_ATT = "field";
281 public static final String USER_INFORMATION_ELEM = "userInformation";
282 public static final String USERNAME_ATT = "username";
283 public static final String GROUPS_ATT = "groups";
284 public static final String BASE_URL = "baseURL";
285
286 //for classifiers
287 public static final String CHILD_TYPE_ATT = "childType";
288 public static final String CLASSIFIER_STYLE_ATT = "classifierStyle";
289 public static final String HLIST = "HList";
290 public static final String VLIST = "VList";
291
292 /**
293 * takes a list of elements, and returns an array of strings of the values
294 * of attribute att_name
295 */
296 public static String[] getAttributeValuesFromList(Element list, String att_name)
297 {
298
299 NodeList children = list.getChildNodes();
300
301 int num_nodes = children.getLength();
302 String[] ids = new String[num_nodes];
303 for (int i = 0; i < num_nodes; i++)
304 {
305 Element e = (Element) children.item(i);
306 String id = e.getAttribute(att_name);
307 ids[i] = id;
308 }
309
310 return ids;
311 }
312
313 public static HashMap<String, Serializable> extractParams(Element xml, boolean deep)
314 {
315 return extractParams(xml, deep, null);
316 }
317
318 /**
319 * takes a paramList element, and gets a HashMap of name-value pairs if
320 * deep=true, extracts embedded params, otherwise just top level params
321 */
322 public static HashMap<String, Serializable> extractParams(Element xml, boolean deep, String toFind)
323 {
324
325 if (!xml.getNodeName().equals(PARAM_ELEM + LIST_MODIFIER))
326 {
327 logger.error("paramList element should have been passed to extractParams, instead it was " + xml.getNodeName());
328 return null;
329 }
330
331 NodeList params = null;
332 if (deep)
333 { // get all the nested ones
334 params = xml.getElementsByTagName(PARAM_ELEM);
335 }
336 else
337 { // just get the top level ones
338 params = xml.getChildNodes();
339 }
340 HashMap<String, Serializable> param_map = new HashMap<String, Serializable>();
341 for (int i = 0; i < params.getLength(); i++)
342 {
343 if (params.item(i).getNodeName().equals(PARAM_ELEM))
344 {
345 Element param = (Element) params.item(i);
346 String name = param.getAttribute(NAME_ATT);
347 String value = getValue(param); //att or content
348
349 // For only one parameter
350 if (toFind != null && name.equals(toFind))
351 {
352 param_map.put(name, value);
353 return param_map;
354 }
355 else if (toFind != null)
356 continue;
357
358 int pos = name.indexOf('.');
359 if (pos == -1)
360 { // a base param
361 param_map.put(name, value);
362 }
363 else
364 { // a namespaced param
365
366 String namespace = name.substring(0, pos);
367 name = name.substring(pos + 1);
368 HashMap<String, String> map = (HashMap<String, String>) param_map.get(namespace);
369 if (map == null)
370 {
371 map = new HashMap<String, String>();
372 param_map.put(namespace, map);
373 }
374 map.put(name, value);
375 }
376 }
377 }
378 return param_map;
379 }
380
381 /** gets the value att or the text content */
382 public static String getValue(Element e)
383 {
384 String val = e.getAttribute(VALUE_ATT);
385 if (val == null || val.equals(""))
386 {
387 // have to get it out of the text
388 val = getNodeText(e);
389
390 }
391 else
392 {
393 // unescape the xml stuff
394 val = unXmlSafe(val);
395 }
396 return val;
397 }
398
399 /** extracts the text out of a node */
400 public static Node getNodeTextNode(Element param)
401 {
402 param.normalize();
403 Node n = param.getFirstChild();
404 while (n != null && n.getNodeType() != Node.TEXT_NODE)
405 {
406 n = n.getNextSibling();
407 }
408 return n;
409 }
410
411 /** extracts the text out of a node */
412 public static String getNodeText(Element param)
413 {
414 Node text_node = getNodeTextNode(param);
415 if (text_node == null)
416 {
417 return "";
418 }
419 return text_node.getNodeValue();
420 }
421
422 public static void setNodeText(Element elem, String text)
423 {
424 Node old_text_node = getNodeTextNode(elem);
425 if (old_text_node != null)
426 {
427 elem.removeChild(old_text_node);
428 }
429 Text t = elem.getOwnerDocument().createTextNode(text);
430 elem.appendChild(t);
431 }
432
433 /** add text to a document/subsection element */
434 public static boolean addDocText(Document owner, Element doc, String text)
435 {
436
437 Element content = owner.createElement(NODE_CONTENT_ELEM);
438 Text t = owner.createTextNode(text);
439 content.appendChild(t);
440 doc.appendChild(content);
441 return true;
442 }
443
444 /** add an error message, unknown error type */
445 public static boolean addError(Document owner, Element doc, String text)
446 {
447 return addError(owner, doc, text, ERROR_TYPE_OTHER);
448 }
449
450 /** add an error message */
451 public static boolean addError(Document owner, Element doc, String text, String error_type)
452 {
453
454 Element content = owner.createElement(ERROR_ELEM);
455 content.setAttribute(ERROR_TYPE_ATT, error_type);
456 Text t = owner.createTextNode(text);
457 content.appendChild(t);
458 doc.appendChild(content);
459 return true;
460 }
461
462 /** add an error message */
463 public static boolean addError(Document owner, Element doc, Throwable error)
464 {
465 return addError(owner, doc, error, ERROR_TYPE_OTHER);
466 }
467
468 /** add an error message */
469 public static boolean addError(Document owner, Element doc, Throwable error, String error_type)
470 {
471 error.printStackTrace();
472 return addError(owner, doc, error.toString(), error_type);
473 }
474
475 public static Element createMetadataParamList(Document owner, Vector meta_values)
476 {
477
478 Element meta_param_list = owner.createElement(PARAM_ELEM + LIST_MODIFIER);
479 Iterator i = meta_values.iterator();
480 while (i.hasNext())
481 {
482 String next = (String) i.next();
483 Element meta_param = owner.createElement(PARAM_ELEM);
484 meta_param_list.appendChild(meta_param);
485 meta_param.setAttribute(NAME_ATT, "metadata");
486 meta_param.setAttribute(VALUE_ATT, next);
487 }
488 return meta_param_list;
489 }
490
491 /** adds a metadata elem to a list */
492 public static boolean addMetadata(Document owner, Element list, String meta_name, String meta_value)
493 {
494 if (meta_value == null || meta_value.equals(""))
495 {
496 return false;
497 }
498 Element data = owner.createElement(METADATA_ELEM);
499 data.setAttribute(NAME_ATT, meta_name);
500 Text t = owner.createTextNode(meta_value);
501 data.appendChild(t);
502 list.appendChild(data);
503 return true;
504
505 }
506
507 /**
508 * copies the metadata out of the metadataList of 'from' into the
509 * metadataList of 'to'
510 */
511 public static boolean mergeMetadataLists(Node to, Node from)
512 {
513 Node from_meta = getChildByTagName(from, METADATA_ELEM + LIST_MODIFIER);
514 if (from_meta == null)
515 { // nothing to copy
516 return true;
517 }
518 return mergeMetadataFromList(to, from_meta);
519 }
520
521 /**
522 * copies the metadata out of the meta_list metadataList into the
523 * metadataList of 'to'
524 */
525 public static boolean mergeMetadataFromList(Node to, Node meta_list)
526 {
527 if (meta_list == null)
528 return false;
529 Node to_meta = getChildByTagName(to, METADATA_ELEM + LIST_MODIFIER);
530 Document to_owner = to.getOwnerDocument();
531 if (to_meta == null)
532 {
533 to.appendChild(to_owner.importNode(meta_list, true));
534 return true;
535 }
536 // copy individual metadata elements
537 NodeList meta_items = ((Element) meta_list).getElementsByTagName(METADATA_ELEM);
538 for (int i = 0; i < meta_items.getLength(); i++)
539 {
540 to_meta.appendChild(to_owner.importNode(meta_items.item(i), true));
541 }
542 return true;
543 }
544
545 /** copies all the children from from to to */
546 public static boolean mergeElements(Element to, Element from)
547 {
548
549 Document owner = to.getOwnerDocument();
550 Node child = from.getFirstChild();
551 while (child != null)
552 {
553 to.appendChild(owner.importNode(child, true));
554 child = child.getNextSibling();
555 }
556 return true;
557 }
558
559 /** returns the (first) element child of the node n */
560 public static Element getFirstElementChild(Node n)
561 {
562
563 Node child = n.getFirstChild();
564 while (child != null)
565 {
566 if (child.getNodeType() == Node.ELEMENT_NODE)
567 {
568 return (Element) child;
569 }
570 child = child.getNextSibling();
571 }
572 return null; //no element child found
573 }
574
575 /** returns the (first) child element with the given name */
576 public static Node getChildByTagName(Node n, String name)
577 {
578 if (n != null)
579 { // this line is an attempted solution to the NullPointerException mentioned
580 // in trac bug ticket #225. If n is null can't do n.getFirstChild() below. As per bug #225:
581 // GSXML.getNodeByPath() is called by GS2BrowseAction, which then calls this method.
582 // If n is null, null will be returned which GS2BrowseAction already checks for. It's here
583 // that the NullPointerException was thrown.
584
585 Node child = n.getFirstChild();
586 while (child != null)
587 {
588 if (child.getNodeName().equals(name))
589 {
590 return child;
591 }
592 child = child.getNextSibling();
593 }
594 }
595 return null; //not found
596 }
597
598 /**
599 * returns the (nth) child element with the given name index numbers start
600 * at 0
601 */
602 public static Node getChildByTagNameIndexed(Node n, String name, int index)
603 {
604 if (index == -1)
605 {
606 return getChildByTagName(n, name);
607 }
608 int count = 0;
609 Node child = n.getFirstChild();
610 while (child != null)
611 {
612 if (child.getNodeName().equals(name))
613 {
614 if (count == index)
615 {
616 return child;
617 }
618 else
619 {
620 count++;
621 }
622 }
623 child = child.getNextSibling();
624 }
625 return null; //not found
626 }
627
628 /**
629 * takes an xpath type expression of the form name/name/... and returns the
630 * first node that matches, or null if not found
631 */
632 public static Node getNodeByPath(Node n, String path)
633 {
634
635 String link = GSPath.getFirstLink(path);
636 path = GSPath.removeFirstLink(path);
637 while (!link.equals(""))
638 {
639 n = getChildByTagName(n, link);
640 if (n == null)
641 {
642 return null;
643 }
644 link = GSPath.getFirstLink(path);
645 path = GSPath.removeFirstLink(path);
646 }
647 return n;
648 }
649
650 /**
651 * takes an xpath type expression of the form name/name/... and returns the
652 * first node that matches, or null if not found can include [i] indices.
653 * index numbers start at 0
654 */
655 public static Node getNodeByPathIndexed(Node n, String path)
656 {
657
658 String link = GSPath.getFirstLink(path);
659 int index = GSPath.getIndex(link);
660 if (index != -1)
661 {
662 link = GSPath.removeIndex(link);
663 }
664 path = GSPath.removeFirstLink(path);
665 while (!link.equals(""))
666 {
667 n = getChildByTagNameIndexed(n, link, index);
668 if (n == null)
669 {
670 return null;
671 }
672 link = GSPath.getFirstLink(path);
673 index = GSPath.getIndex(link);
674 if (index != -1)
675 {
676 link = GSPath.removeIndex(link);
677 }
678 path = GSPath.removeFirstLink(path);
679 }
680 return n;
681 }
682
683 public static HashMap<String, Node> getChildrenMap(Node n)
684 {
685
686 HashMap<String, Node> map = new HashMap<String, Node>();
687 Node child = n.getFirstChild();
688 while (child != null)
689 {
690 String name = child.getNodeName();
691 map.put(name, child);
692 child = child.getNextSibling();
693 }
694 return map;
695 }
696
697 public static NodeList getChildrenByTagName(Node n, String name)
698 {
699 MyNodeList node_list = new MyNodeList();
700 Node child = n.getFirstChild();
701 while (child != null)
702 {
703 if (child.getNodeName().equals(name))
704 {
705 node_list.addNode(child);
706 }
707 child = child.getNextSibling();
708 }
709 return node_list;
710 }
711 public static NodeList getChildrenByTagNameNS(Node n, String namespace, String local_name)
712 {
713 MyNodeList node_list = new MyNodeList();
714 Node child = n.getFirstChild();
715 while (child != null)
716 {
717 if (child.getNodeType() == Node.ELEMENT_NODE && child.getNamespaceURI().equals(namespace) && child.getLocalName() != null && child.getLocalName().equals(local_name))
718 {
719 node_list.addNode(child);
720 }
721 child = child.getNextSibling();
722 }
723 return node_list;
724 }
725
726 /** Duplicates an element, but gives it a new name */
727 public static Element duplicateWithNewName(Document owner, Element element, String element_name, boolean with_attributes)
728 {
729 return duplicateWithNewNameNS(owner, element, element_name, null, with_attributes);
730 }
731
732 /** Duplicates an element, but gives it a new name */
733 public static Element duplicateWithNewNameNS(Document owner, Element element, String element_name, String namespace_uri, boolean with_attributes)
734 {
735 Element duplicate;
736 if (namespace_uri == null)
737 {
738 duplicate = owner.createElement(element_name);
739 }
740 else
741 {
742 duplicate = owner.createElementNS(namespace_uri, element_name);
743 }
744 // Copy element attributes
745 if (with_attributes)
746 {
747 NamedNodeMap attributes = element.getAttributes();
748 for (int i = 0; i < attributes.getLength(); i++)
749 {
750 Node attribute = attributes.item(i);
751 duplicate.setAttribute(attribute.getNodeName(), attribute.getNodeValue());
752 }
753 }
754
755 // Copy element children
756 NodeList children = element.getChildNodes();
757 for (int i = 0; i < children.getLength(); i++)
758 {
759 Node child = children.item(i);
760 duplicate.appendChild(owner.importNode(child, true));
761 }
762
763 return duplicate;
764 }
765
766 public static void copyAllChildren(Element to, Element from)
767 {
768
769 Document to_doc = to.getOwnerDocument();
770 Node child = from.getFirstChild();
771 while (child != null)
772 {
773 to.appendChild(to_doc.importNode(child, true));
774 child = child.getNextSibling();
775 }
776 }
777
778 /** returns a basic request message */
779 public static Element createBasicRequest(Document owner, String request_type, String to, UserContext userContext)
780 {
781 Element request = owner.createElement(REQUEST_ELEM);
782 request.setAttribute(TYPE_ATT, request_type);
783 request.setAttribute(LANG_ATT, userContext._lang);
784 request.setAttribute(TO_ATT, to);
785 request.setAttribute(USER_ID_ATT, userContext._userID);
786 return request;
787 }
788
789 public static Element createBasicResponse(Document owner, String from)
790 {
791 Element response = owner.createElement(GSXML.RESPONSE_ELEM);
792 response.setAttribute(GSXML.FROM_ATT, from);
793 response.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
794 return response;
795 }
796
797 public static Element createMetadataElement(Document owner, String name, String value)
798 {
799 Element metaElem = owner.createElement(GSXML.METADATA_ELEM);
800 metaElem.setAttribute(GSXML.NAME_ATT, name);
801 metaElem.setAttribute(GSXML.VALUE_ATT, value);
802 return metaElem;
803 }
804
805 public static Element createTextElement(Document owner, String elem_name, String text)
806 {
807 Element e = owner.createElement(elem_name);
808 Text t = owner.createTextNode(text);
809 e.appendChild(t);
810 return e;
811
812 }
813
814 public static Element createTextElement(Document owner, String elem_name, String text, String att_name, String att_value)
815 {
816 Element e = owner.createElement(elem_name);
817 e.setAttribute(att_name, att_value);
818 Text t = owner.createTextNode(text);
819 e.appendChild(t);
820 return e;
821
822 }
823
824 public static Element createDisplayTextElement(Document owner, String text_name, String text)
825 {
826 Element e = owner.createElement(DISPLAY_TEXT_ELEM);
827 e.setAttribute(NAME_ATT, text_name);
828 Text t = owner.createTextNode(text);
829 e.appendChild(t);
830 return e;
831
832 }
833
834 public static Element createParameter(Document owner, String name, String value)
835 {
836 Element param = owner.createElement(PARAM_ELEM);
837 param.setAttribute(NAME_ATT, name);
838 param.setAttribute(VALUE_ATT, value);
839 return param;
840 }
841
842 public static void addParametersToList(Document owner, Element param_list, HashMap params)
843 {
844 if (params == null)
845 {
846 return;
847 }
848
849 Set items = params.entrySet();
850 Iterator i = items.iterator();
851 while (i.hasNext())
852 {
853 Map.Entry m = (Map.Entry) i.next();
854 param_list.appendChild(createParameter(owner, (String) m.getKey(), (String) m.getValue()));
855 }
856
857 }
858
859 public static Element createParameterDescription(Document owner, String id, String display_name, String type, String default_value, String[] option_ids, String[] option_names)
860 {
861
862 Element p = owner.createElement(PARAM_ELEM);
863 p.setAttribute(NAME_ATT, id);
864 p.setAttribute(TYPE_ATT, type);
865 p.appendChild(createDisplayTextElement(owner, GSXML.DISPLAY_TEXT_NAME, display_name));
866
867 if (default_value != null)
868 {
869 p.setAttribute(DEFAULT_ATT, default_value);
870 }
871 if (option_ids != null && option_names != null)
872 {
873 for (int i = 0; i < option_ids.length; i++)
874 {
875 Element e = owner.createElement(PARAM_OPTION_ELEM);
876 e.setAttribute(NAME_ATT, option_ids[i]);
877 e.appendChild(createDisplayTextElement(owner, GSXML.DISPLAY_TEXT_NAME, option_names[i]));
878 p.appendChild(e);
879 }
880 }
881 return p;
882 }
883
884 public static Element createParameterDescription2(Document owner, String id, String display_name, String type, String default_value, ArrayList<String> option_ids, ArrayList<String> option_names)
885 {
886
887 Element p = owner.createElement(PARAM_ELEM);
888 p.setAttribute(NAME_ATT, id);
889 p.setAttribute(TYPE_ATT, type);
890 p.appendChild(createDisplayTextElement(owner, GSXML.DISPLAY_TEXT_NAME, display_name));
891 if (default_value != null)
892 {
893 p.setAttribute(DEFAULT_ATT, default_value);
894 }
895 if (option_ids != null && option_names != null)
896 {
897 for (int i = 0; i < option_ids.size(); i++)
898 {
899 Element e = owner.createElement(PARAM_OPTION_ELEM);
900 e.setAttribute(NAME_ATT, option_ids.get(i));
901 e.appendChild(createDisplayTextElement(owner, GSXML.DISPLAY_TEXT_NAME, option_names.get(i)));
902 p.appendChild(e);
903 }
904 }
905 return p;
906 }
907
908 /** returns the element parent/node_name[@attribute_name='attribute_value'] */
909 public static Element getNamedElement(Element parent, String node_name, String attribute_name, String attribute_value)
910 {
911
912 NodeList children = parent.getChildNodes();
913 for (int i = 0; i < children.getLength(); i++)
914 {
915 Node child = children.item(i);
916 if (child.getNodeName().equals(node_name))
917 {
918 if (((Element) child).getAttribute(attribute_name).equals(attribute_value))
919 return (Element) child;
920 }
921 }
922 // not found
923 return null;
924 }
925
926 public static Element getNamedElementNS(Element parent, String namespace_uri, String node_local_name, String attribute_name, String attribute_value)
927 {
928 NodeList children = parent.getChildNodes();
929 for (int i = 0; i < children.getLength(); i++)
930 {
931 Node child = children.item(i);
932 if (child.getNodeType() == Node.ELEMENT_NODE &&child.getNamespaceURI().equals(namespace_uri) && child.getLocalName().equals(node_local_name))
933 {
934 if (((Element) child).getAttribute(attribute_name).equals(attribute_value))
935 return (Element) child;
936 }
937 }
938 // not found
939 return null;
940
941
942 }
943
944 // In element main, tries to find any previous occurrence of elements with xsl-template-name=templateName,
945 // and whose named attribute (attributeName) has the same value as the same attribute in node.
946 // If this is the case, such a previous occurrence is removed from element main, since
947 // the new node will contain a more specific redefinition of this element.
948 public static void removeNamedElementNS(Element parent, String namespace_uri, String node_local_name, String attribute_name, String attribute_value)
949 {
950 if (attribute_value.equals("")) {
951 // it has no identifying attribute, so we can't find any matches
952 return;
953 }
954
955 Element old_elem = GSXML.getNamedElementNS(parent, namespace_uri, node_local_name, attribute_name, attribute_value);
956 if (old_elem != null)
957 {
958 parent.removeChild(old_elem);
959 }
960
961 }
962
963 public static void removeNamedElementsNS(Element parent, String namespace, String node_local_name, String attribute_name, String attribute_value)
964 {
965 if (attribute_value.equals("")) {
966 // it has no identifying attribute, so we can't find any matches
967 return;
968 }
969
970 NodeList children = parent.getChildNodes();
971 for (int i = children.getLength()-1; i >= 0; i--)
972 {
973 Node child = children.item(i);
974 if (child.getNodeType() == Node.ELEMENT_NODE && child.getNamespaceURI().equals(namespace) && child.getLocalName() != null && child.getLocalName().equals(node_local_name))
975 {
976 if (((Element) child).getAttribute(attribute_name).equals(attribute_value))
977 parent.removeChild(child);
978 }
979 }
980 }
981
982
983
984 /**
985 * returns a NodeList of elements:
986 * ancestor/node_name[@attribute_name='attribute_value']
987 */
988 public static NodeList getNamedElements(Element ancestor, String node_name, String attribute_name, String attribute_value)
989 {
990 MyNodeList node_list = new MyNodeList();
991 NodeList children = ancestor.getElementsByTagName(node_name);
992
993 if (children != null && children.getLength() > 0)
994 {
995
996 for (int i = 0; i < children.getLength(); i++)
997 {
998 Node child = children.item(i);
999 if (child.getNodeName().equals(node_name))
1000 {
1001 if (((Element) child).getAttribute(attribute_name).equals(attribute_value))
1002 node_list.addNode(child);
1003 }
1004 }
1005 }
1006 return node_list;
1007 }
1008
1009 public static Element getLastElementByTagNameNS(Element main, String namespace, String node_name) {
1010
1011 NodeList nodes = main.getElementsByTagNameNS(namespace, node_name);
1012 int len = nodes.getLength();
1013 if (len==0) {
1014 return null;
1015 }
1016 return (Element)nodes.item(len-1);
1017 }
1018
1019
1020 public static int SORT_TYPE_STRING = 0;
1021 public static int SORT_TYPE_INT = 1;
1022 public static int SORT_TYPE_FLOAT = 2;
1023
1024 // sort type:
1025 public static Element insertIntoOrderedList(Element parent_node, String node_name, Element start_from_elem, Element new_elem, String sort_att, boolean descending)
1026 {
1027 if (new_elem == null)
1028 return null;
1029 Element cloned_elem = (Element) parent_node.getOwnerDocument().importNode(new_elem, true);
1030 if (start_from_elem == null)
1031 {
1032 parent_node.appendChild(cloned_elem);
1033 return cloned_elem;
1034 }
1035
1036 Node current_node = start_from_elem;
1037 String insert_att = cloned_elem.getAttribute(sort_att);
1038 String list_att = start_from_elem.getAttribute(sort_att);
1039 while ((!descending && list_att.compareTo(insert_att) < 0) || (descending && list_att.compareTo(insert_att) > 0))
1040 {
1041 current_node = current_node.getNextSibling();
1042 if (current_node == null)
1043 break; // end of the list
1044 if (!current_node.getNodeName().equals(node_name))
1045 {
1046 continue; // not a valid node
1047 }
1048 list_att = ((Element) current_node).getAttribute(sort_att);
1049 }
1050
1051 parent_node.insertBefore(cloned_elem, current_node);
1052 return cloned_elem;
1053 }
1054
1055 /**
1056 * Returns the appropriate language element from a display elem, display is
1057 * the containing element, name is the name of the element to look for, lang
1058 * is the preferred language, lang_default is the fall back lang if neither
1059 * lang is found, will return the first one it finds
1060 */
1061 public static String getDisplayText(Element display, String name, String lang, String lang_default)
1062 {
1063
1064 String def = null;
1065 String first = null;
1066 NodeList elems = display.getElementsByTagName(DISPLAY_TEXT_ELEM);
1067 if (elems.getLength() == 0)
1068 return "";
1069 for (int i = 0; i < elems.getLength(); i++)
1070 {
1071 Element e = (Element) elems.item(i);
1072 String n = e.getAttribute(NAME_ATT);
1073 if (name.equals(n))
1074 {
1075 String l = e.getAttribute(LANG_ATT);
1076 if (lang.equals(l))
1077 {
1078 return getNodeText(e);
1079 }
1080 else if (lang_default.equals(l))
1081 {
1082 def = getNodeText(e);
1083 }
1084 else if (first == null)
1085 {
1086 first = getNodeText(e);
1087 }
1088 }
1089 else
1090 {
1091 continue;
1092 }
1093 }
1094
1095 if (def != null)
1096 {
1097 return def;
1098 }
1099 if (first != null)
1100 {
1101 return first;
1102 }
1103 return "";
1104 }
1105
1106 // replaces < > " ' & in the original with their entities
1107 public static String xmlSafe(String original)
1108 {
1109
1110 StringBuffer filtered = new StringBuffer(original.length());
1111 char c;
1112 for (int i = 0; i < original.length(); i++)
1113 {
1114 c = original.charAt(i);
1115 if (c == '>')
1116 {
1117 filtered.append("&gt;");
1118 }
1119 else if (c == '<')
1120 {
1121 filtered.append("&lt;");
1122 }
1123 else if (c == '"')
1124 {
1125 filtered.append("&quot;");
1126 }
1127 else if (c == '&')
1128 {
1129 filtered.append("&amp;");
1130 }
1131 else if (c == '\'')
1132 {
1133 filtered.append("&apos;");
1134 }
1135 else
1136 {
1137 filtered.append(c);
1138 }
1139 }
1140 return filtered.toString();
1141 }
1142
1143 // replaces < > " ' & entities with their originals
1144 public static String unXmlSafe(String original)
1145 {
1146
1147 StringBuffer filtered = new StringBuffer(original.length());
1148 char c;
1149 for (int i = 0; i < original.length(); i++)
1150 {
1151 c = original.charAt(i);
1152 if (c == '&')
1153 {
1154 int pos = original.indexOf(";", i);
1155 String entity = original.substring(i + 1, pos);
1156 if (entity.equals("gt"))
1157 {
1158 filtered.append(">");
1159 }
1160 else if (entity.equals("lt"))
1161 {
1162 filtered.append("<");
1163 }
1164 else if (entity.equals("apos"))
1165 {
1166 filtered.append("'");
1167 }
1168 else if (entity.equals("amp"))
1169 {
1170 filtered.append("&");
1171 }
1172 else if (entity.equals("quot"))
1173 {
1174 filtered.append("\"");
1175 }
1176 else
1177 {
1178 filtered.append("&" + entity + ";");
1179 }
1180 i = pos;
1181 }
1182 else
1183 {
1184 filtered.append(c);
1185 }
1186 }
1187 return filtered.toString();
1188 }
1189
1190 public static void printXMLNode(Node e, boolean printText)
1191 {
1192 printXMLNode(e, 0, printText);
1193 }
1194
1195 public static String xmlNodeToString(Node e)
1196 {
1197 StringBuffer sb = new StringBuffer("");
1198 xmlNodeToString(sb, e, true, "\t", 0);
1199 return sb.toString();
1200 }
1201
1202 public static void xmlNodeToString(StringBuffer sb, Node e, boolean indent, String indentString, int depth)
1203 {
1204 if (e.getNodeType() == Node.TEXT_NODE)
1205 {
1206 if (e.getNodeValue() != "")
1207 {
1208 String text = e.getNodeValue();
1209 text = text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("^[\\n\\r\\t\\s]*", "").replaceAll("[\\n\\r\\t\\s]*$", "");
1210 sb.append(text);
1211 }
1212 return;
1213 }
1214
1215 if (e.getNodeType() == Node.COMMENT_NODE)
1216 {
1217 if (e.getNodeValue() != "")
1218 {
1219 sb.append("<!--" + e.getNodeValue() + "-->");
1220 }
1221 return;
1222 }
1223
1224 if (indent)
1225 {
1226 for (int i = 0; i < depth; i++)
1227 {
1228 sb.append(indentString);
1229 }
1230 }
1231
1232 sb.append('<');
1233 sb.append(e.getNodeName());
1234 NamedNodeMap attrs = e.getAttributes();
1235 if (attrs != null)
1236 {
1237 for (int i = 0; i < attrs.getLength(); i++)
1238 {
1239 Node attr = attrs.item(i);
1240 sb.append(' ');
1241 sb.append(attr.getNodeName());
1242 sb.append("=\"");
1243 sb.append(attr.getNodeValue().replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;"));
1244 sb.append('"');
1245 }
1246 }
1247 NodeList children = e.getChildNodes();
1248
1249 boolean hasElements = false;
1250 boolean indentSwapped = false;
1251 for (int i = 0; i < children.getLength(); i++)
1252 {
1253 if (children.item(i).getNodeType() == Node.ELEMENT_NODE)
1254 {
1255 hasElements = true;
1256 }
1257 if (children.item(i).getNodeType() == Node.TEXT_NODE && indent)
1258 {
1259 if (children.item(i).getNodeValue().trim().length() > 0)
1260 {
1261 indentSwapped = true;
1262 indent = false;
1263 }
1264 }
1265 }
1266
1267 if (children == null || children.getLength() == 0)
1268 {
1269 sb.append("/>");
1270
1271 if (indent)
1272 {
1273 sb.append("\n");
1274 }
1275 }
1276 else
1277 {
1278 sb.append(">");
1279 if (hasElements && indent)
1280 {
1281 sb.append("\n");
1282 }
1283
1284 int len = children.getLength();
1285 for (int i = 0; i < len; i++)
1286 {
1287 xmlNodeToString(sb, children.item(i), indent, indentString, depth + 1);
1288 }
1289
1290 if (indent)
1291 {
1292 for (int i = 0; i < depth; i++)
1293 {
1294 sb.append(indentString);
1295 }
1296 }
1297
1298 sb.append("</" + e.getNodeName() + ">");
1299
1300 if ((hasElements && indent) || indentSwapped)
1301 {
1302 sb.append("\n");
1303 }
1304 }
1305 }
1306
1307 public static void printXMLNode(Node e, int depth, boolean printText)
1308 { //recursive method call using DOM API...
1309
1310 if (e == null)
1311 {
1312 return;
1313 }
1314
1315 for (int i = 0; i < depth; i++)
1316 System.out.print(' ');
1317
1318 if (e.getNodeType() == Node.TEXT_NODE)
1319 {
1320 if (printText)
1321 {
1322 System.out.println(e.getNodeValue());
1323 }
1324 else
1325 {
1326 System.out.println("text");
1327 }
1328 return;
1329 }
1330
1331 System.out.print('<');
1332 System.out.print(e.getNodeName());
1333 NamedNodeMap attrs = e.getAttributes();
1334
1335 if (attrs != null)
1336 {
1337 for (int i = 0; i < attrs.getLength(); i++)
1338 {
1339 Node attr = attrs.item(i);
1340 System.out.print(' ');
1341 System.out.print(attr.getNodeName());
1342 System.out.print("=\"");
1343 System.out.print(attr.getNodeValue());
1344 System.out.print('"');
1345 }
1346 }
1347
1348 NodeList children = e.getChildNodes();
1349
1350 if (children == null || children.getLength() == 0)
1351 System.out.println("/>");
1352 else
1353 {
1354
1355 System.out.println('>');
1356
1357 int len = children.getLength();
1358 for (int i = 0; i < len; i++)
1359 {
1360 printXMLNode(children.item(i), depth + 1, printText);
1361 }
1362
1363 for (int i = 0; i < depth; i++)
1364 System.out.print(' ');
1365
1366 System.out.println("</" + e.getNodeName() + ">");
1367 }
1368 }
1369
1370 public static void elementToLogAsString(Element e, boolean indent)
1371 {
1372 String str = elementToString(e, indent);
1373 System.err.println(str);
1374 logger.error(str);
1375 }
1376
1377 public static String elementToString(Element e, boolean indent)
1378 {
1379 String str = "";
1380 try
1381 {
1382 TransformerFactory tf = TransformerFactory.newInstance();
1383 Transformer trans = tf.newTransformer();
1384 StringWriter sw = new StringWriter();
1385 if (indent)
1386 {
1387 trans.setOutputProperty(OutputKeys.INDENT, "yes");
1388 }
1389 else
1390 {
1391 trans.setOutputProperty(OutputKeys.INDENT, "no");
1392 }
1393 trans.transform(new DOMSource(e), new StreamResult(sw));
1394 str += sw.toString();
1395 }
1396 catch (Exception ex)
1397 {
1398 str += "Exception: couldn't write " + e + " to log";
1399 }
1400 finally
1401 {
1402 return str;
1403 }
1404 }
1405
1406 public static ArrayList<String> getGroupsFromSecurityResponse(Element securityResponse)
1407 {
1408 ArrayList<String> groups = new ArrayList<String>();
1409
1410 Element groupList = (Element) GSXML.getChildByTagName(securityResponse, GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER);
1411 if (groupList == null)
1412 {
1413 return groups;
1414 }
1415
1416 NodeList groupElems = GSXML.getChildrenByTagName(groupList, GSXML.GROUP_ELEM);
1417
1418 for (int i = 0; i < groupElems.getLength(); i++)
1419 {
1420 Element groupElem = (Element) groupElems.item(i);
1421 groups.add(groupElem.getAttribute(GSXML.NAME_ATT));
1422 }
1423
1424 return groups;
1425 }
1426
1427 public static NodeList getHTMLStructureElements(Document doc)
1428 {
1429 MyNodeList elems = new MyNodeList();
1430
1431 String[] structureTagNames = new String[] { "html", "div", "td", "li" };
1432
1433 for (String tagName : structureTagNames)
1434 {
1435 NodeList htmlElems = doc.getElementsByTagName(tagName);
1436 elems.addNodeList(htmlElems);
1437 }
1438
1439 return elems;
1440 }
1441
1442 public static void addDebugSpanTags(Document doc)
1443 {
1444 NodeList allElements = doc.getElementsByTagName("*");
1445
1446 for (int i = 0; i < allElements.getLength(); i++)
1447 {
1448 Element current = (Element) allElements.item(i);
1449 String debugString = null;
1450 if ((debugString = (String) current.getUserData("GSDEBUGFILENAME")) != null)
1451 {
1452 System.err.println("DEBUGSTRING = " + debugString);
1453
1454 Element xmlSpan = doc.createElement("span");
1455 xmlSpan.setAttribute("style", "display:none;");
1456 xmlSpan.setAttribute("class", "debugSpan");
1457 xmlSpan.appendChild(doc.createTextNode("\"filename\":\"" + debugString + "\", \"xml\":\"" + GSXML.xmlNodeToString((Element) current.getUserData("GSDEBUGXML")) + "\""));
1458
1459 if (current.hasChildNodes())
1460 {
1461 current.insertBefore(xmlSpan, current.getFirstChild());
1462 }
1463 else
1464 {
1465 current.appendChild(xmlSpan);
1466 }
1467 }
1468 }
1469 }
1470}
Note: See TracBrowser for help on using the repository browser.