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/XPropertySetInfo.hpp>
26 #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
27 #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
28 #include <com/sun/star/ucb/XCommandInfo.hpp>
30 #include <cppuhelper/queryinterface.hxx>
31 #include <osl/mutex.hxx>
32 #include <ucbhelper/contenthelper.hxx>
33 #include <ucbhelper/contentinfo.hxx>
34 #include <ucbhelper/macros.hxx>
36 using namespace com::sun::star
;
39 // PropertySetInfo Implementation.
44 PropertySetInfo::PropertySetInfo(
45 const uno::Reference
< css::ucb::XCommandEnvironment
>& rxEnv
,
46 ContentImplHelper
* pContent
)
48 m_pContent( pContent
)
54 PropertySetInfo::~PropertySetInfo()
59 // XPropertySetInfo methods.
63 uno::Sequence
< beans::Property
> SAL_CALL
PropertySetInfo::getProperties()
67 osl::MutexGuard
aGuard( m_aMutex
);
71 // Get info for core ( native) properties.
76 uno::Sequence
< beans::Property
> aProps
77 = m_pContent
->getProperties( m_xEnv
);
78 m_pProps
.reset(new uno::Sequence
< beans::Property
>( aProps
));
80 catch ( uno::RuntimeException
const & )
84 catch ( uno::Exception
const & )
86 m_pProps
.reset(new uno::Sequence
< beans::Property
>( 0 ));
90 // Get info for additional properties.
93 uno::Reference
< css::ucb::XPersistentPropertySet
>
94 xSet ( m_pContent
->getAdditionalPropertySet( false ) );
98 // Get property set info.
99 uno::Reference
< beans::XPropertySetInfo
> xInfo(
100 xSet
->getPropertySetInfo() );
103 const uno::Sequence
< beans::Property
>& rAddProps
104 = xInfo
->getProperties();
105 sal_Int32 nAddProps
= rAddProps
.getLength();
108 sal_Int32 nPos
= m_pProps
->getLength();
109 m_pProps
->realloc( nPos
+ nAddProps
);
111 std::copy(rAddProps
.begin(), rAddProps
.end(),
112 std::next(m_pProps
->begin(), nPos
));
123 beans::Property SAL_CALL
PropertySetInfo::getPropertyByName(
124 const OUString
& aName
)
126 beans::Property aProp
;
127 if ( queryProperty( aName
, aProp
) )
130 throw beans::UnknownPropertyException(aName
);
135 sal_Bool SAL_CALL
PropertySetInfo::hasPropertyByName(
136 const OUString
& Name
)
138 beans::Property aProp
;
139 return queryProperty( Name
, aProp
);
143 // Non-Interface methods.
146 void PropertySetInfo::reset()
148 osl::MutexGuard
aGuard( m_aMutex
);
153 bool PropertySetInfo::queryProperty(
154 const OUString
& rName
, beans::Property
& rProp
)
156 osl::MutexGuard
aGuard( m_aMutex
);
160 const beans::Property
* pProps
= m_pProps
->getConstArray();
161 sal_Int32 nCount
= m_pProps
->getLength();
162 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
164 const beans::Property
& rCurrProp
= pProps
[ n
];
165 if ( rCurrProp
.Name
== rName
)
176 // CommandProcessorInfo Implementation.
179 CommandProcessorInfo::CommandProcessorInfo(
180 const uno::Reference
< css::ucb::XCommandEnvironment
>& rxEnv
,
181 ContentImplHelper
* pContent
)
183 m_pContent( pContent
)
189 CommandProcessorInfo::~CommandProcessorInfo()
194 // XCommandInfo methods.
198 uno::Sequence
< css::ucb::CommandInfo
> SAL_CALL
199 CommandProcessorInfo::getCommands()
203 osl::MutexGuard
aGuard( m_aMutex
);
207 // Get info for commands.
212 uno::Sequence
< css::ucb::CommandInfo
> aCmds
213 = m_pContent
->getCommands( m_xEnv
);
214 m_pCommands
.reset(new uno::Sequence
< css::ucb::CommandInfo
>( aCmds
));
216 catch ( uno::RuntimeException
const & )
220 catch ( uno::Exception
const & )
222 m_pCommands
.reset(new uno::Sequence
< css::ucb::CommandInfo
>( 0 ));
231 css::ucb::CommandInfo SAL_CALL
232 CommandProcessorInfo::getCommandInfoByName(
233 const OUString
& Name
)
235 css::ucb::CommandInfo aInfo
;
236 if ( queryCommand( Name
, aInfo
) )
239 throw css::ucb::UnsupportedCommandException();
244 css::ucb::CommandInfo SAL_CALL
245 CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle
)
247 css::ucb::CommandInfo aInfo
;
248 if ( queryCommand( Handle
, aInfo
) )
251 throw css::ucb::UnsupportedCommandException();
256 sal_Bool SAL_CALL
CommandProcessorInfo::hasCommandByName(
257 const OUString
& Name
)
259 css::ucb::CommandInfo aInfo
;
260 return queryCommand( Name
, aInfo
);
265 sal_Bool SAL_CALL
CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle
)
267 css::ucb::CommandInfo aInfo
;
268 return queryCommand( Handle
, aInfo
);
272 // Non-Interface methods.
275 void CommandProcessorInfo::reset()
277 osl::MutexGuard
aGuard( m_aMutex
);
282 bool CommandProcessorInfo::queryCommand(
283 const OUString
& rName
,
284 css::ucb::CommandInfo
& rCommand
)
286 osl::MutexGuard
aGuard( m_aMutex
);
290 const css::ucb::CommandInfo
* pCommands
291 = m_pCommands
->getConstArray();
292 sal_Int32 nCount
= m_pCommands
->getLength();
293 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
295 const css::ucb::CommandInfo
& rCurrCommand
= pCommands
[ n
];
296 if ( rCurrCommand
.Name
== rName
)
298 rCommand
= rCurrCommand
;
307 bool CommandProcessorInfo::queryCommand(
309 css::ucb::CommandInfo
& rCommand
)
311 osl::MutexGuard
aGuard( m_aMutex
);
315 const css::ucb::CommandInfo
* pCommands
= m_pCommands
->getConstArray();
316 sal_Int32 nCount
= m_pCommands
->getLength();
317 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
319 const css::ucb::CommandInfo
& rCurrCommand
= pCommands
[ n
];
320 if ( rCurrCommand
.Handle
== nHandle
)
322 rCommand
= rCurrCommand
;
330 } // namespace ucbhelper
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */