Changeset 26196 for main/trunk


Ignore:
Timestamp:
2012-09-18T15:17:35+12:00 (12 years ago)
Author:
kjdon
Message:

use a class loader for the dictionary to allow a colleciton to have a resource bundle in its resources folder. Need to read from the dictionary each time, without caching, otherwise may end up with the wrong language being cached. Thi scan happen when you ask for a metadata value to be resolved. the lang is new, so reload the dictionary entry. But when ask for a text to be resolved, now the lang does not look new, but the last time the text fragment was looked up in the dictionary it might have been a different language. - not all dictionary lookups are done each time, so can get out of date. So now, do a new lookup each time, but only do it if the macro is in the text

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GS2MacroResolver.java

    r25672 r26196  
    3434
    3535    protected SimpleCollectionDatabase coll_db = null;
    36 
     36  protected ClassLoader class_loader = null;
    3737    private static Pattern p_back_slash = Pattern.compile("\\\"");// create a pattern "\\\"", but it matches both " and \"
    3838
    3939    // need to make it not add macros if they are already present
    40     public GS2MacroResolver(SimpleCollectionDatabase db)
     40  public GS2MacroResolver(SimpleCollectionDatabase db, ClassLoader class_loader)
    4141    {
    4242        super();
    4343        coll_db = db;
     44        this.class_loader = class_loader;
    4445    }
    4546
     
    5354        this.coll_db = db;
    5455    }
    55 
    56     public String resolve(String text, String lang, String scope, String doc_oid)
     56  public void setClassLoader(ClassLoader class_loader) {
     57    this.class_loader = class_loader;
     58  }
     59 
     60  public String resolve(String text, String lang, String scope, String doc_oid)
    5761    {
    5862        if (text == null || text.equals(""))
     
    103107            {
    104108            case TYPE_DICT:
    105                 if (m.text == null || new_lang)
    106                 {
    107                     Dictionary dict = new Dictionary(m.bundle, lang);
    108                     m.text = dict.get(m.key, null);
    109                 }
     109              if (text.contains(m.macro))
     110
     111                {
     112              // if we change the lang, then do a metadata resolve, then a text resolve, the lang hasn't changed, but the text might be leftover from the last language.
     113              // if (m.text == null || new_lang)
     114              // {
     115                  Dictionary dict = new Dictionary(m.bundle, lang, this.class_loader);
     116                  m.text = dict.get(m.key, null);
     117                    //  }
    110118                // we assume that dictionary entries will contain no macros
    111119                // otherwise we can't cache the answer because it might be
    112120                // document specific
    113                 text = StringUtils.replace(text, m.macro, m.text);
     121                  text = StringUtils.replace(text, m.macro, m.text);}
    114122                break;
    115123            case TYPE_TEXT:
     
    131139                    if (m.resolve)
    132140                    {
    133                         new_text = this.resolve(m.text, lang, scope, doc_oid);
     141                      new_text = this.resolve(m.text, lang, scope, doc_oid);
    134142                    }
    135143                    else
     
    191199                        if (m.resolve)
    192200                        {
    193                             new_text = this.resolve(new_text, lang, scope, doc_oid);
     201                          new_text = this.resolve(new_text, lang, scope, doc_oid);
    194202                        }
    195203                        text = StringUtils.replace(text, m.macro, new_text);
Note: See TracChangeset for help on using the changeset viewer.