[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:
Kim Shepherd
2011-03-04 03:15:24 +00:00
parent 7c465277d8
commit 66573b33b7
5 changed files with 100 additions and 67 deletions

View File

@@ -75,15 +75,31 @@ public class DisplayStatisticsServlet extends DSpaceServlet
SQLException, AuthorizeException SQLException, AuthorizeException
{ {
DSpaceObject dso = null;
String handle = request.getParameter("handle"); String handle = request.getParameter("handle");
DSpaceObject dso = HandleManager.resolveToObject(context, handle);
if(dso == null) { if("".equals(handle) || handle == null)
response.setStatus(HttpServletResponse.SC_NOT_FOUND); {
JSPManager.showJSP(request, response, "/error/404.jsp"); // We didn't get passed a handle parameter.
return; // 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; boolean isItem = false;
@@ -181,7 +197,6 @@ public class DisplayStatisticsServlet extends DSpaceServlet
if(dso instanceof org.dspace.content.Item) if(dso instanceof org.dspace.content.Item)
{ {
isItem = true; isItem = true;
try try
{ {

View File

@@ -13,6 +13,7 @@ import java.net.URLEncoder;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@@ -66,7 +67,7 @@ import org.jdom.output.XMLOutputter;
public class HandleServlet extends DSpaceServlet public class HandleServlet extends DSpaceServlet
{ {
/** log4j category */ /** 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> */ /** For obtaining <meta> elements to put in the <head> */
private DisseminationCrosswalk xHTMLHeadCrosswalk; private DisseminationCrosswalk xHTMLHeadCrosswalk;
@@ -134,34 +135,56 @@ public class HandleServlet extends DSpaceServlet
return; 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? // OK, we have a valid Handle. What is it?
if (dso.getType() == Constants.ITEM) if (dso.getType() == Constants.ITEM)
{ {
Item item = (Item) dso; // do we actually want to display the item, or forward to another page?
if ((extraPathInfo == null) || (extraPathInfo.equals("/")))
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)
{ {
response.setDateHeader("Last-Modified", item Item item = (Item) dso;
.getLastModified().getTime());
// Check for if-modified-since header // Only use last-modified if this is an anonymous access
long modSince = request.getDateHeader("If-Modified-Since"); // - 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, response.setDateHeader("Last-Modified", item
// hence bitstream has not; return 304 .getLastModified().getTime());
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
// 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 else
{ {
@@ -171,25 +194,16 @@ public class HandleServlet extends DSpaceServlet
} }
else else
{ {
// Display the item page // Forward to another servlet
displayItem(context, request, response, item, handle); request.getRequestDispatcher(extraPathInfo).forward(request,
response);
} }
} }
else if (dso.getType() == Constants.COLLECTION) else if (dso.getType() == Constants.COLLECTION)
{ {
Collection c = (Collection) dso; 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 // Store collection location in request
request.setAttribute("dspace.collection", c); request.setAttribute("dspace.collection", c);
@@ -225,17 +239,6 @@ public class HandleServlet extends DSpaceServlet
{ {
Community c = (Community) dso; 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 // Store collection location in request
request.setAttribute("dspace.community", c); request.setAttribute("dspace.community", c);
@@ -395,7 +398,15 @@ public class HandleServlet extends DSpaceServlet
suggestEnable = (context.getCurrentUser() == null ? false : true); 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 // Set attributes and display
request.setAttribute("suggest.enable", Boolean.valueOf(suggestEnable)); request.setAttribute("suggest.enable", Boolean.valueOf(suggestEnable));
request.setAttribute("display.all", Boolean.valueOf(displayAll)); request.setAttribute("display.all", Boolean.valueOf(displayAll));
@@ -460,6 +471,14 @@ public class HandleServlet extends DSpaceServlet
request.setAttribute("remove_button", Boolean.TRUE); 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 // Forward to community home page
request.setAttribute("community", community); request.setAttribute("community", community);
request.setAttribute("collections", collections); 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 // Forward to collection home page
request.setAttribute("collection", collection); request.setAttribute("collection", collection);
request.setAttribute("community", community); request.setAttribute("community", community);

View File

@@ -211,10 +211,7 @@
</tr> </tr>
</table> </table>
<div align="center"> <div align="center">
<form method="get" action="<%= request.getContextPath() %>/displaystats"> <a class="statisticsLink" href="<%= request.getContextPath() %>/handle/<%= collection.getHandle() %>/statistics"><fmt:message key="jsp.collection-home.display-statistics"/></a>
<input type="hidden" name="handle" value="<%= collection.getHandle() %>"/>
<input type="submit" name="submit_simple" value="<fmt:message key="jsp.collection-home.display-statistics"/>" />
</form>
</div> </div>
<%= intro %> <%= intro %>

View File

@@ -407,10 +407,7 @@
</dspace:sidebar> </dspace:sidebar>
<div align="center"> <div align="center">
<form method="get" action="<%= request.getContextPath() %>/displaystats"> <a class="statisticsLink" href="<%= request.getContextPath() %>/handle/<%= community.getHandle() %>/statistics"><fmt:message key="jsp.community-home.display-statistics"/></a>
<input type="hidden" name="handle" value="<%= community.getHandle() %>"/>
<input type="submit" name="submit_simple" value="<fmt:message key="jsp.community-home.display-statistics"/>" />
</form>
</div> </div>

View File

@@ -201,10 +201,7 @@
%> %>
<div align="center"> <div align="center">
<form method="get" action="<%= request.getContextPath() %>/displaystats"> <a class="statisticsLink" href="<%= request.getContextPath() %>/handle/<%= handle %>/statistics"><fmt:message key="jsp.display-item.display-statistics"/></a>
<input type="hidden" name="handle" value="<%= handle %>"/>
<input type="submit" name="submit_simple" value="<fmt:message key="jsp.display-item.display-statistics"/>" />
</form>
</div> </div>
<% <%