LibreOffice Module ucbhelper (master)  1
contentinfo.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 /**************************************************************************
21  TODO
22  **************************************************************************
23 
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>
29 
31 #include <osl/mutex.hxx>
33 #include "contentinfo.hxx"
34 #include <ucbhelper/macros.hxx>
35 
36 using namespace com::sun::star;
37 
38 
39 // PropertySetInfo Implementation.
40 
41 
42 namespace ucbhelper {
43 
44 PropertySetInfo::PropertySetInfo(
45  const uno::Reference< css::ucb::XCommandEnvironment >& rxEnv,
46  ContentImplHelper* pContent )
47 : m_xEnv( rxEnv ),
48  m_pContent( pContent )
49 {
50 }
51 
52 
53 // virtual
55 {
56 }
57 
58 
59 // XPropertySetInfo methods.
60 
61 
62 // virtual
63 uno::Sequence< beans::Property > SAL_CALL PropertySetInfo::getProperties()
64 {
65  if ( !m_pProps )
66  {
67  osl::MutexGuard aGuard( m_aMutex );
68  if ( !m_pProps )
69  {
70 
71  // Get info for core ( native) properties.
72 
73 
74  try
75  {
76  uno::Sequence< beans::Property > aProps
78  m_pProps.reset(new uno::Sequence< beans::Property >( aProps ));
79  }
80  catch ( uno::RuntimeException const & )
81  {
82  throw;
83  }
84  catch ( uno::Exception const & )
85  {
86  m_pProps.reset(new uno::Sequence< beans::Property >( 0 ));
87  }
88 
89 
90  // Get info for additional properties.
91 
92 
93  uno::Reference< css::ucb::XPersistentPropertySet >
94  xSet ( m_pContent->getAdditionalPropertySet( false ) );
95 
96  if ( xSet.is() )
97  {
98  // Get property set info.
99  uno::Reference< beans::XPropertySetInfo > xInfo(
100  xSet->getPropertySetInfo() );
101  if ( xInfo.is() )
102  {
103  const uno::Sequence< beans::Property >& rAddProps
104  = xInfo->getProperties();
105  sal_Int32 nAddProps = rAddProps.getLength();
106  if ( nAddProps > 0 )
107  {
108  sal_Int32 nPos = m_pProps->getLength();
109  m_pProps->realloc( nPos + nAddProps );
110 
111  std::copy(rAddProps.begin(), rAddProps.end(),
112  std::next(m_pProps->begin(), nPos));
113  }
114  }
115  }
116  }
117  }
118  return *m_pProps;
119 }
120 
121 
122 // virtual
123 beans::Property SAL_CALL PropertySetInfo::getPropertyByName(
124  const OUString& aName )
125 {
126  beans::Property aProp;
127  if ( queryProperty( aName, aProp ) )
128  return aProp;
129 
130  throw beans::UnknownPropertyException(aName);
131 }
132 
133 
134 // virtual
136  const OUString& Name )
137 {
138  beans::Property aProp;
139  return queryProperty( Name, aProp );
140 }
141 
142 
143 // Non-Interface methods.
144 
145 
147 {
148  osl::MutexGuard aGuard( m_aMutex );
149  m_pProps.reset();
150 }
151 
152 
154  const OUString& rName, beans::Property& rProp )
155 {
156  osl::MutexGuard aGuard( m_aMutex );
157 
158  getProperties();
159 
160  const beans::Property* pProps = m_pProps->getConstArray();
161  sal_Int32 nCount = m_pProps->getLength();
162  for ( sal_Int32 n = 0; n < nCount; ++n )
163  {
164  const beans::Property& rCurrProp = pProps[ n ];
165  if ( rCurrProp.Name == rName )
166  {
167  rProp = rCurrProp;
168  return true;
169  }
170  }
171 
172  return false;
173 }
174 
175 
176 // CommandProcessorInfo Implementation.
177 
178 
180  const uno::Reference< css::ucb::XCommandEnvironment >& rxEnv,
181  ContentImplHelper* pContent )
182 : m_xEnv( rxEnv ),
183  m_pContent( pContent )
184 {
185 }
186 
187 
188 // virtual
190 {
191 }
192 
193 
194 // XCommandInfo methods.
195 
196 
197 // virtual
198 uno::Sequence< css::ucb::CommandInfo > SAL_CALL
200 {
201  if ( !m_pCommands )
202  {
203  osl::MutexGuard aGuard( m_aMutex );
204  if ( !m_pCommands )
205  {
206 
207  // Get info for commands.
208 
209 
210  try
211  {
212  uno::Sequence< css::ucb::CommandInfo > aCmds
214  m_pCommands.reset(new uno::Sequence< css::ucb::CommandInfo >( aCmds ));
215  }
216  catch ( uno::RuntimeException const & )
217  {
218  throw;
219  }
220  catch ( uno::Exception const & )
221  {
222  m_pCommands.reset(new uno::Sequence< css::ucb::CommandInfo >( 0 ));
223  }
224  }
225  }
226  return *m_pCommands;
227 }
228 
229 
230 // virtual
231 css::ucb::CommandInfo SAL_CALL
233  const OUString& Name )
234 {
235  css::ucb::CommandInfo aInfo;
236  if ( queryCommand( Name, aInfo ) )
237  return aInfo;
238 
239  throw css::ucb::UnsupportedCommandException();
240 }
241 
242 
243 // virtual
244 css::ucb::CommandInfo SAL_CALL
246 {
247  css::ucb::CommandInfo aInfo;
248  if ( queryCommand( Handle, aInfo ) )
249  return aInfo;
250 
251  throw css::ucb::UnsupportedCommandException();
252 }
253 
254 
255 // virtual
257  const OUString& Name )
258 {
259  css::ucb::CommandInfo aInfo;
260  return queryCommand( Name, aInfo );
261 }
262 
263 
264 // virtual
266 {
267  css::ucb::CommandInfo aInfo;
268  return queryCommand( Handle, aInfo );
269 }
270 
271 
272 // Non-Interface methods.
273 
274 
276 {
277  osl::MutexGuard aGuard( m_aMutex );
278  m_pCommands.reset();
279 }
280 
281 
283  const OUString& rName,
284  css::ucb::CommandInfo& rCommand )
285 {
286  osl::MutexGuard aGuard( m_aMutex );
287 
288  getCommands();
289 
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 )
294  {
295  const css::ucb::CommandInfo& rCurrCommand = pCommands[ n ];
296  if ( rCurrCommand.Name == rName )
297  {
298  rCommand = rCurrCommand;
299  return true;
300  }
301  }
302 
303  return false;
304 }
305 
306 
308  sal_Int32 nHandle,
309  css::ucb::CommandInfo& rCommand )
310 {
311  osl::MutexGuard aGuard( m_aMutex );
312 
313  getCommands();
314 
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 )
318  {
319  const css::ucb::CommandInfo& rCurrCommand = pCommands[ n ];
320  if ( rCurrCommand.Handle == nHandle )
321  {
322  rCommand = rCurrCommand;
323  return true;
324  }
325  }
326 
327  return false;
328 }
329 
330 } // namespace ucbhelper
331 
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::ucb::XCommandEnvironment > m_xEnv
Definition: contentinfo.hxx:90
CommandProcessorInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &rxEnv, ContentImplHelper *pContent)
virtual sal_Bool SAL_CALL hasCommandByHandle(sal_Int32 Handle) override
virtual sal_Bool SAL_CALL hasPropertyByName(const OUString &Name) override
std::unique_ptr< css::uno::Sequence< css::ucb::CommandInfo > > m_pCommands
Definition: contentinfo.hxx:92
css::uno::Reference< css::ucb::XCommandEnvironment > m_xEnv
Definition: contentinfo.hxx:50
bool queryCommand(const OUString &rName, css::ucb::CommandInfo &rCommand)
sal_Int64 n
This is an abstract base class for implementations of the service com.sun.star.ucb.Content.
css::uno::Reference< css::ucb::XPersistentPropertySet > getAdditionalPropertySet(bool bCreate)
Use this method to get access to the Additional Core Properties of the content ( added using content'...
int nCount
virtual css::uno::Sequence< css::beans::Property > SAL_CALL getProperties() override
Definition: contentinfo.cxx:63
virtual css::uno::Sequence< css::ucb::CommandInfo > SAL_CALL getCommands() override
sal_Int32 nHandle
Definition: resultset.cxx:46
ContentImplHelper * m_pContent
Definition: contentinfo.hxx:94
virtual css::ucb::CommandInfo SAL_CALL getCommandInfoByHandle(sal_Int32 Handle) override
unsigned char sal_Bool
virtual ~CommandProcessorInfo() override
virtual css::ucb::CommandInfo SAL_CALL getCommandInfoByName(const OUString &Name) override
std::unique_ptr< css::uno::Sequence< css::beans::Property > > m_pProps
Definition: contentinfo.hxx:52
SQLHANDLE Handle
virtual sal_Bool SAL_CALL hasCommandByName(const OUString &Name) override
virtual UCBHELPER_DLLPRIVATE css::uno::Sequence< css::ucb::CommandInfo > getCommands(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)=0
Your implementation of this method must return a sequence containing the meta data of the commands su...
virtual UCBHELPER_DLLPRIVATE css::uno::Sequence< css::beans::Property > getProperties(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)=0
Your implementation of this method must return a sequence containing the meta data of the properties ...
ContentImplHelper * m_pContent
Definition: contentinfo.hxx:54
virtual ~PropertySetInfo() override
Definition: contentinfo.cxx:54
sal_uInt16 nPos
virtual css::beans::Property SAL_CALL getPropertyByName(const OUString &aName) override
bool queryProperty(const OUString &rName, css::beans::Property &rProp)