How to display thumbnails from harvested items in DSpace?

徘徊边缘 提交于 2019-12-10 10:18:19

问题


I am trying to display the thumbnails from harvested items. The settings I have for the harvesting options is Harvest metadata and references to bitstreams (requires ORE support). When looking for the code on how DSpace displays the filenames and file sizes of the bitstreams of the harvested items in simple view, I found that in https://github.com/DSpace/DSpace/blob/dspace-6.1/dspace-xmlui-mirage2/src/main/webapp/xsl/aspect/artifactbrowser/item-view.xsl#L375-L378

<!-- Special case for handling ORE resource maps stored as DSpace bitstreams -->
<xsl:when test="//mets:fileSec/mets:fileGrp[@USE='ORE']">
  <xsl:apply-templates select="//mets:fileSec/mets:fileGrp[@USE='ORE']" mode="itemSummaryView-DIM" />
</xsl:when>

and for the full item record view in https://github.com/DSpace/DSpace/blob/dspace-6.1/dspace-xmlui-mirage2/src/main/webapp/xsl/aspect/artifactbrowser/item-view.xsl#L81-L84.

<!-- Special case for handling ORE resource maps stored as DSpace bitstreams -->
<xsl:when test="./mets:fileSec/mets:fileGrp[@USE='ORE']">
  <xsl:apply-templates select="./mets:fileSec/mets:fileGrp[@USE='ORE']" mode="itemDetailView-DIM" />
</xsl:when>

So it seems that code found in item-view.xsl is calling the template match found in ORE.xsl.

Now, looking at a sample mets.xml file of a harvested item specifically in //mets:fileSec/mets:fileGrp[@USE='ORE'], we can see that it is referencing the ORE.xml in /bitstream/handle/10862/3360/ORE.xml.

<mets:fileSec>
  <mets:fileGrp USE="ORE">
    <mets:file GROUPID="group_file_f148a8ad-b7ad-49fe-8b4b-0d3893d2c351" CHECKSUM="7afebcfcf393395503377219395e3926" MIMETYPE="text/xml" SIZE="4137" ID="file_f148a8ad-b7ad-49fe-8b4b-0d3893d2c351" CHECKSUMTYPE="MD5">
      <mets:FLocat LOCTYPE="URL" xlink:href="/bitstream/handle/10862/3360/ORE.xml?sequence=1&isAllowed=y" xlink:type="locator" xlink:title="ORE.xml"/>
    </mets:file>
  </mets:fileGrp>
</mets:fileSec>

Based on the template match found in ORE.xsl, we can see that the file names and file size was generated from this code:

<xsl:template match="mets:fileGrp[@USE='ORE']" mode="itemSummaryView-DIM">
    <xsl:variable name="AtomMapURL" select="concat('cocoon:/',substring-after(mets:file/mets:FLocat[@LOCTYPE='URL']//@*[local-name(.)='href'],$context-path))"/>
    <div class="item-page-field-wrapper table">
        <h5>
            <i18n:text>xmlui.dri2xhtml.METS-1.0.item-files-viewOpen</i18n:text>
        </h5>

        <xsl:for-each select="document($AtomMapURL)/atom:entry/atom:link[@rel='http://www.openarchives.org/ore/terms/aggregates']">
            <xsl:variable name="link_href" select="@href"/>
            <xsl:if test="/atom:entry/oreatom:triples/rdf:Description[@rdf:about=$link_href][dcterms:description='ORIGINAL']
                        or not(/atom:entry/oreatom:triples/rdf:Description[@rdf:about=$link_href])">
                <xsl:call-template name="itemSummaryView-DIM-file-section-entry">
                    <xsl:with-param name="href" select="@href" />
                    <xsl:with-param name="mimetype" select="@type" />
                    <xsl:with-param name="label-1" select="'title'" />
                    <xsl:with-param name="label-2" select="'title'" />
                    <xsl:with-param name="title" select="@title" />
                    <xsl:with-param name="label" select="@title" />
                    <xsl:with-param name="size" select="@length" />
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
    </div>
</xsl:template>

Viewing the /bitstream/handle/10862/3360/ORE.xml, we can see that aside from the ORIGINAL bundle, the TEXT and THUMBNAIL bundles were also captured when it was harvested.

