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;
164 if(rr==null) rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
166 boolean isDashboard = false;
167 if ((request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)!=null) && ( ((String) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).equals(rr.getReportID())) ) {
172 String reportID = (String) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID);
173 ReportRuntime rrDash = rh.loadReportRuntime(request, reportID, true, 1);
174 pb = preparePdfBean(request,rrDash);
177 document.setPageSize(PageSize.getRectangle(pb.getPagesize()));
178 if(!pb.isPortrait()) // get this from properties file
179 document.setPageSize(document.getPageSize().rotate());
182 writer = PdfWriter.getInstance(document, response.getOutputStream());
183 writer.setPageEvent(new PageEvent(pb));//header,footer,bookmark
186 formattedReportName = new HtmlStripper().stripSpecialCharacters(rrDash.getReportName());
187 if(pb.isAttachmentOfEmail())
188 response.setHeader("Content-disposition", "inline");
190 response.setHeader("Content-disposition", "attachment;filename="+ formattedReportName+formattedDate+user_id+".pdf");
192 pdfFName = "dashboard"+formattedReportName+formattedDate+user_id+".pdf";
193 Map reportRuntimeMap = null;
194 Map reportDataMap = null;
195 Map reportDisplayTypeMap = null;
197 reportRuntimeMap = (TreeMap) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP);
198 reportDataMap = (TreeMap) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP);
199 reportDisplayTypeMap = (TreeMap) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP);
201 if(reportRuntimeMap!=null) {
202 //ServletOutputStream sos = response.getOutputStream();
203 Set setReportRuntime = reportRuntimeMap.entrySet();
204 Set setReportDataMap = reportDataMap.entrySet();
205 Set setReportDisplayTypeMap = reportDisplayTypeMap.entrySet();
207 Iterator iter2 = setReportDataMap.iterator();
208 Iterator iter3 = setReportDisplayTypeMap.iterator();
210 for(Iterator iter = setReportRuntime.iterator(); iter.hasNext(); ) {
212 Map.Entry entryData = (Entry) iter2.next();
213 Map.Entry entry = (Entry) iter.next();
214 Map.Entry entryCheckChart = (Entry) iter3.next();
215 //String rep_id = (String) entry.getKey();
216 ReportRuntime rrDashRep = (ReportRuntime) entry.getValue();
219 firstReportRuntimeObj = (ReportRuntime) entry.getValue();
220 if(pb.isCoverPageIncluded()) {
221 document = paintDashboardCoverPage(document, rrDash, firstReportRuntimeObj, request);
224 ReportData rdDashRep = (ReportData) entryData.getValue();
226 //pb.setDisplayChart(nvl(rr.getChartType()).trim().length()>0 && rr.getDisplayChart());
227 if( ((rrDashRep.getChartType()).trim().length()>0 && rrDashRep.getDisplayChart()) && entryCheckChart.getValue().toString().equals("c")) {
229 pb.setTitle(nvl(rrDashRep.getReportTitle()).length()>0?rrDashRep.getReportTitle():rrDashRep.getReportName());
230 paintPdfImage(request, document,AppUtils.getTempFolderPath()+"cr_"+ pb.getUserId()+"_"+request.getSession().getId()+"_"+rrDashRep.getReportID()+".png", rrDashRep);
233 pb.setTitle(nvl(rrDashRep.getReportTitle()).length()>0?rrDashRep.getReportTitle():rrDashRep.getReportName());
234 paintPdfData(request, document,rdDashRep,rrDashRep, "");
239 } catch (DocumentException dex) {
240 logger.error(EELFLoggerDelegate.errorLogger, "DocumentException in createPdfFileContent", dex);
242 catch (RaptorException rex) {
243 logger.error(EELFLoggerDelegate.errorLogger, "RaptorException in createPdfFileContent", rex);
247 //ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
248 //ReportData rd = (ReportData) request.getSession().getAttribute(AppConstants.RI_REPORT_DATA);
250 ReportData rd = null;
253 if(!nvl(request.getParameter("parent"), "").equals("N")) parent = nvl(request.getParameter("parent"), "");
254 if(parent.startsWith("parent_")) parentFlag = 1;
255 if(parentFlag == 1) {
256 rr = (ReportRuntime) request.getSession().getAttribute(parent+"_rr");
257 rd = (ReportData) request.getSession().getAttribute(parent+"_rd");
259 if(rr==null) rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
260 if(rd==null) rd = (ReportData) request.getSession().getAttribute(AppConstants.RI_REPORT_DATA);
262 pb = preparePdfBean(request,rr);
263 FONT_FAMILY = rr.getPDFFont();
264 FONT_SIZE = rr.getPDFFontSize();
265 //System.out.println(pb);
267 formattedReportName = new HtmlStripper().stripSpecialCharacters(rr.getReportName());
271 response.setContentType("application/pdf");
272 if(pb.isAttachmentOfEmail())
273 response.setHeader("Content-disposition", "inline");
275 response.setHeader("Content-disposition", "attachment;filename="+ formattedReportName+formattedDate+user_id+".pdf");
277 document.setPageSize(PageSize.getRectangle(pb.getPagesize()));
279 if(!pb.isPortrait()) // get this from properties file
280 document.setPageSize(document.getPageSize().rotate());
284 writer = PdfWriter.getInstance(document, outStream);
285 writer.setPageEvent(new PageEvent(pb));//header,footer,bookmark
288 //System.out.println("Document 1 " + document);
289 if(pb.isCoverPageIncluded()) {
290 document = paintCoverPage(document, rr, request);
293 //boolean isImageRotate = false;
294 //System.out.println("Document 2 " + document);
296 if(pb.isDisplayChart()) {
297 paintPdfImage(request, document,AppUtils.getTempFolderPath()+"cr_"+ pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+".png", rr);
299 //System.out.println("Document 4" + document);
302 if(type == 3 && rr.getSemaphoreList()==null && !(rr.getReportType().equals(AppConstants.RT_CROSSTAB)) ) { //type = 3 is whole
303 String sql_whole = (String) request.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE);
304 returnValue = paintPdfData(request, document, rd, rr, sql_whole);
305 } else if(type == 2) {
306 returnValue = paintPdfData(request, document, rd, rr, "");
308 //String sql_whole = (String) request.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE);
309 int downloadLimit = (rr.getMaxRowsInExcelDownload()>0)?rr.getMaxRowsInExcelDownload():Globals.getDownloadLimit();
310 String action = request.getParameter(AppConstants.RI_ACTION);
312 if(!(rr.getReportType().equals(AppConstants.RT_CROSSTAB)) && !action.endsWith("session"))
313 rd = rr.loadReportData(-1, AppUtils.getUserID(request), downloadLimit,request, false /*download*/);
314 if(rr.getSemaphoreList()!=null) {
315 rd = rr.loadReportData(-1, AppUtils.getUserID(request), downloadLimit,request, true);
316 returnValue = paintPdfData(request, document, rd, rr, "");
318 returnValue = paintPdfData(request, document, rd, rr, rr.getWholeSQL());
325 //paintPdfData(document,rd,rr);
328 } catch (DocumentException de) {
329 logger.error(EELFLoggerDelegate.errorLogger, "DocumentException in createPdfFileContent", de);
335 Runtime runtime = Runtime.getRuntime();
336 logger.debug(EELFLoggerDelegate.debugLogger, ("##### Heap utilization statistics [MB] #####"));
337 logger.debug(EELFLoggerDelegate.debugLogger, ("Used Memory:"
338 + (runtime.maxMemory() - runtime.freeMemory()) / mb));
339 logger.debug(EELFLoggerDelegate.debugLogger, ("Free Memory:"
340 + runtime.freeMemory() / mb));
341 logger.debug(EELFLoggerDelegate.debugLogger, ("Total Memory:" + runtime.totalMemory() / mb));
342 logger.debug(EELFLoggerDelegate.debugLogger, ("Max Memory:" + runtime.maxMemory() / mb));
346 private Document paintCoverPage(Document doc, ReportRuntime rr, HttpServletRequest request) throws IOException, DocumentException {
348 //System.out.println("PDFREPORTHANDLER STARTED ... " );
349 if(nvl(rr.getPdfImg()).length()>0) {
350 Image image1 = Image.getInstance(AppUtils.getExcelTemplatePath()+"../../"+AppUtils.getImgFolderURL()+rr.getPdfImg());
351 image1.scalePercent(20f, 20f);
354 float firstColumnSize = Globals.getCoverPageFirstColumnSize();
355 float[] relativeWidths = {firstColumnSize,1f-firstColumnSize};
356 PdfPTable table = new PdfPTable(relativeWidths);
357 table.getDefaultCell().setBorderWidth(0);
358 addEmptyRows(table,6);
359 HTMLWorker worker = new HTMLWorker(doc);
360 StyleSheet style = new StyleSheet();
361 style.loadTagStyle("body", "leading", "16,0");
362 StringBuffer reportDescrBuf = new StringBuffer("");
363 ArrayList descr = HTMLWorker.parseToList(new StringReader(nvl(rr.getReportDescr())), style);
364 ArrayList paraList = null;
365 if(nvl(rr.getReportTitle()).length()>0) {
366 add2Cells(table,"Report Title : ",nvl(rr.getReportTitle()));
367 if(nvl(rr.getReportSubTitle()).length()>0) {
368 add2Cells(table,"Report Sub-Title : ",nvl(rr.getReportSubTitle()));
369 System.out.println("Adding the report sub-title ");
373 add2Cells(table,"Report Name : ",nvl(rr.getReportName()));
375 if((descr!=null && descr.size()>0)) {
376 paraList = (com.lowagie.text.Paragraph)descr.get(0);
377 for (int i=0 ; i<paraList.size(); i++) {
378 reportDescrBuf.append(paraList.get(i));
382 add2Cells(table,"Description : ",reportDescrBuf.toString());
383 if(Globals.getSessionInfoForTheCoverPage().length()>0) {
384 String nameValue[] = Globals.getSessionInfoForTheCoverPage().split(",");
385 String name=nameValue[0];
386 String value=nameValue[1];
387 add2Cells(table,name+" : ",(AppUtils.getRequestNvlValue(request, value).length()>0?AppUtils.getRequestNvlValue(request, value):nvl((String)request.getSession().getAttribute(value))));
390 if(Globals.isCreatedOwnerInfoNeeded()) {
391 add2Cells(table,"Created By : ",nvl(AppUtils.getUserName(rr.getCreateID())));
392 add2Cells(table,"Owner : ",nvl(AppUtils.getUserName(rr.getOwnerID())));
394 if(Globals.displayLoginIdForDownloadedBy())
395 add2Cells(table,"Downloaded by : ",nvl(AppUtils.getUserBackdoorLoginId(request)));
397 add2Cells(table,"Downloaded by : ",nvl(AppUtils.getUserName(AppUtils.getUserID(request))));
399 addEmptyRows(table,1);
401 boolean isFirstRow = true;
402 ArrayList al = rr.getParamNameValuePairsforPDFExcel(request, 1);
404 al = (ArrayList) request.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
407 Iterator it = al.iterator();
408 addEmptyRows(table,1);
409 //if(!Globals.customizeFormFieldInfo()) {
410 if(rr.getFormFieldComments(request).length()<=0) {
411 while(it.hasNext()) {
414 add2Cells(table, "Run-time Criteria : ", " ");
418 IdNameValue value = (IdNameValue)it.next();
419 if(!value.getId().trim().equals("BLANK"))
420 //System.out.println("PDFREPORTHANDLER " + value.getId()+" : "+value.getName());
421 add2Cells(table, value.getId()+" : ",value.getName().replaceAll("~",","));
422 //add2Cells(table, rr.getFormFieldComments(request), " ");
424 addEmptyRows(table,1);
430 //add2Cells(table, "Run-time Criteria : ", " ");
431 addEmptyRows(table,1);
433 //com.lowagie.text.html.HtmlParser.parse(doc, new StringReader(rr.getFormFieldComments(request)));
434 ArrayList p = HTMLWorker.parseToList(new StringReader(rr.getFormFieldComments(request).replaceAll("~",",")), style);
436 for (int k = 0; k < p.size(); ++k){
437 doc.add((com.lowagie.text.Element)p.get(k));
446 private Document paintDashboardCoverPage(Document doc, ReportRuntime rrDashRep, ReportRuntime firstReportRuntimeObj, HttpServletRequest request) throws IOException, DocumentException {
448 //System.out.println("PDFREPORTHANDLER STARTED ... " );
449 float firstColumnSize = Globals.getCoverPageFirstColumnSize();
450 float[] relativeWidths = {firstColumnSize,1f-firstColumnSize};
451 PdfPTable table = new PdfPTable(relativeWidths);
452 table.getDefaultCell().setBorderWidth(0);
453 addEmptyRows(table,6);
455 add2Cells(table,"Report Name : ",rrDashRep.getReportName());
456 add2Cells(table,"Description : ",rrDashRep.getReportDescr());
457 if(Globals.getSessionInfoForTheCoverPage().length()>0) {
458 String nameValue[] = Globals.getSessionInfoForTheCoverPage().split(",");
459 String name=nameValue[0];
460 String value=nameValue[1];
461 add2Cells(table,name+" : ",(AppUtils.getRequestNvlValue(request, value).length()>0?AppUtils.getRequestNvlValue(request, value):nvl((String)request.getSession().getAttribute(value))));
464 if(Globals.isCreatedOwnerInfoNeeded()) {
465 add2Cells(table,"Created By : ",AppUtils.getUserName(rrDashRep.getCreateID()));
466 add2Cells(table,"Owner : ",AppUtils.getUserName(rrDashRep.getOwnerID()));
468 if(Globals.displayLoginIdForDownloadedBy())
469 add2Cells(table,"Downloaded by : ",AppUtils.getUserBackdoorLoginId(request));
471 add2Cells(table,"Downloaded by : ",AppUtils.getUserName(request));
473 addEmptyRows(table,1);
475 boolean isFirstRow = true;
476 ArrayList al = firstReportRuntimeObj.getParamNameValuePairsforPDFExcel(request, 2);
477 Iterator it = al.iterator();
478 addEmptyRows(table,1);
479 //if(!Globals.customizeFormFieldInfo()) {
480 if(firstReportRuntimeObj.getFormFieldComments(request).length()<=0) {
481 while(it.hasNext()) {
484 add2Cells(table, "Run-time Criteria : ", " ");
488 IdNameValue value = (IdNameValue)it.next();
489 if(!value.getId().trim().equals("BLANK"))
490 //System.out.println("PDFREPORTHANDLER " + value.getId()+" : "+value.getName());
491 add2Cells(table, value.getId()+" : ",value.getName());
492 //add2Cells(table, rr.getFormFieldComments(request), " ");
494 addEmptyRows(table,1);
500 //add2Cells(table, "Run-time Criteria : ", " ");
501 addEmptyRows(table,1);
503 //com.lowagie.text.html.HtmlParser.parse(doc, new StringReader(rr.getFormFieldComments(request)));
504 HTMLWorker worker = new HTMLWorker(doc);
505 StyleSheet style = new StyleSheet();
506 style.loadTagStyle("body", "leading", "16,0");
507 ArrayList p = HTMLWorker.parseToList(new StringReader(firstReportRuntimeObj.getFormFieldComments(request)), style);
509 for (int k = 0; k < p.size(); ++k){
510 doc.add((com.lowagie.text.Element)p.get(k));
519 public static void addEmptyRows(PdfPTable table, int rows) throws DocumentException {
520 for (int i=0; i<rows; i++)
521 for(int j=0;j<table.getAbsoluteWidths().length;j++)
522 table.addCell(new Paragraph(" "));
526 private void add2Cells(PdfPTable table, String key, String value) {
529 cell = new PdfPCell(new Paragraph(key));
530 cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT);
531 cell.setBorderWidth(0f);
534 cell = new PdfPCell(new Paragraph(value));
535 cell.setHorizontalAlignment(Rectangle.ALIGN_LEFT);
536 cell.setBorderWidth(0f);
540 private void paintPdfImage(HttpServletRequest request, Document document, String fileName, ReportRuntime rr)
541 throws DocumentException
544 ArrayList images = getImage(request, fileName,pb.isAttachmentOfEmail()?true:false, rr);
545 //Image image = getImage(request, fileName,pb.isAttachmentOfEmail()?true:false);
546 PdfPTable table = null;
547 PdfPCell cellValue = null;
550 for (int i = 0; i < images.size(); i++) {
551 table = new PdfPTable(1);
552 cellValue = new PdfPCell();
553 cellValue.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
554 Image image = (Image) images.get(i);
555 image.setAlignment(Image.ALIGN_CENTER);
556 //System.out.println("Document 3 " + document + " i-" + i);
559 //System.out.println("Document 31 " + document);
560 cellValue.setImage(image);
561 //table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
562 table.addCell(cellValue);
563 //System.out.println("Document 32 " + document + "table " + table);
565 //System.out.println("Document 33 " + document);
570 private ArrayList getImage(HttpServletRequest request, String fileName, boolean isGenerateNewImage, ReportRuntime rr) {
571 ArrayList images = new ArrayList();
572 if(!isGenerateNewImage) {
574 Image image = Image.getInstance(fileName);
578 catch (MalformedURLException e) {
579 isGenerateNewImage = true;
580 logger.error(EELFLoggerDelegate.errorLogger, "MalformedURLException in getImage", e);
582 catch (BadElementException e) {
583 isGenerateNewImage = true;
584 logger.error(EELFLoggerDelegate.errorLogger, "BadElementException in getImage", e);
585 } catch (FileNotFoundException e) {
586 isGenerateNewImage = true;
587 logger.error(EELFLoggerDelegate.errorLogger, "FileNotFoundException in getImage", e);
588 } catch (IOException e) {
589 isGenerateNewImage = true;
590 logger.error(EELFLoggerDelegate.errorLogger, "IOException in getImage", e);
594 if(isGenerateNewImage && retryCreateNewImageCount<RetryCreateNewImage){
595 retryCreateNewImageCount++;
596 return generateNewImage(request, rr);
597 //return getImage(request,fileName, false);
604 private ArrayList generateNewImage(HttpServletRequest request, ReportRuntime rr) {
605 ArrayList images = new ArrayList();
606 final String MALFORMEDURLEXCEPTION_MSG = "MalformedURLException in generateNewImage";
607 final String BADELEMENTEXCEPTION_MSG = "BadElementException in generateNewImage";
608 final String FILENOTFOUNDEXCEPTION_MSG = "FileNotFoundException in generateNewImage";
609 final String IOEXCEPTION_MSG = "IOException in generateNewImage";
611 //ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
613 if(request.getSession().getAttribute(AppConstants.RI_CHART_DATA)!=null) {
614 ds = (DataSet) request.getSession().getAttribute(AppConstants.RI_CHART_DATA);
616 ds = rr.loadChartData(pb.getUserId(),request);
618 String downloadFileName = "";
619 HashMap additionalChartOptionsMap = new HashMap();
620 String chartType = nvl(rr.getChartType());
621 if(chartType.equals(AppConstants.GT_PIE_MULTIPLE)) {
622 additionalChartOptionsMap.put("multiplePieOrderRow", new Boolean((AppUtils.getRequestNvlValue(request, "multiplePieOrder").length()>0?AppUtils.getRequestNvlValue(request, "multiplePieOrder").equals("row"):rr.isMultiplePieOrderByRow())) );
623 additionalChartOptionsMap.put("multiplePieLabelDisplay", AppUtils.getRequestNvlValue(request, "multiplePieLabelDisplay").length()>0? AppUtils.getRequestNvlValue(request, "multiplePieLabelDisplay"):rr.getMultiplePieLabelDisplay());
624 additionalChartOptionsMap.put("chartDisplay", new Boolean(AppUtils.getRequestNvlValue(request, "chartDisplay").length()>0? AppUtils.getRequestNvlValue(request, "chartDisplay").equals("3D"):rr.isChartDisplayIn3D()));
625 } else if (chartType.equals(AppConstants.GT_BAR_3D)) {
626 additionalChartOptionsMap.put("chartOrientation", new Boolean((AppUtils.getRequestNvlValue(request, "chartOrientation").length()>0?AppUtils.getRequestNvlValue(request, "chartOrientation").equals("vertical"):rr.isVerticalOrientation())) );
627 additionalChartOptionsMap.put("secondaryChartRenderer", AppUtils.getRequestNvlValue(request, "secondaryChartRenderer").length()>0? AppUtils.getRequestNvlValue(request, "secondaryChartRenderer"):rr.getSecondaryChartRenderer());
628 additionalChartOptionsMap.put("chartDisplay", new Boolean(AppUtils.getRequestNvlValue(request, "chartDisplay").length()>0? AppUtils.getRequestNvlValue(request, "chartDisplay").equals("3D"):rr.isChartDisplayIn3D()));
629 additionalChartOptionsMap.put("lastSeriesALineChart", new Boolean(rr.isLastSeriesALineChart()));
630 } else if (chartType.equals(AppConstants.GT_LINE)) {
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("lastSeriesABarChart", new Boolean(rr.isLastSeriesABarChart()));
635 } else if (chartType.equals(AppConstants.GT_TIME_DIFFERENCE_CHART)) {
636 additionalChartOptionsMap.put("intervalFromDate",AppUtils.getRequestNvlValue(request, "intervalFromDate").length()>0?AppUtils.getRequestNvlValue(request, "intervalFromDate"):rr.getIntervalFromdate());
637 additionalChartOptionsMap.put("intervalToDate", AppUtils.getRequestNvlValue(request, "intervalToDate").length()>0? AppUtils.getRequestNvlValue(request, "intervalToDate"):rr.getIntervalTodate());
638 additionalChartOptionsMap.put("intervalLabel", AppUtils.getRequestNvlValue(request, "intervalLabel").length()>0? AppUtils.getRequestNvlValue(request, "intervalLabel"):rr.getIntervalLabel());
639 } else if (chartType.equals(AppConstants.GT_REGRESSION)) {
640 additionalChartOptionsMap.put("regressionType",AppUtils.getRequestNvlValue(request, "regressionType").length()>0?AppUtils.getRequestNvlValue(request, "regressionType"):rr.getLinearRegression());
641 additionalChartOptionsMap.put("linearRegressionColor",nvl(rr.getLinearRegressionColor()));
642 additionalChartOptionsMap.put("expRegressionColor",nvl(rr.getExponentialRegressionColor()));
643 additionalChartOptionsMap.put("maxRegression",nvl(rr.getCustomizedRegressionPoint()));
644 } else if (chartType.equals(AppConstants.GT_STACK_BAR) ||chartType.equals(AppConstants.GT_STACKED_HORIZ_BAR) || chartType.equals(AppConstants.GT_STACKED_HORIZ_BAR_LINES)
645 || chartType.equals(AppConstants.GT_STACKED_VERT_BAR) || chartType.equals(AppConstants.GT_STACKED_VERT_BAR_LINES)
647 additionalChartOptionsMap.put("overlayItemValue",new Boolean(nvl(rr.getOverlayItemValueOnStackBar()).equals("Y")));
649 additionalChartOptionsMap.put("legendPosition", nvl(rr.getLegendPosition()));
650 additionalChartOptionsMap.put("hideToolTips", new Boolean(rr.hideChartToolTips()));
651 additionalChartOptionsMap.put("hideLegend", new Boolean(AppUtils.getRequestNvlValue(request, "hideLegend").length()>0? AppUtils.getRequestNvlValue(request, "hideLegend").equals("Y"):rr.hideChartLegend()));
652 additionalChartOptionsMap.put("labelAngle", nvl(rr.getLegendLabelAngle()));
653 additionalChartOptionsMap.put("maxLabelsInDomainAxis", nvl(rr.getMaxLabelsInDomainAxis()));
654 additionalChartOptionsMap.put("rangeAxisLowerLimit", nvl(rr.getRangeAxisLowerLimit()));
655 additionalChartOptionsMap.put("rangeAxisUpperLimit", nvl(rr.getRangeAxisUpperLimit()));
658 boolean totalOnChart = false;
659 totalOnChart = AppUtils.getRequestNvlValue(request, "totalOnChart").equals("Y");
660 String filename = null;
661 ArrayList graphURL = new ArrayList();
662 ArrayList chartNames = new ArrayList();
663 ArrayList fileNames = new ArrayList();
664 List l = rr.getAllColumns();
665 List lGroups = rr.getAllChartGroups();
666 HashMap mapYAxis = rr.getAllChartYAxis(rr.getReportParamValues());
667 String chartLeftAxisLabel = rr.getFormFieldFilled(nvl(rr.getChartLeftAxisLabel()));
668 String chartRightAxisLabel = rr.getFormFieldFilled(nvl(rr.getChartRightAxisLabel()));
669 int displayTotalOnChart = 0;
670 HashMap formValues = Globals.getRequestParamtersMap(request, false);
672 for (Iterator iterC = l.iterator(); iterC.hasNext();) {
673 DataColumnType dc = (DataColumnType) iterC.next();
674 if(nvl(dc.getColName()).equals(AppConstants.RI_CHART_TOTAL_COL)) {
675 displayTotalOnChart = 1;
679 String legendColumnName = (rr.getChartLegendColumn()!=null)?rr.getChartLegendColumn().getDisplayName():"Legend Column";
685 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**/
686 for (int i=0; i<rr.getChartValueColumnAxisList(AppConstants.CHART_ALL_COLUMNS, formValues).size();i++) {
687 String chartTitle = Globals.getDisplayChartTitle()? rr.getReportName():"";
688 chartTitle = rr.getFormFieldFilled(chartTitle);
689 downloadFileName = AppUtils.getTempFolderPath()+"cr_"+pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_"+i+".png";
690 filename = null;/*(String) ChartGen.generateChart( chartType,
691 request.getSession(),
696 rr.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues).subList(i, i+1),
697 rr.getChartColumnColorsList(AppConstants.CHART_ALL_COLUMNS, formValues).subList(i, i+1),
698 rr.getChartValueColumnAxisList(AppConstants.CHART_ALL_COLUMNS, formValues).subList(i, i+1),
702 rr.getChartWidthAsInt(),
703 rr.getChartHeightAsInt(),
704 rr.getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, formValues).subList(i,i+1),
705 rr.hasSeriesColumn(),
706 //rr.isChartMultiSeries(),
711 AppConstants.WEB_VERSION deviceType,
712 additionalChartOptionsMap,
716 Image image = Image.getInstance(downloadFileName);
718 } catch (MalformedURLException e) {
719 logger.error(EELFLoggerDelegate.errorLogger, MALFORMEDURLEXCEPTION_MSG,
721 } catch (BadElementException e) {
722 logger.error(EELFLoggerDelegate.errorLogger, BADELEMENTEXCEPTION_MSG,
724 } catch (FileNotFoundException e) {
725 logger.error(EELFLoggerDelegate.errorLogger, FILENOTFOUNDEXCEPTION_MSG,
727 } catch (IOException e) {
728 logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e);
732 } else { /** first check the columns to be opened in new charts and loop around in ChartGen generate chart function - sundar**/
733 String tempChartGroupPrev = "";
734 String tempChartGroupCurrent = "";
735 for (int i=0; i<lGroups.size();i++) {
736 String chartGroupOrg = (String) lGroups.get(i);
737 String chartYAxis = (String) mapYAxis.get(chartGroupOrg);
738 //System.out.println("chartGroupOrg " + chartGroupOrg);
739 if(nvl(chartGroupOrg).length()>0)
740 tempChartGroupCurrent = chartGroupOrg.substring(0,chartGroupOrg.lastIndexOf("|"));
741 if(i>0) tempChartGroupPrev = ((String) lGroups.get(i-1)).substring(0,((String) lGroups.get(i-1)).lastIndexOf("|"));
742 //System.out.println("TEMPCHARTGROUP " + tempChartGroupCurrent + " " + tempChartGroupPrev);
743 if(tempChartGroupCurrent.equals(tempChartGroupPrev)) continue;
744 //System.out.println("CHARTGROUPORG " + chartGroupOrg + " " + lGroups) ;
745 //String chartGroup = chartGroupOrg.substring(0,chartGroupOrg.lastIndexOf("|"));
746 String chartGroup = chartGroupOrg;
748 //System.out.println("$$$$CHARTGROUP in JSP " +chartGroup+ " "+ chartGroupOrg );
749 //System.out.println(" rr.getChartGroupDisplayNamesList(chartGroup) " + rr.getChartGroupDisplayNamesList(chartGroup));
750 //System.out.println(" rr.getChartGroupColumnColorsList(chartGroup) " + rr.getChartGroupColumnColorsList(chartGroup));
751 //System.out.println(" rr.getChartGroupColumnAxisList(chartGroup) " + rr.getChartGroupColumnAxisList(chartGroup));
752 //System.out.println(" rr.getChartGroupValueColumnAxisList(chartGroupOrg) " + rr.getChartGroupValueColumnAxisList(chartGroupOrg));
754 downloadFileName = AppUtils.getTempFolderPath()+"cr_"+pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_"+i+".png";
755 String chartTitle = (Globals.getDisplayChartTitle()? (chartGroup!=null && chartGroup.indexOf("|") > 0 ?chartGroup.substring(0,chartGroup.lastIndexOf("|")):rr.getReportName()):"");
756 chartTitle = rr.getFormFieldFilled(chartTitle);
757 String leftAxisLabel = "";
758 //if(!rr.isChartMultiSeries()) {
759 if(!rr.isMultiSeries()) {
760 leftAxisLabel = ((chartYAxis!=null && chartYAxis.indexOf("|") > 0) ? chartYAxis.substring(0,chartYAxis.lastIndexOf("|")): chartLeftAxisLabel );
762 leftAxisLabel = chartLeftAxisLabel;
765 filename = null;/*(String) ChartGen.generateChart( chartType,
766 request.getSession(),
771 ((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)),
772 ((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)),
773 ((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)),
777 rr.getChartWidthAsInt(),
778 rr.getChartHeightAsInt(),
779 ((chartType.indexOf("Stacked")>0 || chartType.equals(AppConstants.GT_PIE_MULTIPLE))?rr.getChartValueColumnsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues):rr.getChartGroupValueColumnAxisList(chartGroupOrg, formValues)),
780 rr.hasSeriesColumn(),
781 //rr.isChartMultiSeries(),
786 AppConstants.WEB_VERSION deviceType,
787 additionalChartOptionsMap,
791 Image image = Image.getInstance(downloadFileName);
793 } catch (MalformedURLException e) {
794 logger.error(EELFLoggerDelegate.errorLogger, MALFORMEDURLEXCEPTION_MSG,
796 } catch (BadElementException e) {
797 logger.error(EELFLoggerDelegate.errorLogger, BADELEMENTEXCEPTION_MSG,
799 } catch (FileNotFoundException e) {
800 logger.error(EELFLoggerDelegate.errorLogger, FILENOTFOUNDEXCEPTION_MSG,
802 } catch (IOException e) {
803 logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e);
807 if(!chartType.equals(AppConstants.GT_PIE_MULTIPLE)) {
808 for (int i=0; i<rr.getChartValueColumnAxisList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).size();i++) {
809 //System.out.println(" rr.getChartDisplayNamesList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i, i+1) " + rr.getChartDisplayNamesList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i, i+1));
810 //System.out.println(" rr.getChartValueColumnAxisList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i, i+1) " + rr.getChartValueColumnAxisList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i, i+1));
811 //System.out.println(" rr.getChartValueColumnsList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i,i+1) " + rr.getChartValueColumnsList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i,i+1));
813 downloadFileName = AppUtils.getTempFolderPath()+"cr_"+ pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_"+i+".png";
814 String chartTitle = Globals.getDisplayChartTitle()? rr.getReportName():"";
815 chartTitle = rr.getFormFieldFilled(chartTitle);
817 filename = null; /*(String) ChartGen.generateChart( chartType,
818 request.getSession(),
823 (chartType.equals(AppConstants.GT_PIE_MULTIPLE))?rr.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues):rr.getChartDisplayNamesList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).subList(i, i+1),
824 (chartType.equals(AppConstants.GT_PIE_MULTIPLE))?rr.getChartColumnColorsList(AppConstants.CHART_ALL_COLUMNS, formValues):rr.getChartColumnColorsList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).subList(i, i+1),
825 (chartType.equals(AppConstants.GT_PIE_MULTIPLE))?rr.getChartValueColumnAxisList(AppConstants.CHART_ALL_COLUMNS, formValues):rr.getChartValueColumnAxisList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).subList(i, i+1),
829 rr.getChartWidthAsInt(),
830 rr.getChartHeightAsInt(),
831 rr.getChartValueColumnsList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).subList(i,i+1),
832 rr.hasSeriesColumn(),
833 //rr.isChartMultiSeries(),
838 AppConstants.WEB_VERSION,
839 additionalChartOptionsMap,
843 Image image = Image.getInstance(downloadFileName);
845 } catch (MalformedURLException e) {
846 logger.error(EELFLoggerDelegate.errorLogger,
847 MALFORMEDURLEXCEPTION_MSG, e);
848 } catch (BadElementException e) {
849 logger.error(EELFLoggerDelegate.errorLogger,
850 BADELEMENTEXCEPTION_MSG, e);
851 } catch (FileNotFoundException e) {
852 logger.error(EELFLoggerDelegate.errorLogger,
853 FILENOTFOUNDEXCEPTION_MSG, e);
854 } catch (IOException e) {
855 logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e);
859 /** second rest of the columns are merged to one single chart - sundar**/
860 // System.out.println(" rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS) " + rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS));
861 // System.out.println(" rr.getChartValueColumnAxisList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS) " + rr.getChartValueColumnAxisList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS));
862 // System.out.println(" rr.getChartValueColumnsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS) " + rr.getChartValueColumnsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS));
864 if((!(lGroups!=null && lGroups.size() > 0))) {
866 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) {
867 downloadFileName = AppUtils.getTempFolderPath()+"cr_"+ pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_All.png";
868 String chartTitle = Globals.getDisplayChartTitle()? rr.getReportName():"";
869 chartTitle = rr.getFormFieldFilled(chartTitle);
871 filename = null; /*(String) ChartGen.generateChart( chartType,
872 request.getSession(),
877 rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues),
878 rr.getChartColumnColorsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues),
879 rr.getChartValueColumnAxisList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues),
883 rr.getChartWidthAsInt(),
884 rr.getChartHeightAsInt(),
885 rr.getChartValueColumnsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues),
886 rr.hasSeriesColumn(),
887 //rr.isChartMultiSeries(),
892 AppConstants.WEB_VERSION,
893 additionalChartOptionsMap,
897 Image image = Image.getInstance(downloadFileName);
899 } catch (MalformedURLException e) {
900 logger.error(EELFLoggerDelegate.errorLogger,
901 MALFORMEDURLEXCEPTION_MSG, e);
902 } catch (BadElementException e) {
903 logger.error(EELFLoggerDelegate.errorLogger,
904 BADELEMENTEXCEPTION_MSG, e);
905 } catch (FileNotFoundException e) {
906 logger.error(EELFLoggerDelegate.errorLogger,
907 FILENOTFOUNDEXCEPTION_MSG, e);
908 } catch (IOException e) {
909 logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e);
912 } // Stacked Chart Check
913 } // else no Series Column
917 } catch (Exception e) {
918 logger.error(EELFLoggerDelegate.errorLogger, "Exception in generateNewImage", e);
920 // System.out.println("Total Images " + images.size());
921 return images.size()>0?images:null;
926 private boolean isImageRotate(Document doc, Image image) {
928 System.out.println("image size="+image.getWidthPercentage()+ " "+ image.scaledWidth()+
929 " "+image.scaledHeight()+" "+image.getXYRatio());
930 System.out.println("page size = "+ doc.getPageSize().width() + " " +doc.getPageSize().height() +" "+
931 doc.topMargin() + " " +doc.bottomMargin() + " " + doc.leftMargin() + " " +
933 System.out.println(image.scaledWidth()/image.scaledHeight());
934 System.out.println((PageEvent.getPageWidth(doc)/PageEvent.getPageHeight(doc)));
935 // System.out.println(doc.getPageSize().getRotation());
937 float image_w = image.scaledWidth();
938 float image_h = image.scaledHeight();
939 float image_ratio = image_w/image_h;
941 float page_w = PageEvent.getPageWidth(doc);
942 float page_h = PageEvent.getPageHeight(doc);
943 float page_ratio = page_w/page_h;
945 return (image_w > page_w && image_ratio > page_ratio) ||
946 (image_h > page_h && image_ratio < page_ratio);
951 private final int DEFAULT_PDF_DISPLAY_WIDTH = 10;
953 private int paintPdfData(final HttpServletRequest request, final Document document, final ReportData rd,
954 final ReportRuntime rr, final String sql_whole) throws DocumentException, RaptorException, IOException {
956 final int mb = 1024 * 1024;
957 final Runtime runtime = Runtime.getRuntime();
960 final float f[] = getRelativeWidths(rd, AppConstants.RT_CROSSTAB.equals(rr.getReportType()));
961 PdfPTable table = new PdfPTable(f);
962 table.setWidthPercentage(100f);
963 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
964 table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM);
966 final ReportDefinition rdef = (new ReportHandler()).loadReportDefinition(request, rr.getReportID());
968 final List allColumns = rdef.getAllColumns();
970 final float[] repotWidths = new float[rdef.getVisibleColumnCount()];
972 float pdfDisplayWidth = 0;
973 for (final Iterator iter = allColumns.iterator(); iter.hasNext(); ) {
974 final DataColumnType dct = (DataColumnType) iter.next();
975 if (dct.isVisible()) {
977 if (dct.getPdfDisplayWidthInPxls() == null || dct.getPdfDisplayWidthInPxls().isEmpty() || dct
978 .getPdfDisplayWidthInPxls().startsWith("null")) {
979 pdfDisplayWidth = DEFAULT_PDF_DISPLAY_WIDTH;
981 pdfDisplayWidth = Float.parseFloat(dct.getPdfDisplayWidthInPxls());
984 repotWidths[columnIdx++] = pdfDisplayWidth;
988 table.setWidths(repotWidths);
990 //TODO: check title and subtitle
991 final HttpSession session = request.getSession();
992 final String drilldown_index = (String) session.getAttribute("drilldown_index");
995 index = Integer.parseInt(drilldown_index);
996 } catch (NumberFormatException ex) {
999 final String titleRep = (String) session.getAttribute("TITLE_" + index);
1000 final String subtitle = (String) session.getAttribute("SUBTITLE_" + index);
1002 if (nvl(titleRep).length() > 0 && nvl(subtitle).length() > 0) {
1003 table.setHeaderRows(3);
1004 } else if (nvl(titleRep).length() > 0) {
1005 table.setHeaderRows(2);
1007 table.setHeaderRows(1);
1009 table = paintPdfReportHeader(request, document, table, rr, f);
1010 paintPdfTableHeader(document, rd, table);
1013 final int fragmentsize = 30; //for memory management
1015 rd.reportDataRows.resetNext();
1016 DataRow dr = rd.reportDataRows.getNext();
1018 if (nvl(sql_whole).length() > 0 && AppConstants.RT_LINEAR.equals(rr.getReportType())) {
1019 try (final Connection conn = ConnectionUtils.getConnection(rr.getDbInfo());
1020 final Statement st = conn.createStatement();
1021 final ResultSet rs = st.executeQuery(sql_whole);) {
1023 logger.debug(EELFLoggerDelegate.debugLogger, ("************* Map Whole SQL *************"));
1024 logger.debug(EELFLoggerDelegate.debugLogger, (sql_whole));
1025 logger.debug(EELFLoggerDelegate.debugLogger, ("*****************************************"));
1027 final ResultSetMetaData rsmd = rs.getMetaData();
1028 final int numberOfColumns = rsmd.getColumnCount();
1034 final Map colHash = new HashMap();
1035 for (int i = 1; i <= numberOfColumns; i++) {
1036 colHash.put(rsmd.getColumnLabel(i).toUpperCase(), rs.getString(i));
1038 rd.reportDataRows.resetNext();
1040 dr = rd.reportDataRows.getNext();
1042 for (dr.resetNext(); dr.hasNext(); ) {
1043 final DataValue dv = dr.getNext();
1045 final String value = nvl((String) colHash.get(dv.getColId().toUpperCase()));
1046 if (dv.isVisible()) {
1048 final HtmlFormatter cfmt = dv.getCellFormatter();
1049 final HtmlFormatter rfmt = dv.getRowFormatter();
1051 final Font cellFont = FontFactory.getFont(FONT_FAMILY,
1053 Font.NORMAL, Color.BLACK);
1055 cellFormatterFont(cfmt, cellFont);
1056 } else if (rfmt != null) {
1057 cellFormatterFont(rfmt, cellFont);
1060 cellFont.setStyle(Font.BOLD);
1064 final String cellValue = strip.stripHtml(value.trim());
1065 final PdfPCell cell = new PdfPCell(new Paragraph(cellValue, cellFont));
1067 //row background color can be overwritten by cell background color
1068 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1070 if (nvl(dv.getAlignment()).trim().length() > 0) {
1071 cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment()));
1073 cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1077 formatterCell(cfmt, cell);
1078 } else if (rfmt != null) {
1079 formatterCell(rfmt, cell);
1082 table.addCell(cell);
1089 if (rd.reportDataTotalRow != null) {
1090 for (rd.reportDataTotalRow.resetNext(); rd.reportDataTotalRow.hasNext(); idx++) {
1091 dr = rd.reportDataTotalRow.getNext();
1092 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1093 final Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY,
1095 Font.NORMAL, Color.BLACK);
1096 rowHeaderFont.setStyle(Font.BOLD);
1097 rowHeaderFont.setSize(FONT_SIZE + 1f);
1098 table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx));
1099 table.addCell(new Paragraph("Total", rowHeaderFont));
1101 addTotalRowColumns(table, dr, idx);
1102 if (idx % fragmentsize == fragmentsize - 1) {
1103 document.add(table);
1104 table.deleteBodyRows();
1105 table.setSkipFirstHeader(true);
1110 } catch (final SQLException | ReportSQLException ex) {
1111 throw new RaptorException(ex);
1112 } catch (final Exception ex) {
1113 if (!(ex.getCause() instanceof java.net.SocketException)) {
1114 throw new RaptorException(ex);
1117 //document.add(table);
1119 if (rr.getReportType().equals(AppConstants.RT_LINEAR)) {
1120 for (rd.reportDataRows.resetNext(); rd.reportDataRows.hasNext(); idx++) {
1122 if (runtime.freeMemory() / mb <= ((runtime.maxMemory() / mb) * Globals.getMemoryThreshold()
1127 dr = rd.reportDataRows.getNext();
1129 addRowHeader(table, dr, idx, rd);
1131 addRowColumns(table, dr, idx);
1133 if (idx % fragmentsize == fragmentsize - 1) {
1134 document.add(table);
1135 table.deleteBodyRows();
1136 table.setSkipFirstHeader(true);
1140 if (rd.reportDataTotalRow != null) {
1141 for (rd.reportDataTotalRow.resetNext(); rd.reportDataTotalRow.hasNext(); idx++) {
1142 dr = rd.reportDataTotalRow.getNext();
1143 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1144 Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY,
1146 Font.NORMAL, Color.BLACK);
1147 rowHeaderFont.setStyle(Font.BOLD);
1148 rowHeaderFont.setSize(FONT_SIZE + 1f);
1149 table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx));
1150 table.addCell(new Paragraph("Total", rowHeaderFont));
1152 addTotalRowColumns(table, dr, idx);
1153 if (idx % fragmentsize == fragmentsize - 1) {
1154 document.add(table);
1155 table.deleteBodyRows();
1156 table.setSkipFirstHeader(true);
1162 } else if (AppConstants.RT_CROSSTAB.equals(rr.getReportType())) {
1164 final List l = rd.getReportDataList();
1165 boolean first = true;
1166 for (int dataRow = 0; dataRow < l.size(); dataRow++) {
1169 dr = (DataRow) l.get(dataRow);
1170 final Vector<DataValue> rowNames = dr.getRowValues();
1171 for (dr.resetNext(); dr.hasNext(); ) {
1174 HtmlFormatter rfmt = dr.getRowFormatter();
1176 Font cellFont = FontFactory.getFont(FONT_FAMILY,
1178 Font.NORMAL, Color.BLACK);
1180 cellFormatterFont(rfmt, cellFont);
1183 if (rowNames != null) {
1184 for (int i = 0; i < rowNames.size(); i++) {
1185 final DataValue dv = rowNames.get(i);
1186 rfmt = dr.getRowFormatter();
1188 cellFont = FontFactory.getFont(FONT_FAMILY,
1190 Font.NORMAL, Color.BLACK);
1192 cellFormatterFont(rfmt, cellFont);
1194 String cellValue = dv.getDisplayValue();
1195 if (cellValue.indexOf("|#") != -1) {
1196 cellValue = cellValue.substring(0, cellValue.indexOf("|"));
1199 final PdfPCell cell = new PdfPCell(new Paragraph(cellValue, cellFont));
1200 //row background color can be overwritten by cell background color
1201 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1203 cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1206 formatterCell(rfmt, cell);
1208 table.addCell(cell);
1214 if (runtime.freeMemory() / mb <= ((runtime.maxMemory() / mb) * Globals.getMemoryThreshold()
1219 //addRowHeader(table,dr,idx,rd);
1221 addRowColumns(table, dr, idx);
1223 if (idx % fragmentsize == fragmentsize - 1) {
1224 document.add(table);
1225 table.deleteBodyRows();
1226 table.setSkipFirstHeader(true);
1233 //document.add(table);
1237 document.add(table);
1238 paintPdfReportFooter(request, document, rr, f);
1243 private void addRowHeader(PdfPTable table, DataRow dr, int idx, ReportData rd) {
1245 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1247 for(rd.reportRowHeaderCols.resetNext();rd.reportRowHeaderCols.hasNext();) {
1248 RowHeaderCol rhc = rd.reportRowHeaderCols.getNext();
1251 RowHeader rh = rhc.getNext();
1252 //System.out.println(" =============== RowHeader\n "+rh);
1254 Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY,
1256 Font.NORMAL, Color.BLACK);
1258 rowHeaderFont.setStyle(Font.BOLD);
1259 rowHeaderFont.setSize(FONT_SIZE+1f);
1262 if(rh.getColSpan()>0) {
1263 table.getDefaultCell().setColspan(rh.getColSpan());
1264 table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx));
1265 table.addCell(new Paragraph(strip.stripHtml(rh.getRowTitle()),rowHeaderFont));
1270 private void addRowColumns(PdfPTable table, DataRow dr, int idx) {
1272 table.getDefaultCell().setColspan(1);
1274 for(dr.resetNext();dr.hasNext();)
1276 DataValue dv = dr.getNext();
1277 //System.out.println(columnCount +" --> "+dv);
1278 if(dv.isVisible()) {
1279 HtmlFormatter cfmt = dv.getCellFormatter();
1280 HtmlFormatter rfmt = dv.getRowFormatter();
1282 Font cellFont = FontFactory.getFont(FONT_FAMILY,
1284 Font.NORMAL, Color.BLACK);
1286 cellFormatterFont(cfmt,cellFont);
1288 else if(rfmt != null) {
1289 cellFormatterFont(rfmt,cellFont);
1293 cellFont.setStyle(Font.BOLD);
1297 String cellValue = strip.stripHtml(dv.getDisplayValue().trim());
1298 PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont));
1300 //row background color can be overwritten by cell background color
1301 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1303 if(nvl(dv.getAlignment()).trim().length()>0)
1304 cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment()));
1306 cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1309 formatterCell(cfmt,cell);
1311 else if(rfmt != null) {
1312 formatterCell(rfmt,cell);
1315 table.addCell(cell);
1322 private void addTotalRowColumns(PdfPTable table, DataRow dr, int idx) {
1324 table.getDefaultCell().setColspan(1);
1329 DataValue dv = dr.getNext();
1330 //System.out.println(columnCount +" --> "+dv);
1331 if(dv.isVisible()) {
1332 HtmlFormatter cfmt = dv.getCellFormatter();
1333 HtmlFormatter rfmt = dv.getRowFormatter();
1335 Font cellFont = FontFactory.getFont(FONT_FAMILY,
1337 Font.NORMAL, Color.BLACK);
1339 cellFormatterFont(cfmt,cellFont);
1341 else if(rfmt != null) {
1342 cellFormatterFont(rfmt,cellFont);
1346 cellFont.setStyle(Font.BOLD);
1350 String cellValue = strip.stripHtml(dv.getDisplayValue().trim());
1351 PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont));
1353 //row background color can be overwritten by cell background color
1354 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1356 if(nvl(dv.getAlignment()).trim().length()>0)
1357 cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment()));
1359 cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1362 formatterCell(cfmt,cell);
1364 else if(rfmt != null) {
1365 formatterCell(rfmt,cell);
1368 table.addCell(cell);
1375 private void formatterCell(HtmlFormatter fmt, PdfPCell cell) {
1377 if(nvl(fmt.getBgColor()).trim().length()>0)
1378 cell.setBackgroundColor(Color.decode(fmt.getBgColor()));
1379 if(nvl(fmt.getAlignment()).trim().length()>0)
1380 cell.setHorizontalAlignment(ElementTags.alignmentValue(fmt.getAlignment()));
1383 private void cellFormatterFont(HtmlFormatter fmt, Font font) {
1386 font.setStyle(Font.BOLD);
1388 font.setStyle(Font.ITALIC);
1389 if(fmt.isUnderline())
1390 font.setStyle(Font.UNDERLINE);
1391 if(fmt.getFontColor().trim().length()>0)
1392 font.setColor(Color.decode(fmt.getFontColor()));
1393 if(fmt.getFontSize().trim().length()>0)
1394 font.setSize(Float.parseFloat(fmt.getFontSize())-Globals.getDataFontSizeOffset());
1395 // if(fmt.getFontFace().trim().length()>0)
1396 // cellFont.setFamily()
1400 private Color getRowBackgroundColor(DataRow dr, int idx) {
1402 Color color = Color.decode(Globals.getDataDefaultBackgroundHexCode());
1404 HtmlFormatter rhf = dr.getRowFormatter();
1405 if(rhf!=null && nvl(rhf.getBgColor()).trim().length()>0)
1407 color = Color.decode(rhf.getBgColor());
1409 else if(pb.isAlternateColor() && idx%2==0)
1411 color = Color.decode(Globals.getDataBackgroundAlternateHexCode());
1417 private int getTotalVisbleColumns(ReportData rd) {
1419 int totalVisbleColumn = rd.getTotalColumnCount();
1420 for(rd.reportDataRows.resetNext();rd.reportDataRows.hasNext();)
1422 DataRow dr = rd.reportDataRows.getNext();
1423 for(dr.resetNext();dr.hasNext();) {
1424 DataValue dv = dr.getNext();
1425 if(!dv.isVisible()) totalVisbleColumn--;
1431 return totalVisbleColumn;
1435 private int getFirstRowIndex(ReportRuntime rr) {
1436 return (pb.getCurrentPage()>0)?pb.getCurrentPage()*rr.getPageSize()+1 : 1;
1439 private float[] getRelativeWidths(ReportData rd, boolean crosstab){
1441 int totalColumns = getTotalVisbleColumns(rd);
1442 /*if(rd.reportTotalRowHeaderCols!=null) {
1449 if(totalColumns == 0 )
1452 float[] relativeWidths = new float[totalColumns];
1453 //initial widths are even
1454 for(int i=0; i<relativeWidths.length; i++)
1455 relativeWidths[i] = 10f;
1458 boolean firstPass = true;
1460 for (rd.reportColumnHeaderRows.resetNext(); rd.reportColumnHeaderRows.hasNext();)
1463 /*if(rd.reportTotalRowHeaderCols!=null) {
1464 String columnWidth = "5";
1466 if(columnWidth != null && columnWidth.trim().endsWith("%"))
1467 relativeWidths[index] = Float.parseFloat(removeLastCharacter(columnWidth));
1472 for(rd.reportRowHeaderCols.resetNext();rd.reportRowHeaderCols.hasNext();) {
1473 String columnWidth = rd.reportRowHeaderCols.getNext().getColumnWidth();
1475 if(columnWidth != null && columnWidth.trim().endsWith("%"))
1476 relativeWidths[index] = Float.parseFloat(removeLastCharacter(columnWidth));
1483 ColumnHeaderRow chr = rd.reportColumnHeaderRows.getNext();
1484 for (chr.resetNext(); chr.hasNext();) {
1486 ColumnHeader ch = chr.getNext();
1488 if(ch.isVisible()) {
1490 String columnWidth = ch.getColumnWidth();
1492 if(ch.getColSpan() <= 1){
1493 if(columnWidth != null && columnWidth.trim().endsWith("%"))
1494 relativeWidths[index] = Float.parseFloat(removeLastCharacter(columnWidth));
1497 for(int i=0; i<ch.getColSpan(); i++) {
1499 if(columnWidth != null && columnWidth.trim().endsWith("%"))
1500 relativeWidths[index] =
1501 (Float.parseFloat(removeLastCharacter(columnWidth)))/ch.getColSpan();
1510 return relativeWidths;
1513 public static String removeLastCharacter(String str) {
1514 return str.substring(0, str.length()-1);
1517 private PdfPTable paintPdfReportHeader(HttpServletRequest request, Document document, PdfPTable table, ReportRuntime rr, float[] f)
1518 throws DocumentException, IOException {
1520 HttpSession session = request.getSession();
1521 String drilldown_index = (String) session.getAttribute("drilldown_index");
1524 index = Integer.parseInt(drilldown_index);
1525 } catch (NumberFormatException ex) {
1528 String title = (String) session.getAttribute("TITLE_"+index);
1529 String subtitle = (String) session.getAttribute("SUBTITLE_"+index);
1530 if(nvl(title).length()>0) {
1531 //PdfPTable table = new PdfPTable(1);
1532 table.setWidthPercentage(100f);
1533 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1534 table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM);
1537 Font font = FontFactory.getFont(FONT_FAMILY,
1542 //addEmptyRows(table,1);
1543 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1544 //table.getDefaultCell().setBackgroundColor(Color.decode(Globals.getDataTableHeaderBackgroundFontColor()));
1545 title = Utils.replaceInString(title, "<BR/>", " ");
1546 title = Utils.replaceInString(title, "<br/>", " ");
1547 title = Utils.replaceInString(title, "<br>", " ");
1548 title = strip.stripHtml(nvl(title).trim());
1549 //subtitle = Utils.replaceInString(subtitle, "<BR/>", " ");
1550 //subtitle = Utils.replaceInString(subtitle, "<br/>", " ");
1551 //subtitle = Utils.replaceInString(subtitle, "<br>", " ");
1552 //subtitle = strip.stripHtml(nvl(subtitle).trim());
1553 StyleSheet styles = new StyleSheet();
1555 HTMLWorker htmlWorker = new HTMLWorker(document);
1556 ArrayList cc = new ArrayList();
1557 cc = htmlWorker.parseToList(new StringReader(subtitle), styles);
1559 Phrase p1 = new Phrase();
1560 for (int i = 0; i < cc.size(); i++){
1561 Element elem = (Element)cc.get(i);
1562 ArrayList al = elem.getChunks();
1563 for (int j = 0; j < al.size(); j++) {
1564 Chunk chunk = (Chunk) al.get(j);
1565 chunk.font().setSize(6.0f);
1569 //cell = new PdfPCell(p1);
1570 StyleSheet style = new StyleSheet();
1571 style.loadTagStyle("font", "font-size", "3");
1572 style.loadTagStyle("font", "size", "3");
1573 styles.loadStyle("pdfFont1", "size", "11px");
1574 styles.loadStyle("pdfFont1", "font-size", "11px");
1575 /*ArrayList p = HTMLWorker.parseToList(new StringReader(nvl(title)), style);
1576 for (int k = 0; k < p.size(); ++k){
1577 document.add((com.lowagie.text.Element)p.get(k));
1579 //p1.font().setSize(3.0f);
1580 PdfPCell titleCell = new PdfPCell(new Phrase(title, font));
1581 titleCell.setColspan(rr.getVisibleColumnCount());
1582 PdfPCell subtitleCell = new PdfPCell(p1);
1583 subtitleCell.setColspan(rr.getVisibleColumnCount());
1584 titleCell.setHorizontalAlignment(1);
1585 subtitleCell.setHorizontalAlignment(1);
1586 table.addCell(titleCell);
1587 table.addCell(subtitleCell);
1588 //document.add(table);
1594 private void paintPdfReportFooter(HttpServletRequest request, Document document, ReportRuntime rr, float[] f)
1595 throws DocumentException, IOException {
1597 HttpSession session = request.getSession();
1598 String drilldown_index = (String) session.getAttribute("drilldown_index");
1601 index = Integer.parseInt(drilldown_index);
1602 } catch (NumberFormatException ex) {
1606 String title = (String) session.getAttribute("FOOTER_"+index);
1607 if(nvl(title).length()>0) {
1608 PdfPTable table = new PdfPTable(1);
1609 table.setWidthPercentage(100f);
1610 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1611 table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM);
1613 Font font = FontFactory.getFont(FONT_FAMILY,
1619 //addEmptyRows(table,1);
1620 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1621 //table.getDefaultCell().setBackgroundColor(Color.decode(Globals.getDataTableHeaderBackgroundFontColor()));
1622 /*title = Utils.replaceInString(title, "<BR/>", " ");
1623 title = Utils.replaceInString(title, "<br/>", " ");
1624 title = Utils.replaceInString(title, "<br>", " ");
1625 title = strip.stripHtml(nvl(title).trim());*/
1626 StyleSheet style = new StyleSheet();
1628 HTMLWorker htmlWorker = new HTMLWorker(document);
1629 ArrayList cc = new ArrayList();
1630 cc = htmlWorker.parseToList(new StringReader(title), style);
1632 Phrase p1 = new Phrase();
1633 for (int i = 0; i < cc.size(); i++){
1634 Element elem = (Element)cc.get(i);
1635 ArrayList al = elem.getChunks();
1636 for (int j = 0; j < al.size(); j++) {
1637 Chunk chunk = (Chunk) al.get(j);
1638 chunk.font().setSize(6.0f);
1644 HTMLWorker.parseToList(new StringReader(nvl(title)), style);*/
1645 PdfPCell titleCell = new PdfPCell(p1);
1646 titleCell.setHorizontalAlignment(Element.ALIGN_LEFT);
1647 table.addCell(titleCell);
1649 document.add(table);
1655 private void paintPdfTableHeader(Document document, ReportData rd, PdfPTable table)
1656 throws DocumentException {
1658 Font font = FontFactory.getFont(FONT_FAMILY,
1661 Color.decode(Globals.getDataTableHeaderFontColor()));
1662 //table.setHeaderRows(1);
1663 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1664 table.getDefaultCell().setBackgroundColor(Color.decode(Globals.getDataTableHeaderBackgroundFontColor()));
1667 boolean firstPass = true;
1669 /*if(rd.reportTotalRowHeaderCols!=null) {
1671 table.addCell(new Paragraph("No.", font));
1675 for (rd.reportColumnHeaderRows.resetNext(); rd.reportColumnHeaderRows.hasNext();)
1678 for(rd.reportRowHeaderCols.resetNext();rd.reportRowHeaderCols.hasNext();) {
1680 table.addCell(new Paragraph("No.", font));
1683 RowHeaderCol rhc = rd.reportRowHeaderCols.getNext();
1684 title = rhc.getColumnTitle();
1685 title = Utils.replaceInString(title,"_nl_", " \n");
1686 table.addCell(new Paragraph(title,font));
1691 ColumnHeaderRow chr = rd.reportColumnHeaderRows.getNext();
1692 for (chr.resetNext(); chr.hasNext();) {
1693 ColumnHeader ch = chr.getNext();
1694 //System.out.println(ch);
1695 if(ch.isVisible()) {
1696 title = ch.getColumnTitle();
1697 title = Utils.replaceInString(title,"_nl_", " \n");
1698 table.addCell(new Paragraph(title,font));
1704 public static String currentTime(String pattern) {
1706 SimpleDateFormat oracleDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss");
1707 Date sysdate = oracleDateFormat.parse(ReportLoader.getSystemDateTime());
1708 SimpleDateFormat dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern());
1709 return dtimestamp.format(sysdate)+" "+Globals.getTimeZone();
1710 //paramList.add(new IdNameValue("DATE", dtimestamp.format(sysdate)+" "+Globals.getTimeZone()));
1711 } catch(Exception ex) {}
1713 SimpleDateFormat s = new SimpleDateFormat(pattern);
1714 s.setTimeZone(TimeZone.getTimeZone(Globals.getTimeZone()));
1715 //System.out.println("^^^^^^^^^^^^^^^^^^^^ " + Calendar.getInstance().getTime());
1716 //System.out.println("^^^^^^^^^^^^^^^^^^^^ " + s.format(Calendar.getInstance().getTime()));
1717 return s.format(Calendar.getInstance().getTime());
1720 private PdfBean preparePdfBean(HttpServletRequest request,ReportRuntime rr) {
1721 PdfBean pb = new PdfBean();
1723 pb.setUserId(AppUtils.getUserID(request));
1725 pb.setWhereToShowPageNumber(Globals.getPageNumberPosition());
1726 pb.setAlternateColor(Globals.isDataAlternateColor());
1727 pb.setTimestampPattern(Globals.getDatePattern());
1731 temp = Integer.parseInt(request.getParameter(AppConstants.RI_NEXT_PAGE));
1732 } catch (NumberFormatException e) {}
1733 pb.setCurrentPage(temp);
1735 //pb.setPortrait( trueORfalse(request.getParameter("isPortrait"),true));
1736 pb.setPortrait(trueORfalse(rr.getPDFOrientation() == "portait"?"true":"false", true));
1737 //pb.setCoverPageIncluded( trueORfalse(request.getParameter("isCoverPageIncluded"), true));
1738 //if(Globals.isCoverPageNeeded()) {
1739 pb.setCoverPageIncluded(Globals.isCoverPageNeeded()?rr.isPDFCoverPage():false);
1741 pb.setTitle(nvl(request.getParameter("title")));
1742 pb.setPagesize(nvls(request.getParameter("pagesize"),"LETTER"));
1744 pb.setLogo1Url(rr.getPDFLogo1());
1745 pb.setLogo2Url(rr.getPDFLogo2());
1746 pb.setLogo1Size(rr.getPDFLogo1Size());
1747 pb.setLogo2Size(rr.getPDFLogo2Size());
1748 pb.setFullWebContextPath(request.getSession().getServletContext().getRealPath(File.separator));
1751 pb.setDisplayChart(nvl(rr.getChartType()).trim().length()>0 && rr.getDisplayChart());
1753 String id = nvl(request.getParameter("pdfAttachmentKey")).trim();
1754 String log_id = nvl(request.getParameter("log_id")).trim();
1755 if(id.length()>0 && log_id.length()>0)
1756 pb.setAttachmentOfEmail(true);
1761 private boolean trueORfalse(String str) {
1762 return (str != null) && (str.equalsIgnoreCase("true"));
1765 private boolean trueORfalse(String str,boolean b_default) {
1766 return str==null ? b_default : (str.equalsIgnoreCase("true"));