/*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* Copyright (c) 2001 - 2009 Object Refinery Ltd, Pentaho Corporation and Contributors.. All rights reserved.
*/
package org.pentaho.reporting.engine.classic.core.layout.output;
import java.io.File;
import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
import org.pentaho.reporting.engine.classic.core.DefaultReportEnvironment;
import org.pentaho.reporting.engine.classic.core.DefaultResourceBundleFactory;
import org.pentaho.reporting.engine.classic.core.MasterReport;
import org.pentaho.reporting.engine.classic.core.ReportEnvironment;
import org.pentaho.reporting.engine.classic.core.ReportProcessingException;
import org.pentaho.reporting.engine.classic.core.ResourceBundleFactory;
import org.pentaho.reporting.engine.classic.core.function.ProcessingContext;
import org.pentaho.reporting.engine.classic.core.layout.DefaultLayoutSupport;
import org.pentaho.reporting.engine.classic.core.layout.LayoutSupport;
import org.pentaho.reporting.libraries.base.config.Configuration;
import org.pentaho.reporting.libraries.docbundle.DocumentMetaData;
import org.pentaho.reporting.libraries.docbundle.MemoryDocumentMetaData;
import org.pentaho.reporting.libraries.formula.DefaultFormulaContext;
import org.pentaho.reporting.libraries.formula.FormulaContext;
import org.pentaho.reporting.libraries.resourceloader.ResourceKey;
import org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
/**
* Creation-Date: 08.04.2007, 15:46:44
*
* @author Thomas Morgner
*/
public class DefaultProcessingContext implements ProcessingContext
{
private FormulaContext formulaContext;
private boolean prepareRun;
private LayoutSupport layoutSupport;
private int processingLevel;
private OutputProcessorMetaData outputProcessorMetaData;
private ResourceBundleFactory resourceBundleFactory;
private Configuration configuration;
private int progressLevelCount;
private int progressLevel;
private ResourceManager resourceManager;
private ResourceKey contentBase;
private DocumentMetaData metaData;
private ReportEnvironment reportEnvironment;
/**
* This constructor exists for test-case use only. If you use this to process a real report, most of the settings
* of the report will be ignored and your export will not work as expected.
*/
public DefaultProcessingContext()
{
outputProcessorMetaData = new GenericOutputProcessorMetaData();
layoutSupport = new DefaultLayoutSupport(true, true);
resourceBundleFactory = new DefaultResourceBundleFactory();
configuration = ClassicEngineBoot.getInstance().getGlobalConfig();
resourceManager = new ResourceManager();
resourceManager.registerDefaults();
reportEnvironment = new DefaultReportEnvironment(configuration);
try
{
this.contentBase = resourceManager.createKey(new File("."));
}
catch (ResourceKeyCreationException rkce)
{
this.contentBase = null;
}
metaData = new MemoryDocumentMetaData();
}
public DefaultProcessingContext(final ResourceKey contentBase)
{
this();
if (contentBase != null)
{
this.contentBase = contentBase;
}
}
public DefaultProcessingContext(final Configuration configuration,
final ReportEnvironment reportEnvironment)
{
this();
if (configuration == null)
{
throw new NullPointerException();
}
if (reportEnvironment == null)
{
throw new NullPointerException();
}
this.configuration = configuration;
this.reportEnvironment = reportEnvironment;
}
/**
* @param resourceBundleFactory
* @param configuration
* @deprecated Unless you're writing a test case, this constructor is probably wrong.
*/
public DefaultProcessingContext(final ResourceBundleFactory resourceBundleFactory,
final Configuration configuration)
{
this();
if (resourceBundleFactory == null)
{
throw new NullPointerException();
}
if (configuration == null)
{
throw new NullPointerException();
}
this.resourceBundleFactory = resourceBundleFactory;
this.configuration = configuration;
this.reportEnvironment = new DefaultReportEnvironment(configuration);
}
public DefaultProcessingContext(final MasterReport report) throws ReportProcessingException
{
this(new GenericOutputProcessorMetaData(report.getConfiguration()),
new DefaultLayoutSupport(true, true),
report.getResourceBundleFactory(),
report.getConfiguration(),
report.getResourceManager(),
report.getContentBase(),
report.getBundle().getMetaData(),
report.getReportEnvironment());
}
/**
* @param resourceBundleFactory
* @param configuration
* @param resourceManager
* @param contentBase the content base, from where to load additional resources. (Can be null).
* @param metaData
*/
public DefaultProcessingContext(final ResourceBundleFactory resourceBundleFactory,
final Configuration configuration,
final ResourceManager resourceManager,
final ResourceKey contentBase,
final DocumentMetaData metaData,
final ReportEnvironment environment) throws ReportProcessingException
{
this(new GenericOutputProcessorMetaData(configuration),
new DefaultLayoutSupport(true, true),
resourceBundleFactory,
configuration,
resourceManager,
contentBase,
metaData,
environment);
}
/**
* @param outputProcessorMetaData
* @param layoutSupport
* @param resourceBundleFactory
* @param configuration
* @param resourceManager
* @param contentBase the content base, from where to load additional resources. (Can be null).
* @param metaData
*/
public DefaultProcessingContext(final OutputProcessorMetaData outputProcessorMetaData,
final LayoutSupport layoutSupport,
final ResourceBundleFactory resourceBundleFactory,
final Configuration configuration,
final ResourceManager resourceManager,
final ResourceKey contentBase,
final DocumentMetaData metaData,
final ReportEnvironment environment) throws ReportProcessingException
{
if (environment == null)
{
throw new NullPointerException();
}
if (configuration == null)
{
throw new NullPointerException();
}
if (outputProcessorMetaData == null)
{
throw new NullPointerException();
}
if (layoutSupport == null)
{
throw new NullPointerException();
}
if (resourceBundleFactory == null)
{
throw new NullPointerException();
}
if (resourceManager == null)
{
throw new NullPointerException();
}
this.contentBase = contentBase;
this.resourceManager = resourceManager;
this.formulaContext = new DefaultFormulaContext();
this.outputProcessorMetaData = outputProcessorMetaData;
this.resourceBundleFactory = MasterReport.computeAndInitResourceBundleFactory(resourceBundleFactory, environment);
this.configuration = configuration;
this.layoutSupport = layoutSupport;
if (metaData == null)
{
this.metaData = new MemoryDocumentMetaData();
}
else
{
this.metaData = metaData;
}
this.reportEnvironment = environment;
}
public ResourceManager getResourceManager()
{
return resourceManager;
}
public ResourceKey getContentBase()
{
return contentBase;
}
public int getProgressLevel()
{
return progressLevel;
}
public void setProgressLevel(final int progressLevel)
{
this.progressLevel = progressLevel;
}
public int getProgressLevelCount()
{
return progressLevelCount;
}
public void setProgressLevelCount(final int progressLevelCount)
{
this.progressLevelCount = progressLevelCount;
}
public void setProcessingLevel(final int processingLevel)
{
this.processingLevel = processingLevel;
}
public int getProcessingLevel()
{
return processingLevel;
}
public FormulaContext getFormulaContext()
{
return formulaContext;
}
public void setPrepareRun(final boolean prepareRun)
{
this.prepareRun = prepareRun;
}
public boolean isPrepareRun()
{
return prepareRun;
}
public String getExportDescriptor()
{
return outputProcessorMetaData.getExportDescriptor();
}
public OutputProcessorMetaData getOutputProcessorMetaData()
{
return outputProcessorMetaData;
}
public LayoutSupport getLayoutSupport()
{
return layoutSupport;
}
public ResourceBundleFactory getResourceBundleFactory()
{
return resourceBundleFactory;
}
public Configuration getConfiguration()
{
return configuration;
}
/**
* Returns the outermost master-report's document meta-data.
*
* @return the document meta-data.
*/
public DocumentMetaData getDocumentMetaData()
{
return metaData;
}
public ReportEnvironment getEnvironment()
{
return reportEnvironment;
}
}