问题
I would like to shorten the file name that is being displayed in the simple item view.
If I have a very long file name, this is displayed in the simple item record:
This example file name is shortened if you view the full item record:
But if you edit this item and click the Item Bitstreams tab, the file name is being displayed like this:
My goal is to apply what is being displayed in the edit bitstream (the 3rd picture) to the simple and full item view. I don't know where this transformation is being generated. I looked at administrative.xsl and I can't find anything on the shortening of the file name. Please advice on how to achieve this or where to look for this transformation.
回答1:
The rewrite of the file name in the "Item Bitstreams" tab is done in Java code, not in the XSL. It's here: EditItemBitstreamsForm.java.
Your item page screenshot looks like you're working in XMLUI / Mirage 2, is that right? Your best bet is to use the shortenString
method in org.dspace.app.xmlui.utils.XSLUtils
(code). Actually maybe you aren't 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:
Thanks to Andrea for the answer. Here's my code and how I used it.
I created a new method shortenFileName
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
like this:
<xsl:value-of select="util:shortenFileName(mets:FLocat[@LOCTYPE='URL']/@xlink:title, ' … ', 20)" />
The file name now looked like this:
来源:https://stackoverflow.com/questions/31799754/how-to-shorten-filename-displayed-in-dspace