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
;
35 //=========================================================================
36 //=========================================================================
38 // PropertySetInfo Implementation.
40 //=========================================================================
41 //=========================================================================
45 PropertySetInfo::PropertySetInfo(
46 const uno::Reference
< com::sun::star::ucb::XCommandEnvironment
>& rxEnv
,
47 ContentImplHelper
* pContent
)
50 m_pContent( pContent
)
54 //=========================================================================
56 PropertySetInfo::~PropertySetInfo()
61 //=========================================================================
63 // XInterface methods.
65 //=========================================================================
67 XINTERFACE_IMPL_2( PropertySetInfo
,
69 beans::XPropertySetInfo
);
71 //=========================================================================
73 // XTypeProvider methods.
75 //=========================================================================
77 XTYPEPROVIDER_IMPL_2( PropertySetInfo
,
79 beans::XPropertySetInfo
);
81 //=========================================================================
83 // XPropertySetInfo methods.
85 //=========================================================================
88 uno::Sequence
< beans::Property
> SAL_CALL
PropertySetInfo::getProperties()
89 throw( uno::RuntimeException
)
93 osl::MutexGuard
aGuard( m_aMutex
);
96 //////////////////////////////////////////////////////////////
97 // Get info for core ( native) properties.
98 //////////////////////////////////////////////////////////////
102 uno::Sequence
< beans::Property
> aProps
103 = m_pContent
->getProperties( m_xEnv
);
104 m_pProps
= new uno::Sequence
< beans::Property
>( aProps
);
106 catch ( uno::RuntimeException
const & )
110 catch ( uno::Exception
const & )
112 m_pProps
= new uno::Sequence
< beans::Property
>( 0 );
115 //////////////////////////////////////////////////////////////
116 // Get info for additional properties.
117 //////////////////////////////////////////////////////////////
119 uno::Reference
< com::sun::star::ucb::XPersistentPropertySet
>
120 xSet ( m_pContent
->getAdditionalPropertySet( sal_False
) );
124 // Get property set info.
125 uno::Reference
< beans::XPropertySetInfo
> xInfo(
126 xSet
->getPropertySetInfo() );
129 const uno::Sequence
< beans::Property
>& rAddProps
130 = xInfo
->getProperties();
131 sal_Int32 nAddProps
= rAddProps
.getLength();
134 sal_Int32 nPos
= m_pProps
->getLength();
135 m_pProps
->realloc( nPos
+ nAddProps
);
137 beans::Property
* pProps
= m_pProps
->getArray();
138 const beans::Property
* pAddProps
139 = rAddProps
.getConstArray();
141 for ( sal_Int32 n
= 0; n
< nAddProps
; ++n
, ++nPos
)
142 pProps
[ nPos
] = pAddProps
[ n
];
151 //=========================================================================
153 beans::Property SAL_CALL
PropertySetInfo::getPropertyByName(
154 const OUString
& aName
)
155 throw( beans::UnknownPropertyException
, uno::RuntimeException
)
157 beans::Property aProp
;
158 if ( queryProperty( aName
, aProp
) )
161 throw beans::UnknownPropertyException();
164 //=========================================================================
166 sal_Bool SAL_CALL
PropertySetInfo::hasPropertyByName(
167 const OUString
& Name
)
168 throw( uno::RuntimeException
)
170 beans::Property aProp
;
171 return queryProperty( Name
, aProp
);
174 //=========================================================================
176 // Non-Interface methods.
178 //=========================================================================
180 void PropertySetInfo::reset()
182 osl::MutexGuard
aGuard( m_aMutex
);
187 //=========================================================================
188 sal_Bool
PropertySetInfo::queryProperty(
189 const OUString
& rName
, beans::Property
& rProp
)
191 osl::MutexGuard
aGuard( m_aMutex
);
195 const beans::Property
* pProps
= m_pProps
->getConstArray();
196 sal_Int32 nCount
= m_pProps
->getLength();
197 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
199 const beans::Property
& rCurrProp
= pProps
[ n
];
200 if ( rCurrProp
.Name
== rName
)
210 //=========================================================================
211 //=========================================================================
213 // CommandProcessorInfo Implementation.
215 //=========================================================================
216 //=========================================================================
218 CommandProcessorInfo::CommandProcessorInfo(
219 const uno::Reference
< com::sun::star::ucb::XCommandEnvironment
>& rxEnv
,
220 ContentImplHelper
* pContent
)
223 m_pContent( pContent
)
227 //=========================================================================
229 CommandProcessorInfo::~CommandProcessorInfo()
234 //=========================================================================
236 // XInterface methods.
238 //=========================================================================
240 XINTERFACE_IMPL_2( CommandProcessorInfo
,
242 com::sun::star::ucb::XCommandInfo
);
244 //=========================================================================
246 // XTypeProvider methods.
248 //=========================================================================
250 XTYPEPROVIDER_IMPL_2( CommandProcessorInfo
,
252 com::sun::star::ucb::XCommandInfo
);
254 //=========================================================================
256 // XCommandInfo methods.
258 //=========================================================================
261 uno::Sequence
< com::sun::star::ucb::CommandInfo
> SAL_CALL
262 CommandProcessorInfo::getCommands()
263 throw( uno::RuntimeException
)
267 osl::MutexGuard
aGuard( m_aMutex
);
270 //////////////////////////////////////////////////////////////
271 // Get info for commands.
272 //////////////////////////////////////////////////////////////
276 uno::Sequence
< com::sun::star::ucb::CommandInfo
> aCmds
277 = m_pContent
->getCommands( m_xEnv
);
279 = new uno::Sequence
< com::sun::star::ucb::CommandInfo
>(
282 catch ( uno::RuntimeException
const & )
286 catch ( uno::Exception
const & )
289 = new uno::Sequence
< com::sun::star::ucb::CommandInfo
>(
297 //=========================================================================
299 com::sun::star::ucb::CommandInfo SAL_CALL
300 CommandProcessorInfo::getCommandInfoByName(
301 const OUString
& Name
)
302 throw( com::sun::star::ucb::UnsupportedCommandException
,
303 uno::RuntimeException
)
305 com::sun::star::ucb::CommandInfo aInfo
;
306 if ( queryCommand( Name
, aInfo
) )
309 throw com::sun::star::ucb::UnsupportedCommandException();
312 //=========================================================================
314 com::sun::star::ucb::CommandInfo SAL_CALL
315 CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle
)
316 throw( com::sun::star::ucb::UnsupportedCommandException
,
317 uno::RuntimeException
)
319 com::sun::star::ucb::CommandInfo aInfo
;
320 if ( queryCommand( Handle
, aInfo
) )
323 throw com::sun::star::ucb::UnsupportedCommandException();
326 //=========================================================================
328 sal_Bool SAL_CALL
CommandProcessorInfo::hasCommandByName(
329 const OUString
& Name
)
330 throw( uno::RuntimeException
)
332 com::sun::star::ucb::CommandInfo aInfo
;
333 return queryCommand( Name
, aInfo
);
336 //=========================================================================
338 sal_Bool SAL_CALL
CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle
)
339 throw( uno::RuntimeException
)
341 com::sun::star::ucb::CommandInfo aInfo
;
342 return queryCommand( Handle
, aInfo
);
345 //=========================================================================
347 // Non-Interface methods.
349 //=========================================================================
351 void CommandProcessorInfo::reset()
353 osl::MutexGuard
aGuard( m_aMutex
);
359 //=========================================================================
360 sal_Bool
CommandProcessorInfo::queryCommand(
361 const OUString
& rName
,
362 com::sun::star::ucb::CommandInfo
& rCommand
)
364 osl::MutexGuard
aGuard( m_aMutex
);
368 const com::sun::star::ucb::CommandInfo
* pCommands
369 = m_pCommands
->getConstArray();
370 sal_Int32 nCount
= m_pCommands
->getLength();
371 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
373 const com::sun::star::ucb::CommandInfo
& rCurrCommand
= pCommands
[ n
];
374 if ( rCurrCommand
.Name
== rName
)
376 rCommand
= rCurrCommand
;
384 //=========================================================================
385 sal_Bool
CommandProcessorInfo::queryCommand(
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
.Handle
== nHandle
)
401 rCommand
= rCurrCommand
;
409 } // namespace ucbhelper
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */