Changeset 25805


Ignore:
Timestamp:
2012-06-21T17:42:41+12:00 (12 years ago)
Author:
ak19
Message:

Asking for a piece of metadata like dc.Creator returns all values for dc.Creator. So multiple=true is always the case by default. No multiple=false was defined. Moreover, there was no way of getting a single value, which was the default in GS2 and which returned the first value for the requested metadata. Now multiple is no longer used, as all values are (still) returned by default. Instead the pos attribute has been introduced, which can be the terms first or last, or else it can be a number representing which value for that metadata needs to be returned.

Location:
main/trunk/greenstone3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/Action.java

    r25635 r25805  
    106106            Element elem = (Element) metadata_nodes.item(i);
    107107            StringBuffer metadata = new StringBuffer();
    108             String all = elem.getAttribute("multiple");
     108            String pos = elem.getAttribute("pos");
    109109            String name = elem.getAttribute("name");
    110110            String select = elem.getAttribute("select");
    111111            String sep = elem.getAttribute("separator");
    112             if (all.equals("true"))
    113             {
    114                 metadata.append("all");
     112            if (!pos.equals(""))
     113            {
     114                metadata.append("pos"+pos); // first, last or indexing number
    115115                metadata.append(GSConstants.META_RELATION_SEP);
    116116            }
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java

    r25635 r25805  
    369369    protected String getMetadata(String node_id, DBInfo info, String metadata, String lang)
    370370    {
    371         boolean multiple = false;
     371        String pos = "";
    372372        String relation = "";
    373373        String separator = ", ";
    374         int pos = metadata.indexOf(GSConstants.META_RELATION_SEP);
    375         if (pos == -1)
     374        int index = metadata.indexOf(GSConstants.META_RELATION_SEP);
     375        if (index == -1)
    376376        {
    377377            Vector<String> values = info.getMultiInfo(metadata);
     
    402402        }
    403403
    404         String temp = metadata.substring(0, pos);
    405         metadata = metadata.substring(pos + 1);
    406         // check for all on the front
    407         if (temp.equals("all"))
    408         {
    409             multiple = true;
    410             pos = metadata.indexOf(GSConstants.META_RELATION_SEP);
    411             if (pos == -1)
     404        String temp = metadata.substring(0, index);     
     405        metadata = metadata.substring(index + 1);
     406        // check for pos on the front, indicating which piece of meta the user wants
     407        // pos can be "first", "last" or the position value of the requested piece of metadata
     408        if (temp.startsWith(GSConstants.META_POS))
     409        {
     410            temp = temp.substring(GSConstants.META_POS.length());
     411            pos = temp;
     412           
     413            index = metadata.indexOf(GSConstants.META_RELATION_SEP);
     414            if (index == -1)
    412415            {
    413416                temp = "";
     
    415418            else
    416419            {
    417                 temp = metadata.substring(0, pos);
    418                 metadata = metadata.substring(pos + 1);
     420                temp = metadata.substring(0, index);
     421                metadata = metadata.substring(index + 1);
    419422            }
    420423        }
    421424
    422425        // now check for relational info
    423         if (temp.equals("parent") || temp.equals("root") || temp.equals("ancestors"))
     426        if (temp.equals("parent") || temp.equals("root") || temp.equals("ancestors")
     427             || temp.equals("siblings") || temp.equals("children") || temp.equals("descendants"))
    424428        { // "current" "siblings" "children" "descendants"
     429            // gets all siblings by default
    425430            relation = temp;
    426             pos = metadata.indexOf(GSConstants.META_RELATION_SEP);
    427             if (pos == -1)
     431            index = metadata.indexOf(GSConstants.META_RELATION_SEP);
     432            if (index == -1)
    428433            {
    429434                temp = "";
     
    431436            else
    432437            {
    433                 temp = metadata.substring(0, pos);
    434                 metadata = metadata.substring(pos + 1);
     438                temp = metadata.substring(0, index);
     439                metadata = metadata.substring(index + 1);
    435440            }
    436441        }
     
    474479
    475480        StringBuffer result = new StringBuffer();
    476 
    477         if (!multiple)
    478         {
    479             result.append(this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, MacroResolver.SCOPE_META, relation_id));
     481       
     482        Vector<String> values = relation_info.getMultiInfo(metadata);
     483
     484        if (!pos.equals("")) // if a particular position was specified, so not multiple values for the metadata
     485        {
     486            String meta = "";
     487            if (values != null) {
     488                if(pos.equals(GSConstants.META_FIRST)) {               
     489                    meta = values.firstElement();
     490                } else if(pos.equals(GSConstants.META_LAST)) {
     491                    meta = values.lastElement();
     492                } else {
     493                    int position = Integer.parseInt(pos);
     494                    if(position < values.size()) {         
     495                        meta = values.elementAt(position);
     496                    }
     497                }               
     498            } // else ""
     499                       
     500            result.append(this.macro_resolver.resolve(meta, lang, MacroResolver.SCOPE_META, relation_id));         
    480501        }
    481502        else
    482503        {
    483             // we have multiple meta
    484             Vector<String> values = relation_info.getMultiInfo(metadata);
    485504            if (values != null)
    486505            {
     
    515534            if (relation_info == null)
    516535                return result.toString();
    517             if (!multiple)
    518             {
     536           
     537            values = relation_info.getMultiInfo(metadata);
     538            if (!pos.equals("")) // if a particular position was specified, so not multiple values for the metadata
     539            {
     540                String meta = "";
     541                if (values != null) {
     542                    if(pos.equals(GSConstants.META_FIRST)) {
     543                        meta = values.firstElement();
     544                    } else if(pos.equals(GSConstants.META_LAST)) {
     545                        meta = values.lastElement();
     546                    } else {
     547                        int position = Integer.parseInt(pos);
     548                        if(position < values.size()) {         
     549                            meta = values.elementAt(position);
     550                        }
     551                    }               
     552                } // else ""
     553               
    519554                result.insert(0, separator);
    520                 result.insert(0, this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, MacroResolver.SCOPE_META, relation_id));
     555                result.insert(0, this.macro_resolver.resolve(meta, lang, MacroResolver.SCOPE_META, relation_id));                           
    521556            }
    522557            else
    523558            {
    524                 Vector<String> values = relation_info.getMultiInfo(metadata);
    525559                if (values != null)
    526560                {
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSConstants.java

    r24719 r25805  
    3232    public static final String META_RELATION_SEP = "_";
    3333    public static final String META_SEPARATOR_SEP = "*";
     34    public static final String META_FIRST = "first";
     35    public static final String META_LAST = "last";
     36    public static final String META_POS = "pos";
    3437}
  • main/trunk/greenstone3/web/interfaces/default/transform/config_format.xsl

    r25752 r25805  
    183183
    184184    <xsl:template match="gsf:metadata" mode="get-metadata-name">
    185         <xsl:if test="@multiple='true'">
    186             <xsl:text>all_</xsl:text>
     185        <xsl:if test="@pos">
     186            <xsl:text>pos</xsl:text>
     187            <xsl:value-of select='@pos'/>
     188            <xsl:text>_</xsl:text>
    187189        </xsl:if>
    188190        <xsl:if test='@select'>
     
    191193        </xsl:if>
    192194        <xsl:if test="@separator">
    193             <xsl:text>*</xsl:text>
     195            <xsl:text>*</xsl:text>
    194196            <xsl:value-of select='@separator'/>
    195197            <xsl:text>*_</xsl:text>
     
    197199        <xsl:value-of select="@name"/>
    198200    </xsl:template>
    199  
    200     <xsl:template match="gsf:metadata-old">
     201
     202    <xsl:template match="gsf:metadata-old" mode="get-metadata-name">
     203        <xsl:if test="@multiple='true'">
     204            <xsl:text>all_</xsl:text>
     205        </xsl:if>
     206        <xsl:if test='@select'>
     207            <xsl:value-of select='@select'/>
     208            <xsl:text>_</xsl:text>
     209        </xsl:if>
     210        <xsl:if test="@separator">
     211            <xsl:text>*</xsl:text>
     212            <xsl:value-of select='@separator'/>
     213            <xsl:text>*_</xsl:text>
     214        </xsl:if>
     215        <xsl:value-of select="@name"/>
     216    </xsl:template>
     217 
     218    <xsl:template match="gsf:metadata-older">
    201219        <xslt:value-of disable-output-escaping="yes">
    202220            <xsl:attribute name="select">
Note: See TracChangeset for help on using the changeset viewer.