OutputStream os = null;
try
{
os = new FileOutputStream(tmpfile);
WritableWorkbook workbook = Workbook.createWorkbook(os);
int r = 0;
WritableSheet sheet = null;
int sheetNumber = 0;
int oldType = -1;
for (StatSubscription statSub : statSubscriptions)
{
boolean changedType = false;
if (oldType != statSub.getTypeDef())
{
changedType = true;
r = 0;
}
oldType = statSub.getTypeDef();
SummaryStatBean statdetails = getStatBean(context, service,
statSub);
r++;
if (statdetails == null)
continue;
SummaryStatBean.StatDataBean statDataBean = statdetails
.getData().get(0);
if (changedType)
{
sheet = workbook.createSheet(I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.sheet." + statdetails.getType()),
sheetNumber);
WritableFont labelFont = new WritableFont(
WritableFont.ARIAL, 10, WritableFont.BOLD);
WritableCellFormat cfobj = new WritableCellFormat(labelFont);
sheet.addCell(new Label(
0,
0,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.type"),
cfobj));
sheet.addCell(new Label(
1,
0,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.name"),
cfobj));
sheet.addCell(new Label(
2,
0,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.url"),
cfobj));
sheet.addCell(new Label(
3,
0,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.totalView"),
cfobj));
sheet.addCell(new Label(4, 0, I18nUtil
.getMessage("it.cilea.hku.statistics.Subscribe."
+ sfreq + "View"), cfobj));
int headerCell = 4;
if (statDataBean.isShowSelectedObjectDownload())
{
sheet.addCell(new Label(
++headerCell,
0,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.totalDownload"),
cfobj));
sheet.addCell(new Label(++headerCell, 0, I18nUtil
.getMessage("it.cilea.hku.statistics.Subscribe."
+ sfreq + "Download"), cfobj));
}
for (String topKey : statDataBean
.getPeriodAndTotalTopView().keySet())
{
if (!statDataBean.getPeriodAndTotalTopView()
.get(topKey).isEmpty())
{
sheet.addCell(new Label(
++headerCell,
0,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.total"
+ topKey + "View"), cfobj));
sheet.addCell(new Label(
++headerCell,
0,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe."
+ sfreq + topKey + "View"), cfobj));
}
}
for (String topKey : statDataBean
.getPeriodAndTotalTopDownload().keySet())
{
if (!statDataBean.getPeriodAndTotalTopDownload()
.get(topKey).isEmpty())
{
sheet.addCell(new Label(
++headerCell,
0,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.total"
+ topKey + "Download"), cfobj));
sheet.addCell(new Label(
++headerCell,
0,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe."
+ sfreq + topKey + "Download"), cfobj));
}
}
for (int i = 0; i < headerCell; i++)
{
final CellView view = sheet.getColumnView(i);
view.setAutosize(true);
sheet.setColumnView(i, view);
}
sheetNumber++;
}
sheet.addCell(new Label(0, r, I18nUtil
.getMessage("it.cilea.hku.statistics.Subscribe.type."
+ statdetails.getType())));
sheet.addCell(new Label(1, r, statdetails.getObjectName()));
sheet.addCell(new Label(2, r, statdetails.getObjectURL()));
if (statDataBean.getTotalSelectedView() == -1)
{
sheet.addCell(new Label(3, r, I18nUtil
.getMessage("it.cilea.hku.statistics.Subscribe.na")));
}
else
{
sheet.addCell(new Label(3, r, new Long(statDataBean
.getTotalSelectedView()).toString()));
}
if (statDataBean.getPeriodSelectedView() == -1)
{
sheet.addCell(new Label(4, r, I18nUtil
.getMessage("it.cilea.hku.statistics.Subscribe.na")));
}
else
{
sheet.addCell(new Label(4, r, new Long(statDataBean
.getPeriodSelectedView()).toString()));
}
int countTopCell = 4;
if (statDataBean.isShowSelectedObjectDownload())
{
if (statDataBean.getTotalSelectedDownload() == -1)
{
sheet.addCell(new Label(
++countTopCell,
r,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.na")));
}
else
{
sheet.addCell(new Label(++countTopCell, r, new Long(
statDataBean.getTotalSelectedDownload())
.toString()));
}
if (statDataBean.getPeriodSelectedDownload() == -1)
{
sheet.addCell(new Label(
++countTopCell,
r,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.na")));
}
else
{
sheet.addCell(new Label(++countTopCell, r, new Long(
statDataBean.getPeriodSelectedDownload())
.toString()));
}
}
for (String topKey : statDataBean.getPeriodAndTotalTopView()
.keySet())
{
List<Long> tmpList = statDataBean
.getPeriodAndTotalTopView().get(topKey);
if (!tmpList.isEmpty())
{
if (tmpList.get(1) == null)
{
sheet.addCell(new Label(
++countTopCell,
r,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.na")));
}
else
{
sheet.addCell(new Label(++countTopCell, r,
new Long(tmpList.get(1)).toString()));
}
}
if (!tmpList.isEmpty())
{
if (tmpList.get(0) == null)
{
sheet.addCell(new Label(
++countTopCell,
r,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.na")));
}
else
{
sheet.addCell(new Label(++countTopCell, r,
new Long(tmpList.get(0)).toString()));
}
}
}
for (String topKey : statDataBean
.getPeriodAndTotalTopDownload().keySet())
{
List<Long> tmpList = statDataBean
.getPeriodAndTotalTopDownload().get(topKey);
if (!tmpList.isEmpty())
{
if (tmpList.get(1) == null)
{
sheet.addCell(new Label(
++countTopCell,
r,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.na")));
}
else
{
sheet.addCell(new Label(++countTopCell, r,
new Long(tmpList.get(1)).toString()));
}
}
if (!tmpList.isEmpty())
{
if (tmpList.get(0) == null)
{
sheet.addCell(new Label(
++countTopCell,
r,
I18nUtil.getMessage("it.cilea.hku.statistics.Subscribe.na")));
}
else
{
sheet.addCell(new Label(++countTopCell, r,
new Long(tmpList.get(0)).toString()));
}
}
}
}
workbook.write();
workbook.close();
}
catch (Exception e)
{
log.error(e.getMessage(), e);
throw new MessagingException(