2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
39 /* ===========================================================================================
40 * This class is part of <I>RAPTOR (Rapid Application Programming Tool for OLAP Reporting)</I>
41 * Raptor : This tool is used to generate different kinds of reports with lot of utilities
42 * ===========================================================================================
44 * -------------------------------------------------------------------------------------------
45 * PdfReportHandler.java - This class is used to generate reports in PDF using iText
46 * -------------------------------------------------------------------------------------------
51 * 14-Jul-2009 : Version 8.4 (Sundar); <UL>
52 * <LI> Dashboard reports can be downloaded with each report occupying separate page including its charts. </LI>
56 package org.onap.portalsdk.analytics.model.pdf;
58 import com.lowagie.text.BadElementException;
59 import com.lowagie.text.Chunk;
60 import com.lowagie.text.Document;
61 import com.lowagie.text.DocumentException;
62 import com.lowagie.text.Element;
63 import com.lowagie.text.ElementTags;
64 import com.lowagie.text.Font;
65 import com.lowagie.text.FontFactory;
66 import com.lowagie.text.Image;
67 import com.lowagie.text.PageSize;
68 import com.lowagie.text.Paragraph;
69 import com.lowagie.text.Phrase;
70 import com.lowagie.text.Rectangle;
71 import com.lowagie.text.html.simpleparser.HTMLWorker;
72 import com.lowagie.text.html.simpleparser.StyleSheet;
73 import com.lowagie.text.pdf.PdfPCell;
74 import com.lowagie.text.pdf.PdfPTable;
75 import com.lowagie.text.pdf.PdfWriter;
76 import java.awt.Color;
78 import java.io.FileNotFoundException;
79 import java.io.IOException;
80 import java.io.OutputStream;
81 import java.io.StringReader;
82 import java.net.MalformedURLException;
83 import java.sql.Connection;
84 import java.sql.ResultSet;
85 import java.sql.ResultSetMetaData;
86 import java.sql.SQLException;
87 import java.sql.Statement;
88 import java.text.SimpleDateFormat;
89 import java.util.ArrayList;
90 import java.util.Calendar;
91 import java.util.Date;
92 import java.util.HashMap;
93 import java.util.Iterator;
94 import java.util.List;
96 import java.util.Map.Entry;
98 import java.util.TimeZone;
99 import java.util.TreeMap;
100 import java.util.Vector;
101 import javax.servlet.http.HttpServletRequest;
102 import javax.servlet.http.HttpServletResponse;
103 import javax.servlet.http.HttpSession;
104 import org.onap.portalsdk.analytics.error.RaptorException;
105 import org.onap.portalsdk.analytics.error.ReportSQLException;
106 import org.onap.portalsdk.analytics.model.ReportHandler;
107 import org.onap.portalsdk.analytics.model.ReportLoader;
108 import org.onap.portalsdk.analytics.model.base.IdNameValue;
109 import org.onap.portalsdk.analytics.model.definition.ReportDefinition;
110 import org.onap.portalsdk.analytics.model.runtime.ReportRuntime;
111 import org.onap.portalsdk.analytics.system.AppUtils;
112 import org.onap.portalsdk.analytics.system.ConnectionUtils;
113 import org.onap.portalsdk.analytics.system.Globals;
114 import org.onap.portalsdk.analytics.util.AppConstants;
115 import org.onap.portalsdk.analytics.util.DataSet;
116 import org.onap.portalsdk.analytics.util.HtmlStripper;
117 import org.onap.portalsdk.analytics.util.Utils;
118 import org.onap.portalsdk.analytics.view.ColumnHeader;
119 import org.onap.portalsdk.analytics.view.ColumnHeaderRow;
120 import org.onap.portalsdk.analytics.view.DataRow;
121 import org.onap.portalsdk.analytics.view.DataValue;
122 import org.onap.portalsdk.analytics.view.HtmlFormatter;
123 import org.onap.portalsdk.analytics.view.ReportData;
124 import org.onap.portalsdk.analytics.view.RowHeader;
125 import org.onap.portalsdk.analytics.view.RowHeaderCol;
126 import org.onap.portalsdk.analytics.xmlobj.DataColumnType;
127 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
130 * @author mwliu and sundar
133 public class PdfReportHandler extends org.onap.portalsdk.analytics.RaptorObject{
135 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PdfReportHandler.class);
138 private HtmlStripper strip = new HtmlStripper();
139 private static final int RetryCreateNewImage = 3;
140 private int retryCreateNewImageCount=0;
142 private String FONT_FAMILY = "Arial";
143 private int FONT_SIZE = 9;
145 public PdfReportHandler() { }
147 public void createPdfFileContent(HttpServletRequest request, HttpServletResponse response, int type) throws IOException, RaptorException {
149 Document document = new Document();
150 ReportHandler rh = new ReportHandler();
151 String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new Date());
152 String pdfFName = "";
153 String user_id = AppUtils.getUserID(request);
155 response.setContentType("application/pdf");
156 OutputStream outStream = response.getOutputStream();
158 String formattedReportName = "";
159 PdfWriter writer = null;
160 ReportRuntime firstReportRuntimeObj = null;
163 ReportRuntime rr = null;
165 rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
167 boolean isDashboard = false;
168 if ((request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)!=null) && ( ((String) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).equals(rr.getReportID())) ) {
173 String reportID = (String) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID);
174 ReportRuntime rrDash = rh.loadReportRuntime(request, reportID, true, 1);
175 pb = preparePdfBean(request,rrDash);
178 document.setPageSize(PageSize.getRectangle(pb.getPagesize()));
179 if(!pb.isPortrait()) // get this from properties file
180 document.setPageSize(document.getPageSize().rotate());
183 writer = PdfWriter.getInstance(document, response.getOutputStream());
184 writer.setPageEvent(new PageEvent(pb));//header,footer,bookmark
187 formattedReportName = new HtmlStripper().stripSpecialCharacters(rrDash.getReportName());
188 if(pb.isAttachmentOfEmail())
189 response.setHeader("Content-disposition", "inline");
191 response.setHeader("Content-disposition", "attachment;filename="+ formattedReportName+formattedDate+user_id+".pdf");
193 pdfFName = "dashboard"+formattedReportName+formattedDate+user_id+".pdf";
194 Map reportRuntimeMap = null;
195 Map reportDataMap = null;
196 Map reportDisplayTypeMap = null;
198 reportRuntimeMap = (TreeMap) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP);
199 reportDataMap = (TreeMap) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP);
200 reportDisplayTypeMap = (TreeMap) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP);
202 if(reportRuntimeMap!=null) {
203 //ServletOutputStream sos = response.getOutputStream();
204 Set setReportRuntime = reportRuntimeMap.entrySet();
205 Set setReportDataMap = reportDataMap.entrySet();
206 Set setReportDisplayTypeMap = reportDisplayTypeMap.entrySet();
208 Iterator iter2 = setReportDataMap.iterator();
209 Iterator iter3 = setReportDisplayTypeMap.iterator();
211 for(Iterator iter = setReportRuntime.iterator(); iter.hasNext(); ) {
213 Map.Entry entryData = (Entry) iter2.next();
214 Map.Entry entry = (Entry) iter.next();
215 Map.Entry entryCheckChart = (Entry) iter3.next();
216 //String rep_id = (String) entry.getKey();
217 ReportRuntime rrDashRep = (ReportRuntime) entry.getValue();
220 firstReportRuntimeObj = (ReportRuntime) entry.getValue();
221 if(pb.isCoverPageIncluded()) {
222 document = paintDashboardCoverPage(document, rrDash, firstReportRuntimeObj, request);
225 ReportData rdDashRep = (ReportData) entryData.getValue();
227 //pb.setDisplayChart(nvl(rr.getChartType()).trim().length()>0 && rr.getDisplayChart());
228 if( ((rrDashRep.getChartType()).trim().length()>0 && rrDashRep.getDisplayChart()) && entryCheckChart.getValue().toString().equals("c")) {
230 pb.setTitle(nvl(rrDashRep.getReportTitle()).length()>0?rrDashRep.getReportTitle():rrDashRep.getReportName());
231 paintPdfImage(request, document,AppUtils.getTempFolderPath()+"cr_"+ pb.getUserId()+"_"+request.getSession().getId()+"_"+rrDashRep.getReportID()+".png", rrDashRep);
234 pb.setTitle(nvl(rrDashRep.getReportTitle()).length()>0?rrDashRep.getReportTitle():rrDashRep.getReportName());
235 paintPdfData(request, document,rdDashRep,rrDashRep, "");
240 } catch (DocumentException dex) {
241 logger.error(EELFLoggerDelegate.errorLogger, "DocumentException in createPdfFileContent", dex);
243 catch (RaptorException rex) {
244 logger.error(EELFLoggerDelegate.errorLogger, "RaptorException in createPdfFileContent", rex);
248 //ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
249 //ReportData rd = (ReportData) request.getSession().getAttribute(AppConstants.RI_REPORT_DATA);
251 ReportData rd = null;
254 if(!nvl(request.getParameter("parent"), "").equals("N"))
255 parent = nvl(request.getParameter("parent"), "");
256 if(parent.startsWith("parent_"))
258 if(parentFlag == 1) {
259 rr = (ReportRuntime) request.getSession().getAttribute(parent+"_rr");
260 rd = (ReportData) request.getSession().getAttribute(parent+"_rd");
263 rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
265 rd = (ReportData) request.getSession().getAttribute(AppConstants.RI_REPORT_DATA);
267 pb = preparePdfBean(request,rr);
268 FONT_FAMILY = rr.getPDFFont();
269 FONT_SIZE = rr.getPDFFontSize();
270 //System.out.println(pb);
272 formattedReportName = new HtmlStripper().stripSpecialCharacters(rr.getReportName());
276 response.setContentType("application/pdf");
277 if(pb.isAttachmentOfEmail())
278 response.setHeader("Content-disposition", "inline");
280 response.setHeader("Content-disposition", "attachment;filename="+ formattedReportName+formattedDate+user_id+".pdf");
282 document.setPageSize(PageSize.getRectangle(pb.getPagesize()));
284 if(!pb.isPortrait()) // get this from properties file
285 document.setPageSize(document.getPageSize().rotate());
289 writer = PdfWriter.getInstance(document, outStream);
290 writer.setPageEvent(new PageEvent(pb));//header,footer,bookmark
293 //System.out.println("Document 1 " + document);
294 if(pb.isCoverPageIncluded()) {
295 document = paintCoverPage(document, rr, request);
298 //boolean isImageRotate = false;
299 //System.out.println("Document 2 " + document);
301 if(pb.isDisplayChart()) {
302 paintPdfImage(request, document,AppUtils.getTempFolderPath()+"cr_"+ pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+".png", rr);
304 //System.out.println("Document 4" + document);
307 if(type == 3 && rr.getSemaphoreList()==null && !(rr.getReportType().equals(AppConstants.RT_CROSSTAB)) ) { //type = 3 is whole
308 String sql_whole = (String) request.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE);
309 returnValue = paintPdfData(request, document, rd, rr, sql_whole);
310 } else if(type == 2) {
311 returnValue = paintPdfData(request, document, rd, rr, "");
313 //String sql_whole = (String) request.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE);
314 int downloadLimit = (rr.getMaxRowsInExcelDownload()>0)?rr.getMaxRowsInExcelDownload():Globals.getDownloadLimit();
315 String action = request.getParameter(AppConstants.RI_ACTION);
317 if(!(rr.getReportType().equals(AppConstants.RT_CROSSTAB)) && !action.endsWith("session"))
318 rd = rr.loadReportData(-1, AppUtils.getUserID(request), downloadLimit,request, false /*download*/);
319 if(rr.getSemaphoreList()!=null) {
320 rd = rr.loadReportData(-1, AppUtils.getUserID(request), downloadLimit,request, true);
321 returnValue = paintPdfData(request, document, rd, rr, "");
323 returnValue = paintPdfData(request, document, rd, rr, rr.getWholeSQL());
330 //paintPdfData(document,rd,rr);
333 } catch (DocumentException de) {
334 logger.error(EELFLoggerDelegate.errorLogger, "DocumentException in createPdfFileContent", de);
340 Runtime runtime = Runtime.getRuntime();
341 logger.debug(EELFLoggerDelegate.debugLogger, ("##### Heap utilization statistics [MB] #####"));
342 logger.debug(EELFLoggerDelegate.debugLogger, ("Used Memory:"
343 + (runtime.maxMemory() - runtime.freeMemory()) / mb));
344 logger.debug(EELFLoggerDelegate.debugLogger, ("Free Memory:"
345 + runtime.freeMemory() / mb));
346 logger.debug(EELFLoggerDelegate.debugLogger, ("Total Memory:" + runtime.totalMemory() / mb));
347 logger.debug(EELFLoggerDelegate.debugLogger, ("Max Memory:" + runtime.maxMemory() / mb));
351 private Document paintCoverPage(Document doc, ReportRuntime rr, HttpServletRequest request) throws IOException, DocumentException {
353 //System.out.println("PDFREPORTHANDLER STARTED ... " );
354 if(nvl(rr.getPdfImg()).length()>0) {
355 Image image1 = Image.getInstance(AppUtils.getExcelTemplatePath()+"../../"+AppUtils.getImgFolderURL()+rr.getPdfImg());
356 image1.scalePercent(20f, 20f);
359 float firstColumnSize = Globals.getCoverPageFirstColumnSize();
360 float[] relativeWidths = {firstColumnSize,1f-firstColumnSize};
361 PdfPTable table = new PdfPTable(relativeWidths);
362 table.getDefaultCell().setBorderWidth(0);
363 addEmptyRows(table,6);
364 HTMLWorker worker = new HTMLWorker(doc);
365 StyleSheet style = new StyleSheet();
366 style.loadTagStyle("body", "leading", "16,0");
367 StringBuffer reportDescrBuf = new StringBuffer("");
368 ArrayList descr = HTMLWorker.parseToList(new StringReader(nvl(rr.getReportDescr())), style);
369 ArrayList paraList = null;
370 if(nvl(rr.getReportTitle()).length()>0) {
371 add2Cells(table,"Report Title : ",nvl(rr.getReportTitle()));
372 if(nvl(rr.getReportSubTitle()).length()>0) {
373 add2Cells(table,"Report Sub-Title : ",nvl(rr.getReportSubTitle()));
374 System.out.println("Adding the report sub-title ");
378 add2Cells(table,"Report Name : ",nvl(rr.getReportName()));
380 if((descr!=null && descr.size()>0)) {
381 paraList = (com.lowagie.text.Paragraph)descr.get(0);
382 for (int i=0 ; i<paraList.size(); i++) {
383 reportDescrBuf.append(paraList.get(i));
387 add2Cells(table,"Description : ",reportDescrBuf.toString());
388 if(Globals.getSessionInfoForTheCoverPage().length()>0) {
389 String nameValue[] = Globals.getSessionInfoForTheCoverPage().split(",");
390 String name=nameValue[0];
391 String value=nameValue[1];
392 add2Cells(table,name+" : ",(AppUtils.getRequestNvlValue(request, value).length()>0?AppUtils.getRequestNvlValue(request, value):nvl((String)request.getSession().getAttribute(value))));
395 if(Globals.isCreatedOwnerInfoNeeded()) {
396 add2Cells(table,"Created By : ",nvl(AppUtils.getUserName(rr.getCreateID())));
397 add2Cells(table,"Owner : ",nvl(AppUtils.getUserName(rr.getOwnerID())));
399 if(Globals.displayLoginIdForDownloadedBy())
400 add2Cells(table,"Downloaded by : ",nvl(AppUtils.getUserBackdoorLoginId(request)));
402 add2Cells(table,"Downloaded by : ",nvl(AppUtils.getUserName(AppUtils.getUserID(request))));
404 addEmptyRows(table,1);
406 boolean isFirstRow = true;
407 ArrayList al = rr.getParamNameValuePairsforPDFExcel(request, 1);
409 al = (ArrayList) request.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
412 Iterator it = al.iterator();
413 addEmptyRows(table,1);
414 //if(!Globals.customizeFormFieldInfo()) {
415 if(rr.getFormFieldComments(request).length()<=0) {
416 while(it.hasNext()) {
419 add2Cells(table, "Run-time Criteria : ", " ");
423 IdNameValue value = (IdNameValue)it.next();
424 if(!value.getId().trim().equals("BLANK"))
425 //System.out.println("PDFREPORTHANDLER " + value.getId()+" : "+value.getName());
426 add2Cells(table, value.getId()+" : ",value.getName().replaceAll("~",","));
427 //add2Cells(table, rr.getFormFieldComments(request), " ");
429 addEmptyRows(table,1);
435 //add2Cells(table, "Run-time Criteria : ", " ");
436 addEmptyRows(table,1);
438 //com.lowagie.text.html.HtmlParser.parse(doc, new StringReader(rr.getFormFieldComments(request)));
439 ArrayList p = HTMLWorker.parseToList(new StringReader(rr.getFormFieldComments(request).replaceAll("~",",")), style);
441 for (int k = 0; k < p.size(); ++k){
442 doc.add((com.lowagie.text.Element)p.get(k));
451 private Document paintDashboardCoverPage(Document doc, ReportRuntime rrDashRep, ReportRuntime firstReportRuntimeObj, HttpServletRequest request) throws IOException, DocumentException {
453 //System.out.println("PDFREPORTHANDLER STARTED ... " );
454 float firstColumnSize = Globals.getCoverPageFirstColumnSize();
455 float[] relativeWidths = {firstColumnSize,1f-firstColumnSize};
456 PdfPTable table = new PdfPTable(relativeWidths);
457 table.getDefaultCell().setBorderWidth(0);
458 addEmptyRows(table,6);
460 add2Cells(table,"Report Name : ",rrDashRep.getReportName());
461 add2Cells(table,"Description : ",rrDashRep.getReportDescr());
462 if(Globals.getSessionInfoForTheCoverPage().length()>0) {
463 String nameValue[] = Globals.getSessionInfoForTheCoverPage().split(",");
464 String name=nameValue[0];
465 String value=nameValue[1];
466 add2Cells(table,name+" : ",(AppUtils.getRequestNvlValue(request, value).length()>0?AppUtils.getRequestNvlValue(request, value):nvl((String)request.getSession().getAttribute(value))));
469 if(Globals.isCreatedOwnerInfoNeeded()) {
470 add2Cells(table,"Created By : ",AppUtils.getUserName(rrDashRep.getCreateID()));
471 add2Cells(table,"Owner : ",AppUtils.getUserName(rrDashRep.getOwnerID()));
473 if(Globals.displayLoginIdForDownloadedBy())
474 add2Cells(table,"Downloaded by : ",AppUtils.getUserBackdoorLoginId(request));
476 add2Cells(table,"Downloaded by : ",AppUtils.getUserName(request));
478 addEmptyRows(table,1);
480 boolean isFirstRow = true;
481 ArrayList al = firstReportRuntimeObj.getParamNameValuePairsforPDFExcel(request, 2);
482 Iterator it = al.iterator();
483 addEmptyRows(table,1);
484 //if(!Globals.customizeFormFieldInfo()) {
485 if(firstReportRuntimeObj.getFormFieldComments(request).length()<=0) {
486 while(it.hasNext()) {
489 add2Cells(table, "Run-time Criteria : ", " ");
493 IdNameValue value = (IdNameValue)it.next();
494 if(!value.getId().trim().equals("BLANK"))
495 //System.out.println("PDFREPORTHANDLER " + value.getId()+" : "+value.getName());
496 add2Cells(table, value.getId()+" : ",value.getName());
497 //add2Cells(table, rr.getFormFieldComments(request), " ");
499 addEmptyRows(table,1);
505 //add2Cells(table, "Run-time Criteria : ", " ");
506 addEmptyRows(table,1);
508 //com.lowagie.text.html.HtmlParser.parse(doc, new StringReader(rr.getFormFieldComments(request)));
509 HTMLWorker worker = new HTMLWorker(doc);
510 StyleSheet style = new StyleSheet();
511 style.loadTagStyle("body", "leading", "16,0");
512 ArrayList p = HTMLWorker.parseToList(new StringReader(firstReportRuntimeObj.getFormFieldComments(request)), style);
514 for (int k = 0; k < p.size(); ++k){
515 doc.add((com.lowagie.text.Element)p.get(k));
524 public static void addEmptyRows(PdfPTable table, int rows) throws DocumentException {
525 for (int i=0; i<rows; i++)
526 for(int j=0;j<table.getAbsoluteWidths().length;j++)
527 table.addCell(new Paragraph(" "));
531 private void add2Cells(PdfPTable table, String key, String value) {
534 cell = new PdfPCell(new Paragraph(key));
535 cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT);
536 cell.setBorderWidth(0f);
539 cell = new PdfPCell(new Paragraph(value));
540 cell.setHorizontalAlignment(Rectangle.ALIGN_LEFT);
541 cell.setBorderWidth(0f);
545 private void paintPdfImage(HttpServletRequest request, Document document, String fileName, ReportRuntime rr)
546 throws DocumentException
549 ArrayList images = getImage(request, fileName,pb.isAttachmentOfEmail()?true:false, rr);
550 //Image image = getImage(request, fileName,pb.isAttachmentOfEmail()?true:false);
551 PdfPTable table = null;
552 PdfPCell cellValue = null;
555 for (int i = 0; i < images.size(); i++) {
556 table = new PdfPTable(1);
557 cellValue = new PdfPCell();
558 cellValue.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
559 Image image = (Image) images.get(i);
560 image.setAlignment(Image.ALIGN_CENTER);
561 //System.out.println("Document 3 " + document + " i-" + i);
564 //System.out.println("Document 31 " + document);
565 cellValue.setImage(image);
566 //table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
567 table.addCell(cellValue);
568 //System.out.println("Document 32 " + document + "table " + table);
570 //System.out.println("Document 33 " + document);
575 private ArrayList getImage(HttpServletRequest request, String fileName, boolean isGenerateNewImage, ReportRuntime rr) {
576 ArrayList images = new ArrayList();
577 if(!isGenerateNewImage) {
579 Image image = Image.getInstance(fileName);
583 catch (MalformedURLException e) {
584 isGenerateNewImage = true;
585 logger.error(EELFLoggerDelegate.errorLogger, "MalformedURLException in getImage", e);
587 catch (BadElementException e) {
588 isGenerateNewImage = true;
589 logger.error(EELFLoggerDelegate.errorLogger, "BadElementException in getImage", e);
590 } catch (FileNotFoundException e) {
591 isGenerateNewImage = true;
592 logger.error(EELFLoggerDelegate.errorLogger, "FileNotFoundException in getImage", e);
593 } catch (IOException e) {
594 isGenerateNewImage = true;
595 logger.error(EELFLoggerDelegate.errorLogger, "IOException in getImage", e);
599 if(isGenerateNewImage && retryCreateNewImageCount<RetryCreateNewImage){
600 retryCreateNewImageCount++;
601 return generateNewImage(request, rr);
602 //return getImage(request,fileName, false);
609 private ArrayList generateNewImage(HttpServletRequest request, ReportRuntime rr) {
610 ArrayList images = new ArrayList();
611 final String MALFORMEDURLEXCEPTION_MSG = "MalformedURLException in generateNewImage";
612 final String BADELEMENTEXCEPTION_MSG = "BadElementException in generateNewImage";
613 final String FILENOTFOUNDEXCEPTION_MSG = "FileNotFoundException in generateNewImage";
614 final String IOEXCEPTION_MSG = "IOException in generateNewImage";
616 //ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
618 if(request.getSession().getAttribute(AppConstants.RI_CHART_DATA)!=null) {
619 ds = (DataSet) request.getSession().getAttribute(AppConstants.RI_CHART_DATA);
621 ds = rr.loadChartData(pb.getUserId(),request);
623 String downloadFileName = "";
624 HashMap additionalChartOptionsMap = new HashMap();
625 String chartType = nvl(rr.getChartType());
626 if(chartType.equals(AppConstants.GT_PIE_MULTIPLE)) {
627 additionalChartOptionsMap.put("multiplePieOrderRow", new Boolean((AppUtils.getRequestNvlValue(request, "multiplePieOrder").length()>0?AppUtils.getRequestNvlValue(request, "multiplePieOrder").equals("row"):rr.isMultiplePieOrderByRow())) );
628 additionalChartOptionsMap.put("multiplePieLabelDisplay", AppUtils.getRequestNvlValue(request, "multiplePieLabelDisplay").length()>0? AppUtils.getRequestNvlValue(request, "multiplePieLabelDisplay"):rr.getMultiplePieLabelDisplay());
629 additionalChartOptionsMap.put("chartDisplay", new Boolean(AppUtils.getRequestNvlValue(request, "chartDisplay").length()>0? AppUtils.getRequestNvlValue(request, "chartDisplay").equals("3D"):rr.isChartDisplayIn3D()));
630 } else if (chartType.equals(AppConstants.GT_BAR_3D)) {
631 additionalChartOptionsMap.put("chartOrientation", new Boolean((AppUtils.getRequestNvlValue(request, "chartOrientation").length()>0?AppUtils.getRequestNvlValue(request, "chartOrientation").equals("vertical"):rr.isVerticalOrientation())) );
632 additionalChartOptionsMap.put("secondaryChartRenderer", AppUtils.getRequestNvlValue(request, "secondaryChartRenderer").length()>0? AppUtils.getRequestNvlValue(request, "secondaryChartRenderer"):rr.getSecondaryChartRenderer());
633 additionalChartOptionsMap.put("chartDisplay", new Boolean(AppUtils.getRequestNvlValue(request, "chartDisplay").length()>0? AppUtils.getRequestNvlValue(request, "chartDisplay").equals("3D"):rr.isChartDisplayIn3D()));
634 additionalChartOptionsMap.put("lastSeriesALineChart", new Boolean(rr.isLastSeriesALineChart()));
635 } else if (chartType.equals(AppConstants.GT_LINE)) {
636 additionalChartOptionsMap.put("chartOrientation", new Boolean((AppUtils.getRequestNvlValue(request, "chartOrientation").length()>0?AppUtils.getRequestNvlValue(request, "chartOrientation").equals("vertical"):rr.isVerticalOrientation())) );
637 //additionalChartOptionsMap.put("secondaryChartRenderer", AppUtils.getRequestNvlValue(request, "secondaryChartRenderer").length()>0? AppUtils.getRequestNvlValue(request, "secondaryChartRenderer"):rr.getSecondaryChartRenderer());
638 additionalChartOptionsMap.put("chartDisplay", new Boolean(AppUtils.getRequestNvlValue(request, "chartDisplay").length()>0? AppUtils.getRequestNvlValue(request, "chartDisplay").equals("3D"):rr.isChartDisplayIn3D()));
639 additionalChartOptionsMap.put("lastSeriesABarChart", new Boolean(rr.isLastSeriesABarChart()));
640 } else if (chartType.equals(AppConstants.GT_TIME_DIFFERENCE_CHART)) {
641 additionalChartOptionsMap.put("intervalFromDate",AppUtils.getRequestNvlValue(request, "intervalFromDate").length()>0?AppUtils.getRequestNvlValue(request, "intervalFromDate"):rr.getIntervalFromdate());
642 additionalChartOptionsMap.put("intervalToDate", AppUtils.getRequestNvlValue(request, "intervalToDate").length()>0? AppUtils.getRequestNvlValue(request, "intervalToDate"):rr.getIntervalTodate());
643 additionalChartOptionsMap.put("intervalLabel", AppUtils.getRequestNvlValue(request, "intervalLabel").length()>0? AppUtils.getRequestNvlValue(request, "intervalLabel"):rr.getIntervalLabel());
644 } else if (chartType.equals(AppConstants.GT_REGRESSION)) {
645 additionalChartOptionsMap.put("regressionType",AppUtils.getRequestNvlValue(request, "regressionType").length()>0?AppUtils.getRequestNvlValue(request, "regressionType"):rr.getLinearRegression());
646 additionalChartOptionsMap.put("linearRegressionColor",nvl(rr.getLinearRegressionColor()));
647 additionalChartOptionsMap.put("expRegressionColor",nvl(rr.getExponentialRegressionColor()));
648 additionalChartOptionsMap.put("maxRegression",nvl(rr.getCustomizedRegressionPoint()));
649 } else if (chartType.equals(AppConstants.GT_STACK_BAR) ||chartType.equals(AppConstants.GT_STACKED_HORIZ_BAR) || chartType.equals(AppConstants.GT_STACKED_HORIZ_BAR_LINES)
650 || chartType.equals(AppConstants.GT_STACKED_VERT_BAR) || chartType.equals(AppConstants.GT_STACKED_VERT_BAR_LINES)
652 additionalChartOptionsMap.put("overlayItemValue",new Boolean(nvl(rr.getOverlayItemValueOnStackBar()).equals("Y")));
654 additionalChartOptionsMap.put("legendPosition", nvl(rr.getLegendPosition()));
655 additionalChartOptionsMap.put("hideToolTips", new Boolean(rr.hideChartToolTips()));
656 additionalChartOptionsMap.put("hideLegend", new Boolean(AppUtils.getRequestNvlValue(request, "hideLegend").length()>0? AppUtils.getRequestNvlValue(request, "hideLegend").equals("Y"):rr.hideChartLegend()));
657 additionalChartOptionsMap.put("labelAngle", nvl(rr.getLegendLabelAngle()));
658 additionalChartOptionsMap.put("maxLabelsInDomainAxis", nvl(rr.getMaxLabelsInDomainAxis()));
659 additionalChartOptionsMap.put("rangeAxisLowerLimit", nvl(rr.getRangeAxisLowerLimit()));
660 additionalChartOptionsMap.put("rangeAxisUpperLimit", nvl(rr.getRangeAxisUpperLimit()));
663 boolean totalOnChart = false;
664 totalOnChart = AppUtils.getRequestNvlValue(request, "totalOnChart").equals("Y");
665 String filename = null;
666 ArrayList graphURL = new ArrayList();
667 ArrayList chartNames = new ArrayList();
668 ArrayList fileNames = new ArrayList();
669 List l = rr.getAllColumns();
670 List lGroups = rr.getAllChartGroups();
671 HashMap mapYAxis = rr.getAllChartYAxis(rr.getReportParamValues());
672 String chartLeftAxisLabel = rr.getFormFieldFilled(nvl(rr.getChartLeftAxisLabel()));
673 String chartRightAxisLabel = rr.getFormFieldFilled(nvl(rr.getChartRightAxisLabel()));
674 int displayTotalOnChart = 0;
675 HashMap formValues = Globals.getRequestParamtersMap(request, false);
677 for (Iterator iterC = l.iterator(); iterC.hasNext();) {
678 DataColumnType dc = (DataColumnType) iterC.next();
679 if(nvl(dc.getColName()).equals(AppConstants.RI_CHART_TOTAL_COL)) {
680 displayTotalOnChart = 1;
684 String legendColumnName = (rr.getChartLegendColumn()!=null)?rr.getChartLegendColumn().getDisplayName():"Legend Column";
690 if(rr.hasSeriesColumn() && chartType.equals(AppConstants.GT_TIME_SERIES) && (lGroups==null || lGroups.size() <= 0)) { /** Check whether Report has only category columns if so then all the columns will open in seperate chart - sundar**/
691 for (int i=0; i<rr.getChartValueColumnAxisList(AppConstants.CHART_ALL_COLUMNS, formValues).size();i++) {
692 String chartTitle = Globals.getDisplayChartTitle()? rr.getReportName():"";
693 chartTitle = rr.getFormFieldFilled(chartTitle);
694 downloadFileName = AppUtils.getTempFolderPath()+"cr_"+pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_"+i+".png";
695 filename = null;/*(String) ChartGen.generateChart( chartType,
696 request.getSession(),
701 rr.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues).subList(i, i+1),
702 rr.getChartColumnColorsList(AppConstants.CHART_ALL_COLUMNS, formValues).subList(i, i+1),
703 rr.getChartValueColumnAxisList(AppConstants.CHART_ALL_COLUMNS, formValues).subList(i, i+1),
707 rr.getChartWidthAsInt(),
708 rr.getChartHeightAsInt(),
709 rr.getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, formValues).subList(i,i+1),
710 rr.hasSeriesColumn(),
711 //rr.isChartMultiSeries(),
716 AppConstants.WEB_VERSION deviceType,
717 additionalChartOptionsMap,
721 Image image = Image.getInstance(downloadFileName);
723 } catch (MalformedURLException e) {
724 logger.error(EELFLoggerDelegate.errorLogger, MALFORMEDURLEXCEPTION_MSG,
726 } catch (BadElementException e) {
727 logger.error(EELFLoggerDelegate.errorLogger, BADELEMENTEXCEPTION_MSG,
729 } catch (FileNotFoundException e) {
730 logger.error(EELFLoggerDelegate.errorLogger, FILENOTFOUNDEXCEPTION_MSG,
732 } catch (IOException e) {
733 logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e);
737 } else { /** first check the columns to be opened in new charts and loop around in ChartGen generate chart function - sundar**/
738 String tempChartGroupPrev = "";
739 String tempChartGroupCurrent = "";
740 for (int i=0; i<lGroups.size();i++) {
741 String chartGroupOrg = (String) lGroups.get(i);
742 String chartYAxis = (String) mapYAxis.get(chartGroupOrg);
743 //System.out.println("chartGroupOrg " + chartGroupOrg);
744 if(nvl(chartGroupOrg).length()>0)
745 tempChartGroupCurrent = chartGroupOrg.substring(0,chartGroupOrg.lastIndexOf("|"));
747 tempChartGroupPrev = ((String) lGroups.get(i-1)).substring(0,((String) lGroups.get(i-1)).lastIndexOf("|"));
748 //System.out.println("TEMPCHARTGROUP " + tempChartGroupCurrent + " " + tempChartGroupPrev);
749 if(tempChartGroupCurrent.equals(tempChartGroupPrev))
751 //System.out.println("CHARTGROUPORG " + chartGroupOrg + " " + lGroups) ;
752 //String chartGroup = chartGroupOrg.substring(0,chartGroupOrg.lastIndexOf("|"));
753 String chartGroup = chartGroupOrg;
755 //System.out.println("$$$$CHARTGROUP in JSP " +chartGroup+ " "+ chartGroupOrg );
756 //System.out.println(" rr.getChartGroupDisplayNamesList(chartGroup) " + rr.getChartGroupDisplayNamesList(chartGroup));
757 //System.out.println(" rr.getChartGroupColumnColorsList(chartGroup) " + rr.getChartGroupColumnColorsList(chartGroup));
758 //System.out.println(" rr.getChartGroupColumnAxisList(chartGroup) " + rr.getChartGroupColumnAxisList(chartGroup));
759 //System.out.println(" rr.getChartGroupValueColumnAxisList(chartGroupOrg) " + rr.getChartGroupValueColumnAxisList(chartGroupOrg));
761 downloadFileName = AppUtils.getTempFolderPath()+"cr_"+pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_"+i+".png";
762 String chartTitle = (Globals.getDisplayChartTitle()? (chartGroup!=null && chartGroup.indexOf("|") > 0 ?chartGroup.substring(0,chartGroup.lastIndexOf("|")):rr.getReportName()):"");
763 chartTitle = rr.getFormFieldFilled(chartTitle);
764 String leftAxisLabel = "";
765 //if(!rr.isChartMultiSeries()) {
766 if(!rr.isMultiSeries()) {
767 leftAxisLabel = ((chartYAxis!=null && chartYAxis.indexOf("|") > 0) ? chartYAxis.substring(0,chartYAxis.lastIndexOf("|")): chartLeftAxisLabel );
769 leftAxisLabel = chartLeftAxisLabel;
772 filename = null;/*(String) ChartGen.generateChart( chartType,
773 request.getSession(),
778 ((chartType.indexOf("Stacked")>0 || chartType.equals(AppConstants.GT_PIE_MULTIPLE) || chartType.equals(AppConstants.GT_BAR_3D))?rr.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues):rr.getChartGroupDisplayNamesList(chartGroup, formValues)),
779 ((chartType.indexOf("Stacked")>0 || chartType.equals(AppConstants.GT_PIE_MULTIPLE) || chartType.equals(AppConstants.GT_BAR_3D))?rr.getChartColumnColorsList(AppConstants.CHART_ALL_COLUMNS, formValues):rr.getChartGroupColumnColorsList(chartGroup, formValues)),
780 ((chartType.indexOf("Stacked")>0 || chartType.equals(AppConstants.GT_PIE_MULTIPLE) || chartType.equals(AppConstants.GT_BAR_3D))?rr.getChartValueColumnAxisList(AppConstants.CHART_ALL_COLUMNS, formValues):rr.getChartGroupValueColumnAxisList(chartGroupOrg, formValues)),
784 rr.getChartWidthAsInt(),
785 rr.getChartHeightAsInt(),
786 ((chartType.indexOf("Stacked")>0 || chartType.equals(AppConstants.GT_PIE_MULTIPLE))?rr.getChartValueColumnsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues):rr.getChartGroupValueColumnAxisList(chartGroupOrg, formValues)),
787 rr.hasSeriesColumn(),
788 //rr.isChartMultiSeries(),
793 AppConstants.WEB_VERSION deviceType,
794 additionalChartOptionsMap,
798 Image image = Image.getInstance(downloadFileName);
800 } catch (MalformedURLException e) {
801 logger.error(EELFLoggerDelegate.errorLogger, MALFORMEDURLEXCEPTION_MSG,
803 } catch (BadElementException e) {
804 logger.error(EELFLoggerDelegate.errorLogger, BADELEMENTEXCEPTION_MSG,
806 } catch (FileNotFoundException e) {
807 logger.error(EELFLoggerDelegate.errorLogger, FILENOTFOUNDEXCEPTION_MSG,
809 } catch (IOException e) {
810 logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e);
814 if(!chartType.equals(AppConstants.GT_PIE_MULTIPLE)) {
815 for (int i=0; i<rr.getChartValueColumnAxisList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).size();i++) {
816 //System.out.println(" rr.getChartDisplayNamesList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i, i+1) " + rr.getChartDisplayNamesList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i, i+1));
817 //System.out.println(" rr.getChartValueColumnAxisList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i, i+1) " + rr.getChartValueColumnAxisList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i, i+1));
818 //System.out.println(" rr.getChartValueColumnsList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i,i+1) " + rr.getChartValueColumnsList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i,i+1));
820 downloadFileName = AppUtils.getTempFolderPath()+"cr_"+ pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_"+i+".png";
821 String chartTitle = Globals.getDisplayChartTitle()? rr.getReportName():"";
822 chartTitle = rr.getFormFieldFilled(chartTitle);
824 filename = null; /*(String) ChartGen.generateChart( chartType,
825 request.getSession(),
830 (chartType.equals(AppConstants.GT_PIE_MULTIPLE))?rr.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues):rr.getChartDisplayNamesList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).subList(i, i+1),
831 (chartType.equals(AppConstants.GT_PIE_MULTIPLE))?rr.getChartColumnColorsList(AppConstants.CHART_ALL_COLUMNS, formValues):rr.getChartColumnColorsList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).subList(i, i+1),
832 (chartType.equals(AppConstants.GT_PIE_MULTIPLE))?rr.getChartValueColumnAxisList(AppConstants.CHART_ALL_COLUMNS, formValues):rr.getChartValueColumnAxisList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).subList(i, i+1),
836 rr.getChartWidthAsInt(),
837 rr.getChartHeightAsInt(),
838 rr.getChartValueColumnsList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).subList(i,i+1),
839 rr.hasSeriesColumn(),
840 //rr.isChartMultiSeries(),
845 AppConstants.WEB_VERSION,
846 additionalChartOptionsMap,
850 Image image = Image.getInstance(downloadFileName);
852 } catch (MalformedURLException e) {
853 logger.error(EELFLoggerDelegate.errorLogger,
854 MALFORMEDURLEXCEPTION_MSG, e);
855 } catch (BadElementException e) {
856 logger.error(EELFLoggerDelegate.errorLogger,
857 BADELEMENTEXCEPTION_MSG, e);
858 } catch (FileNotFoundException e) {
859 logger.error(EELFLoggerDelegate.errorLogger,
860 FILENOTFOUNDEXCEPTION_MSG, e);
861 } catch (IOException e) {
862 logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e);
866 /** second rest of the columns are merged to one single chart - sundar**/
867 // System.out.println(" rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS) " + rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS));
868 // System.out.println(" rr.getChartValueColumnAxisList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS) " + rr.getChartValueColumnAxisList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS));
869 // System.out.println(" rr.getChartValueColumnsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS) " + rr.getChartValueColumnsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS));
871 if((!(lGroups!=null && lGroups.size() > 0))) {
873 if(/*chartType.equals(AppConstants.GT_TIME_SERIES) && */rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues)!=null && rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues).size()>0) {
874 downloadFileName = AppUtils.getTempFolderPath()+"cr_"+ pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_All.png";
875 String chartTitle = Globals.getDisplayChartTitle()? rr.getReportName():"";
876 chartTitle = rr.getFormFieldFilled(chartTitle);
878 filename = null; /*(String) ChartGen.generateChart( chartType,
879 request.getSession(),
884 rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues),
885 rr.getChartColumnColorsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues),
886 rr.getChartValueColumnAxisList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues),
890 rr.getChartWidthAsInt(),
891 rr.getChartHeightAsInt(),
892 rr.getChartValueColumnsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues),
893 rr.hasSeriesColumn(),
894 //rr.isChartMultiSeries(),
899 AppConstants.WEB_VERSION,
900 additionalChartOptionsMap,
904 Image image = Image.getInstance(downloadFileName);
906 } catch (MalformedURLException e) {
907 logger.error(EELFLoggerDelegate.errorLogger,
908 MALFORMEDURLEXCEPTION_MSG, e);
909 } catch (BadElementException e) {
910 logger.error(EELFLoggerDelegate.errorLogger,
911 BADELEMENTEXCEPTION_MSG, e);
912 } catch (FileNotFoundException e) {
913 logger.error(EELFLoggerDelegate.errorLogger,
914 FILENOTFOUNDEXCEPTION_MSG, e);
915 } catch (IOException e) {
916 logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e);
919 } // Stacked Chart Check
920 } // else no Series Column
924 } catch (Exception e) {
925 logger.error(EELFLoggerDelegate.errorLogger, "Exception in generateNewImage", e);
927 // System.out.println("Total Images " + images.size());
928 return images.size()>0?images:null;
933 private boolean isImageRotate(Document doc, Image image) {
935 System.out.println("image size="+image.getWidthPercentage()+ " "+ image.scaledWidth()+
936 " "+image.scaledHeight()+" "+image.getXYRatio());
937 System.out.println("page size = "+ doc.getPageSize().width() + " " +doc.getPageSize().height() +" "+
938 doc.topMargin() + " " +doc.bottomMargin() + " " + doc.leftMargin() + " " +
940 System.out.println(image.scaledWidth()/image.scaledHeight());
941 System.out.println((PageEvent.getPageWidth(doc)/PageEvent.getPageHeight(doc)));
942 // System.out.println(doc.getPageSize().getRotation());
944 float image_w = image.scaledWidth();
945 float image_h = image.scaledHeight();
946 float image_ratio = image_w/image_h;
948 float page_w = PageEvent.getPageWidth(doc);
949 float page_h = PageEvent.getPageHeight(doc);
950 float page_ratio = page_w/page_h;
952 return (image_w > page_w && image_ratio > page_ratio) ||
953 (image_h > page_h && image_ratio < page_ratio);
958 private final int DEFAULT_PDF_DISPLAY_WIDTH = 10;
960 private int paintPdfData(final HttpServletRequest request, final Document document, final ReportData rd,
961 final ReportRuntime rr, final String sql_whole) throws DocumentException, RaptorException, IOException {
963 final int mb = 1024 * 1024;
964 final Runtime runtime = Runtime.getRuntime();
967 final float f[] = getRelativeWidths(rd, AppConstants.RT_CROSSTAB.equals(rr.getReportType()));
968 PdfPTable table = new PdfPTable(f);
969 table.setWidthPercentage(100f);
970 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
971 table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM);
973 final ReportDefinition rdef = (new ReportHandler()).loadReportDefinition(request, rr.getReportID());
975 final List allColumns = rdef.getAllColumns();
977 final float[] repotWidths = new float[rdef.getVisibleColumnCount()];
979 float pdfDisplayWidth = 0;
980 for (final Iterator iter = allColumns.iterator(); iter.hasNext(); ) {
981 final DataColumnType dct = (DataColumnType) iter.next();
982 if (dct.isVisible()) {
984 if (dct.getPdfDisplayWidthInPxls() == null || dct.getPdfDisplayWidthInPxls().isEmpty() || dct
985 .getPdfDisplayWidthInPxls().startsWith("null")) {
986 pdfDisplayWidth = DEFAULT_PDF_DISPLAY_WIDTH;
988 pdfDisplayWidth = Float.parseFloat(dct.getPdfDisplayWidthInPxls());
991 repotWidths[columnIdx++] = pdfDisplayWidth;
995 table.setWidths(repotWidths);
997 //TODO: check title and subtitle
998 final HttpSession session = request.getSession();
999 final String drilldown_index = (String) session.getAttribute("drilldown_index");
1002 index = Integer.parseInt(drilldown_index);
1003 } catch (NumberFormatException ex) {
1006 final String titleRep = (String) session.getAttribute("TITLE_" + index);
1007 final String subtitle = (String) session.getAttribute("SUBTITLE_" + index);
1009 if (nvl(titleRep).length() > 0 && nvl(subtitle).length() > 0) {
1010 table.setHeaderRows(3);
1011 } else if (nvl(titleRep).length() > 0) {
1012 table.setHeaderRows(2);
1014 table.setHeaderRows(1);
1016 table = paintPdfReportHeader(request, document, table, rr, f);
1017 paintPdfTableHeader(document, rd, table);
1020 final int fragmentsize = 30; //for memory management
1022 rd.reportDataRows.resetNext();
1023 DataRow dr = rd.reportDataRows.getNext();
1025 if (nvl(sql_whole).length() > 0 && AppConstants.RT_LINEAR.equals(rr.getReportType())) {
1026 try (final Connection conn = ConnectionUtils.getConnection(rr.getDbInfo());
1027 final Statement st = conn.createStatement();
1028 final ResultSet rs = st.executeQuery(sql_whole);) {
1030 logger.debug(EELFLoggerDelegate.debugLogger, ("************* Map Whole SQL *************"));
1031 logger.debug(EELFLoggerDelegate.debugLogger, (sql_whole));
1032 logger.debug(EELFLoggerDelegate.debugLogger, ("*****************************************"));
1034 final ResultSetMetaData rsmd = rs.getMetaData();
1035 final int numberOfColumns = rsmd.getColumnCount();
1041 final Map colHash = new HashMap();
1042 for (int i = 1; i <= numberOfColumns; i++) {
1043 colHash.put(rsmd.getColumnLabel(i).toUpperCase(), rs.getString(i));
1045 rd.reportDataRows.resetNext();
1047 dr = rd.reportDataRows.getNext();
1049 for (dr.resetNext(); dr.hasNext(); ) {
1050 final DataValue dv = dr.getNext();
1052 final String value = nvl((String) colHash.get(dv.getColId().toUpperCase()));
1053 if (dv.isVisible()) {
1055 final HtmlFormatter cfmt = dv.getCellFormatter();
1056 final HtmlFormatter rfmt = dv.getRowFormatter();
1058 final Font cellFont = FontFactory.getFont(FONT_FAMILY,
1060 Font.NORMAL, Color.BLACK);
1062 cellFormatterFont(cfmt, cellFont);
1063 } else if (rfmt != null) {
1064 cellFormatterFont(rfmt, cellFont);
1067 cellFont.setStyle(Font.BOLD);
1071 final String cellValue = strip.stripHtml(value.trim());
1072 final PdfPCell cell = new PdfPCell(new Paragraph(cellValue, cellFont));
1074 //row background color can be overwritten by cell background color
1075 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1077 if (nvl(dv.getAlignment()).trim().length() > 0) {
1078 cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment()));
1080 cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1084 formatterCell(cfmt, cell);
1085 } else if (rfmt != null) {
1086 formatterCell(rfmt, cell);
1089 table.addCell(cell);
1096 if (rd.reportDataTotalRow != null) {
1097 for (rd.reportDataTotalRow.resetNext(); rd.reportDataTotalRow.hasNext(); idx++) {
1098 dr = rd.reportDataTotalRow.getNext();
1099 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1100 final Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY,
1102 Font.NORMAL, Color.BLACK);
1103 rowHeaderFont.setStyle(Font.BOLD);
1104 rowHeaderFont.setSize(FONT_SIZE + 1f);
1105 table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx));
1106 table.addCell(new Paragraph("Total", rowHeaderFont));
1108 addTotalRowColumns(table, dr, idx);
1109 if (idx % fragmentsize == fragmentsize - 1) {
1110 document.add(table);
1111 table.deleteBodyRows();
1112 table.setSkipFirstHeader(true);
1117 } catch (final SQLException | ReportSQLException ex) {
1118 throw new RaptorException(ex);
1119 } catch (final Exception ex) {
1120 if (!(ex.getCause() instanceof java.net.SocketException)) {
1121 throw new RaptorException(ex);
1124 //document.add(table);
1126 if (rr.getReportType().equals(AppConstants.RT_LINEAR)) {
1127 for (rd.reportDataRows.resetNext(); rd.reportDataRows.hasNext(); idx++) {
1129 if (runtime.freeMemory() / mb <= ((runtime.maxMemory() / mb) * Globals.getMemoryThreshold()
1134 dr = rd.reportDataRows.getNext();
1136 addRowHeader(table, dr, idx, rd);
1138 addRowColumns(table, dr, idx);
1140 if (idx % fragmentsize == fragmentsize - 1) {
1141 document.add(table);
1142 table.deleteBodyRows();
1143 table.setSkipFirstHeader(true);
1147 if (rd.reportDataTotalRow != null) {
1148 for (rd.reportDataTotalRow.resetNext(); rd.reportDataTotalRow.hasNext(); idx++) {
1149 dr = rd.reportDataTotalRow.getNext();
1150 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1151 Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY,
1153 Font.NORMAL, Color.BLACK);
1154 rowHeaderFont.setStyle(Font.BOLD);
1155 rowHeaderFont.setSize(FONT_SIZE + 1f);
1156 table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx));
1157 table.addCell(new Paragraph("Total", rowHeaderFont));
1159 addTotalRowColumns(table, dr, idx);
1160 if (idx % fragmentsize == fragmentsize - 1) {
1161 document.add(table);
1162 table.deleteBodyRows();
1163 table.setSkipFirstHeader(true);
1169 } else if (AppConstants.RT_CROSSTAB.equals(rr.getReportType())) {
1171 final List l = rd.getReportDataList();
1172 boolean first = true;
1173 for (int dataRow = 0; dataRow < l.size(); dataRow++) {
1176 dr = (DataRow) l.get(dataRow);
1177 final Vector<DataValue> rowNames = dr.getRowValues();
1178 for (dr.resetNext(); dr.hasNext(); ) {
1181 HtmlFormatter rfmt = dr.getRowFormatter();
1183 Font cellFont = FontFactory.getFont(FONT_FAMILY,
1185 Font.NORMAL, Color.BLACK);
1187 cellFormatterFont(rfmt, cellFont);
1190 if (rowNames != null) {
1191 for (int i = 0; i < rowNames.size(); i++) {
1192 final DataValue dv = rowNames.get(i);
1193 rfmt = dr.getRowFormatter();
1195 cellFont = FontFactory.getFont(FONT_FAMILY,
1197 Font.NORMAL, Color.BLACK);
1199 cellFormatterFont(rfmt, cellFont);
1201 String cellValue = dv.getDisplayValue();
1202 if (cellValue.indexOf("|#") != -1) {
1203 cellValue = cellValue.substring(0, cellValue.indexOf("|"));
1206 final PdfPCell cell = new PdfPCell(new Paragraph(cellValue, cellFont));
1207 //row background color can be overwritten by cell background color
1208 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1210 cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1213 formatterCell(rfmt, cell);
1215 table.addCell(cell);
1221 if (runtime.freeMemory() / mb <= ((runtime.maxMemory() / mb) * Globals.getMemoryThreshold()
1226 //addRowHeader(table,dr,idx,rd);
1228 addRowColumns(table, dr, idx);
1230 if (idx % fragmentsize == fragmentsize - 1) {
1231 document.add(table);
1232 table.deleteBodyRows();
1233 table.setSkipFirstHeader(true);
1240 //document.add(table);
1244 document.add(table);
1245 paintPdfReportFooter(request, document, rr, f);
1250 private void addRowHeader(PdfPTable table, DataRow dr, int idx, ReportData rd) {
1252 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1254 for(rd.reportRowHeaderCols.resetNext();rd.reportRowHeaderCols.hasNext();) {
1255 RowHeaderCol rhc = rd.reportRowHeaderCols.getNext();
1258 RowHeader rh = rhc.getNext();
1259 //System.out.println(" =============== RowHeader\n "+rh);
1261 Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY,
1263 Font.NORMAL, Color.BLACK);
1265 rowHeaderFont.setStyle(Font.BOLD);
1266 rowHeaderFont.setSize(FONT_SIZE+1f);
1269 if(rh.getColSpan()>0) {
1270 table.getDefaultCell().setColspan(rh.getColSpan());
1271 table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx));
1272 table.addCell(new Paragraph(strip.stripHtml(rh.getRowTitle()),rowHeaderFont));
1277 private void addRowColumns(PdfPTable table, DataRow dr, int idx) {
1279 table.getDefaultCell().setColspan(1);
1281 for(dr.resetNext();dr.hasNext();)
1283 DataValue dv = dr.getNext();
1284 //System.out.println(columnCount +" --> "+dv);
1285 if(dv.isVisible()) {
1286 HtmlFormatter cfmt = dv.getCellFormatter();
1287 HtmlFormatter rfmt = dv.getRowFormatter();
1289 Font cellFont = FontFactory.getFont(FONT_FAMILY,
1291 Font.NORMAL, Color.BLACK);
1293 cellFormatterFont(cfmt,cellFont);
1295 else if(rfmt != null) {
1296 cellFormatterFont(rfmt,cellFont);
1300 cellFont.setStyle(Font.BOLD);
1304 String cellValue = strip.stripHtml(dv.getDisplayValue().trim());
1305 PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont));
1307 //row background color can be overwritten by cell background color
1308 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1310 if(nvl(dv.getAlignment()).trim().length()>0)
1311 cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment()));
1313 cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1316 formatterCell(cfmt,cell);
1318 else if(rfmt != null) {
1319 formatterCell(rfmt,cell);
1322 table.addCell(cell);
1329 private void addTotalRowColumns(PdfPTable table, DataRow dr, int idx) {
1331 table.getDefaultCell().setColspan(1);
1336 DataValue dv = dr.getNext();
1337 //System.out.println(columnCount +" --> "+dv);
1338 if(dv.isVisible()) {
1339 HtmlFormatter cfmt = dv.getCellFormatter();
1340 HtmlFormatter rfmt = dv.getRowFormatter();
1342 Font cellFont = FontFactory.getFont(FONT_FAMILY,
1344 Font.NORMAL, Color.BLACK);
1346 cellFormatterFont(cfmt,cellFont);
1348 else if(rfmt != null) {
1349 cellFormatterFont(rfmt,cellFont);
1353 cellFont.setStyle(Font.BOLD);
1357 String cellValue = strip.stripHtml(dv.getDisplayValue().trim());
1358 PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont));
1360 //row background color can be overwritten by cell background color
1361 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1363 if(nvl(dv.getAlignment()).trim().length()>0)
1364 cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment()));
1366 cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1369 formatterCell(cfmt,cell);
1371 else if(rfmt != null) {
1372 formatterCell(rfmt,cell);
1375 table.addCell(cell);
1382 private void formatterCell(HtmlFormatter fmt, PdfPCell cell) {
1384 if(nvl(fmt.getBgColor()).trim().length()>0)
1385 cell.setBackgroundColor(Color.decode(fmt.getBgColor()));
1386 if(nvl(fmt.getAlignment()).trim().length()>0)
1387 cell.setHorizontalAlignment(ElementTags.alignmentValue(fmt.getAlignment()));
1390 private void cellFormatterFont(HtmlFormatter fmt, Font font) {
1393 font.setStyle(Font.BOLD);
1395 font.setStyle(Font.ITALIC);
1396 if(fmt.isUnderline())
1397 font.setStyle(Font.UNDERLINE);
1398 if(fmt.getFontColor().trim().length()>0)
1399 font.setColor(Color.decode(fmt.getFontColor()));
1400 if(fmt.getFontSize().trim().length()>0)
1401 font.setSize(Float.parseFloat(fmt.getFontSize())-Globals.getDataFontSizeOffset());
1402 // if(fmt.getFontFace().trim().length()>0)
1403 // cellFont.setFamily()
1407 private Color getRowBackgroundColor(DataRow dr, int idx) {
1409 Color color = Color.decode(Globals.getDataDefaultBackgroundHexCode());
1411 HtmlFormatter rhf = dr.getRowFormatter();
1412 if(rhf!=null && nvl(rhf.getBgColor()).trim().length()>0)
1414 color = Color.decode(rhf.getBgColor());
1416 else if(pb.isAlternateColor() && idx%2==0)
1418 color = Color.decode(Globals.getDataBackgroundAlternateHexCode());
1424 private int getTotalVisbleColumns(ReportData rd) {
1426 int totalVisbleColumn = rd.getTotalColumnCount();
1427 for(rd.reportDataRows.resetNext();rd.reportDataRows.hasNext();)
1429 DataRow dr = rd.reportDataRows.getNext();
1430 for(dr.resetNext();dr.hasNext();) {
1431 DataValue dv = dr.getNext();
1433 totalVisbleColumn--;
1439 return totalVisbleColumn;
1443 private int getFirstRowIndex(ReportRuntime rr) {
1444 return (pb.getCurrentPage()>0)?pb.getCurrentPage()*rr.getPageSize()+1 : 1;
1447 private float[] getRelativeWidths(ReportData rd, boolean crosstab){
1449 int totalColumns = getTotalVisbleColumns(rd);
1450 /*if(rd.reportTotalRowHeaderCols!=null) {
1457 if(totalColumns == 0 )
1460 float[] relativeWidths = new float[totalColumns];
1461 //initial widths are even
1462 for(int i=0; i<relativeWidths.length; i++)
1463 relativeWidths[i] = 10f;
1466 boolean firstPass = true;
1468 for (rd.reportColumnHeaderRows.resetNext(); rd.reportColumnHeaderRows.hasNext();)
1471 /*if(rd.reportTotalRowHeaderCols!=null) {
1472 String columnWidth = "5";
1474 if(columnWidth != null && columnWidth.trim().endsWith("%"))
1475 relativeWidths[index] = Float.parseFloat(removeLastCharacter(columnWidth));
1480 for(rd.reportRowHeaderCols.resetNext();rd.reportRowHeaderCols.hasNext();) {
1481 String columnWidth = rd.reportRowHeaderCols.getNext().getColumnWidth();
1483 if(columnWidth != null && columnWidth.trim().endsWith("%"))
1484 relativeWidths[index] = Float.parseFloat(removeLastCharacter(columnWidth));
1491 ColumnHeaderRow chr = rd.reportColumnHeaderRows.getNext();
1492 for (chr.resetNext(); chr.hasNext();) {
1494 ColumnHeader ch = chr.getNext();
1496 if(ch.isVisible()) {
1498 String columnWidth = ch.getColumnWidth();
1500 if(ch.getColSpan() <= 1){
1501 if(columnWidth != null && columnWidth.trim().endsWith("%"))
1502 relativeWidths[index] = Float.parseFloat(removeLastCharacter(columnWidth));
1505 for(int i=0; i<ch.getColSpan(); i++) {
1507 if(columnWidth != null && columnWidth.trim().endsWith("%"))
1508 relativeWidths[index] =
1509 (Float.parseFloat(removeLastCharacter(columnWidth)))/ch.getColSpan();
1518 return relativeWidths;
1521 public static String removeLastCharacter(String str) {
1522 return str.substring(0, str.length()-1);
1525 private PdfPTable paintPdfReportHeader(HttpServletRequest request, Document document, PdfPTable table, ReportRuntime rr, float[] f)
1526 throws DocumentException, IOException {
1528 HttpSession session = request.getSession();
1529 String drilldown_index = (String) session.getAttribute("drilldown_index");
1532 index = Integer.parseInt(drilldown_index);
1533 } catch (NumberFormatException ex) {
1536 String title = (String) session.getAttribute("TITLE_"+index);
1537 String subtitle = (String) session.getAttribute("SUBTITLE_"+index);
1538 if(nvl(title).length()>0) {
1539 //PdfPTable table = new PdfPTable(1);
1540 table.setWidthPercentage(100f);
1541 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1542 table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM);
1545 Font font = FontFactory.getFont(FONT_FAMILY,
1550 //addEmptyRows(table,1);
1551 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1552 //table.getDefaultCell().setBackgroundColor(Color.decode(Globals.getDataTableHeaderBackgroundFontColor()));
1553 title = Utils.replaceInString(title, "<BR/>", " ");
1554 title = Utils.replaceInString(title, "<br/>", " ");
1555 title = Utils.replaceInString(title, "<br>", " ");
1556 title = strip.stripHtml(nvl(title).trim());
1557 //subtitle = Utils.replaceInString(subtitle, "<BR/>", " ");
1558 //subtitle = Utils.replaceInString(subtitle, "<br/>", " ");
1559 //subtitle = Utils.replaceInString(subtitle, "<br>", " ");
1560 //subtitle = strip.stripHtml(nvl(subtitle).trim());
1561 StyleSheet styles = new StyleSheet();
1563 HTMLWorker htmlWorker = new HTMLWorker(document);
1564 ArrayList cc = new ArrayList();
1565 cc = htmlWorker.parseToList(new StringReader(subtitle), styles);
1567 Phrase p1 = new Phrase();
1568 for (int i = 0; i < cc.size(); i++){
1569 Element elem = (Element)cc.get(i);
1570 ArrayList al = elem.getChunks();
1571 for (int j = 0; j < al.size(); j++) {
1572 Chunk chunk = (Chunk) al.get(j);
1573 chunk.font().setSize(6.0f);
1577 //cell = new PdfPCell(p1);
1578 StyleSheet style = new StyleSheet();
1579 style.loadTagStyle("font", "font-size", "3");
1580 style.loadTagStyle("font", "size", "3");
1581 styles.loadStyle("pdfFont1", "size", "11px");
1582 styles.loadStyle("pdfFont1", "font-size", "11px");
1583 /*ArrayList p = HTMLWorker.parseToList(new StringReader(nvl(title)), style);
1584 for (int k = 0; k < p.size(); ++k){
1585 document.add((com.lowagie.text.Element)p.get(k));
1587 //p1.font().setSize(3.0f);
1588 PdfPCell titleCell = new PdfPCell(new Phrase(title, font));
1589 titleCell.setColspan(rr.getVisibleColumnCount());
1590 PdfPCell subtitleCell = new PdfPCell(p1);
1591 subtitleCell.setColspan(rr.getVisibleColumnCount());
1592 titleCell.setHorizontalAlignment(1);
1593 subtitleCell.setHorizontalAlignment(1);
1594 table.addCell(titleCell);
1595 table.addCell(subtitleCell);
1596 //document.add(table);
1602 private void paintPdfReportFooter(HttpServletRequest request, Document document, ReportRuntime rr, float[] f)
1603 throws DocumentException, IOException {
1605 HttpSession session = request.getSession();
1606 String drilldown_index = (String) session.getAttribute("drilldown_index");
1609 index = Integer.parseInt(drilldown_index);
1610 } catch (NumberFormatException ex) {
1614 String title = (String) session.getAttribute("FOOTER_"+index);
1615 if(nvl(title).length()>0) {
1616 PdfPTable table = new PdfPTable(1);
1617 table.setWidthPercentage(100f);
1618 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1619 table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM);
1621 Font font = FontFactory.getFont(FONT_FAMILY,
1627 //addEmptyRows(table,1);
1628 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1629 //table.getDefaultCell().setBackgroundColor(Color.decode(Globals.getDataTableHeaderBackgroundFontColor()));
1630 /*title = Utils.replaceInString(title, "<BR/>", " ");
1631 title = Utils.replaceInString(title, "<br/>", " ");
1632 title = Utils.replaceInString(title, "<br>", " ");
1633 title = strip.stripHtml(nvl(title).trim());*/
1634 StyleSheet style = new StyleSheet();
1636 HTMLWorker htmlWorker = new HTMLWorker(document);
1637 ArrayList cc = new ArrayList();
1638 cc = htmlWorker.parseToList(new StringReader(title), style);
1640 Phrase p1 = new Phrase();
1641 for (int i = 0; i < cc.size(); i++){
1642 Element elem = (Element)cc.get(i);
1643 ArrayList al = elem.getChunks();
1644 for (int j = 0; j < al.size(); j++) {
1645 Chunk chunk = (Chunk) al.get(j);
1646 chunk.font().setSize(6.0f);
1652 HTMLWorker.parseToList(new StringReader(nvl(title)), style);*/
1653 PdfPCell titleCell = new PdfPCell(p1);
1654 titleCell.setHorizontalAlignment(Element.ALIGN_LEFT);
1655 table.addCell(titleCell);
1657 document.add(table);
1663 private void paintPdfTableHeader(Document document, ReportData rd, PdfPTable table)
1664 throws DocumentException {
1666 Font font = FontFactory.getFont(FONT_FAMILY,
1669 Color.decode(Globals.getDataTableHeaderFontColor()));
1670 //table.setHeaderRows(1);
1671 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1672 table.getDefaultCell().setBackgroundColor(Color.decode(Globals.getDataTableHeaderBackgroundFontColor()));
1675 boolean firstPass = true;
1677 /*if(rd.reportTotalRowHeaderCols!=null) {
1679 table.addCell(new Paragraph("No.", font));
1683 for (rd.reportColumnHeaderRows.resetNext(); rd.reportColumnHeaderRows.hasNext();)
1686 for(rd.reportRowHeaderCols.resetNext();rd.reportRowHeaderCols.hasNext();) {
1688 table.addCell(new Paragraph("No.", font));
1691 RowHeaderCol rhc = rd.reportRowHeaderCols.getNext();
1692 title = rhc.getColumnTitle();
1693 title = Utils.replaceInString(title,"_nl_", " \n");
1694 table.addCell(new Paragraph(title,font));
1699 ColumnHeaderRow chr = rd.reportColumnHeaderRows.getNext();
1700 for (chr.resetNext(); chr.hasNext();) {
1701 ColumnHeader ch = chr.getNext();
1702 //System.out.println(ch);
1703 if(ch.isVisible()) {
1704 title = ch.getColumnTitle();
1705 title = Utils.replaceInString(title,"_nl_", " \n");
1706 table.addCell(new Paragraph(title,font));
1712 public static String currentTime(String pattern) {
1714 SimpleDateFormat oracleDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss");
1715 Date sysdate = oracleDateFormat.parse(ReportLoader.getSystemDateTime());
1716 SimpleDateFormat dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern());
1717 return dtimestamp.format(sysdate)+" "+Globals.getTimeZone();
1718 //paramList.add(new IdNameValue("DATE", dtimestamp.format(sysdate)+" "+Globals.getTimeZone()));
1719 } catch(Exception ex) {}
1721 SimpleDateFormat s = new SimpleDateFormat(pattern);
1722 s.setTimeZone(TimeZone.getTimeZone(Globals.getTimeZone()));
1723 //System.out.println("^^^^^^^^^^^^^^^^^^^^ " + Calendar.getInstance().getTime());
1724 //System.out.println("^^^^^^^^^^^^^^^^^^^^ " + s.format(Calendar.getInstance().getTime()));
1725 return s.format(Calendar.getInstance().getTime());
1728 private PdfBean preparePdfBean(HttpServletRequest request,ReportRuntime rr) {
1729 PdfBean pb = new PdfBean();
1731 pb.setUserId(AppUtils.getUserID(request));
1733 pb.setWhereToShowPageNumber(Globals.getPageNumberPosition());
1734 pb.setAlternateColor(Globals.isDataAlternateColor());
1735 pb.setTimestampPattern(Globals.getDatePattern());
1739 temp = Integer.parseInt(request.getParameter(AppConstants.RI_NEXT_PAGE));
1740 } catch (NumberFormatException e) {}
1741 pb.setCurrentPage(temp);
1743 //pb.setPortrait( trueORfalse(request.getParameter("isPortrait"),true));
1744 pb.setPortrait(trueORfalse(rr.getPDFOrientation() == "portait"?"true":"false", true));
1745 //pb.setCoverPageIncluded( trueORfalse(request.getParameter("isCoverPageIncluded"), true));
1746 //if(Globals.isCoverPageNeeded()) {
1747 pb.setCoverPageIncluded(Globals.isCoverPageNeeded()?rr.isPDFCoverPage():false);
1749 pb.setTitle(nvl(request.getParameter("title")));
1750 pb.setPagesize(nvls(request.getParameter("pagesize"),"LETTER"));
1752 pb.setLogo1Url(rr.getPDFLogo1());
1753 pb.setLogo2Url(rr.getPDFLogo2());
1754 pb.setLogo1Size(rr.getPDFLogo1Size());
1755 pb.setLogo2Size(rr.getPDFLogo2Size());
1756 pb.setFullWebContextPath(request.getSession().getServletContext().getRealPath(File.separator));
1759 pb.setDisplayChart(nvl(rr.getChartType()).trim().length()>0 && rr.getDisplayChart());
1761 String id = nvl(request.getParameter("pdfAttachmentKey")).trim();
1762 String log_id = nvl(request.getParameter("log_id")).trim();
1763 if(id.length()>0 && log_id.length()>0)
1764 pb.setAttachmentOfEmail(true);
1769 private boolean trueORfalse(String str) {
1770 return (str != null) && (str.equalsIgnoreCase("true"));
1773 private boolean trueORfalse(String str,boolean b_default) {
1774 return str==null ? b_default : (str.equalsIgnoreCase("true"));