001: package org.pentaho.plugin.jfreereport.helper;
002:
003: import java.util.Enumeration;
004: import java.util.Iterator;
005: import java.util.List;
006:
007: import org.dom4j.Attribute;
008: import org.dom4j.Element;
009: import org.jfree.report.util.PropertyLookupParser;
010: import org.jfree.util.Configuration;
011: import org.jfree.util.DefaultConfiguration;
012: import org.pentaho.core.solution.IParameterProvider;
013: import org.pentaho.core.system.IApplicationContext;
014: import org.pentaho.core.system.ISystemSettings;
015: import org.pentaho.core.system.PentahoSystem;
016:
017: /**
018: * Creation-Date: 05.07.2007, 19:48:16
019: *
020: * @author Thomas Morgner
021: */
022: public class PentahoReportConfiguration extends PropertyLookupParser
023: implements Configuration {
024: private static final long serialVersionUID = -1191667017348135395L;
025:
026: private DefaultConfiguration config;
027:
028: public PentahoReportConfiguration() {
029: setOpeningBraceChar('(');
030: setClosingBraceChar(')');
031: config = new DefaultConfiguration();
032: final ISystemSettings cfg = PentahoSystem.getSystemSettings();
033: if (cfg == null) {
034: return;
035: }
036: final List reportSettings = cfg
037: .getSystemSettings("report-config/entry");//$NON-NLS-1$
038: for (int i = 0; i < reportSettings.size(); i++) {
039: final Element element = (Element) reportSettings.get(i);
040: final Attribute name = element.attribute("name");//$NON-NLS-1$
041: final Attribute value = element.attribute("value");//$NON-NLS-1$
042: if (name != null && value != null) {
043: this .config.setConfigProperty(name.getValue(),
044: translateAndLookup(value.getValue()));
045: }
046: }
047: }
048:
049: public Object clone() throws CloneNotSupportedException {
050: final PentahoReportConfiguration cfg = (PentahoReportConfiguration) super
051: .clone();
052: cfg.config = (DefaultConfiguration) cfg.clone();
053: return cfg;
054: }
055:
056: public Iterator findPropertyKeys(final String prefix) {
057: return config.findPropertyKeys(prefix);
058: }
059:
060: public Enumeration getConfigProperties() {
061: return config.getConfigProperties();
062: }
063:
064: public String getConfigProperty(final String key) {
065: return getConfigProperty(key, null);
066: }
067:
068: public String getConfigProperty(final String key,
069: final String defaultvalue) {
070: return config.getConfigProperty(key, defaultvalue);
071: }
072:
073: protected String lookupVariable(final String property) {
074: final IApplicationContext context = PentahoSystem
075: .getApplicationContext();
076: if (context != null) {
077: final String contextParam = context.getProperty(property);
078: if (contextParam != null) {
079: return contextParam;
080: }
081: }
082:
083: final IParameterProvider globalParameters = PentahoSystem
084: .getGlobalParameters();
085: if (globalParameters != null) {
086: final String globalParam = globalParameters
087: .getStringParameter(property, null);
088: if (globalParam != null) {
089: return globalParam;
090: }
091: }
092:
093: final String systemSetting = PentahoSystem.getSystemSetting(
094: property, null);
095: if (systemSetting != null) {
096: return systemSetting;
097: }
098:
099: if (context != null) {
100: if ("base-url".equals(property))//$NON-NLS-1$
101: {
102: return context.getBaseUrl();
103: }
104: }
105: return null;
106: }
107: }
|