LCOV - code coverage report
Current view: top level - reportdesign/source/core/api - ReportEngineJFree.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 23 189 12.2 %
Date: 2015-06-13 12:38:46 Functions: 12 34 35.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #include <com/sun/star/beans/PropertyValue.hpp>
      20             : #include "ReportEngineJFree.hxx"
      21             : #include <comphelper/enumhelper.hxx>
      22             : #include <comphelper/documentconstants.hxx>
      23             : #include <comphelper/storagehelper.hxx>
      24             : #include <connectivity/dbtools.hxx>
      25             : #include <comphelper/mimeconfighelper.hxx>
      26             : #include <comphelper/property.hxx>
      27             : #include <comphelper/string.hxx>
      28             : #include <cppuhelper/supportsservice.hxx>
      29             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      30             : #include <com/sun/star/beans/NamedValue.hpp>
      31             : #include <com/sun/star/frame/Desktop.hpp>
      32             : #include <com/sun/star/frame/XComponentLoader.hpp>
      33             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      34             : #include <com/sun/star/embed/XTransactedObject.hpp>
      35             : #include <com/sun/star/sdb/XCompletedExecution.hpp>
      36             : #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
      37             : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
      38             : #include <com/sun/star/sdb/CommandType.hpp>
      39             : 
      40             : #include <com/sun/star/task/XInteractionHandler.hpp>
      41             : #include <com/sun/star/task/XJob.hpp>
      42             : 
      43             : #include <tools/debug.hxx>
      44             : #include <unotools/useroptions.hxx>
      45             : #include <unotools/tempfile.hxx>
      46             : #include <unotools/sharedunocomponent.hxx>
      47             : 
      48             : #include "Tools.hxx"
      49             : #include "corestrings.hrc"
      50             : #include "core_resource.hrc"
      51             : #include "core_resource.hxx"
      52             : 
      53             : #include <connectivity/CommonTools.hxx>
      54             : #include <rtl/ustrbuf.hxx>
      55             : #include <sfx2/docfilt.hxx>
      56             : 
      57             : namespace reportdesign
      58             : {
      59             : 
      60             :     using namespace com::sun::star;
      61             :     using namespace comphelper;
      62             : 
      63             : 
      64           1 : OReportEngineJFree::OReportEngineJFree( const uno::Reference< uno::XComponentContext >& context)
      65             : :ReportEngineBase(m_aMutex)
      66             : ,ReportEnginePropertySet(context,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),uno::Sequence< OUString >())
      67             : ,m_xContext(context)
      68           1 : ,m_nMaxRows(0)
      69             : {
      70           1 : }
      71             : 
      72             : // TODO: VirtualFunctionFinder: This is virtual function!
      73             : 
      74           2 : OReportEngineJFree::~OReportEngineJFree()
      75             : {
      76           2 : }
      77             : 
      78          26 : IMPLEMENT_FORWARD_XINTERFACE2(OReportEngineJFree,ReportEngineBase,ReportEnginePropertySet)
      79             : 
      80           1 : void SAL_CALL OReportEngineJFree::dispose() throw(uno::RuntimeException, std::exception)
      81             : {
      82           1 :     ReportEnginePropertySet::dispose();
      83           1 :     cppu::WeakComponentImplHelperBase::dispose();
      84           1 :     m_xActiveConnection.clear();
      85           1 : }
      86             : 
      87           9 : OUString OReportEngineJFree::getImplementationName_Static(  ) throw(uno::RuntimeException)
      88             : {
      89           9 :     return OUString("com.sun.star.comp.report.OReportEngineJFree");
      90             : }
      91             : 
      92             : 
      93           1 : OUString SAL_CALL OReportEngineJFree::getImplementationName(  ) throw(uno::RuntimeException, std::exception)
      94             : {
      95           1 :     return getImplementationName_Static();
      96             : }
      97             : 
      98           2 : uno::Sequence< OUString > OReportEngineJFree::getSupportedServiceNames_Static(  ) throw(uno::RuntimeException)
      99             : {
     100           2 :     uno::Sequence< OUString > aServices(1);
     101           2 :     aServices[0] = "com.sun.star.report.ReportEngine";
     102             : 
     103           2 :     return aServices;
     104             : }
     105             : 
     106           1 : uno::Reference< uno::XInterface > OReportEngineJFree::create(uno::Reference< uno::XComponentContext > const & xContext)
     107             : {
     108           1 :     return *(new OReportEngineJFree(xContext));
     109             : }
     110             : 
     111             : 
     112           1 : uno::Sequence< OUString > SAL_CALL OReportEngineJFree::getSupportedServiceNames(  ) throw(uno::RuntimeException, std::exception)
     113             : {
     114           1 :     return getSupportedServiceNames_Static();
     115             : }
     116             : 
     117           0 : sal_Bool SAL_CALL OReportEngineJFree::supportsService(const OUString& ServiceName) throw( uno::RuntimeException, std::exception )
     118             : {
     119           0 :     return cppu::supportsService(this, ServiceName);
     120             : }
     121             : 
     122             : // XReportEngine
     123             :     // Attributes
     124           0 : uno::Reference< report::XReportDefinition > SAL_CALL OReportEngineJFree::getReportDefinition() throw (uno::RuntimeException, std::exception)
     125             : {
     126           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     127           0 :     return m_xReport;
     128             : }
     129             : 
     130           0 : void SAL_CALL OReportEngineJFree::setReportDefinition( const uno::Reference< report::XReportDefinition >& _report ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     131             : {
     132           0 :     if ( !_report.is() )
     133           0 :         throw lang::IllegalArgumentException();
     134           0 :     BoundListeners l;
     135             :     {
     136           0 :         ::osl::MutexGuard aGuard(m_aMutex);
     137           0 :         if ( m_xReport != _report )
     138             :         {
     139           0 :             prepareSet(PROPERTY_REPORTDEFINITION, uno::makeAny(m_xReport), uno::makeAny(_report), &l);
     140           0 :             m_xReport = _report;
     141           0 :         }
     142             :     }
     143           0 :     l.notify();
     144           0 : }
     145             : 
     146           0 : uno::Reference< task::XStatusIndicator > SAL_CALL OReportEngineJFree::getStatusIndicator() throw (uno::RuntimeException, std::exception)
     147             : {
     148           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     149           0 :     return m_StatusIndicator;
     150             : }
     151             : 
     152           0 : void SAL_CALL OReportEngineJFree::setStatusIndicator( const uno::Reference< task::XStatusIndicator >& _statusindicator ) throw (uno::RuntimeException, std::exception)
     153             : {
     154           0 :     set(PROPERTY_STATUSINDICATOR,_statusindicator,m_StatusIndicator);
     155           0 : }
     156             : 
     157           0 : OUString OReportEngineJFree::getNewOutputName()
     158             : {
     159           0 :     OUString sOutputName;
     160             :     {
     161           0 :         ::osl::MutexGuard aGuard(m_aMutex);
     162           0 :         ::connectivity::checkDisposed(ReportEngineBase::rBHelper.bDisposed);
     163           0 :         if ( !m_xReport.is() || !m_xActiveConnection.is() )
     164           0 :             throw lang::IllegalArgumentException();
     165             : 
     166             :         static const char s_sMediaType[] = "MediaType";
     167             :         try
     168             :         {
     169           0 :             MimeConfigurationHelper aConfighelper(m_xContext);
     170           0 :             const OUString sMimeType = m_xReport->getMimeType();
     171           0 :             const SfxFilter* pFilter = SfxFilter::GetDefaultFilter( aConfighelper.GetDocServiceNameFromMediaType(sMimeType) );
     172           0 :             OUString sExt(".rpt");
     173           0 :             if ( pFilter )
     174           0 :                 sExt = ::comphelper::string::stripStart(pFilter->GetDefaultExtension(), '*');
     175             : 
     176           0 :             uno::Reference< embed::XStorage > xTemp = OStorageHelper::GetTemporaryStorage(/*sFileTemp,embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE,*/ m_xContext);
     177           0 :             utl::DisposableComponent aTemp(xTemp);
     178           0 :             uno::Sequence< beans::PropertyValue > aEmpty;
     179           0 :             uno::Reference< beans::XPropertySet> xStorageProp(xTemp,uno::UNO_QUERY);
     180           0 :             if ( xStorageProp.is() )
     181             :             {
     182           0 :                 xStorageProp->setPropertyValue( s_sMediaType, uno::makeAny(sMimeType));
     183             :             }
     184           0 :             m_xReport->storeToStorage(xTemp,aEmpty); // store to temp file because it may contain information which isn't in the database yet.
     185             : 
     186           0 :             uno::Sequence< beans::NamedValue > aConvertedProperties(8);
     187           0 :             sal_Int32 nPos = 0;
     188           0 :             aConvertedProperties[nPos].Name = "InputStorage";
     189           0 :             aConvertedProperties[nPos++].Value <<= xTemp;
     190           0 :             aConvertedProperties[nPos].Name = "OutputStorage";
     191             : 
     192           0 :             OUString sFileURL;
     193           0 :             OUString sName = m_xReport->getCaption();
     194           0 :             if ( sName.isEmpty() )
     195           0 :                 sName = m_xReport->getName();
     196             :             {
     197           0 :                 ::utl::TempFile aTestFile(sName, false, &sExt);
     198           0 :                 if ( !aTestFile.IsValid() )
     199             :                 {
     200           0 :                     sName = RPT_RESSTRING(RID_STR_REPORT,m_xContext->getServiceManager());
     201           0 :                     ::utl::TempFile aFile(sName, false, &sExt);
     202           0 :                     sFileURL = aFile.GetURL();
     203             :                 }
     204             :                 else
     205           0 :                     sFileURL = aTestFile.GetURL();
     206             :             }
     207             : 
     208           0 :             uno::Reference< embed::XStorage > xOut = OStorageHelper::GetStorageFromURL(sFileURL,embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE, m_xContext);
     209           0 :             utl::DisposableComponent aOut(xOut);
     210           0 :             xStorageProp.set(xOut,uno::UNO_QUERY);
     211           0 :             if ( xStorageProp.is() )
     212             :             {
     213           0 :                 xStorageProp->setPropertyValue( s_sMediaType, uno::makeAny(sMimeType));
     214             :             }
     215             : 
     216           0 :             aConvertedProperties[nPos++].Value <<= xOut;
     217             : 
     218           0 :             aConvertedProperties[nPos].Name = PROPERTY_REPORTDEFINITION;
     219           0 :             aConvertedProperties[nPos++].Value <<= m_xReport;
     220             : 
     221           0 :             aConvertedProperties[nPos].Name = PROPERTY_ACTIVECONNECTION;
     222           0 :             aConvertedProperties[nPos++].Value <<= m_xActiveConnection;
     223             : 
     224           0 :             aConvertedProperties[nPos].Name = PROPERTY_MAXROWS;
     225           0 :             aConvertedProperties[nPos++].Value <<= m_nMaxRows;
     226             : 
     227             :             // some meta data
     228           0 :             SvtUserOptions aUserOpts;
     229           0 :             OUStringBuffer sAuthor(aUserOpts.GetFirstName());
     230           0 :             sAuthor.appendAscii(" ");
     231           0 :             sAuthor.append(aUserOpts.GetLastName());
     232             :             static const char s_sAuthor[] = "Author";
     233           0 :             aConvertedProperties[nPos].Name = s_sAuthor;
     234           0 :             aConvertedProperties[nPos++].Value <<= sAuthor.makeStringAndClear();
     235             : 
     236             :             static const char s_sTitle[] = "Title";
     237           0 :             aConvertedProperties[nPos].Name = s_sTitle;
     238           0 :             aConvertedProperties[nPos++].Value <<= m_xReport->getCaption();
     239             : 
     240             :             // create job factory and initialize
     241           0 :             const OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_xContext);
     242           0 :             uno::Reference<task::XJob> xJob(m_xContext->getServiceManager()->createInstanceWithContext(sReportEngineServiceName,m_xContext),uno::UNO_QUERY_THROW);
     243           0 :             if ( !m_xReport->getCommand().isEmpty() )
     244             :             {
     245           0 :                 xJob->execute(aConvertedProperties);
     246           0 :                 if ( xStorageProp.is() )
     247             :                 {
     248           0 :                     sOutputName = sFileURL;
     249             :                 }
     250             :             }
     251             : 
     252           0 :             uno::Reference<embed::XTransactedObject> xTransact(xOut,uno::UNO_QUERY);
     253           0 :             if ( !sOutputName.isEmpty() && xTransact.is() )
     254           0 :                 xTransact->commit();
     255             : 
     256           0 :             if ( sOutputName.isEmpty() )
     257           0 :                 throw lang::IllegalArgumentException();
     258             :         }
     259           0 :         catch(const uno::Exception& e)
     260             :         {
     261             :             (void)e; // helper to know what e contains
     262           0 :             throw;
     263           0 :         }
     264             :     }
     265           0 :     return sOutputName;
     266             : }
     267             : 
     268             : // Methods
     269           0 : uno::Reference< frame::XModel > SAL_CALL OReportEngineJFree::createDocumentModel( ) throw (lang::DisposedException, lang::IllegalArgumentException, uno::Exception, uno::RuntimeException, std::exception)
     270             : {
     271           0 :     return createDocumentAlive(NULL,true);
     272             : }
     273             : 
     274           0 : uno::Reference< frame::XModel > SAL_CALL OReportEngineJFree::createDocumentAlive( const uno::Reference< frame::XFrame >& _frame ) throw (lang::DisposedException, lang::IllegalArgumentException, uno::Exception, uno::RuntimeException, std::exception)
     275             : {
     276           0 :     return createDocumentAlive(_frame,false);
     277             : }
     278             : 
     279           0 : uno::Reference< frame::XModel > SAL_CALL OReportEngineJFree::createDocumentAlive( const uno::Reference< frame::XFrame >& _frame,bool _bHidden ) throw (lang::DisposedException, lang::IllegalArgumentException, uno::Exception, uno::RuntimeException)
     280             : {
     281           0 :     uno::Reference< frame::XModel > xModel;
     282           0 :     OUString sOutputName = getNewOutputName(); // starts implicite the report generator
     283           0 :     if ( !sOutputName.isEmpty() )
     284             :     {
     285           0 :         ::osl::MutexGuard aGuard(m_aMutex);
     286           0 :         ::connectivity::checkDisposed(ReportEngineBase::rBHelper.bDisposed);
     287           0 :         uno::Reference<frame::XComponentLoader> xFrameLoad(_frame,uno::UNO_QUERY);
     288           0 :         if ( !xFrameLoad.is() )
     289             :         {
     290             :             // if there is no frame given, find the right
     291           0 :             xFrameLoad.set( frame::Desktop::create(m_xContext), uno::UNO_QUERY);
     292           0 :             OUString sTarget("_blank");
     293           0 :             sal_Int32 nFrameSearchFlag = frame::FrameSearchFlag::TASKS | frame::FrameSearchFlag::CREATE;
     294           0 :             uno::Reference< frame::XFrame> xFrame = uno::Reference< frame::XFrame>(xFrameLoad,uno::UNO_QUERY)->findFrame(sTarget,nFrameSearchFlag);
     295           0 :             xFrameLoad.set( xFrame,uno::UNO_QUERY);
     296             :         }
     297             : 
     298           0 :         if ( xFrameLoad.is() )
     299             :         {
     300           0 :             uno::Sequence < beans::PropertyValue > aArgs( _bHidden ? 3 : 2 );
     301           0 :             sal_Int32 nLen = 0;
     302           0 :             aArgs[nLen].Name = "AsTemplate";
     303           0 :             aArgs[nLen++].Value <<= sal_False;
     304             : 
     305           0 :             aArgs[nLen].Name = "ReadOnly";
     306           0 :             aArgs[nLen++].Value <<= sal_True;
     307             : 
     308           0 :             if ( _bHidden )
     309             :             {
     310           0 :                 aArgs[nLen].Name = "Hidden";
     311           0 :                 aArgs[nLen++].Value <<= sal_True;
     312             :             }
     313             : 
     314           0 :             uno::Reference< lang::XMultiServiceFactory > xFac(m_xContext->getServiceManager(),uno::UNO_QUERY);
     315           0 :             xModel.set( xFrameLoad->loadComponentFromURL(
     316             :                 sOutputName,
     317             :                 OUString(), // empty frame name
     318             :                 0,
     319             :                 aArgs
     320           0 :                 ),uno::UNO_QUERY);
     321           0 :         }
     322             :     }
     323           0 :     return xModel;
     324             : }
     325             : 
     326           0 : util::URL SAL_CALL OReportEngineJFree::createDocument( ) throw (lang::DisposedException, lang::IllegalArgumentException, uno::Exception, uno::RuntimeException, std::exception)
     327             : {
     328           0 :     util::URL aRet;
     329           0 :     uno::Reference< frame::XModel > xModel = createDocumentModel();
     330           0 :     if ( xModel.is() )
     331             :     {
     332           0 :         ::osl::MutexGuard aGuard(m_aMutex);
     333           0 :         ::connectivity::checkDisposed(ReportEngineBase::rBHelper.bDisposed);
     334             :     }
     335           0 :     return aRet;
     336             : }
     337             : 
     338           0 : void SAL_CALL OReportEngineJFree::interrupt(  ) throw (lang::DisposedException, uno::Exception, uno::RuntimeException, std::exception)
     339             : {
     340             :     {
     341           0 :         ::osl::MutexGuard aGuard(m_aMutex);
     342           0 :         ::connectivity::checkDisposed(ReportEngineBase::rBHelper.bDisposed);
     343             :     }
     344           0 : }
     345             : 
     346           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL OReportEngineJFree::getPropertySetInfo(  ) throw(uno::RuntimeException, std::exception)
     347             : {
     348           0 :     return ReportEnginePropertySet::getPropertySetInfo();
     349             : }
     350             : 
     351           0 : void SAL_CALL OReportEngineJFree::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     352             : {
     353           0 :     ReportEnginePropertySet::setPropertyValue( aPropertyName, aValue );
     354           0 : }
     355             : 
     356           0 : uno::Any SAL_CALL OReportEngineJFree::getPropertyValue( const OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     357             : {
     358           0 :     return ReportEnginePropertySet::getPropertyValue( PropertyName);
     359             : }
     360             : 
     361           0 : void SAL_CALL OReportEngineJFree::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     362             : {
     363           0 :     ReportEnginePropertySet::addPropertyChangeListener( aPropertyName, xListener );
     364           0 : }
     365             : 
     366           0 : void SAL_CALL OReportEngineJFree::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     367             : {
     368           0 :     ReportEnginePropertySet::removePropertyChangeListener( aPropertyName, aListener );
     369           0 : }
     370             : 
     371           0 : void SAL_CALL OReportEngineJFree::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     372             : {
     373           0 :     ReportEnginePropertySet::addVetoableChangeListener( PropertyName, aListener );
     374           0 : }
     375             : 
     376           0 : void SAL_CALL OReportEngineJFree::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     377             : {
     378           0 :     ReportEnginePropertySet::removeVetoableChangeListener( PropertyName, aListener );
     379           0 : }
     380             : 
     381           0 : uno::Reference< sdbc::XConnection > SAL_CALL OReportEngineJFree::getActiveConnection() throw (uno::RuntimeException, std::exception)
     382             : {
     383           0 :     return m_xActiveConnection;
     384             : }
     385             : 
     386           0 : void SAL_CALL OReportEngineJFree::setActiveConnection( const uno::Reference< sdbc::XConnection >& _activeconnection ) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     387             : {
     388           0 :     if ( !_activeconnection.is() )
     389           0 :         throw lang::IllegalArgumentException();
     390           0 :     set(PROPERTY_ACTIVECONNECTION,_activeconnection,m_xActiveConnection);
     391           0 : }
     392             : 
     393           0 : ::sal_Int32 SAL_CALL OReportEngineJFree::getMaxRows() throw (uno::RuntimeException, std::exception)
     394             : {
     395           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     396           0 :     return m_nMaxRows;
     397             : }
     398             : 
     399           0 : void SAL_CALL OReportEngineJFree::setMaxRows( ::sal_Int32 _MaxRows ) throw (uno::RuntimeException, std::exception)
     400             : {
     401           0 :     set(PROPERTY_MAXROWS,_MaxRows,m_nMaxRows);
     402           0 : }
     403             : 
     404             : } // namespace reportdesign
     405             : 
     406             : 
     407             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11