001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.web.controllers.core;
034:
035: import org.jfree.chart.ChartRenderingInfo;
036: import org.jfree.chart.ChartUtilities;
037: import org.jfree.chart.JFreeChart;
038: import org.jfree.chart.entity.StandardEntityCollection;
039:
040: import org.libresource.Libresource;
041:
042: import org.libresource.core.CoreConstants;
043: import org.libresource.core.interfaces.LibresourceStatsService;
044:
045: import org.libresource.web.Controller;
046:
047: import java.io.ByteArrayOutputStream;
048: import java.io.PrintWriter;
049: import java.io.StringWriter;
050:
051: import java.net.URI;
052:
053: import javax.servlet.http.HttpServletRequest;
054: import javax.servlet.http.HttpServletResponse;
055:
056: public class ProjectStatsController implements Controller {
057: public Object process(URI resource, HttpServletRequest request,
058: HttpServletResponse response) throws Exception {
059: LibresourceStatsService libresourceStatsService = (LibresourceStatsService) Libresource
060: .getService(CoreConstants.SERVICE_STAT);
061:
062: try {
063: request.setAttribute("stats", libresourceStatsService
064: .getProjectStats(resource));
065: } catch (Exception e) {
066: }
067:
068: if (StatsCache.getImage(resource,
069: DrawPieChartHelper.MOST_ACTIVE_USERS) == null) {
070: JFreeChart chart = DrawPieChartHelper.drawChart(resource,
071: DrawPieChartHelper.MOST_ACTIVE_USERS);
072: ChartRenderingInfo info = new ChartRenderingInfo(
073: new StandardEntityCollection());
074: ByteArrayOutputStream baos = new ByteArrayOutputStream();
075: ChartUtilities.writeChartAsPNG(baos, chart, 500, 250, info);
076:
077: StringWriter writer = new StringWriter();
078: ChartUtilities.writeImageMap(new PrintWriter(writer),
079: DrawPieChartHelper.MOST_ACTIVE_USERS, info);
080: StatsCache.putItem(baos.toByteArray(), writer.toString(),
081: resource, DrawPieChartHelper.MOST_ACTIVE_USERS);
082: }
083:
084: request.setAttribute(DrawPieChartHelper.MOST_ACTIVE_USERS,
085: StatsCache.getMap(resource,
086: DrawPieChartHelper.MOST_ACTIVE_USERS));
087:
088: if (StatsCache.getImage(resource,
089: DrawPieChartHelper.PREFERED_RESOURCES) == null) {
090: JFreeChart chart = DrawPieChartHelper.drawChart(resource,
091: DrawPieChartHelper.PREFERED_RESOURCES);
092: ChartRenderingInfo info = new ChartRenderingInfo(
093: new StandardEntityCollection());
094: ByteArrayOutputStream baos = new ByteArrayOutputStream();
095: ChartUtilities.writeChartAsPNG(baos, chart, 500, 250, info);
096:
097: StringWriter writer = new StringWriter();
098: ChartUtilities.writeImageMap(new PrintWriter(writer),
099: DrawPieChartHelper.PREFERED_RESOURCES, info);
100: StatsCache.putItem(baos.toByteArray(), writer.toString(),
101: resource, DrawPieChartHelper.PREFERED_RESOURCES);
102: }
103:
104: request.setAttribute(DrawPieChartHelper.PREFERED_RESOURCES,
105: StatsCache.getMap(resource,
106: DrawPieChartHelper.PREFERED_RESOURCES));
107:
108: if (StatsCache.getImage(resource,
109: DrawPieChartHelper.MOST_ACTIVE_RESOURCES) == null) {
110: JFreeChart chart = DrawPieChartHelper.drawChart(resource,
111: DrawPieChartHelper.MOST_ACTIVE_RESOURCES);
112: ChartRenderingInfo info = new ChartRenderingInfo(
113: new StandardEntityCollection());
114: ByteArrayOutputStream baos = new ByteArrayOutputStream();
115: ChartUtilities.writeChartAsPNG(baos, chart, 500, 250, info);
116:
117: StringWriter writer = new StringWriter();
118: ChartUtilities.writeImageMap(new PrintWriter(writer),
119: DrawPieChartHelper.MOST_ACTIVE_RESOURCES, info);
120: StatsCache.putItem(baos.toByteArray(), writer.toString(),
121: resource, DrawPieChartHelper.MOST_ACTIVE_RESOURCES);
122: }
123:
124: request.setAttribute(DrawPieChartHelper.MOST_ACTIVE_RESOURCES,
125: StatsCache.getMap(resource,
126: DrawPieChartHelper.MOST_ACTIVE_RESOURCES));
127:
128: return "/pages/modules/core/projectStats.jsp";
129: }
130: }
|