1 28 package net.sf.jasperreports.engine.base; 29 30 import java.io.Serializable ; 31 import java.util.Arrays ; 32 import java.util.HashSet ; 33 import java.util.Set ; 34 35 import net.sf.jasperreports.engine.JRBand; 36 import net.sf.jasperreports.engine.JRConstants; 37 import net.sf.jasperreports.engine.JRDataset; 38 import net.sf.jasperreports.engine.JRExpressionCollector; 39 import net.sf.jasperreports.engine.JRField; 40 import net.sf.jasperreports.engine.JRGroup; 41 import net.sf.jasperreports.engine.JRParameter; 42 import net.sf.jasperreports.engine.JRPropertiesMap; 43 import net.sf.jasperreports.engine.JRQuery; 44 import net.sf.jasperreports.engine.JRReport; 45 import net.sf.jasperreports.engine.JRReportFont; 46 import net.sf.jasperreports.engine.JRSortField; 47 import net.sf.jasperreports.engine.JRStyle; 48 import net.sf.jasperreports.engine.JRVariable; 49 50 51 55 public class JRBaseReport implements JRReport, Serializable 56 { 57 58 59 62 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 63 64 67 protected String name = null; 68 protected String language = LANGUAGE_JAVA; 69 protected int columnCount = 1; 70 protected byte printOrder = PRINT_ORDER_VERTICAL; 71 protected int pageWidth = 595; 72 protected int pageHeight = 842; 73 protected byte orientation = ORIENTATION_PORTRAIT; 74 protected byte whenNoDataType = WHEN_NO_DATA_TYPE_NO_PAGES; 75 protected int columnWidth = 555; 76 protected int columnSpacing = 0; 77 protected int leftMargin = 20; 78 protected int rightMargin = 20; 79 protected int topMargin = 30; 80 protected int bottomMargin = 30; 81 protected boolean isTitleNewPage = false; 82 protected boolean isSummaryNewPage = false; 83 protected boolean isFloatColumnFooter = false; 84 protected boolean ignorePagination = false; 85 86 89 protected String formatFactoryClass = null; 90 91 94 protected Set importsSet = null; 95 protected JRReportFont defaultFont = null; 96 protected JRReportFont[] fonts = null; 97 protected JRStyle defaultStyle = null; 98 protected JRStyle[] styles = null; 99 100 103 protected JRDataset mainDataset; 104 105 108 protected JRDataset[] datasets; 109 110 protected JRBand background = null; 111 protected JRBand title = null; 112 protected JRBand pageHeader = null; 113 protected JRBand columnHeader = null; 114 protected JRBand detail = null; 115 protected JRBand columnFooter = null; 116 protected JRBand pageFooter = null; 117 protected JRBand lastPageFooter = null; 118 protected JRBand summary = null; 119 120 121 124 public JRBaseReport() 125 { 126 } 127 128 134 public JRBaseReport(JRReport report, JRExpressionCollector expressionCollector) 135 { 136 137 name = report.getName(); 138 language = report.getLanguage(); 139 columnCount = report.getColumnCount(); 140 printOrder = report.getPrintOrder(); 141 pageWidth = report.getPageWidth(); 142 pageHeight = report.getPageHeight(); 143 orientation = report.getOrientation(); 144 whenNoDataType = report.getWhenNoDataType(); 145 columnWidth = report.getColumnWidth(); 146 columnSpacing = report.getColumnSpacing(); 147 leftMargin = report.getLeftMargin(); 148 rightMargin = report.getRightMargin(); 149 topMargin = report.getTopMargin(); 150 bottomMargin = report.getBottomMargin(); 151 isTitleNewPage = report.isTitleNewPage(); 152 isSummaryNewPage = report.isSummaryNewPage(); 153 isFloatColumnFooter = report.isFloatColumnFooter(); 154 ignorePagination = report.isIgnorePagination(); 155 156 formatFactoryClass = report.getFormatFactoryClass(); 157 158 159 String [] imports = report.getImports(); 160 if (imports != null && imports.length > 0) 161 { 162 importsSet = new HashSet (imports.length); 163 importsSet.addAll(Arrays.asList(imports)); 164 } 165 166 167 JRBaseObjectFactory factory = new JRBaseObjectFactory(this, expressionCollector); 168 169 170 defaultFont = factory.getReportFont(report.getDefaultFont()); 171 172 173 JRReportFont[] jrFonts = report.getFonts(); 174 if (jrFonts != null && jrFonts.length > 0) 175 { 176 fonts = new JRReportFont[jrFonts.length]; 177 for(int i = 0; i < fonts.length; i++) 178 { 179 fonts[i] = factory.getReportFont(jrFonts[i]); 180 } 181 } 182 183 184 defaultStyle = factory.getStyle(report.getDefaultStyle()); 185 186 187 JRStyle[] jrStyles = report.getStyles(); 188 if (jrStyles != null && jrStyles.length > 0) 189 { 190 styles = new JRStyle[jrStyles.length]; 191 for(int i = 0; i < styles.length; i++) 192 { 193 styles[i] = factory.getStyle(jrStyles[i]); 194 } 195 } 196 197 mainDataset = factory.getDataset(report.getMainDataset()); 198 199 JRDataset[] datasetArray = report.getDatasets(); 200 if (datasetArray != null && datasetArray.length > 0) 201 { 202 datasets = new JRDataset[datasetArray.length]; 203 for (int i = 0; i < datasets.length; i++) 204 { 205 datasets[i] = factory.getDataset(datasetArray[i]); 206 } 207 } 208 209 background = factory.getBand(report.getBackground()); 210 title = factory.getBand(report.getTitle()); 211 pageHeader = factory.getBand(report.getPageHeader()); 212 columnHeader = factory.getBand(report.getColumnHeader()); 213 detail = factory.getBand(report.getDetail()); 214 columnFooter = factory.getBand(report.getColumnFooter()); 215 pageFooter = factory.getBand(report.getPageFooter()); 216 lastPageFooter = factory.getBand(report.getLastPageFooter()); 217 summary = factory.getBand(report.getSummary()); 218 } 219 220 221 public JRBaseReport(JRReport report) 222 { 223 this(report, null); 224 } 225 226 227 230 public String getName() 231 { 232 return name; 233 } 234 235 238 public String getLanguage() 239 { 240 return language; 241 } 242 243 246 public int getColumnCount() 247 { 248 return columnCount; 249 } 250 251 254 public byte getPrintOrder() 255 { 256 return printOrder; 257 } 258 259 262 public int getPageWidth() 263 { 264 return pageWidth; 265 } 266 267 270 public int getPageHeight() 271 { 272 return pageHeight; 273 } 274 275 278 public byte getOrientation() 279 { 280 return orientation; 281 } 282 283 286 public byte getWhenNoDataType() 287 { 288 return whenNoDataType; 289 } 290 291 294 public void setWhenNoDataType(byte whenNoDataType) 295 { 296 this.whenNoDataType = whenNoDataType; 297 } 298 299 302 public int getColumnWidth() 303 { 304 return columnWidth; 305 } 306 307 310 public int getColumnSpacing() 311 { 312 return columnSpacing; 313 } 314 315 318 public int getLeftMargin() 319 { 320 return leftMargin; 321 } 322 323 326 public int getRightMargin() 327 { 328 return rightMargin; 329 } 330 331 334 public int getTopMargin() 335 { 336 return topMargin; 337 } 338 339 342 public int getBottomMargin() 343 { 344 return bottomMargin; 345 } 346 347 350 public boolean isTitleNewPage() 351 { 352 return isTitleNewPage; 353 } 354 355 358 public boolean isSummaryNewPage() 359 { 360 return isSummaryNewPage; 361 } 362 363 366 public boolean isFloatColumnFooter() 367 { 368 return isFloatColumnFooter; 369 } 370 371 374 public String getScriptletClass() 375 { 376 return mainDataset.getScriptletClass(); 377 } 378 379 382 public String getFormatFactoryClass() 383 { 384 return formatFactoryClass; 385 } 386 387 390 public String getResourceBundle() 391 { 392 return mainDataset.getResourceBundle(); 393 } 394 395 398 public String [] getPropertyNames() 399 { 400 return mainDataset.getPropertiesMap().getPropertyNames(); 401 } 402 403 406 public String getProperty(String propName) 407 { 408 return mainDataset.getPropertiesMap().getProperty(propName); 409 } 410 411 414 public void setProperty(String propName, String value) 415 { 416 mainDataset.getPropertiesMap().setProperty(propName, value); 417 } 418 419 422 public void removeProperty(String propName) 423 { 424 mainDataset.getPropertiesMap().removeProperty(propName); 425 } 426 427 430 public String [] getImports() 431 { 432 if (importsSet != null) 433 { 434 return (String [])importsSet.toArray(new String [importsSet.size()]); 435 } 436 return null; 437 } 438 439 442 public JRReportFont getDefaultFont() 443 { 444 return defaultFont; 445 } 446 447 450 public JRReportFont[] getFonts() 451 { 452 return fonts; 453 } 454 455 458 public JRStyle getDefaultStyle() 459 { 460 return defaultStyle; 461 } 462 463 466 public JRStyle[] getStyles() 467 { 468 return styles; 469 } 470 471 474 public JRParameter[] getParameters() 475 { 476 return mainDataset.getParameters(); 477 } 478 479 482 public JRQuery getQuery() 483 { 484 return mainDataset.getQuery(); 485 } 486 487 490 public JRField[] getFields() 491 { 492 return mainDataset.getFields(); 493 } 494 495 498 public JRSortField[] getSortFields() 499 { 500 return mainDataset.getSortFields(); 501 } 502 503 506 public JRVariable[] getVariables() 507 { 508 return mainDataset.getVariables(); 509 } 510 511 514 public JRGroup[] getGroups() 515 { 516 return mainDataset.getGroups(); 517 } 518 519 522 public JRBand getBackground() 523 { 524 return background; 525 } 526 527 530 public JRBand getTitle() 531 { 532 return title; 533 } 534 535 538 public JRBand getPageHeader() 539 { 540 return pageHeader; 541 } 542 543 546 public JRBand getColumnHeader() 547 { 548 return columnHeader; 549 } 550 551 554 public JRBand getDetail() 555 { 556 return detail; 557 } 558 559 562 public JRBand getColumnFooter() 563 { 564 return columnFooter; 565 } 566 567 570 public JRBand getPageFooter() 571 { 572 return pageFooter; 573 } 574 575 578 public JRBand getLastPageFooter() 579 { 580 return lastPageFooter; 581 } 582 583 586 public JRBand getSummary() 587 { 588 return summary; 589 } 590 591 592 595 public byte getWhenResourceMissingType() 596 { 597 return mainDataset.getWhenResourceMissingType(); 598 } 599 600 603 public void setWhenResourceMissingType(byte whenResourceMissingType) 604 { 605 mainDataset.setWhenResourceMissingType(whenResourceMissingType); 606 } 607 608 609 public JRDataset getMainDataset() 610 { 611 return mainDataset; 612 } 613 614 615 public JRDataset[] getDatasets() 616 { 617 return datasets; 618 } 619 620 621 public boolean isIgnorePagination() 622 { 623 return ignorePagination; 624 } 625 626 public JRPropertiesMap getPropertiesMap() 627 { 628 return mainDataset.getPropertiesMap(); 629 } 630 } 631 | Popular Tags |