protected void copyTemplates(JRReport report, JRBaseObjectFactory factory) { JRReportTemplate[] reportTemplates = report.getTemplates(); if (reportTemplates == null || reportTemplates.length == 0) { templates = null; } else { templates = new JRReportTemplate[reportTemplates.length]; for (int i = 0; i < reportTemplates.length; i++) { templates[i] = factory.getReportTemplate(reportTemplates[i]); } } }
/** * */ protected void writeTemplates(JRReport report, String indent) { JRReportTemplate[] templates = report.getTemplates(); if (templates != null) { for (int i = 0; i < templates.length; i++) { JRReportTemplate template = templates[i]; writeTemplate( template, "reportTemplate" + i); write( "jasperDesign.addTemplate(reportTemplate" + i + ");\n"); } write("\n"); flush(); } }
public static List<?> getGroupList(TableComponent table, JRReport report) { List<?> groupsList = null; JRDatasetRun datasetRun = table.getDatasetRun(); if (datasetRun != null) { String dataSetName = datasetRun.getDatasetName(); JRDataset[] datasets = report.getDatasets(); if (datasets != null && dataSetName != null) { for (JRDataset ds : datasets) { JRGroup[] groups = ds.getGroups(); if (dataSetName.equals(ds.getName()) && groups != null) { groupsList = Arrays.asList(groups); break; } } } } return groupsList; }
/** * */ public static String getVersion(JasperReportsContext jasperReportsContext, JRPart part, JRXmlWriter reportWriter) { String version = null; ComponentKey componentKey = part.getComponentKey(); String versionProperty = PROPERTY_PART_COMPONENTS_PREFIX + componentKey.getName() + AbstractComponentXmlWriter.PROPERTY_COMPONENTS_VERSION_SUFFIX; if (part.getPropertiesMap().containsProperty(versionProperty)) { version = part.getPropertiesMap().getProperty(versionProperty); } else { JRReport report = reportWriter.getReport(); version = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(report, versionProperty); if (version == null) { version = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(report, JRXmlBaseWriter.PROPERTY_REPORT_VERSION); } } return version; }
/** * */ public ReportConverter(JasperReportsContext jasperReportsContext, JRReport report, boolean ignoreContent) { this.jasperReportsContext = jasperReportsContext; this.componentsEnvironment = ComponentsEnvironment.getInstance(jasperReportsContext); this.report = report; this.locale = readLocale();//allow to pass this explicitly? this.timezone = readTimeZone(); if (report instanceof JasperDesign) { ((JasperDesign)report).preprocess(); } convert(ignoreContent); }
protected void loadReportStyles(JRReport report) { JRReportTemplate[] templates = report.getTemplates(); if (templates != null) { Set<String> loadedLocations = new HashSet<String>(); for (int i = 0; i < templates.length; i++) { loadReportTemplateStyles(templates[i], loadedLocations); } } collectStyles(report.getStyles()); }
/** * */ public String write(JRReport report, String encoding) { StringWriter buffer = new StringWriter(); try { writeReport(report, encoding, buffer); } catch (IOException e) { // doesn't actually happen throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_REPORT_DESIGN_WRITE_ERROR, (Object[])null, e); } return buffer.toString(); }
/** * */ public void write( JRReport report, OutputStream outputStream, String encoding ) throws JRException { try { Writer out = new OutputStreamWriter(outputStream, encoding); writeReport(report, encoding, out); } catch (Exception e) { throw new JRException( EXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITE_ERROR, new Object[]{report.getName()}, e); } }
protected void writeTemplates(JRReport report) throws IOException { JRReportTemplate[] templates = report.getTemplates(); if (templates != null) { for (int i = 0; i < templates.length; i++) { JRReportTemplate template = templates[i]; writeTemplate(template); } } }
/** * */ public void write( JRReport report, OutputStream outputStream ) throws JRException { try { String encoding = report.getProperty(WriterExporterOutput.PROPERTY_CHARACTER_ENCODING) != null ? report.getProperty(WriterExporterOutput.PROPERTY_CHARACTER_ENCODING) : "UTF-8"; Writer out = new OutputStreamWriter(outputStream, encoding); writeReport(report, out); } catch (Exception e) { throw new JRException( EXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITE_ERROR, new Object[]{report.getName()}, e); } }
/** * Visits all the elements of a report. * * @param report the report */ public void visitReport(JRReport report) { visitBand(report.getBackground()); visitBand(report.getTitle()); visitBand(report.getPageHeader()); visitBand(report.getColumnHeader()); visitSection(report.getDetailSection()); visitBand(report.getColumnFooter()); visitBand(report.getPageFooter()); visitBand(report.getLastPageFooter()); visitBand(report.getSummary()); visitBand(report.getNoData()); JRGroup[] groups = report.getGroups(); if (groups != null) { for(int i = 0; i < groups.length; i++) { JRGroup group = groups[i]; visitSection(group.getGroupHeaderSection()); visitSection(group.getGroupFooterSection()); } } }
@Override protected void checkLanguage(String language) throws JRException { if (!JRReport.LANGUAGE_JAVA.equals(language)) { throw new JRException( EXCEPTION_MESSAGE_KEY_EXPECTED_JAVA_LANGUAGE, new Object[]{language, JRReport.LANGUAGE_JAVA}); } }
protected static String getUnitName(JRReport report, JRDataset dataset, String nameSuffix) { String className; if (dataset.isMainDataset()) { className = report.getName(); } else { className = report.getName() + "_" + dataset.getName(); } className = JRStringUtil.getJavaIdentifier(className) + nameSuffix; return className; }
/** * */ public DrawVisitor(ReportConverter reportConverter, Graphics2D grx) { this.convertVisitor = new ConvertVisitor(reportConverter); JasperReportsContext jasperReportsContext = reportConverter.getJasperReportsContext(); JRReport report = reportConverter.getReport(); JRPropertiesUtil propUtil = JRPropertiesUtil.getInstance(jasperReportsContext); this.drawVisitor = new PrintDrawVisitor( jasperReportsContext, new RenderersCache(jasperReportsContext), propUtil.getBooleanProperty(report, Graphics2DReportConfiguration.MINIMIZE_PRINTER_JOB_SIZE, true), propUtil.getBooleanProperty(report, JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT, false) ); setGraphics2D(grx); this.drawVisitor.setClip(true); }
/** * */ protected WhenNoDataTypeEnum getWhenNoDataType() { WhenNoDataTypeEnum result = whenNoDataType; if (result == null) { result = WhenNoDataTypeEnum.getByName( propertiesUtil.getProperty(mainDataset, JRReport.CONFIG_PROPERTY_WHEN_NO_DATA_TYPE) ); } return result; }
/** * */ public static String getVersion(JasperReportsContext jasperReportsContext, JRComponentElement componentElement, JRXmlWriter reportWriter) { String version = null; ComponentKey componentKey = componentElement.getComponentKey(); String versionProperty = PROPERTY_COMPONENTS_PREFIX + componentKey.getName() + PROPERTY_COMPONENTS_VERSION_SUFFIX; if (componentElement.getPropertiesMap().containsProperty(versionProperty)) { version = componentElement.getPropertiesMap().getProperty(versionProperty); } else { JRReport report = reportWriter.getReport(); version = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(report, versionProperty); if (version == null) { version = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(report, JRXmlBaseWriter.PROPERTY_REPORT_VERSION); } } return version; }
public static String[] getExpressionLanguages(JasperReportsConfiguration jconfig) { Set<String> compilers = new HashSet<String>(); compilers.add(JRReport.LANGUAGE_JAVA); Map<String, String> params = jconfig.getProperties(); for (String key : params.keySet()) { if (key.startsWith(JRCompiler.COMPILER_PREFIX)) { try { if (jconfig.getClassLoader() != null) { Class<?> clazz = jconfig.getClassLoader().loadClass(params.get(key)); if (JRCompiler.class.isAssignableFrom(clazz)) compilers.add(key.substring(JRCompiler.COMPILER_PREFIX.length()).toLowerCase()); } } catch (ClassNotFoundException e) { } } } String[] langs = new String[compilers.size() + 1]; langs[0] = ""; //$NON-NLS-1$ int i = 1; for (String lang : compilers) langs[i++] = lang; return langs; }
public ExpressionInterpreter(JRDesignDataset dataset, JasperDesign jasperDesign, JasperReportsConfiguration jConfig) { try { this.jConfig = jConfig; if (jasperDesign.getLanguage().equalsIgnoreCase(JRReport.LANGUAGE_JAVA)) interpreter = new JavaInterpreter(); else if (jasperDesign.getLanguage().equalsIgnoreCase(JRReport.LANGUAGE_GROOVY)) interpreter = new GroovyInterpretter(); else if (jasperDesign.getLanguage().equalsIgnoreCase("bsh")) interpreter = new JavaInterpreter(); else if (jasperDesign.getLanguage().equalsIgnoreCase("jeval")) interpreter = new JEvalInterpreter(); if (interpreter != null) interpreter.prepareExpressionEvaluator(dataset, jasperDesign, jConfig); } catch (Exception ex) { ex.printStackTrace(); } }
/** * */ public JSSDrawVisitor(ReportConverter reportConverter, Graphics2D grx) { this.reportConverter = reportConverter; this.convertVisitor = new JSSConvertVisitor(reportConverter); final JasperReportsContext jasperReportsContext = reportConverter.getJasperReportsContext(); this.drawVisitor = new PrintDrawVisitor(jasperReportsContext) { @Override public void setTextRenderer(JRReport report) { AwtTextRenderer textRenderer = new AwtTextRenderer(jasperReportsContext, JRPropertiesUtil.getInstance( jasperReportsContext).getBooleanProperty(report, JRGraphics2DExporter.MINIMIZE_PRINTER_JOB_SIZE, true), JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(report, JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT, false)); setTextDrawer(new TextDrawer(jasperReportsContext, textRenderer)); setFrameDrawer(new FrameDrawer(jasperReportsContext, null, textRenderer)); } }; setTextRenderer(reportConverter.getReport()); this.grx = grx; setGraphics2D(grx); this.drawVisitor.setClip(true); }
protected String getVersion(JRComponentElement componentElement, JRXmlWriter reportWriter) { String version = null; ComponentKey componentKey = componentElement.getComponentKey(); String versionProperty = PROPERTY_COMPONENTS_PREFIX + componentKey.getName() + PROPERTY_COMPONENTS_VERSION_SUFFIX; if (componentElement.getPropertiesMap().containsProperty(versionProperty)) { version = componentElement.getPropertiesMap() .getProperty(versionProperty); } else { JRReport report = reportWriter.getReport(); version = JRPropertiesUtil.getInstance(jasperReportsContext) .getProperty(report, versionProperty); if (version == null) { version = JRPropertiesUtil.getInstance(jasperReportsContext) .getProperty(report, JRXmlBaseWriter.PROPERTY_REPORT_VERSION); } } return version; }
/** * */ public JasperDesignViewer( JasperReportsContext jasperReportsContext, JRReport report ) throws JRException { initComponents(); net.sf.jasperreports.swing.JRDesignViewer viewer = new net.sf.jasperreports.swing.JRDesignViewer(jasperReportsContext, report); this.pnlMain.add(viewer, BorderLayout.CENTER); }
/** * */ public static void viewReportDesign( JasperReportsContext jasperReportsContext, JRReport report ) throws JRException { JasperDesignViewer jasperDesignViewer = new JasperDesignViewer(jasperReportsContext, report); jasperDesignViewer.setVisible(true); }
/** * Constructs a copy of a report. */ public JRBaseReport(JRReport report, JRBaseObjectFactory factory) { /* */ name = report.getName(); language = report.getLanguage(); columnCount = report.getColumnCount(); printOrderValue = report.getPrintOrderValue(); columnDirection = report.getColumnDirection(); pageWidth = report.getPageWidth(); pageHeight = report.getPageHeight(); orientationValue = report.getOrientationValue(); whenNoDataTypeValue = report.getWhenNoDataTypeValue(); sectionType = report.getSectionType(); columnWidth = report.getColumnWidth(); columnSpacing = report.getColumnSpacing(); leftMargin = report.getLeftMargin(); rightMargin = report.getRightMargin(); topMargin = report.getTopMargin(); bottomMargin = report.getBottomMargin(); isTitleNewPage = report.isTitleNewPage(); isSummaryNewPage = report.isSummaryNewPage(); isSummaryWithPageHeaderAndFooter = report.isSummaryWithPageHeaderAndFooter(); isFloatColumnFooter = report.isFloatColumnFooter(); ignorePagination = report.isIgnorePagination(); formatFactoryClass = report.getFormatFactoryClass(); /* */ String[] imports = report.getImports(); if (imports != null && imports.length > 0) { importsSet = new HashSet<String>(imports.length); importsSet.addAll(Arrays.asList(imports)); } /* */ factory.setDefaultStyleProvider(this); copyTemplates(report, factory); /* */ defaultStyle = factory.getStyle(report.getDefaultStyle()); /* */ JRStyle[] jrStyles = report.getStyles(); if (jrStyles != null && jrStyles.length > 0) { styles = new JRStyle[jrStyles.length]; for(int i = 0; i < styles.length; i++) { styles[i] = factory.getStyle(jrStyles[i]); } } mainDataset = factory.getDataset(report.getMainDataset()); JRDataset[] datasetArray = report.getDatasets(); if (datasetArray != null && datasetArray.length > 0) { datasets = new JRDataset[datasetArray.length]; for (int i = 0; i < datasets.length; i++) { datasets[i] = factory.getDataset(datasetArray[i]); } } background = factory.getBand(report.getBackground()); title = factory.getBand(report.getTitle()); pageHeader = factory.getBand(report.getPageHeader()); columnHeader = factory.getBand(report.getColumnHeader()); detailSection = factory.getSection(report.getDetailSection()); columnFooter = factory.getBand(report.getColumnFooter()); pageFooter = factory.getBand(report.getPageFooter()); lastPageFooter = factory.getBand(report.getLastPageFooter()); summary = factory.getBand(report.getSummary()); noData = factory.getBand(report.getNoData()); }
/** * @see #write(JRReport, String, String) */ public static void writeReport( JRReport report, String destFileName, String encoding ) throws JRException { new JRXmlWriter(DefaultJasperReportsContext.getInstance()).write(report, destFileName, encoding); }
/** * @see #write(JRReport, OutputStream, String) */ public static void writeReport( JRReport report, OutputStream outputStream, String encoding ) throws JRException { new JRXmlWriter(DefaultJasperReportsContext.getInstance()).write(report, outputStream, encoding); }
/** * */ public String write(JRReport report) { StringWriter buffer = new StringWriter();//FIXME use file buffered writer writeReport(report, buffer); return buffer.toString(); }
/** * @see #write(JRReport, String) */ public static void writeReport( JRReport report, String destFileName ) throws JRException { new JRApiWriter(DefaultJasperReportsContext.getInstance()).write(report, destFileName); }
/** * @see #write(JRReport, OutputStream) */ public static void writeReport( JRReport report, OutputStream outputStream ) throws JRException { new JRApiWriter(DefaultJasperReportsContext.getInstance()).write(report, outputStream); }
protected static String getUnitName(JRReport report, JRCrosstab crosstab, JRExpressionCollector expressionCollector, String nameSuffix) { Integer crosstabId = expressionCollector.getCrosstabId(crosstab); if (crosstabId == null) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_CROSSTAB_ID_NOT_FOUND, (Object[])null); } return getUnitName(report, crosstabId.intValue(), nameSuffix); }
/** * @deprecated Replaced by {@link #PrintDrawVisitor(JasperReportsContext, RenderersCache, boolean, boolean)}. */ public void setTextRenderer(JRReport report) { AwtTextRenderer textRenderer = new AwtTextRenderer( jasperReportsContext, JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(report, Graphics2DReportConfiguration.MINIMIZE_PRINTER_JOB_SIZE, true), JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(report, JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT, false) ); textDrawer = new TextDrawer(jasperReportsContext, textRenderer); frameDrawer = new FrameDrawer(jasperReportsContext, null, textRenderer); }
@Override protected void checkLanguage(String language) throws JRException { if ( !LANGUAGE_BSH.equals(language) && !JRReport.LANGUAGE_JAVA.equals(language) ) { throw new JRException( EXCEPTION_MESSAGE_KEY_LANGUAGE_NOT_SUPPORTED, new Object[]{language, LANGUAGE_BSH, JRReport.LANGUAGE_JAVA}); } }
@Override protected void checkLanguage(String language) throws JRException { if ( !JRReport.LANGUAGE_GROOVY.equals(language) && !JRReport.LANGUAGE_JAVA.equals(language) ) { throw new JRException( EXCEPTION_MESSAGE_KEY_LANGUAGE_NOT_SUPPORTED, new Object[]{language, JRReport.LANGUAGE_GROOVY, JRReport.LANGUAGE_JAVA}); } }
public List<PropertyMetadata> getReportProperties(JRReport report) { Collection<PropertyMetadata> allProperties = allProperties(); List<PropertyMetadata> reportProperties = new ArrayList<PropertyMetadata>(); for (PropertyMetadata propertyMetadata : allProperties) { List<PropertyScope> scopes = propertyMetadata.getScopes(); if (scopes != null && scopes.contains(PropertyScope.REPORT)) { reportProperties.add(propertyMetadata); } } return reportProperties; }
@Override protected void setReport(String fileName, boolean isXmlReport) throws JRException { if (isXmlReport) { JasperDesign jasperDesign = JRXmlLoader.load(fileName); setReport(jasperDesign); } else { setReport((JRReport) JRLoader.loadObjectFromFile(fileName)); } }
@Override protected void setReport(InputStream is, boolean isXmlReport) throws JRException { if (isXmlReport) { JasperDesign jasperDesign = JRXmlLoader.load(is); setReport(jasperDesign); } else { setReport((JRReport) JRLoader.loadObject(is)); } }
/** * */ public JRDesignViewer( JasperReportsContext jasperReportsContext, JRReport report ) throws JRException { super(jasperReportsContext, new ReportConverter(jasperReportsContext, report, false).getJasperPrint(), null, null); //reconfigureReloadButton(); hideUnusedComponents(); }
public static String writeReport(JasperReportsContext jrContext, JRReport report, String encoding, String version) throws Exception { encoding = fixencoding(encoding); if (!writers.contains(version)) version = LAST_VERSION; if (jrContext == null) jrContext = JasperReportsConfiguration.getDefaultJRConfig(); jrContext.removeProperty(JRXmlBaseWriter.PROPERTY_REPORT_VERSION); if (writers.contains(version)) jrContext.setProperty(JRXmlBaseWriter.PROPERTY_REPORT_VERSION, version); if (report != null) { // jrContext.setProperty("net.sf.jasperreports.components.table.version", version); String xml = new JRXmlWriter(jrContext).write(report, encoding); // request Bug 37455 - [Case #48613] Simple jrxml timestamp on Save or Save As String timestamp = "<!-- " + DateFormatUtils.ISO_DATETIME_FORMAT.format(new Date()) + " -->\r\n"; // Replace with a more meaningful JR version if(version.equals(LAST_VERSION)){ version = getInstalledJasperReportsVersion(); } // Get JSS bundle version String jssPluginVersion = JaspersoftStudioPlugin.getInstance().getBundle().getVersion().toString(); String jrVersionTxt = " using PDFReporter Library version " + version + " "; xml = xml .replaceFirst( "<jasperReport ", "<!-- Created with PDFReporter Studio version " + jssPluginVersion + jrVersionTxt + " -->\r\n" + timestamp + "<jasperReport "); //$NON-NLS-1$ //$NON-NLS-2$ return xml; } return null; }
public static void loadFileIntoViewer(final IFile file, final IReportViewer viewer, Display display) { display.asyncExec(new Runnable() { public void run() { ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { ClassLoader projectClassLoader = createProjectClassLoader(file.getProject()); if (projectClassLoader != null) { Thread.currentThread().setContextClassLoader(projectClassLoader); } try { JRReport report = ReportLoader.loadReport(file); if (report == null) { viewer.setReport(null); } else { viewer.setReport(new ReportConverter(DefaultJasperReportsContext.getInstance(), report, false).getJasperPrint()); } } catch (Throwable t) { UIUtils.showError(t); } } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } } }); }
public static String writeReport(JRReport report, String encoding) throws Exception { // The user does not want to use compatibility... JRXmlWriter writer = new JRXmlWriter(new VersionJRContext(null)); return writer.write(report, encoding); }