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

Generated by: LCOV version 1.10