Changeset 3576
- Timestamp:
- 2002-11-26T14:05:37+13:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/CGIArgConverter.java
r3487 r3576 4 4 import org.w3c.dom.Element; 5 5 6 /** converts long names for parameters into short names for cgi args, and vice versa */ 6 7 public class CGIArgConverter { 7 8 9 /** long to short mapping */ 8 10 protected HashMap long_map_=null; 11 /** short to long mapping */ 9 12 protected HashMap short_map_=null; 10 13 14 /** initialises the maps with known parameters */ 11 15 public CGIArgConverter() { 12 16 long_map_ = new HashMap(); … … 14 18 15 19 // initialize with the ones we know about 20 short_map_.put("a", "action"); 21 long_map_.put("action", "a"); 22 23 short_map_.put("sa", "subaction"); 24 long_map_.put("subaction", "sa"); 25 26 short_map_.put("sn", "serviceName"); 27 long_map_.put("serviceName", "sn"); 28 29 short_map_.put("sc", "serviceCluster"); 30 long_map_.put("serviceCluster", "sc"); 31 32 short_map_.put("l", "lang"); 33 long_map_.put("lang", "l"); 34 35 short_map_.put("c", "collection"); 36 long_map_.put("collection", "c"); 37 38 long_map_.put("resource", "r"); 39 short_map_.put("r", "resource"); 40 41 // these are service specific - should we have these here?? 16 42 long_map_.put("case", "k"); 17 43 short_map_.put("k", "case"); … … 35 61 short_map_.put("md", "maxDocs"); 36 62 37 short_map_.put("c", "collection");38 long_map_.put("collection", "c");39 40 short_map_.put("a", "action");41 long_map_.put("action", "a");42 43 short_map_.put("sa", "subaction");44 long_map_.put("subaction", "sa");45 46 short_map_.put("sn", "serviceName");47 long_map_.put("serviceName", "sn");48 49 short_map_.put("sc", "serviceCluster");50 long_map_.put("serviceCluster", "sc");51 52 short_map_.put("l", "lang");53 long_map_.put("lang", "l");54 55 63 long_map_.put("query", "q"); 56 64 short_map_.put("q", "query"); 57 65 58 long_map_.put("resource", "r");59 short_map_.put("r", "resource");60 61 66 short_map_.put("cl", "classifier"); 62 67 long_map_.put("classifier", "cl"); 63 68 } 64 69 70 /** takes a paramList element - contains <param name="x"> elements 71 * converts all the short names to long names 72 * returns true if successful, false otherwise */ 65 73 public boolean toLong(Element param_list) { 66 74 67 if (!param_list.getNodeName().equals( "paramList")) {68 System. out.println("wrong element to CGIArgConverter:toLong");75 if (!param_list.getNodeName().equals(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER)) { 76 System.err.println("CGIArgConverter Error: wrong element passed to toLong"); 69 77 return false; 70 78 } … … 72 80 Element param = (Element)param_list.getFirstChild(); 73 81 while (param!=null) { 74 String name = param.getAttribute("name"); 75 param.setAttribute("name", toLong(name)); 82 String name = param.getAttribute(GSXML.NAME_ATT); 83 param.setAttribute(GSXML.NAME_ATT, toLong(name)); 84 param = (Element)param.getNextSibling(); 85 } 86 return true; 87 88 } 89 /** adds shortnames to the params in the list */ 90 public boolean addShortNames(Element param_list) { 91 if (!param_list.getNodeName().equals(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER)) { 92 System.err.println("CGIArgConverter Error: wrong element passed to addShortNames"); 93 return false; 94 } 95 96 Element param = (Element)param_list.getFirstChild(); 97 while (param!=null) { 98 String name = param.getAttribute(GSXML.NAME_ATT); 99 param.setAttribute(GSXML.PARAM_SHORTNAME_ATT, toShort(name)); 76 100 param = (Element)param.getNextSibling(); 77 101 } … … 80 104 } 81 105 82 public boolean addShortNames(Element param_list) { 83 if (!param_list.getNodeName().equals("paramList")) { 84 System.out.println("wrong element to CGIArgConverter:toShort"); 85 return false; 86 } 87 88 Element param = (Element)param_list.getFirstChild(); 89 while (param!=null) { 90 String name = param.getAttribute("name"); 91 param.setAttribute("shortname", toShort(name)); 92 param = (Element)param.getNextSibling(); 93 } 94 return true; 95 96 } 97 98 106 /** returns the long form of a short arg - 107 * returns the original if it doesn't know about this short arg */ 99 108 public String toLong(String short_name) { 100 101 109 102 110 if (short_map_.containsKey(short_name)) { 103 111 return (String)short_map_.get(short_name); 104 112 } 105 System.err.println("CGIArgConverter: short name '"+short_name+"' not found in map!");106 113 return short_name; // just return the original 107 114 } 108 115 /** returns the short form of a long arg */ 109 116 public String toShort(String long_name) { 110 117 … … 119 126 return short_name; 120 127 } 121 128 129 /** tries to create a new short form of the long name - 130 * if it cant, it just returns the original name */ 122 131 protected String newShortName(String long_name) { 123 132 124 133 // for now, try the first letter, then first two etc. 125 134 int i=1; … … 129 138 short_try = long_name.substring(0, i); 130 139 } 131 if (i==long_name.length()) {132 return ""; // couldn't find one133 }134 140 return short_try; 141 135 142 } 136 143 }
Note:
See TracChangeset
for help on using the changeset viewer.