001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * ResourceMessageTemplate.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.filter.templates;
030:
031: import java.util.MissingResourceException;
032:
033: import org.jfree.report.filter.ResourceMessageFormatFilter;
034: import org.jfree.report.filter.StringFilter;
035: import org.jfree.report.function.ExpressionRuntime;
036:
037: /**
038: * A field template that formats values from the datarow using a message format object. The message format string
039: * is looked up from a Resource-Bundle.
040: *
041: * @author Thomas Morgner
042: * @since 2006-01-24
043: */
044: public class ResourceMessageTemplate extends AbstractTemplate {
045: /**
046: * A string filter.
047: */
048: private StringFilter stringFilter;
049:
050: /**
051: * A resource file filter.
052: */
053: private ResourceMessageFormatFilter resourceFilter;
054:
055: /**
056: * Creates a new template.
057: */
058: public ResourceMessageTemplate() {
059: resourceFilter = new ResourceMessageFormatFilter();
060: stringFilter = new StringFilter();
061: stringFilter.setDataSource(resourceFilter);
062: }
063:
064: /**
065: * Returns the key that is used to lookup the format string used in the message format in the resource bundle.
066: *
067: * @return the resource bundle key.
068: */
069: public String getFormatKey() {
070: return resourceFilter.getFormatKey();
071: }
072:
073: /**
074: * Defines the key that is used to lookup the format string used in the message format in the resource bundle.
075: *
076: * @param formatKey a resourcebundle key for the message format lookup.
077: */
078: public void setFormatKey(final String formatKey) {
079: resourceFilter.setFormatKey(formatKey);
080: }
081:
082: /**
083: * Returns the resource class name.
084: *
085: * @return The resource class name.
086: */
087: public String getResourceIdentifier() {
088: return resourceFilter.getResourceIdentifier();
089: }
090:
091: /**
092: * Sets the resource class name.
093: *
094: * @param resourceClassName the resource class name.
095: * @throws MissingResourceException if the resource is missing.
096: */
097: public void setResourceIdentifier(final String resourceClassName)
098: throws MissingResourceException {
099: resourceFilter.setResourceIdentifier(resourceClassName);
100: }
101:
102: /**
103: * Returns the string that represents a <code>null</code> value.
104: *
105: * @return The string that represents a <code>null</code> value.
106: */
107: public String getNullValue() {
108: return stringFilter.getNullValue();
109: }
110:
111: /**
112: * Sets the string that represents a <code>null</code> value.
113: *
114: * @param nullValue the string that represents a <code>null</code> value.
115: */
116: public void setNullValue(final String nullValue) {
117: stringFilter.setNullValue(nullValue);
118: resourceFilter.setNullString(nullValue);
119: }
120:
121: /**
122: * Returns the current value for the data source.
123: *
124: * @param runtime the expression runtime that is used to evaluate formulas and expressions when computing the value of
125: * this filter.
126: * @return the value.
127: */
128: public Object getValue(final ExpressionRuntime runtime) {
129: return stringFilter.getValue(runtime);
130: }
131:
132: /**
133: * Clones the template.
134: *
135: * @return the clone.
136: *
137: * @throws CloneNotSupportedException this should never happen.
138: */
139: public Object clone() throws CloneNotSupportedException {
140: final ResourceMessageTemplate template = (ResourceMessageTemplate) super
141: .clone();
142: template.stringFilter = (StringFilter) stringFilter.clone();
143: template.resourceFilter = (ResourceMessageFormatFilter) template.stringFilter
144: .getDataSource();
145: return template;
146: }
147:
148: }
|