📄 reportconfiguration.java
字号:
/**
* Returns the global configuration for JFreeReport.
* <p>
* In the current implementation, the configuration has no properties defined,
* but references a parent configuration that:
* <ul>
* <li>copies across all the <code>System</code> properties to use as report
* configuration properties (obviously the majority of them will not apply to reports);</li>
* <li>itself references a parent configuration that reads its properties from a file
* <code>jfreereport.properties</code>.
* </ul>
*
* @return the global configuration.
*/
public static synchronized ReportConfiguration getGlobalConfig()
{
if (globalConfig == null)
{
globalConfig = new ReportConfiguration();
final PropertyFileReportConfiguration rootProperty = new PropertyFileReportConfiguration();
rootProperty.load("/org/jfree/report/jfreereport.properties");
rootProperty.load("/org/jfree/report/ext/jfreereport-ext.properties");
globalConfig.insertConfiguration(rootProperty);
globalConfig.insertConfiguration(PackageManager.getInstance().getPackageConfiguration());
final PropertyFileReportConfiguration baseProperty = new PropertyFileReportConfiguration();
baseProperty.load("/jfreereport.properties");
globalConfig.insertConfiguration(baseProperty);
final SystemPropertyConfiguration systemConfig = new SystemPropertyConfiguration();
globalConfig.insertConfiguration(systemConfig);
// just in case it is not already started ...
Boot.start();
}
return globalConfig;
}
/**
* The new configuartion will be inserted into the list of report configuration,
* so that this configuration has the given report configuration instance as parent.
*
* @param config the new report configuration.
*/
protected void insertConfiguration(final ReportConfiguration config)
{
config.setParentConfig(getParentConfig());
setParentConfig(config);
}
/**
* Set the parent configuration. The parent configuration is queried, if the
* requested configuration values was not found in this report configuration.
*
* @param config the parent configuration.
*/
protected void setParentConfig(final ReportConfiguration config)
{
if (parentConfiguration == this)
{
throw new IllegalArgumentException("Cannot add myself as parent configuration.");
}
parentConfiguration = config;
}
/**
* Returns the parent configuration. The parent configuration is queried, if the
* requested configuration values was not found in this report configuration.
*
* @return the parent configuration.
*/
protected ReportConfiguration getParentConfig()
{
return parentConfiguration;
}
/**
* Returns the current log target.
*
* @return the log target.
*/
public String getLogTarget()
{
return getConfigProperty(LOGTARGET, LOGTARGET_DEFAULT);
}
/**
* Sets the log target.
*
* @param logTarget the new log target.
*/
public void setLogTarget(final String logTarget)
{
setConfigProperty(LOGTARGET, logTarget);
}
/**
* Returns true, if invalid columns in the dataRow are logged as warning.
*
* @return true, if invalid columns in the dataRow are logged as warning.
*/
public boolean isWarnInvalidColumns()
{
return getConfigProperty(WARN_INVALID_COLUMNS,
WARN_INVALID_COLUMNS_DEFAULT).equalsIgnoreCase("true");
}
/**
* Set to true, if you want to get informed when invalid column-requests are
* made to the DataRow.
*
* @param warnInvalidColumns the warning flag
*/
public void setWarnInvalidColumns(final boolean warnInvalidColumns)
{
setConfigProperty(WARN_INVALID_COLUMNS, String.valueOf(warnInvalidColumns));
}
/**
* Returns true, if physical operation comments should be added to the physical page.
* This is only usefull for debugging.
*
* @return true, if comments are enabled.
*/
public boolean isPrintOperationComment()
{
return getConfigProperty(PRINT_OPERATION_COMMENT,
PRINT_OPERATION_COMMENT_DEFAULT).equalsIgnoreCase("true");
}
/**
* set to true, if physical operation comments should be added to the physical page.
* This is only usefull for debugging.
*
* @param print set to true, if comments should be enabled.
*/
public void setPrintOperationComment(final boolean print)
{
setConfigProperty(PRINT_OPERATION_COMMENT, String.valueOf(print));
}
/**
* Returns true, if the Graphics2D should use aliasing to render text. Defaults to false.
*
* @return true, if aliasing is enabled.
*/
public boolean isFontRendererUseAliasing()
{
return getConfigProperty(FONTRENDERER_USEALIASING,
FONTRENDERER_USEALIASING_DEFAULT).equalsIgnoreCase("true");
}
/**
* set to true, if the Graphics2D should use aliasing to render text. Defaults to false.
*
* @param alias set to true, if the Graphics2D should use aliasing.
*/
public void setFontRendererUseAliasing(final boolean alias)
{
setConfigProperty(FONTRENDERER_USEALIASING, String.valueOf(alias));
}
/**
* Returns true, if the Graphics2D implementation is buggy and is not really able
* to place/calculate the fontsizes correctly. Defaults to false. (SunJDK on Windows
* is detected and corrected, Linux SunJDK 1.3 is buggy, but not detectable).
*
* @return true, if the Graphics2D implementation does not calculate the string
* positions correctly and an alternative implementation should be used.
*/
public boolean isFontRendererBuggy()
{
return getConfigProperty(FONTRENDERER_ISBUGGY_FRC,
FONTRENDERER_ISBUGGY_FRC_DEFAULT).equalsIgnoreCase("true");
}
/**
* set to true, if the Graphics2D implementation is buggy and is not really able
* to place/calculate the fontsizes correctly. Defaults to false. (SunJDK on Windows
* is detected and corrected, Linux SunJDK 1.3 is buggy, but not detectable).
*
* @param buggy set to true, if the Graphics2D implementation does not calculate the string
* positions correctly and an alternative implementation should be used.
*/
public void setFontRendererBuggy(final boolean buggy)
{
setConfigProperty(FONTRENDERER_ISBUGGY_FRC, String.valueOf(buggy));
}
/**
* Returns all defined configuration properties for the report. The enumeration
* contains all keys of the changed properties, properties set from files or
* the system properties are not included.
*
* @return all defined configuration properties for the report.
*/
public Enumeration getConfigProperties()
{
return configuration.keys();
}
/**
* Checks, whether a stricter error handling is applied to the report processing.
* If set to true, then errors in the handling of report events will cause the report
* processing to fail. This is a safe-and-paranoid setting, life is simpler with
* this set to false. The property defaults to false, as this is the old behaviour.
* <p>
* A properly defined report should not throw exceptions, so it is safe to set this
* to true.
*
* @return true, if the strict handling is enabled, false otherwise.
*/
public boolean isStrictErrorHandling()
{
return getConfigProperty(STRICT_ERRORHANDLING,
STRICT_ERRORHANDLING_DEFAULT).equalsIgnoreCase("true");
}
/**
* Defines, whether a stricter error handling is applied to the report processing.
* If set to true, then errors in the handling of report events will cause the report
* processing to fail. This is a safe-and-paranoid setting, life is simpler with
* this set to false. The property defaults to false, as this is the old behaviour.
* <p>
* A properly defined report should not throw exceptions, so it is safe to set this
* to true.
*
* @param strictErrorHandling if set to true, then errors in the event dispatching will
* cause the reporting to fail.
*/
public void setStrictErrorHandling(final boolean strictErrorHandling)
{
setConfigProperty(STRICT_ERRORHANDLING, String.valueOf(strictErrorHandling));
}
/**
* Helper method for serialization.
*
* @param out the output stream where to write the object.
* @throws IOException if errors occur while writing the stream.
*/
private void writeObject(final ObjectOutputStream out)
throws IOException
{
out.defaultWriteObject();
if (parentConfiguration == globalConfig)
{
out.writeBoolean(false);
}
else
{
out.writeBoolean(true);
out.writeObject(parentConfiguration);
}
}
/**
* Helper method for serialization.
*
* @param in the input stream from where to read the serialized object.
* @throws IOException when reading the stream fails.
* @throws ClassNotFoundException if a class definition for a serialized object
* could not be found.
*/
private void readObject(final ObjectInputStream in)
throws IOException, ClassNotFoundException
{
in.defaultReadObject();
final boolean readParent = in.readBoolean();
if (readParent)
{
parentConfiguration = (ReportConfiguration) in.readObject();
}
else
{
parentConfiguration = ReportConfiguration.getGlobalConfig();
}
}
/**
* Searches all property keys that start with a given prefix.
*
* @param prefix the prefix that all selected property keys should share
* @return the properties as iterator.
*/
public Iterator findPropertyKeys(final String prefix)
{
final TreeSet keys = new TreeSet();
collectPropertyKeys(prefix, this, keys);
return Collections.unmodifiableSet(keys).iterator();
}
/**
* Collects property keys from this and all parent report configurations, which
* start with the given prefix.
*
* @param prefix the prefix, that selects the property keys.
* @param config the currently processed report configuration.
* @param collector the target list, that should receive all valid keys.
*/
private void collectPropertyKeys(final String prefix, final ReportConfiguration config,
final TreeSet collector)
{
final Enumeration enum = config.getConfigProperties();
while (enum.hasMoreElements())
{
final String key = (String) enum.nextElement();
if (key.startsWith(prefix))
{
if (collector.contains(key) == false)
{
collector.add(key);
}
}
}
if (config.parentConfiguration != null)
{
collectPropertyKeys(prefix, config.parentConfiguration, collector);
}
}
/**
* Checks, whether the given key is localy defined in this instance or
* whether the key's value is inherited.
*
* @param key the key that should be checked.
* @return true, if the key is defined locally, false otherwise.
*/
public boolean isLocallyDefined (final String key)
{
return configuration.containsKey(key);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -