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 INCLUDED_TDOC_CONTENT_HXX 25 #define INCLUDED_TDOC_CONTENT_HXX 26 27 #include <ucbhelper/contenthelper.hxx> 28 #include <com/sun/star/task/DocumentPasswordRequest.hpp> 29 #include <com/sun/star/ucb/XContentCreator.hpp> 30 #include <com/sun/star/ucb/CommandFailedException.hpp> 31 #include "tdoc_provider.hxx" 32 33 #define NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT 1 34 35 namespace com { namespace sun { namespace star { 36 namespace sdbc { class XRow; } 37 namespace io { class XInputStream; class XOutputStream; } 38 namespace beans { struct PropertyValue; } 39 namespace ucb { struct OpenCommandArgument2; struct TransferInfo; 40 struct ContentInfo; } 41 } } } 42 43 namespace tdoc_ucp 44 { 45 46 //========================================================================= 47 48 #define TDOC_ROOT_CONTENT_SERVICE_NAME \ 49 "com.sun.star.ucb.TransientDocumentsRootContent" 50 #define TDOC_DOCUMENT_CONTENT_SERVICE_NAME \ 51 "com.sun.star.ucb.TransientDocumentsDocumentContent" 52 #define TDOC_FOLDER_CONTENT_SERVICE_NAME \ 53 "com.sun.star.ucb.TransientDocumentsFolderContent" 54 #define TDOC_STREAM_CONTENT_SERVICE_NAME \ 55 "com.sun.star.ucb.TransientDocumentsStreamContent" 56 57 //========================================================================= 58 59 enum ContentType { STREAM, FOLDER, DOCUMENT, ROOT }; 60 61 class ContentProperties 62 { 63 public: ContentProperties()64 ContentProperties() 65 {} 66 ContentProperties(const ContentType & rType,const rtl::OUString & rTitle)67 ContentProperties( const ContentType & rType, const rtl::OUString & rTitle ) 68 : m_eType( rType ), 69 m_aContentType( rType == STREAM 70 ? rtl::OUString::createFromAscii( TDOC_STREAM_CONTENT_TYPE ) 71 : rType == FOLDER 72 ? rtl::OUString::createFromAscii( TDOC_FOLDER_CONTENT_TYPE ) 73 : rType == DOCUMENT 74 ? rtl::OUString::createFromAscii( TDOC_DOCUMENT_CONTENT_TYPE ) 75 : rtl::OUString::createFromAscii( TDOC_ROOT_CONTENT_TYPE ) ), 76 m_aTitle( rTitle ) 77 {} 78 getType() const79 ContentType getType() const { return m_eType; } 80 81 // Properties 82 getContentType() const83 const rtl::OUString & getContentType() const { return m_aContentType; } 84 getIsFolder() const85 bool getIsFolder() const { return m_eType > STREAM; } getIsDocument() const86 bool getIsDocument() const { return !getIsFolder(); } 87 getTitle() const88 const rtl::OUString & getTitle() const { return m_aTitle; } setTitle(const rtl::OUString & rTitle)89 void setTitle( const rtl::OUString & rTitle ) { m_aTitle = rTitle; } 90 91 com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo > 92 getCreatableContentsInfo() const; 93 94 bool isContentCreator() const; 95 96 private: 97 ContentType m_eType; 98 rtl::OUString m_aContentType; 99 rtl::OUString m_aTitle; 100 }; 101 102 //========================================================================= 103 104 class Content : public ::ucbhelper::ContentImplHelper, 105 public com::sun::star::ucb::XContentCreator 106 { 107 enum ContentState { TRANSIENT, // created via createNewContent, 108 // but did not process "insert" yet 109 PERSISTENT, // processed "insert" 110 DEAD // processed "delete" / document was closed 111 }; 112 113 ContentProperties m_aProps; 114 ContentState m_eState; 115 ContentProvider* m_pProvider; 116 117 private: 118 Content( const com::sun::star::uno::Reference< 119 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 120 ContentProvider* pProvider, 121 const com::sun::star::uno::Reference< 122 com::sun::star::ucb::XContentIdentifier >& Identifier, 123 const ContentProperties & rProps ); 124 Content( const com::sun::star::uno::Reference< 125 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 126 ContentProvider* pProvider, 127 const com::sun::star::uno::Reference< 128 com::sun::star::ucb::XContentIdentifier >& Identifier, 129 const com::sun::star::ucb::ContentInfo& Info ); 130 131 virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property > 132 getProperties( const com::sun::star::uno::Reference< 133 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 134 virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo > 135 getCommands( const com::sun::star::uno::Reference< 136 com::sun::star::ucb::XCommandEnvironment > & xEnv ); 137 virtual ::rtl::OUString getParentURL(); 138 139 static bool hasData( ContentProvider* pProvider, const Uri & rUri ); hasData(const Uri & rUri)140 bool hasData( const Uri & rUri ) { return hasData( m_pProvider, rUri ); } 141 142 static bool loadData( ContentProvider* pProvider, 143 const Uri & rUri, 144 ContentProperties& rProps ); 145 bool storeData( const com::sun::star::uno::Reference< 146 com::sun::star::io::XInputStream >& xData, 147 const com::sun::star::uno::Reference< 148 com::sun::star::ucb::XCommandEnvironment >& xEnv ); 149 bool renameData( const com::sun::star::uno::Reference< 150 com::sun::star::ucb::XContentIdentifier >& xOldId, 151 const com::sun::star::uno::Reference< 152 com::sun::star::ucb::XContentIdentifier >& xNewId ); 153 bool removeData(); 154 155 bool copyData( const Uri & rSourceUri, const rtl::OUString & rNewName ); 156 157 ::com::sun::star::uno::Reference< 158 ::com::sun::star::ucb::XContentIdentifier > 159 makeNewIdentifier( const rtl::OUString& rTitle ); 160 161 typedef rtl::Reference< Content > ContentRef; 162 typedef std::list< ContentRef > ContentRefList; 163 void queryChildren( ContentRefList& rChildren ); 164 165 sal_Bool exchangeIdentity( 166 const ::com::sun::star::uno::Reference< 167 ::com::sun::star::ucb::XContentIdentifier >& xNewId ); 168 169 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 170 getPropertyValues( const ::com::sun::star::uno::Sequence< 171 ::com::sun::star::beans::Property >& rProperties ); 172 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > 173 setPropertyValues( 174 const ::com::sun::star::uno::Sequence< 175 ::com::sun::star::beans::PropertyValue >& rValues, 176 const ::com::sun::star::uno::Reference< 177 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ); 178 179 com::sun::star::uno::Any 180 open( const ::com::sun::star::ucb::OpenCommandArgument2& rArg, 181 const ::com::sun::star::uno::Reference< 182 ::com::sun::star::ucb::XCommandEnvironment >& xEnv ); 183 184 void insert( const ::com::sun::star::uno::Reference< 185 ::com::sun::star::io::XInputStream >& xData, 186 sal_Int32 nNameClashResolve, 187 const ::com::sun::star::uno::Reference< 188 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ); 189 190 void destroy( sal_Bool bDeletePhysical, 191 const ::com::sun::star::uno::Reference< 192 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ); 193 194 void transfer( const ::com::sun::star::ucb::TransferInfo& rInfo, 195 const ::com::sun::star::uno::Reference< 196 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ); 197 198 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 199 getPropertyValues( const ::com::sun::star::uno::Reference< 200 ::com::sun::star::lang::XMultiServiceFactory >& rSMgr, 201 const ::com::sun::star::uno::Sequence< 202 ::com::sun::star::beans::Property >& rProperties, 203 const ContentProperties& rData, 204 ContentProvider* pProvider, 205 const ::rtl::OUString& rContentId ); 206 207 208 static bool commitStorage( 209 const com::sun::star::uno::Reference< 210 com::sun::star::embed::XStorage > & xStorage ); 211 212 static bool closeOutputStream( 213 const com::sun::star::uno::Reference< 214 com::sun::star::io::XOutputStream > & xOut ); 215 216 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 217 getInputStream( const ::com::sun::star::uno::Reference< 218 ::com::sun::star::ucb::XCommandEnvironment > & 219 xEnv ); 220 221 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > 222 getTruncatedOutputStream( 223 const ::com::sun::star::uno::Reference< 224 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ); 225 226 ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent > 227 queryChildContent( const rtl::OUString & rRelativeChildUri ); 228 229 ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > 230 getStream( const ::com::sun::star::uno::Reference< 231 ::com::sun::star::ucb::XCommandEnvironment > & xEnv ); 232 233 public: 234 // Create existing content. Fail, if not already exists. 235 static Content* create( 236 const com::sun::star::uno::Reference< 237 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 238 ContentProvider* pProvider, 239 const com::sun::star::uno::Reference< 240 com::sun::star::ucb::XContentIdentifier >& Identifier ); 241 242 // Create new content. Fail, if already exists. 243 static Content* create( 244 const com::sun::star::uno::Reference< 245 com::sun::star::lang::XMultiServiceFactory >& rxSMgr, 246 ContentProvider* pProvider, 247 const com::sun::star::uno::Reference< 248 com::sun::star::ucb::XContentIdentifier >& Identifier, 249 const com::sun::star::ucb::ContentInfo& Info ); 250 251 virtual ~Content(); 252 253 // XInterface 254 XINTERFACE_DECL() 255 256 // XTypeProvider 257 XTYPEPROVIDER_DECL() 258 259 // XServiceInfo 260 virtual ::rtl::OUString SAL_CALL 261 getImplementationName(); 262 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 263 getSupportedServiceNames(); 264 265 // XContent 266 virtual rtl::OUString SAL_CALL 267 getContentType(); 268 virtual com::sun::star::uno::Reference< 269 com::sun::star::ucb::XContentIdentifier > SAL_CALL 270 getIdentifier(); 271 272 // XCommandProcessor 273 virtual com::sun::star::uno::Any SAL_CALL 274 execute( const com::sun::star::ucb::Command& aCommand, 275 sal_Int32 CommandId, 276 const com::sun::star::uno::Reference< 277 com::sun::star::ucb::XCommandEnvironment >& Environment ); 278 virtual void SAL_CALL 279 abort( sal_Int32 CommandId ); 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 virtual com::sun::star::uno::Reference< 290 com::sun::star::ucb::XContent > SAL_CALL 291 createNewContent( const com::sun::star::ucb::ContentInfo& Info ); 292 293 ////////////////////////////////////////////////////////////////////// 294 // Non-interface methods. 295 ////////////////////////////////////////////////////////////////////// 296 297 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > 298 getPropertyValues( const ::com::sun::star::uno::Reference< 299 ::com::sun::star::lang::XMultiServiceFactory >& rSMgr, 300 const ::com::sun::star::uno::Sequence< 301 ::com::sun::star::beans::Property >& rProperties, 302 ContentProvider* pProvider, 303 const ::rtl::OUString& rContentId ); 304 305 void notifyDocumentClosed(); 306 void notifyChildRemoved( const rtl::OUString & rRelativeChildUri ); 307 void notifyChildInserted( const rtl::OUString & rRelativeChildUri ); 308 getContentProvider() const309 rtl::Reference< ContentProvider > getContentProvider() const 310 { return rtl::Reference< ContentProvider >( m_pProvider ); } 311 }; 312 313 } // namespace tdoc_ucp 314 315 #endif /* !INCLUDED_TDOC_CONTENT_HXX */ 316