Changeset 6873


Ignore:
Timestamp:
2004-02-24T11:13:42+13:00 (20 years ago)
Author:
kjdon
Message:

added some code to replace macros that come out of the GDBM db - the replacements need to be specified in the collectionConfig.xml file, at the top level <replace from= to=> in a <replaceList>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Retrieve.java

    r6676 r6873  
    3535import java.util.Set;
    3636import java.util.Iterator;
     37import java.util.ArrayList;
    3738
    3839/** Implements the generic retrieval and classifier services for GS2
     
    7879    protected Element config_info = null; // the xml from the config file
    7980
     81    protected ArrayList replacements = null;
    8082    /** constructor */
    8183    protected GS2Retrieve()
     
    185187        this.format_info_map.put(DOCUMENT_CONTENT_RETRIEVE_SERVICE, this.doc.importNode(display_format, true));
    186188        // shoudl we make a copy?
     189    }
     190
     191    // set up the replacement list
     192    Element replacement_elem = (Element)GSXML.getChildByTagName(extra_info, "replaceList");
     193    if (replacement_elem != null) {
     194        this.replacements = new ArrayList();
     195        NodeList replaces = replacement_elem.getElementsByTagName("replace");
     196        for (int i=0; i<replaces.getLength(); i++) {
     197        Element e = (Element)replaces.item(i);
     198        String from = e.getAttribute("from");
     199        String to = e.getAttribute("to");
     200        System.out.println("replace "+from+" with "+to);
     201        this.replacements.add(from);
     202        this.replacements.add(to);
     203        }
    187204    }
    188205    return true;
     
    746763            String key = (String)it.next();
    747764            String value = info.getInfo(key);
    748             GSXML.addMetadata(this.doc, node_meta_list, key, value);
     765            GSXML.addMetadata(this.doc, node_meta_list, key, replaceMacros(value));
    749766        }
    750767        } else { // just get the selected ones
     
    771788    if (pos ==-1) {
    772789        // just a plain meta entry eg dc.Title
    773         return info.getInfo(metadata);
     790        return replaceMacros((String)info.getInfo(metadata));
    774791    }
    775792   
     
    831848
    832849    if (!multiple) {
    833         result.append(relation_info.getInfo(metadata));
     850        result.append(replaceMacros(relation_info.getInfo(metadata)));
    834851    } else {
    835852        // we have multiple meta
     
    843860            result.append(separator);
    844861            }
    845             result.append(values.elementAt(i));
     862            result.append(replaceMacros((String)values.elementAt(i)));
    846863        }
    847864        }
     
    860877        if (!multiple) {
    861878        result.insert(0, separator);
    862         result.insert(0, relation_info.getInfo(metadata));
     879        result.insert(0, replaceMacros(relation_info.getInfo(metadata)));
    863880        } else {
    864881        Vector values = relation_info.getMultiInfo(metadata);
     
    866883            for (int i=values.size()-1; i>=0; i--) {
    867884            result.insert(0, separator);
    868             result.insert(0, values.elementAt(i));
     885            result.insert(0, replaceMacros((String)values.elementAt(i)));
    869886            }
    870887        }
     
    877894    }
    878895   
     896
     897    protected String replaceMacros(String text) {
     898    if (this.replacements == null) {
     899        return text;
     900    }
     901    for (int i=0; i<this.replacements.size()-1; i+=2) {
     902        String from  = (String)this.replacements.get(i);
     903        String to = (String)this.replacements.get(i+1);
     904        text = text.replaceAll(from, to);
     905    }
     906    return text;
     907    }
    879908    /** Retrieve the content of a document - implemented by concrete subclasses */
    880909    protected abstract Element processDocumentContentRetrieve(Element request);
Note: See TracChangeset for help on using the changeset viewer.