- Timestamp:
- 2011-03-15T17:06:39+13:00 (13 years ago)
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.