1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef ODMA_PROVIDER_HXX 29 #define ODMA_PROVIDER_HXX 30 31 #include <ucbhelper/providerhelper.hxx> 32 #include "odma_lib.hxx" 33 34 #include "rtl/ref.hxx" 35 36 #include <map> 37 #include "odma_contentprops.hxx" 38 39 namespace odma { 40 41 //========================================================================= 42 43 // UNO service name for the provider. This name will be used by the UCB to 44 // create instances of the provider. 45 #define ODMA_CONTENT_PROVIDER_SERVICE_NAME \ 46 "com.sun.star.ucb.OdmaContentProvider" 47 // #define ODMA_CONTENT_PROVIDER_SERVICE_NAME_LENGTH 34 48 49 // URL scheme. This is the scheme the provider will be able to create 50 // contents for. The UCB will select the provider ( i.e. in order to create 51 // contents ) according to this scheme. 52 #define ODMA_URL_ODMAID "::ODMA" 53 #define ODMA_URL_SCHEME "vnd.sun.star.odma" 54 #define ODMA_URL_SCHEME_SHORT "odma" 55 #define ODMA_URL_SHORT ":" 56 #define ODMA_URL_SHORT_LGTH 5 57 #define ODMA_URL_LGTH 18 58 #define ODMA_URL_ODMAID_LGTH 6 59 60 // UCB Content Type. 61 #define ODMA_CONTENT_TYPE "application/" ODMA_URL_SCHEME "-content" 62 #define ODMA_ODMA_REGNAME "sodma" 63 #define ODM_NAME_MAX 64 // Max length of a name document including 64 // the terminating NULL character. 65 66 //========================================================================= 67 class ContentProperties; 68 class ContentProvider : public ::ucbhelper::ContentProviderImplHelper 69 { 70 typedef ::std::map< ::rtl::OString, ::rtl::Reference<ContentProperties> > ContentsMap; 71 ContentsMap m_aContents; // contains all ContentProperties 72 static ODMHANDLE m_aOdmHandle; // the one and only ODMA handle to our DMS 73 74 /** fillDocumentProperties fills the given _rProp with ODMA properties 75 @param _rProp the ContentProperties 76 */ 77 void fillDocumentProperties(const ::rtl::Reference<ContentProperties>& _rProp); 78 79 /** 80 */ 81 ::rtl::Reference<ContentProperties> getContentProperty(const ::rtl::OUString& _sName, 82 const ContentPropertiesMemberFunctor& _aFunctor) const; 83 public: 84 ContentProvider( const ::com::sun::star::uno::Reference< 85 ::com::sun::star::lang::XMultiServiceFactory >& rSMgr ); 86 virtual ~ContentProvider(); 87 88 // XInterface 89 XINTERFACE_DECL() 90 91 // XTypeProvider 92 XTYPEPROVIDER_DECL() 93 94 // XServiceInfo 95 XSERVICEINFO_DECL() 96 97 // XContentProvider 98 virtual ::com::sun::star::uno::Reference< 99 ::com::sun::star::ucb::XContent > SAL_CALL 100 queryContent( const ::com::sun::star::uno::Reference< 101 ::com::sun::star::ucb::XContentIdentifier >& Identifier ) 102 throw( ::com::sun::star::ucb::IllegalIdentifierException, 103 ::com::sun::star::uno::RuntimeException ); 104 105 ////////////////////////////////////////////////////////////////////// 106 // Additional interfaces 107 ////////////////////////////////////////////////////////////////////// 108 109 ////////////////////////////////////////////////////////////////////// 110 // Non-interface methods. 111 ////////////////////////////////////////////////////////////////////// 112 static ODMHANDLE getHandle(); 113 114 /** append add an entry to the internal map 115 @param _rProp the content properties 116 */ 117 void append(const ::rtl::Reference<ContentProperties>& _rProp); 118 119 /** closeDocument closes the document 120 @param _sDocumentId the id of the document 121 */ 122 void closeDocument(const ::rtl::OString& _sDocumentId); 123 124 /** saveDocument saves the document in DMS 125 @param _sDocumentId the id of the document 126 */ 127 void saveDocument(const ::rtl::OString& _sDocumentId); 128 129 /** queryContentProperty query in the DMS for a content which document name is equal to _sDocumentName 130 @param _sDocumentName the document to query for 131 132 @return the content properties for this content or an empty refernce 133 */ 134 ::rtl::Reference<ContentProperties> queryContentProperty(const ::rtl::OUString& _sDocumentName); 135 136 /** getContentProperty returns the ContentProperties for the first content with that title 137 @param _sTitle the title of the document 138 139 @return the content properties 140 */ 141 ::rtl::Reference<ContentProperties> getContentPropertyWithTitle(const ::rtl::OUString& _sTitle) const; 142 143 /** getContentProperty returns the ContentProperties for the first content with that SavedAsName 144 @param _sSaveAsName the SavedAsName of the document 145 146 @return the content properties 147 */ 148 ::rtl::Reference<ContentProperties> getContentPropertyWithSavedAsName(const ::rtl::OUString& _sSaveAsName) const; 149 150 /** openDoc returns the URL for the temporary file for the specific Content and opens it 151 @param _rProp used for check if already open, the member m_sFileURL will be set if is wan't opened yet 152 153 @return the URL of the temporary file 154 */ 155 static ::rtl::OUString openDoc(const ::rtl::Reference<ContentProperties>& _rProp) throw (::com::sun::star::uno::Exception); 156 157 /** convertURL converts a normal URL into an ODMA understandable name 158 @param _sCanonicURL the URL from ContentIndentifier 159 160 @return the ODMA name 161 */ 162 static ::rtl::OUString convertURL(const ::rtl::OUString& _sCanonicURL); 163 164 /** deleteDocument deletes the document inside the DMS and remove the content properties from inside list 165 @param _rProp the ContentProperties 166 167 @return true when successful 168 */ 169 sal_Bool deleteDocument(const ::rtl::Reference<ContentProperties>& _rProp); 170 }; 171 172 } 173 174 #endif 175