Source Code Cross Referenced for JFreeReportGeneratorComponent.java in  » Report » pentaho-report » org » pentaho » plugin » jfreereport » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » pentaho report » org.pentaho.plugin.jfreereport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Pentaho Corporation.  All rights reserved. 
003:         * This software was developed by Pentaho Corporation and is provided under the terms 
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
005:         * this file except in compliance with the license. If you need a copy of the license, 
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
011:         * the license for the specific language governing your rights and limitations.
012:         *
013:         * @created Jun 23, 2005 
014:         * @author James Dixon
015:         */
016:        package org.pentaho.plugin.jfreereport;
017:
018:        import java.io.ByteArrayOutputStream;
019:        import java.math.BigDecimal;
020:        import java.sql.Date;
021:        import java.sql.Types;
022:        import java.util.LinkedList;
023:        import java.util.List;
024:        import java.util.Set;
025:
026:        import org.apache.commons.logging.Log;
027:        import org.apache.commons.logging.LogFactory;
028:        import org.dom4j.Document;
029:        import org.dom4j.Node;
030:        import org.pentaho.actionsequence.dom.actions.JFreeReportGenAction;
031:        import org.pentaho.commons.connection.IPentahoResultSet;
032:        import org.pentaho.core.system.PentahoSystem;
033:        import org.pentaho.core.util.XmlHelper;
034:        import org.pentaho.jfreereport.castormodel.reportspec.Field;
035:        import org.pentaho.jfreereport.castormodel.reportspec.ReportSpec;
036:        import org.pentaho.jfreereport.castormodel.reportspec.ReportSpecChoice;
037:        import org.pentaho.jfreereport.wizard.utility.report.ReportGenerationUtility;
038:        import org.pentaho.messages.Messages;
039:        import org.pentaho.plugin.ComponentBase;
040:
041:        /**
042:         * @author Bill Seyler, Michael D'Amour
043:         * 
044:         * 
045:         */
046:        public class JFreeReportGeneratorComponent extends ComponentBase {
047:            /**
048:             * 
049:             */
050:            private static final long serialVersionUID = 9050456842938084174L;
051:
052:            private static final String GROUP_LABELS_PROP = "group-labels"; //$NON-NLS-1$
053:
054:            private static final String GROUP_LABEL_PROP = "group-label"; //$NON-NLS-1$
055:
056:            private static final String GROUPED_COLUMNS_PROP = "grouped-columns"; //$NON-NLS-1$
057:
058:            private static final String GROUPED_COLUMN_INDICES_PROP = "group-index"; //$NON-NLS-1$
059:
060:            private static final String COLUMN_NAMES_PROP = "column-names"; //$NON-NLS-1$
061:
062:            private static final String COLUMN_NAME_PROP = "column-name"; //$NON-NLS-1$
063:
064:            private static final String COLUMN_WIDTHS_PROP = "column-widths"; //$NON-NLS-1$
065:
066:            private static final String WIDTH_PROP = "width"; //$NON-NLS-1$
067:
068:            private static final String COLUMN_ALIGNMENTS_PROP = "column-alignments"; //$NON-NLS-1$
069:
070:            private static final String COLUMN_ALIGNMENT_PROP = "column-alignment"; //$NON-NLS-1$
071:
072:            private static final String ITEM_HIDES_PROP = "item-hide-columns"; //$NON-NLS-1$
073:
074:            private static final String ITEM_HIDE_PROP = "use-item-hide"; //$NON-NLS-1$
075:
076:            private static final String COLUMN_FORMATS_PROP = "column-formats"; //$NON-NLS-1$
077:
078:            private static final String FORMAT_PROP = "column-format"; //$NON-NLS-1$
079:
080:            IPentahoResultSet resultSet = null;
081:
082:            String[] displayNames = null;
083:
084:            String compPath = null;
085:
086:            String path = null;
087:
088:            String orientation = "landscape"; //$NON-NLS-1$
089:
090:            String[] groupLabels = null;
091:
092:            int[] groupIndices = null;
093:
094:            int[] widths = null;
095:
096:            boolean[] itemHides = null;
097:
098:            String[] formats = null;
099:
100:            String[] columnAlignments;
101:
102:            String reportName = ""; //$NON-NLS-1$
103:
104:            boolean createSubTotals = false;
105:
106:            boolean createGrandTotals = false;
107:
108:            boolean createRowBanding = false;
109:
110:            boolean createTotalColumn = false;
111:
112:            String totalColumnName = "All"; //$NON-NLS-1$
113:
114:            int totalColumnWidth = 120;
115:
116:            String totalColumnFormat = "#,##0"; //$NON-NLS-1$
117:
118:            String rowBandingColor = "#A0A0A0"; //$NON-NLS-1$
119:
120:            int spacerWidth = 10;
121:
122:            String columnHeaderBackgroundColor = "#C0C0C0"; //$NON-NLS-1$
123:
124:            String columnHeaderForegroundColor = "#202020"; //$NON-NLS-1$
125:
126:            String columnHeaderFontFace = "SansSerif"; //$NON-NLS-1$
127:
128:            String columnHeaderFontSize = "12"; //$NON-NLS-1$
129:
130:            int columnHeaderGap = 2;
131:
132:            String nullString = ""; //$NON-NLS-1$
133:
134:            int horizontalOffset = 0;
135:
136:            public Log getLogger() {
137:                return LogFactory.getLog(JFreeReportGeneratorComponent.class);
138:            }
139:
140:            protected boolean validateSystemSettings() {
141:                // This component does not have any system settings to validate
142:                return true;
143:            }
144:
145:            protected boolean validateAction() {
146:                /*
147:                 * String templatePath = getComponentSetting(TEMPLATE_PATH_PROP); if (templatePath == null) { error("Undefined Template Path"); return false; }
148:                 */
149:                return true;
150:            }
151:
152:            public void done() {
153:            }
154:
155:            protected boolean executeAction() {
156:                /*
157:                 * The on-the-fly JFreeReport generator will expect the following: =============================================
158:                 * 
159:                 * INPUT: Path (String) to Existing JFreeReport to use as "template" OutputStream to write generated report IPentahoResultSet List of Columns to "Group" List of column widths
160:                 * 
161:                 * OUTPUT: JFreeReport XML to provided Path or OutputStream
162:                 * 
163:                 * ASSUMPTIONS: List of column widths - last provided item is to be repeated for all remaining columns Perform ItemSumFunction on all numeric columns per group and grand total Perform ItemSumFunction on calculated column per group and
164:                 * grand total Groups and Items will be removed from template (we will retain font/color data) =============================================
165:                 * 
166:                 * public OnTheFlyJFreeReportGenerator(String path, IPentahoResultSet set, List groupLabels, List widths, OutputStream stream) ------ public void process()
167:                 */
168:
169:                JFreeReportGenAction genAction = null;
170:
171:                if (!(getActionDefinition() instanceof  JFreeReportGenAction)) {
172:                    error(Messages
173:                            .getErrorString(
174:                                    "ComponentBase.ERROR_0001_UNKNOWN_ACTION_TYPE", getActionDefinition().getElement().asXML())); //$NON-NLS-1$
175:                    return false;
176:                } else {
177:                    genAction = (JFreeReportGenAction) getActionDefinition();
178:
179:                    resultSet = (IPentahoResultSet) genAction.getResultSet()
180:                            .getValue();
181:                    Node componentNode = null;
182:                    String settingsFromActionSequence = null;
183:                    try {
184:                        settingsFromActionSequence = genAction
185:                                .getComponentSettings().getStringValue();
186:                    } catch (Exception ex) {
187:                    }
188:                    if (settingsFromActionSequence != null) {
189:                        Document settingsDoc = XmlHelper
190:                                .getDocFromString(settingsFromActionSequence);
191:                        componentNode = settingsDoc.getRootElement();
192:                    } else {
193:                        componentNode = getComponentDefinition();
194:                    }
195:                    try {
196:                        compPath = genAction.getTemplatePath().getStringValue();
197:                        path = PentahoSystem.getApplicationContext()
198:                                .getSolutionPath(compPath);
199:                        orientation = genAction.getOrientation()
200:                                .getStringValue();
201:                        nullString = genAction.getNullStrin().getStringValue();
202:                        horizontalOffset = genAction.getHorizontalOffset()
203:                                .getIntValue(horizontalOffset);
204:                        reportName = genAction.getReportName().getStringValue();
205:                        createSubTotals = genAction.getCreateSubTotals()
206:                                .getBooleanValue(false);
207:                        createGrandTotals = genAction.getCreateGrandTotals()
208:                                .getBooleanValue(false);
209:                        createRowBanding = genAction.getCreateRowBanding()
210:                                .getBooleanValue(false);
211:                        createTotalColumn = genAction.getCreateTotalColumn()
212:                                .getBooleanValue(false);
213:                        totalColumnName = genAction.getTotalColumnName()
214:                                .getStringValue();
215:                        totalColumnWidth = genAction.getTotalColumnWidth()
216:                                .getIntValue(totalColumnWidth);
217:                        totalColumnFormat = genAction.getTotalColumnFormat()
218:                                .getStringValue();
219:                        rowBandingColor = genAction.getRowBandingColor()
220:                                .getStringValue();
221:                        spacerWidth = genAction.getSpacerWidth().getIntValue(
222:                                spacerWidth);
223:                        columnHeaderBackgroundColor = genAction
224:                                .getColumnHeaderBackgroundColor()
225:                                .getStringValue();
226:                        columnHeaderForegroundColor = genAction
227:                                .getColumnHeaderForegroundColor()
228:                                .getStringValue();
229:                        columnHeaderFontFace = genAction
230:                                .getColumnHeaderFontFace().getStringValue();
231:                        columnHeaderFontSize = genAction
232:                                .getColumnHeaderFontSize().getStringValue();
233:                        columnHeaderGap = genAction.getColumnHeaderGap()
234:                                .getIntValue(columnHeaderGap);
235:                    } catch (Exception e) {
236:                        e.printStackTrace();
237:                    }
238:
239:                    // Get the group display labels
240:                    List groupLabelNodes = componentNode
241:                            .selectNodes(GROUP_LABELS_PROP
242:                                    + "/" + GROUP_LABEL_PROP); //$NON-NLS-1$
243:                    if (groupLabelNodes != null) {
244:                        groupLabels = new String[groupLabelNodes.size()];
245:                        for (int i = 0; i < groupLabels.length; i++) {
246:                            groupLabels[i] = ((Node) groupLabelNodes.get(i))
247:                                    .getText();
248:                        }
249:                    }
250:                    // Get the grouped columns indices
251:                    List groupedColumnsIndicesNodes = componentNode
252:                            .selectNodes(GROUPED_COLUMNS_PROP
253:                                    + "/" + GROUPED_COLUMN_INDICES_PROP); //$NON-NLS-1$
254:                    if (groupedColumnsIndicesNodes != null) {
255:                        groupIndices = new int[groupedColumnsIndicesNodes
256:                                .size()];
257:                        for (int i = 0; i < groupIndices.length; i++) {
258:                            groupIndices[i] = Integer
259:                                    .parseInt(((Node) groupedColumnsIndicesNodes
260:                                            .get(i)).getText()) - 1;
261:                            // I am zero based, this is not
262:                        }
263:                    }
264:                    // get display names
265:                    List displayNameNodes = componentNode
266:                            .selectNodes(COLUMN_NAMES_PROP
267:                                    + "/" + COLUMN_NAME_PROP); //$NON-NLS-1$
268:                    if (displayNameNodes != null) {
269:                        displayNames = new String[displayNameNodes.size()];
270:                        for (int i = 0; i < displayNames.length; i++) {
271:                            displayNames[i] = ((Node) displayNameNodes.get(i))
272:                                    .getText();
273:                        }
274:                    }
275:                    // get column alignments
276:                    List columnAlignmentNodes = componentNode
277:                            .selectNodes(COLUMN_ALIGNMENTS_PROP
278:                                    + "/" + COLUMN_ALIGNMENT_PROP); //$NON-NLS-1$
279:                    if (columnAlignmentNodes != null) {
280:                        columnAlignments = new String[columnAlignmentNodes
281:                                .size()];
282:                        for (int i = 0; i < columnAlignments.length; i++) {
283:                            columnAlignments[i] = ((Node) columnAlignmentNodes
284:                                    .get(i)).getText();
285:                        }
286:                    }
287:                    // Get the column widths
288:                    List widthNodes = componentNode
289:                            .selectNodes(COLUMN_WIDTHS_PROP + "/" + WIDTH_PROP); //$NON-NLS-1$
290:                    if (widthNodes != null) {
291:                        widths = new int[widthNodes.size()];
292:                        for (int i = 0; i < widths.length; i++) {
293:                            widths[i] = Integer.valueOf(
294:                                    ((Node) widthNodes.get(i)).getText())
295:                                    .intValue();
296:                        }
297:                    }
298:                    // Get the column item hides
299:                    List itemHideNodes = componentNode
300:                            .selectNodes(ITEM_HIDES_PROP + "/" + ITEM_HIDE_PROP); //$NON-NLS-1$
301:                    if (itemHideNodes != null) {
302:                        itemHides = new boolean[itemHideNodes.size()];
303:                        for (int i = 0; i < itemHides.length; i++) {
304:                            itemHides[i] = Boolean.valueOf(
305:                                    ((Node) itemHideNodes.get(i)).getText())
306:                                    .booleanValue();
307:                        }
308:                    }
309:                    // Get the column formats
310:                    List formatNodes = componentNode
311:                            .selectNodes(COLUMN_FORMATS_PROP
312:                                    + "/" + FORMAT_PROP); //$NON-NLS-1$
313:                    if (formatNodes != null) {
314:                        formats = new String[formatNodes.size()];
315:                        for (int i = 0; i < formats.length; i++) {
316:                            formats[i] = ((Node) formatNodes.get(i)).getText();
317:                        }
318:                    }
319:                }
320:                String reportDefinition = process();
321:                if (reportDefinition != null) {
322:                    if (genAction.getOutputReportDefinition() != null) {
323:                        genAction.getOutputReportDefinition().setValue(
324:                                reportDefinition);
325:                    } else {
326:                        // This is to support the old way where 
327:                        // we did not check if report-definition existed in the output section
328:                        setOutputValue(JFreeReportGenAction.REPORT_DEFINITION,
329:                                reportDefinition); //$NON-NLS-1$
330:                    }
331:                }
332:
333:                return true;
334:            }
335:
336:            public String process() {
337:                // CREATE report-spec.xml
338:                // USE passed in jfreeReportTemplate as "include" -- stuff in
339:                // report-spec
340:                // GENERATE JFreeReport from report-spec using code already written in
341:                // DesignerUtility
342:                //  
343:                ByteArrayOutputStream outputStream = null;
344:                try {
345:                    outputStream = new ByteArrayOutputStream();
346:                } catch (Exception e) {
347:                    getLogger().error(e);
348:                }
349:                ReportSpec reportSpec = new ReportSpec();
350:                reportSpec.setReportName(reportName);
351:                reportSpec.setHorizontalOffset(horizontalOffset);
352:                reportSpec.setIncludeSrc(getPath());
353:                reportSpec.setQuery("no query"); //$NON-NLS-1$
354:                reportSpec.setReportSpecChoice(new ReportSpecChoice());
355:                reportSpec.getReportSpecChoice().setJndiSource("SampleData"); //$NON-NLS-1$
356:                reportSpec.setCalculateGrandTotals(createGrandTotals);
357:                reportSpec.setTopMargin(10);
358:                reportSpec.setBottomMargin(10);
359:                reportSpec.setLeftMargin(10);
360:                reportSpec.setRightMargin(10);
361:                reportSpec.setUseRowBanding(createRowBanding);
362:                reportSpec.setColumnHeaderGap(columnHeaderGap);
363:                if (rowBandingColor != null) {
364:                    reportSpec.setRowBandingColor(rowBandingColor);
365:                }
366:                if (columnHeaderBackgroundColor != null) {
367:                    reportSpec
368:                            .setColumnHeaderBackgroundColor(columnHeaderBackgroundColor);
369:                }
370:                if (columnHeaderForegroundColor != null) {
371:                    reportSpec
372:                            .setColumnHeaderFontColor(columnHeaderForegroundColor);
373:                }
374:                if (columnHeaderFontFace != null) {
375:                    reportSpec.setColumnHeaderFontName(columnHeaderFontFace);
376:                }
377:                if (columnHeaderFontSize != null) {
378:                    reportSpec.setColumnHeaderFontSize(Integer
379:                            .parseInt(columnHeaderFontSize));
380:                }
381:                reportSpec.setOrientation(orientation);
382:                Object colHeaders[] = resultSet.getMetaData()
383:                        .getColumnHeaders()[0];
384:                int totalWidth = reportSpec.getLeftMargin()
385:                        + reportSpec.getRightMargin();
386:                List groupsList = new LinkedList();
387:                List details = new LinkedList();
388:                // leading spacer
389:                if (spacerWidth > 0) {
390:                    Field spacer = new Field();
391:                    spacer.setName(""); //$NON-NLS-1$
392:                    spacer.setDisplayName(""); //$NON-NLS-1$
393:                    spacer.setType(Types.VARCHAR);
394:                    spacer.setFormat(""); //$NON-NLS-1$
395:                    spacer.setHorizontalAlignment("right"); //$NON-NLS-1$
396:                    spacer.setVerticalAlignment("middle"); //$NON-NLS-1$
397:                    spacer.setWidth(new BigDecimal(spacerWidth));
398:                    spacer.setWidthLocked(true);
399:                    totalWidth += spacerWidth;
400:                    spacer.setExpression("none"); //$NON-NLS-1$
401:                    spacer.setIsWidthPercent(false);
402:                    spacer.setIsDetail(true);
403:                    reportSpec.addField(spacer);
404:                }
405:                for (int i = 0; i < colHeaders.length; i++) {
406:                    // System.out.println("header [" + i + "] = " + colHeaders[i]);
407:                    Class typeClass = null;
408:                    for (int j = 0; j < resultSet.getRowCount(); j++) {
409:                        Object value = resultSet.getValueAt(j, i);
410:                        if (value != null && !value.toString().equals("")) { //$NON-NLS-1$
411:                            typeClass = value.getClass();
412:                        }
413:                    }
414:                    String columnName = colHeaders[i].toString();
415:                    Field f = new Field();
416:                    f.setName(columnName);
417:                    f.setNullString(getNullString());
418:                    if (isGroup(columnName)) {
419:                        f.setDisplayName(getGroupLabel(columnName, i));
420:                    } else if (i < displayNames.length) {
421:                        f.setDisplayName(displayNames[i]);
422:                    } else {
423:                        f.setDisplayName(columnName);
424:                    }
425:                    f.setIsWidthPercent(false);
426:                    f.setWidth(new BigDecimal(getWidth(columnName)));
427:                    f.setWidthLocked(true);
428:                    f.setIsDetail(!isGroup(columnName));
429:                    if (f.getIsDetail()) {
430:                        details.add(f);
431:                    } else {
432:                        groupsList.add(f);
433:                    }
434:                    f.setBackgroundColor("#FFFFFF"); //$NON-NLS-1$
435:                    f.setType(getType(typeClass));
436:                    if (itemHides == null || itemHides.length == 0) {
437:                        f
438:                                .setUseItemHide(getType(typeClass) == Types.NUMERIC ? false
439:                                        : true);
440:                    } else {
441:                        f.setUseItemHide(useItemHide(columnName));
442:                    }
443:                    f.setVerticalAlignment("middle"); //$NON-NLS-1$
444:                    f.setFormat(getColumnFormat(columnName));
445:                    String alignment = getColumnAlignment(columnName);
446:                    if (alignment != null) {
447:                        f.setHorizontalAlignment(alignment);
448:                    } else {
449:                        if (f.getIsDetail() && f.getType() == Types.NUMERIC) {
450:                            f.setHorizontalAlignment("right"); //$NON-NLS-1$
451:                        }
452:                    }
453:                    if (f.getIsDetail() && f.getType() == Types.NUMERIC) {
454:                        f.setExpression("sum"); //$NON-NLS-1$
455:                    } else {
456:                        f.setExpression("none"); //$NON-NLS-1$
457:                    }
458:                    f.setCalculateGroupTotals(createSubTotals);
459:                    reportSpec.addField(f);
460:                    if (spacerWidth > 0 && f.getIsDetail()) {
461:                        // spacer
462:                        Field spacer = new Field();
463:                        spacer.setName(""); //$NON-NLS-1$
464:                        spacer.setDisplayName(""); //$NON-NLS-1$
465:                        spacer.setType(Types.VARCHAR);
466:                        spacer.setFormat(""); //$NON-NLS-1$
467:                        spacer.setHorizontalAlignment("right"); //$NON-NLS-1$
468:                        spacer.setVerticalAlignment("middle"); //$NON-NLS-1$
469:                        spacer.setWidth(new BigDecimal(spacerWidth));
470:                        spacer.setWidthLocked(true);
471:                        totalWidth += spacerWidth;
472:                        spacer.setExpression("none"); //$NON-NLS-1$
473:                        spacer.setIsWidthPercent(false);
474:                        spacer.setIsDetail(true);
475:                        reportSpec.addField(spacer);
476:                    }
477:                }
478:                for (int i = 0; i < details.size(); i++) {
479:                    Field f = (Field) details.get(i);
480:                    totalWidth += f.getWidth().intValue();
481:                }
482:                if (createTotalColumn) {
483:                    Field f = new Field();
484:                    f.setName("TOTAL_COLUMN"); //$NON-NLS-1$
485:                    f.setDisplayName(totalColumnName);
486:                    f.setType(Types.NUMERIC);
487:                    f.setFormat(totalColumnFormat);
488:                    f.setHorizontalAlignment("right"); //$NON-NLS-1$
489:                    f.setVerticalAlignment("middle"); //$NON-NLS-1$
490:                    f.setWidth(new BigDecimal(totalColumnWidth));
491:                    f.setWidthLocked(true);
492:                    f.setExpression("sum"); //$NON-NLS-1$
493:                    f.setIsWidthPercent(false);
494:                    f.setIsDetail(true);
495:                    reportSpec.addField(f);
496:                    totalWidth += totalColumnWidth;
497:                    if (spacerWidth > 0) {
498:                        // spacer
499:                        Field spacer = new Field();
500:                        spacer.setName(""); //$NON-NLS-1$
501:                        spacer.setDisplayName(""); //$NON-NLS-1$
502:                        spacer.setType(Types.VARCHAR);
503:                        spacer.setFormat(""); //$NON-NLS-1$
504:                        spacer.setHorizontalAlignment("right"); //$NON-NLS-1$
505:                        spacer.setVerticalAlignment("middle"); //$NON-NLS-1$
506:                        spacer.setWidth(new BigDecimal(spacerWidth));
507:                        spacer.setWidthLocked(true);
508:                        totalWidth += spacerWidth;
509:                        spacer.setExpression("none"); //$NON-NLS-1$
510:                        spacer.setIsWidthPercent(false);
511:                        spacer.setIsDetail(true);
512:                        reportSpec.addField(spacer);
513:                    }
514:                }
515:                try {
516:                    reportSpec.setUseCustomPageFormat(true);
517:                    int width = 612;
518:                    int height = 792;
519:                    if (orientation.equalsIgnoreCase("landscape")) { //$NON-NLS-1$
520:                        width = height;
521:                        height = 612;
522:                    }
523:                    // w totalWidth
524:                    // - = ------------
525:                    // h scaledHeight
526:                    int scaledHeight = (height * totalWidth) / width;
527:                    if (orientation.equalsIgnoreCase("landscape")) { //$NON-NLS-1$
528:                        reportSpec.setCustomPageFormatHeight(totalWidth);
529:                        reportSpec.setCustomPageFormatWidth(scaledHeight);
530:                        ReportGenerationUtility.createJFreeReportXML(
531:                                reportSpec, outputStream, scaledHeight,
532:                                totalWidth, createTotalColumn, totalColumnName,
533:                                totalColumnWidth, spacerWidth);
534:                    } else {
535:                        reportSpec.setCustomPageFormatHeight(scaledHeight);
536:                        reportSpec.setCustomPageFormatWidth(totalWidth);
537:                        ReportGenerationUtility.createJFreeReportXML(
538:                                reportSpec, outputStream, totalWidth,
539:                                scaledHeight, createTotalColumn,
540:                                totalColumnName, totalColumnWidth, spacerWidth);
541:                    }
542:                } catch (Exception e) {
543:                }
544:                return new String(outputStream.toByteArray());
545:            }
546:
547:            public int getType(Class typeClass) {
548:                if (typeClass != null) {
549:                    if (typeClass.getName().equals(String.class.getName())) {
550:                        return Types.VARCHAR;
551:                    } else if (typeClass.getName().equals(
552:                            BigDecimal.class.getName())
553:                            || typeClass.getName().equals(
554:                                    Integer.class.getName())) {
555:                        return Types.NUMERIC;
556:                    } else if (typeClass.getName().equals(Date.class.getName())) {
557:                        return Types.DATE;
558:                    }
559:                }
560:                return Types.VARCHAR;
561:            }
562:
563:            public String getGroupLabel(String columnName, int index) {
564:                Object colHeaders[] = resultSet.getMetaData()
565:                        .getColumnHeaders()[0];
566:                for (int i = 0; i < colHeaders.length; i++) {
567:                    if (colHeaders[i].equals(columnName)) {
568:                        // at this point we verified the column is in the metadata, but is the index a group?
569:                        for (int j = 0; j < getGroupIndices().length; j++) {
570:                            if (i == getGroupIndices()[j]) {
571:                                return groupLabels[j];
572:                            }
573:                        }
574:                    }
575:                }
576:                return displayNames[index];
577:            }
578:
579:            public boolean isGroup(String columnName) {
580:                Object colHeaders[] = resultSet.getMetaData()
581:                        .getColumnHeaders()[0];
582:                for (int i = 0; i < colHeaders.length; i++) {
583:                    if (colHeaders[i].equals(columnName)) {
584:                        // at this point we verified the column is in the metadata, but is the index a group?
585:                        for (int j = 0; j < getGroupIndices().length; j++) {
586:                            if (i == getGroupIndices()[j]) {
587:                                return true;
588:                            }
589:                        }
590:                    }
591:                }
592:                return false;
593:            }
594:
595:            public String getColumnAlignment(String columnName) {
596:                Object colHeaders[] = resultSet.getMetaData()
597:                        .getColumnHeaders()[0];
598:                for (int i = 0; i < colHeaders.length; i++) {
599:                    if (colHeaders[i].equals(columnName)) {
600:                        try {
601:                            String alignment = getColumnAlignments()[getColumnAlignments().length - 1];
602:                            alignment = getColumnAlignments()[i];
603:                            return alignment;
604:                        } catch (Exception e) {
605:                        }
606:                    }
607:                }
608:                return null;
609:            }
610:
611:            public boolean useItemHide(String columnName) {
612:                Object colHeaders[] = resultSet.getMetaData()
613:                        .getColumnHeaders()[0];
614:                for (int i = 0; i < colHeaders.length; i++) {
615:                    if (colHeaders[i].equals(columnName)) {
616:                        boolean itemHide = getItemHides()[getItemHides().length - 1];
617:                        try {
618:                            itemHide = getItemHides()[i];
619:                        } catch (Exception e) {
620:                        }
621:                        return itemHide;
622:                    }
623:                }
624:                return false;
625:            }
626:
627:            public int getWidth(String columnName) {
628:                Object colHeaders[] = resultSet.getMetaData()
629:                        .getColumnHeaders()[0];
630:                for (int i = 0; i < colHeaders.length; i++) {
631:                    if (colHeaders[i].equals(columnName)) {
632:                        int width = getWidths()[getWidths().length - 1];
633:                        try {
634:                            width = getWidths()[i];
635:                        } catch (Exception e) {
636:                        }
637:                        return width;
638:                    }
639:                }
640:                return 0;
641:            }
642:
643:            public String getColumnFormat(String columnName) {
644:                Object colHeaders[] = resultSet.getMetaData()
645:                        .getColumnHeaders()[0];
646:                for (int i = 0; i < colHeaders.length; i++) {
647:                    if (colHeaders[i].equals(columnName)) {
648:                        String format = ""; //$NON-NLS-1$
649:                        try {
650:                            format = getFormats()[getFormats().length - 1];
651:                            format = getFormats()[i];
652:                        } catch (Exception e) {
653:                        }
654:                        return format;
655:                    }
656:                }
657:                return ""; //$NON-NLS-1$
658:            }
659:
660:            public String getResultOutputName() {
661:                Set outputs = getOutputNames();
662:                if ((outputs == null) || (outputs.size() == 0)) {
663:                    error("NO OUPUT DEFINED"); //$NON-NLS-1$
664:                    return null;
665:                }
666:                String outputName = (String) outputs.iterator().next();
667:                return outputName;
668:            }
669:
670:            public boolean init() {
671:                // nothing to do here really
672:                return true;
673:            }
674:
675:            /**
676:             * @return Returns the formats.
677:             */
678:            public String[] getFormats() {
679:                return formats;
680:            }
681:
682:            /**
683:             * @param formats
684:             *          The formats to set.
685:             */
686:            public void setFormats(String[] formats) {
687:                this .formats = formats;
688:            }
689:
690:            /**
691:             * @return Returns the groupLabels.
692:             */
693:            public String[] getGroupLabels() {
694:                return groupLabels;
695:            }
696:
697:            /**
698:             * @param groupLabels
699:             *          The groupLabels to set.
700:             */
701:            public void setGroups(String[] groupLabels) {
702:                this .groupLabels = groupLabels;
703:            }
704:
705:            /**
706:             * @return Returns the path.
707:             */
708:            public String getPath() {
709:                return path;
710:            }
711:
712:            /**
713:             * @param path
714:             *          The path to set.
715:             */
716:            public void setPath(String path) {
717:                this .path = path;
718:            }
719:
720:            /**
721:             * @return Returns the widths.
722:             */
723:            public int[] getWidths() {
724:                return widths;
725:            }
726:
727:            /**
728:             * @param widths
729:             *          The widths to set.
730:             */
731:            public void setWidths(int[] widths) {
732:                this .widths = widths;
733:            }
734:
735:            /**
736:             * @return Returns the item hides
737:             */
738:            public boolean[] getItemHides() {
739:                return itemHides;
740:            }
741:
742:            /**
743:             * @param widths
744:             *          The item hides to set.
745:             */
746:            public void setItemHides(boolean[] itemHides) {
747:                this .itemHides = itemHides;
748:            }
749:
750:            /**
751:             * @return Returns the widths.
752:             */
753:            public String[] getColumnAlignments() {
754:                return columnAlignments;
755:            }
756:
757:            /**
758:             * @param widths
759:             *          The widths to set.
760:             */
761:            public void setColumnAlignments(String[] columnAlignments) {
762:                this .columnAlignments = columnAlignments;
763:            }
764:
765:            public int[] getGroupIndices() {
766:                return groupIndices;
767:            }
768:
769:            public void setGroupIndices(int[] groupIndices) {
770:                this .groupIndices = groupIndices;
771:            }
772:
773:            public String getNullString() {
774:                return nullString;
775:            }
776:
777:            public void setNullString(String nullString) {
778:                this.nullString = nullString;
779:            }
780:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.