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/XPropertySetRegistry.hpp>
28 #include "osl/diagnose.h"
29 #include "osl/mutex.hxx"
30 #include <ucbhelper/contenthelper.hxx>
31 #include <ucbhelper/contentinfo.hxx>
33 using namespace com::sun::star
;
38 // PropertySetInfo Implementation.
45 PropertySetInfo::PropertySetInfo(
46 const uno::Reference
< com::sun::star::ucb::XCommandEnvironment
>& rxEnv
,
47 ContentImplHelper
* pContent
)
50 m_pContent( pContent
)
56 PropertySetInfo::~PropertySetInfo()
63 // XInterface methods.
65 void SAL_CALL
PropertySetInfo::acquire()
68 OWeakObject::acquire();
71 void SAL_CALL
PropertySetInfo::release()
74 OWeakObject::release();
77 css::uno::Any SAL_CALL
PropertySetInfo::queryInterface( const css::uno::Type
& rType
)
78 throw( css::uno::RuntimeException
, std::exception
)
80 css::uno::Any aRet
= cppu::queryInterface( rType
,
81 (static_cast< lang::XTypeProvider
* >(this)),
82 (static_cast< beans::XPropertySetInfo
* >(this))
84 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
87 // XTypeProvider methods.
88 XTYPEPROVIDER_IMPL_2( PropertySetInfo
,
90 beans::XPropertySetInfo
);
93 // XPropertySetInfo methods.
98 uno::Sequence
< beans::Property
> SAL_CALL
PropertySetInfo::getProperties()
99 throw( uno::RuntimeException
, std::exception
)
103 osl::MutexGuard
aGuard( m_aMutex
);
107 // Get info for core ( native) properties.
112 uno::Sequence
< beans::Property
> aProps
113 = m_pContent
->getProperties( m_xEnv
);
114 m_pProps
= new uno::Sequence
< beans::Property
>( aProps
);
116 catch ( uno::RuntimeException
const & )
120 catch ( uno::Exception
const & )
122 m_pProps
= new uno::Sequence
< beans::Property
>( 0 );
126 // Get info for additional properties.
129 uno::Reference
< com::sun::star::ucb::XPersistentPropertySet
>
130 xSet ( m_pContent
->getAdditionalPropertySet( false ) );
134 // Get property set info.
135 uno::Reference
< beans::XPropertySetInfo
> xInfo(
136 xSet
->getPropertySetInfo() );
139 const uno::Sequence
< beans::Property
>& rAddProps
140 = xInfo
->getProperties();
141 sal_Int32 nAddProps
= rAddProps
.getLength();
144 sal_Int32 nPos
= m_pProps
->getLength();
145 m_pProps
->realloc( nPos
+ nAddProps
);
147 beans::Property
* pProps
= m_pProps
->getArray();
148 const beans::Property
* pAddProps
149 = rAddProps
.getConstArray();
151 for ( sal_Int32 n
= 0; n
< nAddProps
; ++n
, ++nPos
)
152 pProps
[ nPos
] = pAddProps
[ n
];
163 beans::Property SAL_CALL
PropertySetInfo::getPropertyByName(
164 const OUString
& aName
)
165 throw( beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
167 beans::Property aProp
;
168 if ( queryProperty( aName
, aProp
) )
171 throw beans::UnknownPropertyException();
176 sal_Bool SAL_CALL
PropertySetInfo::hasPropertyByName(
177 const OUString
& Name
)
178 throw( uno::RuntimeException
, std::exception
)
180 beans::Property aProp
;
181 return queryProperty( Name
, aProp
);
186 // Non-Interface methods.
190 void PropertySetInfo::reset()
192 osl::MutexGuard
aGuard( m_aMutex
);
198 bool PropertySetInfo::queryProperty(
199 const OUString
& rName
, beans::Property
& rProp
)
201 osl::MutexGuard
aGuard( m_aMutex
);
205 const beans::Property
* pProps
= m_pProps
->getConstArray();
206 sal_Int32 nCount
= m_pProps
->getLength();
207 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
209 const beans::Property
& rCurrProp
= pProps
[ n
];
210 if ( rCurrProp
.Name
== rName
)
223 // CommandProcessorInfo Implementation.
228 CommandProcessorInfo::CommandProcessorInfo(
229 const uno::Reference
< com::sun::star::ucb::XCommandEnvironment
>& rxEnv
,
230 ContentImplHelper
* pContent
)
233 m_pContent( pContent
)
239 CommandProcessorInfo::~CommandProcessorInfo()
246 // XInterface methods.
249 void SAL_CALL
CommandProcessorInfo::acquire()
252 OWeakObject::acquire();
255 void SAL_CALL
CommandProcessorInfo::release()
258 OWeakObject::release();
261 css::uno::Any SAL_CALL
CommandProcessorInfo::queryInterface( const css::uno::Type
& rType
)
262 throw( css::uno::RuntimeException
, std::exception
)
264 css::uno::Any aRet
= cppu::queryInterface( rType
,
265 (static_cast< lang::XTypeProvider
* >(this)),
266 (static_cast< css::ucb::XCommandInfo
* >(this))
268 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
271 // XTypeProvider methods.
275 XTYPEPROVIDER_IMPL_2( CommandProcessorInfo
,
277 com::sun::star::ucb::XCommandInfo
);
281 // XCommandInfo methods.
286 uno::Sequence
< com::sun::star::ucb::CommandInfo
> SAL_CALL
287 CommandProcessorInfo::getCommands()
288 throw( uno::RuntimeException
, std::exception
)
292 osl::MutexGuard
aGuard( m_aMutex
);
296 // Get info for commands.
301 uno::Sequence
< com::sun::star::ucb::CommandInfo
> aCmds
302 = m_pContent
->getCommands( m_xEnv
);
304 = new uno::Sequence
< com::sun::star::ucb::CommandInfo
>(
307 catch ( uno::RuntimeException
const & )
311 catch ( uno::Exception
const & )
314 = new uno::Sequence
< com::sun::star::ucb::CommandInfo
>(
324 com::sun::star::ucb::CommandInfo SAL_CALL
325 CommandProcessorInfo::getCommandInfoByName(
326 const OUString
& Name
)
327 throw( com::sun::star::ucb::UnsupportedCommandException
,
328 uno::RuntimeException
, std::exception
)
330 com::sun::star::ucb::CommandInfo aInfo
;
331 if ( queryCommand( Name
, aInfo
) )
334 throw com::sun::star::ucb::UnsupportedCommandException();
339 com::sun::star::ucb::CommandInfo SAL_CALL
340 CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle
)
341 throw( com::sun::star::ucb::UnsupportedCommandException
,
342 uno::RuntimeException
, std::exception
)
344 com::sun::star::ucb::CommandInfo aInfo
;
345 if ( queryCommand( Handle
, aInfo
) )
348 throw com::sun::star::ucb::UnsupportedCommandException();
353 sal_Bool SAL_CALL
CommandProcessorInfo::hasCommandByName(
354 const OUString
& Name
)
355 throw( uno::RuntimeException
, std::exception
)
357 com::sun::star::ucb::CommandInfo aInfo
;
358 return queryCommand( Name
, aInfo
);
363 sal_Bool SAL_CALL
CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle
)
364 throw( uno::RuntimeException
, std::exception
)
366 com::sun::star::ucb::CommandInfo aInfo
;
367 return queryCommand( Handle
, aInfo
);
372 // Non-Interface methods.
376 void CommandProcessorInfo::reset()
378 osl::MutexGuard
aGuard( m_aMutex
);
385 bool CommandProcessorInfo::queryCommand(
386 const OUString
& rName
,
387 com::sun::star::ucb::CommandInfo
& rCommand
)
389 osl::MutexGuard
aGuard( m_aMutex
);
393 const com::sun::star::ucb::CommandInfo
* pCommands
394 = m_pCommands
->getConstArray();
395 sal_Int32 nCount
= m_pCommands
->getLength();
396 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
398 const com::sun::star::ucb::CommandInfo
& rCurrCommand
= pCommands
[ n
];
399 if ( rCurrCommand
.Name
== rName
)
401 rCommand
= rCurrCommand
;
410 bool CommandProcessorInfo::queryCommand(
412 com::sun::star::ucb::CommandInfo
& rCommand
)
414 osl::MutexGuard
aGuard( m_aMutex
);
418 const com::sun::star::ucb::CommandInfo
* pCommands
419 = m_pCommands
->getConstArray();
420 sal_Int32 nCount
= m_pCommands
->getLength();
421 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
423 const com::sun::star::ucb::CommandInfo
& rCurrCommand
= pCommands
[ n
];
424 if ( rCurrCommand
.Handle
== nHandle
)
426 rCommand
= rCurrCommand
;
434 } // namespace ucbhelper
436 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */