| 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 |
|
| 26 |
#include <ucbhelper/contenthelper.hxx> |
| 27 |
#include <com/sun/star/ucb/XContentCreator.hpp> |
| 28 |
#include <utility> |
| 29 |
#include "tdoc_provider.hxx" |
| 30 |
|
| 31 |
namespace com::sun::star { |
| 32 |
namespace sdbc { class XRow; } |
| 33 |
namespace io { class XInputStream; class XOutputStream; } |
| 34 |
namespace beans { struct PropertyValue; } |
| 35 |
namespace ucb { struct OpenCommandArgument2; struct TransferInfo; |
| 36 |
struct ContentInfo; } |
| 37 |
} |
| 38 |
|
| 39 |
namespace tdoc_ucp |
| 40 |
{ |
| 41 |
|
| 42 |
|
| 43 |
enum ContentType { STREAM, FOLDER, DOCUMENT, ROOT }; |
| 44 |
|
| 45 |
class ContentProperties |
| 46 |
{ |
| 47 |
public: |
| 48 |
ContentProperties() |
| 49 |
: m_eType( STREAM ) |
| 50 |
{} |
| 51 |
|
| 52 |
ContentProperties( const ContentType & rType, OUString aTitle ) |
| 53 |
: m_eType( rType ), |
| 54 |
m_aContentType( rType == STREAM |
| 55 |
? TDOC_STREAM_CONTENT_TYPE |
| 56 |
: rType == FOLDER |
| 57 |
? TDOC_FOLDER_CONTENT_TYPE |
| 58 |
: rType == DOCUMENT |
| 59 |
? TDOC_DOCUMENT_CONTENT_TYPE |
| 60 |
: TDOC_ROOT_CONTENT_TYPE ), |
| 61 |
m_aTitle(std::move( aTitle )) |
| 62 |
{} |
| 63 |
|
| 64 |
ContentType getType() const { return m_eType; } |
| 65 |
|
| 66 |
// Properties |
| 67 |
|
| 68 |
const OUString & getContentType() const { return m_aContentType; } |
| 69 |
|
| 70 |
bool getIsFolder() const { return m_eType > STREAM; } |
| 71 |
bool getIsDocument() const { return !getIsFolder(); } |
| 72 |
|
| 73 |
const OUString & getTitle() const { return m_aTitle; } |
| 74 |
void setTitle( const OUString & rTitle ) { m_aTitle = rTitle; } |
| 75 |
|
| 76 |
css::uno::Sequence< css::ucb::ContentInfo > |
| 77 |
getCreatableContentsInfo() const; |
| 78 |
|
| 79 |
bool isContentCreator() const; |
| 80 |
|
| 81 |
private: |
| 82 |
ContentType m_eType; |
| 83 |
OUString m_aContentType; |
| 84 |
OUString m_aTitle; |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
class Content : public ::ucbhelper::ContentImplHelper, |
| 89 |
public css::ucb::XContentCreator |
| 90 |
{ |
| 91 |
enum ContentState { TRANSIENT, // created via createNewContent, |
| 92 |
// but did not process "insert" yet |
| 93 |
PERSISTENT, // processed "insert" |
| 94 |
DEAD // processed "delete" / document was closed |
| 95 |
}; |
| 96 |
|
| 97 |
ContentProperties m_aProps; |
| 98 |
ContentState m_eState; |
| 99 |
ContentProvider* m_pProvider; |
| 100 |
|
| 101 |
private: |
| 102 |
Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 103 |
ContentProvider* pProvider, |
| 104 |
const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier, |
| 105 |
ContentProperties aProps ); |
| 106 |
Content( const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 107 |
ContentProvider* pProvider, |
| 108 |
const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier, |
| 109 |
const css::ucb::ContentInfo& Info ); |
| 110 |
|
| 111 |
virtual css::uno::Sequence< css::beans::Property > |
| 112 |
getProperties( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override; |
| 113 |
virtual css::uno::Sequence< css::ucb::CommandInfo > |
| 114 |
getCommands( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override; |
| 115 |
virtual OUString getParentURL() override; |
| 116 |
|
| 117 |
static bool hasData( ContentProvider const * pProvider, const Uri & rUri ); |
| 118 |
bool hasData( const Uri & rUri ) const { return hasData( m_pProvider, rUri ); } |
| 119 |
|
| 120 |
static bool loadData( ContentProvider const * pProvider, |
| 121 |
const Uri & rUri, |
| 122 |
ContentProperties& rProps ); |
| 123 |
/// @throws css::ucb::CommandFailedException |
| 124 |
/// @throws css::task::DocumentPasswordRequest |
| 125 |
/// @throws css::uno::RuntimeException |
| 126 |
bool storeData( const css::uno::Reference< css::io::XInputStream >& xData, |
| 127 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv ); |
| 128 |
void renameData( const css::uno::Reference< css::ucb::XContentIdentifier >& xOldId, |
| 129 |
const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId ); |
| 130 |
bool removeData(); |
| 131 |
|
| 132 |
bool copyData( const Uri & rSourceUri, const OUString & rNewName ); |
| 133 |
|
| 134 |
css::uno::Reference< css::ucb::XContentIdentifier > |
| 135 |
makeNewIdentifier( const OUString& rTitle ); |
| 136 |
|
| 137 |
typedef rtl::Reference< Content > ContentRef; |
| 138 |
typedef std::vector< ContentRef > ContentRefList; |
| 139 |
void queryChildren( ContentRefList& rChildren ); |
| 140 |
|
| 141 |
bool exchangeIdentity( |
| 142 |
const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId ); |
| 143 |
|
| 144 |
css::uno::Reference< css::sdbc::XRow > |
| 145 |
getPropertyValues( const css::uno::Sequence< css::beans::Property >& rProperties ); |
| 146 |
css::uno::Sequence< css::uno::Any > |
| 147 |
/// @throws css::uno::Exception |
| 148 |
setPropertyValues( |
| 149 |
const css::uno::Sequence< css::beans::PropertyValue >& rValues, |
| 150 |
const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ); |
| 151 |
|
| 152 |
/// @throws css::uno::Exception |
| 153 |
css::uno::Any |
| 154 |
open( const css::ucb::OpenCommandArgument2& rArg, |
| 155 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& xEnv ); |
| 156 |
|
| 157 |
/// @throws css::uno::Exception |
| 158 |
void insert( const css::uno::Reference< css::io::XInputStream >& xData, |
| 159 |
sal_Int32 nNameClashResolve, |
| 160 |
const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ); |
| 161 |
|
| 162 |
/// @throws css::uno::Exception |
| 163 |
void destroy( bool bDeletePhysical, |
| 164 |
const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ); |
| 165 |
|
| 166 |
/// @throws css::uno::Exception |
| 167 |
void transfer( const css::ucb::TransferInfo& rInfo, |
| 168 |
const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ); |
| 169 |
|
| 170 |
static css::uno::Reference< css::sdbc::XRow > |
| 171 |
getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 172 |
const css::uno::Sequence< css::beans::Property >& rProperties, |
| 173 |
const ContentProperties& rData, |
| 174 |
ContentProvider* pProvider, |
| 175 |
const OUString& rContentId ); |
| 176 |
|
| 177 |
|
| 178 |
static bool commitStorage( |
| 179 |
const css::uno::Reference< css::embed::XStorage > & xStorage ); |
| 180 |
|
| 181 |
static bool closeOutputStream( |
| 182 |
const css::uno::Reference< css::io::XOutputStream > & xOut ); |
| 183 |
|
| 184 |
/// @throws css::ucb::CommandFailedException |
| 185 |
/// @throws css::task::DocumentPasswordRequest |
| 186 |
/// @throws css::uno::RuntimeException |
| 187 |
css::uno::Reference< css::io::XInputStream > |
| 188 |
getInputStream( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ); |
| 189 |
|
| 190 |
/// @throws css::ucb::CommandFailedException |
| 191 |
/// @throws css::task::DocumentPasswordRequest |
| 192 |
/// @throws css::uno::RuntimeException |
| 193 |
css::uno::Reference< css::io::XOutputStream > |
| 194 |
getTruncatedOutputStream( |
| 195 |
const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ); |
| 196 |
|
| 197 |
css::uno::Reference< css::ucb::XContent > |
| 198 |
queryChildContent( std::u16string_view rRelativeChildUri ); |
| 199 |
|
| 200 |
/// @throws css::ucb::CommandFailedException |
| 201 |
/// @throws css::task::DocumentPasswordRequest |
| 202 |
/// @throws css::uno::RuntimeException |
| 203 |
css::uno::Reference< css::io::XStream > |
| 204 |
getStream( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ); |
| 205 |
|
| 206 |
public: |
| 207 |
// Create existing content. Fail, if not 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 |
|
| 213 |
// Create new content. Fail, if already exists. |
| 214 |
static rtl::Reference<Content> create( |
| 215 |
const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 216 |
ContentProvider* pProvider, |
| 217 |
const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier, |
| 218 |
const css::ucb::ContentInfo& Info ); |
| 219 |
|
| 220 |
virtual ~Content() override; |
| 221 |
|
| 222 |
// XInterface |
| 223 |
virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; |
| 224 |
virtual void SAL_CALL acquire() |
| 225 |
noexcept override; |
| 226 |
virtual void SAL_CALL release() |
| 227 |
noexcept override; |
| 228 |
|
| 229 |
// XTypeProvider |
| 230 |
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override; |
| 231 |
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override; |
| 232 |
|
| 233 |
// XServiceInfo |
| 234 |
virtual OUString SAL_CALL |
| 235 |
getImplementationName() override; |
| 236 |
virtual css::uno::Sequence< OUString > SAL_CALL |
| 237 |
getSupportedServiceNames() override; |
| 238 |
|
| 239 |
// XContent |
| 240 |
virtual OUString SAL_CALL |
| 241 |
getContentType() override; |
| 242 |
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL |
| 243 |
getIdentifier() override; |
| 244 |
|
| 245 |
// XCommandProcessor |
| 246 |
virtual css::uno::Any SAL_CALL |
| 247 |
execute( const css::ucb::Command& aCommand, |
| 248 |
sal_Int32 CommandId, |
| 249 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) override; |
| 250 |
virtual void SAL_CALL |
| 251 |
abort( sal_Int32 CommandId ) override; |
| 252 |
|
| 253 |
|
| 254 |
// Additional interfaces |
| 255 |
|
| 256 |
|
| 257 |
// XContentCreator |
| 258 |
virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL |
| 259 |
queryCreatableContentsInfo() override; |
| 260 |
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL |
| 261 |
createNewContent( const css::ucb::ContentInfo& Info ) override; |
| 262 |
|
| 263 |
|
| 264 |
// Non-interface methods. |
| 265 |
|
| 266 |
|
| 267 |
static css::uno::Reference< css::sdbc::XRow > |
| 268 |
getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 269 |
const css::uno::Sequence< css::beans::Property >& rProperties, |
| 270 |
ContentProvider* pProvider, |
| 271 |
const OUString& rContentId ); |
| 272 |
|
| 273 |
void notifyDocumentClosed(); |
| 274 |
void notifyChildRemoved( std::u16string_view rRelativeChildUri ); |
| 275 |
void notifyChildInserted( std::u16string_view rRelativeChildUri ); |
| 276 |
|
| 277 |
rtl::Reference< ContentProvider > getContentProvider() const |
| 278 |
{ return rtl::Reference< ContentProvider >( m_pProvider ); } |
| 279 |
}; |
| 280 |
|
| 281 |
} // namespace tdoc_ucp |
| 282 |
|
| 283 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |