Changeset 4902
- Timestamp:
- 2003-07-11T16:18:01+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSXML.java
r4703 r4902 47 47 public static final String SEARCH_ELEM = "search"; 48 48 public static final String BROWSE_ELEM = "browse"; 49 public static final String DISPLAY_ELEM = "display"; 49 50 public static final String FIELD_ELEM = "field"; 50 public static final String DISPLAYNAME_ELEM = "displayName";51 51 public static final String SHORTNAME_ATT = "shortname"; 52 52 … … 88 88 89 89 // document stuff 90 public static final String DOC_TYPE_ATT = "doc umentType";90 public static final String DOC_TYPE_ATT = "docType"; 91 91 public static final String DOC_NODE_ELEM = "documentNode"; 92 92 public static final String NODE_CONTENT_ELEM = "nodeContent"; … … 114 114 public static final String PARAM_TYPE_MULTI = "multi"; 115 115 public static final String PARAM_TYPE_FILE = "file"; 116 116 117 // stuff for text strings 117 public static final String DISPLAY_ELEM = "display"; 118 public static final String DISPLAY_NAME_ELEM = "name"; 119 public static final String DISPLAY_SUBMIT_ELEM = "submit"; 118 public static final String DISPLAY_TEXT_ELEM = "displayItem"; 119 // the following are used for the name attributes 120 public static final String DISPLAY_TEXT_NAME = "name"; 121 public static final String DISPLAY_TEXT_SUBMIT = "submit"; 120 122 121 123 // request types - do we need all these? or just … … 267 269 while(i.hasNext()) { 268 270 String next = (String)i.next(); 269 Element meta_param = owner.createElement( GSXML.PARAM_ELEM);271 Element meta_param = owner.createElement(PARAM_ELEM); 270 272 meta_param_list.appendChild(meta_param); 271 meta_param.setAttribute( GSXML.NAME_ATT, "metadata");272 meta_param.setAttribute( GSXML.VALUE_ATT, next);273 meta_param.setAttribute(NAME_ATT, "metadata"); 274 meta_param.setAttribute(VALUE_ATT, next); 273 275 } 274 276 return meta_param_list; … … 402 404 return request; 403 405 } 406 404 407 public static Element createTextElement(Document owner, String elem_name, 405 408 String text) { … … 411 414 } 412 415 416 public static Element createDisplayTextElement(Document owner, 417 String text_name, 418 String text) { 419 Element e = owner.createElement(DISPLAY_TEXT_ELEM); 420 e.setAttribute(NAME_ATT, text_name); 421 Text t = owner.createTextNode(text); 422 e.appendChild(t); 423 return e; 424 425 } 426 413 427 414 428 public static Element createParameter(Document owner, String name, … … 420 434 } 421 435 422 public static Element createParameterDescription(Document owner, String name, 423 String type, String default_value, 424 String []options) { 425 426 436 public static Element createParameterDescription(Document owner, 437 String id, 438 String display_name, 439 String type, 440 String default_value, 441 String []option_ids, 442 String []option_names) { 443 444 427 445 Element p = owner.createElement(PARAM_ELEM); 428 p.setAttribute(NAME_ATT, name);446 p.setAttribute(NAME_ATT, id); 429 447 p.setAttribute(TYPE_ATT, type); 448 p.appendChild(createDisplayTextElement(owner, GSXML.DISPLAY_TEXT_NAME, display_name)); 430 449 if (default_value != null) { 431 450 p.setAttribute(DEFAULT_ATT, default_value); 432 451 } 433 if ( type.startsWith(PARAM_TYPE_ENUM_START) && options!=null) {434 for (int i=0; i<option s.length; i++) {452 if (option_ids!=null && option_names!=null) { 453 for (int i=0; i<option_ids.length; i++) { 435 454 Element e = owner.createElement(PARAM_OPTION_ELEM); 436 e.setAttribute(NAME_ATT, options[i]); 455 e.setAttribute(NAME_ATT, option_ids[i]); 456 e.appendChild(createDisplayTextElement(owner, GSXML.DISPLAY_TEXT_NAME, option_names[i])); 437 457 p.appendChild(e); 438 458 } … … 441 461 } 442 462 443 /** creates a parm elem containing the text strings444 * <param><name>xxx<name><option name='x'>yyy</option><option name='y'>zzz</option></param>445 */446 public static Element createParameterDisplay(Document owner, String name,447 String name_text,448 String []options,449 String []option_texts) {450 451 452 Element param = owner.createElement(PARAM_ELEM);453 param.setAttribute(NAME_ATT, name);454 param.appendChild(createTextElement(owner, DISPLAY_NAME_ELEM, name_text));455 if (options != null) {456 for (int i=0; i<options.length; i++) {457 Element e = GSXML.createTextElement(owner, PARAM_OPTION_ELEM, option_texts[i]);458 e.setAttribute(NAME_ATT, options[i]);459 param.appendChild(e);460 }461 }462 463 return param;464 }465 463 466 464 /** returns the element parent/node_name[@attribute_name='attribute_value'] … … 491 489 public static String getDisplayText(Element display, String name, 492 490 String lang, String lang_default) { 493 Element item = getNamedElement(display, name, GSXML.LANG_ATT, lang); 494 if (item==null) { 495 item = getNamedElement(display, name, GSXML.LANG_ATT, lang_default); 496 } 497 if (item ==null) { 498 item = (Element)getChildByTagName(display, name); // just get the first one 499 } 500 if (item==null) { 501 return ""; // should we return an empty string? or null? 502 } 503 return getNodeText(item); 504 505 } 491 492 String def = null; 493 String first = null; 494 NodeList elems = display.getElementsByTagName(DISPLAY_TEXT_ELEM); 495 if (elems.getLength() == 0) return ""; 496 for (int i=0; i<elems.getLength(); i++) { 497 Element e = (Element)elems.item(i); 498 String n = e.getAttribute(NAME_ATT); 499 if (name.equals(n)) { 500 String l = e.getAttribute(LANG_ATT); 501 if (lang.equals(l)) { 502 return getNodeText(e); 503 } else if (lang_default.equals(l)) { 504 def = getNodeText(e); 505 } else if (first == null) { 506 first = getNodeText(e); 507 } 508 } else { 509 continue; 510 } 511 } 512 513 if (def != null) { 514 return def; 515 } 516 if (first != null) { 517 return first; 518 } 519 return ""; 520 } 521 506 522 // replaces < > " ' & in the original with their entities 507 523 public static String xmlSafe(String original) {
Note:
See TracChangeset
for help on using the changeset viewer.