private String getPropertyValue(String propertyName, byte evaluation) { String value = null; if (lateEvaluated && stylePropertyExpressions != null && stylePropertyExpressions.containsKey(propertyName)) { JRPropertyExpression stylePropertyExpression = stylePropertyExpressions.get(propertyName); JRExpression expression = stylePropertyExpression.getValueExpression(); if (expression != null) { value = (String) context.evaluateExpression(expression, evaluation); } } else { value = context.getElement().getPropertiesMap().getProperty(propertyName); } return value; }
protected void writePropertyExpression(JRPropertyExpression propertyExpression) throws IOException { String expressionText = ""; ExpressionTypeEnum expressionType = null; JRExpression valueExpression = propertyExpression.getValueExpression(); if (valueExpression != null) { expressionText = valueExpression.getText(); expressionType = valueExpression.getType(); } writer.writeCDATAElement( JRXmlConstants.ELEMENT_propertyExpression, getNamespace(), expressionText, new String[]{ JRXmlConstants.ATTRIBUTE_name, JRXmlConstants.ATTRIBUTE_type}, new Object[]{ propertyExpression.getName(), expressionType == null ? null : expressionType.getName()} ); }
/** * Remove a property expression. * * @param name the name of the property to remove * @return the removed property expression (if found) */ public JRPropertyExpression removePropertyExpression(String name) { JRPropertyExpression removed = null; for (ListIterator<JRPropertyExpression> it = propertyExpressions.listIterator(); it.hasNext();) { JRPropertyExpression prop = it.next(); if (name.equals(prop.getName())) { removed = prop; int idx = it.previousIndex(); it.remove(); getEventSupport().fireCollectionElementRemovedEvent(PROPERTY_PROPERTY_EXPRESSIONS, removed, idx); break; } } return removed; }
/** * */ protected JRFillField( JRField field, JRFillObjectFactory factory ) { factory.put(field, this); parent = field; expressionEvaluator = factory.getExpressionEvaluator(); staticProperties = field.hasProperties() ? field.getPropertiesMap().cloneProperties() : null; mergedProperties = staticProperties; JRPropertyExpression[] fieldPropertyExpressions = field.getPropertyExpressions(); propertyExpressions = fieldPropertyExpressions == null ? new ArrayList<JRPropertyExpression>(0) : new ArrayList<JRPropertyExpression>(Arrays.asList(fieldPropertyExpressions)); }
/** * */ protected void evaluateProperties() throws JRException { if (propertyExpressions.isEmpty()) { mergedProperties = staticProperties; } else { JRPropertiesMap dynamicProperties = new JRPropertiesMap(); for (JRPropertyExpression prop : propertyExpressions) { String value = (String) evaluateExpression(prop.getValueExpression()); //if (value != null) //is the null value significant for some field properties? { dynamicProperties.setProperty(prop.getName(), value); } } mergedProperties = dynamicProperties.cloneProperties(); mergedProperties.setBaseProperties(staticProperties); } }
private List<String> findDynamicTransferProperties() { if (propertyExpressions.isEmpty()) { return null; } List<String> prefixes = filler.getPrintTransferPropertyPrefixes(); List<String> transferProperties = new ArrayList<String>(propertyExpressions.size()); for (JRPropertyExpression propertyExpression : propertyExpressions) { String propertyName = propertyExpression.getName(); for (String prefix : prefixes) { if (propertyName.startsWith(prefix)) { transferProperties.add(propertyName); break; } } } return transferProperties; }
/** * Remove a property expression. * * @param name the name of the property to remove * @return the removed property expression (if found) */ public JRPropertyExpression removePropertyExpression(String name) { JRPropertyExpression removed = null; for (ListIterator<JRPropertyExpression> it = propertyExpressions.listIterator(); it.hasNext();) { JRPropertyExpression prop = it.next(); if (name.equals(prop.getName())) { removed = prop; int idx = it.previousIndex(); it.remove(); getEventSupport().fireCollectionElementRemovedEvent(JRDesignElement.PROPERTY_PROPERTY_EXPRESSIONS, removed, idx); break; } } return removed; }
public Object getPropertyValue(Object id) { StandardBaseColumn jrElement = getValue(); if (id.equals(StandardBaseColumn.PROPERTY_WIDTH)) return jrElement.getWidth(); if (id.equals(StandardBaseColumn.PROPERTY_PRINT_WHEN_EXPRESSION)) return ExprUtil.getExpression(jrElement.getPrintWhenExpression()); if (id.equals(DesignCell.PROPERTY_HEIGHT)) return getMTable().getTableManager().getYhcolumn(type, grName, jrElement).height; JRPropertiesMap propertiesMap = jrElement.getPropertiesMap(); if (propertiesMap != null) propertiesMap = propertiesMap.cloneProperties(); if (id.equals(JRDesignElement.PROPERTY_PROPERTY_EXPRESSIONS)) { JRPropertyExpression[] propertyExpressions = jrElement .getPropertyExpressions(); if (propertyExpressions != null) propertyExpressions = propertyExpressions.clone(); return new PropertyExpressionsDTO(propertyExpressions, propertiesMap, this); } if (id.equals(MGraphicElement.PROPERTY_MAP)) return propertiesMap; return null; }
@Override public void dispose() { // clear all properties List<PropertyDTO> props = (List<PropertyDTO>) tableViewer.getInput(); List<JRPropertyExpression> pexpr = new ArrayList<JRPropertyExpression>(); for (String str : value.getPropMap().getPropertyNames()) value.getPropMap().removeProperty(str); value.setPropExpressions(null); for (PropertyDTO p : props) { if (p.getValue() instanceof JRExpression) { JRDesignPropertyExpression jrpexp = new JRDesignPropertyExpression(); jrpexp.setName(p.getProperty()); jrpexp.setValueExpression((JRExpression) p.getValue()); pexpr.add(jrpexp); } else if (p.getValue() instanceof String) { value.getPropMap().setProperty(p.getProperty(), (String) p.getValue()); } } if (pexpr != null && !pexpr.isEmpty()) value.setPropExpressions(pexpr.toArray(new JRPropertyExpression[pexpr.size()])); super.dispose(); }
public Object getValue() throws IllegalAccessException, InvocationTargetException { JRPropertiesMap map = column.getPropertiesMap(); List properties = new ArrayList(); String[] names = map.getPropertyNames(); for (int i=0; i<names.length; ++i) { properties.add(new GenericProperty(names[i], map.getProperty(names[i]))); } // add to the list the expression properties... JRPropertyExpression[] expProperties = column.getPropertyExpressions(); for (int i=0; expProperties != null && i<expProperties.length; ++i) { properties.add(new GenericProperty(expProperties[i].getName(), (JRDesignExpression)expProperties[i].getValueExpression())); } return properties; }
/** * replace the expression properties in element with the ones found in newExpressionProperties. */ public static void replaceExpressionProperties(StandardBaseColumn column, List<GenericProperty> newExpressionProperties) { // Update names. List usedProps = new ArrayList(); List propertyExpressions = column.getPropertyExpressionsList(); for(int i = 0; i < propertyExpressions.size(); i++) { column.removePropertyExpression((JRPropertyExpression)propertyExpressions.get(i)); } if (newExpressionProperties == null) return; for(GenericProperty prop : newExpressionProperties) { if (!prop.isUseExpression()) continue; JRDesignPropertyExpression newProp = new JRDesignPropertyExpression(); newProp.setName(prop.getKey()); newProp.setValueExpression(prop.getExpression()); column.addPropertyExpression(newProp); } }
/** * replace the expression properties in element with the ones found in newExpressionProperties. */ public static void replaceExpressionProperties(JRDesignElement element, List<GenericProperty> newExpressionProperties) { // Update names. List usedProps = new ArrayList(); // List propertyExpressions = element.getPropertyExpressionsList(); while(element.getPropertyExpressionsList().size() > 0) { element.removePropertyExpression((JRPropertyExpression)element.getPropertyExpressionsList().get(0)); } if (newExpressionProperties == null) return; for(GenericProperty prop : newExpressionProperties) { if (!prop.isUseExpression()) continue; JRDesignPropertyExpression newProp = new JRDesignPropertyExpression(); newProp.setName(prop.getKey()); newProp.setValueExpression(prop.getExpression()); element.addPropertyExpression(newProp); } }
public Object getValue() throws IllegalAccessException, InvocationTargetException { JRPropertiesMap map = element.getPropertiesMap(); List properties = new ArrayList(); String[] names = map.getPropertyNames(); for (int i=0; i<names.length; ++i) { properties.add(new GenericProperty(names[i], map.getProperty(names[i]))); } // add to the list the expression properties... JRPropertyExpression[] expProperties = element.getPropertyExpressions(); for (int i=0; expProperties != null && i<expProperties.length; ++i) { properties.add(new GenericProperty(expProperties[i].getName(), (JRDesignExpression)expProperties[i].getValueExpression())); } return properties; }
public JRPropertyExpression[] getPropertyExpressions(JRPropertyExpression[] props) { JRPropertyExpression[] propertyExpressions = null; if (props != null && props.length > 0) { propertyExpressions = new JRPropertyExpression[props.length]; for (int i = 0; i < props.length; i++) { propertyExpressions[i] = getPropertyExpression(props[i]); } } return propertyExpressions; }
@Override public StyleProvider getStyleProvider(StyleProviderContext context, JasperReportsContext jasperreportsContext) { Map<String, JRPropertyExpression> stylePropertyExpressions = null; JRPropertyExpression[] propertyExpressions = context.getElement().getPropertyExpressions(); if (propertyExpressions != null) { for(JRPropertyExpression propertyExpression : propertyExpressions) { if (propertyExpression.getName().startsWith(PropertyStyleProvider.STYLE_PROPERTY_PREFIX)) { if (stylePropertyExpressions == null) { stylePropertyExpressions = new HashMap<String, JRPropertyExpression>(); } stylePropertyExpressions.put(propertyExpression.getName(), propertyExpression); } } } List<PropertySuffix> styleProperties = JRPropertiesUtil.getProperties(context.getElement(), PropertyStyleProvider.STYLE_PROPERTY_PREFIX); if ( stylePropertyExpressions != null || (styleProperties != null && styleProperties.size() > 0) ) { return new PropertyStyleProvider(context, stylePropertyExpressions); } return null; }
public void writePropertyExpressions(JRPropertyExpression[] propertyExpressions) throws IOException { if (propertyExpressions != null) { for (int i = 0; i < propertyExpressions.length; i++) { writePropertyExpression(propertyExpressions[i]); } } }
/** * */ protected void writePropertyExpressions( JRPropertyExpression[] propertyExpressions, String propertyHolderName) { if (propertyExpressions != null && propertyExpressions.length > 0) { for (int i = 0; i < propertyExpressions.length; i++) { writePropertyExpression( propertyExpressions[i], propertyHolderName + "PropertyExpression" + i); write( propertyHolderName + ".addPropertyExpression(" + propertyHolderName + "PropertyExpression" + i +");\n"); } flush(); } }
/** * */ protected void writePropertyExpression( JRPropertyExpression propertyExpression, String propertyExpressionName) { if(propertyExpression != null) { write( "JRDesignPropertyExpression " + propertyExpressionName + " = new JRDesignPropertyExpression();\n"); write( propertyExpressionName + ".setName(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(propertyExpression.getName())); writeExpression( propertyExpression.getValueExpression(), propertyExpressionName, "ValueExpression"); flush(); } }
protected void verifyProperyExpressions( JRPropertyExpression[] propertyExpressions) { if (propertyExpressions != null) { for (int i = 0; i < propertyExpressions.length; i++) { verifyPropertyExpression(propertyExpressions[i]); } } }
protected void verifyPropertyExpression(JRPropertyExpression propertyExpression) { String name = propertyExpression.getName(); if (name == null) { addBrokenRule("Property name missing.", propertyExpression); } JRExpression expr = propertyExpression.getValueExpression(); if (expr == null) { addBrokenRule("Property value expression missing.", propertyExpression); } }
/** * Add a dynamic/expression-based property. * * @param propertyExpression the property to add * @see #getPropertyExpressions() */ public void addPropertyExpression(JRPropertyExpression propertyExpression) { propertyExpressions.add(propertyExpression); getEventSupport().fireCollectionElementAddedEvent(PROPERTY_PROPERTY_EXPRESSIONS, propertyExpression, propertyExpressions.size() - 1); }
/** * Remove a property expression. * * @param propertyExpression the property expression to remove * @see #addPropertyExpression(JRPropertyExpression) */ public void removePropertyExpression(JRPropertyExpression propertyExpression) { int idx = propertyExpressions.indexOf(propertyExpression); if (idx >= 0) { propertyExpressions.remove(idx); getEventSupport().fireCollectionElementRemovedEvent(PROPERTY_PROPERTY_EXPRESSIONS, propertyExpression, idx); } }
@Override public JRPropertyExpression[] getPropertyExpressions() { JRPropertyExpression[] props; if (propertyExpressions.isEmpty()) { props = null; } else { props = propertyExpressions.toArray(new JRPropertyExpression[propertyExpressions.size()]); } return props; }
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); if (propertyExpressions == null) { propertyExpressions = new ArrayList<JRPropertyExpression>(); } }
/** * * private JRElement topElementInGroup; private JRElement bottomElementInGroup; /** * */ protected JRFillElement( JRBaseFiller filler, JRElement element, JRFillObjectFactory factory ) { factory.put(element, this); this.parent = element; this.filler = filler; this.expressionEvaluator = factory.getExpressionEvaluator(); this.defaultStyleProvider = factory.getDefaultStyleProvider(); printElementOriginator = filler.assignElementId(this); /* */ printWhenGroupChanges = factory.getGroup(element.getPrintWhenGroupChanges()); elementGroup = (JRFillElementGroup)factory.getVisitResult(element.getElementGroup()); x = element.getX(); y = element.getY(); width = element.getWidth(); height = element.getHeight(); staticProperties = element.hasProperties() ? element.getPropertiesMap().cloneProperties() : null; mergedProperties = staticProperties; JRPropertyExpression[] elementPropertyExpressions = element.getPropertyExpressions(); propertyExpressions = elementPropertyExpressions == null ? new ArrayList<JRPropertyExpression>(0) : new ArrayList<JRPropertyExpression>(Arrays.asList(elementPropertyExpressions)); dynamicTransferProperties = findDynamicTransferProperties(); factory.registerDelayedStyleSetter(this, parent); initStyleProviders(); }
protected JRFillElement(JRFillElement element, JRFillCloneFactory factory) { factory.put(element, this); this.parent = element.parent; this.filler = element.filler; this.expressionEvaluator = element.expressionEvaluator; this.defaultStyleProvider = element.defaultStyleProvider; this.originProvider = element.originProvider; printElementOriginator = element.printElementOriginator; /* */ printWhenGroupChanges = element.printWhenGroupChanges; elementGroup = (JRFillElementGroup) factory.getClone((JRFillElementGroup) element.getElementGroup()); x = element.getX(); y = element.getY(); width = element.getWidth(); height = element.getHeight(); templates = element.templates; initStyle = element.initStyle; shrinkable = element.shrinkable; staticProperties = element.staticProperties == null ? null : element.staticProperties.cloneProperties(); mergedProperties = staticProperties; this.propertyExpressions = new ArrayList<JRPropertyExpression>(element.propertyExpressions); this.dynamicTransferProperties = element.dynamicTransferProperties; // we need a style provider context for this element instance initStyleProviders(); }
@Override public boolean hasDynamicProperty(String name) { // not called very often for now so doing linear search in array for (JRPropertyExpression prop : propertyExpressions) { if (prop.getName().equals(name)) { return true; } } return false; }
private void copyPropertyExpressions(BaseColumn column, ColumnFactory factory) { JRPropertyExpression[] props = column.getPropertyExpressions(); if (props != null && props.length > 0) { propertyExpressions = new ArrayList<JRPropertyExpression>(props.length); for (int i = 0; i < props.length; i++) { propertyExpressions.add(factory.getBaseObjectFactory().getPropertyExpression(props[i])); } } }
/** * Add a dynamic/expression-based property. * * @param propertyExpression the property to add * @see #getPropertyExpressions() */ public void addPropertyExpression(JRPropertyExpression propertyExpression) { propertyExpressions.add(propertyExpression); getEventSupport().fireCollectionElementAddedEvent(JRDesignElement.PROPERTY_PROPERTY_EXPRESSIONS, propertyExpression, propertyExpressions.size() - 1); }
/** * Remove a property expression. * * @param propertyExpression the property expression to remove * @see #addPropertyExpression(JRPropertyExpression) */ public void removePropertyExpression(JRPropertyExpression propertyExpression) { int idx = propertyExpressions.indexOf(propertyExpression); if (idx >= 0) { propertyExpressions.remove(idx); getEventSupport().fireCollectionElementRemovedEvent(JRDesignElement.PROPERTY_PROPERTY_EXPRESSIONS, propertyExpression, idx); } }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); if (propertyExpressions == null) { propertyExpressions = new ArrayList<JRPropertyExpression>(); } }
protected JRPropertiesMap evaluateProperties(BaseColumn column, byte evaluation) throws JRException { JRPropertiesMap staticProperties = column.hasProperties() ? column.getPropertiesMap().cloneProperties() : null; JRPropertiesMap mergedProperties = null; JRPropertyExpression[] propExprs = column.getPropertyExpressions(); if (propExprs == null || propExprs.length == 0) { mergedProperties = staticProperties; } else { JRPropertiesMap dynamicProperties = new JRPropertiesMap(); for (int i = 0; i < propExprs.length; i++) { JRPropertyExpression prop = propExprs[i]; String value = (String) evaluateExpression(prop.getValueExpression(), evaluation); //if (value != null) //for some properties such as data properties in metadata exporters, the null value is significant { dynamicProperties.setProperty(prop.getName(), value); } } mergedProperties = dynamicProperties.cloneProperties(); mergedProperties.setBaseProperties(staticProperties); } return mergedProperties; }
@Override public JRPropertyExpression[] getPropertyExpressions() { return propertyExpressions; }