| 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 <vector> |
| 23 |
#include <rtl/ref.hxx> |
| 24 |
#include <com/sun/star/ucb/XContentCreator.hpp> |
| 25 |
#include <ucbhelper/contenthelper.hxx> |
| 26 |
#include "hierarchydata.hxx" |
| 27 |
#include "hierarchyprovider.hxx" |
| 28 |
|
| 29 |
namespace com::sun::star::beans { |
| 30 |
struct Property; |
| 31 |
struct PropertyValue; |
| 32 |
} |
| 33 |
|
| 34 |
namespace com::sun::star::sdbc { |
| 35 |
class XRow; |
| 36 |
} |
| 37 |
|
| 38 |
namespace com::sun::star::ucb { |
| 39 |
struct TransferInfo; |
| 40 |
} |
| 41 |
|
| 42 |
namespace hierarchy_ucp |
| 43 |
{ |
| 44 |
|
| 45 |
|
| 46 |
class HierarchyContentProperties |
| 47 |
{ |
| 48 |
public: |
| 49 |
HierarchyContentProperties() {}; |
| 50 |
|
| 51 |
explicit HierarchyContentProperties( const HierarchyEntryData::Type & rType ) |
| 52 |
: m_aData( rType ), |
| 53 |
m_aContentType( rType == HierarchyEntryData::FOLDER |
| 54 |
? HIERARCHY_FOLDER_CONTENT_TYPE |
| 55 |
: HIERARCHY_LINK_CONTENT_TYPE ) {} |
| 56 |
|
| 57 |
explicit HierarchyContentProperties( const HierarchyEntryData & rData ) |
| 58 |
: m_aData( rData ), |
| 59 |
m_aContentType( rData.getType() == HierarchyEntryData::FOLDER |
| 60 |
? HIERARCHY_FOLDER_CONTENT_TYPE |
| 61 |
: HIERARCHY_LINK_CONTENT_TYPE ) {} |
| 62 |
|
| 63 |
const OUString & getName() const { return m_aData.getName(); } |
| 64 |
void setName( const OUString & rName ) { m_aData.setName( rName ); }; |
| 65 |
|
| 66 |
const OUString & getTitle() const { return m_aData.getTitle(); } |
| 67 |
void setTitle( const OUString & rTitle ) |
| 68 |
{ m_aData.setTitle( rTitle ); }; |
| 69 |
|
| 70 |
const OUString & getTargetURL() const |
| 71 |
{ return m_aData.getTargetURL(); } |
| 72 |
void setTargetURL( const OUString & rURL ) |
| 73 |
{ m_aData.setTargetURL( rURL ); }; |
| 74 |
|
| 75 |
const OUString & getContentType() const { return m_aContentType; } |
| 76 |
|
| 77 |
bool getIsFolder() const |
| 78 |
{ return m_aData.getType() == HierarchyEntryData::FOLDER; } |
| 79 |
|
| 80 |
bool getIsDocument() const { return !getIsFolder(); } |
| 81 |
|
| 82 |
css::uno::Sequence< css::ucb::ContentInfo > |
| 83 |
getCreatableContentsInfo() const; |
| 84 |
|
| 85 |
const HierarchyEntryData & getHierarchyEntryData() const { return m_aData; } |
| 86 |
|
| 87 |
private: |
| 88 |
HierarchyEntryData m_aData; |
| 89 |
OUString m_aContentType; |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
class HierarchyContent : public ::ucbhelper::ContentImplHelper, |
| 94 |
public css::ucb::XContentCreator |
| 95 |
{ |
| 96 |
enum ContentKind { LINK, FOLDER, ROOT }; |
| 97 |
enum ContentState { TRANSIENT, // created via CreateNewContent, |
| 98 |
// but did not process "insert" yet |
| 99 |
PERSISTENT, // processed "insert" |
| 100 |
DEAD // processed "delete" |
| 101 |
}; |
| 102 |
|
| 103 |
HierarchyContentProperties m_aProps; |
| 104 |
ContentKind m_eKind; |
| 105 |
ContentState m_eState; |
| 106 |
HierarchyContentProvider* m_pProvider; |
| 107 |
bool m_bCheckedReadOnly; |
| 108 |
bool m_bIsReadOnly; |
| 109 |
|
| 110 |
private: |
| 111 |
HierarchyContent( |
| 112 |
const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 113 |
HierarchyContentProvider* pProvider, |
| 114 |
const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier, |
| 115 |
HierarchyContentProperties aProps ); |
| 116 |
HierarchyContent( |
| 117 |
const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 118 |
HierarchyContentProvider* pProvider, |
| 119 |
const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier, |
| 120 |
const css::ucb::ContentInfo& Info ); |
| 121 |
|
| 122 |
virtual css::uno::Sequence< css::beans::Property > |
| 123 |
getProperties( const css::uno::Reference<css::ucb::XCommandEnvironment > & xEnv ) override; |
| 124 |
virtual css::uno::Sequence< css::ucb::CommandInfo > |
| 125 |
getCommands( const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ) override; |
| 126 |
virtual OUString getParentURL() override; |
| 127 |
|
| 128 |
static bool hasData( |
| 129 |
const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 130 |
HierarchyContentProvider* pProvider, |
| 131 |
const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier ); |
| 132 |
bool hasData( |
| 133 |
const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier ) |
| 134 |
{ return hasData( m_xContext, m_pProvider, Identifier ); } |
| 135 |
static bool loadData( |
| 136 |
const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 137 |
HierarchyContentProvider* pProvider, |
| 138 |
const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier, |
| 139 |
HierarchyContentProperties& rProps ); |
| 140 |
bool storeData(); |
| 141 |
void renameData( const css::uno::Reference< css::ucb::XContentIdentifier >& xOldId, |
| 142 |
const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId ); |
| 143 |
bool removeData(); |
| 144 |
|
| 145 |
void setKind( const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier ); |
| 146 |
|
| 147 |
bool isReadOnly(); |
| 148 |
|
| 149 |
bool isFolder() const { return ( m_eKind > LINK ); } |
| 150 |
|
| 151 |
css::uno::Reference< css::ucb::XContentIdentifier > |
| 152 |
makeNewIdentifier( const OUString& rTitle ); |
| 153 |
|
| 154 |
typedef rtl::Reference< HierarchyContent > HierarchyContentRef; |
| 155 |
typedef std::vector< HierarchyContentRef > HierarchyContentRefVector; |
| 156 |
void queryChildren( HierarchyContentRefVector& rChildren ); |
| 157 |
|
| 158 |
bool exchangeIdentity( |
| 159 |
const css::uno::Reference< css::ucb::XContentIdentifier >& xNewId ); |
| 160 |
|
| 161 |
css::uno::Reference< css::sdbc::XRow > |
| 162 |
getPropertyValues( const css::uno::Sequence< css::beans::Property >& rProperties ); |
| 163 |
/// @throws css::uno::Exception |
| 164 |
css::uno::Sequence< css::uno::Any > |
| 165 |
setPropertyValues( |
| 166 |
const css::uno::Sequence< css::beans::PropertyValue >& rValues, |
| 167 |
const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ); |
| 168 |
|
| 169 |
/// @throws css::uno::Exception |
| 170 |
void insert( sal_Int32 nNameClashResolve, |
| 171 |
const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ); |
| 172 |
|
| 173 |
/// @throws css::uno::Exception |
| 174 |
void destroy( bool bDeletePhysical, |
| 175 |
const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ); |
| 176 |
|
| 177 |
/// @throws css::uno::Exception |
| 178 |
void transfer( const css::ucb::TransferInfo& rInfo, |
| 179 |
const css::uno::Reference< css::ucb::XCommandEnvironment > & xEnv ); |
| 180 |
|
| 181 |
public: |
| 182 |
// Create existing content. Fail, if not already exists. |
| 183 |
static rtl::Reference<HierarchyContent> create( |
| 184 |
const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 185 |
HierarchyContentProvider* pProvider, |
| 186 |
const css::uno::Reference< |
| 187 |
css::ucb::XContentIdentifier >& Identifier ); |
| 188 |
|
| 189 |
// Create new content. Fail, if already exists. |
| 190 |
static rtl::Reference<HierarchyContent> create( |
| 191 |
const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 192 |
HierarchyContentProvider* pProvider, |
| 193 |
const css::uno::Reference< css::ucb::XContentIdentifier >& Identifier, |
| 194 |
const css::ucb::ContentInfo& Info ); |
| 195 |
|
| 196 |
virtual ~HierarchyContent() override; |
| 197 |
|
| 198 |
// XInterface |
| 199 |
virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; |
| 200 |
virtual void SAL_CALL acquire() |
| 201 |
noexcept override; |
| 202 |
virtual void SAL_CALL release() |
| 203 |
noexcept override; |
| 204 |
|
| 205 |
// XTypeProvider |
| 206 |
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override; |
| 207 |
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override; |
| 208 |
|
| 209 |
// XServiceInfo |
| 210 |
virtual OUString SAL_CALL |
| 211 |
getImplementationName() override; |
| 212 |
virtual css::uno::Sequence< OUString > SAL_CALL |
| 213 |
getSupportedServiceNames() override; |
| 214 |
|
| 215 |
// XContent |
| 216 |
virtual OUString SAL_CALL |
| 217 |
getContentType() override; |
| 218 |
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL |
| 219 |
getIdentifier() override; |
| 220 |
|
| 221 |
// XCommandProcessor |
| 222 |
virtual css::uno::Any SAL_CALL |
| 223 |
execute( const css::ucb::Command& aCommand, |
| 224 |
sal_Int32 CommandId, |
| 225 |
const css::uno::Reference< css::ucb::XCommandEnvironment >& Environment ) override; |
| 226 |
virtual void SAL_CALL |
| 227 |
abort( sal_Int32 CommandId ) override; |
| 228 |
|
| 229 |
|
| 230 |
// Additional interfaces |
| 231 |
|
| 232 |
|
| 233 |
// XContentCreator |
| 234 |
virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL |
| 235 |
queryCreatableContentsInfo() override; |
| 236 |
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL |
| 237 |
createNewContent( const css::ucb::ContentInfo& Info ) override; |
| 238 |
|
| 239 |
|
| 240 |
// Non-interface methods. |
| 241 |
|
| 242 |
|
| 243 |
static css::uno::Reference< css::sdbc::XRow > |
| 244 |
getPropertyValues( const css::uno::Reference< css::uno::XComponentContext >& rxContext, |
| 245 |
const css::uno::Sequence< css::beans::Property >& rProperties, |
| 246 |
const HierarchyContentProperties& rData, |
| 247 |
HierarchyContentProvider* pProvider, |
| 248 |
const OUString& rContentId ); |
| 249 |
}; |
| 250 |
|
| 251 |
} // namespace hierarchy_ucp |
| 252 |
|
| 253 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |