Created
June 20, 2012 21:07
-
-
Save aschweer/2962222 to your computer and use it in GitHub Desktop.
Show mimetype icons on DSpace XMLUI item page (files section)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:stylesheet | |
xmlns:i18n="http://apache.org/cocoon/i18n/2.1" | |
xmlns:dri="http://di.tamu.edu/DRI/1.0/" | |
xmlns:mets="http://www.loc.gov/METS/" | |
xmlns:dim="http://www.dspace.org/xmlns/dspace/dim" | |
xmlns:xlink="http://www.w3.org/TR/xlink/" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" | |
xmlns:atom="http://www.w3.org/2005/Atom" | |
xmlns:ore="http://www.openarchives.org/ore/terms/" | |
xmlns:oreatom="http://www.openarchives.org/ore/atom/" | |
xmlns="http://www.w3.org/1999/xhtml" | |
xmlns:xalan="http://xml.apache.org/xalan" | |
xmlns:encoder="xalan://java.net.URLEncoder" | |
xmlns:util="org.dspace.app.xmlui.utils.XSLUtils" | |
exclude-result-prefixes="xalan encoder i18n dri mets dim xlink xsl"> | |
<xsl:output indent="yes"/> | |
<xsl:template match="mets:file"> | |
<xsl:param name="context" select="."/> | |
<div class="file-wrapper clearfix"> | |
<div class="thumbnail-wrapper"> | |
<a class="image-link"> | |
<xsl:attribute name="href"> | |
<xsl:value-of select="mets:FLocat[@LOCTYPE='URL']/@xlink:href"/> | |
</xsl:attribute> | |
<xsl:choose> | |
<xsl:when test="$context/mets:fileSec/mets:fileGrp[@USE='THUMBNAIL']/ | |
mets:file[@GROUPID=current()/@GROUPID]"> | |
<img alt="Thumbnail"> | |
<xsl:attribute name="src"> | |
<xsl:value-of select="$context/mets:fileSec/mets:fileGrp[@USE='THUMBNAIL']/ | |
mets:file[@GROUPID=current()/@GROUPID]/mets:FLocat[@LOCTYPE='URL']/@xlink:href"/> | |
</xsl:attribute> | |
</img> | |
</xsl:when> | |
<xsl:when test="@MIMETYPE = 'application/pdf'"> | |
<!--<img alt="Icon" src="{concat($theme-path, '/images/mime.png')}" style="height: {$thumbnail.maxheight}px;"/>--> | |
<img alt="[PDF]" src="{concat($theme-path, '/images/mimes/pdf.png')}" style="height: 48px;" width="48" height="48" title="PDF file"/> | |
</xsl:when> | |
<xsl:when test="starts-with(@MIMETYPE, 'audio/')"> | |
<img alt="[Audio]" src="{concat($theme-path, '/images/mimes/audio.png')}" style="height: 48px;" width="48" height="48" title="Audio file"/> | |
</xsl:when> | |
<xsl:when test="starts-with(@MIMETYPE, 'video/')"> | |
<img alt="[Video]" src="{concat($theme-path, '/images/mimes/video.png')}" style="height: 48px;" width="48" height="48" title="Video file"/> | |
</xsl:when> | |
<xsl:when test="starts-with(@MIMETYPE, 'image/')"> | |
<img alt="[Image]" src="{concat($theme-path, '/images/mimes/image.png')}" style="height: 48px;" width="48" height="48" title="Image file"/> | |
</xsl:when> | |
<xsl:when test="@MIMETYPE = 'application/vnd.ms-powerpoint' or @MIMETYPE = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'"> | |
<img alt="[PP]" src="{concat($theme-path, '/images/mimes/mspowerpoint.png')}" style="height: 48px;" width="48" height="48" title="MS Powerpoint file"/> | |
</xsl:when> | |
<xsl:when test="@MIMETYPE = 'application/vnd.oasis.opendocument.presentation' or @MIMETYPE = 'application/vnd.sun.xml.impress' or @MIMETYPE = 'application/vnd.stardivision.impress'"> | |
<img alt="[Presentation]" src="{concat($theme-path, '/images/mimes/oopresentation.png')}" style="height: 48px;" width="48" height="48" title="Presentation slide deck"/> | |
</xsl:when> | |
<xsl:when test="@MIMETYPE = 'application/msword' or @MIMETYPE = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'"> | |
<img alt="[Word]" src="{concat($theme-path, '/images/mimes/msword.png')}" style="height: 48px;" width="48" height="48" title="MS Word file"/> | |
</xsl:when> | |
<xsl:when test="@MIMETYPE = 'application/vnd.oasis.opendocument.text' or @MIMETYPE = 'application/vnd.sun.xml.writer' or @MIMETYPE = 'application/vnd.stardivision.writer'"> | |
<img alt="[Writer]" src="{concat($theme-path, '/images/mimes/ootext.png')}" style="height: 48px;" width="48" height="48" title="Word processor file"/> | |
</xsl:when> | |
<xsl:when test="@MIMETYPE = 'application/vnd.ms-excel' or @MIMETYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'"> | |
<img alt="[Excel]" src="{concat($theme-path, '/images/mimes/msexcel.png')}" style="height: 48px;" width="48" height="48" title="MS Excel file"/> | |
</xsl:when> | |
<xsl:when test="@MIMETYPE = 'application/vnd.oasis.opendocument.spreadsheet' or @MIMETYPE = 'application/vnd.sun.xml.calc' or @MIMETYPE = 'application/vnd.stardivision.calc'"> | |
<img alt="[Spreadsheet]" src="{concat($theme-path, '/images/mimes/oospreadsheet.png')}" style="height: 48px;" width="48" height="48" title="Spreadsheet"/> | |
</xsl:when> | |
<xsl:when test="@MIMETYPE = 'application/x-iso9660-image'"> | |
<img alt="[ISO]" src="{concat($theme-path, '/images/mimes/iso.png')}" style="height: 48px;" width="48" height="48" title="Disk image"/> | |
</xsl:when> | |
<xsl:when test="@MIMETYPE = 'application/zip'"> | |
<img alt="[ZIP]" src="{concat($theme-path, '/images/mimes/archive.png')}" style="height: 48px;" width="48" height="48" title="ZIP archive"/> | |
</xsl:when> | |
<xsl:when test="@MIMETYPE = 'text/richtext'"> | |
<img alt="[RTF]" src="{concat($theme-path, '/images/mimes/rtf.png')}" style="height: 48px;" width="48" height="48" title="RTF file"/> | |
</xsl:when> | |
<xsl:when test="@MIMETYPE = 'text/xml'"> | |
<img alt="[XML]" src="{concat($theme-path, '/images/mimes/html.png')}" style="height: 48px;" width="48" height="48" title="XML file"/> | |
</xsl:when> | |
<xsl:when test="@MIMETYPE = 'text/html'"> | |
<img alt="[HTML]" src="{concat($theme-path, '/images/mimes/html.png')}" style="height: 48px;" width="48" height="48" title="HTML file"/> | |
</xsl:when> | |
<xsl:when test="starts-with(@MIMETYPE, 'text/')"> | |
<img alt="[Text]" src="{concat($theme-path, '/images/mimes/text.png')}" style="height: 48px;" width="48" height="48" title="Text file"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<img alt="[File]" src="{concat($theme-path, '/images/mime.png')}" style="height: 48px;" width="48" height="48"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</a> | |
</div> | |
<div class="file-metadata" style="height: {$thumbnail.maxheight}px;"> | |
<div> | |
<span class="bold"> | |
<i18n:text>xmlui.dri2xhtml.METS-1.0.item-files-name</i18n:text> | |
<xsl:text>:</xsl:text> | |
</span> | |
<span> | |
<xsl:attribute name="title"><xsl:value-of select="mets:FLocat[@LOCTYPE='URL']/@xlink:title"/></xsl:attribute> | |
<xsl:value-of select="util:shortenString(mets:FLocat[@LOCTYPE='URL']/@xlink:title, 17, 5)"/> | |
</span> | |
</div> | |
<!-- File size always comes in bytes and thus needs conversion --> | |
<div> | |
<span class="bold"> | |
<i18n:text>xmlui.dri2xhtml.METS-1.0.item-files-size</i18n:text> | |
<xsl:text>:</xsl:text> | |
</span> | |
<span> | |
<xsl:choose> | |
<xsl:when test="@SIZE < 1024"> | |
<xsl:value-of select="@SIZE"/> | |
<i18n:text>xmlui.dri2xhtml.METS-1.0.size-bytes</i18n:text> | |
</xsl:when> | |
<xsl:when test="@SIZE < 1024 * 1024"> | |
<xsl:value-of select="substring(string(@SIZE div 1024),1,5)"/> | |
<i18n:text>xmlui.dri2xhtml.METS-1.0.size-kilobytes</i18n:text> | |
</xsl:when> | |
<xsl:when test="@SIZE < 1024 * 1024 * 1024"> | |
<xsl:value-of select="substring(string(@SIZE div (1024 * 1024)),1,5)"/> | |
<i18n:text>xmlui.dri2xhtml.METS-1.0.size-megabytes</i18n:text> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="substring(string(@SIZE div (1024 * 1024 * 1024)),1,5)"/> | |
<i18n:text>xmlui.dri2xhtml.METS-1.0.size-gigabytes</i18n:text> | |
</xsl:otherwise> | |
</xsl:choose> | |
</span> | |
</div> | |
<!-- Lookup File Type description in local messages.xml based on MIME Type. | |
In the original DSpace, this would get resolved to an application via | |
the Bitstream Registry, but we are constrained by the capabilities of METS | |
and can't really pass that info through. --> | |
<div> | |
<span class="bold"> | |
<i18n:text>xmlui.dri2xhtml.METS-1.0.item-files-format</i18n:text> | |
<xsl:text>:</xsl:text> | |
</span> | |
<span> | |
<xsl:call-template name="getFileTypeDesc"> | |
<xsl:with-param name="mimetype"> | |
<xsl:value-of select="substring-before(@MIMETYPE,'/')"/> | |
<xsl:text>/</xsl:text> | |
<xsl:value-of select="substring-after(@MIMETYPE,'/')"/> | |
</xsl:with-param> | |
</xsl:call-template> | |
</span> | |
</div> | |
<!----> | |
<!-- Display the contents of 'Description' only if bitstream contains a description --> | |
<xsl:if test="mets:FLocat[@LOCTYPE='URL']/@xlink:label != ''"> | |
<div> | |
<span class="bold"> | |
<i18n:text>xmlui.dri2xhtml.METS-1.0.item-files-description</i18n:text> | |
<xsl:text>:</xsl:text> | |
</span> | |
<span> | |
<xsl:attribute name="title"><xsl:value-of select="mets:FLocat[@LOCTYPE='URL']/@xlink:label"/></xsl:attribute> | |
<!--<xsl:value-of select="mets:FLocat[@LOCTYPE='URL']/@xlink:label"/>--> | |
<xsl:value-of select="util:shortenString(mets:FLocat[@LOCTYPE='URL']/@xlink:label, 17, 5)"/> | |
</span> | |
</div> | |
</xsl:if> | |
</div> | |
<div class="file-link" style="height: {$thumbnail.maxheight}px;"> | |
<a> | |
<xsl:attribute name="href"> | |
<xsl:value-of select="mets:FLocat[@LOCTYPE='URL']/@xlink:href"/> | |
</xsl:attribute> | |
<i18n:text>xmlui.dri2xhtml.METS-1.0.item-files-viewOpen</i18n:text> | |
</a> | |
</div> | |
</div> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As used on item pages in OUR Archive.