/** * Returns the current value for the data source. * * @param runtime the expression runtime that is used to evaluate formulas and expressions when * computing the value of this filter. * @param element * @return the value. */ public Object getValue(final ExpressionRuntime runtime, final ReportElement element) { if (runtime == null) { return null; } final String resourceId; if (resourceIdentifier != null) { resourceId = resourceIdentifier; } else { resourceId = runtime .getConfiguration() .getConfigProperty(ResourceBundleFactory.DEFAULT_RESOURCE_BUNDLE_CONFIG_KEY); } if (resourceId == null) { return null; } try { final ResourceBundleFactory resourceBundleFactory = runtime.getResourceBundleFactory(); final ResourceBundle bundle = resourceBundleFactory.getResourceBundle(resourceId); // update the format string, if neccessary ... if (ObjectUtilities.equal(formatKey, appliedFormatKey) == false) { final String newFormatString = bundle.getString(formatKey); messageFormatSupport.setFormatString(newFormatString); appliedFormatKey = formatKey; } messageFormatSupport.setLocale(resourceBundleFactory.getLocale()); return messageFormatSupport.performFormat(runtime.getDataRow()); } catch (MissingResourceException mre) { if (logger.isDebugEnabled()) { logger.debug( "Failed to format the value for resource-id " + resourceId + ", was '" + mre.getMessage() + "'"); } return null; } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Failed to format the value for resource-id " + resourceId, e); } return null; } }
/** * Returns the replacement text that is used if one of the referenced message parameters is null. * * @return the replacement text for null-values. */ public String getNullString() { return messageFormatSupport.getNullString(); }
/** * Clones this <code>DataSource</code>. * * @return the clone. * @throws CloneNotSupportedException this should never happen. */ public ResourceMessageFormatFilter clone() throws CloneNotSupportedException { final ResourceMessageFormatFilter mf = (ResourceMessageFormatFilter) super.clone(); mf.messageFormatSupport = (MessageFormatSupport) messageFormatSupport.clone(); return mf; }