Changeset 11264 for trunk/gsdl3
- Timestamp:
- 2006-02-16T13:33:14+13:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GS2MacroResolver.java
r9874 r11264 29 29 // need to make it not add macros if they are already present 30 30 public GS2MacroResolver(GDBMWrapper gdbm) { 31 super(); 31 32 gdbm_src = gdbm; 32 33 } 33 34 34 35 35 36 public String resolve(String text, String lang, String scope, 36 37 String doc_oid) { 37 //System.err.println("resolving macros for "+text);38 if (text == null || text.equals("")) return text; 38 39 if (scope.equals(SCOPE_TEXT) && text_macros.size()==0) return text; 39 40 if (scope.equals(SCOPE_META) && metadata_macros.size() ==0) return text; 40 41 41 DBInfo node_info = null; 42 42 DBInfo root_info = null; … … 53 53 macros = metadata_macros; 54 54 } 55 56 55 for (int i=0; i<macros.size(); i++) { 56 String new_text = null; 57 57 Macro m = (Macro)macros.get(i); 58 58 switch (m.type) { … … 62 62 m.text = dict.get(m.key, null); 63 63 } 64 // now drop through to text case 65 case TYPE_TEXT: 64 // we assume that dictionary entries will contain no macros 65 // otherwise we can't cache the answer because it might be 66 // document specific 66 67 text = text.replaceAll(m.macro, m.text); 67 68 break; 69 case TYPE_TEXT: 70 // make sure we resolve any macros in the text 71 // the (?s) treats the string as a single line, cos . 72 // doesn't necessarily match line breaks 73 if (text.matches("(?s).*"+m.macro+".*")) { 74 if (m.resolve) { 75 new_text = this.resolve(m.text, lang, scope, doc_oid); 76 } else { 77 new_text = m.text; 78 } 79 text = text.replaceAll(m.macro, new_text); 80 } 81 break; 68 82 case TYPE_META: 69 if (text. indexOf(m.macro) != -1) {83 if (text.matches(".*"+m.macro+".*")) { 70 84 if (node_info == null) { 71 85 node_info = gdbm_src.getInfo(doc_oid); … … 74 88 } 75 89 } 76 77 String value = node_info.getInfo(m.text); 78 if (value != null) { 79 text = text.replaceAll(m.macro, value); 80 } else { 90 new_text = node_info.getInfo(m.text); 91 if (new_text == null || new_text.equals("")) { 81 92 // try the root node 82 93 if (root_info == null && !OID.isTop(doc_oid)) { … … 84 95 } 85 96 if (root_info == null) break; 86 value = root_info.getInfo(m.text); 87 if (value != null) { 88 text = text.replaceAll(m.macro, value); 97 new_text = root_info.getInfo(m.text); 98 } 99 if (new_text != null) { 100 if (m.resolve) { 101 new_text = this.resolve(new_text, lang, scope, doc_oid); 89 102 } 103 text = text.replaceAll(m.macro, new_text); 90 104 } 105 91 106 } 92 107 … … 95 110 96 111 } 97 98 112 return text; 99 113
Note:
See TracChangeset
for help on using the changeset viewer.