Changeset 8962
- Timestamp:
- 2005-02-04T11:51:21+13:00 (19 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3/util
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GS2MacroResolver.java
r8827 r8962 1 /* 2 * GS2MacroResolver.java 3 * Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 */ 1 19 package org.greenstone.gsdl3.util; 2 20 … … 5 23 import org.greenstone.gdbm.DBInfo; 6 24 7 public class GS2MacroResolver { 25 public class GS2MacroResolver 26 extends MacroResolver 27 { 8 28 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 29 protected GDBMWrapper gdbm_src = null; 20 30 21 String lang = null;22 31 // need to make it not add macros if they are already present 23 public GS2MacroResolver(GDBMWrapper wrapper) { 24 this.text_macros = new ArrayList(); 25 this.metadata_macros = new ArrayList(); 26 this.gdbm_src = wrapper; 27 } 28 29 public void addMacro(int type, String macro, String text_or_metadata, String scope) { 30 Macro m = new Macro(); 31 m.type = type; 32 m.macro = macro; 33 m.text = text_or_metadata; 34 addMacro(m, scope); 32 public GS2MacroResolver(GDBMWrapper gdbm) { 33 gdbm_src = gdbm; 35 34 } 36 35 37 public void addMacro(int type, String macro, String bundle, String key, String scope) {38 Macro m = new Macro();39 m.type = type;40 m.macro = macro;41 m.bundle = bundle;42 m.key = key;43 addMacro(m, scope);44 }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 }61 36 62 public String resolve(String text, String lang, String scope, String doc_oid, DBInfo info) { 37 public String resolve(String text, String lang, String scope, 38 String doc_oid) { 63 39 //System.err.println("resolving macros for "+text); 64 40 if (scope.equals(SCOPE_TEXT) && text_macros.size()==0) return text; 65 41 if (scope.equals(SCOPE_META) && metadata_macros.size() ==0) return text; 66 42 43 DBInfo node_info = null; 67 44 DBInfo root_info = null; 68 45 boolean new_lang = false; … … 93 70 case TYPE_META: 94 71 if (text.indexOf(m.macro) != -1) { 95 if ( info == null) {96 info = gdbm_src.getInfo(doc_oid);97 if ( info == null) {72 if (node_info == null) { 73 node_info = gdbm_src.getInfo(doc_oid); 74 if (node_info == null) { 98 75 break; 99 76 } 100 77 } 101 String value = info.getInfo(m.text); 78 79 String value = node_info.getInfo(m.text); 102 80 if (value != null) { 103 81 text = text.replaceAll(m.macro, value); … … 105 83 // try the root node 106 84 if (root_info == null && !OID.isTop(doc_oid)) { 107 System.err.println("top="+OID.getTop(doc_oid));108 85 root_info = gdbm_src.getInfo(OID.getTop(doc_oid)); 109 86 } … … 125 102 } 126 103 127 128 129 130 private class Macro {131 132 public int type;133 public String macro = null;134 public String text = null;135 public String key = null;136 public String bundle = null;137 138 139 140 }141 142 143 104 }
Note:
See TracChangeset
for help on using the changeset viewer.