LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/misc - linkeddocuments.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 155 0.0 %
Date: 2012-12-27 Functions: 0 11 0.0 %
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             : 
      20             : 
      21             : #include "linkeddocuments.hxx"
      22             : #include <osl/diagnose.h>
      23             : #include <tools/diagnose_ex.h>
      24             : #include <unotools/confignode.hxx>
      25             : #include "dbustrings.hrc"
      26             : #include <comphelper/classids.hxx>
      27             : #include <comphelper/namedvaluecollection.hxx>
      28             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      29             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      30             : #include <com/sun/star/frame/XComponentLoader.hpp>
      31             : #include <com/sun/star/util/URL.hpp>
      32             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      33             : #include <com/sun/star/container/XNameContainer.hpp>
      34             : #include <com/sun/star/ucb/XCommandProcessor.hpp>
      35             : #include <com/sun/star/ucb/OpenCommandArgument.hpp>
      36             : #include <com/sun/star/ucb/OpenMode.hpp>
      37             : #include <com/sun/star/task/XJobExecutor.hpp>
      38             : #include <comphelper/extract.hxx>
      39             : #include <comphelper/types.hxx>
      40             : #include <vcl/msgbox.hxx>
      41             : #include <ucbhelper/content.hxx>
      42             : #include "dbu_misc.hrc"
      43             : #include <svl/filenotation.hxx>
      44             : #include "browserids.hxx"
      45             : #include <sfx2/new.hxx>
      46             : #include "moduledbu.hxx"
      47             : // -----------------
      48             : // for calling basic
      49             : #include <sfx2/app.hxx>
      50             : #include <basic/sbx.hxx>
      51             : #include <basic/sbuno.hxx>
      52             : #include <svtools/ehdl.hxx>
      53             : #include <svx/dataaccessdescriptor.hxx>
      54             : #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
      55             : #include <vcl/waitobj.hxx>
      56             : #include <comphelper/mimeconfighelper.hxx>
      57             : 
      58             : #include <cppuhelper/exc_hlp.hxx>
      59             : #include <connectivity/dbtools.hxx>
      60             : #include <toolkit/helper/vclunohelper.hxx>
      61             : #include <com/sun/star/io/WrongFormatException.hpp>
      62             : #include "com/sun/star/sdb/RowSetVetoException.hpp"
      63             : 
      64             : //......................................................................
      65             : namespace dbaui
      66             : {
      67             : //......................................................................
      68             : 
      69             :     using namespace ::com::sun::star::uno;
      70             :     using namespace ::com::sun::star::container;
      71             :     using namespace ::com::sun::star::lang;
      72             :     using namespace ::com::sun::star::frame;
      73             :     using namespace ::com::sun::star::beans;
      74             :     using namespace ::com::sun::star::util;
      75             :     using namespace ::com::sun::star::ucb;
      76             :     using namespace ::com::sun::star::sdbc;
      77             :     using namespace ::com::sun::star::sdb::application;
      78             :     using namespace ::com::sun::star::task;
      79             :     using namespace ::svt;
      80             : 
      81             :     namespace
      82             :     {
      83           0 :         Sequence< sal_Int8 > lcl_GetSequenceClassID( sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3,
      84             :                                                     sal_uInt8 b8, sal_uInt8 b9, sal_uInt8 b10, sal_uInt8 b11,
      85             :                                                     sal_uInt8 b12, sal_uInt8 b13, sal_uInt8 b14, sal_uInt8 b15 )
      86             :         {
      87           0 :             Sequence< sal_Int8 > aResult( 16 );
      88           0 :             aResult[0] = static_cast<sal_Int8>(n1 >> 24);
      89           0 :             aResult[1] = static_cast<sal_Int8>(( n1 << 8 ) >> 24);
      90           0 :             aResult[2] = static_cast<sal_Int8>(( n1 << 16 ) >> 24);
      91           0 :             aResult[3] = static_cast<sal_Int8>(( n1 << 24 ) >> 24);
      92           0 :             aResult[4] = static_cast<sal_Int8>(n2 >> 8);
      93           0 :             aResult[5] = static_cast<sal_Int8>(( n2 << 8 ) >> 8);
      94           0 :             aResult[6] = static_cast<sal_Int8>(n3 >> 8);
      95           0 :             aResult[7] = static_cast<sal_Int8>(( n3 << 8 ) >> 8);
      96           0 :             aResult[8] = b8;
      97           0 :             aResult[9] = b9;
      98           0 :             aResult[10] = b10;
      99           0 :             aResult[11] = b11;
     100           0 :             aResult[12] = b12;
     101           0 :             aResult[13] = b13;
     102           0 :             aResult[14] = b14;
     103           0 :             aResult[15] = b15;
     104             : 
     105           0 :             return aResult;
     106             :         }
     107             :     }
     108             : 
     109             : 
     110             :     //==================================================================
     111             :     //= OLinkedDocumentsAccess
     112             :     //==================================================================
     113             :     DBG_NAME(OLinkedDocumentsAccess)
     114             :     //------------------------------------------------------------------
     115           0 :     OLinkedDocumentsAccess::OLinkedDocumentsAccess( Window* _pDialogParent, const Reference< XDatabaseDocumentUI >& i_rDocumentUI,
     116             :         const Reference< XComponentContext >& _rxContext, const Reference< XNameAccess >& _rxContainer,
     117             :         const Reference< XConnection>& _xConnection, const ::rtl::OUString& _sDataSourceName )
     118             :         :m_xContext(_rxContext)
     119             :         ,m_xDocumentContainer(_rxContainer)
     120             :         ,m_xConnection(_xConnection)
     121             :         ,m_xDocumentUI( i_rDocumentUI )
     122             :         ,m_pDialogParent(_pDialogParent)
     123           0 :         ,m_sDataSourceName(_sDataSourceName)
     124             :     {
     125             :         DBG_CTOR(OLinkedDocumentsAccess,NULL);
     126             :         OSL_ENSURE(m_xContext.is(), "OLinkedDocumentsAccess::OLinkedDocumentsAccess: invalid service factory!");
     127             :         OSL_ENSURE(m_pDialogParent, "OLinkedDocumentsAccess::OLinkedDocumentsAccess: really need a dialog parent!");
     128           0 :     }
     129             :     //------------------------------------------------------------------
     130           0 :     OLinkedDocumentsAccess::~OLinkedDocumentsAccess()
     131             :     {
     132             :         DBG_DTOR(OLinkedDocumentsAccess,NULL);
     133           0 :     }
     134             :     //------------------------------------------------------------------
     135           0 :     Reference< XComponent> OLinkedDocumentsAccess::impl_open( const ::rtl::OUString& _rLinkName, Reference< XComponent >& _xDefinition,
     136             :         ElementOpenMode _eOpenMode, const ::comphelper::NamedValueCollection& _rAdditionalArgs )
     137             :     {
     138           0 :         Reference< XComponent> xRet;
     139             :         OSL_ENSURE(m_xDocumentContainer.is(), "OLinkedDocumentsAccess::OLinkedDocumentsAccess: invalid document container!");
     140           0 :         Reference< XComponentLoader > xComponentLoader(m_xDocumentContainer,UNO_QUERY);
     141           0 :         if ( !xComponentLoader.is() )
     142             :             return xRet;
     143             : 
     144           0 :         WaitObject aWaitCursor( m_pDialogParent );
     145             : 
     146           0 :         ::comphelper::NamedValueCollection aArguments;
     147           0 :         ::rtl::OUString sOpenMode;
     148           0 :         switch ( _eOpenMode )
     149             :         {
     150             :             case E_OPEN_NORMAL:
     151           0 :                 sOpenMode = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) );
     152           0 :                 break;
     153             : 
     154             :             case E_OPEN_FOR_MAIL:
     155           0 :                 aArguments.put( "Hidden", true );
     156             :                 // fall through
     157             : 
     158             :             case E_OPEN_DESIGN:
     159           0 :                 sOpenMode = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "openDesign" ) );
     160           0 :                 break;
     161             : 
     162             :             default:
     163             :                 OSL_FAIL( "OLinkedDocumentsAccess::implOpen: invalid open mode!" );
     164           0 :                 break;
     165             :         }
     166           0 :         aArguments.put( "OpenMode", sOpenMode );
     167             : 
     168           0 :         aArguments.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, m_xConnection );
     169             :         try
     170             :         {
     171           0 :             Reference<XHierarchicalNameContainer> xHier(m_xDocumentContainer,UNO_QUERY);
     172           0 :             if ( xHier.is() && xHier->hasByHierarchicalName(_rLinkName) )
     173             :             {
     174           0 :                 _xDefinition.set(xHier->getByHierarchicalName(_rLinkName),UNO_QUERY);
     175             :             }
     176             : 
     177           0 :             aArguments.merge( _rAdditionalArgs, true );
     178             : 
     179           0 :             xRet = xComponentLoader->loadComponentFromURL( _rLinkName, ::rtl::OUString(), 0, aArguments.getPropertyValues() );
     180             :         }
     181           0 :         catch(const Exception&)
     182             :         {
     183           0 :             throw;
     184             :         }
     185             : 
     186           0 :         return xRet;
     187             :     }
     188             :     //------------------------------------------------------------------
     189           0 :     void OLinkedDocumentsAccess::impl_newWithPilot( const char* _pWizardService,
     190             :         const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName )
     191             :     {
     192             :         try
     193             :         {
     194           0 :             ::comphelper::NamedValueCollection aArgs;
     195           0 :             aArgs.put( "DataSourceName", m_sDataSourceName );
     196             : 
     197           0 :             if ( m_xConnection.is() )
     198           0 :                 aArgs.put( "ActiveConnection", m_xConnection );
     199             : 
     200           0 :             if ( !_rObjectName.isEmpty() && ( _nCommandType != -1 ) )
     201             :             {
     202           0 :                 aArgs.put( "CommandType", _nCommandType );
     203           0 :                 aArgs.put( "Command", _rObjectName );
     204             :             }
     205             : 
     206           0 :             aArgs.put( "DocumentUI", m_xDocumentUI );
     207             : 
     208           0 :             Reference< XJobExecutor > xWizard;
     209             :             {
     210           0 :                 WaitObject aWaitCursor( m_pDialogParent );
     211           0 :                 xWizard.set( m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
     212             :                     ::rtl::OUString::createFromAscii( _pWizardService ),
     213             :                     aArgs.getWrappedPropertyValues(),
     214             :                     m_xContext
     215           0 :                     ), UNO_QUERY_THROW );
     216             :             }
     217             : 
     218           0 :             xWizard->trigger( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "start" ) ) );
     219           0 :             ::comphelper::disposeComponent( xWizard );
     220             :         }
     221           0 :         catch(const Exception&)
     222             :         {
     223             :             DBG_UNHANDLED_EXCEPTION();
     224             :         }
     225           0 :     }
     226             :     //------------------------------------------------------------------
     227           0 :     void OLinkedDocumentsAccess::newFormWithPilot( const sal_Int32 _nCommandType,const ::rtl::OUString& _rObjectName )
     228             :     {
     229           0 :         impl_newWithPilot( "com.sun.star.wizards.form.CallFormWizard", _nCommandType, _rObjectName );
     230           0 :     }
     231             : 
     232             :     //------------------------------------------------------------------
     233           0 :     void OLinkedDocumentsAccess::newReportWithPilot( const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName )
     234             :     {
     235           0 :         impl_newWithPilot( "com.sun.star.wizards.report.CallReportWizard", _nCommandType, _rObjectName );
     236           0 :     }
     237             :     //------------------------------------------------------------------
     238           0 :     void OLinkedDocumentsAccess::newTableWithPilot()
     239             :     {
     240           0 :         impl_newWithPilot( "com.sun.star.wizards.table.CallTableWizard", -1, ::rtl::OUString() );
     241           0 :     }
     242             :     //------------------------------------------------------------------
     243           0 :     void OLinkedDocumentsAccess::newQueryWithPilot()
     244             :     {
     245           0 :         impl_newWithPilot( "com.sun.star.wizards.query.CallQueryWizard", -1, ::rtl::OUString() );
     246           0 :     }
     247             :     //------------------------------------------------------------------
     248           0 :     Reference< XComponent > OLinkedDocumentsAccess::newDocument( sal_Int32 i_nActionID,
     249             :         const ::comphelper::NamedValueCollection& i_rCreationArgs, Reference< XComponent >& o_rDefinition )
     250             :     {
     251             :         OSL_ENSURE(m_xDocumentContainer.is(), "OLinkedDocumentsAccess::newDocument: invalid document container!");
     252             :         // determine the class ID to use for the new document
     253           0 :         Sequence<sal_Int8> aClassId;
     254           0 :         if  (   !i_rCreationArgs.has( "ClassID" )
     255           0 :             &&  !i_rCreationArgs.has( "MediaType" )
     256           0 :             &&  !i_rCreationArgs.has( "DocumentServiceName" )
     257             :             )
     258             :         {
     259           0 :             switch ( i_nActionID )
     260             :             {
     261             :                 case ID_FORM_NEW_TEXT:
     262           0 :                     aClassId = lcl_GetSequenceClassID(SO3_SW_CLASSID);
     263             :                     OSL_ENSURE(aClassId == comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_SW_CLASSID),"Not equal");
     264           0 :                     break;
     265             : 
     266             :                 case ID_FORM_NEW_CALC:
     267           0 :                     aClassId = lcl_GetSequenceClassID(SO3_SC_CLASSID);
     268           0 :                     break;
     269             : 
     270             :                 case ID_FORM_NEW_IMPRESS:
     271           0 :                     aClassId = lcl_GetSequenceClassID(SO3_SIMPRESS_CLASSID);
     272           0 :                     break;
     273             : 
     274             :                 case ID_REPORT_NEW_TEXT:
     275           0 :                     aClassId = comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_90);
     276           0 :                     break;
     277             : 
     278             :                 default:
     279             :                     OSL_FAIL( "OLinkedDocumentsAccess::newDocument: please use newFormWithPilot!" );
     280           0 :                     return Reference< XComponent >();
     281             : 
     282             :             }
     283             :         }
     284             : 
     285             :         // load the document as template
     286           0 :         Reference< XComponent > xNewDocument;
     287             :         try
     288             :         {   // get the desktop object
     289             : 
     290           0 :             Reference<XMultiServiceFactory> xORB(m_xDocumentContainer,UNO_QUERY);
     291           0 :             if ( xORB.is() )
     292             :             {
     293           0 :                 ::comphelper::NamedValueCollection aCreationArgs( i_rCreationArgs );
     294           0 :                 if ( aClassId.getLength() )
     295           0 :                     aCreationArgs.put( "ClassID", aClassId );
     296           0 :                 aCreationArgs.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, m_xConnection );
     297             : 
     298             :                 // separate values which are real creation args from args relevant for opening the doc
     299           0 :                 ::comphelper::NamedValueCollection aCommandArgs;
     300           0 :                 if ( aCreationArgs.has( "Hidden" ) )
     301             :                 {
     302           0 :                     aCommandArgs.put( "Hidden", aCreationArgs.get( "Hidden" ) );
     303           0 :                     aCreationArgs.remove( "Hidden" );
     304             :                 }
     305             : 
     306           0 :                 Reference< XCommandProcessor > xContent( xORB->createInstanceWithArguments(
     307             :                         SERVICE_SDB_DOCUMENTDEFINITION,
     308             :                         aCreationArgs.getWrappedPropertyValues()
     309           0 :                     ),
     310             :                     UNO_QUERY_THROW
     311           0 :                 );
     312           0 :                 o_rDefinition.set( xContent, UNO_QUERY );
     313             : 
     314             :                 // put the OpenMode into the OpenArgs
     315           0 :                 OpenCommandArgument aOpenModeArg;
     316           0 :                 aOpenModeArg.Mode = OpenMode::DOCUMENT;
     317           0 :                 aCommandArgs.put( "OpenMode", aOpenModeArg );
     318             : 
     319           0 :                 Command aCommand;
     320           0 :                 aCommand.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "openDesign" ) );
     321           0 :                 aCommand.Argument <<= aCommandArgs.getPropertyValues();
     322           0 :                 WaitObject aWaitCursor( m_pDialogParent );
     323           0 :                 xNewDocument.set( xContent->execute( aCommand, xContent->createCommandIdentifier(), NULL ), UNO_QUERY );
     324           0 :             }
     325             :         }
     326           0 :         catch(const Exception&)
     327             :         {
     328             :             DBG_UNHANDLED_EXCEPTION();
     329             :         }
     330             : 
     331           0 :         return xNewDocument;
     332             :     }
     333             : 
     334             :     //------------------------------------------------------------------
     335           0 :     Reference< XComponent > OLinkedDocumentsAccess::open( const ::rtl::OUString& _rLinkName, Reference< XComponent >& _xDefinition,
     336             :         ElementOpenMode _eOpenMode, const ::comphelper::NamedValueCollection& _rAdditionalArgs )
     337             :     {
     338           0 :         dbtools::SQLExceptionInfo aInfo;
     339           0 :         Reference< XComponent > xRet;
     340             :         try
     341             :         {
     342           0 :             xRet = impl_open( _rLinkName, _xDefinition, _eOpenMode, _rAdditionalArgs );
     343           0 :             if ( !xRet.is() )
     344             :             {
     345           0 :                 String sMessage = String(ModuleRes(STR_COULDNOTOPEN_LINKEDDOC));
     346           0 :                 sMessage.SearchAndReplaceAscii("$file$",_rLinkName);
     347             : 
     348           0 :                 com::sun::star::sdbc::SQLException aSQLException;
     349           0 :                 aSQLException.Message = sMessage;
     350           0 :                 aInfo = dbtools::SQLExceptionInfo(aSQLException);
     351             :             }
     352             :             return xRet;
     353             :         }
     354           0 :         catch(const com::sun::star::io::WrongFormatException &e)
     355             :         {
     356           0 :             com::sun::star::sdbc::SQLException aSQLException;
     357           0 :             aSQLException.Message = e.Message;
     358           0 :             aSQLException.Context = e.Context;
     359           0 :             aInfo = dbtools::SQLExceptionInfo(aSQLException);
     360             : 
     361             :             // more like a hack, insert an empty message
     362           0 :             String sText( ModuleRes( RID_STR_EXTENSION_NOT_PRESENT ) );
     363           0 :             sText.SearchAndReplaceAscii("$file$",_rLinkName);
     364           0 :             aInfo.prepend(sText);
     365             : 
     366           0 :             String sMessage = String(ModuleRes(STR_COULDNOTOPEN_LINKEDDOC));
     367           0 :             sMessage.SearchAndReplaceAscii("$file$",_rLinkName);
     368           0 :             aInfo.prepend(sMessage);
     369             :         }
     370           0 :         catch(const Exception& e)
     371             :         {
     372           0 :             Any aAny = ::cppu::getCaughtException();
     373           0 :             com::sun::star::sdbc::SQLException a;
     374           0 :             if ( !(aAny >>= a) || (a.ErrorCode != dbtools::ParameterInteractionCancelled) )
     375             :             {
     376           0 :                 com::sun::star::sdbc::SQLException aSQLException;
     377           0 :                 aSQLException.Message = e.Message;
     378           0 :                 aSQLException.Context = e.Context;
     379           0 :                 aInfo = dbtools::SQLExceptionInfo(aSQLException);
     380             : 
     381             :                 // more like a hack, insert an empty message
     382           0 :                 aInfo.prepend(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" \n")));
     383             : 
     384           0 :                 String sMessage = String(ModuleRes(STR_COULDNOTOPEN_LINKEDDOC));
     385           0 :                 sMessage.SearchAndReplaceAscii("$file$",_rLinkName);
     386           0 :                 aInfo.prepend(sMessage);
     387           0 :             }
     388             :         }
     389           0 :         if (aInfo.isValid())
     390             :         {
     391           0 :             showError(aInfo, VCLUnoHelper::GetInterface(m_pDialogParent), m_xContext );
     392             :         }
     393           0 :         return xRet;
     394             :     }
     395             : 
     396             : 
     397             : //......................................................................
     398             : }   // namespace dbaui
     399             : //......................................................................
     400             : 
     401             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10