1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _HIERARCHYCONTENT_HXX
25 #define _HIERARCHYCONTENT_HXX
26 
27 #include <list>
28 #include <rtl/ref.hxx>
29 #include <com/sun/star/ucb/XContentCreator.hpp>
30 #include <ucbhelper/contenthelper.hxx>
31 #include "hierarchydata.hxx"
32 #include "hierarchyprovider.hxx"
33 
34 namespace com { namespace sun { namespace star { namespace beans {
35     struct Property;
36     struct PropertyValue;
37 } } } }
38 
39 namespace com { namespace sun { namespace star { namespace sdbc {
40     class XRow;
41 } } } }
42 
43 namespace com { namespace sun { namespace star { namespace ucb {
44     struct TransferInfo;
45 } } } }
46 
47 namespace hierarchy_ucp
48 {
49 
50 //=========================================================================
51 
52 #define HIERARCHY_ROOT_FOLDER_CONTENT_SERVICE_NAME \
53                             "com.sun.star.ucb.HierarchyRootFolderContent"
54 #define HIERARCHY_FOLDER_CONTENT_SERVICE_NAME \
55                             "com.sun.star.ucb.HierarchyFolderContent"
56 #define HIERARCHY_LINK_CONTENT_SERVICE_NAME \
57                             "com.sun.star.ucb.HierarchyLinkContent"
58 
59 //=========================================================================
60 
61 class HierarchyContentProperties
62 {
63 public:
HierarchyContentProperties()64     HierarchyContentProperties() {};
65 
HierarchyContentProperties(const HierarchyEntryData::Type & rType)66     HierarchyContentProperties( const HierarchyEntryData::Type & rType )
67     : m_aData( rType ),
68       m_aContentType( rType == HierarchyEntryData::FOLDER
69         ? rtl::OUString::createFromAscii( HIERARCHY_FOLDER_CONTENT_TYPE )
70         : rtl::OUString::createFromAscii( HIERARCHY_LINK_CONTENT_TYPE ) ) {}
71 
HierarchyContentProperties(const HierarchyEntryData & rData)72     HierarchyContentProperties( const HierarchyEntryData & rData )
73     : m_aData( rData ),
74       m_aContentType( rData.getType() == HierarchyEntryData::FOLDER
75         ? rtl::OUString::createFromAscii( HIERARCHY_FOLDER_CONTENT_TYPE )
76         : rtl::OUString::createFromAscii( HIERARCHY_LINK_CONTENT_TYPE ) ) {}
77 
getName() const78     const rtl::OUString & getName() const { return m_aData.getName(); }
setName(const rtl::OUString & rName)79     void setName( const rtl::OUString & rName ) { m_aData.setName( rName ); };
80 
getTitle() const81     const rtl::OUString & getTitle() const { return m_aData.getTitle(); }
setTitle(const rtl::OUString & rTitle)82     void setTitle( const rtl::OUString & rTitle )
83     { m_aData.setTitle( rTitle ); };
84 
getTargetURL() const85     const rtl::OUString & getTargetURL() const
86     { return m_aData.getTargetURL(); }
setTargetURL(const rtl::OUString & rURL)87     void setTargetURL( const rtl::OUString & rURL )
88     { m_aData.setTargetURL( rURL ); };
89 
getContentType() const90     const rtl::OUString & getContentType() const { return m_aContentType; }
91 
getIsFolder() const92     sal_Bool getIsFolder() const
93     { return m_aData.getType() == HierarchyEntryData::FOLDER; }
94 
getIsDocument() const95     sal_Bool getIsDocument() const { return !getIsFolder(); }
96 
97     com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo >
98     getCreatableContentsInfo() const;
99 
getHierarchyEntryData() const100     const HierarchyEntryData & getHierarchyEntryData() const { return m_aData; }
101 
102 private:
103     HierarchyEntryData m_aData;
104     rtl::OUString m_aContentType;
105 };
106 
107 //=========================================================================
108 
109 class HierarchyContentProvider;
110 
111 class HierarchyContent : public ::ucbhelper::ContentImplHelper,
112                          public com::sun::star::ucb::XContentCreator
113 {
114     enum ContentKind  { LINK, FOLDER, ROOT };
115     enum ContentState { TRANSIENT,  // created via CreateNewContent,
116                                         // but did not process "insert" yet
117                         PERSISTENT, // processed "insert"
118                         DEAD        // processed "delete"
119                       };
120 
121     HierarchyContentProperties m_aProps;
122     ContentKind                m_eKind;
123     ContentState               m_eState;
124     HierarchyContentProvider*  m_pProvider;
125     bool                       m_bCheckedReadOnly;
126     bool                       m_bIsReadOnly;
127 
128 private:
129     HierarchyContent(
130             const com::sun::star::uno::Reference<
131                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
132             HierarchyContentProvider* pProvider,
133             const com::sun::star::uno::Reference<
134                 com::sun::star::ucb::XContentIdentifier >& Identifier,
135             const HierarchyContentProperties& rProps );
136     HierarchyContent(
137             const com::sun::star::uno::Reference<
138                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
139             HierarchyContentProvider* pProvider,
140             const com::sun::star::uno::Reference<
141                 com::sun::star::ucb::XContentIdentifier >& Identifier,
142             const com::sun::star::ucb::ContentInfo& Info );
143 
144     virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
145     getProperties( const com::sun::star::uno::Reference<
146                     com::sun::star::ucb::XCommandEnvironment > & xEnv );
147     virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo >
148     getCommands( const com::sun::star::uno::Reference<
149                     com::sun::star::ucb::XCommandEnvironment > & xEnv );
150     virtual ::rtl::OUString getParentURL();
151 
152     static sal_Bool hasData(
153             const com::sun::star::uno::Reference<
154                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
155             HierarchyContentProvider* pProvider,
156             const com::sun::star::uno::Reference<
157                 com::sun::star::ucb::XContentIdentifier >& Identifier );
hasData(const com::sun::star::uno::Reference<com::sun::star::ucb::XContentIdentifier> & Identifier)158     sal_Bool hasData(
159             const com::sun::star::uno::Reference<
160                 com::sun::star::ucb::XContentIdentifier >& Identifier )
161     { return hasData( m_xSMgr, m_pProvider, Identifier ); }
162     static sal_Bool loadData(
163             const com::sun::star::uno::Reference<
164                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
165             HierarchyContentProvider* pProvider,
166             const com::sun::star::uno::Reference<
167                 com::sun::star::ucb::XContentIdentifier >& Identifier,
168             HierarchyContentProperties& rProps );
169     sal_Bool storeData();
170     sal_Bool renameData( const com::sun::star::uno::Reference<
171                             com::sun::star::ucb::XContentIdentifier >& xOldId,
172                          const com::sun::star::uno::Reference<
173                             com::sun::star::ucb::XContentIdentifier >& xNewId );
174     sal_Bool removeData();
175 
176     void setKind( const com::sun::star::uno::Reference<
177                     com::sun::star::ucb::XContentIdentifier >& Identifier );
178 
179     bool isReadOnly();
180 
isFolder() const181     sal_Bool isFolder() const { return ( m_eKind > LINK ); }
182 
183     ::com::sun::star::uno::Reference<
184         ::com::sun::star::ucb::XContentIdentifier >
185     makeNewIdentifier( const rtl::OUString& rTitle );
186 
187     typedef rtl::Reference< HierarchyContent > HierarchyContentRef;
188     typedef std::list< HierarchyContentRef > HierarchyContentRefList;
189     void queryChildren( HierarchyContentRefList& rChildren );
190 
191     sal_Bool exchangeIdentity(
192                 const ::com::sun::star::uno::Reference<
193                         ::com::sun::star::ucb::XContentIdentifier >& xNewId );
194 
195     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
196     getPropertyValues( const ::com::sun::star::uno::Sequence<
197                             ::com::sun::star::beans::Property >& rProperties );
198     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
199     setPropertyValues(
200             const ::com::sun::star::uno::Sequence<
201                     ::com::sun::star::beans::PropertyValue >& rValues,
202             const ::com::sun::star::uno::Reference<
203                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
204         throw( ::com::sun::star::uno::Exception );
205 
206     void insert( sal_Int32 nNameClashResolve,
207                  const ::com::sun::star::uno::Reference<
208                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
209         throw( ::com::sun::star::uno::Exception );
210 
211     void destroy( sal_Bool bDeletePhysical,
212                   const ::com::sun::star::uno::Reference<
213                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
214         throw( ::com::sun::star::uno::Exception );
215 
216     void transfer( const ::com::sun::star::ucb::TransferInfo& rInfo,
217                    const ::com::sun::star::uno::Reference<
218                     ::com::sun::star::ucb::XCommandEnvironment > & xEnv )
219         throw( ::com::sun::star::uno::Exception );
220 
221 public:
222     // Create existing content. Fail, if not already exists.
223     static HierarchyContent* create(
224             const com::sun::star::uno::Reference<
225                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
226             HierarchyContentProvider* pProvider,
227             const com::sun::star::uno::Reference<
228                 com::sun::star::ucb::XContentIdentifier >& Identifier );
229 
230     // Create new content. Fail, if already exists.
231     static HierarchyContent* create(
232             const com::sun::star::uno::Reference<
233                 com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
234             HierarchyContentProvider* pProvider,
235             const com::sun::star::uno::Reference<
236                 com::sun::star::ucb::XContentIdentifier >& Identifier,
237             const com::sun::star::ucb::ContentInfo& Info );
238 
239     virtual ~HierarchyContent();
240 
241     // XInterface
242     XINTERFACE_DECL()
243 
244     // XTypeProvider
245     XTYPEPROVIDER_DECL()
246 
247     // XServiceInfo
248     virtual ::rtl::OUString SAL_CALL
249     getImplementationName()
250         throw( ::com::sun::star::uno::RuntimeException );
251     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
252     getSupportedServiceNames()
253         throw( ::com::sun::star::uno::RuntimeException );
254 
255     // XContent
256     virtual rtl::OUString SAL_CALL
257     getContentType()
258         throw( com::sun::star::uno::RuntimeException );
259     virtual com::sun::star::uno::Reference<
260                 com::sun::star::ucb::XContentIdentifier > SAL_CALL
261     getIdentifier()
262         throw( com::sun::star::uno::RuntimeException );
263 
264     // XCommandProcessor
265     virtual com::sun::star::uno::Any SAL_CALL
266     execute( const com::sun::star::ucb::Command& aCommand,
267              sal_Int32 CommandId,
268              const com::sun::star::uno::Reference<
269                 com::sun::star::ucb::XCommandEnvironment >& Environment )
270         throw( com::sun::star::uno::Exception,
271                com::sun::star::ucb::CommandAbortedException,
272                com::sun::star::uno::RuntimeException );
273     virtual void SAL_CALL
274     abort( sal_Int32 CommandId )
275         throw( com::sun::star::uno::RuntimeException );
276 
277     //////////////////////////////////////////////////////////////////////
278     // Additional interfaces
279     //////////////////////////////////////////////////////////////////////
280 
281     // XContentCreator
282     virtual com::sun::star::uno::Sequence<
283                 com::sun::star::ucb::ContentInfo > SAL_CALL
284     queryCreatableContentsInfo()
285         throw( com::sun::star::uno::RuntimeException );
286     virtual com::sun::star::uno::Reference<
287                 com::sun::star::ucb::XContent > SAL_CALL
288     createNewContent( const com::sun::star::ucb::ContentInfo& Info )
289         throw( com::sun::star::uno::RuntimeException );
290 
291     //////////////////////////////////////////////////////////////////////
292     // Non-interface methods.
293     //////////////////////////////////////////////////////////////////////
294 
295     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
296     getPropertyValues( const ::com::sun::star::uno::Reference<
297                         ::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
298                        const ::com::sun::star::uno::Sequence<
299                             ::com::sun::star::beans::Property >& rProperties,
300                        const HierarchyContentProperties& rData,
301                        HierarchyContentProvider* pProvider,
302                        const ::rtl::OUString& rContentId );
303 };
304 
305 } // namespace hierarchy_ucp
306 
307 #endif /* !_HIERARCHYCONTENT_HXX */
308