How to shorten the file name displayed in DSpace

I would like to shorten the file name that appears in the simple element view.

If I have a very long file name, this is displayed in a simple entry for the element:

simple-view

This example file name is abbreviated if you are viewing the full record of an element:

full-record-view

But if you edit this element and go to the Bitstreams Element tab, the file name will be displayed as follows:

enter image description here

My goal is to apply what is displayed in the edit stream (3rd image) to a simple and complete representation of the elements. I do not know where this transformation is created. I looked at Administrative.xsl and I can not find anything about file name abbreviations. Please advise how to achieve this or where to look for this transformation.

+4
source share
2 answers

Rewriting the file name on the Bitstreams Element tab is done in Java code, not XSL. Here: EditItemBitstreamsForm.java .

The screenshot of your page looks like you're working in XMLUI / Mirage 2, right? It is best to use the shortenString method in org.dspace.app.xmlui.utils.XSLUtils ( code ). Actually, maybe you are not using Mirage 2 because Mirage 2 does just that, see item-view.xsl :

 <xsl:value-of select="util:shortenString(mets:FLocat[@LOCTYPE='URL']/@xlink:title, 30, 5)"/> 
+2
source

Thanks Andrea for the answer. Here is my code and how I used it.

I created a new shortenFileName method in org.dspace.app.xmlui.utils.XSLUtils

  public static String shortenFileName(String string, String middle, int targetLength) { targetLength = Math.abs(targetLength); if (string != null && string.length() > targetLength) { // If the file name is too long then shorten it so that it will display nicely. return StringUtils.abbreviateMiddle(string, middle, targetLength); } else return string; } 

and then used it in item-view.xsl as follows:

 <xsl:value-of select="util:shortenFileName(mets:FLocat[@LOCTYPE='URL']/@xlink:title, ' &#8230; ', 20)" /> 

The file name now looks like this:

enter image description here

+1
source

All Articles