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 		throw( ::com::sun::star::ucb::IllegalIdentifierException,
99 			   ::com::sun::star::uno::RuntimeException );
100 
101 	//////////////////////////////////////////////////////////////////////
102 	// Additional interfaces
103 	//////////////////////////////////////////////////////////////////////
104 
105 	//////////////////////////////////////////////////////////////////////
106 	// Non-interface methods.
107 	//////////////////////////////////////////////////////////////////////
108 	static ODMHANDLE getHandle();
109 
110 	/** append add an entry to the internal map
111 		@param	_rProp	the content properties
112 	*/
113 	void append(const ::rtl::Reference<ContentProperties>& _rProp);
114 
115 	/** closeDocument closes the document
116 		@param	_sDocumentId	the id of the document
117 	*/
118 	void closeDocument(const ::rtl::OString& _sDocumentId);
119 
120 	/** saveDocument saves the document in DMS
121 		@param	_sDocumentId	the id of the document
122 	*/
123 	void saveDocument(const ::rtl::OString& _sDocumentId);
124 
125 	/** queryContentProperty query in the DMS for a content which document name is equal to _sDocumentName
126 		@param	_sDocumentName	the document to query for
127 
128 		@return	the content properties for this content or an empty refernce
129 	*/
130 	::rtl::Reference<ContentProperties> queryContentProperty(const ::rtl::OUString& _sDocumentName);
131 
132 	/** getContentProperty returns the ContentProperties for the first content with that title
133 		@param	_sTitle	the title of the document
134 
135 		@return	the content properties
136 	*/
137 	::rtl::Reference<ContentProperties> getContentPropertyWithTitle(const ::rtl::OUString& _sTitle) const;
138 
139 	/** getContentProperty returns the ContentProperties for the first content with that SavedAsName
140 		@param	_sSaveAsName	the SavedAsName of the document
141 
142 		@return	the content properties
143 	*/
144 	::rtl::Reference<ContentProperties> getContentPropertyWithSavedAsName(const ::rtl::OUString& _sSaveAsName) const;
145 
146 	/** openDoc returns the URL for the temporary file for the specific Content and opens it
147 		@param	_rProp	used for check if already open, the member m_sFileURL will be set if is wan't opened yet
148 
149 		@return the URL of the temporary file
150 	*/
151 	static ::rtl::OUString openDoc(const ::rtl::Reference<ContentProperties>& _rProp) throw (::com::sun::star::uno::Exception);
152 
153 	/** convertURL converts a normal URL into an ODMA understandable name
154 		@param	_sCanonicURL	the URL from ContentIndentifier
155 
156 		@return	the ODMA name
157 	*/
158 	static ::rtl::OUString convertURL(const ::rtl::OUString& _sCanonicURL);
159 
160 	/** deleteDocument deletes the document inside the DMS and remove the content properties from inside list
161 		@param	_rProp	the ContentProperties
162 
163 		@return true when successful
164 	*/
165 	sal_Bool deleteDocument(const ::rtl::Reference<ContentProperties>& _rProp);
166 };
167 
168 }
169 
170 #endif
171