Changeset 23791
- Timestamp:
- 2011-03-15T17:06:39+13:00 (13 years ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GS2MacroResolver.java
r15756 r23791 24 24 import java.net.URLDecoder; 25 25 26 // Apache Commons 27 import org.apache.commons.lang3.*; 28 29 import java.util.Stack; 30 26 31 public class GS2MacroResolver 27 32 extends MacroResolver … … 29 34 30 35 protected SimpleCollectionDatabase coll_db = null; 36 37 private static Pattern p_back_slash = Pattern.compile("\\\"");// create a pattern "\\\"", but it matches both " and \" 31 38 32 39 // need to make it not add macros if they are already present … … 58 65 } 59 66 60 ArrayList macros;67 Stack macros;//ArrayList macros; 61 68 if (scope.equals(SCOPE_TEXT)) { 62 69 macros = text_macros; … … 64 71 macros = metadata_macros; 65 72 } 66 for (int i=0; i<macros.size(); i++) { 73 //for (int i=0; i<macros.size(); i++) { 74 while(!macros.empty()) { 67 75 String new_text = null; 68 Macro m = (Macro)macros. get(i);76 Macro m = (Macro)macros.pop();//.get(i); 69 77 switch (m.type) { 70 78 case TYPE_DICT: … … 76 84 // otherwise we can't cache the answer because it might be 77 85 // document specific 78 text = text.replaceAll(m.macro, m.text);86 text = StringUtils.replace(text, m.macro, m.text); 79 87 break; 80 88 case TYPE_TEXT: … … 83 91 // doesn't necessarily match line breaks 84 92 //if (text.matches("(?s).*"+m.macro+".*")) { 85 Pattern p_text = Pattern.compile(".*" + m.macro + ".*",Pattern.DOTALL); 86 Matcher match_text = p_text.matcher(text); 87 if (match_text.matches()) { 93 94 /*Pattern p_text = Pattern.compile(".*" + m.macro + ".*",Pattern.DOTALL); 95 Matcher match_text = p_text.matcher(text);*/ 96 97 // sm252 98 // String.contains is far faster than regex! 99 if (text.contains(m.macro)) { //match_text.matches()) { //text.matches("(?s).*"+m.macro+".*")) { 88 100 if (m.resolve) { 89 101 new_text = this.resolve(m.text, lang, scope, doc_oid); … … 91 103 new_text = m.text; 92 104 } 93 text = text.replaceAll(m.macro, new_text);105 text = StringUtils.replace(text, m.macro, new_text); 94 106 if (m.macro.endsWith("\\\\")){ // to get rid of "\" from the string likes: "src="http://www.greenstone.org:80/.../mw.gif\">" 95 Pattern p_back_slash = Pattern.compile("\\\"");// create a pattern "\\\"", but it matches both " and \"107 96 108 Matcher m_slash = p_back_slash.matcher(text); 97 109 String clean_str = ""; … … 111 123 break; 112 124 case TYPE_META: 113 Pattern p = Pattern.compile(".*" + m.macro + ".*",Pattern.DOTALL); 114 Matcher match = p.matcher(text); 115 if (match.matches()) { 125 //Pattern p = Pattern.compile(".*" + m.macro + ".*",Pattern.DOTALL); 126 //Matcher match = p.matcher(text); 127 // sm252 128 if (text.contains(m.macro)) { //(match.matches()) { //text.matches("(?s).*"+m.macro+".*")) { 116 129 if (node_info == null) { 117 130 node_info = coll_db.getInfo(doc_oid); … … 133 146 new_text = this.resolve(new_text, lang, scope, doc_oid); 134 147 } 135 text = text.replaceAll(m.macro, new_text);148 text = StringUtils.replace(text, m.macro, new_text); 136 149 } 137 150 -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSConstants.java
r16869 r23791 27 27 public static final String LIBRARY_NAME = "library_name"; 28 28 public static final String DEFAULT_LANG = "default_lang"; 29 29 public static final String ALLOW_CLIENT_SIDE_XSLT = "allow_client_side_xslt"; 30 30 31 31 public static final String META_RELATION_SEP = "_"; -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java
r23627 r23791 264 264 } 265 265 266 public static HashMap extractParams(Element xml, boolean deep) { 267 return extractParams(xml, deep, null); 268 } 269 266 270 /** takes a paramList element, and gets a HashMap of name-value pairs 267 271 * if deep=true, extracts embedded params, otherwise just top level 268 272 * params*/ 269 public static HashMap extractParams(Element xml, boolean deep ) {273 public static HashMap extractParams(Element xml, boolean deep, String toFind) { 270 274 271 275 if (!xml.getNodeName().equals(PARAM_ELEM+LIST_MODIFIER)) { … … 286 290 String name=param.getAttribute(NAME_ATT); 287 291 String value=getValue(param); //att or content 292 293 // For only one parameter 294 if(toFind != null && name.equals(toFind)) { 295 param_map.put(name, value); 296 return param_map; 297 } 298 else if(toFind != null) 299 continue; 300 288 301 int pos = name.indexOf('.'); 289 302 if (pos == -1) { // a base param -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/SimpleCollectionDatabase.java
r22973 r23791 21 21 import org.apache.log4j.*; 22 22 23 import org.apache.commons.lang3.StringUtils; 24 23 25 public class SimpleCollectionDatabase implements OID.OIDTranslatable { 24 26 … … 104 106 DBInfo info = new DBInfo(); 105 107 106 String [] lines = key_info.split("\n");108 String [] lines = StringUtils.split(key_info, "\n"); 107 109 String key; 108 110 String value; … … 193 195 return top; 194 196 } 195 contains = contains.replaceAll("\"", doc_id);196 String [] children = contains.split(";");197 contains = StringUtils.replace(contains, "\"", doc_id); 198 String [] children = StringUtils.split(contains, ";"); 197 199 if (suff.equals("fc")) { 198 200 return children[0]; -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XMLConverter.java
r18434 r23791 41 41 import java.io.FileInputStream; 42 42 import java.io.FileReader; 43 import java.util.regex.*; 43 44 44 45 import org.apache.log4j.*; 46 47 // Apache Commons 48 import org.apache.commons.lang3.*; 49 50 import java.util.*; 51 import java.lang.reflect.*; 45 52 46 53 /** XMLConverter - utility class for greenstone … … 59 66 60 67 private static boolean outputEscaping = true; 61 62 68 63 69 /** the no-args constructor */ … … 216 222 } 217 223 224 /* For the purposes of logger.debug statements, where this is called and hence outputted, 225 returns an empty string if debugging is not enabled */ 226 public static String getPrettyStringLogger(Node xmlNode, Logger log) { 227 228 if(log.isDebugEnabled()) 229 return getPrettyString(xmlNode); 230 231 return ""; 232 233 } 234 218 235 private static void getString(Node xmlNode, StringBuffer xmlRepresentation, 219 236 int depth, boolean pretty) … … 242 259 String sid = dt.getSystemId(); 243 260 244 String doctype_str = "<!DOCTYPE " + dt.getName() + " PUBLIC \"" + pid + "\" \"" + sid + "\">\n"; 261 // Use previously assigned name, not dt.getName() again 262 String doctype_str = "<!DOCTYPE " + name + " PUBLIC \"" + pid + "\" \"" + sid + "\">\n"; 245 263 246 264 xmlRepresentation.append(doctype_str); … … 321 339 322 340 // Perform output escaping, if required 341 // Apache Commons replace method is far superior to String.replaceAll - very fast! 323 342 if (outputEscaping) { 324 text = text.replaceAll("&", "&"); // Must be done first!! 325 text = text.replaceAll("<", "<"); 326 text = text.replaceAll(">", ">"); 327 text = text.replaceAll("\"", """); 328 text = text.replaceAll("\'", "'"); 343 344 text = StringUtils.replace(text, "&", "&"); 345 text = StringUtils.replace(text, "<", "<"); 346 text = StringUtils.replace(text, ">", ">"); 347 text = StringUtils.replace(text, "'", "'"); 348 text = StringUtils.replace(text, "\"", """); 329 349 } 330 350 331 351 // Remove any control-C characters 332 text = text.replaceAll("" + (char) 3, ""); 352 text = StringUtils.replace(text, "" + (char)3, ""); 353 333 354 xmlRepresentation.append(text); 334 355 } -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java
r18308 r23791 28 28 import org.w3c.dom.Node; 29 29 30 import org.apache.commons.lang3.StringUtils; 31 30 32 /** a class to contain various static methods that are used by the xslt 31 33 * stylesheets … … 88 90 89 91 public static String getNumberedItem(String list, int number) { 90 String [] items = list.split(",", -1);92 String [] items = StringUtils.split(list, ",", -1); 91 93 if (items.length > number) { 92 94 return items[number]; … … 112 114 String [] args = null; 113 115 if (args_str!=null && !args_str.equals("")) { 114 args = args_str.split(";");116 args = StringUtils.split(args_str, ";"); 115 117 } 116 118 Dictionary dict = new Dictionary("interface_"+interface_name, lang);
Note:
See TracChangeset
for help on using the changeset viewer.