1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "sdbcoretools.hxx"
21 #include "dbastrings.hrc"
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/container/XChild.hpp>
26 #include <com/sun/star/util/XModifiable.hpp>
27 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
28 #include <com/sun/star/task/InteractionRequestStringResolver.hpp>
29 #include <com/sun/star/embed/XTransactedObject.hpp>
30 #include <com/sun/star/embed/ElementModes.hpp>
32 #include <tools/diagnose_ex.h>
33 #include <tools/debug.hxx>
34 #include <comphelper/interaction.hxx>
35 #include <rtl/ref.hxx>
36 #include <rtl/ustrbuf.hxx>
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::com::sun::star::util
;
44 using namespace ::com::sun::star::io
;
45 using namespace ::com::sun::star::sdbc
;
46 using namespace ::com::sun::star::sdb
;
47 using namespace ::com::sun::star::beans
;
48 using namespace ::com::sun::star::task
;
49 using namespace ::com::sun::star::embed
;
50 using namespace ::com::sun::star::container
;
52 void notifyDataSourceModified(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxObject
,bool _bModified
)
54 Reference
< XInterface
> xDs
= getDataSource( _rxObject
);
55 Reference
<XDocumentDataSource
> xDocumentDataSource(xDs
,UNO_QUERY
);
56 if ( xDocumentDataSource
.is() )
57 xDs
= xDocumentDataSource
->getDatabaseDocument();
58 Reference
< XModifiable
> xModi( xDs
, UNO_QUERY
);
60 xModi
->setModified(_bModified
);
63 Reference
< XInterface
> getDataSource( const Reference
< XInterface
>& _rxDependentObject
)
65 Reference
< XInterface
> xParent
= _rxDependentObject
;
66 Reference
< XInterface
> xReturn
;
70 Reference
<XChild
> xChild(xParent
,UNO_QUERY
);
71 xParent
.set(xChild
.is() ? xChild
->getParent() : Reference
< XInterface
>(),UNO_QUERY
);
76 OUString
extractExceptionMessage( const Reference
<XComponentContext
> & _rContext
, const Any
& _rError
)
78 OUString sDisplayMessage
;
82 Reference
< XInteractionRequestStringResolver
> xStringResolver
= InteractionRequestStringResolver::create(_rContext
);
84 ::rtl::Reference
< ::comphelper::OInteractionRequest
> pRequest( new ::comphelper::OInteractionRequest( _rError
) );
85 ::rtl::Reference
< ::comphelper::OInteractionApprove
> pApprove( new ::comphelper::OInteractionApprove
);
86 pRequest
->addContinuation( pApprove
.get() );
87 Optional
< OUString
> aMessage
= xStringResolver
->getStringFromInformationalRequest( pRequest
.get() );
88 if ( aMessage
.IsPresent
)
89 sDisplayMessage
= aMessage
.Value
;
91 catch( const Exception
& )
93 DBG_UNHANDLED_EXCEPTION();
96 if ( sDisplayMessage
.isEmpty() )
101 OUStringBuffer aBuffer
;
102 aBuffer
.append( _rError
.getValueTypeName() );
103 aBuffer
.appendAscii( ":\n" );
104 aBuffer
.append( aExcept
.Message
);
106 sDisplayMessage
= aBuffer
.makeStringAndClear();
109 return sDisplayMessage
;
112 namespace tools
{ namespace stor
{
114 bool storageIsWritable_nothrow( const Reference
< XStorage
>& _rxStorage
)
116 if ( !_rxStorage
.is() )
119 sal_Int32 nMode
= ElementModes::READ
;
122 Reference
< XPropertySet
> xStorageProps( _rxStorage
, UNO_QUERY_THROW
);
123 xStorageProps
->getPropertyValue( "OpenMode" ) >>= nMode
;
125 catch( const Exception
& )
127 DBG_UNHANDLED_EXCEPTION();
129 return ( nMode
& ElementModes::WRITE
) != 0;
132 bool commitStorageIfWriteable( const Reference
< XStorage
>& _rxStorage
)
134 bool bSuccess
= false;
135 Reference
< XTransactedObject
> xTrans( _rxStorage
, UNO_QUERY
);
138 if ( storageIsWritable_nothrow( _rxStorage
) )
147 } // namespace dbaccess
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */