c27ba0c5656dc44fcff1129b07361ef11a51bdb9
[portal/sdk.git] /
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20
21 /* ===========================================================================================
22  * This class is part of <I>RAPTOR (Rapid Application Programming Tool for OLAP Reporting)</I> 
23  * Raptor : This tool is used to generate different kinds of reports with lot of utilities
24  * ===========================================================================================
25  *
26  * -------------------------------------------------------------------------------------------
27  * PdfReportHandler.java - This class is used to generate reports in PDF using iText 
28  * -------------------------------------------------------------------------------------------
29  *
30  *
31  * Changes
32  * -------
33  * 14-Jul-2009 : Version 8.4 (Sundar); <UL> 
34  *                                     <LI> Dashboard reports can be downloaded with each report occupying separate page including its charts. </LI>
35  *                                     </UL>   
36  *
37  */
38 package org.openecomp.portalsdk.analytics.model.pdf;
39
40 import java.awt.Color;
41 import java.io.File;
42 import java.io.FileNotFoundException;
43 import java.io.IOException;
44 import java.io.OutputStream;
45 import java.io.StringReader;
46 import java.net.MalformedURLException;
47 import java.sql.Connection;
48 import java.sql.ResultSet;
49 import java.sql.ResultSetMetaData;
50 import java.sql.SQLException;
51 import java.sql.Statement;
52 import java.text.SimpleDateFormat;
53 import java.util.ArrayList;
54 import java.util.Calendar;
55 import java.util.Date;
56 import java.util.HashMap;
57 import java.util.Iterator;
58 import java.util.List;
59 import java.util.Map;
60 import java.util.Map.Entry;
61 import java.util.Set;
62 import java.util.TimeZone;
63 import java.util.TreeMap;
64 import java.util.Vector;
65
66 import javax.servlet.http.HttpServletRequest;
67 import javax.servlet.http.HttpServletResponse;
68 import javax.servlet.http.HttpSession;
69
70 import org.openecomp.portalsdk.analytics.error.RaptorException;
71 import org.openecomp.portalsdk.analytics.error.ReportSQLException;
72 import org.openecomp.portalsdk.analytics.model.ReportHandler;
73 import org.openecomp.portalsdk.analytics.model.ReportLoader;
74 import org.openecomp.portalsdk.analytics.model.base.IdNameValue;
75 import org.openecomp.portalsdk.analytics.model.definition.ReportDefinition;
76 import org.openecomp.portalsdk.analytics.model.runtime.ReportRuntime;
77 import org.openecomp.portalsdk.analytics.system.AppUtils;
78 import org.openecomp.portalsdk.analytics.system.ConnectionUtils;
79 import org.openecomp.portalsdk.analytics.system.Globals;
80 import org.openecomp.portalsdk.analytics.util.AppConstants;
81 import org.openecomp.portalsdk.analytics.util.DataSet;
82 import org.openecomp.portalsdk.analytics.util.HtmlStripper;
83 import org.openecomp.portalsdk.analytics.util.Utils;
84 import org.openecomp.portalsdk.analytics.view.ColumnHeader;
85 import org.openecomp.portalsdk.analytics.view.ColumnHeaderRow;
86 import org.openecomp.portalsdk.analytics.view.DataRow;
87 import org.openecomp.portalsdk.analytics.view.DataValue;
88 import org.openecomp.portalsdk.analytics.view.HtmlFormatter;
89 import org.openecomp.portalsdk.analytics.view.ReportData;
90 import org.openecomp.portalsdk.analytics.view.RowHeader;
91 import org.openecomp.portalsdk.analytics.view.RowHeaderCol;
92 import org.openecomp.portalsdk.analytics.xmlobj.DataColumnType;
93 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
94
95 import com.lowagie.text.BadElementException;
96 import com.lowagie.text.Chunk;
97 import com.lowagie.text.Document;
98 import com.lowagie.text.DocumentException;
99 import com.lowagie.text.Element;
100 import com.lowagie.text.ElementTags;
101 import com.lowagie.text.Font;
102 import com.lowagie.text.FontFactory;
103 import com.lowagie.text.Image;
104 import com.lowagie.text.PageSize;
105 import com.lowagie.text.Paragraph;
106 import com.lowagie.text.Phrase;
107 import com.lowagie.text.Rectangle;
108 import com.lowagie.text.html.simpleparser.HTMLWorker;
109 import com.lowagie.text.html.simpleparser.StyleSheet;
110 import com.lowagie.text.pdf.PdfPCell;
111 import com.lowagie.text.pdf.PdfPTable;
112 import com.lowagie.text.pdf.PdfWriter;
113
114 /**
115  * @author mwliu and sundar
116  *
117  */
118 public class PdfReportHandler extends org.openecomp.portalsdk.analytics.RaptorObject{
119
120         /**
121          * 
122          */
123         private PdfBean pb;
124         private HtmlStripper strip = new HtmlStripper();
125         private static final int RetryCreateNewImage = 3;
126         private int retryCreateNewImageCount=0;
127         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PdfReportHandler.class);
128
129         private String FONT_FAMILY = "Arial";
130         private int FONT_SIZE = 9;
131         
132         public PdfReportHandler() {     }
133
134         public void createPdfFileContent(HttpServletRequest request, HttpServletResponse response, int type) throws IOException, RaptorException {
135
136                 Document document = new Document();
137                 ReportHandler rh = new ReportHandler();
138         String formattedDate = new SimpleDateFormat("MMddyyyyHHmm").format(new Date());
139                 String pdfFName = "";
140                 String user_id = AppUtils.getUserID(request);
141                 response.reset();
142                 response.setContentType("application/pdf");
143                 OutputStream outStream = response.getOutputStream();
144         
145         String formattedReportName = "";
146         PdfWriter writer = null;
147         ReportRuntime firstReportRuntimeObj = null;
148         int returnValue = 0;
149
150         ReportRuntime rr = null;
151         if(rr==null) rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
152         
153         boolean isDashboard = false;
154         if ((request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)!=null) && ( ((String) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID)).equals(rr.getReportID())) ) {
155                 isDashboard = true;
156         }
157                 if(isDashboard) {
158                         try {
159                                         String reportID = (String) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REP_ID);
160                                         ReportRuntime rrDash = rh.loadReportRuntime(request, reportID, true, 1);
161                                         pb = preparePdfBean(request,rrDash);
162                 
163                                         // Setting pb Values
164                                 document.setPageSize(PageSize.getRectangle(pb.getPagesize()));
165                                         if(!pb.isPortrait()) // get this from properties file
166                                                 document.setPageSize(document.getPageSize().rotate());
167                                 
168                                 //                      
169                                         writer = PdfWriter.getInstance(document, response.getOutputStream());
170                                         writer.setPageEvent(new PageEvent(pb));//header,footer,bookmark
171                                         document.open();
172
173                                         formattedReportName = new HtmlStripper().stripSpecialCharacters(rrDash.getReportName());
174                                 if(pb.isAttachmentOfEmail())
175                                         response.setHeader("Content-disposition", "inline");
176                                 else
177                                         response.setHeader("Content-disposition", "attachment;filename="+ formattedReportName+formattedDate+user_id+".pdf");
178                                         
179                                         pdfFName = "dashboard"+formattedReportName+formattedDate+user_id+".pdf";
180                                         Map reportRuntimeMap = null;
181                                         Map reportDataMap = null;
182                                         Map reportDisplayTypeMap = null;
183
184                                         reportRuntimeMap                        = (TreeMap) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTRUNTIME_MAP);
185                                         reportDataMap                           = (TreeMap) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_REPORTDATA_MAP);
186                                         reportDisplayTypeMap            = (TreeMap) request.getSession().getAttribute(AppConstants.SI_DASHBOARD_DISPLAYTYPE_MAP);
187
188                                         if(reportRuntimeMap!=null) {
189                                                 //ServletOutputStream sos = response.getOutputStream();
190                                                 Set setReportRuntime            = reportRuntimeMap.entrySet();
191                                                 Set setReportDataMap            = reportDataMap.entrySet();
192                                                 Set setReportDisplayTypeMap = reportDisplayTypeMap.entrySet();
193                                                 
194                                                 Iterator iter2 = setReportDataMap.iterator();
195                                                 Iterator iter3 = setReportDisplayTypeMap.iterator();
196                                 int count = 0;
197                                                 for(Iterator iter = setReportRuntime.iterator(); iter.hasNext(); ) {
198                                                         count++;
199                                                         Map.Entry entryData             = (Entry) iter2.next();
200                                                         Map.Entry entry                         = (Entry) iter.next();
201                                                         Map.Entry entryCheckChart       = (Entry) iter3.next();
202                                                         //String rep_id                                 = (String) entry.getKey();
203                                                         ReportRuntime rrDashRep         = (ReportRuntime) entry.getValue();
204                                                         
205                                                         if(count == 1)  { 
206                                                                 firstReportRuntimeObj = (ReportRuntime) entry.getValue();
207                                                                 if(pb.isCoverPageIncluded()) {
208                                                                         document = paintDashboardCoverPage(document, rrDash, firstReportRuntimeObj, request);
209                                                                 }
210                                                         }
211                                                         ReportData rdDashRep            = (ReportData) entryData.getValue();
212                                                 int col = 0;
213                                                 //pb.setDisplayChart(nvl(rr.getChartType()).trim().length()>0 && rr.getDisplayChart());
214                                                         if( ((rrDashRep.getChartType()).trim().length()>0 && rrDashRep.getDisplayChart()) && entryCheckChart.getValue().toString().equals("c")) {
215                                                                 document.newPage();
216                                                                 pb.setTitle(nvl(rrDashRep.getReportTitle()).length()>0?rrDashRep.getReportTitle():rrDashRep.getReportName());
217                                                                 paintPdfImage(request, document,AppUtils.getTempFolderPath()+"cr_"+  pb.getUserId()+"_"+request.getSession().getId()+"_"+rrDashRep.getReportID()+".png", rrDashRep);
218                                                         } else {
219                                                                 document.newPage();
220                                                                 pb.setTitle(nvl(rrDashRep.getReportTitle()).length()>0?rrDashRep.getReportTitle():rrDashRep.getReportName());
221                                                                 paintPdfData(request, document,rdDashRep,rrDashRep, "");
222                                                         }
223                                                 }
224                                         
225                                 }
226                         } catch (DocumentException dex) {dex.printStackTrace();}
227                         catch (RaptorException rex) {rex.printStackTrace();}
228                 } else {
229
230                         //ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
231                         //ReportData    rd = (ReportData)    request.getSession().getAttribute(AppConstants.RI_REPORT_DATA);
232                         rr = null;
233                         ReportData    rd = null;
234                         String parent = "";
235                         int parentFlag = 0;
236                         if(!nvl(request.getParameter("parent"), "").equals("N")) parent = nvl(request.getParameter("parent"), "");
237                         if(parent.startsWith("parent_")) parentFlag = 1;
238                         if(parentFlag == 1) {
239                                 rr = (ReportRuntime) request.getSession().getAttribute(parent+"_rr");
240                                 rd = (ReportData) request.getSession().getAttribute(parent+"_rd");
241                         }
242                         if(rr==null) rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
243                         if(rd==null) rd = (ReportData)    request.getSession().getAttribute(AppConstants.RI_REPORT_DATA);
244                         
245                         pb = preparePdfBean(request,rr);
246                         FONT_FAMILY = rr.getPDFFont();
247                         FONT_SIZE = rr.getPDFFontSize();
248                         //System.out.println(pb);
249                                         
250                         formattedReportName = new HtmlStripper().stripSpecialCharacters(rr.getReportName());
251                         
252                         
253                         
254                 response.setContentType("application/pdf");
255                 if(pb.isAttachmentOfEmail())
256                         response.setHeader("Content-disposition", "inline");
257                 else
258                         response.setHeader("Content-disposition", "attachment;filename="+ formattedReportName+formattedDate+user_id+".pdf");
259                         
260                         document.setPageSize(PageSize.getRectangle(pb.getPagesize()));
261                         
262                         if(!pb.isPortrait()) // get this from properties file
263                                 document.setPageSize(document.getPageSize().rotate());
264         
265                         try {
266                                 
267                                 writer = PdfWriter.getInstance(document, outStream);
268                                 writer.setPageEvent(new PageEvent(pb));//header,footer,bookmark
269                                 document.open();
270                                 
271                                 //System.out.println("Document 1 " + document);
272                                 if(pb.isCoverPageIncluded()) {
273                                         document = paintCoverPage(document, rr, request);
274                                 }
275                                 
276                                 //boolean isImageRotate = false;
277                                 //System.out.println("Document 2 " + document);
278         
279                                 if(pb.isDisplayChart()) {
280                                         paintPdfImage(request, document,AppUtils.getTempFolderPath()+"cr_"+  pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+".png", rr);
281                                 }
282                                 //System.out.println("Document 4" + document);
283         
284                                 document.newPage();
285                         if(type == 3 && rr.getSemaphoreList()==null && !(rr.getReportType().equals(AppConstants.RT_CROSSTAB)) ) { //type = 3 is whole
286                                 String sql_whole = (String) request.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE);
287                                 returnValue = paintPdfData(request, document, rd, rr, sql_whole);
288                         } else if(type == 2) {
289                                 returnValue = paintPdfData(request, document, rd, rr, "");
290                         } else {
291                                 //String sql_whole = (String) request.getAttribute(AppConstants.RI_REPORT_SQL_WHOLE);
292                                         int downloadLimit = (rr.getMaxRowsInExcelDownload()>0)?rr.getMaxRowsInExcelDownload():Globals.getDownloadLimit();
293                                         String action = request.getParameter(AppConstants.RI_ACTION);
294
295                                         if(!(rr.getReportType().equals(AppConstants.RT_CROSSTAB)) && !action.endsWith("session"))
296                                                 rd              = rr.loadReportData(-1, AppUtils.getUserID(request), downloadLimit,request, false /*download*/);
297                                         if(rr.getSemaphoreList()!=null) {
298                                                 rd   =  rr.loadReportData(-1, AppUtils.getUserID(request), downloadLimit,request, true);
299                                                 returnValue = paintPdfData(request, document, rd, rr, "");
300                                         } else {
301                                                 returnValue = paintPdfData(request, document, rd, rr, rr.getWholeSQL());
302                                         }
303                                         
304                                         
305                         }
306                         
307                                 
308                                 //paintPdfData(document,rd,rr);
309                         
310                         
311                         } catch (DocumentException de) {
312                     de.printStackTrace();
313                     //System.err.println("document: " + de.getMessage());
314                 }
315                         
316                 }
317                 document.close();
318         int mb = 1024*1024;
319         Runtime runtime = Runtime.getRuntime();         
320         logger.debug(EELFLoggerDelegate.debugLogger, ("##### Heap utilization statistics [MB] #####"));
321         logger.debug(EELFLoggerDelegate.debugLogger, ("Used Memory:"
322                         + (runtime.maxMemory() - runtime.freeMemory()) / mb));
323         logger.debug(EELFLoggerDelegate.debugLogger, ("Free Memory:"
324                         + runtime.freeMemory() / mb));
325         logger.debug(EELFLoggerDelegate.debugLogger, ("Total Memory:" + runtime.totalMemory() / mb));
326         logger.debug(EELFLoggerDelegate.debugLogger, ("Max Memory:" + runtime.maxMemory() / mb));
327
328         }
329         
330         private Document paintCoverPage(Document doc, ReportRuntime rr, HttpServletRequest request) throws IOException, DocumentException {
331                 
332                 //System.out.println("PDFREPORTHANDLER STARTED ... " );
333                 if(nvl(rr.getPdfImg()).length()>0) {
334                         Image image1 = Image.getInstance(AppUtils.getExcelTemplatePath()+"../../"+AppUtils.getImgFolderURL()+rr.getPdfImg());
335                         image1.scalePercent(20f, 20f);
336                         doc.add(image1);
337                 }
338                 float firstColumnSize = Globals.getCoverPageFirstColumnSize();
339                 float[] relativeWidths = {firstColumnSize,1f-firstColumnSize};
340                 PdfPTable table = new PdfPTable(relativeWidths);
341                 table.getDefaultCell().setBorderWidth(0);
342                 addEmptyRows(table,6);
343                 HTMLWorker worker = new HTMLWorker(doc);
344         StyleSheet style = new StyleSheet();
345         style.loadTagStyle("body", "leading", "16,0");
346         StringBuffer reportDescrBuf = new StringBuffer("");
347         ArrayList descr = HTMLWorker.parseToList(new StringReader(nvl(rr.getReportDescr())), style);
348         ArrayList paraList = null;
349            if(nvl(rr.getReportTitle()).length()>0) {
350                         add2Cells(table,"Report Title   : ",nvl(rr.getReportTitle()));
351                         if(nvl(rr.getReportSubTitle()).length()>0) {
352                                 add2Cells(table,"Report Sub-Title       : ",nvl(rr.getReportSubTitle()));
353                                 System.out.println("Adding the report sub-title ");
354                         }
355                         
356            } else {
357                         add2Cells(table,"Report Name    : ",nvl(rr.getReportName()));
358            }
359                         if((descr!=null && descr.size()>0)) {
360                                 paraList = (com.lowagie.text.Paragraph)descr.get(0);
361                                 for (int i=0 ; i<paraList.size(); i++) {
362                                         reportDescrBuf.append(paraList.get(i));
363                                 }
364                                 
365                         }
366                         add2Cells(table,"Description    : ",reportDescrBuf.toString());
367                 if(Globals.getSessionInfoForTheCoverPage().length()>0) {
368                         String nameValue[] = Globals.getSessionInfoForTheCoverPage().split(",");
369                                 String name=nameValue[0];
370                                 String value=nameValue[1];
371                                 add2Cells(table,name+" : ",(AppUtils.getRequestNvlValue(request, value).length()>0?AppUtils.getRequestNvlValue(request, value):nvl((String)request.getSession().getAttribute(value))));
372                 }
373                 
374                 if(Globals.isCreatedOwnerInfoNeeded()) {
375                         add2Cells(table,"Created By     : ",nvl(AppUtils.getUserName(rr.getCreateID())));
376                         add2Cells(table,"Owner                  : ",nvl(AppUtils.getUserName(rr.getOwnerID())));
377                 }
378                 if(Globals.displayLoginIdForDownloadedBy())
379                         add2Cells(table,"Downloaded by  : ",nvl(AppUtils.getUserBackdoorLoginId(request)));
380                 else
381                         add2Cells(table,"Downloaded by  : ",nvl(AppUtils.getUserName(AppUtils.getUserID(request))));
382                 
383                 addEmptyRows(table,1);
384
385                 boolean isFirstRow = true;
386         ArrayList al = rr.getParamNameValuePairsforPDFExcel(request, 1);
387         if(al.size()<=0) {
388                 al = (ArrayList) request.getSession().getAttribute(AppConstants.SI_FORMFIELD_DOWNLOAD_INFO);
389         }
390
391                 Iterator it = al.iterator();
392                 addEmptyRows(table,1);
393                 //if(!Globals.customizeFormFieldInfo()) {
394                 if(rr.getFormFieldComments(request).length()<=0) {
395                         while(it.hasNext()) {
396                 
397                                 if(isFirstRow) {
398                         add2Cells(table, "Run-time Criteria : ", " ");
399                                         isFirstRow = false;
400                                 }
401                                         
402                                 IdNameValue value = (IdNameValue)it.next();
403                                 if(!value.getId().trim().equals("BLANK"))
404                                         //System.out.println("PDFREPORTHANDLER " + value.getId()+" : "+value.getName());
405                                         add2Cells(table, value.getId()+" : ",value.getName().replaceAll("~",","));
406                                         //add2Cells(table, rr.getFormFieldComments(request), " ");
407                         }
408                         addEmptyRows(table,1);
409                         doc.add(table);
410                         
411                 } else {
412                 it = al.iterator();
413                 if(it.hasNext()) {
414                         //add2Cells(table, "Run-time Criteria : ", " ");
415                         addEmptyRows(table,1);                  
416                         doc.add(table);
417                         //com.lowagie.text.html.HtmlParser.parse(doc, new StringReader(rr.getFormFieldComments(request)));
418                         ArrayList p = HTMLWorker.parseToList(new StringReader(rr.getFormFieldComments(request).replaceAll("~",",")), style);
419                         
420                          for (int k = 0; k < p.size(); ++k){
421                             doc.add((com.lowagie.text.Element)p.get(k));
422                          }
423                 }
424                 } 
425                 
426                 return doc;             
427         }
428         
429
430         private Document paintDashboardCoverPage(Document doc, ReportRuntime rrDashRep, ReportRuntime firstReportRuntimeObj, HttpServletRequest request) throws IOException, DocumentException {
431                 
432                 //System.out.println("PDFREPORTHANDLER STARTED ... " );
433                 float firstColumnSize = Globals.getCoverPageFirstColumnSize();
434                 float[] relativeWidths = {firstColumnSize,1f-firstColumnSize};
435                 PdfPTable table = new PdfPTable(relativeWidths);
436                 table.getDefaultCell().setBorderWidth(0);
437                 addEmptyRows(table,6);
438
439                 add2Cells(table,"Report Name : ",rrDashRep.getReportName());
440                 add2Cells(table,"Description : ",rrDashRep.getReportDescr());
441                 if(Globals.getSessionInfoForTheCoverPage().length()>0) {
442                         String nameValue[] = Globals.getSessionInfoForTheCoverPage().split(",");
443                                 String name=nameValue[0];
444                                 String value=nameValue[1];
445                                 add2Cells(table,name+" : ",(AppUtils.getRequestNvlValue(request, value).length()>0?AppUtils.getRequestNvlValue(request, value):nvl((String)request.getSession().getAttribute(value))));
446                 }
447                 
448                 if(Globals.isCreatedOwnerInfoNeeded()) {
449                         add2Cells(table,"Created By : ",AppUtils.getUserName(rrDashRep.getCreateID()));
450                         add2Cells(table,"Owner : ",AppUtils.getUserName(rrDashRep.getOwnerID()));
451                 }
452                 if(Globals.displayLoginIdForDownloadedBy())
453                         add2Cells(table,"Downloaded by : ",AppUtils.getUserBackdoorLoginId(request));
454                 else
455                         add2Cells(table,"Downloaded by : ",AppUtils.getUserName(request));
456                 
457                 addEmptyRows(table,1);
458
459                 boolean isFirstRow = true;
460                 ArrayList al = firstReportRuntimeObj.getParamNameValuePairsforPDFExcel(request, 2);
461                 Iterator it = al.iterator();
462                 addEmptyRows(table,1);
463                 //if(!Globals.customizeFormFieldInfo()) {
464                 if(firstReportRuntimeObj.getFormFieldComments(request).length()<=0) {
465                         while(it.hasNext()) {
466                 
467                                 if(isFirstRow) {
468                                         add2Cells(table, "Run-time Criteria : ", " ");
469                                         isFirstRow = false;
470                                 }
471                                         
472                                 IdNameValue value = (IdNameValue)it.next();
473                                 if(!value.getId().trim().equals("BLANK"))
474                                         //System.out.println("PDFREPORTHANDLER " + value.getId()+" : "+value.getName());
475                                         add2Cells(table, value.getId()+" : ",value.getName());
476                                         //add2Cells(table, rr.getFormFieldComments(request), " ");
477                         }
478                         addEmptyRows(table,1);
479                         doc.add(table);
480                         
481                 } else {
482                 it = al.iterator();
483                 if(it.hasNext()) {
484                         //add2Cells(table, "Run-time Criteria : ", " ");
485                         addEmptyRows(table,1);                  
486                         doc.add(table);
487                         //com.lowagie.text.html.HtmlParser.parse(doc, new StringReader(rr.getFormFieldComments(request)));
488                         HTMLWorker worker = new HTMLWorker(doc);
489                         StyleSheet style = new StyleSheet();
490                         style.loadTagStyle("body", "leading", "16,0");
491                         ArrayList p = HTMLWorker.parseToList(new StringReader(firstReportRuntimeObj.getFormFieldComments(request)), style);
492                         
493                          for (int k = 0; k < p.size(); ++k){
494                             doc.add((com.lowagie.text.Element)p.get(k));
495                          }
496                 }
497                 } 
498                 
499                 return doc;             
500         }
501         
502         
503         public static void addEmptyRows(PdfPTable table, int rows) throws DocumentException {
504                 for (int i=0; i<rows; i++) 
505                         for(int j=0;j<table.getAbsoluteWidths().length;j++)
506                                 table.addCell(new Paragraph(" "));
507                 
508         }
509         
510         private void add2Cells(PdfPTable table, String key, String value) {
511                 
512                 PdfPCell cell;
513                 cell = new PdfPCell(new Paragraph(key));
514                 cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT);
515                 cell.setBorderWidth(0f);
516                 table.addCell(cell);
517                 
518                 cell = new PdfPCell(new Paragraph(value));
519                 cell.setHorizontalAlignment(Rectangle.ALIGN_LEFT);
520                 cell.setBorderWidth(0f);
521                 table.addCell(cell);
522         }
523
524         private void paintPdfImage(HttpServletRequest request, Document document, String fileName, ReportRuntime rr) 
525                                 throws DocumentException
526         {
527                 
528                 ArrayList images = getImage(request, fileName,pb.isAttachmentOfEmail()?true:false, rr);
529                 //Image image = getImage(request, fileName,pb.isAttachmentOfEmail()?true:false);
530                 PdfPTable table =  null;
531                 PdfPCell cellValue = null;
532                 if(images!=null) {
533                         
534                 for (int i = 0; i < images.size(); i++) {
535                         table = new PdfPTable(1);
536                         cellValue = new PdfPCell();
537                         cellValue.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
538                 Image image = (Image) images.get(i);                            
539                         image.setAlignment(Image.ALIGN_CENTER);
540                         //System.out.println("Document 3 " + document + " i-" + i);
541                         if(i%2 ==0)
542                         document.newPage();
543                         //System.out.println("Document 31 " + document);
544                         cellValue.setImage(image);
545                         //table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
546                         table.addCell(cellValue);
547                         //System.out.println("Document 32 " + document + "table  " + table);
548                         document.add(table);
549                         //System.out.println("Document 33 " + document);                        
550                         }
551                 }
552         }
553         
554         private ArrayList getImage(HttpServletRequest request, String fileName, boolean isGenerateNewImage, ReportRuntime rr) {
555                 ArrayList images = new ArrayList();
556                 if(!isGenerateNewImage) {
557                         try {
558                                 Image image = Image.getInstance(fileName);
559                                 images.add(image);
560                                 return images;
561                         } 
562                         catch (MalformedURLException e) {
563                                 isGenerateNewImage = true;
564                                 //e.printStackTrace();                  
565                         } 
566                         catch (BadElementException e) {
567                                 isGenerateNewImage = true;
568                                 //e.printStackTrace();
569
570                         } catch (FileNotFoundException e) {
571                                 isGenerateNewImage = true;
572                                 //e.printStackTrace();
573                         } catch (IOException e) {
574                                 isGenerateNewImage = true;
575                                 //e.printStackTrace();
576                     }                   
577                 }
578                 
579                 if(isGenerateNewImage && retryCreateNewImageCount<RetryCreateNewImage){
580                         retryCreateNewImageCount++;
581                         return generateNewImage(request, rr);
582                         //return getImage(request,fileName, false);
583                 }
584                 
585                 return null;
586                         
587         }
588
589         private ArrayList generateNewImage(HttpServletRequest request, ReportRuntime rr) {
590                 ArrayList images = new ArrayList();
591                 try {
592                         //ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
593                         DataSet ds = null;
594                         if(request.getSession().getAttribute(AppConstants.RI_CHART_DATA)!=null) {
595                                 ds = (DataSet) request.getSession().getAttribute(AppConstants.RI_CHART_DATA);
596                         } else {
597                                 ds = rr.loadChartData(pb.getUserId(),request);
598                         }
599                     String downloadFileName = "";
600                         HashMap additionalChartOptionsMap = new HashMap();
601                         String chartType = nvl(rr.getChartType());
602                         if(chartType.equals(AppConstants.GT_PIE_MULTIPLE)) {
603                                 additionalChartOptionsMap.put("multiplePieOrderRow", new Boolean((AppUtils.getRequestNvlValue(request, "multiplePieOrder").length()>0?AppUtils.getRequestNvlValue(request, "multiplePieOrder").equals("row"):rr.isMultiplePieOrderByRow())) );
604                                 additionalChartOptionsMap.put("multiplePieLabelDisplay", AppUtils.getRequestNvlValue(request, "multiplePieLabelDisplay").length()>0? AppUtils.getRequestNvlValue(request, "multiplePieLabelDisplay"):rr.getMultiplePieLabelDisplay());
605                                 additionalChartOptionsMap.put("chartDisplay", new Boolean(AppUtils.getRequestNvlValue(request, "chartDisplay").length()>0? AppUtils.getRequestNvlValue(request, "chartDisplay").equals("3D"):rr.isChartDisplayIn3D()));
606                         } else if (chartType.equals(AppConstants.GT_BAR_3D)) {
607                                 additionalChartOptionsMap.put("chartOrientation", new Boolean((AppUtils.getRequestNvlValue(request, "chartOrientation").length()>0?AppUtils.getRequestNvlValue(request, "chartOrientation").equals("vertical"):rr.isVerticalOrientation())) );
608                                 additionalChartOptionsMap.put("secondaryChartRenderer", AppUtils.getRequestNvlValue(request, "secondaryChartRenderer").length()>0? AppUtils.getRequestNvlValue(request, "secondaryChartRenderer"):rr.getSecondaryChartRenderer());
609                                 additionalChartOptionsMap.put("chartDisplay", new Boolean(AppUtils.getRequestNvlValue(request, "chartDisplay").length()>0? AppUtils.getRequestNvlValue(request, "chartDisplay").equals("3D"):rr.isChartDisplayIn3D()));
610                                 additionalChartOptionsMap.put("lastSeriesALineChart", new Boolean(rr.isLastSeriesALineChart()));                
611                         } else if (chartType.equals(AppConstants.GT_LINE)) {
612                                 additionalChartOptionsMap.put("chartOrientation", new Boolean((AppUtils.getRequestNvlValue(request, "chartOrientation").length()>0?AppUtils.getRequestNvlValue(request, "chartOrientation").equals("vertical"):rr.isVerticalOrientation())) );
613                                 //additionalChartOptionsMap.put("secondaryChartRenderer", AppUtils.getRequestNvlValue(request, "secondaryChartRenderer").length()>0? AppUtils.getRequestNvlValue(request, "secondaryChartRenderer"):rr.getSecondaryChartRenderer());
614                                 additionalChartOptionsMap.put("chartDisplay", new Boolean(AppUtils.getRequestNvlValue(request, "chartDisplay").length()>0? AppUtils.getRequestNvlValue(request, "chartDisplay").equals("3D"):rr.isChartDisplayIn3D()));
615                                 additionalChartOptionsMap.put("lastSeriesABarChart", new Boolean(rr.isLastSeriesABarChart()));
616                         } else if (chartType.equals(AppConstants.GT_TIME_DIFFERENCE_CHART)) {
617                                 additionalChartOptionsMap.put("intervalFromDate",AppUtils.getRequestNvlValue(request, "intervalFromDate").length()>0?AppUtils.getRequestNvlValue(request, "intervalFromDate"):rr.getIntervalFromdate());
618                                 additionalChartOptionsMap.put("intervalToDate", AppUtils.getRequestNvlValue(request, "intervalToDate").length()>0? AppUtils.getRequestNvlValue(request, "intervalToDate"):rr.getIntervalTodate());
619                                 additionalChartOptionsMap.put("intervalLabel", AppUtils.getRequestNvlValue(request, "intervalLabel").length()>0? AppUtils.getRequestNvlValue(request, "intervalLabel"):rr.getIntervalLabel());
620                         } else if (chartType.equals(AppConstants.GT_REGRESSION)) {
621                                 additionalChartOptionsMap.put("regressionType",AppUtils.getRequestNvlValue(request, "regressionType").length()>0?AppUtils.getRequestNvlValue(request, "regressionType"):rr.getLinearRegression());
622                                 additionalChartOptionsMap.put("linearRegressionColor",nvl(rr.getLinearRegressionColor()));
623                                 additionalChartOptionsMap.put("expRegressionColor",nvl(rr.getExponentialRegressionColor()));
624                                 additionalChartOptionsMap.put("maxRegression",nvl(rr.getCustomizedRegressionPoint()));
625                         } else if (chartType.equals(AppConstants.GT_STACK_BAR) ||chartType.equals(AppConstants.GT_STACKED_HORIZ_BAR) || chartType.equals(AppConstants.GT_STACKED_HORIZ_BAR_LINES)
626                            || chartType.equals(AppConstants.GT_STACKED_VERT_BAR) || chartType.equals(AppConstants.GT_STACKED_VERT_BAR_LINES)    
627                         ) {
628                                 additionalChartOptionsMap.put("overlayItemValue",new Boolean(nvl(rr.getOverlayItemValueOnStackBar()).equals("Y")));
629                         }
630                         additionalChartOptionsMap.put("legendPosition", nvl(rr.getLegendPosition()));
631                         additionalChartOptionsMap.put("hideToolTips", new Boolean(rr.hideChartToolTips()));
632                         additionalChartOptionsMap.put("hideLegend", new Boolean(AppUtils.getRequestNvlValue(request, "hideLegend").length()>0? AppUtils.getRequestNvlValue(request, "hideLegend").equals("Y"):rr.hideChartLegend()));
633                         additionalChartOptionsMap.put("labelAngle", nvl(rr.getLegendLabelAngle()));
634                         additionalChartOptionsMap.put("maxLabelsInDomainAxis", nvl(rr.getMaxLabelsInDomainAxis()));
635                         additionalChartOptionsMap.put("rangeAxisLowerLimit", nvl(rr.getRangeAxisLowerLimit()));
636                         additionalChartOptionsMap.put("rangeAxisUpperLimit", nvl(rr.getRangeAxisUpperLimit()));
637                         
638                     
639                         boolean totalOnChart = false;
640                         totalOnChart = AppUtils.getRequestNvlValue(request, "totalOnChart").equals("Y");
641                         String filename  = null;
642                         ArrayList graphURL  = new ArrayList();
643                         ArrayList chartNames = new ArrayList();
644                         ArrayList fileNames = new ArrayList(); 
645                     List l = rr.getAllColumns();
646                     List lGroups = rr.getAllChartGroups();
647                     HashMap mapYAxis = rr.getAllChartYAxis(rr.getReportParamValues());
648                     String chartLeftAxisLabel = rr.getFormFieldFilled(nvl(rr.getChartLeftAxisLabel()));
649                 String chartRightAxisLabel = rr.getFormFieldFilled(nvl(rr.getChartRightAxisLabel()));
650                     int displayTotalOnChart = 0;
651                     HashMap formValues = Globals.getRequestParamtersMap(request, false);
652
653                     for (Iterator iterC = l.iterator(); iterC.hasNext();) {
654                                 DataColumnType dc = (DataColumnType) iterC.next();
655                                 if(nvl(dc.getColName()).equals(AppConstants.RI_CHART_TOTAL_COL)) {
656                                         displayTotalOnChart = 1;
657                                 }
658                         }
659                     
660                     String legendColumnName = (rr.getChartLegendColumn()!=null)?rr.getChartLegendColumn().getDisplayName():"Legend Column";
661                     
662                     
663                     
664                         if(ds!=null)
665                         {
666                                    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**/
667                                 for (int i=0; i<rr.getChartValueColumnAxisList(AppConstants.CHART_ALL_COLUMNS, formValues).size();i++) {
668                                 String chartTitle = Globals.getDisplayChartTitle()? rr.getReportName():"";
669                                 chartTitle = rr.getFormFieldFilled(chartTitle);
670                                                 downloadFileName = AppUtils.getTempFolderPath()+"cr_"+pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_"+i+".png";
671                                                 filename = null;/*(String) ChartGen.generateChart(  chartType,
672                                                                                                         request.getSession(),
673                                                                                                         ds,
674                                                                                                         legendColumnName, 
675                                                                                                         chartLeftAxisLabel,
676                                                                                                         chartRightAxisLabel,
677                                                                                                         rr.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues).subList(i, i+1), 
678                                                                                                         rr.getChartColumnColorsList(AppConstants.CHART_ALL_COLUMNS, formValues).subList(i, i+1), 
679                                                                                                         rr.getChartValueColumnAxisList(AppConstants.CHART_ALL_COLUMNS, formValues).subList(i, i+1), 
680                                                                                                         "",
681                                                                                                         chartTitle,
682                                                                                                         null,
683                                                                                                         rr.getChartWidthAsInt(),
684                                                                                                         rr.getChartHeightAsInt(),
685                                                                                     rr.getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, formValues).subList(i,i+1),
686                                                                                     rr.hasSeriesColumn(),
687                                                                                     //rr.isChartMultiSeries(),
688                                                                                     rr.isMultiSeries(),
689                                                                                     rr.getAllColumns(),
690                                                                         downloadFileName,
691                                                                         totalOnChart, 
692                                                                         AppConstants.WEB_VERSION deviceType,
693                                                                         additionalChartOptionsMap,
694                                                                         true
695                                                         );*/
696                                                         try {
697                                                                 Image image = Image.getInstance(downloadFileName);
698                                                 images.add(image);
699                                                         } catch (MalformedURLException e) {
700                                                                 e.printStackTrace();                    
701                                                         } 
702                                                         catch (BadElementException e) {
703                                                                 e.printStackTrace();
704
705                                                         } catch (FileNotFoundException e) {
706                                                                 e.printStackTrace();
707                                                         } catch (IOException e) {
708                                                                 e.printStackTrace();
709                                                     }   
710                                 }
711                                            
712                                    } else { /** first check the columns to be opened in new charts and loop around in ChartGen generate chart function  - sundar**/
713                             String tempChartGroupPrev = "";
714                                         String tempChartGroupCurrent = "";
715                                 for (int i=0; i<lGroups.size();i++) {
716                                         String chartGroupOrg = (String) lGroups.get(i);
717                                         String chartYAxis = (String) mapYAxis.get(chartGroupOrg);
718                                         //System.out.println("chartGroupOrg " + chartGroupOrg);
719                                         if(nvl(chartGroupOrg).length()>0)
720                                                 tempChartGroupCurrent = chartGroupOrg.substring(0,chartGroupOrg.lastIndexOf("|"));
721                                         if(i>0) tempChartGroupPrev = ((String) lGroups.get(i-1)).substring(0,((String) lGroups.get(i-1)).lastIndexOf("|"));
722                                         //System.out.println("TEMPCHARTGROUP " + tempChartGroupCurrent + " " + tempChartGroupPrev);
723                                         if(tempChartGroupCurrent.equals(tempChartGroupPrev)) continue;
724                                         //System.out.println("CHARTGROUPORG " + chartGroupOrg + " " + lGroups) ;
725                                         //String chartGroup = chartGroupOrg.substring(0,chartGroupOrg.lastIndexOf("|"));
726                                         String chartGroup = chartGroupOrg;
727                                         
728                                         //System.out.println("$$$$CHARTGROUP in JSP  " +chartGroup+ " "+ chartGroupOrg );
729                                                            //System.out.println(" rr.getChartGroupDisplayNamesList(chartGroup) " + rr.getChartGroupDisplayNamesList(chartGroup));
730                                                            //System.out.println(" rr.getChartGroupColumnColorsList(chartGroup) " + rr.getChartGroupColumnColorsList(chartGroup));
731                                                            //System.out.println(" rr.getChartGroupColumnAxisList(chartGroup) " + rr.getChartGroupColumnAxisList(chartGroup));
732                                                            //System.out.println(" rr.getChartGroupValueColumnAxisList(chartGroupOrg) " + rr.getChartGroupValueColumnAxisList(chartGroupOrg));
733                                         
734                                                         downloadFileName = AppUtils.getTempFolderPath()+"cr_"+pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_"+i+".png";
735                                                         String chartTitle = (Globals.getDisplayChartTitle()? (chartGroup!=null && chartGroup.indexOf("|") > 0 ?chartGroup.substring(0,chartGroup.lastIndexOf("|")):rr.getReportName()):"");
736                                                         chartTitle = rr.getFormFieldFilled(chartTitle);
737                                                         String leftAxisLabel = "";
738                                                         //if(!rr.isChartMultiSeries()) {
739                                                           if(!rr.isMultiSeries()) {
740                                                                 leftAxisLabel = ((chartYAxis!=null && chartYAxis.indexOf("|") > 0) ? chartYAxis.substring(0,chartYAxis.lastIndexOf("|")): chartLeftAxisLabel );
741                                                         } else {
742                                                                 leftAxisLabel = chartLeftAxisLabel;
743                                                         }
744
745                                                 filename = null;/*(String) ChartGen.generateChart(  chartType,
746                                                                                                                                 request.getSession(),
747                                                                                                                                 ds,
748                                                                                                                                 legendColumnName,  
749                                                                                                                                 leftAxisLabel,
750                                                                                                                                 chartRightAxisLabel,
751                                                                                                                                 ((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)), 
752                                                                                                                                 ((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)), 
753                                                                                                                                 ((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)), 
754                                                                                                                                 "",
755                                                                                                                                 chartTitle,
756                                                                                                                                 null,
757                                                                                                                                 rr.getChartWidthAsInt(),
758                                                                                                                                 rr.getChartHeightAsInt(),
759                                                                                                                                 ((chartType.indexOf("Stacked")>0 || chartType.equals(AppConstants.GT_PIE_MULTIPLE))?rr.getChartValueColumnsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues):rr.getChartGroupValueColumnAxisList(chartGroupOrg, formValues)),
760                                                                                                             rr.hasSeriesColumn(),
761                                                                                                             //rr.isChartMultiSeries(),
762                                                                                                             rr.isMultiSeries(),
763                                                                                                             rr.getAllColumns(),
764                                                                                                 downloadFileName,
765                                                                                                 totalOnChart, 
766                                                                                                 AppConstants.WEB_VERSION deviceType, 
767                                                                                                 additionalChartOptionsMap,
768                                                                                                 true
769                                                                   );*/
770                                                         try {
771                                                                 Image image = Image.getInstance(downloadFileName);
772                                                 images.add(image);
773                                                         } catch (MalformedURLException e) {
774                                                                 e.printStackTrace();                    
775                                                         } 
776                                                         catch (BadElementException e) {
777                                                                 e.printStackTrace();
778
779                                                         } catch (FileNotFoundException e) {
780                                                                 e.printStackTrace();
781                                                         } catch (IOException e) {
782                                                                 e.printStackTrace();
783                                                     }   
784                                                 }
785                                            
786                             if(!chartType.equals(AppConstants.GT_PIE_MULTIPLE)) {    
787                         for (int i=0; i<rr.getChartValueColumnAxisList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).size();i++) { 
788                                            //System.out.println(" rr.getChartDisplayNamesList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i, i+1) " + rr.getChartDisplayNamesList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i, i+1));
789                                            //System.out.println(" rr.getChartValueColumnAxisList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i, i+1) " + rr.getChartValueColumnAxisList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i, i+1));
790                                            //System.out.println(" rr.getChartValueColumnsList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i,i+1) " + rr.getChartValueColumnsList(AppConstants.CHART_NEWCHART_COLUMNS).subList(i,i+1));
791
792                                                 downloadFileName = AppUtils.getTempFolderPath()+"cr_"+ pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_"+i+".png";
793                                 String chartTitle = Globals.getDisplayChartTitle()? rr.getReportName():"";
794                                 chartTitle = rr.getFormFieldFilled(chartTitle);
795
796                         filename = null; /*(String) ChartGen.generateChart(  chartType,
797                                                                                                         request.getSession(),
798                                                                                                         ds,
799                                                                                                         legendColumnName, 
800                                                                                                         chartLeftAxisLabel,
801                                                                                                         chartRightAxisLabel,
802                                                                                                         (chartType.equals(AppConstants.GT_PIE_MULTIPLE))?rr.getChartDisplayNamesList(AppConstants.CHART_ALL_COLUMNS, formValues):rr.getChartDisplayNamesList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).subList(i, i+1), 
803                                                                                                         (chartType.equals(AppConstants.GT_PIE_MULTIPLE))?rr.getChartColumnColorsList(AppConstants.CHART_ALL_COLUMNS, formValues):rr.getChartColumnColorsList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).subList(i, i+1), 
804                                                                                                         (chartType.equals(AppConstants.GT_PIE_MULTIPLE))?rr.getChartValueColumnAxisList(AppConstants.CHART_ALL_COLUMNS, formValues):rr.getChartValueColumnAxisList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).subList(i, i+1), 
805                                                                                                         "",
806                                                                                                         chartTitle,
807                                                                                                         null,
808                                                                                                         rr.getChartWidthAsInt(),
809                                                                                                         rr.getChartHeightAsInt(),
810                                                                         rr.getChartValueColumnsList(AppConstants.CHART_NEWCHART_COLUMNS, formValues).subList(i,i+1),
811                                                                                     rr.hasSeriesColumn(),
812                                                                                     //rr.isChartMultiSeries(),
813                                                                                     rr.isMultiSeries(),
814                                                                                     rr.getAllColumns(),
815                                                                         downloadFileName,
816                                                                         totalOnChart, 
817                                                                         AppConstants.WEB_VERSION, 
818                                                                         additionalChartOptionsMap,
819                                                                         true
820                                           );*/
821                                                         try {
822                                                                 Image image = Image.getInstance(downloadFileName);
823                                                 images.add(image);
824                                                         } catch (MalformedURLException e) {
825                                                                 e.printStackTrace();                    
826                                                         } 
827                                                         catch (BadElementException e) {
828                                                                 e.printStackTrace();
829
830                                                         } catch (FileNotFoundException e) {
831                                                                 e.printStackTrace();
832                                                         } catch (IOException e) {
833                                                                 e.printStackTrace();
834                                                     }   
835                                                 }
836                             }
837                         /** second rest of the columns are merged to one single chart  - sundar**/
838                                           // System.out.println(" rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS) " + rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS));
839                                           // System.out.println(" rr.getChartValueColumnAxisList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS) " + rr.getChartValueColumnAxisList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS));
840                                           // System.out.println(" rr.getChartValueColumnsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS) " + rr.getChartValueColumnsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS));
841
842                                           if((!(lGroups!=null && lGroups.size() > 0))) {
843                                                   
844                                            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) {
845                         downloadFileName = AppUtils.getTempFolderPath()+"cr_"+  pb.getUserId()+"_"+request.getSession().getId()+"_"+rr.getReportID()+"_All.png";
846                         String chartTitle = Globals.getDisplayChartTitle()? rr.getReportName():"";
847                         chartTitle = rr.getFormFieldFilled(chartTitle);
848
849                         filename = null; /*(String) ChartGen.generateChart(  chartType,
850                                                                                                         request.getSession(),
851                                                                                                         ds,
852                                                                                                         legendColumnName, 
853                                                                                                         chartLeftAxisLabel,
854                                                                                                         chartRightAxisLabel,
855                                                                                                         rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues), 
856                                                                                                         rr.getChartColumnColorsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues), 
857                                                                                                         rr.getChartValueColumnAxisList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues), 
858                                                                                                         "",
859                                                                                                         chartTitle,
860                                                                                                         null,
861                                                                                                         rr.getChartWidthAsInt(),
862                                                                                                         rr.getChartHeightAsInt(),
863                                                                         rr.getChartValueColumnsList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS, formValues),
864                                                                                     rr.hasSeriesColumn(),
865                                                                                   //rr.isChartMultiSeries(),
866                                                                                     rr.isMultiSeries(),
867                                                                                     rr.getAllColumns(),
868                                                                         downloadFileName,
869                                                                         totalOnChart, 
870                                                                         AppConstants.WEB_VERSION, 
871                                                                         additionalChartOptionsMap,
872                                                                         true
873                                           );*/
874                                                         try {
875                                                                 Image image = Image.getInstance(downloadFileName);
876                                                 images.add(image);
877                                                         } catch (MalformedURLException e) {
878                                                                 e.printStackTrace();                    
879                                                         } 
880                                                         catch (BadElementException e) {
881                                                                 e.printStackTrace();
882
883                                                         } catch (FileNotFoundException e) {
884                                                                 e.printStackTrace();
885                                                         } catch (IOException e) {
886                                                                 e.printStackTrace();
887                                                     }                                     
888                                      }
889                                           } // Stacked Chart Check   
890                                    } // else no Series Column
891
892                         }// if(ds!=null)
893                         
894                 }catch (Exception e) {
895                                 e.printStackTrace();
896                 }
897 //              System.out.println("Total Images " + images.size());
898                 return images.size()>0?images:null;
899                 
900         }
901
902 /*
903         private boolean isImageRotate(Document doc, Image image) {
904                 
905                 System.out.println("image size="+image.getWidthPercentage()+ " "+ image.scaledWidth()+ 
906                                                         " "+image.scaledHeight()+" "+image.getXYRatio());
907                 System.out.println("page size = "+ doc.getPageSize().width() + " " +doc.getPageSize().height() +" "+ 
908                                    doc.topMargin() + " " +doc.bottomMargin() + " " +   doc.leftMargin() + " " +
909                                    doc.rightMargin());
910                 System.out.println(image.scaledWidth()/image.scaledHeight());
911                 System.out.println((PageEvent.getPageWidth(doc)/PageEvent.getPageHeight(doc)));
912 //              System.out.println(doc.getPageSize().getRotation());
913                 
914                 float image_w = image.scaledWidth();
915                 float image_h = image.scaledHeight();
916                 float image_ratio = image_w/image_h;
917                 
918                 float page_w = PageEvent.getPageWidth(doc);
919                 float page_h = PageEvent.getPageHeight(doc);
920                 float page_ratio = page_w/page_h;
921                 
922                 return  (image_w > page_w && image_ratio > page_ratio) ||
923                                 (image_h > page_h && image_ratio < page_ratio);
924
925         }
926         
927 */
928         private final int DEFAULT_PDF_DISPLAY_WIDTH = 10;
929         private int paintPdfData(HttpServletRequest request, Document document, ReportData rd, ReportRuntime rr, String sql_whole) throws DocumentException, RaptorException, IOException  {
930                 
931         int mb = 1024*1024;
932         Runtime runtime = Runtime.getRuntime();
933         int returnValue = 0;
934         //sql_whole = rr.getWholeSQL();
935         //if(rd.getDataRowCount() >= rr.getReportDataSize()) {
936                 //sql_whole="";
937         //}
938         float f[] = getRelativeWidths(rd, rr.getReportType().equals(AppConstants.RT_CROSSTAB));
939                 PdfPTable table = new PdfPTable(f);
940                 table.setWidthPercentage(100f);
941                 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
942                 table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM);
943                 
944                 ReportDefinition rdef = (new ReportHandler()).loadReportDefinition(request, rr.getReportID());
945                 
946                 List allColumns = rdef.getAllColumns();
947                 
948                 float[] repotWidths = new float[rdef.getVisibleColumnCount()];
949                 int columnIdx = 0;
950                 float pdfDisplayWidth = 0;
951                 for(Iterator iter = allColumns.iterator(); iter.hasNext();){
952                         DataColumnType dct = (DataColumnType) iter.next();
953                         if(dct.isVisible()) {
954                         
955                         if(dct.getPdfDisplayWidthInPxls() == null || dct.getPdfDisplayWidthInPxls().equals("") || dct.getPdfDisplayWidthInPxls().startsWith("null"))
956                                 pdfDisplayWidth = DEFAULT_PDF_DISPLAY_WIDTH;
957                         else
958                                 pdfDisplayWidth = Float.parseFloat(dct.getPdfDisplayWidthInPxls());
959                         
960                         repotWidths [columnIdx++] = pdfDisplayWidth;
961                         }
962                 }               
963                 
964                 table.setWidths(repotWidths);
965                 
966                 //table.setH
967                 
968                 //TODO: check title and subtitle
969                 HttpSession session = request.getSession();
970                 String drilldown_index = (String) session.getAttribute("drilldown_index");
971                 int index = 0;
972                 try {
973                  index = Integer.parseInt(drilldown_index);
974                 } catch (NumberFormatException ex) {
975                         index = 0;
976                 }               
977                 String titleRep = (String) session.getAttribute("TITLE_"+index);
978                 String subtitle = (String) session.getAttribute("SUBTITLE_"+index);
979                 
980                 if(nvl(titleRep).length()>0 && nvl(subtitle).length()>0)
981                         table.setHeaderRows(3);
982                 else if (nvl(titleRep).length()>0)
983                         table.setHeaderRows(2);
984                 else
985                         table.setHeaderRows(1);
986                 table = paintPdfReportHeader(request, document, table, rr, f);
987                 paintPdfTableHeader(document, rd, table);
988                 
989                 int idx = 0;
990                 int fragmentsize = 30; //for memory management
991                 
992                 ResultSet rs = null;
993         Connection conn = null;
994         Statement st = null;
995         ResultSetMetaData rsmd = null;
996         rd.reportDataRows.resetNext();
997         DataRow dr = rd.reportDataRows.getNext();
998                         
999                 //addRowHeader(table,dr,idx,rd);
1000
1001                         //addRowColumns(table,dr,idx);
1002                 if(nvl(sql_whole).length() >0 && rr.getReportType().equals(AppConstants.RT_LINEAR)) {
1003                    try {
1004                                 conn = ConnectionUtils.getConnection(rr.getDbInfo());
1005                                 st = conn.createStatement();
1006                             logger.debug(EELFLoggerDelegate.debugLogger, ("************* Map Whole SQL *************"));
1007                             logger.debug(EELFLoggerDelegate.debugLogger, (sql_whole));
1008                             logger.debug(EELFLoggerDelegate.debugLogger, ("*****************************************"));
1009                                 rs = st.executeQuery(sql_whole);
1010                                 rsmd = rs.getMetaData();
1011                             int numberOfColumns = rsmd.getColumnCount();
1012                             HashMap colHash = new HashMap();
1013                             dr = null;
1014                             int j = 0;
1015                             int rowCount = 0;
1016                             String title = "";
1017                                 while(rs.next()) {
1018                                         
1019 /*                                      if(runtime.freeMemory()/mb <= ((runtime.maxMemory()/mb)*Globals.getMemoryThreshold()/100) ) { 
1020                                                 returnValue = 1;
1021                                                 String cellValue = Globals.getUserDefinedMessageForMemoryLimitReached() + " "+ rowCount +" records out of " + rr.getReportDataSize() + " were downloaded to PDF.";
1022                                                 Font cellFont = FontFactory.getFont(Globals.getDataFontFamily(), 
1023                                                                                                                         Globals.getDataFontSize(),
1024                                                                                                                         Font.NORMAL, Color.BLACK);
1025                                                 PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont));
1026                                                 table.addCell(cell);
1027                                                 document.add(table);
1028                                                 return returnValue;
1029                                         }
1030 */                                      rowCount++;
1031                                         colHash = new HashMap();
1032                                         for (int i = 1; i <= numberOfColumns; i++) {
1033                                                 colHash.put(rsmd.getColumnLabel(i).toUpperCase(), rs.getString(i));
1034                                         }
1035                                         rd.reportDataRows.resetNext();
1036                                         
1037                                         dr = rd.reportDataRows.getNext();
1038                                         
1039                                         j = 0;
1040                                         /*if(rd.reportTotalRowHeaderCols!=null) {
1041                                         
1042                                                 HtmlFormatter rfmt = dr.getRowFormatter();
1043
1044                                                 Font cellFont = FontFactory.getFont(Globals.getDataFontFamily(), 
1045                                                                                                                         Globals.getDataFontSize(),
1046                                                                                                                         Font.NORMAL, Color.BLACK);
1047                                                 if(rfmt != null) {
1048                                                         cellFormatterFont(rfmt,cellFont);
1049                                                 }
1050                                                 
1051                                                 String cellValue = new Integer(rowCount).toString();
1052                                                 PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont));
1053                                                 
1054                                                 //row background color can be overwritten by cell background color
1055                                                 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1056                                                 
1057                                                 cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1058                                                 
1059                                                 if(rfmt != null) {
1060                                                         formatterCell(rfmt,cell);
1061                                                 }
1062                                                 table.addCell(cell);
1063                                         }*/
1064                                         
1065                                         for (dr.resetNext(); dr.hasNext();j++) {
1066                                                         DataValue dv = dr.getNext();
1067                                                         /*if(j == 0) {
1068                                                                 HtmlFormatter cfmt = dv.getCellFormatter();
1069                                                                 HtmlFormatter rfmt = dv.getRowFormatter();
1070
1071                                                                 Font cellFont = FontFactory.getFont(Globals.getDataFontFamily(), 
1072                                                                                                                                         Globals.getDataFontSize(),
1073                                                                                                                                         Font.NORMAL, Color.BLACK);
1074                                                                 if(cfmt!= null) {
1075                                                                         cellFormatterFont(cfmt,cellFont);
1076                                                                 }
1077                                                                 else if(rfmt != null) {
1078                                                                         cellFormatterFont(rfmt,cellFont);
1079                                                                 }
1080                                                                 else {
1081                                                                         if(dv.isBold()) {
1082                                                                                 cellFont.setStyle(Font.BOLD);
1083                                                                         }
1084                                                                 }
1085                                                                 
1086                                                                 //String cellValue = strip.stripHtml(value.trim());
1087                                                                 PdfPCell cell = new PdfPCell(new Paragraph(rowCount+"",cellFont));
1088                                                                 
1089                                                                 //row background color can be overwritten by cell background color
1090                                                                 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1091                                                                 
1092                                                                 if(nvl(dv.getAlignment()).trim().length()>0)
1093                                                                         cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment()));
1094                                                                 else
1095                                                                         cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1096                                                                 
1097                                                                 if(cfmt!= null) {
1098                                                                         formatterCell(cfmt,cell);
1099                                                                 }
1100                                                                 else if(rfmt != null) {
1101                                                                         formatterCell(rfmt,cell);
1102                                                                 }
1103                                                                 table.addCell(cell);
1104                                                         }*/
1105                                                 
1106                                                 //for (chr.resetNext(); chr.hasNext();) {
1107                                                         //ColumnHeader ch = chr.getNext();
1108                                                         String value = nvl((String)colHash.get(dv.getColId().toUpperCase()));
1109                                                         if(dv.isVisible()) {
1110                                                                 
1111                                                                 HtmlFormatter cfmt = dv.getCellFormatter();
1112                                                                 HtmlFormatter rfmt = dv.getRowFormatter();
1113
1114                                                                 Font cellFont = FontFactory.getFont(FONT_FAMILY, 
1115                                                                                                                                         FONT_SIZE,
1116                                                                                                                                         Font.NORMAL, Color.BLACK);
1117                                                                 if(cfmt!= null) {
1118                                                                         cellFormatterFont(cfmt,cellFont);
1119                                                                 }
1120                                                                 else if(rfmt != null) {
1121                                                                         cellFormatterFont(rfmt,cellFont);
1122                                                                 }
1123                                                                 else {
1124                                                                         if(dv.isBold()) {
1125                                                                                 cellFont.setStyle(Font.BOLD);
1126                                                                         }
1127                                                                 }
1128                                                                 
1129                                                                 String cellValue = strip.stripHtml(value.trim());
1130                                                                 PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont));
1131                                                                 
1132                                                                 //row background color can be overwritten by cell background color
1133                                                                 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1134                                                                 
1135                                                                 if(nvl(dv.getAlignment()).trim().length()>0)
1136                                                                         cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment()));
1137                                                                 else
1138                                                                         cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1139                                                                 
1140                                                                 if(cfmt!= null) {
1141                                                                         formatterCell(cfmt,cell);
1142                                                                 }
1143                                                                 else if(rfmt != null) {
1144                                                                         formatterCell(rfmt,cell);
1145                                                                 }
1146                                                                 
1147                                                                 
1148                                                                 
1149                                                                 table.addCell(cell);
1150                                                         
1151                                                         }//if isVisible()
1152                                                         
1153                                                         
1154                                         }
1155                                         
1156                                 }
1157                                 if(rd.reportDataTotalRow!=null) {
1158                                                 for (rd.reportDataTotalRow.resetNext(); rd.reportDataTotalRow.hasNext();idx++) {
1159                                                         dr = rd.reportDataTotalRow.getNext();
1160                                                         table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1161                                                         Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY, 
1162                                                                         FONT_SIZE,
1163                                                                         Font.NORMAL, Color.BLACK);
1164                                                         rowHeaderFont.setStyle(Font.BOLD);
1165                                                         rowHeaderFont.setSize(FONT_SIZE+1f);
1166                                                         table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx));
1167                                                                 table.addCell(new Paragraph("Total",rowHeaderFont));
1168                                                 
1169
1170                                                         addTotalRowColumns(table,dr,idx);
1171                                                         if (idx % fragmentsize == fragmentsize - 1) {
1172                                                                 document.add(table);
1173                                                                 table.deleteBodyRows();
1174                                                                 table.setSkipFirstHeader(true);
1175                                                         }
1176                         
1177                                                 }
1178                                 }                               
1179                             } catch (SQLException ex) { 
1180                                 throw new RaptorException(ex);
1181                             } catch (ReportSQLException ex) { 
1182                                 throw new RaptorException(ex);
1183                             } catch (Exception ex) {
1184                                 if(!(ex.getCause() instanceof java.net.SocketException) )
1185                                         throw new RaptorException (ex);
1186                             } finally {
1187                                 try {
1188                                         if(conn!=null)
1189                                                 conn.close();
1190                                         if(st!=null)
1191                                                 st.close();
1192                                         if(rs!=null)
1193                                                 rs.close();
1194                                 } catch (SQLException ex) {
1195                                         throw new RaptorException(ex);
1196                                 }
1197                         }
1198                         
1199                         
1200 //                      if (idx % fragmentsize == fragmentsize - 1) {
1201 //                              document.add(table);
1202 //                              table.deleteBodyRows();
1203 //                              table.setSkipFirstHeader(true);
1204 //                      }
1205  
1206         //document.add(table);
1207             } else {
1208                  if(rr.getReportType().equals(AppConstants.RT_LINEAR)) {
1209                 int rowCount = 0;
1210                         for(rd.reportDataRows.resetNext();rd.reportDataRows.hasNext();idx++)
1211                         {       
1212                         rowCount++;
1213                         
1214                         /*if(rd.reportTotalRowHeaderCols!=null) { 
1215                                         HtmlFormatter rfmt = dr.getRowFormatter();
1216         
1217                                         Font cellFont = FontFactory.getFont(Globals.getDataFontFamily(), 
1218                                                                                                                 Globals.getDataFontSize(),
1219                                                                                                                 Font.NORMAL, Color.BLACK);
1220                                         if(rfmt != null) {
1221                                                 cellFormatterFont(rfmt,cellFont);
1222                                         }
1223                                         
1224                                         //String cellValue = new Integer(rowCount).toString();
1225                                         //PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont));
1226                                         
1227                                         //row background color can be overwritten by cell background color
1228                                         //cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1229                                         
1230                                         //cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1231                                         
1232                                         //if(rfmt != null) {
1233                                                 //formatterCell(rfmt,cell);
1234                                         //}
1235                                         //table.addCell(cell);
1236                         }*/
1237                         
1238                         
1239                         
1240                                 if(runtime.freeMemory()/mb <= ((runtime.maxMemory()/mb)*Globals.getMemoryThreshold()/100) ) { 
1241                                                 returnValue = 1;
1242                                         }
1243                                 
1244                                 dr = rd.reportDataRows.getNext();
1245                                 
1246                                 addRowHeader(table,dr,idx,rd);
1247
1248                                 addRowColumns(table,dr,idx);
1249                                 
1250                                 if (idx % fragmentsize == fragmentsize - 1) {
1251                                         document.add(table);
1252                                         table.deleteBodyRows();
1253                                         table.setSkipFirstHeader(true);
1254                                 }
1255                         }
1256                         
1257                         if(rd.reportDataTotalRow!=null) {
1258                                         for (rd.reportDataTotalRow.resetNext(); rd.reportDataTotalRow.hasNext();idx++) {
1259                                                 dr = rd.reportDataTotalRow.getNext();
1260                                                 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1261                                                 Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY, 
1262                                                                 FONT_SIZE,
1263                                                                 Font.NORMAL, Color.BLACK);
1264                                                 rowHeaderFont.setStyle(Font.BOLD);
1265                                                 rowHeaderFont.setSize(FONT_SIZE+1f);
1266                                                 table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx));
1267                                                         table.addCell(new Paragraph("Total",rowHeaderFont));
1268                                         
1269
1270                                                 addTotalRowColumns(table,dr,idx);
1271                                                 if (idx % fragmentsize == fragmentsize - 1) {
1272                                                         document.add(table);
1273                                                         table.deleteBodyRows();
1274                                                         table.setSkipFirstHeader(true);
1275                                                 }
1276                 
1277                                         }
1278                         }                               
1279
1280                  } else if (rr.getReportType().equals(AppConstants.RT_CROSSTAB)) {
1281                     int rowCount = 0;
1282                     List l = rd.getReportDataList();
1283                     boolean first = true;
1284                         for (int dataRow = 0; dataRow < l.size(); dataRow++) {
1285                                 first = true;
1286                                 rowCount++;
1287                                 dr = (DataRow) l.get(dataRow);
1288                                         Vector<DataValue> rowNames = dr.getRowValues();
1289                                         for(dr.resetNext(); dr.hasNext(); ) {
1290                                                 
1291                                         if(first) {
1292                                                 HtmlFormatter rfmt = dr.getRowFormatter();
1293                                         
1294                                                 Font cellFont = FontFactory.getFont(FONT_FAMILY, 
1295                                                                                                                         FONT_SIZE,
1296                                                                                                                         Font.NORMAL, Color.BLACK);
1297                                                 if(rfmt != null) {
1298                                                         cellFormatterFont(rfmt,cellFont);
1299                                                 }
1300                                                 String cellValue = "";
1301                                                 PdfPCell cell = null;
1302                                                 //String cellValue = new Integer(rowCount).toString();
1303                                                 //PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont));
1304                                         //row background color can be overwritten by cell background color
1305                                                 //cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1306                                                 
1307                                                 //cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1308                                                 
1309                                                 //if(rfmt != null) {
1310                                                         //formatterCell(rfmt,cell);
1311                                         //      }
1312                                                 //table.addCell(cell);
1313                             if(rowNames!=null) {
1314                                 for(int i=0; i<rowNames.size(); i++) {
1315                                         DataValue dv = rowNames.get(i);
1316                                                         rfmt = dr.getRowFormatter();
1317                                                 
1318                                                         cellFont = FontFactory.getFont(FONT_FAMILY, 
1319                                                                                                                                 FONT_SIZE,
1320                                                                                                                                 Font.NORMAL, Color.BLACK);
1321                                                         if(rfmt != null) {
1322                                                                 cellFormatterFont(rfmt,cellFont);
1323                                                         }
1324                                                         cellValue = dv.getDisplayValue();
1325                                                 if(cellValue.indexOf("|#")!=-1)
1326                                                         cellValue = cellValue.substring(0,cellValue.indexOf("|"));
1327                                                 
1328                                                         cell = new PdfPCell(new Paragraph(cellValue,cellFont));
1329                                                 //row background color can be overwritten by cell background color
1330                                                         cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1331                                                         
1332                                                         cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1333                                                         
1334                                                         if(rfmt != null) {
1335                                                                 formatterCell(rfmt,cell);
1336                                                         }
1337                                                         table.addCell(cell);
1338                                 }
1339                                 }
1340                            }
1341                                         first = false;
1342                                 
1343                                         if(runtime.freeMemory()/mb <= ((runtime.maxMemory()/mb)*Globals.getMemoryThreshold()/100) ) { 
1344                                                         returnValue = 1;
1345                                                 }
1346                                         
1347                                         //addRowHeader(table,dr,idx,rd);
1348
1349                                         addRowColumns(table,dr,idx);
1350                                         
1351                                         if (idx % fragmentsize == fragmentsize - 1) {
1352                                                 document.add(table);
1353                                                 table.deleteBodyRows();
1354                                                 table.setSkipFirstHeader(true);
1355                                         }
1356                                 }
1357
1358                         }
1359                  }
1360             
1361                                 //document.add(table);
1362
1363             }
1364                 
1365             document.add(table);
1366             paintPdfReportFooter(request, document, rr, f);
1367             
1368             return returnValue; 
1369         }
1370         
1371         private void addRowHeader(PdfPTable table, DataRow dr, int idx, ReportData rd) {
1372                 
1373                 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);  
1374
1375                 for(rd.reportRowHeaderCols.resetNext();rd.reportRowHeaderCols.hasNext();) {
1376                         RowHeaderCol rhc = rd.reportRowHeaderCols.getNext();
1377                         if(idx==0) 
1378                                 rhc.resetNext();
1379                         RowHeader rh = rhc.getNext();
1380                         //System.out.println(" =============== RowHeader\n "+rh);
1381                         
1382                         Font rowHeaderFont = FontFactory.getFont(FONT_FAMILY, 
1383                                                                                                         FONT_SIZE,
1384                                                                                                         Font.NORMAL, Color.BLACK);
1385                         if(rh.isBold()) {
1386                                 rowHeaderFont.setStyle(Font.BOLD);
1387                                 rowHeaderFont.setSize(FONT_SIZE+1f);
1388                         }
1389                         
1390                         if(rh.getColSpan()>0) {
1391                                 table.getDefaultCell().setColspan(rh.getColSpan());
1392                                 table.getDefaultCell().setBackgroundColor(getRowBackgroundColor(dr, idx));
1393                                 table.addCell(new Paragraph(strip.stripHtml(rh.getRowTitle()),rowHeaderFont));
1394                         }
1395                 }               
1396         }
1397
1398         private void addRowColumns(PdfPTable table, DataRow dr, int idx) {
1399                         
1400                 table.getDefaultCell().setColspan(1);
1401                         
1402                 for(dr.resetNext();dr.hasNext();)
1403                 {
1404                         DataValue dv = dr.getNext();
1405                         //System.out.println(columnCount +" --> "+dv);
1406                         if(dv.isVisible()) {
1407                                 HtmlFormatter cfmt = dv.getCellFormatter();
1408                                 HtmlFormatter rfmt = dv.getRowFormatter();
1409
1410                                 Font cellFont = FontFactory.getFont(FONT_FAMILY, 
1411                                                                                                         FONT_SIZE,
1412                                                                                                         Font.NORMAL, Color.BLACK);
1413                                 if(cfmt!= null) {
1414                                         cellFormatterFont(cfmt,cellFont);
1415                                 }
1416                                 else if(rfmt != null) {
1417                                         cellFormatterFont(rfmt,cellFont);
1418                                 }
1419                                 else {
1420                                         if(dv.isBold()) {
1421                                                 cellFont.setStyle(Font.BOLD);
1422                                         }
1423                                 }
1424                                 
1425                                 String cellValue = strip.stripHtml(dv.getDisplayValue().trim());
1426                                 PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont));
1427                                 
1428                                 //row background color can be overwritten by cell background color
1429                                 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1430                                 
1431                                 if(nvl(dv.getAlignment()).trim().length()>0)
1432                                         cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment()));
1433                                 else
1434                                         cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1435                                 
1436                                 if(cfmt!= null) {
1437                                         formatterCell(cfmt,cell);
1438                                 }
1439                                 else if(rfmt != null) {
1440                                         formatterCell(rfmt,cell);
1441                                 }
1442                                 
1443                                 table.addCell(cell);
1444                         
1445                         }//if isVisible()
1446                 }                                       
1447         }
1448
1449
1450         private void addTotalRowColumns(PdfPTable table, DataRow dr, int idx) {
1451                 
1452                 table.getDefaultCell().setColspan(1);
1453                 dr.resetNext();
1454                 dr.getNext();
1455                 for(;dr.hasNext();)
1456                 {
1457                         DataValue dv = dr.getNext();
1458                         //System.out.println(columnCount +" --> "+dv);
1459                         if(dv.isVisible()) {
1460                                 HtmlFormatter cfmt = dv.getCellFormatter();
1461                                 HtmlFormatter rfmt = dv.getRowFormatter();
1462
1463                                 Font cellFont = FontFactory.getFont(FONT_FAMILY, 
1464                                                                                                         FONT_SIZE,
1465                                                                                                         Font.NORMAL, Color.BLACK);
1466                                 if(cfmt!= null) {
1467                                         cellFormatterFont(cfmt,cellFont);
1468                                 }
1469                                 else if(rfmt != null) {
1470                                         cellFormatterFont(rfmt,cellFont);
1471                                 }
1472                                 else {
1473                                         if(dv.isBold()) {
1474                                                 cellFont.setStyle(Font.BOLD);
1475                                         }
1476                                 }
1477                                 
1478                                 String cellValue = strip.stripHtml(dv.getDisplayValue().trim());
1479                                 PdfPCell cell = new PdfPCell(new Paragraph(cellValue,cellFont));
1480                                 
1481                                 //row background color can be overwritten by cell background color
1482                                 cell.setBackgroundColor(getRowBackgroundColor(dr, idx));
1483                                 
1484                                 if(nvl(dv.getAlignment()).trim().length()>0)
1485                                         cell.setHorizontalAlignment(ElementTags.alignmentValue(dv.getAlignment()));
1486                                 else
1487                                         cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1488                                 
1489                                 if(cfmt!= null) {
1490                                         formatterCell(cfmt,cell);
1491                                 }
1492                                 else if(rfmt != null) {
1493                                         formatterCell(rfmt,cell);
1494                                 }
1495                                 
1496                                 table.addCell(cell);
1497                         
1498                         }//if isVisible()
1499                 }                                       
1500         }
1501         
1502         
1503         private void formatterCell(HtmlFormatter fmt, PdfPCell cell) {
1504                 
1505                 if(nvl(fmt.getBgColor()).trim().length()>0)
1506                         cell.setBackgroundColor(Color.decode(fmt.getBgColor()));
1507                 if(nvl(fmt.getAlignment()).trim().length()>0)
1508                         cell.setHorizontalAlignment(ElementTags.alignmentValue(fmt.getAlignment()));
1509         }
1510
1511         private void cellFormatterFont(HtmlFormatter fmt, Font font) {
1512                 
1513                 if(fmt.isBold()) 
1514                         font.setStyle(Font.BOLD);
1515                 if(fmt.isItalic()) 
1516                         font.setStyle(Font.ITALIC);
1517                 if(fmt.isUnderline()) 
1518                         font.setStyle(Font.UNDERLINE);
1519                 if(fmt.getFontColor().trim().length()>0)
1520                         font.setColor(Color.decode(fmt.getFontColor()));
1521                 if(fmt.getFontSize().trim().length()>0)
1522                         font.setSize(Float.parseFloat(fmt.getFontSize())-Globals.getDataFontSizeOffset());
1523 //              if(fmt.getFontFace().trim().length()>0)
1524 //                      cellFont.setFamily()
1525                 
1526         }
1527
1528         private Color getRowBackgroundColor(DataRow dr, int idx) {
1529                 
1530                 Color color =  Color.decode(Globals.getDataDefaultBackgroundHexCode());
1531                 
1532                 HtmlFormatter rhf = dr.getRowFormatter();
1533                 if(rhf!=null && nvl(rhf.getBgColor()).trim().length()>0)
1534                         
1535                         color = Color.decode(rhf.getBgColor());
1536                 
1537                 else if(pb.isAlternateColor() && idx%2==0)
1538                         
1539                         color = Color.decode(Globals.getDataBackgroundAlternateHexCode());
1540                 
1541                 return color;           
1542
1543         }
1544
1545         private int getTotalVisbleColumns(ReportData rd) {
1546                 
1547                 int totalVisbleColumn = rd.getTotalColumnCount();
1548                 for(rd.reportDataRows.resetNext();rd.reportDataRows.hasNext();)
1549                 {       
1550                         DataRow dr = rd.reportDataRows.getNext();
1551                         for(dr.resetNext();dr.hasNext();) {
1552                                 DataValue dv = dr.getNext();
1553                                 if(!dv.isVisible()) totalVisbleColumn--;
1554                         }
1555                         
1556                         break;
1557                 }
1558                 
1559                 return totalVisbleColumn;
1560         }
1561
1562         /*
1563         private int getFirstRowIndex(ReportRuntime rr) {
1564                 return (pb.getCurrentPage()>0)?pb.getCurrentPage()*rr.getPageSize()+1 : 1;
1565         }
1566         */
1567         private float[] getRelativeWidths(ReportData rd, boolean crosstab){
1568                 
1569                 int totalColumns = getTotalVisbleColumns(rd);
1570                 /*if(rd.reportTotalRowHeaderCols!=null) {
1571                         totalColumns += 1;
1572                 }*/
1573                 if(crosstab) {
1574                         totalColumns += 1;
1575                 }
1576
1577                 if(totalColumns == 0 )
1578                         totalColumns=1;
1579                 
1580                 float[] relativeWidths = new float[totalColumns];
1581                 //initial widths are even
1582                 for(int i=0; i<relativeWidths.length; i++)
1583                         relativeWidths[i] = 10f;
1584                 
1585                 int index=0;
1586                 boolean firstPass = true;
1587                 
1588                 for (rd.reportColumnHeaderRows.resetNext(); rd.reportColumnHeaderRows.hasNext();) 
1589                 {
1590                         if(firstPass) {
1591                                 /*if(rd.reportTotalRowHeaderCols!=null) { 
1592                                         String columnWidth = "5";
1593                                         
1594                                         if(columnWidth != null && columnWidth.trim().endsWith("%"))
1595                                                 relativeWidths[index] = Float.parseFloat(removeLastCharacter(columnWidth));
1596                                         
1597                                         index++;
1598                                 }*/
1599                                 
1600                                 for(rd.reportRowHeaderCols.resetNext();rd.reportRowHeaderCols.hasNext();) {
1601                                         String columnWidth = rd.reportRowHeaderCols.getNext().getColumnWidth();
1602                                         
1603                                         if(columnWidth != null && columnWidth.trim().endsWith("%"))
1604                                                 relativeWidths[index] = Float.parseFloat(removeLastCharacter(columnWidth));
1605                                         
1606                                         index++;
1607                                 }
1608                                 firstPass = false;
1609                         }
1610                 
1611                         ColumnHeaderRow chr = rd.reportColumnHeaderRows.getNext();
1612                         for (chr.resetNext(); chr.hasNext();) {
1613                                 
1614                                 ColumnHeader ch = chr.getNext();
1615
1616                                 if(ch.isVisible()) {
1617                                         
1618                                         String columnWidth = ch.getColumnWidth();
1619                                         
1620                                         if(ch.getColSpan() <= 1){
1621                                                 if(columnWidth != null && columnWidth.trim().endsWith("%")) 
1622                                                         relativeWidths[index] = Float.parseFloat(removeLastCharacter(columnWidth));
1623                                         } 
1624                                         else {
1625                                                 for(int i=0; i<ch.getColSpan(); i++) {
1626                                                         index += i;
1627                                                         if(columnWidth != null && columnWidth.trim().endsWith("%"))
1628                                                                 relativeWidths[index] = 
1629                                                                         (Float.parseFloat(removeLastCharacter(columnWidth)))/ch.getColSpan();                                                   
1630                                                 }
1631                                         }
1632                                         
1633                                         index++;
1634                                 }
1635                         }
1636                 }
1637                 
1638                 return relativeWidths;
1639         }
1640         
1641         public static String removeLastCharacter(String str) {
1642                 return str.substring(0, str.length()-1);
1643         }
1644         
1645         private PdfPTable paintPdfReportHeader(HttpServletRequest request, Document document, PdfPTable table, ReportRuntime rr, float[] f) 
1646                         throws DocumentException, IOException {
1647                 
1648                 HttpSession session = request.getSession();
1649                 String drilldown_index = (String) session.getAttribute("drilldown_index");
1650                 int index = 0;
1651                 try {
1652                  index = Integer.parseInt(drilldown_index);
1653                 } catch (NumberFormatException ex) {
1654                         index = 0;
1655                 }
1656                 String title = (String) session.getAttribute("TITLE_"+index);
1657                 String subtitle = (String) session.getAttribute("SUBTITLE_"+index);
1658                 if(nvl(title).length()>0) {
1659                         //PdfPTable table = new PdfPTable(1);
1660                         table.setWidthPercentage(100f);
1661                         table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1662                         table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM);
1663                 
1664         
1665                         Font font = FontFactory.getFont(FONT_FAMILY, 
1666                                         FONT_SIZE-2f,
1667                                         Font.BOLD, 
1668                                         Color.BLACK);
1669                 
1670                         //addEmptyRows(table,1);
1671                         table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1672                         //table.getDefaultCell().setBackgroundColor(Color.decode(Globals.getDataTableHeaderBackgroundFontColor()));
1673                     title = Utils.replaceInString(title, "<BR/>", " ");
1674                     title = Utils.replaceInString(title, "<br/>", " ");
1675                     title = Utils.replaceInString(title, "<br>", " ");
1676                         title  = strip.stripHtml(nvl(title).trim());
1677                         //subtitle = Utils.replaceInString(subtitle, "<BR/>", " ");
1678                         //subtitle = Utils.replaceInString(subtitle, "<br/>", " ");
1679                         //subtitle = Utils.replaceInString(subtitle, "<br>", " ");
1680                         //subtitle  = strip.stripHtml(nvl(subtitle).trim());
1681                         StyleSheet styles = new StyleSheet();
1682                         
1683                         HTMLWorker htmlWorker = new HTMLWorker(document); 
1684                         ArrayList cc = new ArrayList(); 
1685                         cc = htmlWorker.parseToList(new StringReader(subtitle), styles); 
1686                                                 
1687                         Phrase p1 = new Phrase(); 
1688                         for (int i = 0; i < cc.size(); i++){ 
1689                                 Element elem = (Element)cc.get(i); 
1690                                 ArrayList al  = elem.getChunks();
1691                                 for (int j = 0; j < al.size(); j++) {
1692                                         Chunk chunk = (Chunk) al.get(j);
1693                                         chunk.font().setSize(6.0f);
1694                                 }
1695                                 p1.add(elem); 
1696                         } 
1697                         //cell = new PdfPCell(p1);
1698                 StyleSheet style = new StyleSheet();
1699                 style.loadTagStyle("font", "font-size", "3");
1700                 style.loadTagStyle("font", "size", "3");
1701             styles.loadStyle("pdfFont1", "size", "11px");                                 
1702             styles.loadStyle("pdfFont1", "font-size", "11px"); 
1703                 /*ArrayList p = HTMLWorker.parseToList(new StringReader(nvl(title)), style);
1704                 for (int k = 0; k < p.size(); ++k){
1705                         document.add((com.lowagie.text.Element)p.get(k));
1706                 }*/
1707             //p1.font().setSize(3.0f);
1708                         PdfPCell titleCell = new PdfPCell(new Phrase(title, font));
1709                         titleCell.setColspan(rr.getVisibleColumnCount());
1710                         PdfPCell subtitleCell = new PdfPCell(p1);
1711                         subtitleCell.setColspan(rr.getVisibleColumnCount());
1712                         titleCell.setHorizontalAlignment(1);
1713                         subtitleCell.setHorizontalAlignment(1);
1714                         table.addCell(titleCell);
1715                         table.addCell(subtitleCell);
1716                         //document.add(table);
1717                 }
1718                 return table;
1719         }
1720
1721
1722         private void paintPdfReportFooter(HttpServletRequest request, Document document, ReportRuntime rr, float[] f) 
1723                         throws DocumentException, IOException {
1724                 
1725                 HttpSession session = request.getSession();
1726                 String drilldown_index = (String) session.getAttribute("drilldown_index");
1727                 int index = 0;
1728                 try {
1729                  index = Integer.parseInt(drilldown_index);
1730                 } catch (NumberFormatException ex) {
1731                         index = 0;
1732                 }
1733
1734                 String title = (String) session.getAttribute("FOOTER_"+index);
1735                 if(nvl(title).length()>0) {
1736                         PdfPTable table = new PdfPTable(1);
1737                         table.setWidthPercentage(100f);
1738                         table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1739                         table.getDefaultCell().setVerticalAlignment(Rectangle.ALIGN_BOTTOM);
1740                 
1741                         Font font = FontFactory.getFont(FONT_FAMILY, 
1742                                         FONT_SIZE-3f,
1743                                         Font.BOLD, 
1744                                         Color.BLACK);
1745                 
1746                         
1747                         //addEmptyRows(table,1);
1748                         table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1749                         //table.getDefaultCell().setBackgroundColor(Color.decode(Globals.getDataTableHeaderBackgroundFontColor()));
1750                     /*title = Utils.replaceInString(title, "<BR/>", " ");
1751                     title = Utils.replaceInString(title, "<br/>", " ");
1752                     title = Utils.replaceInString(title, "<br>", " ");
1753                         title  = strip.stripHtml(nvl(title).trim());*/
1754                 StyleSheet style = new StyleSheet();
1755                 
1756                         HTMLWorker htmlWorker = new HTMLWorker(document); 
1757                         ArrayList cc = new ArrayList(); 
1758                         cc = htmlWorker.parseToList(new StringReader(title), style); 
1759                                                 
1760                         Phrase p1 = new Phrase(); 
1761                         for (int i = 0; i < cc.size(); i++){ 
1762                                 Element elem = (Element)cc.get(i); 
1763                                 ArrayList al  = elem.getChunks();
1764                                 for (int j = 0; j < al.size(); j++) {
1765                                         Chunk chunk = (Chunk) al.get(j);
1766                                         chunk.font().setSize(6.0f);
1767                                 }
1768                                 p1.add(elem); 
1769                         } 
1770                 
1771 /*                      
1772                         HTMLWorker.parseToList(new StringReader(nvl(title)), style);*/
1773                         PdfPCell titleCell = new PdfPCell(p1);
1774                         titleCell.setHorizontalAlignment(Element.ALIGN_LEFT);
1775                         table.addCell(titleCell);
1776                         //table.
1777                         document.add(table);
1778                 }
1779                 //return table;
1780         }
1781         
1782         
1783         private void paintPdfTableHeader(Document document, ReportData rd, PdfPTable table) 
1784                                                                                                                                 throws DocumentException {
1785                         
1786                 Font font = FontFactory.getFont(FONT_FAMILY, 
1787                                                                                 FONT_SIZE+1f,
1788                                                                                 Font.BOLD, 
1789                                                                                 Color.decode(Globals.getDataTableHeaderFontColor()));
1790                 //table.setHeaderRows(1);
1791                 table.getDefaultCell().setHorizontalAlignment(Rectangle.ALIGN_CENTER);
1792                 table.getDefaultCell().setBackgroundColor(Color.decode(Globals.getDataTableHeaderBackgroundFontColor()));
1793                 String title = "";
1794                 
1795                 boolean firstPass = true;
1796                 
1797                 /*if(rd.reportTotalRowHeaderCols!=null) {
1798                         if(firstPass) {
1799                                 table.addCell(new Paragraph("No.", font));
1800                                 firstPass = false;
1801                         }
1802                 }*/             
1803                 for (rd.reportColumnHeaderRows.resetNext(); rd.reportColumnHeaderRows.hasNext();) 
1804                 {
1805                         if(firstPass) {
1806                                 for(rd.reportRowHeaderCols.resetNext();rd.reportRowHeaderCols.hasNext();) {
1807                                         /*if(firstPass) {
1808                                                 table.addCell(new Paragraph("No.", font));
1809                                                 firstPass = false;
1810                                         } else {*/
1811                                                 RowHeaderCol rhc = rd.reportRowHeaderCols.getNext();
1812                                                 title = rhc.getColumnTitle();
1813                                         title = Utils.replaceInString(title,"_nl_", " \n");
1814                                                 table.addCell(new Paragraph(title,font));
1815                                         //}
1816                                 }
1817                         }
1818                         
1819                         ColumnHeaderRow chr = rd.reportColumnHeaderRows.getNext();
1820                         for (chr.resetNext(); chr.hasNext();) {
1821                                 ColumnHeader ch = chr.getNext();
1822                                 //System.out.println(ch);
1823                                 if(ch.isVisible()) {
1824                                         title = ch.getColumnTitle();
1825                                 title = Utils.replaceInString(title,"_nl_", " \n");
1826                                         table.addCell(new Paragraph(title,font));
1827                                 }
1828                         }
1829                 }
1830         }
1831         
1832         public static String currentTime(String pattern) {
1833                 try {
1834                 SimpleDateFormat oracleDateFormat = new SimpleDateFormat("MM/dd/yyyy kk:mm:ss");
1835                 Date sysdate = oracleDateFormat.parse(ReportLoader.getSystemDateTime());
1836                 SimpleDateFormat dtimestamp = new SimpleDateFormat(Globals.getScheduleDatePattern());
1837                 return dtimestamp.format(sysdate)+" "+Globals.getTimeZone();
1838                 //paramList.add(new IdNameValue("DATE", dtimestamp.format(sysdate)+" "+Globals.getTimeZone()));
1839         } catch(Exception ex) {}         
1840                 
1841                 SimpleDateFormat s = new SimpleDateFormat(pattern);
1842                 s.setTimeZone(TimeZone.getTimeZone(Globals.getTimeZone()));
1843                 //System.out.println("^^^^^^^^^^^^^^^^^^^^ " + Calendar.getInstance().getTime());
1844                 //System.out.println("^^^^^^^^^^^^^^^^^^^^ " + s.format(Calendar.getInstance().getTime()));
1845                 return s.format(Calendar.getInstance().getTime());
1846         }
1847
1848         private PdfBean preparePdfBean(HttpServletRequest request,ReportRuntime rr) {
1849                 PdfBean pb = new PdfBean();
1850
1851                 pb.setUserId(AppUtils.getUserID(request));
1852
1853                 pb.setWhereToShowPageNumber(Globals.getPageNumberPosition());
1854                 pb.setAlternateColor(Globals.isDataAlternateColor());
1855                 pb.setTimestampPattern(Globals.getDatePattern());
1856
1857                 int temp = -1;
1858                 try {
1859                         temp = Integer.parseInt(request.getParameter(AppConstants.RI_NEXT_PAGE));
1860                 } catch (NumberFormatException e) {}            
1861                 pb.setCurrentPage(temp);
1862         
1863                 //pb.setPortrait( trueORfalse(request.getParameter("isPortrait"),true));
1864                 pb.setPortrait(trueORfalse(rr.getPDFOrientation() == "portait"?"true":"false", true));
1865                 //pb.setCoverPageIncluded( trueORfalse(request.getParameter("isCoverPageIncluded"), true));
1866                 //if(Globals.isCoverPageNeeded()) {
1867                         pb.setCoverPageIncluded(Globals.isCoverPageNeeded()?rr.isPDFCoverPage():false);
1868                 //}
1869                 pb.setTitle(nvl(request.getParameter("title")));
1870                 pb.setPagesize(nvls(request.getParameter("pagesize"),"LETTER"));
1871                 
1872                 pb.setLogo1Url(rr.getPDFLogo1());
1873                 pb.setLogo2Url(rr.getPDFLogo2());
1874                 pb.setLogo1Size(rr.getPDFLogo1Size());
1875                 pb.setLogo2Size(rr.getPDFLogo2Size());
1876                 pb.setFullWebContextPath(request.getSession().getServletContext().getRealPath(File.separator));
1877                 
1878
1879                 pb.setDisplayChart(nvl(rr.getChartType()).trim().length()>0 && rr.getDisplayChart());
1880                         
1881                 String id = nvl(request.getParameter("pdfAttachmentKey")).trim();
1882                 String log_id = nvl(request.getParameter("log_id")).trim();
1883                 if(id.length()>0 && log_id.length()>0)
1884                         pb.setAttachmentOfEmail(true);
1885                 
1886                 return pb;
1887         }
1888         
1889         private boolean trueORfalse(String str) {
1890                 return (str != null) && (str.equalsIgnoreCase("true"));
1891         }
1892         
1893         private boolean trueORfalse(String str,boolean b_default) {
1894                 return str==null ? b_default : (str.equalsIgnoreCase("true"));
1895         }
1896         
1897    
1898 }