mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[DS-690] Tidy URL mapping for JSPUI statistics and improve HandleServlet
git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@6106 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -75,15 +75,31 @@ public class DisplayStatisticsServlet extends DSpaceServlet
|
||||
SQLException, AuthorizeException
|
||||
{
|
||||
|
||||
|
||||
DSpaceObject dso = null;
|
||||
String handle = request.getParameter("handle");
|
||||
DSpaceObject dso = HandleManager.resolveToObject(context, handle);
|
||||
|
||||
if(dso == null) {
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
JSPManager.showJSP(request, response, "/error/404.jsp");
|
||||
return;
|
||||
}
|
||||
if("".equals(handle) || handle == null)
|
||||
{
|
||||
// We didn't get passed a handle parameter.
|
||||
// That means we're looking at /handle/*/*/statistics
|
||||
// with handle injected as attribute from HandleServlet
|
||||
handle = (String) request.getAttribute("handle");
|
||||
|
||||
}
|
||||
|
||||
if(handle != null)
|
||||
{
|
||||
dso = HandleManager.resolveToObject(context, handle);
|
||||
}
|
||||
|
||||
if(dso == null)
|
||||
{
|
||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
JSPManager.showJSP(request, response, "/error/404.jsp");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
boolean isItem = false;
|
||||
|
||||
@@ -181,7 +197,6 @@ public class DisplayStatisticsServlet extends DSpaceServlet
|
||||
if(dso instanceof org.dspace.content.Item)
|
||||
{
|
||||
isItem = true;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
@@ -13,6 +13,7 @@ import java.net.URLEncoder;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -66,7 +67,7 @@ import org.jdom.output.XMLOutputter;
|
||||
public class HandleServlet extends DSpaceServlet
|
||||
{
|
||||
/** log4j category */
|
||||
private static Logger log = Logger.getLogger(DSpaceServlet.class);
|
||||
private static Logger log = Logger.getLogger(HandleServlet.class);
|
||||
|
||||
/** For obtaining <meta> elements to put in the <head> */
|
||||
private DisseminationCrosswalk xHTMLHeadCrosswalk;
|
||||
@@ -134,34 +135,56 @@ public class HandleServlet extends DSpaceServlet
|
||||
return;
|
||||
}
|
||||
|
||||
if("/statistics".equals(extraPathInfo))
|
||||
{
|
||||
// Check configuration properties, auth, etc.
|
||||
// Inject handle attribute
|
||||
log.info(LogManager.getHeader(context, "display_statistics", "handle=" + handle + ", path=" + extraPathInfo));
|
||||
request.setAttribute("handle", handle);
|
||||
|
||||
// Forward to DisplayStatisticsServlet without changing path.
|
||||
RequestDispatcher dispatch = getServletContext().getNamedDispatcher("displaystats");
|
||||
dispatch.forward(request, response);
|
||||
|
||||
// If we don't return here, we keep processing and end up
|
||||
// throwing a NPE when checking community authorization
|
||||
// and firing a usage event for the DSO we're reporting for
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// OK, we have a valid Handle. What is it?
|
||||
if (dso.getType() == Constants.ITEM)
|
||||
{
|
||||
Item item = (Item) dso;
|
||||
|
||||
new DSpace().getEventService().fireEvent(
|
||||
new UsageEvent(
|
||||
UsageEvent.Action.VIEW,
|
||||
request,
|
||||
context,
|
||||
dso));
|
||||
|
||||
// Only use last-modified if this is an anonymous access
|
||||
// - caching content that may be generated under authorisation
|
||||
// is a security problem
|
||||
if (context.getCurrentUser() == null)
|
||||
// do we actually want to display the item, or forward to another page?
|
||||
if ((extraPathInfo == null) || (extraPathInfo.equals("/")))
|
||||
{
|
||||
response.setDateHeader("Last-Modified", item
|
||||
.getLastModified().getTime());
|
||||
Item item = (Item) dso;
|
||||
|
||||
// Check for if-modified-since header
|
||||
long modSince = request.getDateHeader("If-Modified-Since");
|
||||
// Only use last-modified if this is an anonymous access
|
||||
// - caching content that may be generated under authorisation
|
||||
// is a security problem
|
||||
|
||||
if (modSince != -1 && item.getLastModified().getTime() < modSince)
|
||||
if (context.getCurrentUser() == null)
|
||||
{
|
||||
// Item has not been modified since requested date,
|
||||
// hence bitstream has not; return 304
|
||||
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
|
||||
response.setDateHeader("Last-Modified", item
|
||||
.getLastModified().getTime());
|
||||
|
||||
// Check for if-modified-since header
|
||||
|
||||
long modSince = request.getDateHeader("If-Modified-Since");
|
||||
|
||||
if (modSince != -1 && item.getLastModified().getTime() < modSince)
|
||||
{
|
||||
// Item has not been modified since requested date,
|
||||
// hence bitstream has not; return 304
|
||||
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Display the item page
|
||||
displayItem(context, request, response, item, handle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -171,25 +194,16 @@ public class HandleServlet extends DSpaceServlet
|
||||
}
|
||||
else
|
||||
{
|
||||
// Display the item page
|
||||
displayItem(context, request, response, item, handle);
|
||||
// Forward to another servlet
|
||||
request.getRequestDispatcher(extraPathInfo).forward(request,
|
||||
response);
|
||||
}
|
||||
|
||||
}
|
||||
else if (dso.getType() == Constants.COLLECTION)
|
||||
{
|
||||
Collection c = (Collection) dso;
|
||||
|
||||
new DSpace().getEventService().fireEvent(
|
||||
new UsageEvent(
|
||||
UsageEvent.Action.VIEW,
|
||||
request,
|
||||
context,
|
||||
dso));
|
||||
|
||||
//UsageEvent ue = new UsageEvent();
|
||||
//ue.fire(request, context, AbstractUsageEvent.VIEW,
|
||||
// Constants.COLLECTION, dso.getID());
|
||||
|
||||
// Store collection location in request
|
||||
request.setAttribute("dspace.collection", c);
|
||||
|
||||
@@ -225,17 +239,6 @@ public class HandleServlet extends DSpaceServlet
|
||||
{
|
||||
Community c = (Community) dso;
|
||||
|
||||
new DSpace().getEventService().fireEvent(
|
||||
new UsageEvent(
|
||||
UsageEvent.Action.VIEW,
|
||||
request,
|
||||
context,
|
||||
dso));
|
||||
|
||||
//UsageEvent ue = new UsageEvent();
|
||||
//ue.fire(request, context, AbstractUsageEvent.VIEW,
|
||||
// Constants.COMMUNITY, dso.getID());
|
||||
|
||||
// Store collection location in request
|
||||
request.setAttribute("dspace.community", c);
|
||||
|
||||
@@ -395,7 +398,15 @@ public class HandleServlet extends DSpaceServlet
|
||||
suggestEnable = (context.getCurrentUser() == null ? false : true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fire usage event.
|
||||
new DSpace().getEventService().fireEvent(
|
||||
new UsageEvent(
|
||||
UsageEvent.Action.VIEW,
|
||||
request,
|
||||
context,
|
||||
item));
|
||||
|
||||
// Set attributes and display
|
||||
request.setAttribute("suggest.enable", Boolean.valueOf(suggestEnable));
|
||||
request.setAttribute("display.all", Boolean.valueOf(displayAll));
|
||||
@@ -460,6 +471,14 @@ public class HandleServlet extends DSpaceServlet
|
||||
request.setAttribute("remove_button", Boolean.TRUE);
|
||||
}
|
||||
|
||||
// Fire usage event.
|
||||
new DSpace().getEventService().fireEvent(
|
||||
new UsageEvent(
|
||||
UsageEvent.Action.VIEW,
|
||||
request,
|
||||
context,
|
||||
community));
|
||||
|
||||
// Forward to community home page
|
||||
request.setAttribute("community", community);
|
||||
request.setAttribute("collections", collections);
|
||||
@@ -593,6 +612,14 @@ public class HandleServlet extends DSpaceServlet
|
||||
}
|
||||
}
|
||||
|
||||
// Fire usage event.
|
||||
new DSpace().getEventService().fireEvent(
|
||||
new UsageEvent(
|
||||
UsageEvent.Action.VIEW,
|
||||
request,
|
||||
context,
|
||||
collection));
|
||||
|
||||
// Forward to collection home page
|
||||
request.setAttribute("collection", collection);
|
||||
request.setAttribute("community", community);
|
||||
|
@@ -211,10 +211,7 @@
|
||||
</tr>
|
||||
</table>
|
||||
<div align="center">
|
||||
<form method="get" action="<%= request.getContextPath() %>/displaystats">
|
||||
<input type="hidden" name="handle" value="<%= collection.getHandle() %>"/>
|
||||
<input type="submit" name="submit_simple" value="<fmt:message key="jsp.collection-home.display-statistics"/>" />
|
||||
</form>
|
||||
<a class="statisticsLink" href="<%= request.getContextPath() %>/handle/<%= collection.getHandle() %>/statistics"><fmt:message key="jsp.collection-home.display-statistics"/></a>
|
||||
</div>
|
||||
|
||||
<%= intro %>
|
||||
|
@@ -407,10 +407,7 @@
|
||||
</dspace:sidebar>
|
||||
|
||||
<div align="center">
|
||||
<form method="get" action="<%= request.getContextPath() %>/displaystats">
|
||||
<input type="hidden" name="handle" value="<%= community.getHandle() %>"/>
|
||||
<input type="submit" name="submit_simple" value="<fmt:message key="jsp.community-home.display-statistics"/>" />
|
||||
</form>
|
||||
<a class="statisticsLink" href="<%= request.getContextPath() %>/handle/<%= community.getHandle() %>/statistics"><fmt:message key="jsp.community-home.display-statistics"/></a>
|
||||
</div>
|
||||
|
||||
|
||||
|
@@ -201,10 +201,7 @@
|
||||
%>
|
||||
|
||||
<div align="center">
|
||||
<form method="get" action="<%= request.getContextPath() %>/displaystats">
|
||||
<input type="hidden" name="handle" value="<%= handle %>"/>
|
||||
<input type="submit" name="submit_simple" value="<fmt:message key="jsp.display-item.display-statistics"/>" />
|
||||
</form>
|
||||
<a class="statisticsLink" href="<%= request.getContextPath() %>/handle/<%= handle %>/statistics"><fmt:message key="jsp.display-item.display-statistics"/></a>
|
||||
</div>
|
||||
|
||||
<%
|
||||
|
Reference in New Issue
Block a user