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 .
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"
29 namespace com::sun::star::beans
{
34 namespace com::sun::star::sdbc
{
38 namespace com::sun::star::ucb
{
42 namespace hierarchy_ucp
46 class HierarchyContentProperties
49 HierarchyContentProperties() {};
51 explicit HierarchyContentProperties( const HierarchyEntryData::Type
& rType
)
53 m_aContentType( rType
== HierarchyEntryData::FOLDER
54 ? OUString( HIERARCHY_FOLDER_CONTENT_TYPE
)
55 : OUString( HIERARCHY_LINK_CONTENT_TYPE
) ) {}
57 explicit HierarchyContentProperties( const HierarchyEntryData
& rData
)
59 m_aContentType( rData
.getType() == HierarchyEntryData::FOLDER
60 ? OUString( HIERARCHY_FOLDER_CONTENT_TYPE
)
61 : OUString( HIERARCHY_LINK_CONTENT_TYPE
) ) {}
63 const OUString
& getName() const { return m_aData
.getName(); }
64 void setName( const OUString
& rName
) { m_aData
.setName( rName
); };
66 const OUString
& getTitle() const { return m_aData
.getTitle(); }
67 void setTitle( const OUString
& rTitle
)
68 { m_aData
.setTitle( rTitle
); };
70 const OUString
& getTargetURL() const
71 { return m_aData
.getTargetURL(); }
72 void setTargetURL( const OUString
& rURL
)
73 { m_aData
.setTargetURL( rURL
); };
75 const OUString
& getContentType() const { return m_aContentType
; }
77 bool getIsFolder() const
78 { return m_aData
.getType() == HierarchyEntryData::FOLDER
; }
80 bool getIsDocument() const { return !getIsFolder(); }
82 css::uno::Sequence
< css::ucb::ContentInfo
>
83 getCreatableContentsInfo() const;
85 const HierarchyEntryData
& getHierarchyEntryData() const { return m_aData
; }
88 HierarchyEntryData m_aData
;
89 OUString m_aContentType
;
93 class HierarchyContentProvider
;
95 class HierarchyContent
: public ::ucbhelper::ContentImplHelper
,
96 public css::ucb::XContentCreator
98 enum ContentKind
{ LINK
, FOLDER
, ROOT
};
99 enum ContentState
{ TRANSIENT
, // created via CreateNewContent,
100 // but did not process "insert" yet
101 PERSISTENT
, // processed "insert"
102 DEAD
// processed "delete"
105 HierarchyContentProperties m_aProps
;
107 ContentState m_eState
;
108 HierarchyContentProvider
* m_pProvider
;
109 bool m_bCheckedReadOnly
;
114 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
115 HierarchyContentProvider
* pProvider
,
116 const css::uno::Reference
< css::ucb::XContentIdentifier
>& Identifier
,
117 const HierarchyContentProperties
& rProps
);
119 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
120 HierarchyContentProvider
* pProvider
,
121 const css::uno::Reference
< css::ucb::XContentIdentifier
>& Identifier
,
122 const css::ucb::ContentInfo
& Info
);
124 virtual css::uno::Sequence
< css::beans::Property
>
125 getProperties( const css::uno::Reference
<css::ucb::XCommandEnvironment
> & xEnv
) override
;
126 virtual css::uno::Sequence
< css::ucb::CommandInfo
>
127 getCommands( const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
) override
;
128 virtual OUString
getParentURL() override
;
131 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
132 HierarchyContentProvider
* pProvider
,
133 const css::uno::Reference
< css::ucb::XContentIdentifier
>& Identifier
);
135 const css::uno::Reference
< css::ucb::XContentIdentifier
>& Identifier
)
136 { return hasData( m_xContext
, m_pProvider
, Identifier
); }
137 static bool loadData(
138 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
139 HierarchyContentProvider
* pProvider
,
140 const css::uno::Reference
< css::ucb::XContentIdentifier
>& Identifier
,
141 HierarchyContentProperties
& rProps
);
143 void renameData( const css::uno::Reference
< css::ucb::XContentIdentifier
>& xOldId
,
144 const css::uno::Reference
< css::ucb::XContentIdentifier
>& xNewId
);
147 void setKind( const css::uno::Reference
< css::ucb::XContentIdentifier
>& Identifier
);
151 bool isFolder() const { return ( m_eKind
> LINK
); }
153 css::uno::Reference
< css::ucb::XContentIdentifier
>
154 makeNewIdentifier( const OUString
& rTitle
);
156 typedef rtl::Reference
< HierarchyContent
> HierarchyContentRef
;
157 typedef std::vector
< HierarchyContentRef
> HierarchyContentRefVector
;
158 void queryChildren( HierarchyContentRefVector
& rChildren
);
160 bool exchangeIdentity(
161 const css::uno::Reference
< css::ucb::XContentIdentifier
>& xNewId
);
163 css::uno::Reference
< css::sdbc::XRow
>
164 getPropertyValues( const css::uno::Sequence
< css::beans::Property
>& rProperties
);
165 /// @throws css::uno::Exception
166 css::uno::Sequence
< css::uno::Any
>
168 const css::uno::Sequence
< css::beans::PropertyValue
>& rValues
,
169 const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
);
171 /// @throws css::uno::Exception
172 void insert( sal_Int32 nNameClashResolve
,
173 const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
);
175 /// @throws css::uno::Exception
176 void destroy( bool bDeletePhysical
,
177 const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
);
179 /// @throws css::uno::Exception
180 void transfer( const css::ucb::TransferInfo
& rInfo
,
181 const css::uno::Reference
< css::ucb::XCommandEnvironment
> & xEnv
);
184 // Create existing content. Fail, if not already exists.
185 static rtl::Reference
<HierarchyContent
> create(
186 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
187 HierarchyContentProvider
* pProvider
,
188 const css::uno::Reference
<
189 css::ucb::XContentIdentifier
>& Identifier
);
191 // Create new content. Fail, if already exists.
192 static rtl::Reference
<HierarchyContent
> create(
193 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
194 HierarchyContentProvider
* pProvider
,
195 const css::uno::Reference
< css::ucb::XContentIdentifier
>& Identifier
,
196 const css::ucb::ContentInfo
& Info
);
198 virtual ~HierarchyContent() override
;
201 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
202 virtual void SAL_CALL
acquire()
204 virtual void SAL_CALL
release()
208 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
209 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() override
;
212 virtual OUString SAL_CALL
213 getImplementationName() override
;
214 virtual css::uno::Sequence
< OUString
> SAL_CALL
215 getSupportedServiceNames() override
;
218 virtual OUString SAL_CALL
219 getContentType() override
;
220 virtual css::uno::Reference
< css::ucb::XContentIdentifier
> SAL_CALL
221 getIdentifier() override
;
224 virtual css::uno::Any SAL_CALL
225 execute( const css::ucb::Command
& aCommand
,
227 const css::uno::Reference
< css::ucb::XCommandEnvironment
>& Environment
) override
;
228 virtual void SAL_CALL
229 abort( sal_Int32 CommandId
) override
;
232 // Additional interfaces
236 virtual css::uno::Sequence
< css::ucb::ContentInfo
> SAL_CALL
237 queryCreatableContentsInfo() override
;
238 virtual css::uno::Reference
< css::ucb::XContent
> SAL_CALL
239 createNewContent( const css::ucb::ContentInfo
& Info
) override
;
242 // Non-interface methods.
245 static css::uno::Reference
< css::sdbc::XRow
>
246 getPropertyValues( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
247 const css::uno::Sequence
< css::beans::Property
>& rProperties
,
248 const HierarchyContentProperties
& rData
,
249 HierarchyContentProvider
* pProvider
,
250 const OUString
& rContentId
);
253 } // namespace hierarchy_ucp
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */