NIHVIVO-918 Merge 5377 from branch

This commit is contained in:
jeb228 2010-07-22 14:10:30 +00:00
parent 38130db941
commit 50cc897669
8 changed files with 38 additions and 12 deletions

View file

@ -2,6 +2,9 @@
package edu.cornell.mannlib.vitro.webapp.filestorage;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -42,7 +45,8 @@ public class FileServingHelper {
/**
* <p>
* Combine the URI and the filename to produce a relative URL for the file
* (relative to the context of the webapp).
* (relative to the context of the webapp). The filename will be URLEncoded
* as needed.
* </p>
* <p>
* This should involve stripping the default namespace from the front of the
@ -66,6 +70,13 @@ public class FileServingHelper {
return uri;
}
String remainder = uri.substring(DEFAULT_NAMESPACE.length());
try {
filename = URLEncoder.encode(filename, "UTF-8");
} catch (UnsupportedEncodingException e) {
log.error("No UTF-8 encoding?", e); // Can't happen.
}
String separator = remainder.endsWith("/") ? "" : "/";
return FILE_PATH + remainder + separator + filename;
}

View file

@ -9,6 +9,8 @@ import static javax.servlet.http.HttpServletResponse.SC_OK;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
@ -95,7 +97,8 @@ public class FileServingServlet extends VitroHttpServlet {
response.sendError(SC_NOT_FOUND, ("File not found: " + path));
return;
}
if (!actualFilename.equals(requestedFilename)) {
if (!actualFilename.equals(requestedFilename)
&& !actualFilename.equals(decode(requestedFilename))) {
log.warn("The requested filename does not match the "
+ "actual filename; request: '" + path + "', actual: '"
+ actualFilename + "'");
@ -163,6 +166,18 @@ public class FileServingServlet extends VitroHttpServlet {
}
}
/**
* The filename may have been encoded for URL transfer.
*/
private String decode(String filename) {
try {
return URLDecoder.decode(filename, "UTF-8");
} catch (UnsupportedEncodingException e) {
log.error("How did this happen?", e);
return filename;
}
}
/**
* A POST request is treated the same as a GET request.
*/

View file

@ -223,8 +223,8 @@ if (VitroRequestPrep.isSelfEditing(request) || LoginFormBean.loggedIn(request, L
<div class="datatypeProperties">
<div class="datatypePropertyValue">
<div class="statementWrap thumbnail">
<a class="image" href="<c:url value='${entity.imageUrl}'/>">
<img src="<c:url value='${entity.thumbUrl}'/>"
<a class="image" href="${pageContext.request.contextPath}${entity.imageUrl}">
<img src="${pageContext.request.contextPath}${entity.thumbUrl}"
title="click to view larger image"
alt="" width="115"/>
</a>

View file

@ -49,7 +49,7 @@
<c:param name="uri" value="${ent.URI}"/>
</c:url>
<a class="image" href="<c:out value="${entityHref}"/>" >
<img width="${IMG_WIDTH}" src="<c:url value='${ent.thumbUrl}'/>" title="${ent.name}" alt="${ent.name}" />
<img width="${IMG_WIDTH}" src="${pageContext.request.contextPath}${ent.thumbUrl}" title="${ent.name}" alt="${ent.name}" />
</a>
</td>
</c:if>

View file

@ -80,7 +80,7 @@
<c:param name="home" value="${sessionScope.currentPortalId}"/>
<c:param name="uri" value="${ent.URI}"/>
</c:url>
<div class="tab-image"><a class="image" href="<c:out value="${imageHref}"/>"><img width="${IMG_WIDTH}" src="<c:url value='${ent.thumbUrl}'/>" title="${ent.name}" alt="" /></a></div>
<div class="tab-image"><a class="image" href="<c:out value="${imageHref}"/>"><img width="${IMG_WIDTH}" src="${pageContext.request.contextPath}${ent.thumbUrl}" title="${ent.name}" alt="" /></a></div>
<c:if test="${not empty ent.blurb}"><div class='blurb'>${ent.blurb}</div></c:if>
</c:when>
<c:otherwise>

View file

@ -41,8 +41,8 @@
</c:forEach>
<c:if test="${!empty entity.thumbUrl}">
<div class="thumbnail">
<c:if test="${!empty entity.imageUrl}"><a target="_new" href="<c:url value='${entity.imageUrl}'/>"></c:if>
<img src="<c:url value='${entity.thumbUrl}'/>" title="click to view larger image in new window" width="150">
<c:if test="${!empty entity.imageUrl}"><a target="_new" href="${pageContext.request.contextPath}${entity.imageUrl}"></c:if>
<img src="${pageContext.request.contextPath}${entity.thumbUrl}" title="click to view larger image in new window" width="150">
<c:if test="${!empty entity.imageUrl}"></a></c:if>
</div>
</c:if>

View file

@ -22,9 +22,9 @@
<div id="dashboard"<c:if test="${showCuratorEdits}"> class="loggedIn"</c:if>>
<c:if test="${!empty entity.thumbUrl}">
<c:if test="${!empty entity.imageUrl}">
<a class="image" href="<c:url value='${entity.imageUrl}'/>">
<a class="image" href="${pageContext.request.contextPath}${entity.imageUrl}">
</c:if>
<img class="headshot" src="<c:url value='${entity.thumbUrl}'/>" title="click to view larger image in new window" alt="" width="150"/>
<img class="headshot" src="${pageContext.request.contextPath}${entity.thumbUrl}" title="click to view larger image in new window" alt="" width="150"/>
<c:if test="${!empty entity.imageUrl}"></a></c:if>
</c:if>

View file

@ -22,9 +22,9 @@
<div id="dashboard"<c:if test="${showCuratorEdits}"> class="loggedIn"</c:if>>
<c:if test="${!empty entity.thumbUrl}">
<c:if test="${!empty entity.imageUrl}">
<a class="image" href="<c:url value='${entity.imageUrl}'/>">
<a class="image" href="${pageContext.request.contextPath}${entity.imageUrl}">
</c:if>
<img class="headshot" src="<c:url value='${entity.thumbUrl}'/>" title="click to view larger image in new window" alt="" width="150"/>
<img class="headshot" src="${pageContext.request.contextPath}${entity.thumbUrl}" title="click to view larger image in new window" alt="" width="150"/>
<c:if test="${!empty entity.imageUrl}"></a></c:if>
</c:if>