196de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
396de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
496de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
596de5490SAndrew Rist  * distributed with this work for additional information
696de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
796de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
896de5490SAndrew Rist  * "License"); you may not use this file except in compliance
996de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
1096de5490SAndrew Rist  *
1196de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1296de5490SAndrew Rist  *
1396de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1496de5490SAndrew Rist  * software distributed under the License is distributed on an
1596de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1696de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
1796de5490SAndrew Rist  * specific language governing permissions and limitations
1896de5490SAndrew Rist  * under the License.
1996de5490SAndrew Rist  *
2096de5490SAndrew Rist  *************************************************************/
2196de5490SAndrew Rist 
2296de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b63233d8Sdamjan #include "precompiled_dbui.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _DBAUI_LINKEDDOCUMENTS_HXX_
28cdf0e10cSrcweir #include "linkeddocuments.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef _OSL_DIAGNOSE_H_
31cdf0e10cSrcweir #include <osl/diagnose.h>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include <tools/diagnose_ex.h>
34cdf0e10cSrcweir #include <unotools/confignode.hxx>
35cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
36cdf0e10cSrcweir #include "dbustrings.hrc"
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #include <comphelper/classids.hxx>
39cdf0e10cSrcweir #ifndef COMPHELPER_NAMEDVALUECOLLECTION_HXX
40cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
43cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_XDISPATCHPROVIDER_HPP_
46cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
49cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_URL_HPP_
52cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp>
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
55cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
58cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
59cdf0e10cSrcweir #endif
60cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_
61cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandProcessor.hpp>
62cdf0e10cSrcweir #endif
63cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT_HPP_
64cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument.hpp>
65cdf0e10cSrcweir #endif
66cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_
67cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp>
68cdf0e10cSrcweir #endif
69cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TASK_XJOBEXECUTOR_HPP_
70cdf0e10cSrcweir #include <com/sun/star/task/XJobExecutor.hpp>
71cdf0e10cSrcweir #endif
72cdf0e10cSrcweir #ifndef _COMPHELPER_EXTRACT_HXX_
73cdf0e10cSrcweir #include <comphelper/extract.hxx>
74cdf0e10cSrcweir #endif
75cdf0e10cSrcweir #ifndef _COMPHELPER_TYPES_HXX_
76cdf0e10cSrcweir #include <comphelper/types.hxx>
77cdf0e10cSrcweir #endif
78cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX
79cdf0e10cSrcweir #include <vcl/msgbox.hxx>
80cdf0e10cSrcweir #endif
81cdf0e10cSrcweir #ifndef _UCBHELPER_CONTENT_HXX
82cdf0e10cSrcweir #include <ucbhelper/content.hxx>
83cdf0e10cSrcweir #endif
84cdf0e10cSrcweir #ifndef _DBU_MISC_HRC_
85cdf0e10cSrcweir #include "dbu_misc.hrc"
86cdf0e10cSrcweir #endif
87cdf0e10cSrcweir #ifndef SVTOOLS_FILENOTATION_HXX_
88cdf0e10cSrcweir #include <svl/filenotation.hxx>
89cdf0e10cSrcweir #endif
90cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
91cdf0e10cSrcweir #include "browserids.hxx"
92cdf0e10cSrcweir #endif
93cdf0e10cSrcweir #ifndef _SFXNEW_HXX
94cdf0e10cSrcweir #include <sfx2/new.hxx>
95cdf0e10cSrcweir #endif
96cdf0e10cSrcweir #ifndef _SVTOOLS_TEMPLDLG_HXX
97cdf0e10cSrcweir #include <svtools/templdlg.hxx>
98cdf0e10cSrcweir #endif
99cdf0e10cSrcweir #ifndef _DBAUI_MODULE_DBU_HXX_
100cdf0e10cSrcweir #include "moduledbu.hxx"
101cdf0e10cSrcweir #endif
102cdf0e10cSrcweir // -----------------
103cdf0e10cSrcweir // for calling basic
104cdf0e10cSrcweir #ifndef _SFXAPP_HXX
105cdf0e10cSrcweir #include <sfx2/app.hxx>
106cdf0e10cSrcweir #endif
107cdf0e10cSrcweir #ifndef _SBXCLASS_HXX
108cdf0e10cSrcweir #include <basic/sbx.hxx>
109cdf0e10cSrcweir #endif
110cdf0e10cSrcweir #ifndef _SB_SBUNO_HXX
111cdf0e10cSrcweir #include <basic/sbuno.hxx>
112cdf0e10cSrcweir #endif
113cdf0e10cSrcweir #ifndef _EHDL_HXX
114cdf0e10cSrcweir #include <svtools/ehdl.hxx>
115cdf0e10cSrcweir #endif
116cdf0e10cSrcweir #ifndef _SVX_DATACCESSDESCRIPTOR_HXX_
117cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
118cdf0e10cSrcweir #endif
119cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMECONTAINER_HPP_
120cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
121cdf0e10cSrcweir #endif
122cdf0e10cSrcweir #ifndef _SV_WAITOBJ_HXX
123cdf0e10cSrcweir #include <vcl/waitobj.hxx>
124cdf0e10cSrcweir #endif
125cdf0e10cSrcweir #ifndef _COMPHELPER_MIMECONFIGHELPER_HXX_
126cdf0e10cSrcweir #include <comphelper/mimeconfighelper.hxx>
127cdf0e10cSrcweir #endif
128cdf0e10cSrcweir 
129cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
130cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
131cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
132cdf0e10cSrcweir #include <com/sun/star/io/WrongFormatException.hpp>
133cdf0e10cSrcweir #include "com/sun/star/sdb/RowSetVetoException.hpp"
134cdf0e10cSrcweir 
135cdf0e10cSrcweir //......................................................................
136cdf0e10cSrcweir namespace dbaui
137cdf0e10cSrcweir {
138cdf0e10cSrcweir //......................................................................
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
141cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
142cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
143cdf0e10cSrcweir 	using namespace ::com::sun::star::frame;
144cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
145cdf0e10cSrcweir 	using namespace ::com::sun::star::util;
146cdf0e10cSrcweir 	using namespace ::com::sun::star::ucb;
147cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
148cdf0e10cSrcweir     using namespace ::com::sun::star::sdb::application;
149cdf0e10cSrcweir 	using namespace ::com::sun::star::task;
150cdf0e10cSrcweir 	using namespace ::svt;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	namespace
153cdf0e10cSrcweir 	{
lcl_GetSequenceClassID(sal_uInt32 n1,sal_uInt16 n2,sal_uInt16 n3,sal_uInt8 b8,sal_uInt8 b9,sal_uInt8 b10,sal_uInt8 b11,sal_uInt8 b12,sal_uInt8 b13,sal_uInt8 b14,sal_uInt8 b15)154cdf0e10cSrcweir 		Sequence< sal_Int8 > lcl_GetSequenceClassID( sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3,
155cdf0e10cSrcweir 													sal_uInt8 b8, sal_uInt8 b9, sal_uInt8 b10, sal_uInt8 b11,
156cdf0e10cSrcweir 													sal_uInt8 b12, sal_uInt8 b13, sal_uInt8 b14, sal_uInt8 b15 )
157cdf0e10cSrcweir 		{
158cdf0e10cSrcweir 			Sequence< sal_Int8 > aResult( 16 );
159cdf0e10cSrcweir 			aResult[0] = static_cast<sal_Int8>(n1 >> 24);
160cdf0e10cSrcweir 			aResult[1] = static_cast<sal_Int8>(( n1 << 8 ) >> 24);
161cdf0e10cSrcweir 			aResult[2] = static_cast<sal_Int8>(( n1 << 16 ) >> 24);
162cdf0e10cSrcweir 			aResult[3] = static_cast<sal_Int8>(( n1 << 24 ) >> 24);
163cdf0e10cSrcweir 			aResult[4] = static_cast<sal_Int8>(n2 >> 8);
164cdf0e10cSrcweir 			aResult[5] = static_cast<sal_Int8>(( n2 << 8 ) >> 8);
165cdf0e10cSrcweir 			aResult[6] = static_cast<sal_Int8>(n3 >> 8);
166cdf0e10cSrcweir 			aResult[7] = static_cast<sal_Int8>(( n3 << 8 ) >> 8);
167cdf0e10cSrcweir 			aResult[8] = b8;
168cdf0e10cSrcweir 			aResult[9] = b9;
169cdf0e10cSrcweir 			aResult[10] = b10;
170cdf0e10cSrcweir 			aResult[11] = b11;
171cdf0e10cSrcweir 			aResult[12] = b12;
172cdf0e10cSrcweir 			aResult[13] = b13;
173cdf0e10cSrcweir 			aResult[14] = b14;
174cdf0e10cSrcweir 			aResult[15] = b15;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 			return aResult;
177cdf0e10cSrcweir 		}
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 	//==================================================================
182cdf0e10cSrcweir 	//= OLinkedDocumentsAccess
183cdf0e10cSrcweir 	//==================================================================
DBG_NAME(OLinkedDocumentsAccess)184cdf0e10cSrcweir 	DBG_NAME(OLinkedDocumentsAccess)
185cdf0e10cSrcweir 	//------------------------------------------------------------------
186cdf0e10cSrcweir 	OLinkedDocumentsAccess::OLinkedDocumentsAccess( Window* _pDialogParent, const Reference< XDatabaseDocumentUI >& i_rDocumentUI,
187cdf0e10cSrcweir         const Reference< XMultiServiceFactory >& _rxORB, const Reference< XNameAccess >& _rxContainer,
188cdf0e10cSrcweir         const Reference< XConnection>& _xConnection, const ::rtl::OUString& _sDataSourceName )
189cdf0e10cSrcweir 		:m_xORB(_rxORB)
190cdf0e10cSrcweir 		,m_xDocumentContainer(_rxContainer)
191cdf0e10cSrcweir 		,m_xConnection(_xConnection)
192cdf0e10cSrcweir         ,m_xDocumentUI( i_rDocumentUI )
193cdf0e10cSrcweir 		,m_pDialogParent(_pDialogParent)
194cdf0e10cSrcweir         ,m_sDataSourceName(_sDataSourceName)
195cdf0e10cSrcweir 	{
196cdf0e10cSrcweir 		DBG_CTOR(OLinkedDocumentsAccess,NULL);
197cdf0e10cSrcweir 		OSL_ENSURE(m_xORB.is(), "OLinkedDocumentsAccess::OLinkedDocumentsAccess: invalid service factory!");
198cdf0e10cSrcweir 		OSL_ENSURE(m_pDialogParent, "OLinkedDocumentsAccess::OLinkedDocumentsAccess: really need a dialog parent!");
199cdf0e10cSrcweir 	}
200cdf0e10cSrcweir 	//------------------------------------------------------------------
~OLinkedDocumentsAccess()201cdf0e10cSrcweir 	OLinkedDocumentsAccess::~OLinkedDocumentsAccess()
202cdf0e10cSrcweir 	{
203cdf0e10cSrcweir 		DBG_DTOR(OLinkedDocumentsAccess,NULL);
204cdf0e10cSrcweir 	}
205cdf0e10cSrcweir 	//------------------------------------------------------------------
impl_open(const::rtl::OUString & _rLinkName,Reference<XComponent> & _xDefinition,ElementOpenMode _eOpenMode,const::comphelper::NamedValueCollection & _rAdditionalArgs)206cdf0e10cSrcweir 	Reference< XComponent> OLinkedDocumentsAccess::impl_open( const ::rtl::OUString& _rLinkName, Reference< XComponent >& _xDefinition,
207cdf0e10cSrcweir         ElementOpenMode _eOpenMode, const ::comphelper::NamedValueCollection& _rAdditionalArgs )
208cdf0e10cSrcweir 	{
209cdf0e10cSrcweir 		Reference< XComponent> xRet;
210cdf0e10cSrcweir         OSL_ENSURE(m_xDocumentContainer.is(), "OLinkedDocumentsAccess::OLinkedDocumentsAccess: invalid document container!");
211cdf0e10cSrcweir 		Reference< XComponentLoader > xComponentLoader(m_xDocumentContainer,UNO_QUERY);
212cdf0e10cSrcweir 		if ( !xComponentLoader.is() )
213cdf0e10cSrcweir 			return xRet;
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 		WaitObject aWaitCursor( m_pDialogParent );
216cdf0e10cSrcweir 
217cdf0e10cSrcweir         ::comphelper::NamedValueCollection aArguments;
218cdf0e10cSrcweir         ::rtl::OUString sOpenMode;
219cdf0e10cSrcweir 		switch ( _eOpenMode )
220cdf0e10cSrcweir 		{
221cdf0e10cSrcweir             case E_OPEN_NORMAL:
222cdf0e10cSrcweir                 sOpenMode = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) );
223cdf0e10cSrcweir                 break;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir             case E_OPEN_FOR_MAIL:
226cdf0e10cSrcweir                 aArguments.put( "Hidden", true );
227cdf0e10cSrcweir                 // fall through
228cdf0e10cSrcweir 
229cdf0e10cSrcweir             case E_OPEN_DESIGN:
230cdf0e10cSrcweir                 sOpenMode = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "openDesign" ) );
231cdf0e10cSrcweir                 break;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir             default:
234cdf0e10cSrcweir                 OSL_ENSURE( false, "OLinkedDocumentsAccess::implOpen: invalid open mode!" );
235cdf0e10cSrcweir                 break;
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir         aArguments.put( "OpenMode", sOpenMode );
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         aArguments.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, m_xConnection );
240cdf0e10cSrcweir 		try
241cdf0e10cSrcweir 		{
242cdf0e10cSrcweir 			Reference<XHierarchicalNameContainer> xHier(m_xDocumentContainer,UNO_QUERY);
243cdf0e10cSrcweir 			if ( xHier.is() && xHier->hasByHierarchicalName(_rLinkName) )
244cdf0e10cSrcweir 			{
245cdf0e10cSrcweir 				_xDefinition.set(xHier->getByHierarchicalName(_rLinkName),UNO_QUERY);
246cdf0e10cSrcweir 			}
247cdf0e10cSrcweir 
248cdf0e10cSrcweir             aArguments.merge( _rAdditionalArgs, true );
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 			xRet = xComponentLoader->loadComponentFromURL( _rLinkName, ::rtl::OUString(), 0, aArguments.getPropertyValues() );
251cdf0e10cSrcweir 		}
252cdf0e10cSrcweir 		catch(Exception& e)
253cdf0e10cSrcweir 		{
254cdf0e10cSrcweir 			(void)e;
255cdf0e10cSrcweir 			throw;
256cdf0e10cSrcweir 		}
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 		return xRet;
259cdf0e10cSrcweir 	}
260cdf0e10cSrcweir     //------------------------------------------------------------------
impl_newWithPilot(const char * _pWizardService,const sal_Int32 _nCommandType,const::rtl::OUString & _rObjectName)261cdf0e10cSrcweir     void OLinkedDocumentsAccess::impl_newWithPilot( const char* _pWizardService,
262cdf0e10cSrcweir         const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName )
263cdf0e10cSrcweir 	{
264cdf0e10cSrcweir 		try
265cdf0e10cSrcweir 		{
266cdf0e10cSrcweir             ::comphelper::NamedValueCollection aArgs;
267cdf0e10cSrcweir             aArgs.put( "DataSourceName", m_sDataSourceName );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 			if ( m_xConnection.is() )
270cdf0e10cSrcweir                 aArgs.put( "ActiveConnection", m_xConnection );
271cdf0e10cSrcweir 
272cdf0e10cSrcweir             if ( _rObjectName.getLength() && ( _nCommandType != -1 ) )
273cdf0e10cSrcweir             {
274cdf0e10cSrcweir                 aArgs.put( "CommandType", _nCommandType );
275cdf0e10cSrcweir                 aArgs.put( "Command", _rObjectName );
276cdf0e10cSrcweir             }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir             aArgs.put( "DocumentUI", m_xDocumentUI );
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 			Reference< XJobExecutor > xWizard;
281cdf0e10cSrcweir 			{
282cdf0e10cSrcweir 				WaitObject aWaitCursor( m_pDialogParent );
283cdf0e10cSrcweir                 xWizard.set( m_xORB->createInstanceWithArguments(
284cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii( _pWizardService ),
285cdf0e10cSrcweir                     aArgs.getWrappedPropertyValues()
286cdf0e10cSrcweir                     ), UNO_QUERY_THROW );
287cdf0e10cSrcweir 			}
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 			xWizard->trigger( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "start" ) ) );
290cdf0e10cSrcweir             ::comphelper::disposeComponent( xWizard );
291cdf0e10cSrcweir 		}
292cdf0e10cSrcweir 		catch(const Exception& e)
293cdf0e10cSrcweir 		{
294cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
295cdf0e10cSrcweir 		}
296cdf0e10cSrcweir 	}
297cdf0e10cSrcweir 	//------------------------------------------------------------------
newFormWithPilot(const sal_Int32 _nCommandType,const::rtl::OUString & _rObjectName)298cdf0e10cSrcweir 	void OLinkedDocumentsAccess::newFormWithPilot( const sal_Int32 _nCommandType,const ::rtl::OUString& _rObjectName )
299cdf0e10cSrcweir 	{
300cdf0e10cSrcweir         impl_newWithPilot( "com.sun.star.wizards.form.CallFormWizard", _nCommandType, _rObjectName );
301cdf0e10cSrcweir 	}
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     //------------------------------------------------------------------
newReportWithPilot(const sal_Int32 _nCommandType,const::rtl::OUString & _rObjectName)304cdf0e10cSrcweir 	void OLinkedDocumentsAccess::newReportWithPilot( const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName )
305cdf0e10cSrcweir 	{
306cdf0e10cSrcweir         impl_newWithPilot( "com.sun.star.wizards.report.CallReportWizard", _nCommandType, _rObjectName );
307cdf0e10cSrcweir 	}
308cdf0e10cSrcweir     //------------------------------------------------------------------
newTableWithPilot()309cdf0e10cSrcweir 	void OLinkedDocumentsAccess::newTableWithPilot()
310cdf0e10cSrcweir 	{
311cdf0e10cSrcweir         impl_newWithPilot( "com.sun.star.wizards.table.CallTableWizard", -1, ::rtl::OUString() );
312cdf0e10cSrcweir 	}
313cdf0e10cSrcweir     //------------------------------------------------------------------
newQueryWithPilot()314cdf0e10cSrcweir 	void OLinkedDocumentsAccess::newQueryWithPilot()
315cdf0e10cSrcweir 	{
316cdf0e10cSrcweir         impl_newWithPilot( "com.sun.star.wizards.query.CallQueryWizard", -1, ::rtl::OUString() );
317cdf0e10cSrcweir 	}
318cdf0e10cSrcweir 	//------------------------------------------------------------------
newDocument(sal_Int32 i_nActionID,const::comphelper::NamedValueCollection & i_rCreationArgs,Reference<XComponent> & o_rDefinition)319cdf0e10cSrcweir     Reference< XComponent > OLinkedDocumentsAccess::newDocument( sal_Int32 i_nActionID,
320cdf0e10cSrcweir         const ::comphelper::NamedValueCollection& i_rCreationArgs, Reference< XComponent >& o_rDefinition )
321cdf0e10cSrcweir 	{
322cdf0e10cSrcweir         OSL_ENSURE(m_xDocumentContainer.is(), "OLinkedDocumentsAccess::newDocument: invalid document container!");
323cdf0e10cSrcweir 		// determine the class ID to use for the new document
324cdf0e10cSrcweir 		Sequence<sal_Int8> aClassId;
325cdf0e10cSrcweir         if  (   !i_rCreationArgs.has( "ClassID" )
326cdf0e10cSrcweir             &&  !i_rCreationArgs.has( "MediaType" )
327cdf0e10cSrcweir             &&  !i_rCreationArgs.has( "DocumentServiceName" )
328cdf0e10cSrcweir             )
329cdf0e10cSrcweir         {
330cdf0e10cSrcweir 		    switch ( i_nActionID )
331cdf0e10cSrcweir 		    {
332cdf0e10cSrcweir 			    case ID_FORM_NEW_TEXT:
333cdf0e10cSrcweir 				    aClassId = lcl_GetSequenceClassID(SO3_SW_CLASSID);
334cdf0e10cSrcweir 				    OSL_ENSURE(aClassId == comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_SW_CLASSID),"Not equal");
335cdf0e10cSrcweir 				    break;
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 			    case ID_FORM_NEW_CALC:
338cdf0e10cSrcweir 				    aClassId = lcl_GetSequenceClassID(SO3_SC_CLASSID);
339cdf0e10cSrcweir 				    break;
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 			    case ID_FORM_NEW_IMPRESS:
342cdf0e10cSrcweir 				    aClassId = lcl_GetSequenceClassID(SO3_SIMPRESS_CLASSID);
343cdf0e10cSrcweir 				    break;
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 			    case ID_REPORT_NEW_TEXT:
346cdf0e10cSrcweir 				    aClassId = comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_90);
347cdf0e10cSrcweir 				    break;
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 			    default:
350cdf0e10cSrcweir 				    OSL_ENSURE( sal_False, "OLinkedDocumentsAccess::newDocument: please use newFormWithPilot!" );
351cdf0e10cSrcweir 				    return Reference< XComponent >();
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 		    }
354cdf0e10cSrcweir         }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 		// load the document as template
357cdf0e10cSrcweir 		Reference< XComponent > xNewDocument;
358cdf0e10cSrcweir 		try
359cdf0e10cSrcweir 		{	// get the desktop object
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 			Reference<XMultiServiceFactory> xORB(m_xDocumentContainer,UNO_QUERY);
362cdf0e10cSrcweir 			if ( xORB.is() )
363cdf0e10cSrcweir 			{
364cdf0e10cSrcweir                 ::comphelper::NamedValueCollection aCreationArgs( i_rCreationArgs );
365cdf0e10cSrcweir                 if ( aClassId.getLength() )
366cdf0e10cSrcweir                     aCreationArgs.put( "ClassID", aClassId );
367cdf0e10cSrcweir                 aCreationArgs.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, m_xConnection );
368cdf0e10cSrcweir 
369cdf0e10cSrcweir                 // separate values which are real creation args from args relevant for opening the doc
370cdf0e10cSrcweir                 ::comphelper::NamedValueCollection aCommandArgs;
371cdf0e10cSrcweir                 if ( aCreationArgs.has( "Hidden" ) )
372cdf0e10cSrcweir                 {
373cdf0e10cSrcweir                     aCommandArgs.put( "Hidden", aCreationArgs.get( "Hidden" ) );
374cdf0e10cSrcweir                     aCreationArgs.remove( "Hidden" );
375cdf0e10cSrcweir                 }
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 				Reference< XCommandProcessor > xContent( xORB->createInstanceWithArguments(
378cdf0e10cSrcweir                         SERVICE_SDB_DOCUMENTDEFINITION,
379cdf0e10cSrcweir                         aCreationArgs.getWrappedPropertyValues()
380cdf0e10cSrcweir                     ),
381cdf0e10cSrcweir                     UNO_QUERY_THROW
382cdf0e10cSrcweir                 );
383cdf0e10cSrcweir 				o_rDefinition.set( xContent, UNO_QUERY );
384cdf0e10cSrcweir 
385cdf0e10cSrcweir                 // put the OpenMode into the OpenArgs
386cdf0e10cSrcweir                 OpenCommandArgument aOpenModeArg;
387cdf0e10cSrcweir 			    aOpenModeArg.Mode = OpenMode::DOCUMENT;
388cdf0e10cSrcweir                 aCommandArgs.put( "OpenMode", aOpenModeArg );
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 			    Command aCommand;
391cdf0e10cSrcweir 			    aCommand.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "openDesign" ) );
392cdf0e10cSrcweir 			    aCommand.Argument <<= aCommandArgs.getPropertyValues();
393cdf0e10cSrcweir 			    WaitObject aWaitCursor( m_pDialogParent );
394cdf0e10cSrcweir 			    xNewDocument.set( xContent->execute( aCommand, xContent->createCommandIdentifier(), NULL ), UNO_QUERY );
395cdf0e10cSrcweir 			}
396cdf0e10cSrcweir 		}
397cdf0e10cSrcweir 		catch(const Exception& )
398cdf0e10cSrcweir 		{
399cdf0e10cSrcweir 			DBG_UNHANDLED_EXCEPTION();
400cdf0e10cSrcweir 		}
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 		return xNewDocument;
403cdf0e10cSrcweir 	}
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 	//------------------------------------------------------------------
open(const::rtl::OUString & _rLinkName,Reference<XComponent> & _xDefinition,ElementOpenMode _eOpenMode,const::comphelper::NamedValueCollection & _rAdditionalArgs)406cdf0e10cSrcweir 	Reference< XComponent > OLinkedDocumentsAccess::open( const ::rtl::OUString& _rLinkName, Reference< XComponent >& _xDefinition,
407cdf0e10cSrcweir         ElementOpenMode _eOpenMode, const ::comphelper::NamedValueCollection& _rAdditionalArgs )
408cdf0e10cSrcweir 	{
409cdf0e10cSrcweir 		dbtools::SQLExceptionInfo aInfo;
410cdf0e10cSrcweir         Reference< XComponent > xRet;
411cdf0e10cSrcweir 		try
412cdf0e10cSrcweir 		{
413cdf0e10cSrcweir 			xRet = impl_open( _rLinkName, _xDefinition, _eOpenMode, _rAdditionalArgs );
414cdf0e10cSrcweir 			if ( !xRet.is() )
415cdf0e10cSrcweir 			{
416cdf0e10cSrcweir                 String sMessage = String(ModuleRes(STR_COULDNOTOPEN_LINKEDDOC));
417cdf0e10cSrcweir                 sMessage.SearchAndReplaceAscii("$file$",_rLinkName);
418cdf0e10cSrcweir 
419cdf0e10cSrcweir                 com::sun::star::sdbc::SQLException aSQLException;
420cdf0e10cSrcweir                 aSQLException.Message = sMessage;
421cdf0e10cSrcweir                 // aSQLException.Context = e.Context;
422cdf0e10cSrcweir                 aInfo = dbtools::SQLExceptionInfo(aSQLException);
423cdf0e10cSrcweir 			}
424cdf0e10cSrcweir 			return xRet;
425cdf0e10cSrcweir 		}
426cdf0e10cSrcweir 		catch (com::sun::star::io::WrongFormatException e)
427cdf0e10cSrcweir 		{
428cdf0e10cSrcweir             com::sun::star::sdbc::SQLException aSQLException;
429cdf0e10cSrcweir             aSQLException.Message = e.Message;
430cdf0e10cSrcweir             aSQLException.Context = e.Context;
431cdf0e10cSrcweir 			aInfo = dbtools::SQLExceptionInfo(aSQLException);
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 			// more like a hack, insert an empty message
434cdf0e10cSrcweir             String sText( ModuleRes( RID_STR_EXTENSION_NOT_PRESENT ) );
435cdf0e10cSrcweir             sText.SearchAndReplaceAscii("$file$",_rLinkName);
436cdf0e10cSrcweir             aInfo.prepend(sText);
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 			String sMessage = String(ModuleRes(STR_COULDNOTOPEN_LINKEDDOC));
439cdf0e10cSrcweir 			sMessage.SearchAndReplaceAscii("$file$",_rLinkName);
440cdf0e10cSrcweir             aInfo.prepend(sMessage);
441cdf0e10cSrcweir         }
442cdf0e10cSrcweir         catch(Exception& e)
443cdf0e10cSrcweir         {
444cdf0e10cSrcweir             Any aAny = ::cppu::getCaughtException();
445cdf0e10cSrcweir             com::sun::star::sdbc::SQLException a;
446cdf0e10cSrcweir             if ( !(aAny >>= a) || (a.ErrorCode != dbtools::ParameterInteractionCancelled) )
447cdf0e10cSrcweir             {
448cdf0e10cSrcweir                 com::sun::star::sdbc::SQLException aSQLException;
449cdf0e10cSrcweir                 aSQLException.Message = e.Message;
450cdf0e10cSrcweir                 aSQLException.Context = e.Context;
451cdf0e10cSrcweir                 aInfo = dbtools::SQLExceptionInfo(aSQLException);
452cdf0e10cSrcweir 
453cdf0e10cSrcweir                 // more like a hack, insert an empty message
454cdf0e10cSrcweir                 aInfo.prepend(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" \n")));
455cdf0e10cSrcweir 
456cdf0e10cSrcweir                 String sMessage = String(ModuleRes(STR_COULDNOTOPEN_LINKEDDOC));
457cdf0e10cSrcweir                 sMessage.SearchAndReplaceAscii("$file$",_rLinkName);
458cdf0e10cSrcweir                 aInfo.prepend(sMessage);
459cdf0e10cSrcweir             }
460cdf0e10cSrcweir         }
461cdf0e10cSrcweir         if (aInfo.isValid())
462cdf0e10cSrcweir         {
463cdf0e10cSrcweir             showError(aInfo, VCLUnoHelper::GetInterface(m_pDialogParent), m_xORB );
464cdf0e10cSrcweir         }
465cdf0e10cSrcweir         return xRet;
466cdf0e10cSrcweir     }
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 
469cdf0e10cSrcweir //......................................................................
470cdf0e10cSrcweir }	// namespace dbaui
471cdf0e10cSrcweir //......................................................................
472cdf0e10cSrcweir 
473