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 ODMA_PROVIDER_HXX 25 #define ODMA_PROVIDER_HXX 26 27 #include <ucbhelper/providerhelper.hxx> 28 #include "odma_lib.hxx" 29 30 #include "rtl/ref.hxx" 31 32 #include <map> 33 #include "odma_contentprops.hxx" 34 35 namespace odma { 36 37 //========================================================================= 38 39 // UNO service name for the provider. This name will be used by the UCB to 40 // create instances of the provider. 41 #define ODMA_CONTENT_PROVIDER_SERVICE_NAME \ 42 "com.sun.star.ucb.OdmaContentProvider" 43 // #define ODMA_CONTENT_PROVIDER_SERVICE_NAME_LENGTH 34 44 45 // URL scheme. This is the scheme the provider will be able to create 46 // contents for. The UCB will select the provider ( i.e. in order to create 47 // contents ) according to this scheme. 48 #define ODMA_URL_ODMAID "::ODMA" 49 #define ODMA_URL_SCHEME "vnd.sun.star.odma" 50 #define ODMA_URL_SCHEME_SHORT "odma" 51 #define ODMA_URL_SHORT ":" 52 #define ODMA_URL_SHORT_LGTH 5 53 #define ODMA_URL_LGTH 18 54 #define ODMA_URL_ODMAID_LGTH 6 55 56 // UCB Content Type. 57 #define ODMA_CONTENT_TYPE "application/" ODMA_URL_SCHEME "-content" 58 #define ODMA_ODMA_REGNAME "sodma" 59 #define ODM_NAME_MAX 64 // Max length of a name document including 60 // the terminating NULL character. 61 62 //========================================================================= 63 class ContentProperties; 64 class ContentProvider : public ::ucbhelper::ContentProviderImplHelper 65 { 66 typedef ::std::map< ::rtl::OString, ::rtl::Reference<ContentProperties> > ContentsMap; 67 ContentsMap m_aContents; // contains all ContentProperties 68 static ODMHANDLE m_aOdmHandle; // the one and only ODMA handle to our DMS 69 70 /** fillDocumentProperties fills the given _rProp with ODMA properties 71 @param _rProp the ContentProperties 72 */ 73 void fillDocumentProperties(const ::rtl::Reference<ContentProperties>& _rProp); 74 75 /** 76 */ 77 ::rtl::Reference<ContentProperties> getContentProperty(const ::rtl::OUString& _sName, 78 const ContentPropertiesMemberFunctor& _aFunctor) const; 79 public: 80 ContentProvider( const ::com::sun::star::uno::Reference< 81 ::com::sun::star::lang::XMultiServiceFactory >& rSMgr ); 82 virtual ~ContentProvider(); 83 84 // XInterface 85 XINTERFACE_DECL() 86 87 // XTypeProvider 88 XTYPEPROVIDER_DECL() 89 90 // XServiceInfo 91 XSERVICEINFO_DECL() 92 93 // XContentProvider 94 virtual ::com::sun::star::uno::Reference< 95 ::com::sun::star::ucb::XContent > SAL_CALL 96 queryContent( const ::com::sun::star::uno::Reference< 97 ::com::sun::star::ucb::XContentIdentifier >& Identifier ); 98 99 ////////////////////////////////////////////////////////////////////// 100 // Additional interfaces 101 ////////////////////////////////////////////////////////////////////// 102 103 ////////////////////////////////////////////////////////////////////// 104 // Non-interface methods. 105 ////////////////////////////////////////////////////////////////////// 106 static ODMHANDLE getHandle(); 107 108 /** append add an entry to the internal map 109 @param _rProp the content properties 110 */ 111 void append(const ::rtl::Reference<ContentProperties>& _rProp); 112 113 /** closeDocument closes the document 114 @param _sDocumentId the id of the document 115 */ 116 void closeDocument(const ::rtl::OString& _sDocumentId); 117 118 /** saveDocument saves the document in DMS 119 @param _sDocumentId the id of the document 120 */ 121 void saveDocument(const ::rtl::OString& _sDocumentId); 122 123 /** queryContentProperty query in the DMS for a content which document name is equal to _sDocumentName 124 @param _sDocumentName the document to query for 125 126 @return the content properties for this content or an empty refernce 127 */ 128 ::rtl::Reference<ContentProperties> queryContentProperty(const ::rtl::OUString& _sDocumentName); 129 130 /** getContentProperty returns the ContentProperties for the first content with that title 131 @param _sTitle the title of the document 132 133 @return the content properties 134 */ 135 ::rtl::Reference<ContentProperties> getContentPropertyWithTitle(const ::rtl::OUString& _sTitle) const; 136 137 /** getContentProperty returns the ContentProperties for the first content with that SavedAsName 138 @param _sSaveAsName the SavedAsName of the document 139 140 @return the content properties 141 */ 142 ::rtl::Reference<ContentProperties> getContentPropertyWithSavedAsName(const ::rtl::OUString& _sSaveAsName) const; 143 144 /** openDoc returns the URL for the temporary file for the specific Content and opens it 145 @param _rProp used for check if already open, the member m_sFileURL will be set if is wan't opened yet 146 147 @return the URL of the temporary file 148 */ 149 static ::rtl::OUString openDoc(const ::rtl::Reference<ContentProperties>& _rProp); 150 151 /** convertURL converts a normal URL into an ODMA understandable name 152 @param _sCanonicURL the URL from ContentIndentifier 153 154 @return the ODMA name 155 */ 156 static ::rtl::OUString convertURL(const ::rtl::OUString& _sCanonicURL); 157 158 /** deleteDocument deletes the document inside the DMS and remove the content properties from inside list 159 @param _rProp the ContentProperties 160 161 @return true when successful 162 */ 163 sal_Bool deleteDocument(const ::rtl::Reference<ContentProperties>& _rProp); 164 }; 165 166 } 167 168 #endif 169