1 28 package net.sf.jasperreports.engine.xml; 29 30 import java.awt.Color ; 31 import java.io.FileOutputStream ; 32 import java.io.IOException ; 33 import java.io.OutputStream ; 34 import java.io.OutputStreamWriter ; 35 import java.io.StringWriter ; 36 import java.io.Writer ; 37 import java.util.HashMap ; 38 import java.util.HashSet ; 39 import java.util.Iterator ; 40 import java.util.List ; 41 import java.util.Map ; 42 import java.util.Set ; 43 import java.util.SortedSet ; 44 45 import net.sf.jasperreports.charts.JRAreaPlot; 46 import net.sf.jasperreports.charts.JRBar3DPlot; 47 import net.sf.jasperreports.charts.JRBarPlot; 48 import net.sf.jasperreports.charts.JRBubblePlot; 49 import net.sf.jasperreports.charts.JRCandlestickPlot; 50 import net.sf.jasperreports.charts.JRCategoryDataset; 51 import net.sf.jasperreports.charts.JRCategorySeries; 52 import net.sf.jasperreports.charts.JRChartAxis; 53 import net.sf.jasperreports.charts.JRDataRange; 54 import net.sf.jasperreports.charts.JRHighLowDataset; 55 import net.sf.jasperreports.charts.JRHighLowPlot; 56 import net.sf.jasperreports.charts.JRLinePlot; 57 import net.sf.jasperreports.charts.JRMeterPlot; 58 import net.sf.jasperreports.charts.JRMultiAxisPlot; 59 import net.sf.jasperreports.charts.JRPie3DPlot; 60 import net.sf.jasperreports.charts.JRPieDataset; 61 import net.sf.jasperreports.charts.JRScatterPlot; 62 import net.sf.jasperreports.charts.JRThermometerPlot; 63 import net.sf.jasperreports.charts.JRTimePeriodDataset; 64 import net.sf.jasperreports.charts.JRTimePeriodSeries; 65 import net.sf.jasperreports.charts.JRTimeSeries; 66 import net.sf.jasperreports.charts.JRTimeSeriesDataset; 67 import net.sf.jasperreports.charts.JRTimeSeriesPlot; 68 import net.sf.jasperreports.charts.JRValueDataset; 69 import net.sf.jasperreports.charts.JRValueDisplay; 70 import net.sf.jasperreports.charts.JRXyDataset; 71 import net.sf.jasperreports.charts.JRXySeries; 72 import net.sf.jasperreports.charts.JRXyzDataset; 73 import net.sf.jasperreports.charts.JRXyzSeries; 74 import net.sf.jasperreports.charts.util.JRMeterInterval; 75 import net.sf.jasperreports.charts.xml.JRChartAxisFactory; 76 import net.sf.jasperreports.charts.xml.JRMeterPlotFactory; 77 import net.sf.jasperreports.charts.xml.JRThermometerPlotFactory; 78 import net.sf.jasperreports.crosstabs.JRCellContents; 79 import net.sf.jasperreports.crosstabs.JRCrosstab; 80 import net.sf.jasperreports.crosstabs.JRCrosstabBucket; 81 import net.sf.jasperreports.crosstabs.JRCrosstabCell; 82 import net.sf.jasperreports.crosstabs.JRCrosstabColumnGroup; 83 import net.sf.jasperreports.crosstabs.JRCrosstabDataset; 84 import net.sf.jasperreports.crosstabs.JRCrosstabMeasure; 85 import net.sf.jasperreports.crosstabs.JRCrosstabParameter; 86 import net.sf.jasperreports.crosstabs.JRCrosstabRowGroup; 87 import net.sf.jasperreports.crosstabs.design.JRDesignCrosstab; 88 import net.sf.jasperreports.crosstabs.fill.calculation.BucketDefinition; 89 import net.sf.jasperreports.crosstabs.xml.JRCellContentsFactory; 90 import net.sf.jasperreports.crosstabs.xml.JRCrosstabBucketFactory; 91 import net.sf.jasperreports.crosstabs.xml.JRCrosstabCellFactory; 92 import net.sf.jasperreports.crosstabs.xml.JRCrosstabColumnGroupFactory; 93 import net.sf.jasperreports.crosstabs.xml.JRCrosstabDatasetFactory; 94 import net.sf.jasperreports.crosstabs.xml.JRCrosstabFactory; 95 import net.sf.jasperreports.crosstabs.xml.JRCrosstabGroupFactory; 96 import net.sf.jasperreports.crosstabs.xml.JRCrosstabMeasureFactory; 97 import net.sf.jasperreports.crosstabs.xml.JRCrosstabRowGroupFactory; 98 import net.sf.jasperreports.engine.JRAnchor; 99 import net.sf.jasperreports.engine.JRBand; 100 import net.sf.jasperreports.engine.JRBox; 101 import net.sf.jasperreports.engine.JRBreak; 102 import net.sf.jasperreports.engine.JRChart; 103 import net.sf.jasperreports.engine.JRChartDataset; 104 import net.sf.jasperreports.engine.JRChartPlot; 105 import net.sf.jasperreports.engine.JRChild; 106 import net.sf.jasperreports.engine.JRConditionalStyle; 107 import net.sf.jasperreports.engine.JRDataset; 108 import net.sf.jasperreports.engine.JRDatasetParameter; 109 import net.sf.jasperreports.engine.JRDatasetRun; 110 import net.sf.jasperreports.engine.JRElement; 111 import net.sf.jasperreports.engine.JRElementDataset; 112 import net.sf.jasperreports.engine.JRElementGroup; 113 import net.sf.jasperreports.engine.JREllipse; 114 import net.sf.jasperreports.engine.JRException; 115 import net.sf.jasperreports.engine.JRExpression; 116 import net.sf.jasperreports.engine.JRField; 117 import net.sf.jasperreports.engine.JRFont; 118 import net.sf.jasperreports.engine.JRFrame; 119 import net.sf.jasperreports.engine.JRGraphicElement; 120 import net.sf.jasperreports.engine.JRGroup; 121 import net.sf.jasperreports.engine.JRHyperlink; 122 import net.sf.jasperreports.engine.JRHyperlinkParameter; 123 import net.sf.jasperreports.engine.JRImage; 124 import net.sf.jasperreports.engine.JRLine; 125 import net.sf.jasperreports.engine.JRParameter; 126 import net.sf.jasperreports.engine.JRPropertiesMap; 127 import net.sf.jasperreports.engine.JRQuery; 128 import net.sf.jasperreports.engine.JRRectangle; 129 import net.sf.jasperreports.engine.JRReport; 130 import net.sf.jasperreports.engine.JRReportFont; 131 import net.sf.jasperreports.engine.JRRuntimeException; 132 import net.sf.jasperreports.engine.JRSortField; 133 import net.sf.jasperreports.engine.JRStaticText; 134 import net.sf.jasperreports.engine.JRStyle; 135 import net.sf.jasperreports.engine.JRSubreport; 136 import net.sf.jasperreports.engine.JRSubreportParameter; 137 import net.sf.jasperreports.engine.JRSubreportReturnValue; 138 import net.sf.jasperreports.engine.JRTextElement; 139 import net.sf.jasperreports.engine.JRTextField; 140 import net.sf.jasperreports.engine.JRVariable; 141 import net.sf.jasperreports.engine.JRChartPlot.JRSeriesColor; 142 import net.sf.jasperreports.engine.query.JRJdbcQueryExecuterFactory; 143 import net.sf.jasperreports.engine.util.JRXmlWriteHelper; 144 import net.sf.jasperreports.engine.xml.JRChartPlotFactory.JRSeriesColorFactory; 145 146 import org.jfree.chart.plot.PlotOrientation; 147 import org.jfree.chart.renderer.category.BarRenderer3D; 148 import org.jfree.data.time.Day; 149 150 151 156 public class JRXmlWriter 157 { 158 159 160 163 private JRReport report = null; 164 private String encoding = null; 165 166 169 private JRXmlWriteHelper writer; 170 private Map fontsMap = new HashMap (); 171 private Map stylesMap = new HashMap (); 172 173 174 177 protected JRXmlWriter(JRReport report, String encoding) 178 { 179 this.report = report; 180 this.encoding = encoding; 181 } 182 183 184 187 public static String writeReport(JRReport report, String encoding) 188 { 189 JRXmlWriter writer = new JRXmlWriter(report, encoding); 190 StringWriter buffer = new StringWriter (); 191 try 192 { 193 writer.writeReport(buffer); 194 } 195 catch (IOException e) 196 { 197 throw new JRRuntimeException("Error writing report design.", e); 199 } 200 return buffer.toString(); 201 } 202 203 204 207 public static void writeReport( 208 JRReport report, 209 String destFileName, 210 String encoding 211 ) throws JRException 212 { 213 FileOutputStream fos = null; 214 215 try 216 { 217 fos = new FileOutputStream (destFileName); 218 Writer out = new OutputStreamWriter (fos, encoding); 219 JRXmlWriter writer = new JRXmlWriter(report, encoding); 220 writer.writeReport(out); 221 } 222 catch (IOException e) 223 { 224 throw new JRException("Error writing to file : " + destFileName, e); 225 } 226 finally 227 { 228 if (fos != null) 229 { 230 try 231 { 232 fos.close(); 233 } 234 catch(IOException e) 235 { 236 } 237 } 238 } 239 } 240 241 242 245 public static void writeReport( 246 JRReport report, 247 OutputStream outputStream, 248 String encoding 249 ) throws JRException 250 { 251 try 252 { 253 Writer out = new OutputStreamWriter (outputStream, encoding); 254 JRXmlWriter writer = new JRXmlWriter(report, encoding); 255 writer.writeReport(out); 256 } 257 catch (Exception e) 258 { 259 throw new JRException("Error writing to OutputStream : " + report.getName(), e); 260 } 261 } 262 263 264 267 protected void writeReport(Writer out) throws IOException 268 { 269 writer = new JRXmlWriteHelper(out); 270 271 writer.writeProlog(encoding); 272 writer.writePublicDoctype("jasperReport", "-//JasperReports//DTD Report Design//EN", "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"); 273 274 writer.startElement(JasperDesignFactory.ELEMENT_jasperReport); 275 writer.addEncodedAttribute(JasperDesignFactory.ATTRIBUTE_name, report.getName()); 276 writer.addEncodedAttribute(JasperDesignFactory.ATTRIBUTE_language, report.getLanguage(), JRReport.LANGUAGE_JAVA); 277 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_columnCount, report.getColumnCount(), 1); 278 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_printOrder, report.getPrintOrder(), JRXmlConstants.getPrintOrderMap(), JRReport.PRINT_ORDER_VERTICAL); 279 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_pageWidth, report.getPageWidth()); 280 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_pageHeight, report.getPageHeight()); 281 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_orientation, report.getOrientation(), JRXmlConstants.getOrientationMap(), JRReport.ORIENTATION_PORTRAIT); 282 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_whenNoDataType, report.getWhenNoDataType(), JRXmlConstants.getWhenNoDataTypeMap(), JRReport.WHEN_NO_DATA_TYPE_NO_PAGES); 283 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_columnWidth, report.getColumnWidth()); 284 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_columnSpacing, report.getColumnSpacing(), 0); 285 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_leftMargin, report.getLeftMargin()); 286 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_rightMargin, report.getRightMargin()); 287 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_topMargin, report.getTopMargin()); 288 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_bottomMargin, report.getBottomMargin()); 289 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_isTitleNewPage, report.isTitleNewPage(), false); 290 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_isSummaryNewPage, report.isSummaryNewPage(), false); 291 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_isFloatColumnFooter, report.isFloatColumnFooter(), false); 292 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_scriptletClass, report.getScriptletClass()); 293 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_formatFactoryClass, report.getFormatFactoryClass()); 294 writer.addEncodedAttribute(JasperDesignFactory.ATTRIBUTE_resourceBundle, report.getResourceBundle()); 295 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_whenResourceMissingType, report.getWhenResourceMissingType(), JRXmlConstants.getWhenResourceMissingTypeMap(), JRReport.WHEN_RESOURCE_MISSING_TYPE_NULL); 296 writer.addAttribute(JasperDesignFactory.ATTRIBUTE_isIgnorePagination, report.isIgnorePagination(), false); 297 298 writeProperties(report.getPropertiesMap()); 299 300 301 String [] imports = report.getImports(); 302 if (imports != null && imports.length > 0) 303 { 304 for(int i = 0; i < imports.length; i++) 305 { 306 String value = imports[i]; 307 if (value != null) 308 { 309 writer.startElement("import"); 310 writer.addEncodedAttribute("value", value); 311 writer.closeElement(); 312 } 313 } 314 } 315 316 317 JRReportFont[] fonts = report.getFonts(); 318 if (fonts != null && fonts.length > 0) 319 { 320 for(int i = 0; i < fonts.length; i++) 321 { 322 fontsMap.put(fonts[i].getName(), fonts[i]); 323 writeReportFont(fonts[i]); 324 } 325 } 326 327 328 JRStyle[] styles = report.getStyles(); 329 if (styles != null && styles.length > 0) 330 { 331 for(int i = 0; i < styles.length; i++) 332 { 333 stylesMap.put(styles[i].getName(), styles[i]); 334 writeStyle(styles[i]); 335 } 336 } 337 338 JRDataset[] datasets = report.getDatasets(); 339 if (datasets != null && datasets.length > 0) 340 { 341 for (int i = 0; i < datasets.length; ++i) 342 { 343 writeDataset(datasets[i]); 344 } 345 } 346 347 writeDatasetContents(report.getMainDataset()); 348 349 if (report.getBackground() != null) 350 { 351 writer.startElement("background"); 352 writeBand(report.getBackground()); 353 writer.closeElement(); 354 } 355 356 if (report.getTitle() != null) 357 { 358 writer.startElement("title"); 359 writeBand(report.getTitle()); 360 writer.closeElement(); 361 } 362 363 if (report.getPageHeader() != null) 364 { 365 writer.startElement("pageHeader"); 366 writeBand(report.getPageHeader()); 367 writer.closeElement(); 368 } 369 370 if (report.getColumnHeader() != null) 371 { 372 writer.startElement("columnHeader"); 373 writeBand(report.getColumnHeader()); 374 writer.closeElement(); 375 } 376 377 if (report.getDetail() != null) 378 { 379 writer.startElement("detail"); 380 writeBand(report.getDetail()); 381 writer.closeElement(); 382 } 383 384 if (report.getColumnFooter() != null) 385 { 386 writer.startElement("columnFooter"); 387 writeBand(report.getColumnFooter()); 388 writer.closeElement(); 389 } 390 391 if (report.getPageFooter() != null) 392 { 393 writer.startElement("pageFooter"); 394 writeBand(report.getPageFooter()); 395 writer.closeElement(); 396 } 397 398 if (report.getLastPageFooter() != null) 399 { 400 writer.startElement("lastPageFooter"); 401 writeBand(report.getLastPageFooter()); 402 writer.closeElement(); 403 } 404 405 if (report.getSummary() != null) 406 { 407 writer.startElement("summary"); 408 writeBand(report.getSummary()); 409 writer.closeElement(); 410 } 411 412 writer.closeElement(); 413 414 out.flush(); 415 } 416 417 418 private void writeProperties(JRPropertiesMap propertiesMap) throws IOException 419 { 420 String [] propertyNames = propertiesMap.getPropertyNames(); 421 if (propertyNames != null && propertyNames.length > 0) 422 { 423 for(int i = 0; i < propertyNames.length; i++) 424 { 425 String value = propertiesMap.getProperty(propertyNames[i]); 426 if (value != null) 427 { 428 writer.startElement("property"); 429 writer.addEncodedAttribute("name", propertyNames[i]); 430 writer.addEncodedAttribute("value", value); 431 writer.closeElement(); 432 } 433 } 434 } 435 } 436 437 438 441 private void writeReportFont(JRReportFont font) throws IOException 442 { 443 writer.startElement("reportFont"); 444 writer.addEncodedAttribute("name", font.getName()); 445 writer.addAttribute("isDefault", font.isDefault()); 446 writer.addEncodedAttribute("fontName", font.getFontName()); 447 writer.addAttribute("size", font.getFontSize()); 448 writer.addAttribute("isBold", font.isBold()); 449 writer.addAttribute("isItalic", font.isItalic()); 450 writer.addAttribute("isUnderline", font.isUnderline()); 451 writer.addAttribute("isStrikeThrough", font.isStrikeThrough()); 452 writer.addEncodedAttribute("pdfFontName", font.getPdfFontName()); 453 writer.addEncodedAttribute("pdfEncoding", font.getPdfEncoding()); 454 writer.addAttribute("isPdfEmbedded", font.isPdfEmbedded()); 455 writer.closeElement(); 456 } 457 458 459 462 private void writeStyle(JRStyle style) throws IOException 463 { 464 writer.startElement("style"); 465 writer.addEncodedAttribute("name", style.getName()); 466 writer.addAttribute("isDefault", style.isDefault()); 467 468 if (style.getStyle() != null) 469 { 470 JRStyle baseStyle = 471 (JRStyle)stylesMap.get( 472 style.getStyle().getName() 473 ); 474 if(baseStyle != null) 475 { 476 writer.addEncodedAttribute("style", style.getStyle().getName()); 477 } 478 else 479 { 480 throw 481 new JRRuntimeException( 482 "Referenced report style not found : " 483 + style.getStyle().getName() 484 ); 485 } 486 } 487 488 writer.addAttribute("mode", style.getOwnMode(), JRXmlConstants.getModeMap()); 489 writer.addAttribute("forecolor", style.getOwnForecolor()); 490 writer.addAttribute("backcolor", style.getOwnBackcolor()); 491 writer.addAttribute("pen", style.getOwnPen(), JRXmlConstants.getPenMap()); 492 writer.addAttribute("fill", style.getOwnFill(), JRXmlConstants.getFillMap()); 493 writer.addAttribute("radius", style.getOwnRadius()); 494 writer.addAttribute("scaleImage", style.getOwnScaleImage(), JRXmlConstants.getScaleImageMap()); 495 writer.addAttribute("hAlign", style.getOwnHorizontalAlignment(), JRXmlConstants.getHorizontalAlignMap()); 496 writer.addAttribute("vAlign", style.getOwnVerticalAlignment(), JRXmlConstants.getVerticalAlignMap()); 497 writer.addAttribute("rotation", style.getOwnRotation(), JRXmlConstants.getRotationMap()); 498 writer.addAttribute("lineSpacing", style.getOwnLineSpacing(), JRXmlConstants.getLineSpacingMap()); 499 writer.addAttribute("isStyledText", style.isOwnStyledText()); 500 writer.addEncodedAttribute("pattern", style.getOwnPattern()); 501 writer.addAttribute("isBlankWhenNull", style.isOwnBlankWhenNull()); 502 503 writer.addAttribute("border", style.getOwnBorder(), JRXmlConstants.getPenMap()); 504 writer.addAttribute("borderColor", style.getOwnBorderColor()); 505 writer.addAttribute("padding", style.getOwnPadding()); 506 507 writer.addAttribute("topBorder", style.getOwnTopBorder(), JRXmlConstants.getPenMap()); 508 writer.addAttribute("topBorderColor", style.getOwnTopBorderColor()); 509 writer.addAttribute("topPadding", style.getOwnTopPadding()); 510 511 writer.addAttribute("leftBorder", style.getOwnLeftBorder(), JRXmlConstants.getPenMap()); 512 writer.addAttribute("leftBorderColor", style.getOwnLeftBorderColor()); 513 writer.addAttribute("leftPadding", style.getOwnLeftPadding()); 514 515 writer.addAttribute("bottomBorder", style.getOwnBottomBorder(), JRXmlConstants.getPenMap()); 516 writer.addAttribute("bottomBorderColor", style.getOwnBottomBorderColor()); 517 writer.addAttribute("bottomPadding", style.getOwnBottomPadding()); 518 519 writer.addAttribute("rightBorder", style.getOwnRightBorder(), JRXmlConstants.getPenMap()); 520 writer.addAttribute("rightBorderColor", style.getOwnRightBorderColor()); 521 writer.addAttribute("rightPadding", style.getOwnRightPadding()); 522 523 writer.addEncodedAttribute("fontName", style.getOwnFontName()); 524 writer.addAttribute("fontSize", style.getOwnFontSize()); 525 writer.addAttribute("isBold", style.isOwnBold()); 526 writer.addAttribute("isItalic", style.isOwnItalic()); 527 writer.addAttribute("isUnderline", style.isOwnUnderline()); 528 writer.addAttribute("isStrikeThrough", style.isOwnStrikeThrough()); 529 writer.addEncodedAttribute("pdfFontName", style.getOwnPdfFontName()); 530 writer.addEncodedAttribute("pdfEncoding", style.getOwnPdfEncoding()); 531 writer.addAttribute("isPdfEmbedded", style.isOwnPdfEmbedded()); 532 533 JRConditionalStyle[] conditionalStyles = style.getConditionalStyles(); 534 if (!(style instanceof JRConditionalStyle) && conditionalStyles != null) { 535 for (int i = 0; i < conditionalStyles.length; i++) 536 writeConditionalStyle(conditionalStyles[i]); 537 } 538 539 writer.closeElement(); 540 } 541 542 543 546 private void writeConditionalStyle(JRConditionalStyle style) throws IOException 547 { 548 writer.startElement("conditionalStyle"); 549 writer.writeExpression("conditionExpression", style.getConditionExpression(), false); 550 writeStyle(style); 551 writer.closeElement(); 552 } 553 554 555 558 private void writeParameter(JRParameter parameter) throws IOException 559 { 560 writer.startElement("parameter"); 561 writer.addEncodedAttribute("name", parameter.getName()); 562 writer.addAttribute("class", parameter.getValueClassName()); 563 writer.addAttribute("isForPrompting", parameter.isForPrompting(), true); 564 565 writer.writeCDATAElement("parameterDescription", parameter.getDescription()); 566 writer.writeExpression("defaultValueExpression", parameter.getDefaultValueExpression(), false); 567 568 writer.closeElement(); 569 } 570 571 572 575 private void writeQuery(JRQuery query) throws IOException 576 { 577 writer.startElement("queryString"); 578 writer.addEncodedAttribute(JRQueryFactory.ATTRIBUTE_language, query.getLanguage(), JRJdbcQueryExecuterFactory.QUERY_LANGUAGE_SQL); 579 writer.writeCDATA(query.getText()); 580 writer.closeElement(); 581 } 582 583 584 587 private void writeField(JRField field) throws IOException 588 { 589 writer.startElement("field"); 590 writer.addEncodedAttribute("name", field.getName()); 591 writer.addAttribute("class", field.getValueClassName()); 592 593 writer.writeCDATAElement("fieldDescription", field.getDescription()); 594 595 writer.closeElement(); 596 } 597 598 599 602 private void writeSortField(JRSortField sortField) throws IOException 603 { 604 writer.startElement("sortField"); 605 writer.addEncodedAttribute("name", sortField.getName()); 606 writer.addAttribute("order", sortField.getOrder(), JRXmlConstants.getSortOrderMap(), JRSortField.SORT_ORDER_ASCENDING); 607 writer.closeElement(); 608 } 609 610 611 614 private void writeVariable(JRVariable variable) throws IOException 615 { 616 writer.startElement("variable"); 617 writer.addEncodedAttribute("name", variable.getName()); 618 writer.addAttribute("class", variable.getValueClassName()); 619 writer.addAttribute("resetType", variable.getResetType(), JRXmlConstants.getResetTypeMap(), JRVariable.RESET_TYPE_REPORT); 620 if (variable.getResetGroup() != null) 621 { 622 writer.addEncodedAttribute("resetGroup", variable.getResetGroup().getName()); 623 } 624 writer.addAttribute("incrementType", variable.getIncrementType(), JRXmlConstants.getResetTypeMap(), JRVariable.RESET_TYPE_NONE); 625 if (variable.getIncrementGroup() != null) 626 { 627 writer.addEncodedAttribute("incrementGroup", variable.getIncrementGroup().getName()); 628 } 629 writer.addAttribute("calculation", variable.getCalculation(), JRXmlConstants.getCalculationMap(), JRVariable.CALCULATION_NOTHING); 630 writer.addAttribute("incrementerFactoryClass", variable.getIncrementerFactoryClassName()); 631 632 writer.writeExpression("variableExpression", variable.getExpression(), false); 633 writer.writeExpression("initialValueExpression", variable.getInitialValueExpression(), false); 634 635 writer.closeElement(); 636 } 637 638 639 642 private void writeGroup(JRGroup group) throws IOException 643 { 644 writer.startElement("group"); 645 writer.addEncodedAttribute("name", group.getName()); 646 writer.addAttribute("isStartNewColumn", group.isStartNewColumn(), false); 647 writer.addAttribute("isStartNewPage", group.isStartNewPage(), false); 648 writer.addAttribute("isResetPageNumber", group.isResetPageNumber(), false); 649 writer.addAttribute("isReprintHeaderOnEachPage", group.isReprintHeaderOnEachPage(), false); 650 writer.addAttributePositive("minHeightToStartNewPage", group.getMinHeightToStartNewPage()); 651 652 writer.writeExpression("groupExpression", group.getExpression(), false); 653 654 if (group.getGroupHeader() != null) 655 { 656 writer.startElement("groupHeader"); 657 writeBand(group.getGroupHeader()); 658 writer.closeElement(); 659 } 660 661 if (group.getGroupFooter() != null) 662 { 663 writer.startElement("groupFooter"); 664 writeBand(group.getGroupFooter()); 665 writer.closeElement(); 666 } 667 668 writer.closeElement(); 669 } 670 671 672 675 private void writeBand(JRBand band) throws IOException 676 { 677 writer.startElement("band"); 678 writer.addAttributePositive("height", band.getHeight()); 679 writer.addAttribute("isSplitAllowed", band.isSplitAllowed(), true); 680 681 writer.writeExpression("printWhenExpression", band.getPrintWhenExpression(), false); 682 683 684 List children = band.getChildren(); 685 if (children != null && children.size() > 0) 686 { 687 for(int i = 0; i < children.size(); i++) 688 { 689 ((JRChild)children.get(i)).writeXml(this); 690 } 691 } 692 693 writer.closeElement(); 694 } 695 696 697 700 public void writeElementGroup(JRElementGroup elementGroup) throws IOException 701 { 702 writer.startElement("elementGroup"); 703 704 705 List children = elementGroup.getChildren(); 706 if (children != null && children.size() > 0) 707 { 708 for(int i = 0; i < children.size(); i++) 709 { 710 JRChild child = (JRChild)children.get(i); 711 child.writeXml(this); 712 } 713 } 714 715 writer.closeElement(); 716 } 717 718 719 722 public void writeBreak(JRBreak breakElement) throws IOException 723 { 724 writer.startElement("break"); 725 writer.addAttribute("type", breakElement.getType(), JRXmlConstants.getBreakTypeMap(), JRBreak.TYPE_PAGE); 726 727 writeReportElement(breakElement); 728 729 writer.closeElement(); 730 } 731 732 733 736 public void writeLine(JRLine line) throws IOException 737 { 738 writer.startElement("line"); 739 writer.addAttribute("direction", line.getDirection(), JRXmlConstants.getDirectionMap(), JRLine.DIRECTION_TOP_DOWN); 740 741 writeReportElement(line); 742 writeGraphicElement(line); 743 744 writer.closeElement(); 745 } 746 747 748 751 private void writeReportElement(JRElement element) throws IOException 752 { 753 writer.startElement("reportElement"); 754 writer.addEncodedAttribute("key", element.getKey()); 755 JRStyle style = element.getStyle(); 756 if (style != null) 757 { 758 writer.addEncodedAttribute("style", style.getName()); 759 } 760 writer.addAttribute("positionType", element.getPositionType(), JRXmlConstants.getPositionTypeMap(), JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP); 761 writer.addAttribute("stretchType", element.getStretchType(), JRXmlConstants.getStretchTypeMap(), JRElement.STRETCH_TYPE_NO_STRETCH); 762 writer.addAttribute("isPrintRepeatedValues", element.isPrintRepeatedValues(), true); 763 writer.addAttribute("mode", element.getOwnMode(), JRXmlConstants.getModeMap()); 764 765 writer.addAttribute("x", element.getX()); 766 writer.addAttribute("y", element.getY()); 767 writer.addAttribute("width", element.getWidth()); 768 writer.addAttribute("height", element.getHeight()); 769 writer.addAttribute("isRemoveLineWhenBlank", element.isRemoveLineWhenBlank(), false); 770 writer.addAttribute("isPrintInFirstWholeBand", element.isPrintInFirstWholeBand(), false); 771 writer.addAttribute("isPrintWhenDetailOverflows", element.isPrintWhenDetailOverflows(), false); 772 773 if (element.getPrintWhenGroupChanges() != null) 774 { 775 writer.addEncodedAttribute("printWhenGroupChanges", element.getPrintWhenGroupChanges().getName()); 776 } 777 778 writer.addAttribute("forecolor", element.getOwnForecolor()); 779 writer.addAttribute("backcolor", element.getOwnBackcolor()); 780 781 writer.writeExpression("printWhenExpression", element.getPrintWhenExpression(), false); 782 writer.closeElement(); 783 } 784 785 786 789 private void writeGraphicElement(JRGraphicElement element) throws IOException 790 { 791 writer.startElement("graphicElement"); 792 writer.addAttribute("pen", element.getOwnPen(), JRXmlConstants.getPenMap()); 793 writer.addAttribute("fill", element.getOwnFill(), JRXmlConstants.getFillMap()); 794 writer.closeElement(); 795 } 796 797 798 801 public void writeRectangle(JRRectangle rectangle) throws IOException 802 { 803 writer.startElement("rectangle"); 804 writer.addAttribute("radius", rectangle.getOwnRadius()); 805 806 writeReportElement(rectangle); 807 writeGraphicElement(rectangle); 808 809 writer.closeElement(); 810 } 811 812 813 816 public void writeEllipse(JREllipse ellipse) throws IOException 817 { 818 writer.startElement("ellipse"); 819 820 writeReportElement(ellipse); 821 writeGraphicElement(ellipse); 822 823 writer.closeElement(); 824 } 825 826 827 830 public void writeImage(JRImage image) throws IOException 831 { 832 writer.startElement("image"); 833 writer.addAttribute("scaleImage", image.getOwnScaleImage(), JRXmlConstants.getScaleImageMap()); 834 writer.addAttribute("hAlign", image.getOwnHorizontalAlignment(), JRXmlConstants.getHorizontalAlignMap()); 835 writer.addAttribute("vAlign", image.getOwnVerticalAlignment(), JRXmlConstants.getVerticalAlignMap()); 836 writer.addAttribute("isUsingCache", image.isOwnUsingCache()); 837 writer.addAttribute("isLazy", image.isLazy(), false); 838 writer.addAttribute("onErrorType", image.getOnErrorType(), JRXmlConstants.getOnErrorTypeMap(), JRImage.ON_ERROR_TYPE_ERROR); 839 writer.addAttribute("evaluationTime", image.getEvaluationTime(), JRXmlConstants.getEvaluationTimeMap(), JRExpression.EVALUATION_TIME_NOW); 840 841 if (image.getEvaluationGroup() != null) 842 { 843 writer.addEncodedAttribute("evaluationGroup", image.getEvaluationGroup().getName()); 844 } 845 846 writer.addEncodedAttribute("hyperlinkType", image.getLinkType()); 847 writer.addAttribute("hyperlinkTarget", image.getHyperlinkTarget(), JRXmlConstants.getHyperlinkTargetMap(), JRHyperlink.HYPERLINK_TARGET_SELF); 848 writer.addAttribute("bookmarkLevel", image.getBookmarkLevel(), JRAnchor.NO_BOOKMARK); 849 850 writeReportElement(image); 851 writeBox(image); 852 writeGraphicElement(image); 853 854 856 writer.writeExpression("imageExpression", image.getExpression(), true); 857 writer.writeExpression("anchorNameExpression", image.getAnchorNameExpression(), false); 858 writer.writeExpression("hyperlinkReferenceExpression", image.getHyperlinkReferenceExpression(), false); 859 writer.writeExpression("hyperlinkAnchorExpression", image.getHyperlinkAnchorExpression(), false); 860 writer.writeExpression("hyperlinkPageExpression", image.getHyperlinkPageExpression(), false); 861 writer.writeExpression(JRHyperlinkFactory.ELEMENT_hyperlinkTooltipExpression, image.getHyperlinkTooltipExpression(), false); 862 writeHyperlinkParameters(image.getHyperlinkParameters()); 863 864 writer.closeElement(); 865 } 866 867 868 871 private void writeBox(JRBox box) throws IOException 872 { 873 if (box != null) 874 { 875 writer.startElement("box"); 876 writer.addAttribute("border", box.getOwnBorder(), JRXmlConstants.getPenMap()); 877 writer.addAttribute("borderColor", box.getOwnBorderColor()); 878 writer.addAttribute("padding", box.getOwnPadding()); 879 880 writer.addAttribute("topBorder", box.getOwnTopBorder(), JRXmlConstants.getPenMap()); 881 writer.addAttribute("topBorderColor", box.getOwnTopBorderColor()); 882 writer.addAttribute("topPadding", box.getOwnTopPadding()); 883 884 writer.addAttribute("leftBorder", box.getOwnLeftBorder(), JRXmlConstants.getPenMap()); 885 writer.addAttribute("leftBorderColor", box.getOwnLeftBorderColor()); 886 writer.addAttribute("leftPadding", box.getOwnLeftPadding()); 887 888 writer.addAttribute("bottomBorder", box.getOwnBottomBorder(), JRXmlConstants.getPenMap()); 889 writer.addAttribute("bottomBorderColor", box.getOwnBottomBorderColor()); 890 writer.addAttribute("bottomPadding", box.getOwnBottomPadding()); 891 892 writer.addAttribute("rightBorder", box.getOwnRightBorder(), JRXmlConstants.getPenMap()); 893 writer.addAttribute("rightBorderColor", box.getOwnRightBorderColor()); 894 writer.addAttribute("rightPadding", box.getOwnRightPadding()); 895 896 writer.closeElement(true); 897 } 898 } 899 900 901 904 public void writeStaticText(JRStaticText staticText) throws IOException 905 { 906 writer.startElement("staticText"); 907 908 writeReportElement(staticText); 909 writeBox(staticText); 910 writeTextElement(staticText); 911 912 writer.writeCDATAElement("text", staticText.getText()); 913 914 writer.closeElement(); 915 } 916 917 918 921 private void writeTextElement(JRTextElement textElement) throws IOException 922 { 923 writer.startElement("textElement"); 924 writer.addAttribute("textAlignment", textElement.getOwnHorizontalAlignment(), JRXmlConstants.getHorizontalAlignMap()); 925 writer.addAttribute("verticalAlignment", textElement.getOwnVerticalAlignment(), JRXmlConstants.getVerticalAlignMap()); 926 writer.addAttribute("rotation", textElement.getOwnRotation(), JRXmlConstants.getRotationMap()); 927 writer.addAttribute("lineSpacing", textElement.getOwnLineSpacing(), JRXmlConstants.getLineSpacingMap()); 928 writer.addAttribute("isStyledText", textElement.isOwnStyledText()); 929 930 writeFont(textElement); 931 932 writer.closeElement(); 933 } 934 935 936 939 private void writeFont(JRFont font) throws IOException 940 { 941 if (font != null) 942 { 943 writer.startElement("font"); 944 if (font.getReportFont() != null) 945 { 946 JRFont baseFont = 947 (JRFont)fontsMap.get( 948 font.getReportFont().getName() 949 ); 950 if(baseFont != null) 951 { 952 writer.addEncodedAttribute("reportFont", font.getReportFont().getName()); 953 } 954 else 955 { 956 throw 957 new JRRuntimeException( 958 "Referenced report font not found : " 959 + font.getReportFont().getName() 960 ); 961 } 962 } 963 964 writer.addEncodedAttribute("fontName", font.getOwnFontName()); 965 writer.addAttribute("size", font.getOwnFontSize()); 966 writer.addAttribute("isBold", font.isOwnBold()); 967 writer.addAttribute("isItalic", font.isOwnItalic()); 968 writer.addAttribute("isUnderline", font.isOwnUnderline()); 969 writer.addAttribute("isStrikeThrough", font.isOwnStrikeThrough()); 970 writer.addEncodedAttribute("pdfFontName", font.getOwnPdfFontName()); 971 writer.addEncodedAttribute("pdfEncoding", font.getOwnPdfEncoding()); 972 writer.addAttribute("isPdfEmbedded", font.isOwnPdfEmbedded()); 973 writer.closeElement(true); 974 } 975 } 976 977 978 981 public void writeTextField(JRTextField textField) throws IOException 982 { 983 writer.startElement("textField"); 984 writer.addAttribute("isStretchWithOverflow", textField.isStretchWithOverflow(), false); 985 writer.addAttribute("evaluationTime", textField.getEvaluationTime(), JRXmlConstants.getEvaluationTimeMap(), JRExpression.EVALUATION_TIME_NOW); 986 987 if (textField.getEvaluationGroup() != null) 988 { 989 writer.addEncodedAttribute("evaluationGroup", textField.getEvaluationGroup().getName()); 990 } 991 992 writer.addEncodedAttribute("pattern", textField.getOwnPattern()); 993 writer.addAttribute("isBlankWhenNull", textField.isOwnBlankWhenNull()); 994 995 writer.addEncodedAttribute("hyperlinkType", textField.getLinkType()); 996 writer.addAttribute("hyperlinkTarget", textField.getHyperlinkTarget(), JRXmlConstants.getHyperlinkTargetMap(), JRHyperlink.HYPERLINK_TARGET_SELF); 997 writer.addAttribute("bookmarkLevel", textField.getBookmarkLevel(), JRAnchor.NO_BOOKMARK); 998 999 writeReportElement(textField); 1000 writeBox(textField); 1001 writeTextElement(textField); 1002 1003 writer.writeExpression("textFieldExpression", textField.getExpression(), true); 1004 1005 writer.writeExpression("anchorNameExpression", textField.getAnchorNameExpression(), false); 1006 writer.writeExpression("hyperlinkReferenceExpression", textField.getHyperlinkReferenceExpression(), false); 1007 writer.writeExpression("hyperlinkAnchorExpression", textField.getHyperlinkAnchorExpression(), false); 1008 writer.writeExpression("hyperlinkPageExpression", textField.getHyperlinkPageExpression(), false); 1009 writer.writeExpression(JRHyperlinkFactory.ELEMENT_hyperlinkTooltipExpression, textField.getHyperlinkTooltipExpression(), false); 1010 writeHyperlinkParameters(textField.getHyperlinkParameters()); 1011 1012 writer.closeElement(); 1013 } 1014 1015 1016 1019 public void writeSubreport(JRSubreport subreport) throws IOException 1020 { 1021 writer.startElement("subreport"); 1022 writer.addAttribute("isUsingCache", subreport.isOwnUsingCache()); 1023 1024 writeReportElement(subreport); 1025 1026 writer.writeExpression("parametersMapExpression", subreport.getParametersMapExpression(), false); 1027 1028 1029 JRSubreportParameter[] parameters = subreport.getParameters(); 1030 if (parameters != null && parameters.length > 0) 1031 { 1032 for(int i = 0; i < parameters.length; i++) 1033 { 1034 writeSubreportParameter(parameters[i]); 1035 } 1036 } 1037 1038 writer.writeExpression("connectionExpression", subreport.getConnectionExpression(), false); 1039 writer.writeExpression("dataSourceExpression", subreport.getDataSourceExpression(), false); 1040 1041 JRSubreportReturnValue[] returnValues = subreport.getReturnValues(); 1042 if (returnValues != null && returnValues.length > 0) 1043 { 1044 for(int i = 0; i < returnValues.length; i++) 1045 { 1046 writeSubreportReturnValue(returnValues[i]); 1047 } 1048 } 1049 1050 writer.writeExpression("subreportExpression", subreport.getExpression(), true); 1051 1052 writer.closeElement(); 1053 } 1054 1055 1056 1059 private void writeSubreportParameter(JRSubreportParameter subreportParameter) throws IOException 1060 { 1061 writer.startElement("subreportParameter"); 1062 writer.addEncodedAttribute("name", subreportParameter.getName()); 1063 1064 writer.writeExpression("subreportParameterExpression", subreportParameter.getExpression(), false); 1065 1066 writer.closeElement(); 1067 } 1068 1069 1070 private void writeDatasetParameter(JRDatasetParameter datasetParameter) throws IOException 1071 { 1072 writer.startElement(JRDatasetRunParameterFactory.ELEMENT_datasetParameter); 1073 writer.addEncodedAttribute(JRDatasetRunParameterFactory.ATTRIBUTE_name, datasetParameter.getName()); 1074 1075 writer.writeExpression(JRDatasetRunParameterExpressionFactory.ELEMENT_datasetParameterExpression, datasetParameter.getExpression(), false); 1076 1077 writer.closeElement(); 1078 } 1079 1080 1081 1084 private void writeChart(JRChart chart) throws IOException 1085 { 1086 writer.startElement("chart"); 1087 writer.addAttribute("isShowLegend", chart.isShowLegend(), true); 1088 writer.addAttribute("evaluationTime", chart.getEvaluationTime(), JRXmlConstants.getEvaluationTimeMap(), JRExpression.EVALUATION_TIME_NOW); 1089 1090 if (chart.getEvaluationTime() == JRExpression.EVALUATION_TIME_GROUP) 1091 { 1092 writer.addEncodedAttribute("evaluationGroup", chart.getEvaluationGroup().getName()); 1093 } 1094 1095 writer.addEncodedAttribute("hyperlinkType", chart.getLinkType()); 1096 writer.addAttribute("hyperlinkTarget", chart.getHyperlinkTarget(), JRXmlConstants.getHyperlinkTargetMap(), JRHyperlink.HYPERLINK_TARGET_SELF); 1097 writer.addAttribute("bookmarkLevel", chart.getBookmarkLevel(), JRAnchor.NO_BOOKMARK); 1098 writer.addAttribute("customizerClass", chart.getCustomizerClass()); 1099 1100 writeReportElement(chart); 1101 writeBox(chart); 1102 1103 writer.startElement("chartTitle"); 1105 writer.addAttribute("position", chart.getTitlePosition(), JRXmlConstants.getChartTitlePositionMap(), JRChart.TITLE_POSITION_TOP); 1106 writer.addAttribute("color", chart.getTitleColor(), Color.black); 1107 writeFont(chart.getTitleFont()); 1108 if (chart.getTitleExpression() != null) 1109 { 1110 writer.writeExpression("titleExpression", chart.getTitleExpression(), false); 1111 } 1112 writer.closeElement(); 1113 1114 writer.startElement("chartSubtitle"); 1116 writer.addAttribute("color", chart.getSubtitleColor()); 1117 writeFont(chart.getSubtitleFont()); 1118 if (chart.getSubtitleExpression() != null) 1119 { 1120 writer.writeExpression("subtitleExpression", chart.getSubtitleExpression(), false); 1121 } 1122 writer.closeElement(); 1123 1124 writer.startElement("chartLegend"); 1126 if (chart.getLegendColor() != null) 1127 writer.addAttribute(JRChartFactory.JRChartLegendFactory.ATTRIBUTE_textColor, chart.getLegendColor()); 1128 if (chart.getLegendBackgroundColor() != null) 1129 writer.addAttribute(JRChartFactory.JRChartLegendFactory.ATTRIBUTE_backgroundColor, chart.getLegendBackgroundColor()); 1130 writeFont(chart.getLegendFont()); 1131 writer.closeElement(); 1132 1133 writer.writeExpression("anchorNameExpression", chart.getAnchorNameExpression(), false); 1134 writer.writeExpression("hyperlinkReferenceExpression", chart.getHyperlinkReferenceExpression(), false); 1135 writer.writeExpression("hyperlinkAnchorExpression", chart.getHyperlinkAnchorExpression(), false); 1136 writer.writeExpression("hyperlinkPageExpression", chart.getHyperlinkPageExpression(), false); 1137 writer.writeExpression(JRHyperlinkFactory.ELEMENT_hyperlinkTooltipExpression, chart.getHyperlinkTooltipExpression(), false); 1138 writeHyperlinkParameters(chart.getHyperlinkParameters()); 1139 1140 writer.closeElement(); 1141 } 1142 1143 1144 1147 private void writeElementDataset(JRElementDataset dataset) throws IOException 1148 { 1149 writer.startElement("dataset"); 1150 writer.addAttribute("resetType", dataset.getResetType(), JRXmlConstants.getResetTypeMap(), JRVariable.RESET_TYPE_REPORT); 1151 1152 if (dataset.getResetType() == JRVariable.RESET_TYPE_GROUP) 1153 { 1154 writer.addEncodedAttribute("resetGroup", dataset.getResetGroup().getName()); 1155 } 1156 writer.addAttribute("incrementType", dataset.getIncrementType(), JRXmlConstants.getResetTypeMap(), JRVariable.RESET_TYPE_NONE); 1157 1158 if (dataset.getIncrementType() == JRVariable.RESET_TYPE_GROUP) 1159 { 1160 writer.addEncodedAttribute("incrementGroup", dataset.getIncrementGroup().getName()); 1161 } 1162 1163 writer.writeExpression(JRElementDatasetFactory.ELEMENT_incrementWhenExpression, dataset.getIncrementWhenExpression(), false); 1164 1165 JRDatasetRun datasetRun = dataset.getDatasetRun(); 1166 if (datasetRun != null) 1167 { 1168 writeDatasetRun(datasetRun); 1169 } 1170 1171 writer.closeElement(true); 1172 } 1173 1174 1175 1178 private void writeCategoryDataSet(JRCategoryDataset dataset) throws IOException 1179 { 1180 writer.startElement("categoryDataset"); 1181 1182 writeElementDataset(dataset); 1183 1184 1185 JRCategorySeries[] categorySeries = dataset.getSeries(); 1186 if (categorySeries != null && categorySeries.length > 0) 1187 { 1188 for(int i = 0; i < categorySeries.length; i++) 1189 { 1190 writeCategorySeries(categorySeries[i]); 1191 } 1192 } 1193 1194 writer.closeElement(); 1195 } 1196 1197 1198 private void writeTimeSeriesDataset(JRTimeSeriesDataset dataset) throws IOException 1199 { 1200 writer.startElement("timeSeriesDataset"); 1201 if (dataset.getTimePeriod() != null && !Day.class.getName().equals(dataset.getTimePeriod().getName())) 1202 { 1203 writer.addAttribute("timePeriod", JRXmlConstants.getTimePeriodName(dataset.getTimePeriod())); 1204 } 1205 1206 writeElementDataset( dataset ); 1207 1208 JRTimeSeries[] timeSeries = dataset.getSeries(); 1209 if( timeSeries != null && timeSeries.length > 0 ) 1210 { 1211 for( int i = 0; i < timeSeries.length; i++ ) 1212 { 1213 writeTimeSeries( timeSeries[i] ); 1214 } 1215 } 1216 1217 writer.closeElement(); 1218 } 1219 1220 1221 private void writeTimePeriodDataset(JRTimePeriodDataset dataset) throws IOException 1222 { 1223 writer.startElement("timePeriodDataset"); 1224 writeElementDataset(dataset); 1225 1226 JRTimePeriodSeries[] timePeriodSeries = dataset.getSeries(); 1227 if( timePeriodSeries != null && timePeriodSeries.length > 0 ) 1228 { 1229 for( int i = 0; i < timePeriodSeries.length; i++ ) 1230 { 1231 writeTimePeriodSeries(timePeriodSeries[i]); 1232 } 1233 } 1234 writer.closeElement(); 1235 } 1236 1237 1238 1241 private void writeCategorySeries(JRCategorySeries categorySeries) throws IOException 1242 { 1243 writer.startElement("categorySeries"); 1244 1245 writer.writeExpression("seriesExpression", categorySeries.getSeriesExpression(), false); 1246 writer.writeExpression("categoryExpression", categorySeries.getCategoryExpression(), false); 1247 writer.writeExpression("valueExpression", categorySeries.getValueExpression(), false); 1248 writer.writeExpression("labelExpression", categorySeries.getLabelExpression(), false); 1249 writeHyperlink(JRHyperlinkFactory.ELEMENT_itemHyperlink, categorySeries.getItemHyperlink()); 1250 1251 writer.closeElement(); 1252 } 1253 1254 1257 private void writeXyzDataset(JRXyzDataset dataset) throws IOException 1258 { 1259 writer.startElement("xyzDataset"); 1260 writeElementDataset(dataset); 1261 1262 JRXyzSeries[] series = dataset.getSeries(); 1263 if( series != null && series.length > 0 ) 1264 { 1265 for( int i = 0; i < series.length; i++ ) 1266 { 1267 writeXyzSeries(series[i]); 1268 } 1269 } 1270 1271 writer.closeElement(); 1272 } 1273 1274 1275 1278 private void writeXyzSeries(JRXyzSeries series) throws IOException 1279 { 1280 writer.startElement("xyzSeries"); 1281 1282 writer.writeExpression("seriesExpression", series.getSeriesExpression(), false); 1283 writer.writeExpression("xValueExpression", series.getXValueExpression(), false); 1284 writer.writeExpression("yValueExpression", series.getYValueExpression(), false); 1285 writer.writeExpression("zValueExpression", series.getZValueExpression(), false); 1286 writeHyperlink(JRHyperlinkFactory.ELEMENT_itemHyperlink, series.getItemHyperlink()); 1287 1288 writer.closeElement(); 1289 } 1290 1291 1294 private void writeXySeries(JRXySeries xySeries) throws IOException 1295 { 1296 writer.startElement("xySeries"); 1297 1298 writer.writeExpression("seriesExpression", xySeries.getSeriesExpression(), false); 1299 writer.writeExpression("xValueExpression", xySeries.getXValueExpression(), false); 1300 writer.writeExpression("yValueExpression", xySeries.getYValueExpression(), false); 1301 writer.writeExpression("labelExpression", xySeries.getLabelExpression(), false); 1302 writeHyperlink(JRHyperlinkFactory.ELEMENT_itemHyperlink, xySeries.getItemHyperlink()); 1303 1304 writer.closeElement(); 1305 } 1306 1307 1308 1311 private void writeXyDataset(JRXyDataset dataset) throws IOException 1312 { 1313 writer.startElement("xyDataset"); 1314 1315 writeElementDataset(dataset); 1316 1317 1318 JRXySeries[] xySeries = dataset.getSeries(); 1319 if (xySeries != null && xySeries.length > 0) 1320 { 1321 for(int i = 0; i < xySeries.length; i++) 1322 { 1323 writeXySeries(xySeries[i]); 1324 } 1325 } 1326 1327 writer.closeElement(); 1328 } 1329 1330 1331 1334 private void writeTimeSeries(JRTimeSeries timeSeries) throws IOException 1335 { 1336 writer.startElement("timeSeries"); 1337 1338 writer.writeExpression("seriesExpression", timeSeries.getSeriesExpression(), false); 1339 writer.writeExpression("timePeriodExpression", timeSeries.getTimePeriodExpression(), false); 1340 writer.writeExpression("valueExpression", timeSeries.getValueExpression(), false); 1341 writer.writeExpression("labelExpression", timeSeries.getLabelExpression(), false); 1342 writeHyperlink(JRHyperlinkFactory.ELEMENT_itemHyperlink, timeSeries.getItemHyperlink()); 1343 1344 writer.closeElement(); 1345 } 1346 1347 1348 private void writeTimePeriodSeries(JRTimePeriodSeries timePeriodSeries) throws IOException 1349 { 1350 writer.startElement("timePeriodSeries"); 1351 1352 writer.writeExpression("seriesExpression", timePeriodSeries.getSeriesExpression(), false); 1353 writer.writeExpression("startDateExpression", timePeriodSeries.getStartDateExpression(), false); 1354 writer.writeExpression("endDateExpression", timePeriodSeries.getEndDateExpression(), false); 1355 writer.writeExpression("valueExpression", timePeriodSeries.getValueExpression(), false); 1356 writer.writeExpression("labelExpression", timePeriodSeries.getLabelExpression(), false); 1357 writeHyperlink(JRHyperlinkFactory.ELEMENT_itemHyperlink, timePeriodSeries.getItemHyperlink()); 1358 1359 writer.closeElement(); 1360 } 1361 1362 1363 1366 public void writePieDataset(JRPieDataset dataset) throws IOException 1367 { 1368 writer.startElement("pieDataset"); 1369 1370 writeElementDataset(dataset); 1371 1372 writer.writeExpression("keyExpression", dataset.getKeyExpression(), false); 1373 writer.writeExpression("valueExpression", dataset.getValueExpression(), false); 1374 writer.writeExpression("labelExpression", dataset.getLabelExpression(), false); 1375 writeHyperlink(JRHyperlinkFactory.ELEMENT_sectionHyperlink, dataset.getSectionHyperlink()); 1376 1377 writer.closeElement(); 1378 } 1379 1380 1384 public void writeValueDataset(JRValueDataset dataset) throws IOException 1385 { 1386 writer.startElement("valueDataset"); 1387 1388 writeElementDataset(dataset); 1389 1390 writer.writeExpression("valueExpression", dataset.getValueExpression(), false); 1391 1392 writer.closeElement(); 1393 } 1394 1395 1396 1401 public void writeValueDisplay(JRValueDisplay valueDisplay) throws IOException 1402 { 1403 writer.startElement("valueDisplay"); 1404 1405 writer.addAttribute("color", valueDisplay.getColor()); 1406 writer.addAttribute("mask", valueDisplay.getMask()); 1407 1408 writeFont(valueDisplay.getFont()); 1409 1410 writer.closeElement(); 1411 } 1412 1413 1418 public void writeDataRange(JRDataRange dataRange) throws IOException 1419 { 1420 writer.startElement("dataRange"); 1421 1422 writer.writeExpression("lowExpression", dataRange.getLowExpression(), false); 1423 writer.writeExpression("highExpression", dataRange.getHighExpression(), false); 1424 1425 writer.closeElement(); 1426 } 1427 1428 1429 1434 private void writeMeterInterval(JRMeterInterval interval) throws IOException 1435 { 1436 writer.startElement("meterInterval"); 1437 1438 writer.addAttribute("label", interval.getLabel()); 1439 writer.addAttribute("color", interval.getBackgroundColor()); 1440 writer.addAttribute("alpha", interval.getAlpha()); 1441 1442 writeDataRange(interval.getDataRange()); 1443 1444 writer.closeElement(); 1445 } 1446 1447 1453 private void writeSeriesColors(SortedSet seriesColors) throws IOException 1454 { 1455 if (seriesColors == null || seriesColors.size() == 0) 1456 return; 1457 1458 JRSeriesColor[] colors = (JRSeriesColor[])seriesColors.toArray(new JRSeriesColor[0]); 1459 for (int i = 0; i < colors.length; i++) 1460 { 1461 writer.startElement("seriesColor"); 1462 writer.addAttribute(JRSeriesColorFactory.ATTRIBUTE_seriesOrder, colors[i].getSeriesOrder()); 1463 writer.addAttribute(JRSeriesColorFactory.ATTRIBUTE_color, colors[i].getColor()); 1464 writer.closeElement(); 1465 } 1466 } 1467 1468 1474 private void writeChartAxis(JRChartAxis chartAxis) throws IOException 1475 { 1476 writer.startElement("axis"); 1477 writer.addAttribute(JRChartAxisFactory.ATTRIBUTE_position, chartAxis.getPosition(), 1478 JRXmlConstants.getAxisPositionMap(), JRChartAxis.POSITION_LEFT_OR_TOP); 1479 1480 writeChartTag(chartAxis.getChart()); 1482 writer.closeElement(); 1483 } 1484 1485 1489 private void writePlot(JRChartPlot plot) throws IOException 1490 { 1491 writer.startElement("plot"); 1492 writer.addAttribute("backcolor", plot.getBackcolor()); 1493 writer.addAttribute("orientation", plot.getOrientation(), JRXmlConstants.getPlotOrientationMap(), PlotOrientation.VERTICAL); 1494 writer.addAttribute("backgroundAlpha", plot.getBackgroundAlpha(), 1.0f); 1495 writer.addAttribute("foregroundAlpha", plot.getForegroundAlpha(), 1.0f); 1496 writer.addAttribute("labelRotation", plot.getLabelRotation(), 0.0); 1497 writeSeriesColors(plot.getSeriesColors()); 1498 1499 writer.closeElement(); 1500 } 1501 1502 1503 1506 public void writePieChart(JRChart chart) throws IOException 1507 { 1508 writer.startElement("pieChart"); 1509 writeChart(chart); 1510 writePieDataset((JRPieDataset) chart.getDataset()); 1511 1512 writer.startElement("piePlot"); 1514 writePlot(chart.getPlot()); 1515 writer.closeElement(); 1516 1517 writer.closeElement(); 1518 } 1519 1520 1521 1524 public void writePie3DChart(JRChart chart) throws IOException 1525 { 1526 writer.startElement("pie3DChart"); 1527 writeChart(chart); 1528 writePieDataset((JRPieDataset) chart.getDataset()); 1529 1530 JRPie3DPlot plot = (JRPie3DPlot) chart.getPlot(); 1532 writer.startElement("pie3DPlot"); 1533 writer.addAttribute("depthFactor", plot.getDepthFactor(), JRPie3DPlot.DEPTH_FACTOR_DEFAULT); 1534 writePlot(chart.getPlot()); 1535 writer.closeElement(); 1536 1537 writer.closeElement(); 1538 } 1539 1540 1541 1542 1554 public void writeAxisFormat(String axisFormatElementName, 1555 JRFont axisLabelFont, Color axisLabelColor, 1556 JRFont axisTickLabelFont, Color axisTickLabelColor, 1557 String axisTickLabelMask, Color axisLineColor) throws IOException 1558 { 1559 if (axisLabelFont == null && axisLabelColor == null && 1560 axisTickLabelFont == null && axisTickLabelColor == null && axisLineColor == null) 1561 return; 1562 1563 writer.startElement(axisFormatElementName); 1564 writer.startElement("axisFormat"); 1565 writer.addAttribute(JRChartFactory.JRChartAxisFormatFactory.ATTRIBUTE_labelColor, axisLabelColor); 1566 writer.addAttribute(JRChartFactory.JRChartAxisFormatFactory.ATTRIBUTE_tickLabelColor, axisTickLabelColor); 1567 writer.addAttribute(JRChartFactory.JRChartAxisFormatFactory.ATTRIBUTE_tickLabelMask, axisTickLabelMask); 1568 writer.addAttribute(JRChartFactory.JRChartAxisFormatFactory.ATTRIBUTE_axisLineColor, axisLineColor); 1569 1570 if (axisLabelFont != null) 1571 { 1572 writer.startElement("labelFont"); 1573 writeFont(axisLabelFont); 1574 writer.closeElement(); 1575 } 1576 1577 if (axisTickLabelFont != null) 1578 { 1579 writer.startElement("tickLabelFont"); 1580 writeFont(axisTickLabelFont); 1581 writer.closeElement(); 1582 } 1583 1584 writer.closeElement(); 1585 writer.closeElement(); 1586 } 1587 1590 private void writeBarPlot(JRBarPlot plot) throws IOException 1591 { 1592 writer.startElement("barPlot"); 1593 writer.addAttribute("isShowLabels", plot.isShowLabels(), false); 1594 writer.addAttribute("isShowTickLabels", plot.isShowTickLabels(), true); 1595 writer.addAttribute("isShowTickMarks", plot.isShowTickMarks(), true); 1596 writePlot(plot); 1597 1598 writer.writeExpression("categoryAxisLabelExpression", plot.getCategoryAxisLabelExpression(), false); 1599 writeAxisFormat("categoryAxisFormat", plot.getCategoryAxisLabelFont(), plot.getCategoryAxisLabelColor(), 1600 plot.getCategoryAxisTickLabelFont(), plot.getCategoryAxisTickLabelColor(), 1601 plot.getCategoryAxisTickLabelMask(), plot.getCategoryAxisLineColor()); 1602 writer.writeExpression("valueAxisLabelExpression", plot.getValueAxisLabelExpression(), false); 1603 writeAxisFormat("valueAxisFormat", plot.getValueAxisLabelFont(), plot.getValueAxisLabelColor(), 1604 plot.getValueAxisTickLabelFont(), plot.getValueAxisTickLabelColor(), 1605 plot.getValueAxisTickLabelMask(), plot.getValueAxisLineColor()); 1606 1607 1608 writer.closeElement(); 1609 } 1610 1611 1612 1615 private void writeBubblePlot(JRBubblePlot plot) throws IOException 1616 { 1617 writer.startElement("bubblePlot"); 1618 writer.addAttribute("scaleType", plot.getScaleType(), JRXmlConstants.getScaleTypeMap()); 1619 writePlot(plot); 1620 1621 writer.writeExpression("xAxisLabelExpression", plot.getXAxisLabelExpression(), false); 1622 writeAxisFormat("xAxisFormat", plot.getXAxisLabelFont(), plot.getXAxisLabelColor(), 1623 plot.getXAxisTickLabelFont(), plot.getXAxisTickLabelColor(), 1624 plot.getXAxisTickLabelMask(), plot.getXAxisLineColor()); 1625 writer.writeExpression("yAxisLabelExpression", plot.getYAxisLabelExpression(), false); 1626 writeAxisFormat("yAxisFormat", plot.getYAxisLabelFont(), plot.getYAxisLabelColor(), 1627 plot.getYAxisTickLabelFont(), plot.getYAxisTickLabelColor(), 1628 plot.getYAxisTickLabelMask(), plot.getYAxisLineColor()); 1629 1630 writer.closeElement(); 1631 } 1632 1633 1634 1637 private void writeLinePlot(JRLinePlot plot) throws IOException 1638 { 1639 writer.startElement("linePlot"); 1640 writer.addAttribute("isShowLines", plot.isShowLines(), true); 1641 writer.addAttribute("isShowShapes", plot.isShowShapes(), true); 1642 1643 writePlot(plot); 1644 1645 writer.writeExpression("categoryAxisLabelExpression", plot.getCategoryAxisLabelExpression(), false); 1646 writeAxisFormat("categoryAxisFormat", plot.getCategoryAxisLabelFont(), plot.getCategoryAxisLabelColor(), 1647 plot.getCategoryAxisTickLabelFont(), plot.getCategoryAxisTickLabelColor(), 1648 plot.getCategoryAxisTickLabelMask(), plot.getCategoryAxisLineColor()); 1649 writer.writeExpression("valueAxisLabelExpression", plot.getValueAxisLabelExpression(), false); 1650 writeAxisFormat("valueAxisFormat", plot.getValueAxisLabelFont(), plot.getValueAxisLabelColor(), 1651 plot.getValueAxisTickLabelFont(), plot.getValueAxisTickLabelColor(), 1652 plot.getValueAxisTickLabelMask(), plot.getValueAxisLineColor()); 1653 1654 writer.closeElement(); 1655 } 1656 1657 1658 private void writeTimeSeriesPlot(JRTimeSeriesPlot plot) throws IOException 1659 { 1660 writer.startElement("timeSeriesPlot"); 1661 writer.addAttribute("isShowLines", plot.isShowLines(), true); 1662 writer.addAttribute("isShowShapes", plot.isShowShapes(), true); 1663 1664 writePlot( plot ); 1665 1666 writer.writeExpression("timeAxisLabelExpression", plot.getTimeAxisLabelExpression(), false); 1667 writeAxisFormat("timeAxisFormat", plot.getTimeAxisLabelFont(), plot.getTimeAxisLabelColor(), 1668 plot.getTimeAxisTickLabelFont(), plot.getTimeAxisTickLabelColor(), 1669 plot.getTimeAxisTickLabelMask(), plot.getTimeAxisLineColor()); 1670 writer.writeExpression("valueAxisLabelExpression", plot.getValueAxisLabelExpression(), false); 1671 writeAxisFormat("valueAxisFormat", plot.getValueAxisLabelFont(), plot.getValueAxisLabelColor(), 1672 plot.getValueAxisTickLabelFont(), plot.getValueAxisTickLabelColor(), 1673 plot.getValueAxisTickLabelMask(), plot.getValueAxisLineColor()); 1674 1675 1676 writer.closeElement(); 1677 } 1678 1679 1680 1683 public void writeBar3DPlot(JRBar3DPlot plot) throws IOException 1684 { 1685 writer.startElement("bar3DPlot"); 1686 writer.addAttribute("isShowLabels", plot.isShowLabels(), false); 1687 writer.addAttribute("xOffset", plot.getXOffset(), BarRenderer3D.DEFAULT_X_OFFSET); 1688 writer.addAttribute("yOffset", plot.getYOffset(), BarRenderer3D.DEFAULT_Y_OFFSET); 1689 1690 writePlot(plot); 1691 1692 writer.writeExpression("categoryAxisLabelExpression", plot.getCategoryAxisLabelExpression(), false); 1693 writeAxisFormat("categoryAxisFormat", plot.getCategoryAxisLabelFont(), plot.getCategoryAxisLabelColor(), 1694 plot.getCategoryAxisTickLabelFont(), plot.getCategoryAxisTickLabelColor(), 1695 plot.getCategoryAxisTickLabelMask(), plot.getCategoryAxisLineColor()); 1696 writer.writeExpression("valueAxisLabelExpression", plot.getValueAxisLabelExpression(), false); 1697 writeAxisFormat("valueAxisFormat", plot.getValueAxisLabelFont(), plot.getValueAxisLabelColor(), 1698 plot.getValueAxisTickLabelFont(), plot.getValueAxisTickLabelColor(), 1699 plot.getValueAxisTickLabelMask(), plot.getValueAxisLineColor()); 1700 1701 1702 writer.closeElement(); 1703 } 1704 1705 1706 1709 public void writeBarChart(JRChart chart) throws IOException 1710 { 1711 writer.startElement("barChart"); 1712 1713 writeChart(chart); 1714 writeCategoryDataSet((JRCategoryDataset) chart.getDataset()); 1715 writeBarPlot((JRBarPlot) chart.getPlot()); 1716 1717 writer.closeElement(); 1718 } 1719 1720 1721 1724 public void writeBar3DChart(JRChart chart) throws IOException 1725 { 1726 writer.startElement("bar3DChart"); 1727 1728 writeChart(chart); 1729 writeCategoryDataSet((JRCategoryDataset) chart.getDataset()); 1730 writeBar3DPlot((JRBar3DPlot) chart.getPlot()); 1731 1732 writer.closeElement(); 1733 } 1734 1735 1736 1739 public void writeBubbleChart(JRChart chart) throws IOException 1740 { 1741 writer.startElement("bubbleChart"); 1742 writeChart(chart); 1743 writeXyzDataset((JRXyzDataset) chart.getDataset()); 1744 writeBubblePlot((JRBubblePlot) chart.getPlot()); 1745 writer.closeElement(); 1746 } 1747 1748 1749 1752 public void writeStackedBarChart(JRChart chart) throws IOException 1753 { 1754 writer.startElement("stackedBarChart"); 1755 1756 writeChart(chart); 1757 writeCategoryDataSet((JRCategoryDataset) chart.getDataset()); 1758 writeBarPlot((JRBarPlot) chart.getPlot()); 1759 1760 writer.closeElement(); 1761 } 1762 1763 1764 1767 public void writeStackedBar3DChart(JRChart chart) throws IOException 1768 { 1769 writer.startElement("stackedBar3DChart"); 1770 1771 writeChart(chart); 1772 writeCategoryDataSet((JRCategoryDataset) chart.getDataset()); 1773 writeBar3DPlot((JRBar3DPlot) chart.getPlot()); 1774 writer.closeElement(); 1775 } 1776 1777 1778 1781 public void writeLineChart(JRChart chart) throws IOException 1782 { 1783 writer.startElement("lineChart"); 1784 1785 writeChart(chart); 1786 writeCategoryDataSet((JRCategoryDataset) chart.getDataset()); 1787 writeLinePlot((JRLinePlot) chart.getPlot()); 1788 writer.closeElement(); 1789 } 1790 1791 1792 public void writeTimeSeriesChart(JRChart chart) throws IOException 1793 { 1794 writer.startElement("timeSeriesChart"); 1795 writeChart(chart); 1796 writeTimeSeriesDataset((JRTimeSeriesDataset)chart.getDataset()); 1797 writeTimeSeriesPlot((JRTimeSeriesPlot)chart.getPlot()); 1798 writer.closeElement(); 1799 } 1800 1801 public void writeHighLowDataset(JRHighLowDataset dataset) throws IOException 1802 { 1803 writer.startElement("highLowDataset"); 1804 1805 writeElementDataset(dataset); 1806 1807 writer.writeExpression("seriesExpression", dataset.getSeriesExpression(), false); 1808 writer.writeExpression("dateExpression", dataset.getDateExpression(), false); 1809 writer.writeExpression("highExpression", dataset.getHighExpression(), false); 1810 writer.writeExpression("lowExpression", dataset.getLowExpression(), false); 1811 writer.writeExpression("openExpression", dataset.getOpenExpression(), false); 1812 writer.writeExpression("closeExpression", dataset.getCloseExpression(), false); 1813 writer.writeExpression("volumeExpression", dataset.getVolumeExpression(), false); 1814 writeHyperlink(JRHyperlinkFactory.ELEMENT_itemHyperlink, dataset.getItemHyperlink()); 1815 1816 writer.closeElement(); 1817 } 1818 1819 1820 public void writeHighLowChart(JRChart chart) throws IOException 1821 { 1822 writer.startElement("highLowChart"); 1823 1824 writeChart(chart); 1825 writeHighLowDataset((JRHighLowDataset) chart.getDataset()); 1826 1827 JRHighLowPlot plot = (JRHighLowPlot) chart.getPlot(); 1828 writer.startElement("highLowPlot"); 1829 writer.addAttribute("isShowOpenTicks", plot.isShowOpenTicks(), true); 1830 writer.addAttribute("isShowCloseTicks", plot.isShowCloseTicks(), true); 1831 1832 writePlot(plot); 1833 1834 writer.writeExpression("timeAxisLabelExpression", plot.getTimeAxisLabelExpression(), false); 1835 writeAxisFormat("timeAxisFormat", plot.getTimeAxisLabelFont(), plot.getTimeAxisLabelColor(), 1836 plot.getTimeAxisTickLabelFont(), plot.getTimeAxisTickLabelColor(), 1837 plot.getTimeAxisTickLabelMask(), plot.getTimeAxisLineColor()); 1838 writer.writeExpression("valueAxisLabelExpression", plot.getValueAxisLabelExpression(), false); 1839 writeAxisFormat("valueAxisFormat", plot.getValueAxisLabelFont(), plot.getValueAxisLabelColor(), 1840 plot.getValueAxisTickLabelFont(), plot.getValueAxisTickLabelColor(), 1841 plot.getValueAxisTickLabelMask(), plot.getValueAxisLineColor()); 1842 1843 1844 writer.closeElement(); 1845 writer.closeElement(); 1846 } 1847 1848 1849 public void writeCandlestickChart(JRChart chart) throws IOException 1850 { 1851 writer.startElement("candlestickChart"); 1852 1853 writeChart(chart); 1854 writeHighLowDataset((JRHighLowDataset) chart.getDataset()); 1855 1856 JRCandlestickPlot plot = (JRCandlestickPlot) chart.getPlot(); 1857 writer.startElement("candlestickPlot"); 1858 writer.addAttribute("isShowVolume", plot.isShowVolume(), true); 1859 1860 writePlot(plot); 1861 1862 writer.writeExpression("timeAxisLabelExpression", plot.getTimeAxisLabelExpression(), false); 1863 writeAxisFormat("timeAxisFormat", plot.getTimeAxisLabelFont(), plot.getTimeAxisLabelColor(), 1864 plot.getTimeAxisTickLabelFont(), plot.getTimeAxisTickLabelColor(), 1865 plot.getTimeAxisTickLabelMask(), plot.getTimeAxisLineColor()); 1866 writer.writeExpression("valueAxisLabelExpression", plot.getValueAxisLabelExpression(), false); 1867 writeAxisFormat("valueAxisFormat", plot.getValueAxisLabelFont(), plot.getValueAxisLabelColor(), 1868 plot.getValueAxisTickLabelFont(), plot.getValueAxisTickLabelColor(), 1869 plot.getValueAxisTickLabelMask(), plot.getValueAxisLineColor()); 1870 1871 1872 writer.closeElement(); 1873 writer.closeElement(); 1874 } 1875 1876 1879 private void writeAreaPlot(JRAreaPlot plot) throws IOException 1880 { 1881 writer.startElement("areaPlot"); 1882 writePlot(plot); 1883 1884 writer.writeExpression("categoryAxisLabelExpression", plot.getCategoryAxisLabelExpression(), false); 1885 writeAxisFormat("categoryAxisFormat", plot.getCategoryAxisLabelFont(), plot.getCategoryAxisLabelColor(), 1886 plot.getCategoryAxisTickLabelFont(), plot.getCategoryAxisTickLabelColor(), 1887 plot.getCategoryAxisTickLabelMask(), plot.getCategoryAxisLineColor()); 1888 writer.writeExpression("valueAxisLabelExpression", plot.getValueAxisLabelExpression(), false); 1889 writeAxisFormat("valueAxisFormat", plot.getValueAxisLabelFont(), plot.getValueAxisLabelColor(), 1890 plot.getValueAxisTickLabelFont(), plot.getValueAxisTickLabelColor(), 1891 plot.getValueAxisTickLabelMask(), plot.getValueAxisLineColor()); 1892 1893 1894 writer.closeElement(); 1895 } 1896 1897 1898 1901 public void writeAreaChart(JRChart chart) throws IOException 1902 { 1903 writer.startElement("areaChart"); 1904 1905 writeChart(chart); 1906 writeCategoryDataSet((JRCategoryDataset) chart.getDataset()); 1907 writeAreaPlot((JRAreaPlot) chart.getPlot()); 1908 1909 writer.closeElement(); 1910 } 1911 1912 1913 1916 private void writeScatterPlot(JRScatterPlot plot) throws IOException 1917 { 1918 writer.startElement("scatterPlot"); 1919 writer.addAttribute("isShowLines", plot.isShowLines(), true); 1920 writer.addAttribute("isShowShapes", plot.isShowShapes(), true); 1921 1922 writePlot(plot); 1923 1924 writer.writeExpression("xAxisLabelExpression", plot.getXAxisLabelExpression(), false); 1925 writeAxisFormat("xAxisFormat", plot.getXAxisLabelFont(), plot.getXAxisLabelColor(), 1926 plot.getXAxisTickLabelFont(), plot.getXAxisTickLabelColor(), 1927 plot.getXAxisTickLabelMask(), plot.getXAxisLineColor()); 1928 writer.writeExpression("yAxisLabelExpression", plot.getYAxisLabelExpression(), false); 1929 writeAxisFormat("yAxisFormat", plot.getYAxisLabelFont(), plot.getYAxisLabelColor(), 1930 plot.getYAxisTickLabelFont(), plot.getYAxisTickLabelColor(), 1931 plot.getYAxisTickLabelMask(), plot.getYAxisLineColor()); 1932 1933 writer.closeElement(); 1934 } 1935 1936 1937 1940 public void writeScatterChart(JRChart chart) throws IOException 1941 { 1942 writer.startElement("scatterChart"); 1943 1944 writeChart(chart); 1945 writeXyDataset((JRXyDataset) chart.getDataset()); 1946 writeScatterPlot((JRScatterPlot) chart.getPlot()); 1947 1948 writer.closeElement(); 1949 } 1950 1951 1952 1955 public void writeXyAreaChart(JRChart chart) throws IOException 1956 { 1957 writer.startElement("xyAreaChart"); 1958 1959 writeChart(chart); 1960 writeXyDataset((JRXyDataset) chart.getDataset()); 1961 writeAreaPlot((JRAreaPlot) chart.getPlot()); 1962 1963 writer.closeElement(); 1964 } 1965 1966 1967 1970 public void writeXyBarChart(JRChart chart) throws IOException 1971 { 1972 writer.startElement("xyBarChart"); 1973 1974 writeChart(chart); 1975 JRChartDataset dataset = chart.getDataset(); 1976 1977 if( dataset.getDatasetType() == JRChartDataset.TIMESERIES_DATASET ){ 1978 writeTimeSeriesDataset( (JRTimeSeriesDataset)dataset ); 1979 } 1980 else if( dataset.getDatasetType() == JRChartDataset.TIMEPERIOD_DATASET ){ 1981 writeTimePeriodDataset( (JRTimePeriodDataset)dataset ); 1982 } 1983 else if( dataset.getDatasetType() == JRChartDataset.XY_DATASET ){ 1984 writeXyDataset( (JRXyDataset)dataset ); 1985 } 1986 1987 writeBarPlot((JRBarPlot) chart.getPlot()); 1988 1989 writer.closeElement(); 1990 } 1991 1992 1993 1996 public void writeXyLineChart(JRChart chart) throws IOException 1997 { 1998 writer.startElement("xyLineChart"); 1999 2000 writeChart(chart); 2001 writeXyDataset((JRXyDataset) chart.getDataset()); 2002 writeLinePlot((JRLinePlot) chart.getPlot()); 2003 2004 writer.closeElement(); 2005 } 2006 2007 2008 2013 public void writeMeterChart(JRChart chart) throws IOException 2014 { 2015 writer.startElement("meterChart"); 2016 2017 writeChart(chart); 2018 writeValueDataset((JRValueDataset) chart.getDataset()); 2019 2020 JRMeterPlot plot = (JRMeterPlot) chart.getPlot(); 2022 writer.startElement("meterPlot"); 2023 writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_shape, plot.getShape(), 2024 JRXmlConstants.getMeterShapeMap(), JRMeterPlot.SHAPE_PIE); 2025 writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_angle, plot.getMeterAngle()); 2026 writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_units, plot.getUnits()); 2027 writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_tickInterval, plot.getTickInterval()); 2028 writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_meterColor, plot.getMeterBackgroundColor()); 2029 writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_needleColor, plot.getNeedleColor()); 2030 writer.addAttribute(JRMeterPlotFactory.ATTRIBUTE_tickColor, plot.getTickColor()); 2031 2032 writePlot(chart.getPlot()); 2033 writeValueDisplay(plot.getValueDisplay()); 2034 writeDataRange(plot.getDataRange()); 2035 2036 List intervals = plot.getIntervals(); 2037 if (intervals != null) 2038 { 2039 Iterator iter = intervals.iterator(); 2040 while (iter.hasNext()) 2041 { 2042 JRMeterInterval meterInterval = 2043 (JRMeterInterval) iter.next(); 2044 writeMeterInterval(meterInterval); 2045 } 2046 } 2047 writer.closeElement(); 2048 2049 writer.closeElement(); 2050 } 2051 2052 2053 2058 public void writeThermometerChart(JRChart chart) throws IOException 2059 { 2060 writer.startElement("thermometerChart"); 2061 2062 writeChart(chart); 2063 writeValueDataset((JRValueDataset) chart.getDataset()); 2064 2065 JRThermometerPlot plot = (JRThermometerPlot) chart.getPlot(); 2067 2068 writer.startElement("thermometerPlot"); 2069 2070 writer.addAttribute(JRThermometerPlotFactory.ATTRIBUTE_valueLocation, 2071 plot.getValueLocation(), 2072 JRXmlConstants.getThermometerValueLocationMap(), 2073 JRThermometerPlot.LOCATION_BULB); 2074 writer.addAttribute(JRThermometerPlotFactory.ATTRIBUTE_showValueLines, plot.isShowValueLines()); 2075 writer.addAttribute(JRThermometerPlotFactory.ATTRIBUTE_mercuryColor, plot.getMercuryColor()); 2076 2077 writePlot(chart.getPlot()); 2078 2079 writeValueDisplay(plot.getValueDisplay()); 2080 writeDataRange(plot.getDataRange()); 2081 2082 if (plot.getLowRange() != null) 2083 { 2084 writer.startElement("lowRange"); 2085 writeDataRange(plot.getLowRange()); 2086 writer.closeElement(); 2087 } 2088 2089 if (plot.getMediumRange() != null) 2090 { 2091 writer.startElement("mediumRange"); 2092 writeDataRange(plot.getMediumRange()); 2093 writer.closeElement(); 2094 } 2095 2096 if (plot.getHighRange() != null) 2097 { 2098 writer.startElement("highRange"); 2099 writeDataRange(plot.getHighRange()); 2100 writer.closeElement(); 2101 } 2102 2103 2104 writer.closeElement(); 2105 2106 writer.closeElement(); 2107 } 2108 2109 2110 2115 public void writeMultiAxisChart(JRChart chart) throws IOException 2116 { 2117 writer.startElement("multiAxisChart"); 2118 2119 writeChart(chart); 2120 2121 JRMultiAxisPlot plot = (JRMultiAxisPlot) chart.getPlot(); 2123 writer.startElement("multiAxisPlot"); 2124 2125 writePlot(chart.getPlot()); 2126 2127 List axes = plot.getAxes(); 2128 if (axes != null) 2129 { 2130 Iterator iter = axes.iterator(); 2131 while (iter.hasNext()) 2132 { 2133 JRChartAxis chartAxis = 2134 (JRChartAxis) iter.next(); 2135 writeChartAxis(chartAxis); 2136 } 2137 } 2138 writer.closeElement(); 2139 2140 writer.closeElement(); 2141 } 2142 2143 2144 public void writeChartTag(JRChart chart) throws IOException 2145 { 2146 switch(chart.getChartType()) { 2147 case JRChart.CHART_TYPE_AREA: 2148 writeAreaChart(chart); 2149 break; 2150 case JRChart.CHART_TYPE_BAR: 2151 writeBarChart(chart); 2152 break; 2153 case JRChart.CHART_TYPE_BAR3D: 2154 writeBar3DChart(chart); 2155 break; 2156 case JRChart.CHART_TYPE_BUBBLE: 2157 writeBubbleChart(chart); 2158 break; 2159 case JRChart.CHART_TYPE_CANDLESTICK: 2160 writeCandlestickChart(chart); 2161 break; 2162 case JRChart.CHART_TYPE_HIGHLOW: 2163 writeHighLowChart(chart); 2164 break; 2165 case JRChart.CHART_TYPE_LINE: 2166 writeLineChart(chart); 2167 break; 2168 case JRChart.CHART_TYPE_METER: 2169 writeMeterChart(chart); 2170 break; 2171 case JRChart.CHART_TYPE_MULTI_AXIS: 2172 writeMultiAxisChart(chart); 2173 break; 2174 case JRChart.CHART_TYPE_PIE: 2175 writePieChart(chart); 2176 break; 2177 case JRChart.CHART_TYPE_PIE3D: 2178 writePie3DChart(chart); 2179 break; 2180 case JRChart.CHART_TYPE_SCATTER: 2181 writeScatterChart(chart); 2182 break; 2183 case JRChart.CHART_TYPE_STACKEDBAR: 2184 writeStackedBarChart(chart); 2185 break; 2186 case JRChart.CHART_TYPE_STACKEDBAR3D: 2187 writeStackedBar3DChart(chart); 2188 break; 2189 case JRChart.CHART_TYPE_THERMOMETER: 2190 writeThermometerChart(chart); 2191 break; 2192 case JRChart.CHART_TYPE_TIMESERIES: 2193 writeTimeSeriesChart( chart ); 2194 break; 2195 case JRChart.CHART_TYPE_XYAREA: 2196 writeXyAreaChart(chart); 2197 break; 2198 case JRChart.CHART_TYPE_XYBAR: 2199 writeXyBarChart(chart); 2200 break; 2201 case JRChart.CHART_TYPE_XYLINE: 2202 writeXyLineChart(chart); 2203 break; 2204 default: 2205 throw new JRRuntimeException("Chart type not supported."); 2206 } 2207 } 2208 2209 2210 private void writeSubreportReturnValue(JRSubreportReturnValue returnValue) throws IOException 2211 { 2212 writer.startElement("returnValue"); 2213 writer.addEncodedAttribute("subreportVariable", returnValue.getSubreportVariable()); 2214 writer.addEncodedAttribute("toVariable", returnValue.getToVariable()); 2215 writer.addAttribute("calculation", returnValue.getCalculation(), JRXmlConstants.getCalculationMap(), JRVariable.CALCULATION_NOTHING); 2216 writer.addAttribute("incrementerFactoryClass", returnValue.getIncrementerFactoryClassName()); 2217 writer.closeElement(); 2218 } 2219 2220 2221 public void writeCrosstab(JRCrosstab crosstab) throws IOException 2222 { 2223 writer.startElement("crosstab"); 2224 writer.addAttribute(JRCrosstabFactory.ATTRIBUTE_isRepeatColumnHeaders, crosstab.isRepeatColumnHeaders(), true); 2225 writer.addAttribute(JRCrosstabFactory.ATTRIBUTE_isRepeatRowHeaders, crosstab.isRepeatRowHeaders(), true); 2226 writer.addAttribute(JRCrosstabFactory.ATTRIBUTE_columnBreakOffset, crosstab.getColumnBreakOffset(), JRCrosstab.DEFAULT_COLUMN_BREAK_OFFSET); 2227 2228 writeReportElement(crosstab); 2229 2230 JRCrosstabParameter[] parameters = crosstab.getParameters(); 2231 if (parameters != null) 2232 { 2233 for (int i = 0; i < parameters.length; i++) 2234 { 2235 if (!parameters[i].isSystemDefined()) 2236 { 2237 writeCrosstabParameter(parameters[i]); 2238 } 2239 } 2240 } 2241 2242 writer.writeExpression("parametersMapExpression", crosstab.getParametersMapExpression(), false); 2243 2244 writeCrosstabDataset(crosstab); 2245 2246 writeCrosstabHeaderCell(crosstab); 2247 2248 JRCrosstabRowGroup[] rowGroups = crosstab.getRowGroups(); 2249 for (int i = 0; i < rowGroups.length; i++) 2250 { 2251 writeCrosstabRowGroup(rowGroups[i]); 2252 } 2253 2254 JRCrosstabColumnGroup[] columnGroups = crosstab.getColumnGroups(); 2255 for (int i = 0; i < columnGroups.length; i++) 2256 { 2257 writeCrosstabColumnGroup(columnGroups[i]); 2258 } 2259 2260 JRCrosstabMeasure[] measures = crosstab.getMeasures(); 2261 for (int i = 0; i < measures.length; i++) 2262 { 2263 writeCrosstabMeasure(measures[i]); 2264 } 2265 2266 if (crosstab instanceof JRDesignCrosstab) 2267 { 2268 List cellsList = ((JRDesignCrosstab) crosstab).getCellsList(); 2269 for (Iterator it = cellsList.iterator(); it.hasNext();) 2270 { 2271 JRCrosstabCell cell = (JRCrosstabCell) it.next(); 2272 writeCrosstabCell(cell); 2273 } 2274 } 2275 else 2276 { 2277 JRCrosstabCell[][] cells = crosstab.getCells(); 2278 Set cellsSet = new HashSet (); 2279 for (int i = cells.length - 1; i >= 0 ; --i) 2280 { 2281 for (int j = cells[i].length - 1; j >= 0 ; --j) 2282 { 2283 JRCrosstabCell cell = cells[i][j]; 2284 if (cell != null && cellsSet.add(cell)) 2285 { 2286 writeCrosstabCell(cell); 2287 } 2288 } 2289 } 2290 } 2291 2292 writeCrosstabWhenNoDataCell(crosstab); 2293 2294 writer.closeElement(); 2295 } 2296 2297 2298 private void writeCrosstabDataset(JRCrosstab crosstab) throws IOException 2299 { 2300 JRCrosstabDataset dataset = crosstab.getDataset(); 2301 writer.startElement("crosstabDataset"); 2302 writer.addAttribute(JRCrosstabDatasetFactory.ATTRIBUTE_isDataPreSorted, dataset.isDataPreSorted(), false); 2303 writeElementDataset(dataset); 2304 writer.closeElement(true); 2305 } 2306 2307 2308 private void writeCrosstabWhenNoDataCell(JRCrosstab crosstab) throws IOException 2309 { 2310 JRCellContents whenNoDataCell = crosstab.getWhenNoDataCell(); 2311 if (whenNoDataCell != null) 2312 { 2313 writer.startElement("whenNoDataCell"); 2314 writeCellContents(whenNoDataCell); 2315 writer.closeElement(); 2316 } 2317 } 2318 2319 2320 private void writeCrosstabHeaderCell(JRCrosstab crosstab) throws IOException 2321 { 2322 JRCellContents headerCell = crosstab.getHeaderCell(); 2323 if (headerCell != null) 2324 { 2325 writer.startElement("crosstabHeaderCell"); 2326 writeCellContents(headerCell); 2327 writer.closeElement(); 2328 } 2329 } 2330 2331 2332 protected void writeCrosstabRowGroup(JRCrosstabRowGroup group) throws IOException 2333 { 2334 writer.startElement("rowGroup"); 2335 writer.addEncodedAttribute(JRCrosstabGroupFactory.ATTRIBUTE_name, group.getName()); 2336 writer.addAttribute(JRCrosstabRowGroupFactory.ATTRIBUTE_width, group.getWidth()); 2337 writer.addAttribute(JRCrosstabGroupFactory.ATTRIBUTE_totalPosition, group.getTotalPosition(), JRXmlConstants.getCrosstabTotalPositionMap(), BucketDefinition.TOTAL_POSITION_NONE); 2338 writer.addAttribute(JRCrosstabRowGroupFactory.ATTRIBUTE_headerPosition, group.getPosition(), JRXmlConstants.getCrosstabRowPositionMap(), JRCellContents.POSITION_Y_TOP); 2339 2340 writeBucket(group.getBucket()); 2341 2342 JRCellContents header = group.getHeader(); 2343 writer.startElement("crosstabRowHeader"); 2344 writeCellContents(header); 2345 writer.closeElement(); 2346 2347 JRCellContents totalHeader = group.getTotalHeader(); 2348 writer.startElement("crosstabTotalRowHeader"); 2349 writeCellContents(totalHeader); 2350 writer.closeElement(); 2351 2352 writer.closeElement(); 2353 } 2354 2355 2356 protected void writeCrosstabColumnGroup(JRCrosstabColumnGroup group) throws IOException 2357 { 2358 writer.startElement("columnGroup"); 2359 writer.addEncodedAttribute(JRCrosstabGroupFactory.ATTRIBUTE_name, group.getName()); 2360 writer.addAttribute(JRCrosstabColumnGroupFactory.ATTRIBUTE_height, group.getHeight()); 2361 writer.addAttribute(JRCrosstabGroupFactory.ATTRIBUTE_totalPosition, group.getTotalPosition(), JRXmlConstants.getCrosstabTotalPositionMap(), BucketDefinition.TOTAL_POSITION_NONE); 2362 writer.addAttribute(JRCrosstabColumnGroupFactory.ATTRIBUTE_headerPosition, group.getPosition(), JRXmlConstants.getCrosstabColumnPositionMap(), JRCellContents.POSITION_X_LEFT); 2363 2364 writeBucket(group.getBucket()); 2365 2366 JRCellContents header = group.getHeader(); 2367 writer.startElement("crosstabColumnHeader"); 2368 writeCellContents(header); 2369 writer.closeElement(); 2370 2371 JRCellContents totalHeader = group.getTotalHeader(); 2372 writer.startElement("crosstabTotalColumnHeader"); 2373 writeCellContents(totalHeader); 2374 writer.closeElement(); 2375 2376 writer.closeElement(); 2377 } 2378 2379 2380 protected void writeBucket(JRCrosstabBucket bucket) throws IOException 2381 { 2382 writer.startElement("bucket"); 2383 writer.addAttribute(JRCrosstabBucketFactory.ATTRIBUTE_order, bucket.getOrder(), JRXmlConstants.getCrosstabBucketOrderMap(), BucketDefinition.ORDER_ASCENDING); 2384 writer.writeExpression("bucketExpression", bucket.getExpression(), true); 2385 writer.writeExpression("comparatorExpression", bucket.getComparatorExpression(), false); 2386 writer.closeElement(); 2387 } 2388 2389 2390 protected void writeCrosstabMeasure(JRCrosstabMeasure measure) throws IOException 2391 { 2392 writer.startElement("measure"); 2393 writer.addEncodedAttribute(JRCrosstabMeasureFactory.ATTRIBUTE_name, measure.getName()); 2394 writer.addAttribute(JRCrosstabMeasureFactory.ATTRIBUTE_class, measure.getValueClassName()); 2395 writer.addAttribute(JRCrosstabMeasureFactory.ATTRIBUTE_calculation, measure.getCalculation(), JRXmlConstants.getCalculationMap(), JRVariable.CALCULATION_NOTHING); 2396 writer.addAttribute(JRCrosstabMeasureFactory.ATTRIBUTE_percentageOf, measure.getPercentageOfType(), JRXmlConstants.getCrosstabPercentageMap(), JRCrosstabMeasure.PERCENTAGE_TYPE_NONE); 2397 writer.addAttribute(JRCrosstabMeasureFactory.ATTRIBUTE_percentageCalculatorClass, measure.getPercentageCalculatorClassName()); 2398 writer.writeExpression("measureExpression", measure.getValueExpression(), false); 2399 writer.closeElement(); 2400 } 2401 2402 2403 protected void writeCrosstabCell(JRCrosstabCell cell) throws IOException 2404 { 2405 writer.startElement("crosstabCell"); 2406 writer.addAttribute(JRCrosstabCellFactory.ATTRIBUTE_width, cell.getWidth()); 2407 writer.addAttribute(JRCrosstabCellFactory.ATTRIBUTE_height, cell.getHeight()); 2408 writer.addEncodedAttribute(JRCrosstabCellFactory.ATTRIBUTE_rowTotalGroup, cell.getRowTotalGroup()); 2409 writer.addEncodedAttribute(JRCrosstabCellFactory.ATTRIBUTE_columnTotalGroup, cell.getColumnTotalGroup()); 2410 2411 writeCellContents(cell.getContents()); 2412 2413 writer.closeElement(); 2414 } 2415 2416 2417 protected void writeCellContents(JRCellContents contents) throws IOException 2418 { 2419 if (contents != null) 2420 { 2421 writer.startElement("cellContents"); 2422 writer.addAttribute(JRCellContentsFactory.ATTRIBUTE_backcolor, contents.getBackcolor()); 2423 writer.addAttribute("mode", contents.getMode(), JRXmlConstants.getModeMap()); 2424 JRStyle style = contents.getStyle(); 2425 if (style != null) 2426 { 2427 writer.addEncodedAttribute(JRCellContentsFactory.ATTRIBUTE_style, style.getName()); 2428 } 2429 2430 writeBox(contents.getBox()); 2431 2432 List children = contents.getChildren(); 2433 if (children != null) 2434 { 2435 for (Iterator it = children.iterator(); it.hasNext();) 2436 { 2437 JRChild element = (JRChild) it.next(); 2438 element.writeXml(this); 2439 } 2440 } 2441 2442 writer.closeElement(); 2443 } 2444 } 2445 2446 2447 protected void writeCrosstabParameter(JRCrosstabParameter parameter) throws IOException 2448 { 2449 writer.startElement("crosstabParameter"); 2450 writer.addEncodedAttribute("name", parameter.getName()); 2451 writer.addAttribute("class", parameter.getValueClassName(), "java.lang.String"); 2452 writer.writeExpression("parameterValueExpression", parameter.getExpression(), false); 2453 writer.closeElement(); 2454 } 2455 2456 2457 public void writeDataset(JRDataset dataset) throws IOException 2458 { 2459 writer.startElement(JRDatasetFactory.ELEMENT_subDataset); 2460 writer.addEncodedAttribute(JRDatasetFactory.ATTRIBUTE_name, dataset.getName()); 2461 writer.addAttribute(JRDatasetFactory.ATTRIBUTE_scriptletClass, dataset.getScriptletClass()); 2462 writer.addEncodedAttribute(JRDatasetFactory.ATTRIBUTE_resourceBundle, dataset.getResourceBundle()); 2463 writer.addAttribute(JRDatasetFactory.ATTRIBUTE_whenResourceMissingType, dataset.getWhenResourceMissingType(), JRXmlConstants.getWhenResourceMissingTypeMap(), JRReport.WHEN_RESOURCE_MISSING_TYPE_NULL); 2464 2465 writeProperties(dataset.getPropertiesMap()); 2466 2467 writeDatasetContents(dataset); 2468 2469 writer.closeElement(); 2470 } 2471 2472 protected void writeDatasetContents(JRDataset dataset) throws IOException 2473 { 2474 2475 JRParameter[] parameters = dataset.getParameters(); 2476 if (parameters != null && parameters.length > 0) 2477 { 2478 for(int i = 0; i < parameters.length; i++) 2479 { 2480 if (!parameters[i].isSystemDefined()) 2481 { 2482 writeParameter(parameters[i]); 2483 } 2484 } 2485 } 2486 2487 2488 if(dataset.getQuery() != null) 2489 { 2490 writeQuery(dataset.getQuery()); 2491 } 2492 2493 2494 JRField[] fields = dataset.getFields(); 2495 if (fields != null && fields.length > 0) 2496 { 2497 for(int i = 0; i < fields.length; i++) 2498 { 2499 writeField(fields[i]); 2500 } 2501 } 2502 2503 2504 JRSortField[] sortFields = dataset.getSortFields(); 2505 if (sortFields != null && sortFields.length > 0) 2506 { 2507 for(int i = 0; i < sortFields.length; i++) 2508 { 2509 writeSortField(sortFields[i]); 2510 } 2511 } 2512 2513 2514 JRVariable[] variables = dataset.getVariables(); 2515 if (variables != null && variables.length > 0) 2516 { 2517 for(int i = 0; i < variables.length; i++) 2518 { 2519 if (!variables[i].isSystemDefined()) 2520 { 2521 writeVariable(variables[i]); 2522 } 2523 } 2524 } 2525 2526 writer.writeExpression(JRDatasetFactory.ELEMENT_filterExpression, dataset.getFilterExpression(), false); 2527 2528 2529 JRGroup[] groups = dataset.getGroups(); 2530 if (groups != null && groups.length > 0) 2531 { 2532 for(int i = 0; i < groups.length; i++) 2533 { 2534 writeGroup(groups[i]); 2535 } 2536 } 2537 } 2538 2539 2540 protected void writeDatasetRun(JRDatasetRun datasetRun) throws IOException 2541 { 2542 writer.startElement(JRDatasetRunFactory.ELEMENT_datasetRun); 2543 writer.addEncodedAttribute(JRDatasetRunFactory.ATTRIBUTE_subDataset, datasetRun.getDatasetName()); 2544 2545 writer.writeExpression("parametersMapExpression", datasetRun.getParametersMapExpression(), false); 2546 2547 2548 JRDatasetParameter[] parameters = datasetRun.getParameters(); 2549 if (parameters != null && parameters.length > 0) 2550 { 2551 for(int i = 0; i < parameters.length; i++) 2552 { 2553 writeDatasetParameter(parameters[i]); 2554 } 2555 } 2556 2557 writer.writeExpression("connectionExpression", datasetRun.getConnectionExpression(), false); 2558 writer.writeExpression("dataSourceExpression", datasetRun.getDataSourceExpression(), false); 2559 2560 writer.closeElement(); 2561 } 2562 2563 2564 public void writeFrame(JRFrame frame) throws IOException 2565 { 2566 writer.startElement(JRFrameFactory.ELEMENT_frame); 2567 2568 writeReportElement(frame); 2569 writeBox(frame); 2570 2571 List children = frame.getChildren(); 2572 if (children != null) 2573 { 2574 for (Iterator it = children.iterator(); it.hasNext();) 2575 { 2576 JRChild element = (JRChild) it.next(); 2577 element.writeXml(this); 2578 } 2579 } 2580 2581 writer.closeElement(); 2582 } 2583 2584 2585 protected void writeHyperlinkParameters(JRHyperlinkParameter[] parameters) throws IOException 2586 { 2587 if (parameters != null) 2588 { 2589 for (int i = 0; i < parameters.length; i++) 2590 { 2591 JRHyperlinkParameter parameter = parameters[i]; 2592 writeHyperlinkParameter(parameter); 2593 } 2594 } 2595 } 2596 2597 2598 protected void writeHyperlinkParameter(JRHyperlinkParameter parameter) throws IOException 2599 { 2600 if (parameter != null) 2601 { 2602 writer.startElement(JRHyperlinkParameterFactory.ELEMENT_hyperlinkParameter); 2603 writer.addEncodedAttribute(JRHyperlinkParameterFactory.ATTRIBUTE_name, parameter.getName()); 2604 2605 writer.writeExpression(JRHyperlinkParameterExpressionFactory.ELEMENT_hyperlinkParameterExpression, 2606 parameter.getValueExpression(), true, String .class.getName()); 2607 2608 writer.closeElement(); 2609 } 2610 } 2611 2612 2613 protected void writeHyperlink(String tagName, JRHyperlink hyperlink) throws IOException 2614 { 2615 if (hyperlink != null) 2616 { 2617 writer.startElement(tagName); 2618 2619 writer.addEncodedAttribute("hyperlinkType", hyperlink.getLinkType()); 2620 writer.addAttribute("hyperlinkTarget", hyperlink.getHyperlinkTarget(), JRXmlConstants.getHyperlinkTargetMap(), JRHyperlink.HYPERLINK_TARGET_SELF); 2621 2622 writer.writeExpression("hyperlinkReferenceExpression", hyperlink.getHyperlinkReferenceExpression(), false); 2623 writer.writeExpression("hyperlinkAnchorExpression", hyperlink.getHyperlinkAnchorExpression(), false); 2624 writer.writeExpression("hyperlinkPageExpression", hyperlink.getHyperlinkPageExpression(), false); 2625 writer.writeExpression(JRHyperlinkFactory.ELEMENT_hyperlinkTooltipExpression, hyperlink.getHyperlinkTooltipExpression(), false); 2626 writeHyperlinkParameters(hyperlink.getHyperlinkParameters()); 2627 2628 writer.closeElement(); 2629 } 2630 } 2631} 2632 | Popular Tags |