LibreOffice Module ucb (master)  1
cmis_datasupplier.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 
10 #include <com/sun/star/ucb/OpenMode.hpp>
11 
12 #include "cmis_datasupplier.hxx"
13 #include "cmis_content.hxx"
14 
15 using namespace com::sun::star;
16 
17 namespace cmis
18 {
19 
20  typedef std::vector< ResultListEntry* > ResultList;
21 
22  DataSupplier::DataSupplier( ChildrenProvider* pChildrenProvider, sal_Int32 nOpenMode )
23  : m_pChildrenProvider( pChildrenProvider ), mnOpenMode(nOpenMode), mbCountFinal(false)
24  {
25  }
26 
28  {
29  if ( mbCountFinal )
30  return;
31 
32  std::vector< uno::Reference< ucb::XContent > > aChildren = m_pChildrenProvider->getChildren( );
33 
34  // Loop over the results and filter them
35  for ( const auto& rChild : aChildren )
36  {
37  OUString sContentType = rChild->getContentType( );
38  bool bIsFolder = sContentType != CMIS_FILE_TYPE;
39  if ( ( mnOpenMode == ucb::OpenMode::FOLDERS && bIsFolder ) ||
40  ( mnOpenMode == ucb::OpenMode::DOCUMENTS && !bIsFolder ) ||
41  ( mnOpenMode == ucb::OpenMode::ALL ) )
42  {
43  maResults.emplace_back( rChild );
44  }
45  }
46  mbCountFinal = true;
47  }
48 
50  {
51  }
52 
53  OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
54  {
55  auto const xTemp(queryContentIdentifier(nIndex));
56  return (xTemp.is()) ? xTemp->getContentIdentifier() : OUString();
57  }
58 
59  uno::Reference< ucb::XContentIdentifier > DataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
60  {
61  auto const xTemp(queryContent(nIndex));
62  return (xTemp.is()) ? xTemp->getIdentifier() : uno::Reference<ucb::XContentIdentifier>();
63  }
64 
65  uno::Reference< ucb::XContent > DataSupplier::queryContent( sal_uInt32 nIndex )
66  {
67  if (!getResult(nIndex))
68  return uno::Reference<ucb::XContent>();
69 
70  return maResults[ nIndex ].xContent;
71  }
72 
73  bool DataSupplier::getResult( sal_uInt32 nIndex )
74  {
75  if ( maResults.size() > nIndex ) // Result already present.
76  return true;
77 
78  getData();
79  return maResults.size() > nIndex;
80  }
81 
83  {
84  getData();
85  return maResults.size();
86  }
87 
89  {
90  return maResults.size();
91  }
92 
94  {
95  return mbCountFinal;
96  }
97 
98  uno::Reference< sdbc::XRow > DataSupplier::queryPropertyValues( sal_uInt32 nIndex )
99  {
100  if ( nIndex < maResults.size() )
101  {
102  uno::Reference< sdbc::XRow > xRow = maResults[ nIndex ].xRow;
103  if ( xRow.is() )
104  {
105  // Already cached.
106  return xRow;
107  }
108  }
109 
110  if ( getResult( nIndex ) )
111  {
112  uno::Reference< ucb::XContent > xContent( queryContent( nIndex ) );
113  if ( xContent.is() )
114  {
115  try
116  {
117  uno::Reference< ucb::XCommandProcessor > xCmdProc(
118  xContent, uno::UNO_QUERY_THROW );
119  sal_Int32 nCmdId( xCmdProc->createCommandIdentifier() );
120  ucb::Command aCmd;
121  aCmd.Name = "getPropertyValues";
122  aCmd.Handle = -1;
123  aCmd.Argument <<= getResultSet()->getProperties();
124  uno::Any aResult( xCmdProc->execute(
125  aCmd, nCmdId, getResultSet()->getEnvironment() ) );
126  uno::Reference< sdbc::XRow > xRow;
127  if ( aResult >>= xRow )
128  {
129  maResults[ nIndex ].xRow = xRow;
130  return xRow;
131  }
132  }
133  catch ( uno::Exception const & )
134  {
135  }
136  }
137  }
138  return uno::Reference< sdbc::XRow >();
139  }
140 
141  void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
142  {
143  if ( nIndex < maResults.size() )
144  maResults[ nIndex ].xRow.clear();
145  }
146 
148  {
149  }
150 
152  {
153  }
154 
155 }
156 
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Environment getEnvironment(OUString const &name, OUString const &implementation)
virtual std::vector< css::uno::Reference< css::ucb::XContent > > getChildren()=0
std::vector< ResultListEntry > maResults
virtual OUString queryContentIdentifierString(sal_uInt32 nIndex) override
virtual css::uno::Reference< css::ucb::XContent > queryContent(sal_uInt32 nIndex) override
sal_Int32 const mnOpenMode
std::vector< ResultListEntry * > ResultList
virtual sal_uInt32 totalCount() override
virtual void close() override
ChildrenProvider * m_pChildrenProvider
virtual bool isCountFinal() override
rtl::Reference< ResultSet > getResultSet() const
virtual void validate() override
virtual css::uno::Reference< css::sdbc::XRow > queryPropertyValues(sal_uInt32 nIndex) override
virtual sal_uInt32 currentCount() override
virtual css::uno::Reference< css::ucb::XContentIdentifier > queryContentIdentifier(sal_uInt32 nIndex) override
#define CMIS_FILE_TYPE
virtual bool getResult(sal_uInt32 nIndex) override
virtual void releasePropertyValues(sal_uInt32 nIndex) override
virtual ~DataSupplier() override