Bump version to 6.4.7.2.M8
[LibreOffice.git] / ucbhelper / source / provider / contentinfo.cxx
bloba0a26745b7583ce82d2a6e69576142daef72f5d8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 /**************************************************************************
21 TODO
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.
42 namespace ucbhelper {
44 PropertySetInfo::PropertySetInfo(
45 const uno::Reference< css::ucb::XCommandEnvironment >& rxEnv,
46 ContentImplHelper* pContent )
47 : m_xEnv( rxEnv ),
48 m_pContent( pContent )
53 // virtual
54 PropertySetInfo::~PropertySetInfo()
59 // XPropertySetInfo methods.
62 // virtual
63 uno::Sequence< beans::Property > SAL_CALL PropertySetInfo::getProperties()
65 if ( !m_pProps )
67 osl::MutexGuard aGuard( m_aMutex );
68 if ( !m_pProps )
71 // Get info for core ( native) properties.
74 try
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 & )
82 throw;
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 ) );
96 if ( xSet.is() )
98 // Get property set info.
99 uno::Reference< beans::XPropertySetInfo > xInfo(
100 xSet->getPropertySetInfo() );
101 if ( xInfo.is() )
103 const uno::Sequence< beans::Property >& rAddProps
104 = xInfo->getProperties();
105 sal_Int32 nAddProps = rAddProps.getLength();
106 if ( nAddProps > 0 )
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));
118 return *m_pProps;
122 // virtual
123 beans::Property SAL_CALL PropertySetInfo::getPropertyByName(
124 const OUString& aName )
126 beans::Property aProp;
127 if ( queryProperty( aName, aProp ) )
128 return aProp;
130 throw beans::UnknownPropertyException(aName);
134 // virtual
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 );
149 m_pProps.reset();
153 bool PropertySetInfo::queryProperty(
154 const OUString& rName, beans::Property& rProp )
156 osl::MutexGuard aGuard( m_aMutex );
158 getProperties();
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 )
167 rProp = rCurrProp;
168 return true;
172 return false;
176 // CommandProcessorInfo Implementation.
179 CommandProcessorInfo::CommandProcessorInfo(
180 const uno::Reference< css::ucb::XCommandEnvironment >& rxEnv,
181 ContentImplHelper* pContent )
182 : m_xEnv( rxEnv ),
183 m_pContent( pContent )
188 // virtual
189 CommandProcessorInfo::~CommandProcessorInfo()
194 // XCommandInfo methods.
197 // virtual
198 uno::Sequence< css::ucb::CommandInfo > SAL_CALL
199 CommandProcessorInfo::getCommands()
201 if ( !m_pCommands )
203 osl::MutexGuard aGuard( m_aMutex );
204 if ( !m_pCommands )
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 & )
218 throw;
220 catch ( uno::Exception const & )
222 m_pCommands.reset(new uno::Sequence< css::ucb::CommandInfo >( 0 ));
226 return *m_pCommands;
230 // virtual
231 css::ucb::CommandInfo SAL_CALL
232 CommandProcessorInfo::getCommandInfoByName(
233 const OUString& Name )
235 css::ucb::CommandInfo aInfo;
236 if ( queryCommand( Name, aInfo ) )
237 return aInfo;
239 throw css::ucb::UnsupportedCommandException();
243 // virtual
244 css::ucb::CommandInfo SAL_CALL
245 CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle )
247 css::ucb::CommandInfo aInfo;
248 if ( queryCommand( Handle, aInfo ) )
249 return aInfo;
251 throw css::ucb::UnsupportedCommandException();
255 // virtual
256 sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByName(
257 const OUString& Name )
259 css::ucb::CommandInfo aInfo;
260 return queryCommand( Name, aInfo );
264 // virtual
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 );
278 m_pCommands.reset();
282 bool CommandProcessorInfo::queryCommand(
283 const OUString& rName,
284 css::ucb::CommandInfo& rCommand )
286 osl::MutexGuard aGuard( m_aMutex );
288 getCommands();
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;
299 return true;
303 return false;
307 bool CommandProcessorInfo::queryCommand(
308 sal_Int32 nHandle,
309 css::ucb::CommandInfo& rCommand )
311 osl::MutexGuard aGuard( m_aMutex );
313 getCommands();
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;
323 return true;
327 return false;
330 } // namespace ucbhelper
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */