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(); } }
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()); }
protected void loadReportTemplateStyles(JRReportTemplate template, Set<String> loadedLocations) { JRExpression sourceExpression = template.getSourceExpression(); if (sourceExpression != null) { String location = JRExpressionUtil.getSimpleExpressionText(sourceExpression); if (location == null) { log.warn("Template source expression " + sourceExpression.getText() + "cannot be evaluated; some styles might remain unresolved."); } else { HashSet<String> parentLocations = new HashSet<String>(); loadTemplateStyles(location, loadedLocations, parentLocations); } } }
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 File publish(JasperDesign jd, JRReportTemplate img, MReportUnit mrunit, IProgressMonitor monitor, Set<String> fileset, IFile file) throws Exception { AFileResource fres = findFile(mrunit, monitor, jd, fileset, getExpression(img), file); if (fres != null) { JRSimpleTemplate jrt = (JRSimpleTemplate) JRXmlTemplateLoader.load(fres.getFile()); for (JRTemplateReference r : jrt.getIncludedTemplatesList()) { IFile[] fs = root.findFilesForLocationURI(fres.getFile().toURI()); if (fs != null && fs.length > 0) { File ftr = findFile(file, r.getLocation()); if (ftr != null && ftr.exists()) { fileset.add(ftr.getAbsolutePath()); addResource(monitor, mrunit, fileset, ftr, new PublishOptions()); } } } return fres.getFile(); } return null; }
/** * Resolve an expression and return the reference to the style or null if it can not be resolve * * @param styleExpression expression of the external style * @param project project of the report * @param jConfig Configuration of the report to evaluate the expression * @return path of the style of null if the expression can't be resolved */ public static String evaluateStyleExpression(JRReportTemplate style, IFile project, JasperReportsConfiguration jConfig){ String evaluatedExpression = null; String projectPath = project.getLocation().toPortableString(); JRExpression styleExpression = style.getSourceExpression(); String expString = styleExpression != null ? styleExpression.getText() : ""; try{ //Check first if there are previous failed attempt to evaluate the expression if (!isNotValuable(projectPath, expString)){ evaluatedExpression = ExpressionUtil.cachedExpressionEvaluation(styleExpression, jConfig); if (evaluatedExpression == null){ //The expression is not valuable, add it to the map addNotValuableExpression(projectPath, expString); fireEvent(STYLE_NOT_FOUND_EVENT, style); } } }catch(Exception ex){ ex.printStackTrace(); //The expression is not valuable, add it to the map addNotValuableExpression(projectPath, expString); fireEvent(STYLE_NOT_FOUND_EVENT, style); } return evaluatedExpression; }
/** * If the expression of an external style can be resolved then return all the jrstyle defined inside * otherwise return an empty list * * @param styleExpression expression of the external style * @param project project of the report * @param jConfig Configuration of the report to evaluate the expression * @return Not null list of styles inside the external style associated with the project and expression */ public static List<JRStyle> getStyles(JRReportTemplate style, IFile project, JasperReportsConfiguration jConfig) { String evaluatedExpression = evaluateStyleExpression(style, project, jConfig); if (evaluatedExpression != null) { File styleFile = StyleTemplateFactory.getFile(evaluatedExpression, project); if (styleFile != null) { String key = styleFile.getAbsolutePath(); List<JRStyle> cachedStyles = externalStylesCache.get(key); if (cachedStyles == null) { cachedStyles = new ArrayList<JRStyle>(); StyleTemplateFactory.getStylesReference(project, evaluatedExpression, cachedStyles, new HashSet<File>()); externalStylesCache.put(key, cachedStyles); } fireEvent(STYLE_FOUND_EVENT, style); return cachedStyles; } else { String projectPath = project.getLocation().toPortableString(); JRExpression styleExpression = style.getSourceExpression(); String expString = styleExpression != null ? styleExpression.getText() : ""; addNotValuableExpression(projectPath, expString); fireEvent(STYLE_NOT_FOUND_EVENT, style); } } return new ArrayList<JRStyle>(); }
@Override public List getTagList() { List tags = new ArrayList(); tags.add(new Tag( null , "")); List styles = jasperDesign.getStylesList(); for (int i=0; i<styles.size(); ++i) { JRDesignStyle style = (JRDesignStyle)styles.get(i); tags.add(new Tag( style , style.getName())); style.getEventSupport().addPropertyChangeListener( WeakListeners.propertyChange(this, style.getEventSupport()) ); } // Add all the references too... JRReportTemplate[] templates = jasperDesign.getTemplates(); for (int i=0; i<templates.length; ++i) { tags.addAll(getStyleInTemplate(templates[i])); } return tags; }
protected static void addTemplateRules(Digester digester) { String templatePattern = JRXmlConstants.ELEMENT_jasperReport + "/" + JRXmlConstants.ELEMENT_template; //do not change the order digester.addObjectCreate(templatePattern, JRDesignReportTemplate.class); digester.addSetNext(templatePattern, "addTemplate", JRReportTemplate.class.getName()); @SuppressWarnings("deprecation") Class<?> lcDepStringExprFactoryClass = JRStringExpressionFactory.class; digester.addFactoryCreate(templatePattern, lcDepStringExprFactoryClass); digester.addCallMethod(templatePattern, "setText", 0); digester.addSetNext(templatePattern, "setSourceExpression", JRExpression.class.getName()); }
/** * * @param template * @throws IOException */ protected void writeTemplate(JRReportTemplate template) throws IOException { writeExpression( JRXmlConstants.ELEMENT_template, template.getSourceExpression(), true, String.class.getName()); }
/** * */ protected void writeTemplate( JRReportTemplate template, String templateName) { write( "JRDesignReportTemplate " + templateName + " = new JRDesignReportTemplate();\n"); writeExpression( template.getSourceExpression(), templateName, "SourceExpression", String.class.getName()); flush(); }
protected void verifyReportTemplates() { JRReportTemplate[] templates = jasperDesign.getTemplates(); if (templates != null) { for (int i = 0; i < templates.length; i++) { JRReportTemplate template = templates[i]; verifyTemplate(template); } } }
protected void verifyTemplate(JRReportTemplate template) { JRExpression sourceExpression = template.getSourceExpression(); if (sourceExpression == null) { addBrokenRule("Template source expression missing.", template); } }
/** * Removes a report template. * * @param template the template to remove * @return <code>true</code> if and only if the template has been found and removed */ public boolean removeTemplate(JRReportTemplate template) { int idx = templateList.indexOf(template); if (idx >= 0) { templateList.remove(idx); getEventSupport().fireCollectionElementRemovedEvent(PROPERTY_TEMPLATES, template, idx); return true; } return false; }
public JRFillReportTemplate(JRReportTemplate template, JRBaseFiller filler, JRFillObjectFactory factory) { factory.put(template, this); parent = template; this.filler = filler; }
public JRFillReportTemplate getReportTemplate(JRReportTemplate template) { JRFillReportTemplate fillTemplate = null; if (template != null) { fillTemplate = (JRFillReportTemplate) get(template); if (fillTemplate == null) { fillTemplate = new JRFillReportTemplate(template, filler, this); } } return fillTemplate; }
protected void createReportTemplates(JRFillObjectFactory factory) { JRReportTemplate[] templates = jasperReport.getTemplates(); if (templates != null) { reportTemplates = new JRFillReportTemplate[templates.length]; for (int i = 0; i < templates.length; i++) { JRReportTemplate template = templates[i]; reportTemplates[i] = factory.getReportTemplate(template); } } }
/** * Fire an event of style found or not found * * @param event the text of the event, should be STYLE_NOT_FOUND_EVENT or STYLE_FOUND_EVENT * @param element JRelement of the template style */ private static void fireEvent(String event, JRReportTemplate element){ if (element instanceof JRChangeEventsSupport){ JRChangeEventsSupport eventElement = (JRChangeEventsSupport)element; eventElement.getEventSupport().firePropertyChange(event, null, null); } }
/** * Search in all the external styles template of a report a style with a specific name * and return it. If it can't be found it return null, and if there are more styles in * different templates with the searched name then the first one found is returned * * @param styleName the name of the style searched * @param jConfig jasper configuration of the report * @return a JRStyle reference of the searched style or null if it can't be found between * the defined external styles */ public static JRStyle getExternalStyle(String styleName, JasperReportsConfiguration jConfig){ JasperDesign design = jConfig.getJasperDesign(); if (design != null){ IFile project = (IFile) jConfig.get(FileUtils.KEY_FILE); for (JRReportTemplate template : design.getTemplatesList()){ List<JRStyle> loadedStyles = getStyles(template, project, jConfig); JRStyle searchedStyle = searchStyleInList(loadedStyles, styleName); if (searchedStyle != null) return searchedStyle; } } return null; }
public static void createStyles(JasperReportsConfiguration jConfig, JasperDesign jd, ANode report, int index) { MStyles nStyle = new MStyles(report, index); if (jd.getTemplates() != null) for (Iterator<JRReportTemplate> it = jd.getTemplatesList().iterator(); it.hasNext();) createNode(nStyle, it.next(), -1, (IFile) jConfig.get(FileUtils.KEY_FILE)); if (jd.getStyles() != null) { for (JRStyle jrstyle : jd.getStylesList()) { ANode mstyle = createNode(nStyle, jrstyle, -1); if (((JRDesignStyle) jrstyle).getConditionalStyleList() != null) for (Object jrc : ((JRDesignStyle) jrstyle).getConditionalStyleList()) createNode(mstyle, jrc, -1); } } nStyle.updateDefaulStyle(); }
List getStyleInTemplate(JRReportTemplate template) { List styleNames = new ArrayList(); if (template != null) { String fileNameExp = Misc.getExpressionText(template.getSourceExpression()); if (fileNameExp != null && fileNameExp.length() > 0) { ExpressionFileResolver resolver = new ExpressionFileResolver( (JRDesignExpression)template.getSourceExpression(),jasperDesign.getMainDesignDataset(), jasperDesign); File f = resolver.resolveFile(null); if (f!=null && f.exists()) { try { // try to load this jrtx template... JRSimpleTemplate template2 = (JRSimpleTemplate) JRXmlTemplateLoader.load(new FileInputStream(f)); JRStyle[] styles = template2.getStyles(); for (int i=0; i<styles.length; ++i) { styleNames.add(new Tag(styles[i].getName(),I18n.getString("property.styleNameReference", styles[i].getName()))); } } catch (Exception ex) { ex.printStackTrace(); } } } } return styleNames; }
@Override public JRReportTemplate[] getTemplates() { return templates; }
public JRBaseReportTemplate(JRReportTemplate reportTemplate, JRAbstractObjectFactory factory) { factory.put(reportTemplate, this); sourceExpression = factory.getExpression(reportTemplate.getSourceExpression()); }
@Override public JRReportTemplate[] getTemplates() { return templateList.toArray(new JRReportTemplate[templateList.size()]); }
@Override public JRReportTemplate[] getTemplates() { // the parent report's templates are always used for the subreport return null; }
protected void publishTemplates(MReportUnit mrunit, IProgressMonitor monitor, JasperDesign jasper, Set<String> fileset, IFile file, String version) throws Exception { for (JRReportTemplate rt : jasper.getTemplatesList()) { impStyle.publish(jasper, rt, mrunit, monitor, fileset, file); } }
protected JRDesignExpression getExpression(JRReportTemplate img) { return (JRDesignExpression) ((JRReportTemplate) img).getSourceExpression(); }
private static List<JRStyle> getStyles(JasperReportsConfiguration jConfig, JasperDesign jd, IFile file) { List<JRStyle> list = new ArrayList<JRStyle>(); for (JRReportTemplate t : jd.getTemplatesList()) list.addAll(ExternalStylesManager.getStyles(t, file, jConfig)); return list; }
/** * @return the template */ public JRReportTemplate getTemplate() { return template; }
public TemplateElementValidationItem(JRReportTemplate template) { this.template = template; }
/** * @param template the template to set */ public void setTemplate(JRReportTemplate template) { this.template = template; }
/** * Inserts a report template at specified position. * * @param index the template position. * @param template the template to insert. * @see #getTemplates() */ public void addTemplate(int index, JRReportTemplate template) { templateList.add(index, template); getEventSupport().fireCollectionElementAddedEvent(PROPERTY_TEMPLATES, template, index); }
/** * Adds a report template. * * @param template the template to add. * @see #getTemplates() */ public void addTemplate(JRReportTemplate template) { addTemplate(templateList.size(), template); }
/** * Returns the list of report templates defined in the report. * * @return the list of {@link JRReportTemplate} objects for the report * @see #getTemplates() * @see #addTemplate(JRReportTemplate) */ public List<JRReportTemplate> getTemplatesList() { return templateList; }
/** * Instantiates a new m style template. * * @param parent * the parent * @param jrstyle * the jrstyle * @param newIndex * the new index */ public MStyleTemplate(ANode parent, JRReportTemplate jrstyle, int newIndex) { super(parent, newIndex); setValue(jrstyle); }