<atom:link href="https://repository.seafdec.org.ph/bitstream/10862/152/1/ediblecrustacea.pdf" length="2310365" rel="http://www.openarchives.org/ore/terms/aggregates" title="ediblecrustacea.pdf" type="application/pdf"/>
<atom:link href="https://repository.seafdec.org.ph/bitstream/10862/152/4/edible-crust-errata.pdf" length="177699" rel="http://www.openarchives.org/ore/terms/aggregates" title="edible-crust-errata.pdf" type="application/pdf"/>
<oreatom:triples>
  <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="http://hdl.handle.net/10862/152/ore.xml#atom">
    <rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceItem"/>
    <dcterms:modified>2011-06-07T06:45:26Z</dcterms:modified>
  </rdf:Description>
  <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="https://repository.seafdec.org.ph/bitstream/10862/152/35/edible-crust-errata.pdf.txt">
    <rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceBitstream"/>
    <dcterms:description>TEXT</dcterms:description>
  </rdf:Description>
  <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="https://repository.seafdec.org.ph/bitstream/10862/152/36/ediblecrustacea.pdf.txt">
    <rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceBitstream"/>
    <dcterms:description>TEXT</dcterms:description>
  </rdf:Description>
  <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="https://repository.seafdec.org.ph/bitstream/10862/152/1/ediblecrustacea.pdf">
    <rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceBitstream"/>
    <dcterms:description>ORIGINAL</dcterms:description>
  </rdf:Description>
  <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="https://repository.seafdec.org.ph/bitstream/10862/152/4/edible-crust-errata.pdf">
    <rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceBitstream"/>
    <dcterms:description>ORIGINAL</dcterms:description>
  </rdf:Description>
  <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="https://repository.seafdec.org.ph/bitstream/10862/152/32/ediblecrustacea.pdf.jpg">
    <rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceBitstream"/>
    <dcterms:description>THUMBNAIL</dcterms:description>
  </rdf:Description>
  <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="https://repository.seafdec.org.ph/bitstream/10862/152/33/edible-crust-errata.pdf.jpg">
    <rdf:type rdf:resource="http://www.dspace.org/objectModel/DSpaceBitstream"/>
    <dcterms:description>THUMBNAIL</dcterms:description>
  </rdf:Description>
</oreatom:triples>

Now my goal is to capture and reuse the url found in /atom:entry/oreatom:triples/rdf:Description[@rdf:about][dcterms:description='THUMBNAIL'] and make it as the src of the thumbnail found in the code for the itemSummaryView-DIM-thumnail and mets:filetemplate, sort of hotlinking to the original thumbnail. By the way, the Files in this item view is not that nice anyway so...

With regards to the displaying of thumbnail in simple view, I'm thinking of having an <xsl:when test="//mets:fileSec/mets:fileGrp[@USE='ORE']"> in the itemSummaryView-DIM-thumbnail template ie:

        <xsl:choose>
            <xsl:when test="//mets:fileSec/mets:fileGrp[@USE='THUMBNAIL']">
                <xsl:variable name="src">
                    <xsl:choose>
                        <xsl:when test="/mets:METS/mets:fileSec/mets:fileGrp[@USE='THUMBNAIL']/mets:file[@GROUPID=../../mets:fileGrp[@USE='CONTENT']/mets:file[@GROUPID=../../mets:fileGrp[@USE='THUMBNAIL']/mets:file/@GROUPID][1]/@GROUPID]">
                            <xsl:value-of
                                    select="/mets:METS/mets:fileSec/mets:fileGrp[@USE='THUMBNAIL']/mets:file[@GROUPID=../../mets:fileGrp[@USE='CONTENT']/mets:file[@GROUPID=../../mets:fileGrp[@USE='THUMBNAIL']/mets:file/@GROUPID][1]/@GROUPID]/mets:FLocat[@LOCTYPE='URL']/@xlink:href"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of
                                    select="//mets:fileSec/mets:fileGrp[@USE='THUMBNAIL']/mets:file/mets:FLocat[@LOCTYPE='URL']/@xlink:href"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>
                <!-- Checking if Thumbnail is restricted and if so, show a restricted image --> 
                <xsl:choose>
                    <xsl:when test="contains($src,'isAllowed=n')"/>
                    <xsl:otherwise>
                        <img class="img-thumbnail" alt="Thumbnail">
                            <xsl:attribute name="src">
                                <xsl:value-of select="$src"/>
                            </xsl:attribute>
                        </img>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:when test="//mets:fileSec/mets:fileGrp[@USE='ORE']">
              <xsl:apply-templates select="//mets:fileSec/mets:fileGrp[@USE='ORE']" mode="itemSummaryView-DIM-thumbnail" />
            </xsl:when>
            <xsl:otherwise>
                <img class="img-thumbnail" alt="Thumbnail">
                    <xsl:attribute name="data-src">
                        <xsl:text>holder.js/100%x</xsl:text>
                        <xsl:value-of select="$thumbnail.maxheight"/>
                        <xsl:text>/text:No Thumbnail</xsl:text>
                    </xsl:attribute>
                </img>
            </xsl:otherwise>
        </xsl:choose>

My problem now is that I don't know how to reference the url for the thumbnail in the ORE.xml file. I noticed also that the name and file size were extracted from the /atom:entry/atom:link[@rel='http://www.openarchives.org/ore/terms/aggregates'] based from the ORE.xsl code above.

Thanks in advance!

