/** * */ protected JRBaseScriptlet getScriptlet(JRScriptlet scriptlet) { JRBaseScriptlet baseScriptlet = null; if (scriptlet != null) { baseScriptlet = (JRBaseScriptlet)get(scriptlet); if (baseScriptlet == null) { baseScriptlet = new JRBaseScriptlet(scriptlet, this); } } return baseScriptlet; }
/** * */ private void writeScriptlet(JRScriptlet scriptlet) throws IOException { if(isNewerVersionOrEqual(JRConstants.VERSION_3_1_4)) { writer.startElement(JRXmlConstants.ELEMENT_scriptlet); writer.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_name, scriptlet.getName()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_class, scriptlet.getValueClassName()); writeProperties(scriptlet); writer.writeCDATAElement(JRXmlConstants.ELEMENT_scriptletDescription, scriptlet.getDescription()); writer.closeElement(); } }
/** * Inserts a scriptlet at the specified position into the dataset. * @param index the scriptlet position * @param scriptlet the scriptlet to insert * @throws JRException * @see net.sf.jasperreports.engine.JRDataset#getScriptlets() */ public void addScriptlet(int index, JRScriptlet scriptlet) throws JRException { if (scriptletsMap.containsKey(scriptlet.getName())) { throw new JRException( EXCEPTION_MESSAGE_KEY_DUPLICATE_SCRIPTLET, new Object[]{scriptlet.getName()}); } JRDesignParameter scriptletParameter = new JRDesignParameter(); scriptletParameter.setName(scriptlet.getName() + JRScriptlet.SCRIPTLET_PARAMETER_NAME_SUFFIX); scriptletParameter.setValueClassName(scriptlet.getValueClassName()); scriptletParameter.setSystemDefined(true); scriptletParameter.setForPrompting(false); addParameter(scriptletParameter); scriptletsList.add(index, scriptlet); scriptletsMap.put(scriptlet.getName(), scriptlet); getEventSupport().fireCollectionElementAddedEvent(PROPERTY_SCRIPTLETS, scriptlet, index); }
/** * Removes a scriptlet from the dataset. * * @param scriptlet the scriptlet to be removed * @return the scriptlet to be removed */ public JRScriptlet removeScriptlet(JRScriptlet scriptlet) { if (scriptlet != null) { removeParameter(scriptlet.getName() + JRScriptlet.SCRIPTLET_PARAMETER_NAME_SUFFIX); int idx = scriptletsList.indexOf(scriptlet); if (idx >= 0) { scriptletsList.remove(idx); scriptletsMap.remove(scriptlet.getName()); getEventSupport().fireCollectionElementRemovedEvent(PROPERTY_SCRIPTLETS, scriptlet, idx); } } return scriptlet; }
/** * */ protected JRBaseScriptlet(JRScriptlet scriptlet, JRBaseObjectFactory factory) { factory.put(scriptlet, this); name = scriptlet.getName(); description = scriptlet.getDescription(); valueClassName = scriptlet.getValueClassName(); propertiesMap = scriptlet.getPropertiesMap().cloneProperties(); }
/** * */ private void writeScriptlet( JRScriptlet scriptlet, String scriptletName) { if(scriptlet != null) { write( "JRDesignScriptlet " + scriptletName + " = new JRDesignScriptlet();\n"); write( scriptletName + ".setDescription(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(scriptlet.getDescription())); write( scriptletName + ".setName(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(scriptlet.getName())); write( scriptletName + ".setValueClassName(\"{0}\");\n", scriptlet.getValueClassName()); writeProperties( scriptlet, scriptletName); flush(); } }
@Override public JRScriptlet[] getScriptlets() { JRScriptlet[] scriptletsArray = new JRScriptlet[scriptletsList.size()]; scriptletsList.toArray(scriptletsArray); return scriptletsArray; }
/** * */ protected JRFillScriptlet( JRScriptlet parent, JRFillObjectFactory factory ) { factory.put(parent, this); this.parent = parent; }
public TableReportDataset(JRDataset tableSubdataset, String name) { this.tableSubdataset = tableSubdataset; this.name = name; JRGroup[] datasetGroups = tableSubdataset.getGroups(); groups = new ArrayList<JRGroup>(); if (datasetGroups == null) { tableGroups = null; } else { tableGroups = new TableReportGroup[datasetGroups.length]; for (int i = 0; i < datasetGroups.length; i++) { tableGroups[i] = new TableReportGroup(datasetGroups[i]); groups.add(tableGroups[i]); } } properties = tableSubdataset.getPropertiesMap().cloneProperties(); scriptlets = new ArrayList<JRScriptlet>(); JRScriptlet[] datasetScriptlets = tableSubdataset.getScriptlets(); if (datasetScriptlets != null) { Collections.addAll(scriptlets, datasetScriptlets); } JRParameter[] datasetParameters = tableSubdataset.getParameters(); parameters = new ArrayList<JRParameter>(); if (datasetParameters != null) { Collections.addAll(parameters, datasetParameters); } }
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); }
@Override public void init(Map<String, JRFillParameter> parametersMap, Map<String, JRFillField> fieldsMap, Map<String, JRFillVariable> variablesMap, WhenResourceMissingTypeEnum resourceMissingType) throws JRException { tableScriptletParam = parametersMap.get(TABLE_SCRIPTLET_NAME + JRScriptlet.SCRIPTLET_PARAMETER_NAME_SUFFIX); }
public static Map<String, Object> resetParameters(Map<String, Object> jasperParameters, JasperReportsConfiguration jrContext) { jasperParameters = jrContext.getJRParameters(); if (jasperParameters == null) { jasperParameters = new HashMap<String, Object>(); setDefaultParameterValues(jasperParameters, jrContext); } else { Map<String, Object> map = new HashMap<String, Object>(); List<JRParameter> prm = jrContext.getJasperDesign().getParametersList(); for (JRParameter p : prm) { Object obj = jasperParameters.get(p.getName()); if (p.getName().endsWith(JRScriptlet.SCRIPTLET_PARAMETER_NAME_SUFFIX)) continue; if (p.getName().equals(JRParameter.REPORT_DATA_SOURCE)) continue; if (p.getName().equals(JRParameter.REPORT_CONNECTION)) continue; if (p.getName().startsWith("XML_") || p.getName().startsWith("MONDRIAN_") //$NON-NLS-1$ //$NON-NLS-1$ || p.getName().startsWith("XLSX_") || p.getName().startsWith("XLS_") //$NON-NLS-1$ //$NON-NLS-1$ || p.getName().startsWith("JSON_") || p.getName().startsWith("HIBERNATE_") //$NON-NLS-1$ //$NON-NLS-1$ || p.getName().startsWith("JPA_") || p.getName().startsWith("CSV_") //$NON-NLS-1$ //$NON-NLS-1$ || p.getName().contains("csv.source") || p.getName().startsWith("XMLA_")) //$NON-NLS-1$ //$NON-NLS-1$ continue; try { if (obj != null && p.getValueClass().isAssignableFrom(obj.getClass()) && p.isForPrompting()) { map.put(p.getName(), obj); } } catch (Exception e) { } } jasperParameters.clear(); jasperParameters.putAll(map); } jrContext.setJRParameters(jasperParameters); return jasperParameters; }
@Override @SuppressWarnings("unchecked") public void setName(String s) { if (s.equals("") || s.equals("REPORT")) { throw new IllegalArgumentException("Scriptlet name not valid."); } List<JRScriptlet> currentScriptlets = null; JRDesignDataset dataset = getParentNode().getLookup().lookup(JRDesignDataset.class); currentScriptlets = (List<JRScriptlet>)dataset.getScriptletsList(); for (JRScriptlet pa : currentScriptlets) { JRDesignScriptlet p = (JRDesignScriptlet)pa; if (p != getScriptlet() && p.getName().equals(s)) { throw new IllegalArgumentException("Scriptlet name already in use."); } } String oldName = getScriptlet().getName(); getScriptlet().setName(s); dataset.getScriptletsMap().remove(oldName); dataset.getScriptletsMap().put(s,getScriptlet()); ObjectPropertyUndoableEdit opue = new ObjectPropertyUndoableEdit( getScriptlet(), "Name", String.class, oldName, s); IReportManager.getInstance().addUndoableEdit(opue); }
/** * Gets an array of report scriptlets (excluding the scriptletClass one). */ @Override public JRScriptlet[] getScriptlets() { return mainDataset.getScriptlets(); }
@Override public JRScriptlet[] getScriptlets() { return scriptlets; }
protected void writeDatasetContents(JRDataset dataset) throws IOException { /* */ JRScriptlet[] scriptlets = dataset.getScriptlets(); if (scriptlets != null && scriptlets.length > 0) { for(int i = 0; i < scriptlets.length; i++) { writeScriptlet(scriptlets[i]); } } /* */ JRParameter[] parameters = dataset.getParameters(); if (parameters != null && parameters.length > 0) { for(int i = 0; i < parameters.length; i++) { if (!parameters[i].isSystemDefined()) { writeParameter(parameters[i]); } } } /* */ if(dataset.getQuery() != null) { writeQuery(dataset.getQuery()); } /* */ JRField[] fields = dataset.getFields(); if (fields != null && fields.length > 0) { for(int i = 0; i < fields.length; i++) { writeField(fields[i]); } } /* */ JRSortField[] sortFields = dataset.getSortFields(); if (sortFields != null && sortFields.length > 0) { for(int i = 0; i < sortFields.length; i++) { writeSortField(sortFields[i]); } } /* */ JRVariable[] variables = dataset.getVariables(); if (variables != null && variables.length > 0) { for(int i = 0; i < variables.length; i++) { if (!variables[i].isSystemDefined()) { writeVariable(variables[i]); } } } writeExpression(JRXmlConstants.ELEMENT_filterExpression, dataset.getFilterExpression(), false); /* */ JRGroup[] groups = dataset.getGroups(); if (groups != null && groups.length > 0) { for(int i = 0; i < groups.length; i++) { writeGroup(groups[i]); } } }
/** * Gets a list of report scriptlets (excluding the one specified by scriptletClass). */ public List<JRScriptlet> getScriptletsList() { return mainDesignDataset.getScriptletsList(); }
/** * Gets a map of report scriptlets (excluding the one specified by scriptletClass). */ public Map<String, JRScriptlet> getScriptletsMap() { return mainDesignDataset.getScriptletsMap(); }
/** * Adds a report scriplet. */ public void addScriptlet(JRScriptlet scriptlet) throws JRException { mainDesignDataset.addScriptlet(scriptlet); }
/** * Removes a report scriptlet, based on its name. */ public JRScriptlet removeScriptlet(String scriptletName) { return mainDesignDataset.removeScriptlet(scriptletName); }
/** * Removes a report scriptlet. */ public JRScriptlet removeScriptlet(JRScriptlet scriptlet) { return mainDesignDataset.removeScriptlet(scriptlet); }
@Override public JRScriptlet[] getScriptlets() { return parent.getScriptlets(); }
@Override public JRScriptlet[] getScriptlets() { return scriptlets.toArray(new JRScriptlet[scriptlets.size()]); }
@Override public JRScriptlet[] getScriptlets() { return mainDataset.getScriptlets(); }
public String getDisplayText() { return ((JRScriptlet) getValue()).getName(); }
@Override public DRIScriptlet getScriptlet(String name) { return ((CustomScriptlet) getParameterValue(name + JRScriptlet.SCRIPTLET_PARAMETER_NAME_SUFFIX)).getScriptlet(); }
private void addScriptlet(DRIScriptlet scriptlet) { CustomScriptlet customScriptlet = new CustomScriptlet(scriptlet); addScriptlet(scriptlet.getName(), customScriptlet.getClass()); accessor.getParameters().put(scriptlet.getName() + JRScriptlet.SCRIPTLET_PARAMETER_NAME_SUFFIX, customScriptlet); }
/** * Returns the list of scriptlets, excluding the scriptletClass one. * * @return list of {@link JRScriptlet JRScriptlet} objects */ public List<JRScriptlet> getScriptletsList() { return scriptletsList; }
/** * Returns the map of scriptlets, excluding the scriptletClass one, indexed by name. * * @return {@link JRScriptlet JRScriptlet} objects indexed by name */ public Map<String, JRScriptlet> getScriptletsMap() { return scriptletsMap; }
/** * Adds a scriptlet to the dataset. * @param scriptlet the scriptlet to add * @throws JRException * @see net.sf.jasperreports.engine.JRDataset#getScriptlets() */ public void addScriptlet(JRScriptlet scriptlet) throws JRException { addScriptlet(scriptletsList.size(), scriptlet); }
/** * Removes a scriptlet from the dataset. * * @param scriptletName the scriptlet name * @return the removed scriptlet, or <code>null</code> if the scriptlet was not found */ public JRScriptlet removeScriptlet(String scriptletName) { return removeScriptlet(scriptletsMap.get(scriptletName)); }
/** * Instantiates a new m scriptlet. * * @param parent * the parent * @param jfRield * the jf rield * @param newIndex * the new index */ public MScriptlet(ANode parent, JRScriptlet jfRield, int newIndex) { super(parent, newIndex); setValue(jfRield); }
/** * Instantiates a new m scriptlet. * * @param parent * the parent * @param jfRield * the jf rield * @param newIndex * the new index */ public MSystemScriptlet(ANode parent, JRScriptlet jfRield, int newIndex) { super(parent, newIndex); setValue(jfRield); }