diff options
author | Oliver Bolte <obo@openoffice.org> | 2009-03-04 15:27:10 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2009-03-04 15:27:10 +0000 |
commit | 9544c14f4a931d8d8b2e66a6cb87fb53d4505cd4 (patch) | |
tree | 29b05df340e2c19c9e60947d63bf7b425cfb95c2 /reportbuilder/java/com/sun/star/report/pentaho/SOReportJobFactory.java | |
parent | 4f4fe6aa7203aac35a774108f4880553df5b93a4 (diff) |
CWS-TOOLING: integrate CWS rptfix04
2009-02-23 01:59:54 +0100 rene r268341 : #i10000# fix system-jfreereport build
2009-02-13 10:17:16 +0100 oj r267696 : #i98549# integrate zip form pentaho package
2009-02-03 14:48:34 +0100 oj r267330 : set formula locale to doc locale
2009-02-03 14:45:54 +0100 oj r267329 : set formula locale to doc locale
2009-02-03 11:50:03 +0100 oj r267311 : set formula locale to doc locale
2009-02-03 08:55:02 +0100 oj r267297 : unix line ends
2009-01-28 11:21:24 +0100 rene r267043 : #i98549# s/DESIGN/BUILDER/ also for Sun
2009-01-27 17:17:50 +0100 rene r267012 : merge builfix from trunk
2009-01-27 14:16:30 +0100 rene r266991 : #i10000# fix rebase which left out the whole changes in former config_office; sync variable names (s/LIB_//) and some other things
2009-01-27 10:01:09 +0100 oj r266959 : CWS-TOOLING: rebase CWS rptfix04 to trunk@266944 (milestone: DEV300:m40)
2009-01-27 08:00:16 +0100 oj r266951 : conflict in mergeinfo
2009-01-26 12:23:03 +0100 oj r266914 : #i98383# fix grouping
2009-01-23 22:03:03 +0100 rene r266852 : fix --enable-report-builder description
2009-01-23 10:37:27 +0100 oj r266778 : set escape processing when set at query
2009-01-23 09:17:16 +0100 fs r266770 : add CWS name to version
2009-01-21 13:57:35 +0100 oj r266669 : merge for build bots
2009-01-20 09:07:24 +0100 oj r266552 : CWS-TOOLING: rebase CWS rptfix04 to trunk@266428 (milestone: DEV300:m39)
2009-01-20 08:34:16 +0100 oj r266551 : rebase
2009-01-20 08:33:59 +0100 oj r266550 : rebase
2009-01-20 08:32:50 +0100 oj r266549 : rebase
2009-01-20 08:30:13 +0100 oj r266548 : rebase
2009-01-20 08:29:30 +0100 oj r266547 : rebase
2009-01-20 08:22:33 +0100 oj r266546 : merge short cuts from dba31g
2009-01-19 21:04:08 +0100 rene r266525 : #i10000# we need officecfg for component-update.dtd
2009-01-19 21:01:26 +0100 rene r266524 : #i10000# fix import
2009-01-19 20:26:20 +0100 rene r266523 : #i10000# remove svn conflicts markers; fix build
2009-01-19 14:23:56 +0100 rene r266496 : libbase depends on apache-commons..
2009-01-19 14:00:42 +0100 oj r266495 : merge from m39
2009-01-19 12:39:00 +0100 oj r266489 : CWS-TOOLING: rebase CWS rptfix04 to trunk@266428 (milestone: DEV300:m39)
2009-01-16 11:47:04 +0100 oj r266410 : #i97560# add , between expressions
2009-01-09 17:11:38 +0100 rene r266103 : don't show "checking which Apache commons-* libs to use" when we neither build the wiki editor nor the SRB
2009-01-09 16:48:02 +0100 rene r266099 : #i10000# reportbuilder needs apache-commons
2009-01-09 15:43:35 +0100 oj r266093 : use of new nspaces
2009-01-09 15:41:34 +0100 oj r266092 : use of new nspaces
2009-01-09 14:44:15 +0100 rene r266088 : fix typo/description
2009-01-09 12:48:51 +0100 rene r266074 : #i10000# fix install
2009-01-09 11:52:53 +0100 rene r266070 : #i10000# more build fixes
2009-01-09 10:53:13 +0100 rene r266062 : #i10000# ENABLE_REPORTBUILDER also in set_soenv.in, fix typo
2009-01-09 10:40:24 +0100 rene r266060 : #i10000# configure fix for new reportbuilder module, typo fix at libfonts
2009-01-09 10:01:52 +0100 rene r266055 : #i10000# adapt to current configure.in
2009-01-09 09:59:32 +0100 oj r266054 : add new pentaho jars
2009-01-09 09:47:54 +0100 oj r266049 : merge changes from DEV300_m39
2009-01-09 09:14:08 +0100 oj r266048 : merge from DEV300_m39
2009-01-09 08:28:43 +0100 oj r266045 : merge changes from dba31g
2009-01-09 07:58:10 +0100 oj r266044 : replace JCOMMON with LIB
2009-01-08 13:42:24 +0100 oj r266005 : move ext to reportbuilder
2009-01-08 13:41:38 +0100 oj r266004 : add dep for license
2009-01-08 13:27:56 +0100 oj r266001 : new module for Sun report Builder extension
2009-01-07 12:58:13 +0100 oj r265960 : CWS-TOOLING: rebase CWS rptfix04 to trunk@265758 (milestone: DEV300:m38)
2008-12-15 13:47:18 +0100 oj r265481 : new pentaho resources
2008-12-15 10:04:01 +0100 oj r265462 : integrate new pentaho sources
2008-12-15 10:02:54 +0100 oj r265461 : #i96888# fix date time function
2008-12-12 09:23:29 +0100 oj r265389 : #97174# check of res < 0 removed
2008-12-12 09:15:54 +0100 oj r265388 : #i9716# fix for DayFunction
2008-12-11 12:24:24 +0100 oj r265281 : integrate new pentaho sources
2008-12-11 11:49:16 +0100 oj r265273 : integrate new pentaho sources
2008-12-11 09:34:07 +0100 oj r265248 : integrate new pentaho sources
2008-12-10 18:58:06 +0100 oj r265227 : introduce new pentaho sources
2008-12-10 18:56:43 +0100 oj r265226 : introduce new pentaho sources
2008-12-10 18:54:26 +0100 oj r265225 : introduce new pentaho sources
2008-12-10 18:42:59 +0100 oj r265221 : introduce new pentaho sources
2008-12-10 17:24:23 +0100 oj r265212 : introduce new pentaho sources
2008-12-10 17:24:07 +0100 oj r265211 : new pentaho sources
2008-12-10 17:23:00 +0100 oj r265210 : introduce new pentaho sources
Diffstat (limited to 'reportbuilder/java/com/sun/star/report/pentaho/SOReportJobFactory.java')
-rw-r--r-- | reportbuilder/java/com/sun/star/report/pentaho/SOReportJobFactory.java | 437 |
1 files changed, 437 insertions, 0 deletions
diff --git a/reportbuilder/java/com/sun/star/report/pentaho/SOReportJobFactory.java b/reportbuilder/java/com/sun/star/report/pentaho/SOReportJobFactory.java new file mode 100644 index 000000000000..cda541184968 --- /dev/null +++ b/reportbuilder/java/com/sun/star/report/pentaho/SOReportJobFactory.java @@ -0,0 +1,437 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: SOReportJobFactory.java,v $ + * $Revision: 1.7 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +package com.sun.star.report.pentaho; + +import com.sun.star.beans.NamedValue; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.beans.PropertyVetoException; +import com.sun.star.beans.XPropertyChangeListener; +import com.sun.star.beans.XVetoableChangeListener; +import com.sun.star.embed.XStorage; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.lang.XSingleComponentFactory; +import com.sun.star.lib.uno.helper.Factory; +import com.sun.star.lib.uno.helper.PropertySetMixin; +import com.sun.star.lib.uno.helper.WeakBase; +import com.sun.star.registry.InvalidRegistryException; +import com.sun.star.registry.InvalidValueException; +import com.sun.star.registry.XRegistryKey; +import com.sun.star.registry.XSimpleRegistry; +import com.sun.star.report.DataSourceFactory; +import com.sun.star.report.JobProperties; +import com.sun.star.report.ReportEngineParameterNames; +import com.sun.star.report.ReportExecutionException; +import com.sun.star.report.ReportJob; +import com.sun.star.report.ReportJobDefinition; +import com.sun.star.report.ReportJobFactory; +import com.sun.star.report.SDBCReportDataFactory; +import com.sun.star.report.SOImageService; +import com.sun.star.report.StorageRepository; +import com.sun.star.report.XReportDefinition; +import com.sun.star.report.pentaho.SOReportJobFactory._SOReportJobFactory; +import com.sun.star.sdbc.XConnection; +import com.sun.star.sdbc.XRowSet; +import com.sun.star.task.XJob; +import com.sun.star.uno.Exception; +import com.sun.star.uno.Type; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * This class capsulates the class, that implements the minimal component, a factory for creating the service + * (<CODE>__getComponentFactory</CODE>) and a method, that writes the information into the given registry key + * (<CODE>__writeRegistryServiceInfo</CODE>). + */ +public class SOReportJobFactory +{ + + private SOReportJobFactory() + { + } + + public static class _SOReportJobFactory extends WeakBase implements XInitialization, XServiceInfo, XJob, XPropertySet, ReportJobFactory + { + + private static final Log LOGGER = LogFactory.getLog(_SOReportJobFactory.class); + /** + * The service name, that must be used to get an instance of this service. + */ + private static final String __serviceName = + "com.sun.star.report.pentaho.SOReportJobFactory"; + private final PropertySetMixin m_prophlp; + /** + * The initial component contextr, that gives access to the service manager, supported singletons, ... It's + * often later used + */ + private final XComponentContext m_cmpCtx; + private XConnection activeConnection; + private XReportDefinition report; + + public _SOReportJobFactory(final XComponentContext xCompContext) + { + m_cmpCtx = xCompContext; + m_prophlp = new PropertySetMixin(m_cmpCtx, this, + new Type(XJob.class), + null); // no optionals + } + + /** + * This method is a member of the interface for initializing an object directly after its creation. + * + * @param object This array of arbitrary objects will be passed to the component after its creation. + * @throws Exception Every exception will not be handled, but will be passed to the caller. + */ + public void initialize(final Object[] object) + throws com.sun.star.uno.Exception + { + /* The component describes what arguments its expected and in which + * order!At this point you can read the objects and can intialize + * your component using these objects. + */ + } + + /** + * This method returns an array of all supported service names. + * + * @return Array of supported service names. + */ + public String[] getSupportedServiceNames() + { + return getServiceNames(); + } + + /** + * This method is a simple helper function to used in the static component initialisation functions as well as + * in getSupportedServiceNames. + */ + public static String[] getServiceNames() + { + return new String[] + { + __serviceName + }; + } + + /** + * This method returns true, if the given service will be supported by the component. + * + * @param sServiceName Service name. + * @return True, if the given service name will be supported. + */ + public boolean supportsService(final String sServiceName) + { + return sServiceName.equals(__serviceName); + } + + /** + * Return the class name of the component. + * + * @return Class name of the component. + */ + public String getImplementationName() + { + return SOReportJobFactory.class.getName(); + } + + private String getLocaleFromRegistry(final XSimpleRegistry simpleReg, final String path, final String value) + { + String currentLocale = null; + try + { + simpleReg.open(path, true, false); + XRegistryKey xRegistryRootKey = simpleReg.getRootKey(); + // read locale + XRegistryKey locale = xRegistryRootKey.openKey(value); + if ( locale != null ) + { + final String newLocale = locale.getStringValue(); + if ( newLocale != null ) + { + currentLocale = newLocale.replace('-', '_'); + } + } + } + catch ( InvalidValueException ex ) + { + Logger.getLogger(SOReportJobFactory.class.getName()).log(Level.SEVERE, null, ex); + } + catch ( InvalidRegistryException ex ) + { + Logger.getLogger(SOReportJobFactory.class.getName()).log(Level.SEVERE, null, ex); + } + + return currentLocale; + } + + public Object execute(final NamedValue[] namedValue) + throws com.sun.star.lang.IllegalArgumentException, com.sun.star.uno.Exception + { + final ClassLoader cl = java.lang.Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); + try + { + XSimpleRegistry simpleReg = (XSimpleRegistry) UnoRuntime.queryInterface(XSimpleRegistry.class, + m_cmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.configuration.ConfigurationRegistry", m_cmpCtx)); + + String currentLocale = getLocaleFromRegistry(simpleReg,"org.openoffice.Setup","L10N/ooSetupSystemLocale"); + if ( currentLocale == null || "".equals(currentLocale) ) + { + currentLocale = getLocaleFromRegistry(simpleReg,"org.openoffice.Office.Linguistic","General/DefaultLocale"); + } + if ( currentLocale != null && !"".equals(currentLocale) ) + System.setProperty("org.pentaho.reporting.libraries.formula.locale", currentLocale); + final ReportJob job = createReportJob(namedValue); + job.execute(); + + } + catch ( java.lang.Exception e ) + { + LOGGER.error("ReportProcessing failed", e); + throw new com.sun.star.lang.WrappedTargetException(e.getMessage(), this, null); + } + catch ( java.lang.IncompatibleClassChangeError e2 ) + { + LOGGER.error("Detected an IncompatibleClassChangeError"); + throw new com.sun.star.lang.WrappedTargetException("caught a " + e2.getClass().getName(), this, new com.sun.star.uno.Exception(e2.getLocalizedMessage())); + } + Thread.currentThread().setContextClassLoader(cl); + + return null; + } + + public ReportJob createReportJob(final NamedValue[] namedValue) throws IllegalArgumentException, ReportExecutionException, Exception + { + XStorage input = null; + XStorage output = null; + XRowSet rowSet = null; + String mimetype = null; + String author = null; + String title = null; + + for ( int i = 0; i < namedValue.length; ++i ) + { + final NamedValue aProps = namedValue[i]; + if ( "ActiveConnection".equalsIgnoreCase(aProps.Name) ) + { + activeConnection = (XConnection) UnoRuntime.queryInterface(XConnection.class, aProps.Value); + } + else if ( "ReportDefinition".equalsIgnoreCase(aProps.Name) ) + { + report = (XReportDefinition) UnoRuntime.queryInterface(XReportDefinition.class, aProps.Value); + } + else if ( "InputStorage".equalsIgnoreCase(aProps.Name) ) + { + input = (XStorage) UnoRuntime.queryInterface(XStorage.class, aProps.Value); + } + else if ( "OutputStorage".equalsIgnoreCase(aProps.Name) ) + { + output = (XStorage) UnoRuntime.queryInterface(XStorage.class, aProps.Value); + } + else if ( "RowSet".equalsIgnoreCase(aProps.Name) ) + { + rowSet = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, aProps.Value); + } + else if ( "mimetype".equalsIgnoreCase(aProps.Name) ) + { + mimetype = (String) aProps.Value; + } + else if ( ReportEngineParameterNames.AUTHOR.equalsIgnoreCase(aProps.Name) ) + { + author = (String) aProps.Value; + } + else if ( ReportEngineParameterNames.TITLE.equalsIgnoreCase(aProps.Name) ) + { + title = (String) aProps.Value; + } + } + + if ( input == null || output == null ) + { + throw new com.sun.star.lang.IllegalArgumentException(); + } + + if ( rowSet == null ) + { + if ( report == null || activeConnection == null ) + { + throw new com.sun.star.lang.IllegalArgumentException(); + } + mimetype = report.getMimeType(); + } + else + { + final XPropertySet set = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, rowSet); + if ( set == null ) + { + throw new com.sun.star.lang.IllegalArgumentException(); + } + activeConnection = (XConnection) UnoRuntime.queryInterface(XConnection.class, set.getPropertyValue("ActiveConnection")); + } + if ( mimetype == null ) + { + mimetype = PentahoReportEngineMetaData.OPENDOCUMENT_TEXT; + } + + final DataSourceFactory dataFactory = new SDBCReportDataFactory(m_cmpCtx, activeConnection); + final StorageRepository storageRepository = new StorageRepository(input, output); + + final String inputName = "content.xml"; + final String outputName = "content.xml"; + + final PentahoReportEngine engine = new PentahoReportEngine(); + final ReportJobDefinition definition = engine.createJobDefinition(); + final JobProperties procParms = definition.getProcessingParameters(); + procParms.setProperty(ReportEngineParameterNames.INPUT_REPOSITORY, storageRepository); + procParms.setProperty(ReportEngineParameterNames.OUTPUT_REPOSITORY, storageRepository); + procParms.setProperty(ReportEngineParameterNames.INPUT_NAME, inputName); + procParms.setProperty(ReportEngineParameterNames.OUTPUT_NAME, outputName); + procParms.setProperty(ReportEngineParameterNames.CONTENT_TYPE, mimetype); + procParms.setProperty(ReportEngineParameterNames.INPUT_DATASOURCE_FACTORY, dataFactory); + procParms.setProperty(ReportEngineParameterNames.IMAGE_SERVICE, new SOImageService(m_cmpCtx)); + procParms.setProperty(ReportEngineParameterNames.INPUT_REPORTJOB_FACTORY, this); + if ( author != null ) + { + procParms.setProperty(ReportEngineParameterNames.AUTHOR, author); + } + if ( title != null ) + { + procParms.setProperty(ReportEngineParameterNames.TITLE, title); + } + + return engine.createJob(definition); + } + + // com.sun.star.beans.XPropertySet: + public com.sun.star.beans.XPropertySetInfo getPropertySetInfo() + { + return m_prophlp.getPropertySetInfo(); + } + + public void setPropertyValue(final String aPropertyName, final Object aValue) + throws UnknownPropertyException, PropertyVetoException, com.sun.star.lang.IllegalArgumentException, + WrappedTargetException + { + m_prophlp.setPropertyValue(aPropertyName, aValue); + } + + public Object getPropertyValue(final String aPropertyName) + throws UnknownPropertyException, WrappedTargetException + { + return m_prophlp.getPropertyValue(aPropertyName); + } + + public void addPropertyChangeListener(final String aPropertyName, final XPropertyChangeListener xListener) + throws UnknownPropertyException, WrappedTargetException + { + m_prophlp.addPropertyChangeListener(aPropertyName, xListener); + } + + public void removePropertyChangeListener(final String aPropertyName, final XPropertyChangeListener xListener) + throws UnknownPropertyException, WrappedTargetException + { + m_prophlp.removePropertyChangeListener(aPropertyName, xListener); + } + + public void addVetoableChangeListener(final String aPropertyName, final XVetoableChangeListener xListener) + throws UnknownPropertyException, WrappedTargetException + { + m_prophlp.addVetoableChangeListener(aPropertyName, xListener); + } + + public void removeVetoableChangeListener(final String aPropertyName, final XVetoableChangeListener xListener) + throws UnknownPropertyException, WrappedTargetException + { + m_prophlp.removeVetoableChangeListener(aPropertyName, xListener); + } + } + + /** + * Gives a factory for creating the service. This method is called by the <code>JavaLoader</code> + * <p/> + * + * @param sImplName the name of the implementation for which a service is desired + * @return returns a <code>XSingleComponentFactory</code> for creating the component + * @see com.sun.star.comp.loader.JavaLoader + */ + public static XSingleComponentFactory __getComponentFactory(final String sImplName) + { + XSingleComponentFactory xFactory = null; + + try + { + if ( sImplName.equals(_SOReportJobFactory.class.getName()) ) + { + xFactory = Factory.createComponentFactory(_SOReportJobFactory.class, _SOReportJobFactory.getServiceNames()); + } + else if ( sImplName.equals(SOFunctionManager.class.getName()) ) + { + xFactory = Factory.createComponentFactory(SOFunctionManager.class, SOFunctionManager.getServiceNames()); + } + else if ( sImplName.equals(SOFormulaParser.class.getName()) ) + { + xFactory = Factory.createComponentFactory(SOFormulaParser.class, SOFormulaParser.getServiceNames()); + } + } + catch ( java.lang.IncompatibleClassChangeError e2 ) + { + } + + return xFactory; + } + + /** + * Writes the service information into the given registry key. This method is called by the <code>JavaLoader</code> + * <p/> + * + * @param regKey the registryKey + * @return returns true if the operation succeeded + * @see com.sun.star.comp.loader.JavaLoader + */ + public static boolean __writeRegistryServiceInfo(final XRegistryKey regKey) + { + return Factory.writeRegistryServiceInfo(SOFunctionManager.class.getName(), + SOFunctionManager.getServiceNames(), + regKey) && + Factory.writeRegistryServiceInfo(_SOReportJobFactory.class.getName(), + _SOReportJobFactory.getServiceNames(), + regKey) && + Factory.writeRegistryServiceInfo(SOFormulaParser.class.getName(), + SOFormulaParser.getServiceNames(), + regKey); + } +} |