UPDATE

Here's what I did: I modify the [dspace]/config/crosswalks/oai/metadataFormats/ore.xsl of the source server such that it will expose the thumbnails in the <atom:link rel="http://www.openarchives.org/ore/terms/aggregates"> portion of OAI output when using ore as the metadata format, but I have to clean the cache of oai and do a full reimport of OAI in the source server. Also, I have to reset and import the harvest from the harvesting server to include the new generated ORE.xml files. The modification I did was to change line number 67 of ore.xsl from

<xsl:if test="doc:field[@name='name']/text() = 'ORIGINAL'">

into:

<xsl:if test="doc:field[@name='name']/text() = 'ORIGINAL' or doc:field[@name='name']/text() = 'THUMBNAIL'">

Then in item-view.xsl, I included this line in the <xsl:template name="itemSummaryView-DIM-thumbnail">:

Then, in [dspace]/webapps/xmlui/themes/Mirage2/xsl/aspect/artifactbrowser/ORE.xsl I include these lines:

<xsl:template match="mets:fileGrp[@USE='ORE']" mode="itemSummaryView-DIM-thumbnail">
    <xsl:variable name="AtomMapURL" select="concat('cocoon:/',substring-after(mets:file/mets:FLocat[@LOCTYPE='URL']//@*[local-name(.)='href'],$context-path))"/>
    <xsl:apply-templates select="document($AtomMapURL)/atom:entry/atom:link[@rel='http://www.openarchives.org/ore/terms/aggregates']" mode="itemSummaryView-DIM-thumbnail"/>
</xsl:template>

<xsl:template match="atom:link[@rel='http://www.openarchives.org/ore/terms/aggregates']" mode="itemSummaryView-DIM-thumbnail">
    <xsl:variable name="link_href" select="@href"/>
    <xsl:if test="/atom:entry/oreatom:triples/rdf:Description[@rdf:about=$link_href][dcterms:description='THUMBNAIL' and position() = 1]
                or not(/atom:entry/oreatom:triples/rdf:Description[@rdf:about=$link_href])">
    <img class="img-thumbnail" alt="Thumbnail">
        <xsl:attribute name="src">
            <xsl:value-of select="@href"/>
        </xsl:attribute>
    </img>
    </xsl:if>
</xsl:template>

This worked except that in cases where there are multiple thumbnails in the source item, it will also show more than one thumbnails even though I have in my test condition <xsl:if test="/atom:entry/oreatom:triples/rdf:Description[@rdf:about=$link_href][dcterms:description='THUMBNAIL' and position() = 1] or not(/atom:entry/oreatom:triples/rdf:Description[@rdf:about=$link_href])">. See screenshot below:

Also, I would rather not modify the ore.xsl in the crosswalk directory of the source server hence this post: Extract attribute value if child node contains this text

UPDATE 2 - Thumbnail is now displayed in simple item view

What I did:

In <xsl:template name="itemSummaryView-DIM-thumbnail">, I inserted the code below after line# 195:

<xsl:when test="//mets:fileSec/mets:fileGrp[@USE='ORE']">
    <xsl:apply-templates select="//mets:fileSec/mets:fileGrp[@USE='ORE']" mode="itemSummaryView-DIM-thumbnail" />
</xsl:when>

Then, I added this templates in ORE.xsl:

<xsl:template match="mets:fileGrp[@USE='ORE']" mode="itemSummaryView-DIM-thumbnail">
    <xsl:variable name="AtomMapURL" select="concat('cocoon:/',substring-after(mets:file/mets:FLocat[@LOCTYPE='URL']//@*[local-name(.)='href'],$context-path))"/>
    <xsl:apply-templates select="document($AtomMapURL)/atom:entry/oreatom:triples" mode="itemSummaryView-DIM-thumbnail"/>
</xsl:template>

<xsl:template match="oreatom:triples" mode="itemSummaryView-DIM-thumbnail">
    <xsl:if test="/atom:entry/oreatom:triples/rdf:Description[dcterms:description='THUMBNAIL']
                or not(/atom:entry/oreatom:triples/rdf:Description)">
        <img class="img-thumbnail" alt="Thumbnail">
            <xsl:attribute name="src">
                <xsl:value-of select="rdf:Description[boolean(@rdf:about) and
                   .//dcterms:description[. = 'THUMBNAIL']][1]/@rdf:about"/>
            </xsl:attribute>
        </img>
    </xsl:if>
</xsl:template>

My harvested item is now displaying the thumbnail in item summary view:

It would really be great if I can also make the thumbnails display in the item list and search results but for now, I can't figure out how to match and select the thumbnail url. I don't know how to reference them from within the <xsl:template match="mets:fileSec" mode="artifact-preview"> template.

来源:https://stackoverflow.com/questions/51738232/how-to-display-thumbnails-from-harvested-items-in-dspace

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!