Ignore:
Timestamp:
2011-07-14T21:39:43+12:00 (13 years ago)
Author:
ak19
Message:

Commits for ticket 770 concerning the display of multiple values for a metadata (like dc.Title) when classified by that metadata. So when the user browses by dc.Title, they no longer merely see a doc listed once for each dc.Title assigned but under the same (first retrieved) dc.Title, but they should now see the doc listed once for each dc.Title assigned to it with a different dc.Title value each time.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java

    r23792 r24254  
    4141import java.util.Iterator;
    4242import java.util.ArrayList;
     43import java.util.regex.Matcher;
     44import java.util.regex.Pattern;
    4345
    4446import org.apache.log4j.*;
     
    196198       
    197199    } else {
     200        // prepare regex to work with mdoffset: looking for <offset\d*_>
     201        Pattern pattern = Pattern.compile("offset[0-9]*" + GSConstants.META_RELATION_SEP);
     202
    198203        for (int i=0; i<metadata_names.size(); i++) {
    199204                String meta_name = (String) metadata_names.get(i);
    200205        String value = getMetadata(node_id, info, meta_name, lang);
     206
     207        // Remove the occurrence (if any) in this metaname of the mdoffset number in the pattern <offset\d*_>
     208        // Leaving string "offset" in at this point: it will be handled in config_format.xsl's gsf:metadata template match
     209        Matcher matcher = pattern.matcher(meta_name);
     210        meta_name = matcher.replaceFirst("offset" + GSConstants.META_RELATION_SEP);
     211            //replaceFirst(""); // if removing the occurrence (if any) of entire pattern <offset\d*_> in input     
     212
    201213        GSXML.addMetadata(this.doc, metadata_list, meta_name, value);
    202214        }
     
    317329    protected String getMetadata(String node_id, DBInfo info,
    318330                 String metadata, String lang) {
    319     boolean multiple = false;
     331    String multiple = "false"; // multiple can now be "true", "false" or "offset<number>". It's no longer a boolean
    320332    String relation = "";
    321333    String separator = ", ";
     
    346358    metadata = metadata.substring(pos+1);
    347359    // check for all on the front
    348     if (temp.equals("all")) {
    349         multiple=true;     
     360    if (temp.equals("all") || temp.startsWith("offset")) { // multiple can now be "true", "false" or "offset"
     361        multiple = temp; // multiple=true;
    350362        pos = metadata.indexOf(GSConstants.META_RELATION_SEP);
    351363        if (pos ==-1) {
     
    399411    StringBuffer result = new StringBuffer();
    400412
    401     if (!multiple) {
     413    if (multiple.equals("false")) {
    402414        result.append(this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, MacroResolver.SCOPE_META, relation_id));
    403     } else {
    404         // we have multiple meta
     415    } else if(multiple.startsWith("offset")) { // multiple = offset
     416        String offset = multiple.substring("offset".length(), multiple.length());
     417        int offsetVal = offset.equals("") ? 0 : Integer.parseInt(offset);
     418        String value = relation_info.getInfoOffset(metadata, offsetVal); // what if this metadata is not the one we need to get the offset for? MDTYPE!
     419           // at the moment, do we assume the user will specify retrieving the offset only for such metadata as has an offset?
     420           // At least, getInfoOffset will return the firstelement if the offset exceeds the bounds of the values for this metadata key
     421
     422        result.append(this.macro_resolver.resolve(value, lang, MacroResolver.SCOPE_META, relation_id));
     423       
     424    } else { // multiple = true, we have multiple meta     
    405425        Vector values = relation_info.getMultiInfo(metadata);
    406         if (values != null) {
     426        if (values != null) {
    407427        boolean first = true;
    408428        for (int i=0; i<values.size(); i++) {
     
    415435        }
    416436        }
    417           logger.info(result);
     437        logger.info(result);
    418438    }
    419439    // if not ancestors, then this is all we do
     
    428448        relation_info = this.coll_db.getInfo(relation_id);
    429449        if (relation_info == null) return result.toString();
    430         if (!multiple) {
     450        if (multiple.equals("false")) { //if (!multiple)
    431451        result.insert(0, separator);
    432452        result.insert(0, this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, MacroResolver.SCOPE_META, relation_id));
Note: See TracChangeset for help on using the changeset viewer.