Changeset 11263 for trunk/gsdl3


Ignore:
Timestamp:
2006-02-16T13:31:14+13:00 (18 years ago)
Author:
kjdon
Message:

added a new field to macros: resolve. if true, will try to resolve macros (recursively) in the replacement value. also added setSAiteDetails() method, which sets up two default macros, _httpsite_ and _clustername_

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/MacroResolver.java

    r8962 r11263  
    4444    this.metadata_macros = new ArrayList();
    4545    }
     46
    4647   
    47     public void addMacro(int type, String macro, String text_or_metadata, String scope) {
     48    public void setSiteDetails(String site_address, String cluster_name) {
     49    if (site_address != null) {
     50        addMacro(TYPE_TEXT, "_httpsite_", site_address, SCOPE_ALL, false);
     51    }
     52    if (cluster_name != null) {
     53        addMacro(TYPE_TEXT, "_clustername_", cluster_name, SCOPE_ALL, false);
     54    }
     55    }
     56
     57    public void addMacro(int type, String macro, String text_or_metadata, String scope, boolean resolve) {
    4858    Macro m = new Macro();
    4959    m.type = type;
    5060    m.macro = macro;
    5161    m.text = text_or_metadata;
     62    m.resolve = resolve;
    5263    addMacro(m, scope);
    5364    }
    5465
    55     public void addMacro(int type, String macro, String bundle, String key, String scope) {
     66    public void addMacro(int type, String macro, String bundle, String key, String scope, boolean resolve) {
    5667    Macro m = new Macro();
    5768    m.type = type;
     
    5970    m.bundle = bundle;
    6071    m.key = key;
     72    m.resolve = resolve;
    6173    addMacro(m, scope);
    6274    }
     
    7082        scope = SCOPE_ALL;
    7183        }
     84        boolean resolve = true;
     85        String resolve_str = e.getAttribute("resolve");
     86        if (resolve_str.equals("false")) {
     87        resolve = false;
     88        }
    7289        String from = e.getAttribute("macro");
    7390        String to = e.getAttribute("text");
    7491        if (!to.equals("")) {
    75         addMacro(TYPE_TEXT, from, to, scope);
     92        addMacro(TYPE_TEXT, from, to, scope, resolve);
    7693        } else {
    7794        String meta = e.getAttribute("metadata");
    7895        if (!meta.equals("")) {
    79             addMacro(TYPE_META, from, meta, scope);
     96            addMacro(TYPE_META, from, meta, scope, resolve);
    8097        } else {
    8198            String key = e.getAttribute("key");
    8299            String bundle = e.getAttribute("bundle");
    83             addMacro(TYPE_DICT, from, bundle, key, scope);
     100            addMacro(TYPE_DICT, from, bundle, key, scope, resolve);
    84101        }
    85         }
     102                                                                                                                    }
    86103    }
    87104   
     
    109126    protected class Macro {
    110127   
     128    /** type of replacement: TEXT, METADATA, DICTIONARY */
    111129    public int type;
     130    /** the macro to replace */
    112131    public String macro = null;
    113     public String text = null;
     132    /** If text type, holds the text to replace with. If metadata type, holds the metadata name */
     133    public String text = null;
     134    /** If dictionary type, holds the key to look up in the dictionary */
    114135    public String key = null;
     136    /** If dictionary type, holds the resource bundle name */
    115137    public String bundle = null;
     138    /** If true, will try to resolve macros in the replacement text */
     139    public boolean resolve = true;
    116140   
    117141    }
Note: See TracChangeset for help on using the changeset viewer.