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 /**************************************************************************
22 **************************************************************************
24 *************************************************************************/
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
27 #include <com/sun/star/ucb/XPropertySetRegistry.hpp>
28 #include <com/sun/star/beans/XPropertySetInfo.hpp>
29 #include <com/sun/star/ucb/XCommandInfo.hpp>
31 #include <cppuhelper/queryinterface.hxx>
32 #include <osl/mutex.hxx>
33 #include <ucbhelper/contenthelper.hxx>
34 #include <ucbhelper/contentinfo.hxx>
35 #include <ucbhelper/macros.hxx>
37 using namespace com::sun::star
;
40 // PropertySetInfo Implementation.
45 PropertySetInfo::PropertySetInfo(
46 const uno::Reference
< css::ucb::XCommandEnvironment
>& rxEnv
,
47 ContentImplHelper
* pContent
)
49 m_pContent( pContent
)
55 PropertySetInfo::~PropertySetInfo()
60 // XInterface methods.
62 void SAL_CALL
PropertySetInfo::acquire()
65 OWeakObject::acquire();
68 void SAL_CALL
PropertySetInfo::release()
71 OWeakObject::release();
74 css::uno::Any SAL_CALL
PropertySetInfo::queryInterface( const css::uno::Type
& rType
)
76 css::uno::Any aRet
= cppu::queryInterface( rType
,
77 static_cast< lang::XTypeProvider
* >(this),
78 static_cast< beans::XPropertySetInfo
* >(this)
80 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
83 // XTypeProvider methods.
84 XTYPEPROVIDER_IMPL_2( PropertySetInfo
,
86 beans::XPropertySetInfo
);
89 // XPropertySetInfo methods.
93 uno::Sequence
< beans::Property
> SAL_CALL
PropertySetInfo::getProperties()
97 osl::MutexGuard
aGuard( m_aMutex
);
101 // Get info for core ( native) properties.
106 uno::Sequence
< beans::Property
> aProps
107 = m_pContent
->getProperties( m_xEnv
);
108 m_pProps
.reset(new uno::Sequence
< beans::Property
>( aProps
));
110 catch ( uno::RuntimeException
const & )
114 catch ( uno::Exception
const & )
116 m_pProps
.reset(new uno::Sequence
< beans::Property
>( 0 ));
120 // Get info for additional properties.
123 uno::Reference
< css::ucb::XPersistentPropertySet
>
124 xSet ( m_pContent
->getAdditionalPropertySet( false ) );
128 // Get property set info.
129 uno::Reference
< beans::XPropertySetInfo
> xInfo(
130 xSet
->getPropertySetInfo() );
133 const uno::Sequence
< beans::Property
>& rAddProps
134 = xInfo
->getProperties();
135 sal_Int32 nAddProps
= rAddProps
.getLength();
138 sal_Int32 nPos
= m_pProps
->getLength();
139 m_pProps
->realloc( nPos
+ nAddProps
);
141 beans::Property
* pProps
= m_pProps
->getArray();
142 const beans::Property
* pAddProps
143 = rAddProps
.getConstArray();
145 for ( sal_Int32 n
= 0; n
< nAddProps
; ++n
, ++nPos
)
146 pProps
[ nPos
] = pAddProps
[ n
];
157 beans::Property SAL_CALL
PropertySetInfo::getPropertyByName(
158 const OUString
& aName
)
160 beans::Property aProp
;
161 if ( queryProperty( aName
, aProp
) )
164 throw beans::UnknownPropertyException();
169 sal_Bool SAL_CALL
PropertySetInfo::hasPropertyByName(
170 const OUString
& Name
)
172 beans::Property aProp
;
173 return queryProperty( Name
, aProp
);
177 // Non-Interface methods.
180 void PropertySetInfo::reset()
182 osl::MutexGuard
aGuard( m_aMutex
);
187 bool PropertySetInfo::queryProperty(
188 const OUString
& rName
, beans::Property
& rProp
)
190 osl::MutexGuard
aGuard( m_aMutex
);
194 const beans::Property
* pProps
= m_pProps
->getConstArray();
195 sal_Int32 nCount
= m_pProps
->getLength();
196 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
198 const beans::Property
& rCurrProp
= pProps
[ n
];
199 if ( rCurrProp
.Name
== rName
)
210 // CommandProcessorInfo Implementation.
213 CommandProcessorInfo::CommandProcessorInfo(
214 const uno::Reference
< css::ucb::XCommandEnvironment
>& rxEnv
,
215 ContentImplHelper
* pContent
)
217 m_pContent( pContent
)
223 CommandProcessorInfo::~CommandProcessorInfo()
228 // XInterface methods.
231 void SAL_CALL
CommandProcessorInfo::acquire()
234 OWeakObject::acquire();
237 void SAL_CALL
CommandProcessorInfo::release()
240 OWeakObject::release();
243 css::uno::Any SAL_CALL
CommandProcessorInfo::queryInterface( const css::uno::Type
& rType
)
245 css::uno::Any aRet
= cppu::queryInterface( rType
,
246 static_cast< lang::XTypeProvider
* >(this),
247 static_cast< css::ucb::XCommandInfo
* >(this)
249 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
252 // XTypeProvider methods.
255 XTYPEPROVIDER_IMPL_2( CommandProcessorInfo
,
257 css::ucb::XCommandInfo
);
260 // XCommandInfo methods.
264 uno::Sequence
< css::ucb::CommandInfo
> SAL_CALL
265 CommandProcessorInfo::getCommands()
269 osl::MutexGuard
aGuard( m_aMutex
);
273 // Get info for commands.
278 uno::Sequence
< css::ucb::CommandInfo
> aCmds
279 = m_pContent
->getCommands( m_xEnv
);
280 m_pCommands
.reset(new uno::Sequence
< css::ucb::CommandInfo
>( aCmds
));
282 catch ( uno::RuntimeException
const & )
286 catch ( uno::Exception
const & )
288 m_pCommands
.reset(new uno::Sequence
< css::ucb::CommandInfo
>( 0 ));
297 css::ucb::CommandInfo SAL_CALL
298 CommandProcessorInfo::getCommandInfoByName(
299 const OUString
& Name
)
301 css::ucb::CommandInfo aInfo
;
302 if ( queryCommand( Name
, aInfo
) )
305 throw css::ucb::UnsupportedCommandException();
310 css::ucb::CommandInfo SAL_CALL
311 CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle
)
313 css::ucb::CommandInfo aInfo
;
314 if ( queryCommand( Handle
, aInfo
) )
317 throw css::ucb::UnsupportedCommandException();
322 sal_Bool SAL_CALL
CommandProcessorInfo::hasCommandByName(
323 const OUString
& Name
)
325 css::ucb::CommandInfo aInfo
;
326 return queryCommand( Name
, aInfo
);
331 sal_Bool SAL_CALL
CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle
)
333 css::ucb::CommandInfo aInfo
;
334 return queryCommand( Handle
, aInfo
);
338 // Non-Interface methods.
341 void CommandProcessorInfo::reset()
343 osl::MutexGuard
aGuard( m_aMutex
);
348 bool CommandProcessorInfo::queryCommand(
349 const OUString
& rName
,
350 css::ucb::CommandInfo
& rCommand
)
352 osl::MutexGuard
aGuard( m_aMutex
);
356 const css::ucb::CommandInfo
* pCommands
357 = m_pCommands
->getConstArray();
358 sal_Int32 nCount
= m_pCommands
->getLength();
359 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
361 const css::ucb::CommandInfo
& rCurrCommand
= pCommands
[ n
];
362 if ( rCurrCommand
.Name
== rName
)
364 rCommand
= rCurrCommand
;
373 bool CommandProcessorInfo::queryCommand(
375 css::ucb::CommandInfo
& rCommand
)
377 osl::MutexGuard
aGuard( m_aMutex
);
381 const css::ucb::CommandInfo
* pCommands
= m_pCommands
->getConstArray();
382 sal_Int32 nCount
= m_pCommands
->getLength();
383 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
385 const css::ucb::CommandInfo
& rCurrCommand
= pCommands
[ n
];
386 if ( rCurrCommand
.Handle
== nHandle
)
388 rCommand
= rCurrCommand
;
396 } // namespace ucbhelper
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */