Line data Source code
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 : #ifndef _HIERARCHYCONTENT_HXX
21 : #define _HIERARCHYCONTENT_HXX
22 :
23 : #include <list>
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"
29 :
30 : namespace com { namespace sun { namespace star { namespace beans {
31 : struct Property;
32 : struct PropertyValue;
33 : } } } }
34 :
35 : namespace com { namespace sun { namespace star { namespace sdbc {
36 : class XRow;
37 : } } } }
38 :
39 : namespace com { namespace sun { namespace star { namespace ucb {
40 : struct TransferInfo;
41 : } } } }
42 :
43 : namespace hierarchy_ucp
44 : {
45 :
46 :
47 :
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"
54 :
55 :
56 :
57 0 : class HierarchyContentProperties
58 : {
59 : public:
60 0 : HierarchyContentProperties() {};
61 :
62 0 : HierarchyContentProperties( const HierarchyEntryData::Type & rType )
63 : : m_aData( rType ),
64 0 : m_aContentType( rType == HierarchyEntryData::FOLDER
65 : ? OUString( HIERARCHY_FOLDER_CONTENT_TYPE )
66 0 : : OUString( HIERARCHY_LINK_CONTENT_TYPE ) ) {}
67 :
68 0 : HierarchyContentProperties( const HierarchyEntryData & rData )
69 : : m_aData( rData ),
70 0 : m_aContentType( rData.getType() == HierarchyEntryData::FOLDER
71 : ? OUString( HIERARCHY_FOLDER_CONTENT_TYPE )
72 0 : : OUString( HIERARCHY_LINK_CONTENT_TYPE ) ) {}
73 :
74 0 : const OUString & getName() const { return m_aData.getName(); }
75 0 : void setName( const OUString & rName ) { m_aData.setName( rName ); };
76 :
77 0 : const OUString & getTitle() const { return m_aData.getTitle(); }
78 0 : void setTitle( const OUString & rTitle )
79 0 : { m_aData.setTitle( rTitle ); };
80 :
81 0 : const OUString & getTargetURL() const
82 0 : { return m_aData.getTargetURL(); }
83 0 : void setTargetURL( const OUString & rURL )
84 0 : { m_aData.setTargetURL( rURL ); };
85 :
86 0 : const OUString & getContentType() const { return m_aContentType; }
87 :
88 0 : sal_Bool getIsFolder() const
89 0 : { return m_aData.getType() == HierarchyEntryData::FOLDER; }
90 :
91 0 : sal_Bool getIsDocument() const { return !getIsFolder(); }
92 :
93 : com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo >
94 : getCreatableContentsInfo() const;
95 :
96 0 : const HierarchyEntryData & getHierarchyEntryData() const { return m_aData; }
97 :
98 : private:
99 : HierarchyEntryData m_aData;
100 : OUString m_aContentType;
101 : };
102 :
103 :
104 :
105 : class HierarchyContentProvider;
106 :
107 : class HierarchyContent : public ::ucbhelper::ContentImplHelper,
108 : public com::sun::star::ucb::XContentCreator
109 : {
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"
115 : };
116 :
117 : HierarchyContentProperties m_aProps;
118 : ContentKind m_eKind;
119 : ContentState m_eState;
120 : HierarchyContentProvider* m_pProvider;
121 : bool m_bCheckedReadOnly;
122 : bool m_bIsReadOnly;
123 :
124 : private:
125 : HierarchyContent(
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 );
132 : HierarchyContent(
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 );
139 :
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;
147 :
148 : static sal_Bool hasData(
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 );
154 0 : sal_Bool hasData(
155 : const com::sun::star::uno::Reference<
156 : com::sun::star::ucb::XContentIdentifier >& Identifier )
157 0 : { return hasData( m_xContext, m_pProvider, Identifier ); }
158 : static sal_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 );
165 : sal_Bool storeData();
166 : sal_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 );
170 : sal_Bool removeData();
171 :
172 : void setKind( const com::sun::star::uno::Reference<
173 : com::sun::star::ucb::XContentIdentifier >& Identifier );
174 :
175 : bool isReadOnly();
176 :
177 0 : sal_Bool isFolder() const { return ( m_eKind > LINK ); }
178 :
179 : ::com::sun::star::uno::Reference<
180 : ::com::sun::star::ucb::XContentIdentifier >
181 : makeNewIdentifier( const OUString& rTitle );
182 :
183 : typedef rtl::Reference< HierarchyContent > HierarchyContentRef;
184 : typedef std::list< HierarchyContentRef > HierarchyContentRefList;
185 : void queryChildren( HierarchyContentRefList& rChildren );
186 :
187 : sal_Bool exchangeIdentity(
188 : const ::com::sun::star::uno::Reference<
189 : ::com::sun::star::ucb::XContentIdentifier >& xNewId );
190 :
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 >
195 : setPropertyValues(
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 );
201 :
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 );
206 :
207 : void destroy( sal_Bool bDeletePhysical,
208 : const ::com::sun::star::uno::Reference<
209 : ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
210 : throw( ::com::sun::star::uno::Exception );
211 :
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 );
216 :
217 : public:
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 );
225 :
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 );
234 :
235 : virtual ~HierarchyContent();
236 :
237 : // XInterface
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;
244 :
245 : // XTypeProvider
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;
250 :
251 : // XServiceInfo
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;
258 :
259 : // XContent
260 : virtual OUString SAL_CALL
261 : getContentType()
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
265 : getIdentifier()
266 : throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
267 :
268 : // XCommandProcessor
269 : virtual com::sun::star::uno::Any SAL_CALL
270 : execute( const com::sun::star::ucb::Command& aCommand,
271 : sal_Int32 CommandId,
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;
280 :
281 :
282 : // Additional interfaces
283 :
284 :
285 : // XContentCreator
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;
294 :
295 :
296 : // Non-interface methods.
297 :
298 :
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 );
307 : };
308 :
309 : } // namespace hierarchy_ucp
310 :
311 : #endif /* !_HIERARCHYCONTENT_HXX */
312 :
313 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|