Changeset 8616
- Timestamp:
- 2004-11-22T15:05:37+13:00 (19 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java
r5098 r8616 98 98 return result; 99 99 } 100 100 String lang = request.getAttribute(GSXML.LANG_ATT); 101 101 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); 102 102 result.appendChild(doc_list); … … 118 118 long doc_num = this.gdbm_src.oid2Docnum(doc_id); 119 119 String doc_content = this.mgpp_src.getDocument(textdir, this.default_level, doc_num); 120 doc_content = resolve Images(doc_content, doc_id);120 doc_content = resolveTextMacros(doc_content, doc_id, lang); 121 121 122 122 // For now, stick it in a text node - eventually should be parsed as xml?? -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java
r7823 r8616 101 101 } 102 102 103 String lang = request.getAttribute(GSXML.LANG_ATT); 103 104 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); 104 105 result.appendChild(doc_list); … … 133 134 doc_content = doc_content.replaceAll("\u0002|\u0003", ""); 134 135 // replace _httpimg_ with the correct address 135 doc_content = resolve Images(doc_content, doc_id);136 doc_content = resolveTextMacros(doc_content, doc_id, lang); 136 137 GSXML.addDocText(this.doc, doc, doc_content); 137 138 } else { -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Retrieve.java
r8574 r8616 85 85 { 86 86 this.gdbm_src = new GDBMWrapper(); 87 this.macro_resolver = new GS2MacroResolver( );87 this.macro_resolver = new GS2MacroResolver(gdbm_src); 88 88 } 89 89 … … 132 132 for (int i=0; i<replaces.getLength(); i++) { 133 133 Element e = (Element)replaces.item(i); 134 String scope = e.getAttribute("scope"); 135 if (scope.equals("")) { 136 scope = GS2MacroResolver.SCOPE_ALL; 137 } 134 138 String from = e.getAttribute("macro"); 135 139 String to = e.getAttribute("text"); 136 if (to.equals("")) { 137 String key = e.getAttribute("key"); 138 String bundle = e.getAttribute("bundle"); 139 macro_resolver.addMacro(from, bundle, key); 140 if (!to.equals("")) { 141 macro_resolver.addMacro(GS2MacroResolver.TYPE_TEXT, from, to, scope); 140 142 } else { 141 macro_resolver.addMacro(from, to); 142 } 143 String meta = e.getAttribute("metadata"); 144 if (!meta.equals("")) { 145 macro_resolver.addMacro(GS2MacroResolver.TYPE_META, from, to, scope); 146 } else { 147 String key = e.getAttribute("key"); 148 String bundle = e.getAttribute("bundle"); 149 macro_resolver.addMacro(GS2MacroResolver.TYPE_DICT, from, bundle, key, scope); 150 } 151 } 143 152 } 144 153 } … … 769 778 String key = (String)it.next(); 770 779 String value = info.getInfo(key); 771 GSXML.addMetadata(this.doc, node_meta_list, key, this.macro_resolver.resolve Macros(value, lang));780 GSXML.addMetadata(this.doc, node_meta_list, key, this.macro_resolver.resolve(value, lang, GS2MacroResolver.SCOPE_META, node_id, info)); 772 781 } 773 782 } else { // just get the selected ones … … 794 803 if (pos ==-1) { 795 804 // just a plain meta entry eg dc.Title 796 return macro_resolver.resolve Macros((String)info.getInfo(metadata), lang);805 return macro_resolver.resolve((String)info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, node_id, info); 797 806 } 798 807 … … 854 863 855 864 if (!multiple) { 856 result.append(this.macro_resolver.resolve Macros(relation_info.getInfo(metadata), lang));865 result.append(this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, relation_id, relation_info)); 857 866 } else { 858 867 // we have multiple meta … … 866 875 result.append(separator); 867 876 } 868 result.append(this.macro_resolver.resolve Macros((String)values.elementAt(i), lang));877 result.append(this.macro_resolver.resolve((String)values.elementAt(i), lang, GS2MacroResolver.SCOPE_META, relation_id, relation_info)); 869 878 } 870 879 } … … 883 892 if (!multiple) { 884 893 result.insert(0, separator); 885 result.insert(0, this.macro_resolver.resolve Macros(relation_info.getInfo(metadata), lang));894 result.insert(0, this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, relation_id, relation_info)); 886 895 } else { 887 896 Vector values = relation_info.getMultiInfo(metadata); … … 889 898 for (int i=values.size()-1; i>=0; i--) { 890 899 result.insert(0, separator); 891 result.insert(0, this.macro_resolver.resolve Macros((String)values.elementAt(i), lang));900 result.insert(0, this.macro_resolver.resolve((String)values.elementAt(i), lang, GS2MacroResolver.SCOPE_META, relation_id, relation_info)); 892 901 } 893 902 } … … 904 913 905 914 /** needs to get info from gdbm database - if the calling code gets it already it may pay to pass it in instead */ 906 protected String resolve Images(String doc_content, String doc_id)915 protected String resolveTextMacros(String doc_content, String doc_id, String lang) 907 916 { 908 917 String top_doc_id = OID.getTop(doc_id); … … 910 919 String archivedir = info.getInfo("archivedir"); 911 920 String image_dir = this.site_http_address + "/collect/"+this.cluster_name+"/index/assoc/"+archivedir; 912 921 913 922 // Resolve all "_httpdocimg_"s 914 923 doc_content = doc_content.replaceAll("_httpdocimg_", image_dir); 924 // resolve any collection specific macros 925 doc_content = macro_resolver.resolve(doc_content, lang, GS2MacroResolver.SCOPE_TEXT, top_doc_id, info); 915 926 return doc_content; 916 927 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGRetrieve.java
r8439 r8616 182 182 doc_content = "this is the content for section hash id "+ doc_id+", mg doc num "+doc_int+"\n"; 183 183 } 184 184 185 //ystem.out.println("Doc content: " + doc_content + "|"); 185 186 //ystem.out.println("Doc ID: " + doc_id); … … 192 193 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); 193 194 GSXML.addDocText(this.doc, doc, doc_content); 195 Element nodeContent = (Element)GSXML.getChildByTagName(doc, "nodeContent"); 196 Element file_elem = this.doc.createElement("file"); 197 file_elem.setAttribute("mimeType", "image/jpeg"); 198 file_elem.setAttribute("href", "import/meinahole.jpg"); 199 nodeContent.appendChild(file_elem); 194 200 doc_list.appendChild(doc); 195 201 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GS2MacroResolver.java
r8573 r8616 2 2 3 3 import java.util.ArrayList; 4 import org.greenstone.gdbm.GDBMWrapper; 5 import org.greenstone.gdbm.DBInfo; 4 6 5 7 public class GS2MacroResolver { 6 8 7 ArrayList macros = null; 9 public static final String SCOPE_TEXT = "text"; 10 public static final String SCOPE_META = "metadata"; 11 public static final String SCOPE_ALL = "all"; 12 13 public static final int TYPE_TEXT = 0; 14 public static final int TYPE_META = 1; 15 public static final int TYPE_DICT = 2; 16 17 protected ArrayList text_macros = null; 18 protected ArrayList metadata_macros = null; 19 protected GDBMWrapper gdbm_src = null; 20 8 21 String lang = null; 9 22 // need to make it not add macros if they are already present 10 public GS2MacroResolver() { 11 this.macros = new ArrayList(); 23 public GS2MacroResolver(GDBMWrapper wrapper) { 24 this.text_macros = new ArrayList(); 25 this.metadata_macros = new ArrayList(); 26 this.gdbm_src = wrapper; 12 27 } 13 public void addMacro(String macro, String text) { 28 29 public void addMacro(int type, String macro, String text_or_metadata, String scope) { 14 30 Macro m = new Macro(); 31 m.type = type; 15 32 m.macro = macro; 16 m.text = text ;17 this.macros.add(m);33 m.text = text_or_metadata; 34 addMacro(m, scope); 18 35 } 19 36 20 public void addMacro( String macro, String bundle, String key) {37 public void addMacro(int type, String macro, String bundle, String key, String scope) { 21 38 Macro m = new Macro(); 39 m.type = type; 22 40 m.macro = macro; 23 41 m.bundle = bundle; 24 42 m.key = key; 25 this.macros.add(m);43 addMacro(m, scope); 26 44 } 27 45 46 protected void addMacro(Macro m, String scope) { 47 48 if (scope.equals(SCOPE_TEXT)) { 49 this.text_macros.add(m); 50 } 51 else if (scope.equals(SCOPE_META)) { 52 this.metadata_macros.add(m); 53 } 54 else if (scope.equals(SCOPE_ALL)) { 55 this.text_macros.add(m); 56 this.metadata_macros.add(m); 57 58 } 59 60 } 28 61 29 public String resolve Macros(String text, String lang) {62 public String resolve(String text, String lang, String scope, String doc_oid, DBInfo info) { 30 63 System.err.println("resolving macros for "+text); 31 if (macros.size()==0) return text; 64 if (scope.equals(SCOPE_TEXT) && text_macros.size()==0) return text; 65 if (scope.equals(SCOPE_META) && metadata_macros.size() ==0) return text; 32 66 33 67 boolean new_lang = false; 34 if (this.lang == null) {68 if (this.lang == null || !this.lang.equals(lang) ) { 35 69 new_lang = true; 36 70 this.lang = lang; 71 } 72 73 ArrayList macros; 74 if (scope.equals(SCOPE_TEXT)) { 75 macros = text_macros; 37 76 } else { 38 if (!this.lang.equals(lang)) { 39 new_lang = true; 40 this.lang = lang; 41 } 77 macros = metadata_macros; 42 78 } 79 43 80 for (int i=0; i<macros.size(); i++) { 44 81 Macro m = (Macro)macros.get(i); 45 if (m.key != null) { 82 switch (m.type) { 83 case TYPE_DICT: 46 84 if (m.text==null || new_lang) { 47 85 Dictionary dict = new Dictionary(m.bundle, lang); 48 86 m.text = dict.get(m.key, null); 49 87 } 88 // now drop through to text case 89 case TYPE_TEXT: 90 text = text.replaceAll(m.macro, m.text); 91 break; 92 case TYPE_META: 93 if (text.matches(m.macro)) { 94 if (info == null) { 95 info = gdbm_src.getInfo(doc_oid); 96 if (info == null) { 97 break; 98 } 99 String value = info.getInfo(m.text); 100 if (value != null) { 101 text = text.replaceAll(m.macro, value); 102 } 103 } 104 } 50 105 51 } 52 if (m.text != null) { 53 text = text.replaceAll(m.macro, m.text); 106 break; 54 107 } 55 108 } … … 64 117 private class Macro { 65 118 119 public int type; 66 120 public String macro = null; 67 121 public String text = null; 68 122 public String key = null; 69 123 public String bundle = null; 124 70 125 71 126
Note:
See TracChangeset
for help on using the changeset viewer.