Branch data 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< XMultiServiceFactory >& _rxORB, const Reference< XNameAccess >& _rxContainer,
117 : : const Reference< XConnection>& _xConnection, const ::rtl::OUString& _sDataSourceName )
118 : : :m_xORB(_rxORB)
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_xORB.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_xORB->createInstanceWithArguments(
212 : : ::rtl::OUString::createFromAscii( _pWizardService ),
213 : : aArgs.getWrappedPropertyValues()
214 [ # # ][ # # ]: 0 : ), UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
215 : : }
216 : :
217 [ # # ][ # # ]: 0 : xWizard->trigger( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "start" ) ) );
[ # # ]
218 [ # # ][ # # ]: 0 : ::comphelper::disposeComponent( xWizard );
[ # # ]
219 : : }
220 : 0 : catch(const Exception&)
221 : : {
222 : : DBG_UNHANDLED_EXCEPTION();
223 : : }
224 : 0 : }
225 : : //------------------------------------------------------------------
226 : 0 : void OLinkedDocumentsAccess::newFormWithPilot( const sal_Int32 _nCommandType,const ::rtl::OUString& _rObjectName )
227 : : {
228 : 0 : impl_newWithPilot( "com.sun.star.wizards.form.CallFormWizard", _nCommandType, _rObjectName );
229 : 0 : }
230 : :
231 : : //------------------------------------------------------------------
232 : 0 : void OLinkedDocumentsAccess::newReportWithPilot( const sal_Int32 _nCommandType, const ::rtl::OUString& _rObjectName )
233 : : {
234 : 0 : impl_newWithPilot( "com.sun.star.wizards.report.CallReportWizard", _nCommandType, _rObjectName );
235 : 0 : }
236 : : //------------------------------------------------------------------
237 : 0 : void OLinkedDocumentsAccess::newTableWithPilot()
238 : : {
239 [ # # ]: 0 : impl_newWithPilot( "com.sun.star.wizards.table.CallTableWizard", -1, ::rtl::OUString() );
240 : 0 : }
241 : : //------------------------------------------------------------------
242 : 0 : void OLinkedDocumentsAccess::newQueryWithPilot()
243 : : {
244 [ # # ]: 0 : impl_newWithPilot( "com.sun.star.wizards.query.CallQueryWizard", -1, ::rtl::OUString() );
245 : 0 : }
246 : : //------------------------------------------------------------------
247 : 0 : Reference< XComponent > OLinkedDocumentsAccess::newDocument( sal_Int32 i_nActionID,
248 : : const ::comphelper::NamedValueCollection& i_rCreationArgs, Reference< XComponent >& o_rDefinition )
249 : : {
250 : : OSL_ENSURE(m_xDocumentContainer.is(), "OLinkedDocumentsAccess::newDocument: invalid document container!");
251 : : // determine the class ID to use for the new document
252 [ # # ]: 0 : Sequence<sal_Int8> aClassId;
253 [ # # ][ # # ]: 0 : if ( !i_rCreationArgs.has( "ClassID" )
[ # # ][ # # ]
[ # # ]
254 [ # # ]: 0 : && !i_rCreationArgs.has( "MediaType" )
255 [ # # ]: 0 : && !i_rCreationArgs.has( "DocumentServiceName" )
256 : : )
257 : : {
258 [ # # # # : 0 : switch ( i_nActionID )
# ]
259 : : {
260 : : case ID_FORM_NEW_TEXT:
261 [ # # ][ # # ]: 0 : aClassId = lcl_GetSequenceClassID(SO3_SW_CLASSID);
[ # # ]
262 : : OSL_ENSURE(aClassId == comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_SW_CLASSID),"Not equal");
263 : 0 : break;
264 : :
265 : : case ID_FORM_NEW_CALC:
266 [ # # ][ # # ]: 0 : aClassId = lcl_GetSequenceClassID(SO3_SC_CLASSID);
[ # # ]
267 : 0 : break;
268 : :
269 : : case ID_FORM_NEW_IMPRESS:
270 [ # # ][ # # ]: 0 : aClassId = lcl_GetSequenceClassID(SO3_SIMPRESS_CLASSID);
[ # # ]
271 : 0 : break;
272 : :
273 : : case ID_REPORT_NEW_TEXT:
274 [ # # ][ # # ]: 0 : aClassId = comphelper::MimeConfigurationHelper::GetSequenceClassID(SO3_RPT_CLASSID_90);
[ # # ]
275 : 0 : break;
276 : :
277 : : default:
278 : : OSL_FAIL( "OLinkedDocumentsAccess::newDocument: please use newFormWithPilot!" );
279 : 0 : return Reference< XComponent >();
280 : :
281 : : }
282 : : }
283 : :
284 : : // load the document as template
285 : 0 : Reference< XComponent > xNewDocument;
286 : : try
287 : : { // get the desktop object
288 : :
289 [ # # ]: 0 : Reference<XMultiServiceFactory> xORB(m_xDocumentContainer,UNO_QUERY);
290 [ # # ]: 0 : if ( xORB.is() )
291 : : {
292 [ # # ]: 0 : ::comphelper::NamedValueCollection aCreationArgs( i_rCreationArgs );
293 [ # # ]: 0 : if ( aClassId.getLength() )
294 [ # # ]: 0 : aCreationArgs.put( "ClassID", aClassId );
295 [ # # ][ # # ]: 0 : aCreationArgs.put( (::rtl::OUString)PROPERTY_ACTIVE_CONNECTION, m_xConnection );
296 : :
297 : : // separate values which are real creation args from args relevant for opening the doc
298 [ # # ]: 0 : ::comphelper::NamedValueCollection aCommandArgs;
299 [ # # ][ # # ]: 0 : if ( aCreationArgs.has( "Hidden" ) )
300 : : {
301 [ # # ][ # # ]: 0 : aCommandArgs.put( "Hidden", aCreationArgs.get( "Hidden" ) );
302 [ # # ]: 0 : aCreationArgs.remove( "Hidden" );
303 : : }
304 : :
305 [ # # ]: 0 : Reference< XCommandProcessor > xContent( xORB->createInstanceWithArguments(
306 : : SERVICE_SDB_DOCUMENTDEFINITION,
307 : : aCreationArgs.getWrappedPropertyValues()
308 : 0 : ),
309 : : UNO_QUERY_THROW
310 [ # # ][ # # ]: 0 : );
[ # # ][ # # ]
[ # # ]
311 [ # # ]: 0 : o_rDefinition.set( xContent, UNO_QUERY );
312 : :
313 : : // put the OpenMode into the OpenArgs
314 [ # # ]: 0 : OpenCommandArgument aOpenModeArg;
315 : 0 : aOpenModeArg.Mode = OpenMode::DOCUMENT;
316 [ # # ]: 0 : aCommandArgs.put( "OpenMode", aOpenModeArg );
317 : :
318 : 0 : Command aCommand;
319 [ # # ]: 0 : aCommand.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "openDesign" ) );
320 [ # # ][ # # ]: 0 : aCommand.Argument <<= aCommandArgs.getPropertyValues();
[ # # ]
321 [ # # ]: 0 : WaitObject aWaitCursor( m_pDialogParent );
322 [ # # ][ # # ]: 0 : xNewDocument.set( xContent->execute( aCommand, xContent->createCommandIdentifier(), NULL ), UNO_QUERY );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
323 [ # # ]: 0 : }
324 : : }
325 [ # # ]: 0 : catch(const Exception&)
326 : : {
327 : : DBG_UNHANDLED_EXCEPTION();
328 : : }
329 : :
330 [ # # ]: 0 : return xNewDocument;
331 : : }
332 : :
333 : : //------------------------------------------------------------------
334 : 0 : Reference< XComponent > OLinkedDocumentsAccess::open( const ::rtl::OUString& _rLinkName, Reference< XComponent >& _xDefinition,
335 : : ElementOpenMode _eOpenMode, const ::comphelper::NamedValueCollection& _rAdditionalArgs )
336 : : {
337 [ # # ]: 0 : dbtools::SQLExceptionInfo aInfo;
338 : 0 : Reference< XComponent > xRet;
339 : : try
340 : : {
341 [ # # ][ # # ]: 0 : xRet = impl_open( _rLinkName, _xDefinition, _eOpenMode, _rAdditionalArgs );
342 [ # # ]: 0 : if ( !xRet.is() )
343 : : {
344 [ # # ][ # # ]: 0 : String sMessage = String(ModuleRes(STR_COULDNOTOPEN_LINKEDDOC));
345 [ # # ][ # # ]: 0 : sMessage.SearchAndReplaceAscii("$file$",_rLinkName);
[ # # ]
346 : :
347 [ # # ]: 0 : com::sun::star::sdbc::SQLException aSQLException;
348 [ # # ]: 0 : aSQLException.Message = sMessage;
349 [ # # ][ # # ]: 0 : aInfo = dbtools::SQLExceptionInfo(aSQLException);
[ # # ][ # # ]
[ # # ]
350 : : }
351 : : return xRet;
352 : : }
353 [ # # ]: 0 : catch(const com::sun::star::io::WrongFormatException &e)
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 : String sText( ModuleRes( RID_STR_EXTENSION_NOT_PRESENT ) );
362 [ # # # # : 0 : sText.SearchAndReplaceAscii("$file$",_rLinkName);
# # ]
363 [ # # # # ]: 0 : aInfo.prepend(sText);
364 : :
365 [ # # # # ]: 0 : String sMessage = String(ModuleRes(STR_COULDNOTOPEN_LINKEDDOC));
366 [ # # # # : 0 : sMessage.SearchAndReplaceAscii("$file$",_rLinkName);
# # ]
367 [ # # # # : 0 : aInfo.prepend(sMessage);
# # # # #
# ]
368 : : }
369 [ # # # # : 0 : catch(const Exception& e)
# ]
370 : : {
371 [ # # ]: 0 : Any aAny = ::cppu::getCaughtException();
372 [ # # ]: 0 : com::sun::star::sdbc::SQLException a;
373 [ # # # # : 0 : if ( !(aAny >>= a) || (a.ErrorCode != dbtools::ParameterInteractionCancelled) )
# # # # ]
374 : : {
375 [ # # ]: 0 : com::sun::star::sdbc::SQLException aSQLException;
376 : 0 : aSQLException.Message = e.Message;
377 [ # # ]: 0 : aSQLException.Context = e.Context;
378 [ # # # # : 0 : aInfo = dbtools::SQLExceptionInfo(aSQLException);
# # ]
379 : :
380 : : // more like a hack, insert an empty message
381 [ # # # # ]: 0 : aInfo.prepend(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" \n")));
382 : :
383 [ # # # # ]: 0 : String sMessage = String(ModuleRes(STR_COULDNOTOPEN_LINKEDDOC));
384 [ # # # # : 0 : sMessage.SearchAndReplaceAscii("$file$",_rLinkName);
# # ]
385 [ # # # # : 0 : aInfo.prepend(sMessage);
# # # # ]
386 [ # # ]: 0 : }
387 : : }
388 [ # # ]: 0 : if (aInfo.isValid())
389 : : {
390 [ # # # # ]: 0 : showError(aInfo, VCLUnoHelper::GetInterface(m_pDialogParent), m_xORB );
391 : : }
392 [ # # ]: 0 : return xRet;
393 : : }
394 : :
395 : :
396 : : //......................................................................
397 : : } // namespace dbaui
398 : : //......................................................................
399 : :
400 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|