Changeset 8962


Ignore:
Timestamp:
2005-02-04T11:51:21+13:00 (19 years ago)
Author:
kjdon
Message:

made a base class which GS2MAcroREsolver inherits

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 */
    119package org.greenstone.gsdl3.util;
    220
     
    523import org.greenstone.gdbm.DBInfo;
    624
    7 public class GS2MacroResolver {
     25public class GS2MacroResolver
     26    extends MacroResolver
     27{
    828
    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;
    1929    protected GDBMWrapper gdbm_src = null;
    2030   
    21     String lang = null;
    2231    // 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;
    3534    }
    3635
    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     }
    6136   
    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) {
    6339    //System.err.println("resolving macros for "+text);
    6440    if (scope.equals(SCOPE_TEXT) && text_macros.size()==0) return text;
    6541    if (scope.equals(SCOPE_META) && metadata_macros.size() ==0) return text;
    6642
     43    DBInfo node_info = null;
    6744    DBInfo root_info = null;
    6845    boolean new_lang = false;
     
    9370        case TYPE_META:
    9471        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) {
    9875                break;
    9976            }
    10077            }
    101             String value = info.getInfo(m.text);
     78           
     79            String value = node_info.getInfo(m.text);
    10280            if (value != null) {
    10381            text = text.replaceAll(m.macro, value);
     
    10583            // try the root node
    10684            if (root_info == null && !OID.isTop(doc_oid)) {
    107                 System.err.println("top="+OID.getTop(doc_oid));
    10885                root_info = gdbm_src.getInfo(OID.getTop(doc_oid));
    10986            }
     
    125102    }
    126103
    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 
    143104}
Note: See TracChangeset for help on using the changeset viewer.