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 .
22 #include <sal/config.h>
24 #include <string_view>
26 #include <rtl/ref.hxx>
28 #include <com/sun/star/ucb/XContentCreator.hpp>
29 #include <ucbhelper/contenthelper.hxx>
32 namespace com::sun::star
{
40 class XHierarchicalNameAccess
;
53 struct OpenCommandArgument2
;
62 struct ContentProperties
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
76 : bIsDocument( true ), bIsFolder( false ), nSize( 0 ),
77 bCompressed( true ), bEncrypted( false ),
78 bHasEncryptedEntries( false ) {}
80 explicit ContentProperties( const OUString
& rContentType
);
82 css::uno::Sequence
< css::ucb::ContentInfo
>
83 getCreatableContentsInfo( PackageUri
const & rUri
) const;
87 class ContentProvider
;
89 class Content
: public ::ucbhelper::ContentImplHelper
,
90 public css::ucb::XContentCreator
92 enum ContentState
{ TRANSIENT
, // created via CreateNewContent,
93 // but did not process "insert" yet
94 PERSISTENT
, // processed "insert"
95 DEAD
// processed "delete"
99 ContentProperties m_aProps
;
100 ContentState m_eState
;
102 css::container::XHierarchicalNameAccess
> m_xPackage
;
103 ContentProvider
* m_pProvider
;
104 sal_uInt32 m_nModifiedProps
;
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
);
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
;
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
,
130 const rtl::Reference
< ::ucbhelper::ContentProviderImplHelper
>& rProvider
,
131 const OUString
& rContentId
);
133 css::uno::Reference
< css::sdbc::XRow
>
134 getPropertyValues( const css::uno::Sequence
< css::beans::Property
>& rProperties
);
135 /// @throws css::uno::Exception
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
);
140 css::uno::Reference
< css::container::XHierarchicalNameAccess
>
141 getPackage( const PackageUri
& rURI
);
142 css::uno::Reference
< css::container::XHierarchicalNameAccess
>
146 loadData( ContentProvider
* pProvider
,
147 const PackageUri
& rURI
,
148 ContentProperties
& rProps
,
149 css::uno::Reference
< css::container::XHierarchicalNameAccess
> & rxPackage
);
151 hasData( ContentProvider
* pProvider
,
152 const PackageUri
& rURI
,
153 css::uno::Reference
< css::container::XHierarchicalNameAccess
> & rxPackage
);
156 hasData( const PackageUri
& rURI
);
158 renameData( const css::uno::Reference
< css::ucb::XContentIdentifier
>& xOldId
,
159 const css::uno::Reference
< css::ucb::XContentIdentifier
>& xNewId
);
161 storeData( const css::uno::Reference
< css::io::XInputStream
>& xStream
);
168 typedef rtl::Reference
< Content
> ContentRef
;
169 typedef std::vector
< ContentRef
> ContentRefList
;
170 void queryChildren( ContentRefList
& rChildren
);
173 exchangeIdentity( const css::uno::Reference
<
174 css::ucb::XContentIdentifier
>& xNewId
);
176 /// @throws css::uno::Exception
178 open( const css::ucb::OpenCommandArgument2
& rArg
,
179 const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
);
181 /// @throws css::uno::Exception
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
);
187 /// @throws css::uno::Exception
188 void destroy( bool bDeletePhysical
,
189 const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
);
191 /// @throws css::uno::Exception
192 void transfer( const css::ucb::TransferInfo
& rInfo
,
193 const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
);
195 css::uno::Reference
< css::io::XInputStream
>
198 bool isFolder() const { return m_aProps
.bIsFolder
; }
201 // Create existing content. Fail, if not already exists.
202 static rtl::Reference
<Content
> create(
203 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
204 ContentProvider
* pProvider
,
205 const css::uno::Reference
< css::ucb::XContentIdentifier
>& Identifier
);
207 // Create new content. Fail, if already exists.
208 static rtl::Reference
<Content
> create(
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
);
214 virtual ~Content() override
;
217 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
218 virtual void SAL_CALL
acquire()
220 virtual void SAL_CALL
release()
224 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
225 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() override
;
228 virtual OUString SAL_CALL
229 getImplementationName() override
;
230 virtual css::uno::Sequence
< OUString
> SAL_CALL
231 getSupportedServiceNames() override
;
234 virtual OUString SAL_CALL
235 getContentType() override
;
238 virtual css::uno::Any SAL_CALL
239 execute( const css::ucb::Command
& aCommand
,
241 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& Environment
) override
;
242 virtual void SAL_CALL
243 abort( sal_Int32 CommandId
) override
;
246 // Additional interfaces
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
;
256 // Non-interface methods.
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
);
266 // Called from resultset data supplier.
267 css::uno::Reference
< css::container::XEnumeration
>
271 getContentType( std::u16string_view aScheme
, bool bFolder
);
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */