1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hierarchycontent.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _HIERARCHYCONTENT_HXX
32 #define _HIERARCHYCONTENT_HXX
35 #include <rtl/ref.hxx>
36 #include <com/sun/star/ucb/XContentCreator.hpp>
37 #include <ucbhelper/contenthelper.hxx>
38 #include "hierarchydata.hxx"
39 #include "hierarchyprovider.hxx"
41 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{
46 namespace com
{ namespace sun
{ namespace star
{ namespace sdbc
{
50 namespace com
{ namespace sun
{ namespace star
{ namespace ucb
{
54 namespace hierarchy_ucp
57 //=========================================================================
59 #define HIERARCHY_ROOT_FOLDER_CONTENT_SERVICE_NAME \
60 "com.sun.star.ucb.HierarchyRootFolderContent"
61 #define HIERARCHY_FOLDER_CONTENT_SERVICE_NAME \
62 "com.sun.star.ucb.HierarchyFolderContent"
63 #define HIERARCHY_LINK_CONTENT_SERVICE_NAME \
64 "com.sun.star.ucb.HierarchyLinkContent"
66 //=========================================================================
68 class HierarchyContentProperties
71 HierarchyContentProperties() {};
73 HierarchyContentProperties( const HierarchyEntryData::Type
& rType
)
75 m_aContentType( rType
== HierarchyEntryData::FOLDER
76 ? rtl::OUString::createFromAscii( HIERARCHY_FOLDER_CONTENT_TYPE
)
77 : rtl::OUString::createFromAscii( HIERARCHY_LINK_CONTENT_TYPE
) ) {}
79 HierarchyContentProperties( const HierarchyEntryData
& rData
)
81 m_aContentType( rData
.getType() == HierarchyEntryData::FOLDER
82 ? rtl::OUString::createFromAscii( HIERARCHY_FOLDER_CONTENT_TYPE
)
83 : rtl::OUString::createFromAscii( HIERARCHY_LINK_CONTENT_TYPE
) ) {}
85 const rtl::OUString
& getName() const { return m_aData
.getName(); }
86 void setName( const rtl::OUString
& rName
) { m_aData
.setName( rName
); };
88 const rtl::OUString
& getTitle() const { return m_aData
.getTitle(); }
89 void setTitle( const rtl::OUString
& rTitle
)
90 { m_aData
.setTitle( rTitle
); };
92 const rtl::OUString
& getTargetURL() const
93 { return m_aData
.getTargetURL(); }
94 void setTargetURL( const rtl::OUString
& rURL
)
95 { m_aData
.setTargetURL( rURL
); };
97 const rtl::OUString
& getContentType() const { return m_aContentType
; }
99 sal_Bool
getIsFolder() const
100 { return m_aData
.getType() == HierarchyEntryData::FOLDER
; }
102 sal_Bool
getIsDocument() const { return !getIsFolder(); }
104 const HierarchyEntryData
& getHierarchyEntryData() const { return m_aData
; }
107 HierarchyEntryData m_aData
;
108 rtl::OUString m_aContentType
;
111 //=========================================================================
113 class HierarchyContentProvider
;
115 class HierarchyContent
: public ::ucbhelper::ContentImplHelper
,
116 public com::sun::star::ucb::XContentCreator
118 enum ContentKind
{ LINK
, FOLDER
, ROOT
};
119 enum ContentState
{ TRANSIENT
, // created via CreateNewContent,
120 // but did not process "insert" yet
121 PERSISTENT
, // processed "insert"
122 DEAD
// processed "delete"
125 HierarchyContentProperties m_aProps
;
127 ContentState m_eState
;
128 HierarchyContentProvider
* m_pProvider
;
129 bool m_bCheckedReadOnly
;
134 const com::sun::star::uno::Reference
<
135 com::sun::star::lang::XMultiServiceFactory
>& rxSMgr
,
136 HierarchyContentProvider
* pProvider
,
137 const com::sun::star::uno::Reference
<
138 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
139 const HierarchyContentProperties
& rProps
);
141 const com::sun::star::uno::Reference
<
142 com::sun::star::lang::XMultiServiceFactory
>& rxSMgr
,
143 HierarchyContentProvider
* pProvider
,
144 const com::sun::star::uno::Reference
<
145 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
146 const com::sun::star::ucb::ContentInfo
& Info
);
148 virtual com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>
149 getProperties( const com::sun::star::uno::Reference
<
150 com::sun::star::ucb::XCommandEnvironment
> & xEnv
);
151 virtual com::sun::star::uno::Sequence
< com::sun::star::ucb::CommandInfo
>
152 getCommands( const com::sun::star::uno::Reference
<
153 com::sun::star::ucb::XCommandEnvironment
> & xEnv
);
154 virtual ::rtl::OUString
getParentURL();
156 static sal_Bool
hasData(
157 const com::sun::star::uno::Reference
<
158 com::sun::star::lang::XMultiServiceFactory
>& rxSMgr
,
159 HierarchyContentProvider
* pProvider
,
160 const com::sun::star::uno::Reference
<
161 com::sun::star::ucb::XContentIdentifier
>& Identifier
);
163 const com::sun::star::uno::Reference
<
164 com::sun::star::ucb::XContentIdentifier
>& Identifier
)
165 { return hasData( m_xSMgr
, m_pProvider
, Identifier
); }
166 static sal_Bool
loadData(
167 const com::sun::star::uno::Reference
<
168 com::sun::star::lang::XMultiServiceFactory
>& rxSMgr
,
169 HierarchyContentProvider
* pProvider
,
170 const com::sun::star::uno::Reference
<
171 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
172 HierarchyContentProperties
& rProps
);
173 sal_Bool
storeData();
174 sal_Bool
renameData( const com::sun::star::uno::Reference
<
175 com::sun::star::ucb::XContentIdentifier
>& xOldId
,
176 const com::sun::star::uno::Reference
<
177 com::sun::star::ucb::XContentIdentifier
>& xNewId
);
178 sal_Bool
removeData();
180 void setKind( const com::sun::star::uno::Reference
<
181 com::sun::star::ucb::XContentIdentifier
>& Identifier
);
185 sal_Bool
isFolder() const { return ( m_eKind
> LINK
); }
187 ::com::sun::star::uno::Reference
<
188 ::com::sun::star::ucb::XContentIdentifier
>
189 makeNewIdentifier( const rtl::OUString
& rTitle
);
191 typedef rtl::Reference
< HierarchyContent
> HierarchyContentRef
;
192 typedef std::list
< HierarchyContentRef
> HierarchyContentRefList
;
193 void queryChildren( HierarchyContentRefList
& rChildren
);
195 sal_Bool
exchangeIdentity(
196 const ::com::sun::star::uno::Reference
<
197 ::com::sun::star::ucb::XContentIdentifier
>& xNewId
);
199 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
>
200 getPropertyValues( const ::com::sun::star::uno::Sequence
<
201 ::com::sun::star::beans::Property
>& rProperties
);
202 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>
204 const ::com::sun::star::uno::Sequence
<
205 ::com::sun::star::beans::PropertyValue
>& rValues
,
206 const ::com::sun::star::uno::Reference
<
207 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
208 throw( ::com::sun::star::uno::Exception
);
210 void insert( sal_Int32 nNameClashResolve
,
211 const ::com::sun::star::uno::Reference
<
212 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
213 throw( ::com::sun::star::uno::Exception
);
215 void destroy( sal_Bool bDeletePhysical
,
216 const ::com::sun::star::uno::Reference
<
217 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
218 throw( ::com::sun::star::uno::Exception
);
220 void transfer( const ::com::sun::star::ucb::TransferInfo
& rInfo
,
221 const ::com::sun::star::uno::Reference
<
222 ::com::sun::star::ucb::XCommandEnvironment
> & xEnv
)
223 throw( ::com::sun::star::uno::Exception
);
226 // Create existing content. Fail, if not already exists.
227 static HierarchyContent
* create(
228 const com::sun::star::uno::Reference
<
229 com::sun::star::lang::XMultiServiceFactory
>& rxSMgr
,
230 HierarchyContentProvider
* pProvider
,
231 const com::sun::star::uno::Reference
<
232 com::sun::star::ucb::XContentIdentifier
>& Identifier
);
234 // Create new content. Fail, if already exists.
235 static HierarchyContent
* create(
236 const com::sun::star::uno::Reference
<
237 com::sun::star::lang::XMultiServiceFactory
>& rxSMgr
,
238 HierarchyContentProvider
* pProvider
,
239 const com::sun::star::uno::Reference
<
240 com::sun::star::ucb::XContentIdentifier
>& Identifier
,
241 const com::sun::star::ucb::ContentInfo
& Info
);
243 virtual ~HierarchyContent();
252 virtual ::rtl::OUString SAL_CALL
253 getImplementationName()
254 throw( ::com::sun::star::uno::RuntimeException
);
255 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
256 getSupportedServiceNames()
257 throw( ::com::sun::star::uno::RuntimeException
);
260 virtual rtl::OUString SAL_CALL
262 throw( com::sun::star::uno::RuntimeException
);
263 virtual com::sun::star::uno::Reference
<
264 com::sun::star::ucb::XContentIdentifier
> SAL_CALL
266 throw( com::sun::star::uno::RuntimeException
);
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
);
277 virtual void SAL_CALL
278 abort( sal_Int32 CommandId
)
279 throw( com::sun::star::uno::RuntimeException
);
281 //////////////////////////////////////////////////////////////////////
282 // Additional interfaces
283 //////////////////////////////////////////////////////////////////////
286 virtual com::sun::star::uno::Sequence
<
287 com::sun::star::ucb::ContentInfo
> SAL_CALL
288 queryCreatableContentsInfo()
289 throw( com::sun::star::uno::RuntimeException
);
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
);
295 //////////////////////////////////////////////////////////////////////
296 // Non-interface methods.
297 //////////////////////////////////////////////////////////////////////
299 static ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRow
>
300 getPropertyValues( const ::com::sun::star::uno::Reference
<
301 ::com::sun::star::lang::XMultiServiceFactory
>& rSMgr
,
302 const ::com::sun::star::uno::Sequence
<
303 ::com::sun::star::beans::Property
>& rProperties
,
304 const HierarchyContentProperties
& rData
,
305 HierarchyContentProvider
* pProvider
,
306 const ::rtl::OUString
& rContentId
);
309 } // namespace hierarchy_ucp
311 #endif /* !_HIERARCHYCONTENT_HXX */