/** * Creates the scriptlets. * * @return the scriptlets list * @throws JRException */ protected List<JRAbstractScriptlet> createScriptlets(Map<String,Object> parameterValues) throws JRException { ScriptletFactoryContext context = new ScriptletFactoryContext(getJasperReportsContext(), this, parameterValues); scriptlets = new ArrayList<JRAbstractScriptlet>(); List<ScriptletFactory> factories = getJasperReportsContext().getExtensions(ScriptletFactory.class); for (Iterator<ScriptletFactory> it = factories.iterator(); it.hasNext();) { ScriptletFactory factory = it.next(); List<JRAbstractScriptlet> tmpScriptlets = factory.getScriplets(context); if (tmpScriptlets != null) { scriptlets.addAll(tmpScriptlets); } } if (scriptlets.size() == 0) { scriptlets.add(0, new JRDefaultScriptlet()); } return scriptlets; }
/** * Creates the property descriptors. * * @param desc * the desc */ @Override public void createPropertyDescriptors(List<IPropertyDescriptor> desc, Map<String, Object> defaultsMap) { NTextPropertyDescriptor nameD = new NTextPropertyDescriptor(JRDesignScriptlet.PROPERTY_NAME, Messages.common_name); nameD.setDescription(Messages.MScriptlet_name_description); desc.add(nameD); List<Class<?>> clist = new ArrayList<Class<?>>(); clist.add(JRAbstractScriptlet.class); clist.add(JRDefaultScriptlet.class); NClassTypePropertyDescriptor classD = new NClassTypePropertyDescriptor(JRDesignScriptlet.PROPERTY_VALUE_CLASS_NAME, Messages.common_class); classD.setClasses(clist); classD.setDescription(Messages.MScriptlet_class_description); desc.add(classD); NTextPropertyDescriptor descriptionD = new NTextPropertyDescriptor(JRDesignScriptlet.PROPERTY_DESCRIPTION, Messages.common_description); descriptionD.setDescription(Messages.MScriptlet_description_description); desc.add(descriptionD); }
/** * Sets the scriptlet class name. * <p> * If no scriptlet class name is specified, a default scriptlet is used. * * @param scriptletClass the class name of the scriptlet * @see net.sf.jasperreports.engine.JRDataset#getScriptletClass() */ public void setScriptletClass(String scriptletClass) { Object old = this.scriptletClass; this.scriptletClass = scriptletClass; if (scriptletClass == null) { ((JRDesignParameter) parametersMap.get(JRParameter.REPORT_SCRIPTLET)).setValueClass(JRAbstractScriptlet.class); } else { ((JRDesignParameter) parametersMap.get(JRParameter.REPORT_SCRIPTLET)).setValueClassName(scriptletClass); } getEventSupport().firePropertyChange(PROPERTY_SCRIPTLET_CLASS, old, this.scriptletClass); }
@Override public void setData( Map<String,JRFillParameter> parsm, Map<String,JRFillField> fldsm, Map<String,JRFillVariable> varsm, JRFillGroup[] grps ) { super.setData(parsm, fldsm, varsm, grps); for(Iterator<JRAbstractScriptlet> it = dataset.scriptlets.iterator(); it.hasNext();) { it.next().setData(parsm, fldsm, varsm, grps); } }
@Override public void beforeReportInit() throws JRScriptletException { for(Iterator<JRAbstractScriptlet> it = dataset.scriptlets.iterator(); it.hasNext();) { it.next().beforeReportInit(); } }
@Override public void afterReportInit() throws JRScriptletException { for(Iterator<JRAbstractScriptlet> it = dataset.scriptlets.iterator(); it.hasNext();) { it.next().afterReportInit(); } }
@Override public void beforePageInit() throws JRScriptletException { for(Iterator<JRAbstractScriptlet> it = dataset.scriptlets.iterator(); it.hasNext();) { it.next().beforePageInit(); } }
@Override public void afterPageInit() throws JRScriptletException { for(Iterator<JRAbstractScriptlet> it = dataset.scriptlets.iterator(); it.hasNext();) { it.next().afterPageInit(); } }
@Override public void beforeColumnInit() throws JRScriptletException { for(Iterator<JRAbstractScriptlet> it = dataset.scriptlets.iterator(); it.hasNext();) { it.next().beforeColumnInit(); } }
@Override public void afterColumnInit() throws JRScriptletException { for(Iterator<JRAbstractScriptlet> it = dataset.scriptlets.iterator(); it.hasNext();) { it.next().afterColumnInit(); } }
@Override public void beforeGroupInit(String groupName) throws JRScriptletException { for(Iterator<JRAbstractScriptlet> it = dataset.scriptlets.iterator(); it.hasNext();) { it.next().beforeGroupInit(groupName); } }
@Override public void afterGroupInit(String groupName) throws JRScriptletException { for(Iterator<JRAbstractScriptlet> it = dataset.scriptlets.iterator(); it.hasNext();) { it.next().afterGroupInit(groupName); } }
@Override public void beforeDetailEval() throws JRScriptletException { for(Iterator<JRAbstractScriptlet> it = dataset.scriptlets.iterator(); it.hasNext();) { it.next().beforeDetailEval(); } }
@Override public void afterDetailEval() throws JRScriptletException { for(Iterator<JRAbstractScriptlet> it = dataset.scriptlets.iterator(); it.hasNext();) { it.next().afterDetailEval(); } }
@Override public List<JRAbstractScriptlet> getScriplets(ScriptletFactoryContext context) throws JRException { List<JRAbstractScriptlet> scriptlets = new ArrayList<JRAbstractScriptlet>(); boolean maxPagesEnabled = JRPropertiesUtil.getInstance(context.getJasperReportsContext()).getBooleanProperty(context.getDataset(), MaxPagesGovernor.PROPERTY_MAX_PAGES_ENABLED, true); if (maxPagesEnabled) { int maxPages = JRPropertiesUtil.getInstance(context.getJasperReportsContext()).getIntegerProperty(context.getDataset(), MaxPagesGovernor.PROPERTY_MAX_PAGES, 0); if (maxPages > 0) { scriptlets.add(new MaxPagesGovernor(maxPages)); } } boolean timeoutEnabled = JRPropertiesUtil.getInstance(context.getJasperReportsContext()).getBooleanProperty(context.getDataset(), TimeoutGovernor.PROPERTY_TIMEOUT_ENABLED, true); if (timeoutEnabled) { long timeout = JRPropertiesUtil.getInstance(context.getJasperReportsContext()).getLongProperty(context.getDataset(), TimeoutGovernor.PROPERTY_TIMEOUT, 0l); if (timeout > 0) { scriptlets.add(new TimeoutGovernor(timeout)); } } return scriptlets; }
public void addScriptlet(String name, Class<? extends JRAbstractScriptlet> type) { JRDesignScriptlet scriptlet = new JRDesignScriptlet(); scriptlet.setName(name); scriptlet.setValueClass(type); JRDesignParameter parameter = new JRDesignParameter(); parameter.setName(name + JRScriptlet.SCRIPTLET_PARAMETER_NAME_SUFFIX); parameter.setValueClass(scriptlet.getValueClass()); parameter.setSystemDefined(true); parameter.setForPrompting(false); scriptlets.add(scriptlet); parameters.add(parameter); }
/** * Creates the property descriptors. * * @param desc * the desc */ @Override public void createPropertyDescriptors(List<IPropertyDescriptor> desc, Map<String, Object> defaultsMap) { NTextPropertyDescriptor nameD = new NTextPropertyDescriptor(JRDesignScriptlet.PROPERTY_NAME, Messages.common_name); nameD.setDescription(Messages.MScriptlet_name_description); desc.add(nameD); List<Class<?>> clist = new ArrayList<Class<?>>(); clist.add(JRAbstractScriptlet.class); clist.add(JRDefaultScriptlet.class); NClassTypePropertyDescriptor classD = new NClassTypePropertyDescriptor(JRDesignScriptlet.PROPERTY_VALUE_CLASS_NAME, Messages.common_class); classD.setClasses(clist); classD.setDescription(Messages.MScriptlet_class_description); desc.add(classD); classD.setHelpRefBuilder(new HelpReferenceBuilder( "net.sf.jasperreports.doc/docs/schema.reference.html?cp=0_1#scriptlet_class")); NTextPropertyDescriptor descriptionD = new NTextPropertyDescriptor(JRDesignScriptlet.PROPERTY_DESCRIPTION, Messages.common_description); descriptionD.setDescription(Messages.MScriptlet_description_description); desc.add(descriptionD); descriptionD.setHelpRefBuilder(new HelpReferenceBuilder( "net.sf.jasperreports.doc/docs/schema.reference.html?cp=0_1#scriptletDescription")); setHelpPrefix(desc, "net.sf.jasperreports.doc/docs/schema.reference.html?cp=0_1#scriptlet"); }
public List<JRAbstractScriptlet> getScriplets(ScriptletFactoryContext context) throws JRException { if (list == null) { list = new ArrayList<JRAbstractScriptlet>(); } list.add(new RecordCountScriptlet()); return list; }
public int getRecordCount() { int count = 0; if (list != null) for (JRAbstractScriptlet s : list) if (s instanceof RecordCountScriptlet) count += ((RecordCountScriptlet) s).getCounter(); return count; }
private void addScriptlet(String name, Class<? extends JRAbstractScriptlet> scriptletClass) { try { accessor.getDesign().addScriptlet(scriptlet(name, scriptletClass)); } catch (JRException e) { throw new JasperDesignException("Registration failed for scriptlet \"" + name + "\"", e); } }
/** * */ public JRAbstractScriptlet getScriptlet() { return scriptlet; }
/** * */ public void setScriptlet(JRAbstractScriptlet scriptlet) { this.scriptlet = scriptlet; }
protected JRDesignScriptlet scriptlet(String name, Class<? extends JRAbstractScriptlet> scriptletClass) { JRDesignScriptlet jrScriptlet = new JRDesignScriptlet(); jrScriptlet.setName(name); jrScriptlet.setValueClass(scriptletClass); return jrScriptlet; }
/** * Returns a list of scriptlet instances to be used during report filling. * This method can return <code>null</code> if no scriplet is to be used. */ List<JRAbstractScriptlet> getScriplets(ScriptletFactoryContext context) throws JRException;