diff --git a/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/servlet/DisplayStatisticsServlet.java b/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/servlet/DisplayStatisticsServlet.java index 97f779bef9..03b4cf3bc4 100644 --- a/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/servlet/DisplayStatisticsServlet.java +++ b/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/servlet/DisplayStatisticsServlet.java @@ -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 { diff --git a/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/servlet/HandleServlet.java b/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/servlet/HandleServlet.java index 2f37401e4b..51fedccc8a 100644 --- a/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/servlet/HandleServlet.java +++ b/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/servlet/HandleServlet.java @@ -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); diff --git a/dspace-jspui/dspace-jspui-webapp/src/main/webapp/collection-home.jsp b/dspace-jspui/dspace-jspui-webapp/src/main/webapp/collection-home.jsp index 9dfa1502f7..c011a71513 100644 --- a/dspace-jspui/dspace-jspui-webapp/src/main/webapp/collection-home.jsp +++ b/dspace-jspui/dspace-jspui-webapp/src/main/webapp/collection-home.jsp @@ -211,10 +211,7 @@
-
- - " /> -
+
<%= intro %> diff --git a/dspace-jspui/dspace-jspui-webapp/src/main/webapp/community-home.jsp b/dspace-jspui/dspace-jspui-webapp/src/main/webapp/community-home.jsp index 39eae5a230..89cae89625 100644 --- a/dspace-jspui/dspace-jspui-webapp/src/main/webapp/community-home.jsp +++ b/dspace-jspui/dspace-jspui-webapp/src/main/webapp/community-home.jsp @@ -407,10 +407,7 @@
-
- - " /> -
+
diff --git a/dspace-jspui/dspace-jspui-webapp/src/main/webapp/display-item.jsp b/dspace-jspui/dspace-jspui-webapp/src/main/webapp/display-item.jsp index e3ceae42aa..16493612df 100644 --- a/dspace-jspui/dspace-jspui-webapp/src/main/webapp/display-item.jsp +++ b/dspace-jspui/dspace-jspui-webapp/src/main/webapp/display-item.jsp @@ -201,10 +201,7 @@ %>
-
- - " /> -
+
<%