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