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 .
20 #ifndef INCLUDED_UCB_SOURCE_UCP_HIERARCHY_HIERARCHYCONTENT_HXX
21 #define INCLUDED_UCB_SOURCE_UCP_HIERARCHY_HIERARCHYCONTENT_HXX
24 #include <rtl/ref.hxx>
25 #include <com/sun/star/ucb/XContentCreator.hpp>
26 #include <ucbhelper/contenthelper.hxx>
27 #include "hierarchydata.hxx"
28 #include "hierarchyprovider.hxx"
30 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{
35 namespace com
{ namespace sun
{ namespace star
{ namespace sdbc
{
39 namespace com
{ namespace sun
{ namespace star
{ namespace ucb
{
43 namespace hierarchy_ucp
48 #define HIERARCHY_ROOT_FOLDER_CONTENT_SERVICE_NAME \
49 "com.sun.star.ucb.HierarchyRootFolderContent"
50 #define HIERARCHY_FOLDER_CONTENT_SERVICE_NAME \
51 "com.sun.star.ucb.HierarchyFolderContent"
52 #define HIERARCHY_LINK_CONTENT_SERVICE_NAME \
53 "com.sun.star.ucb.HierarchyLinkContent"
57 class HierarchyContentProperties
60 HierarchyContentProperties() {};
62 HierarchyContentProperties( const HierarchyEntryData::Type
& rType
)
64 m_aContentType( rType
== HierarchyEntryData::FOLDER
65 ? OUString( HIERARCHY_FOLDER_CONTENT_TYPE
)
66 : OUString( HIERARCHY_LINK_CONTENT_TYPE
) ) {}
68 HierarchyContentProperties( const HierarchyEntryData
& rData
)
70 m_aContentType( rData
.getType() == HierarchyEntryData::FOLDER
71 ? OUString( HIERARCHY_FOLDER_CONTENT_TYPE
)
72 : OUString( HIERARCHY_LINK_CONTENT_TYPE
) ) {}
74 const OUString
& getName() const { return m_aData
.getName(); }
75 void setName( const OUString
& rName
) { m_aData
.setName( rName
); };
77 const OUString
& getTitle() const { return m_aData
.getTitle(); }
78 void setTitle( const OUString
& rTitle
)
79 { m_aData
.setTitle( rTitle
); };
81 const OUString
& getTargetURL() const
82 { return m_aData
.getTargetURL(); }
83 void setTargetURL( const OUString
& rURL
)
84 { m_aData
.setTargetURL( rURL
); };
86 const OUString
& getContentType() const { return m_aContentType
; }
88 bool getIsFolder() const
89 { return m_aData
.getType() == HierarchyEntryData::FOLDER
; }
91 bool getIsDocument() const { return !getIsFolder(); }
93 com::sun::star::uno::Sequence
< com::sun::star::ucb::ContentInfo
>
94 getCreatableContentsInfo() const;
96 const HierarchyEntryData
& getHierarchyEntryData() const { return m_aData
; }
99 HierarchyEntryData m_aData
;
100 OUString m_aContentType
;
105 class HierarchyContentProvider
;
107 class HierarchyContent
: public ::ucbhelper::ContentImplHelper
,
108 public com::sun::star::ucb::XContentCreator
110 enum ContentKind
{ LINK
, FOLDER
, ROOT
};
111 enum ContentState
{ TRANSIENT
, // created via CreateNewContent,
112 // but did not process "insert" yet
113 PERSISTENT
, // processed "insert"
114 DEAD
// processed "delete"
117 HierarchyContentProperties m_aProps
;
119 ContentState m_eState
;
120 HierarchyContentProvider
* m_pProvider
;
121 bool m_bCheckedReadOnly
;
126 const com::sun::star::uno::Reference
<
127 com::sun::star::uno::XComponentContext
>& rxContext
,
128 HierarchyContentProvider
* pProvider
,
129 const com::sun::star::uno::Reference
<
130 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
131 const HierarchyContentProperties
& rProps
);
133 const com::sun::star::uno::Reference
<
134 com::sun::star::uno::XComponentContext
>& rxContext
,
135 HierarchyContentProvider
* pProvider
,
136 const com::sun::star::uno::Reference
<
137 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
138 const com::sun::star::ucb::ContentInfo
& Info
);
140 virtual com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>
141 getProperties( const com::sun::star::uno::Reference
<
142 com::sun::star::ucb::XCommandEnvironment
> & xEnv
) SAL_OVERRIDE
;
143 virtual com::sun::star::uno::Sequence
< com::sun::star::ucb::CommandInfo
>
144 getCommands( const com::sun::star::uno::Reference
<
145 com::sun::star::ucb::XCommandEnvironment
> & xEnv
) SAL_OVERRIDE
;
146 virtual OUString
getParentURL() SAL_OVERRIDE
;
149 const com::sun::star::uno::Reference
<
150 com::sun::star::uno::XComponentContext
>& rxContext
,
151 HierarchyContentProvider
* pProvider
,
152 const com::sun::star::uno::Reference
<
153 com::sun::star::ucb::XContentIdentifier
>& Identifier
);
155 const com::sun::star::uno::Reference
<
156 com::sun::star::ucb::XContentIdentifier
>& Identifier
)
157 { return hasData( m_xContext
, m_pProvider
, Identifier
); }
158 static bool loadData(
159 const com::sun::star::uno::Reference
<
160 com::sun::star::uno::XComponentContext
>& rxContext
,
161 HierarchyContentProvider
* pProvider
,
162 const com::sun::star::uno::Reference
<
163 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
164 HierarchyContentProperties
& rProps
);
166 bool renameData( const com::sun::star::uno::Reference
<
167 com::sun::star::ucb::XContentIdentifier
>& xOldId
,
168 const com::sun::star::uno::Reference
<
169 com::sun::star::ucb::XContentIdentifier
>& xNewId
);
172 void setKind( const com::sun::star::uno::Reference
<
173 com::sun::star::ucb::XContentIdentifier
>& Identifier
);
177 bool isFolder() const { return ( m_eKind
> LINK
); }
179 ::com::sun::star::uno::Reference
<
180 ::com::sun::star::ucb::XContentIdentifier
>
181 makeNewIdentifier( const OUString
& rTitle
);
183 typedef rtl::Reference
< HierarchyContent
> HierarchyContentRef
;
184 typedef std::list
< HierarchyContentRef
> HierarchyContentRefList
;
185 void queryChildren( HierarchyContentRefList
& rChildren
);
187 bool exchangeIdentity(
188 const ::com::sun::star::uno::Reference
<
189 ::com::sun::star::ucb::XContentIdentifier
>& xNewId
);
191 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
>
192 getPropertyValues( const ::com::sun::star::uno::Sequence
<
193 ::com::sun::star::beans::Property
>& rProperties
);
194 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>
196 const ::com::sun::star::uno::Sequence
<
197 ::com::sun::star::beans::PropertyValue
>& rValues
,
198 const ::com::sun::star::uno::Reference
<
199 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
200 throw( ::com::sun::star::uno::Exception
);
202 void insert( sal_Int32 nNameClashResolve
,
203 const ::com::sun::star::uno::Reference
<
204 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
205 throw( ::com::sun::star::uno::Exception
);
207 void destroy( bool bDeletePhysical
,
208 const ::com::sun::star::uno::Reference
<
209 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
210 throw( ::com::sun::star::uno::Exception
);
212 void transfer( const ::com::sun::star::ucb::TransferInfo
& rInfo
,
213 const ::com::sun::star::uno::Reference
<
214 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
215 throw( ::com::sun::star::uno::Exception
);
218 // Create existing content. Fail, if not already exists.
219 static HierarchyContent
* create(
220 const com::sun::star::uno::Reference
<
221 com::sun::star::uno::XComponentContext
>& rxContext
,
222 HierarchyContentProvider
* pProvider
,
223 const com::sun::star::uno::Reference
<
224 com::sun::star::ucb::XContentIdentifier
>& Identifier
);
226 // Create new content. Fail, if already exists.
227 static HierarchyContent
* create(
228 const com::sun::star::uno::Reference
<
229 com::sun::star::uno::XComponentContext
>& rxContext
,
230 HierarchyContentProvider
* pProvider
,
231 const com::sun::star::uno::Reference
<
232 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
233 const com::sun::star::ucb::ContentInfo
& Info
);
235 virtual ~HierarchyContent();
238 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
)
239 throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
240 virtual void SAL_CALL
acquire()
241 throw() SAL_OVERRIDE
;
242 virtual void SAL_CALL
release()
243 throw() SAL_OVERRIDE
;
246 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId()
247 throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
248 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes()
249 throw( css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
252 virtual OUString SAL_CALL
253 getImplementationName()
254 throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
255 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
256 getSupportedServiceNames()
257 throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
260 virtual OUString SAL_CALL
262 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
263 virtual com::sun::star::uno::Reference
<
264 com::sun::star::ucb::XContentIdentifier
> SAL_CALL
266 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
269 virtual com::sun::star::uno::Any SAL_CALL
270 execute( const com::sun::star::ucb::Command
& aCommand
,
272 const com::sun::star::uno::Reference
<
273 com::sun::star::ucb::XCommandEnvironment
>& Environment
)
274 throw( com::sun::star::uno::Exception
,
275 com::sun::star::ucb::CommandAbortedException
,
276 com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
277 virtual void SAL_CALL
278 abort( sal_Int32 CommandId
)
279 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
282 // Additional interfaces
286 virtual com::sun::star::uno::Sequence
<
287 com::sun::star::ucb::ContentInfo
> SAL_CALL
288 queryCreatableContentsInfo()
289 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
290 virtual com::sun::star::uno::Reference
<
291 com::sun::star::ucb::XContent
> SAL_CALL
292 createNewContent( const com::sun::star::ucb::ContentInfo
& Info
)
293 throw( com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
296 // Non-interface methods.
299 static ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
>
300 getPropertyValues( const ::com::sun::star::uno::Reference
<
301 ::com::sun::star::uno::XComponentContext
>& rxContext
,
302 const ::com::sun::star::uno::Sequence
<
303 ::com::sun::star::beans::Property
>& rProperties
,
304 const HierarchyContentProperties
& rData
,
305 HierarchyContentProvider
* pProvider
,
306 const OUString
& rContentId
);
309 } // namespace hierarchy_ucp
311 #endif // INCLUDED_UCB_SOURCE_UCP_HIERARCHY_HIERARCHYCONTENT_HXX
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */