LibreOffice Module ucb (master)  1
pkgcontent.hxx
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 #pragma once
21 
22 #include <sal/config.h>
23 
24 #include <string_view>
25 #include <vector>
26 #include <rtl/ref.hxx>
27 
28 #include <com/sun/star/ucb/XContentCreator.hpp>
30 #include "pkguri.hxx"
31 
32 namespace com::sun::star {
33  namespace beans
34  {
35  struct Property;
36  struct PropertyValue;
37  }
38  namespace container
39  {
40  class XHierarchicalNameAccess;
41  class XEnumeration;
42  }
43  namespace io
44  {
45  class XInputStream;
46  }
47  namespace sdbc
48  {
49  class XRow;
50  }
51  namespace ucb
52  {
53  struct OpenCommandArgument2;
54  struct TransferInfo;
55  }
56 }
57 
58 namespace package_ucp
59 {
60 
61 
63 {
64  OUString aTitle; // Title
65  OUString aContentType; // ContentType
66  bool bIsDocument; // IsDocument
67  bool bIsFolder; // IsFolder
68  OUString aMediaType; // MediaType
69  css::uno::Sequence < sal_Int8 > aEncryptionKey; // EncryptionKey
70  sal_Int64 nSize; // Size
71  bool bCompressed; // Compressed
72  bool bEncrypted; // Encrypted
73  bool bHasEncryptedEntries; // HasEncryptedEntries
74 
76  : bIsDocument( true ), bIsFolder( false ), nSize( 0 ),
77  bCompressed( true ), bEncrypted( false ),
78  bHasEncryptedEntries( false ) {}
79 
80  explicit ContentProperties( const OUString& rContentType );
81 
82  css::uno::Sequence< css::ucb::ContentInfo >
83  getCreatableContentsInfo( PackageUri const & rUri ) const;
84 };
85 
86 
87 class ContentProvider;
88 
90  public css::ucb::XContentCreator
91 {
92  enum ContentState { TRANSIENT, // created via CreateNewContent,
93  // but did not process "insert" yet
94  PERSISTENT, // processed "insert"
95  DEAD // processed "delete"
96  };
97 
101  css::uno::Reference<
102  css::container::XHierarchicalNameAccess > m_xPackage;
104  sal_uInt32 m_nModifiedProps;
105 
106 private:
107  Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
108  ContentProvider* pProvider,
109  const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
110  const css::uno::Reference< css::container::XHierarchicalNameAccess >& Package,
111  const PackageUri& rUri,
112  const ContentProperties& rProps );
113  Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
114  ContentProvider* pProvider,
115  const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
116  const css::uno::Reference< css::container::XHierarchicalNameAccess >& Package,
117  const PackageUri& rUri,
118  const css::ucb::ContentInfo& Info );
119 
120  virtual css::uno::Sequence< css::beans::Property >
121  getProperties( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
122  virtual css::uno::Sequence< css::ucb::CommandInfo >
123  getCommands( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override;
124  virtual OUString getParentURL() override;
125 
126  static css::uno::Reference< css::sdbc::XRow >
127  getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
128  const css::uno::Sequence< css::beans::Property >& rProperties,
129  const ContentProperties& rData,
131  const OUString& rContentId );
132 
133  css::uno::Reference< css::sdbc::XRow >
134  getPropertyValues( const css::uno::Sequence< css::beans::Property >& rProperties );
136  css::uno::Sequence< css::uno::Any >
137  setPropertyValues( const css::uno::Sequence< css::beans::PropertyValue >& rValues,
138  const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
139 
140  css::uno::Reference< css::container::XHierarchicalNameAccess >
141  getPackage( const PackageUri& rURI );
142  css::uno::Reference< css::container::XHierarchicalNameAccess >
143  getPackage();
144 
145  static bool
146  loadData( ContentProvider* pProvider,
147  const PackageUri& rURI,
148  ContentProperties& rProps,
149  css::uno::Reference< css::container::XHierarchicalNameAccess > & rxPackage );
150  static bool
151  hasData( ContentProvider* pProvider,
152  const PackageUri& rURI,
153  css::uno::Reference< css::container::XHierarchicalNameAccess > & rxPackage );
154 
155  bool
156  hasData( const PackageUri& rURI );
157  void
158  renameData( const css::uno::Reference< css::ucb::XContentIdentifier >& xOldId,
159  const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId );
160  bool
161  storeData( const css::uno::Reference< css::io::XInputStream >& xStream );
162  bool
163  removeData();
164 
165  bool
166  flushData();
167 
169  typedef std::vector< ContentRef > ContentRefList;
170  void queryChildren( ContentRefList& rChildren );
171 
172  bool
173  exchangeIdentity( const css::uno::Reference<
174  css::ucb::XContentIdentifier >& xNewId );
175 
177  css::uno::Any
178  open( const css::ucb::OpenCommandArgument2& rArg,
179  const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
180 
182  void insert( const css::uno::Reference< css::io::XInputStream >& xStream,
183  sal_Int32 nNameClashResolve,
184  const css::uno::Reference<
185  css::ucb::XCommandEnvironment > & xEnv );
186 
188  void destroy( bool bDeletePhysical,
189  const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
190 
192  void transfer( const css::ucb::TransferInfo& rInfo,
193  const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv );
194 
195  css::uno::Reference< css::io::XInputStream >
196  getInputStream();
197 
198  bool isFolder() const { return m_aProps.bIsFolder; }
199 
200 public:
201  // Create existing content. Fail, if not already exists.
203  const css::uno::Reference< css::uno::XComponentContext >& rxContext,
204  ContentProvider* pProvider,
205  const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier );
206 
207  // Create new content. Fail, if already exists.
209  const css::uno::Reference< css::uno::XComponentContext >& rxContext,
210  ContentProvider* pProvider,
211  const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier,
212  const css::ucb::ContentInfo& Info );
213 
214  virtual ~Content() override;
215 
216  // XInterface
217  virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
218  virtual void SAL_CALL acquire()
219  noexcept override;
220  virtual void SAL_CALL release()
221  noexcept override;
222 
223  // XTypeProvider
224  virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
225  virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
226 
227  // XServiceInfo
228  virtual OUString SAL_CALL
229  getImplementationName() override;
230  virtual css::uno::Sequence< OUString > SAL_CALL
231  getSupportedServiceNames() override;
232 
233  // XContent
234  virtual OUString SAL_CALL
235  getContentType() override;
236 
237  // XCommandProcessor
238  virtual css::uno::Any SAL_CALL
239  execute( const css::ucb::Command& aCommand,
240  sal_Int32 CommandId,
241  const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) override;
242  virtual void SAL_CALL
243  abort( sal_Int32 CommandId ) override;
244 
245 
246  // Additional interfaces
247 
248 
249  // XContentCreator
250  virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL
251  queryCreatableContentsInfo() override;
252  virtual css::uno::Reference< css::ucb::XContent > SAL_CALL
253  createNewContent( const css::ucb::ContentInfo& Info ) override;
254 
255 
256  // Non-interface methods.
257 
258 
259  // Called from resultset data supplier.
260  static css::uno::Reference< css::sdbc::XRow >
261  getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
262  const css::uno::Sequence< css::beans::Property >& rProperties,
263  ContentProvider* pProvider,
264  const OUString& rContentId );
265 
266  // Called from resultset data supplier.
267  css::uno::Reference< css::container::XEnumeration >
268  getIterator();
269 
270  static OUString
271  getContentType( std::u16string_view aScheme, bool bFolder );
272 };
273 
274 }
275 
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
css::uno::Sequence< sal_Int8 > aEncryptionKey
Definition: pkgcontent.hxx:69
exports com.sun.star. sdbc
exports com.sun.star. io
rtl::Reference< Content > ContentRef
Definition: pkgcontent.hxx:168
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
signed char sal_Int8
static css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Sequence< css::beans::Property > &rProperties, const ContentProperties &rData, const rtl::Reference< ::ucbhelper::ContentProviderImplHelper > &rProvider, const OUString &rContentId)
virtual OUString SAL_CALL getContentType() override
Definition: pkgcontent.cxx:373
virtual ~Content() override
Definition: pkgcontent.cxx:269
std::vector< ContentRef > ContentRefList
Definition: pkgcontent.hxx:169
void transfer(const css::ucb::TransferInfo &rInfo, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: pkgcontent.cxx:313
virtual OUString SAL_CALL getImplementationName() override
Definition: pkgcontent.cxx:356
virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL queryCreatableContentsInfo() override
Definition: pkgcontent.cxx:627
ContentState m_eState
Definition: pkgcontent.hxx:100
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL createNewContent(const css::ucb::ContentInfo &Info) override
void destroy(bool bDeletePhysical, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual css::uno::Sequence< css::beans::Property > getProperties(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: pkgcontent.cxx:363
exports com.sun.star. container
void renameData(const css::uno::Reference< css::ucb::XContentIdentifier > &xOldId, const css::uno::Reference< css::ucb::XContentIdentifier > &xNewId)
virtual void SAL_CALL abort(sal_Int32 CommandId) override
Definition: pkgcontent.cxx:615
virtual void SAL_CALL release() noexcept override
Definition: pkgcontent.cxx:286
virtual css::uno::Sequence< css::ucb::CommandInfo > getCommands(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
static bool hasData(ContentProvider *pProvider, const PackageUri &rURI, css::uno::Reference< css::container::XHierarchicalNameAccess > &rxPackage)
static rtl::Reference< Content > create(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
ContentProvider * m_pProvider
Definition: pkgcontent.hxx:103
virtual css::uno::Any SAL_CALL execute(const css::ucb::Command &aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment) override
sal_uInt32 m_nModifiedProps
Definition: pkgcontent.hxx:104
void queryChildren(ContentRefList &rChildren)
static bool loadData(ContentProvider *pProvider, const PackageUri &rURI, ContentProperties &rProps, css::uno::Reference< css::container::XHierarchicalNameAccess > &rxPackage)
css::uno::Reference< css::container::XHierarchicalNameAccess > getPackage()
css::uno::Sequence< css::uno::Any > setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &rValues, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
css::uno::Any open(const css::ucb::OpenCommandArgument2 &rArg, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void insert(const css::uno::Reference< css::io::XInputStream > &xStream, sal_Int32 nNameClashResolve, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
css::uno::Sequence< css::ucb::ContentInfo > getCreatableContentsInfo(PackageUri const &rUri) const
Definition: pkgcontent.cxx:102
css::uno::Reference< css::container::XHierarchicalNameAccess > m_xPackage
Definition: pkgcontent.hxx:102
bool storeData(const css::uno::Reference< css::io::XInputStream > &xStream)
bool exchangeIdentity(const css::uno::Reference< css::ucb::XContentIdentifier > &xNewId)
exports com.sun.star. beans
css::uno::Reference< css::io::XInputStream > getInputStream()
ContentProperties m_aProps
Definition: pkgcontent.hxx:99
virtual void SAL_CALL acquire() noexcept override
Definition: pkgcontent.cxx:278
Content(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier, const css::uno::Reference< css::container::XHierarchicalNameAccess > &Package, const PackageUri &rUri, const ContentProperties &rProps)
friend ContentProvider
Definition: pkgprovider.cxx:53
virtual OUString getParentURL() override
Definition: pkgcontent.cxx:675
bool isFolder() const
Definition: pkgcontent.hxx:198
css::uno::Reference< css::container::XEnumeration > getIterator()