mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
fix issues and recommendations based on @zuki @lap82 comments
This commit is contained in:
@@ -10,6 +10,7 @@ package org.dspace.app.itemmarking;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.dspace.app.util.Util;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Bundle;
|
||||
import org.dspace.content.Item;
|
||||
@@ -67,9 +68,9 @@ public class ItemMarkingAvailabilityBitstreamStrategy implements ItemMarkingExtr
|
||||
+ bitstream.getSequenceID() + "/";
|
||||
|
||||
try {
|
||||
bsLink = bsLink + encodeBitstreamName(bitstream.getName(), Constants.DEFAULT_ENCODING);
|
||||
bsLink = bsLink + Util.encodeBitstreamName(bitstream.getName(), Constants.DEFAULT_ENCODING);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -86,68 +87,5 @@ public class ItemMarkingAvailabilityBitstreamStrategy implements ItemMarkingExtr
|
||||
|
||||
public void setNonAvailableImageName(String nonAvailableImageName) {
|
||||
this.nonAvailableImageName = nonAvailableImageName;
|
||||
}
|
||||
|
||||
public static String encodeBitstreamName(String stringIn, String encoding) throws java.io.UnsupportedEncodingException {
|
||||
// FIXME: This should be moved elsewhere, as it is used outside the UI
|
||||
StringBuffer out = new StringBuffer();
|
||||
|
||||
final String[] pctEncoding = { "%00", "%01", "%02", "%03", "%04",
|
||||
"%05", "%06", "%07", "%08", "%09", "%0a", "%0b", "%0c", "%0d",
|
||||
"%0e", "%0f", "%10", "%11", "%12", "%13", "%14", "%15", "%16",
|
||||
"%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d", "%1e", "%1f",
|
||||
"%20", "%21", "%22", "%23", "%24", "%25", "%26", "%27", "%28",
|
||||
"%29", "%2a", "%2b", "%2c", "%2d", "%2e", "%2f", "%30", "%31",
|
||||
"%32", "%33", "%34", "%35", "%36", "%37", "%38", "%39", "%3a",
|
||||
"%3b", "%3c", "%3d", "%3e", "%3f", "%40", "%41", "%42", "%43",
|
||||
"%44", "%45", "%46", "%47", "%48", "%49", "%4a", "%4b", "%4c",
|
||||
"%4d", "%4e", "%4f", "%50", "%51", "%52", "%53", "%54", "%55",
|
||||
"%56", "%57", "%58", "%59", "%5a", "%5b", "%5c", "%5d", "%5e",
|
||||
"%5f", "%60", "%61", "%62", "%63", "%64", "%65", "%66", "%67",
|
||||
"%68", "%69", "%6a", "%6b", "%6c", "%6d", "%6e", "%6f", "%70",
|
||||
"%71", "%72", "%73", "%74", "%75", "%76", "%77", "%78", "%79",
|
||||
"%7a", "%7b", "%7c", "%7d", "%7e", "%7f", "%80", "%81", "%82",
|
||||
"%83", "%84", "%85", "%86", "%87", "%88", "%89", "%8a", "%8b",
|
||||
"%8c", "%8d", "%8e", "%8f", "%90", "%91", "%92", "%93", "%94",
|
||||
"%95", "%96", "%97", "%98", "%99", "%9a", "%9b", "%9c", "%9d",
|
||||
"%9e", "%9f", "%a0", "%a1", "%a2", "%a3", "%a4", "%a5", "%a6",
|
||||
"%a7", "%a8", "%a9", "%aa", "%ab", "%ac", "%ad", "%ae", "%af",
|
||||
"%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7", "%b8",
|
||||
"%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf", "%c0", "%c1",
|
||||
"%c2", "%c3", "%c4", "%c5", "%c6", "%c7", "%c8", "%c9", "%ca",
|
||||
"%cb", "%cc", "%cd", "%ce", "%cf", "%d0", "%d1", "%d2", "%d3",
|
||||
"%d4", "%d5", "%d6", "%d7", "%d8", "%d9", "%da", "%db", "%dc",
|
||||
"%dd", "%de", "%df", "%e0", "%e1", "%e2", "%e3", "%e4", "%e5",
|
||||
"%e6", "%e7", "%e8", "%e9", "%ea", "%eb", "%ec", "%ed", "%ee",
|
||||
"%ef", "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
|
||||
"%f8", "%f9", "%fa", "%fb", "%fc", "%fd", "%fe", "%ff" };
|
||||
|
||||
byte[] bytes = stringIn.getBytes(encoding);
|
||||
|
||||
for (int i = 0; i < bytes.length; i++)
|
||||
{
|
||||
// Any unreserved char or "/" goes through unencoded
|
||||
if ((bytes[i] >= 'A' && bytes[i] <= 'Z')
|
||||
|| (bytes[i] >= 'a' && bytes[i] <= 'z')
|
||||
|| (bytes[i] >= '0' && bytes[i] <= '9') || bytes[i] == '-'
|
||||
|| bytes[i] == '.' || bytes[i] == '_' || bytes[i] == '~'
|
||||
|| bytes[i] == '/')
|
||||
{
|
||||
out.append((char) bytes[i]);
|
||||
}
|
||||
else if (bytes[i] >= 0)
|
||||
{
|
||||
// encode other chars (byte code < 128)
|
||||
out.append(pctEncoding[bytes[i]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// encode other chars (byte code > 127, so it appears as
|
||||
// negative in Java signed byte data type)
|
||||
out.append(pctEncoding[256 + bytes[i]]);
|
||||
}
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
}
|
@@ -485,7 +485,7 @@ public class BrowseListTag extends TagSupport
|
||||
}
|
||||
else if (field.startsWith("mark_"))
|
||||
{
|
||||
metadata = getMarkingMarkup(hrq, items[i], field);
|
||||
metadata = UIUtil.getMarkingMarkup(hrq, items[i], field);
|
||||
}
|
||||
else if (metadataArray.length > 0)
|
||||
{
|
||||
@@ -918,76 +918,4 @@ public class BrowseListTag extends TagSupport
|
||||
throw new JspException("Server does not support DSpace's default encoding. ", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* generate the (X)HTML required to show the item signing */
|
||||
private String getMarkingMarkup(HttpServletRequest hrq, BrowseItem item, String markType)
|
||||
throws JspException
|
||||
{
|
||||
try
|
||||
{
|
||||
Context c = UIUtil.obtainContext(hrq);
|
||||
|
||||
String mark = markType.replace("mark_", "");
|
||||
|
||||
ItemMarkingInfo markInfo = new DSpace()
|
||||
.getServiceManager()
|
||||
.getServiceByName(
|
||||
ItemMarkingExtractor.class.getName()+"."+mark,
|
||||
ItemMarkingExtractor.class)
|
||||
.getItemMarkingInfo(c, Item.find(c, item.getID()));
|
||||
|
||||
StringBuffer markFrag = new StringBuffer();
|
||||
|
||||
if (markInfo!=null && markInfo.getImageName()!=null){
|
||||
|
||||
//Link
|
||||
if (markInfo.getLink()!=null && !markInfo.getLink().trim().equals("")){
|
||||
markFrag.append("<a href=\"")
|
||||
.append(((HttpServletRequest)pageContext.getRequest()).getContextPath()+"/" + markInfo.getLink())
|
||||
.append("\">");
|
||||
}
|
||||
|
||||
markFrag.append("<img class=\""+markType+"_img\" src=\""+ ((HttpServletRequest)pageContext.getRequest()).getContextPath()+"/")
|
||||
.append(markInfo.getImageName()).append("\"");
|
||||
if (markInfo.getTooltip()!=null){
|
||||
markFrag.append(" title=\"")
|
||||
.append(LocaleSupport.getLocalizedMessage(pageContext, markInfo.getTooltip()))
|
||||
.append("\"");
|
||||
}
|
||||
markFrag.append("/>");
|
||||
|
||||
//Link
|
||||
if (markInfo.getLink()!=null && !markInfo.getLink().trim().equals("")){
|
||||
markFrag.append("</a>");
|
||||
}
|
||||
}
|
||||
else if (markInfo!=null && markInfo.getClassInfo()!=null){
|
||||
//Link
|
||||
if (markInfo.getLink()!=null && !markInfo.getLink().trim().equals("")){
|
||||
markFrag.append("<a href=\"")
|
||||
.append(((HttpServletRequest)pageContext.getRequest()).getContextPath()+"/" + markInfo.getLink())
|
||||
.append("\">");
|
||||
}
|
||||
|
||||
markFrag.append("<div class=\""+markType+"_class" + " " + markInfo.getClassInfo() + "\" ");
|
||||
if (markInfo.getTooltip()!=null){
|
||||
markFrag.append(" title=\"")
|
||||
.append(LocaleSupport.getLocalizedMessage(pageContext, markInfo.getTooltip()))
|
||||
.append("\"");
|
||||
}
|
||||
markFrag.append("/>");
|
||||
|
||||
//Link
|
||||
if (markInfo.getLink()!=null && !markInfo.getLink().trim().equals("")){
|
||||
markFrag.append("</a>");
|
||||
}
|
||||
}
|
||||
|
||||
return markFrag.toString();
|
||||
}
|
||||
catch (SQLException sqle)
|
||||
{
|
||||
throw new JspException(sqle.getMessage(), sqle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -450,7 +450,7 @@ public class ItemListTag extends TagSupport
|
||||
}
|
||||
else if (field.startsWith("mark_"))
|
||||
{
|
||||
metadata = getMarkingMarkup(hrq, items[i], field);
|
||||
metadata = UIUtil.getMarkingMarkup(hrq, items[i], field);
|
||||
}
|
||||
if (metadataArray.length > 0)
|
||||
{
|
||||
@@ -893,76 +893,4 @@ public class ItemListTag extends TagSupport
|
||||
throw new JspException("Server does not support DSpace's default encoding. ", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* generate the (X)HTML required to show the item signing */
|
||||
private String getMarkingMarkup(HttpServletRequest hrq, Item item, String markType)
|
||||
throws JspException
|
||||
{
|
||||
try
|
||||
{
|
||||
Context c = UIUtil.obtainContext(hrq);
|
||||
|
||||
String mark = markType.replace("mark_", "");
|
||||
|
||||
ItemMarkingInfo markInfo = new DSpace()
|
||||
.getServiceManager()
|
||||
.getServiceByName(
|
||||
ItemMarkingExtractor.class.getName()+"."+mark,
|
||||
ItemMarkingExtractor.class)
|
||||
.getItemMarkingInfo(c, Item.find(c, item.getID()));
|
||||
|
||||
StringBuffer markFrag = new StringBuffer();
|
||||
|
||||
if (markInfo!=null && markInfo.getImageName()!=null){
|
||||
|
||||
//Link
|
||||
if (markInfo.getLink()!=null && !markInfo.getLink().trim().equals("")){
|
||||
markFrag.append("<a href=\"")
|
||||
.append(((HttpServletRequest)pageContext.getRequest()).getContextPath()+"/" + markInfo.getLink())
|
||||
.append("\">");
|
||||
}
|
||||
|
||||
markFrag.append("<img class=\""+markType+"_img\" src=\""+ ((HttpServletRequest)pageContext.getRequest()).getContextPath()+"/")
|
||||
.append(markInfo.getImageName()).append("\"");
|
||||
if (markInfo.getTooltip()!=null){
|
||||
markFrag.append(" title=\"")
|
||||
.append(LocaleSupport.getLocalizedMessage(pageContext, markInfo.getTooltip()))
|
||||
.append("\"");
|
||||
}
|
||||
markFrag.append("/>");
|
||||
|
||||
//Link
|
||||
if (markInfo.getLink()!=null && !markInfo.getLink().trim().equals("")){
|
||||
markFrag.append("</a>");
|
||||
}
|
||||
}
|
||||
else if (markInfo!=null && markInfo.getClassInfo()!=null){
|
||||
//Link
|
||||
if (markInfo.getLink()!=null && !markInfo.getLink().trim().equals("")){
|
||||
markFrag.append("<a href=\"")
|
||||
.append(((HttpServletRequest)pageContext.getRequest()).getContextPath()+"/" + markInfo.getLink())
|
||||
.append("\">");
|
||||
}
|
||||
|
||||
markFrag.append("<div class=\""+markType+"_class" + " " + markInfo.getClassInfo() + "\" ");
|
||||
if (markInfo.getTooltip()!=null){
|
||||
markFrag.append(" title=\"")
|
||||
.append(LocaleSupport.getLocalizedMessage(pageContext, markInfo.getTooltip()))
|
||||
.append("\"");
|
||||
}
|
||||
markFrag.append("/>");
|
||||
|
||||
//Link
|
||||
if (markInfo.getLink()!=null && !markInfo.getLink().trim().equals("")){
|
||||
markFrag.append("</a>");
|
||||
}
|
||||
}
|
||||
|
||||
return markFrag.toString();
|
||||
}
|
||||
catch (SQLException sqle)
|
||||
{
|
||||
throw new JspException(sqle.getMessage(), sqle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,21 +22,28 @@ import javax.mail.internet.MimeUtility;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.jstl.core.Config;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.itemmarking.ItemMarkingExtractor;
|
||||
import org.dspace.app.itemmarking.ItemMarkingInfo;
|
||||
import org.dspace.app.util.Util;
|
||||
import org.dspace.authenticate.AuthenticationManager;
|
||||
import org.dspace.browse.BrowseItem;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.DCDate;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.Email;
|
||||
import org.dspace.core.I18nUtil;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.utils.DSpace;
|
||||
|
||||
/**
|
||||
* Miscellaneous UI utility methods
|
||||
@@ -470,4 +477,105 @@ public class UIUtil extends Util
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the (X)HTML required to show the item marking. Based on the markType it tries to find
|
||||
* the corresponding item marking Strategy on the iem_marking.xml Spring configuration file in order
|
||||
* to apply it to the item.
|
||||
* This method is used in BrowseListTag and ItemListTag to du the actual item marking in browse
|
||||
* and search results
|
||||
*
|
||||
* @param hrq The servlet request
|
||||
* @param dso The DSpaceObject to mark (it can be a BrowseItem or an Item)
|
||||
* @param markType the type of the mark.
|
||||
* @return
|
||||
* @throws JspException
|
||||
*/
|
||||
public static String getMarkingMarkup(HttpServletRequest hrq, DSpaceObject dso, String markType)
|
||||
throws JspException
|
||||
{
|
||||
try
|
||||
{
|
||||
String contextPath = hrq.getContextPath();
|
||||
|
||||
Context c = UIUtil.obtainContext(hrq);
|
||||
|
||||
Item item = null;
|
||||
if (dso instanceof BrowseItem){
|
||||
item = Item.find(c, dso.getID());
|
||||
}
|
||||
else if (dso instanceof Item){
|
||||
item = (Item)dso;
|
||||
}
|
||||
|
||||
String mark = markType.replace("mark_", "");
|
||||
|
||||
ItemMarkingInfo markInfo = new DSpace()
|
||||
.getServiceManager()
|
||||
.getServiceByName(
|
||||
ItemMarkingExtractor.class.getName()+"."+mark,
|
||||
ItemMarkingExtractor.class)
|
||||
.getItemMarkingInfo(c, item);
|
||||
|
||||
StringBuffer markFrag = new StringBuffer();
|
||||
|
||||
String localizedTooltip = null;
|
||||
if (markInfo.getTooltip()!=null){
|
||||
localizedTooltip = org.dspace.core.I18nUtil.getMessage(markInfo.getTooltip(), hrq.getLocale());
|
||||
}
|
||||
|
||||
String markLink = markInfo.getLink();
|
||||
|
||||
if (markInfo!=null && markInfo.getImageName()!=null){
|
||||
|
||||
//Link
|
||||
if (StringUtils.isNotEmpty(markLink)){
|
||||
markFrag.append("<a href=\"")
|
||||
.append(contextPath+"/" + markLink)
|
||||
.append("\">");
|
||||
}
|
||||
|
||||
markFrag.append("<img class=\""+markType+"_img\" src=\""+ contextPath+"/")
|
||||
.append(markInfo.getImageName()).append("\"");
|
||||
if (StringUtils.isNotEmpty(localizedTooltip)){
|
||||
markFrag.append(" title=\"")
|
||||
.append(localizedTooltip)
|
||||
.append("\"");
|
||||
}
|
||||
markFrag.append("/>");
|
||||
|
||||
//Link
|
||||
if (StringUtils.isNotEmpty(markLink)){
|
||||
markFrag.append("</a>");
|
||||
}
|
||||
}
|
||||
else if (markInfo!=null && markInfo.getClassInfo()!=null){
|
||||
//Link
|
||||
if (StringUtils.isNotEmpty(markLink)){
|
||||
markFrag.append("<a href=\"")
|
||||
.append(contextPath+"/" + markLink)
|
||||
.append("\">");
|
||||
}
|
||||
|
||||
markFrag.append("<div class=\""+markType+"_class" + " " + markInfo.getClassInfo() + "\" ");
|
||||
if (StringUtils.isNotEmpty(localizedTooltip)){
|
||||
markFrag.append(" title=\"")
|
||||
.append(localizedTooltip)
|
||||
.append("\"");
|
||||
}
|
||||
markFrag.append("/>");
|
||||
|
||||
//Link
|
||||
if (StringUtils.isNotEmpty(markLink)){
|
||||
markFrag.append("</a>");
|
||||
}
|
||||
}
|
||||
|
||||
return markFrag.toString();
|
||||
}
|
||||
catch (SQLException sqle)
|
||||
{
|
||||
throw new JspException(sqle.getMessage(), sqle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user