xref: /AOO41X/main/ucb/source/ucp/odma/odma_provider.hxx (revision 6df1ea1f75e32b7bdb9b43f28f6c06e1fbd0c5ce)
1*6df1ea1fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6df1ea1fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6df1ea1fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6df1ea1fSAndrew Rist  * distributed with this work for additional information
6*6df1ea1fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6df1ea1fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6df1ea1fSAndrew Rist  * "License"); you may not use this file except in compliance
9*6df1ea1fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*6df1ea1fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*6df1ea1fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6df1ea1fSAndrew Rist  * software distributed under the License is distributed on an
15*6df1ea1fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6df1ea1fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*6df1ea1fSAndrew Rist  * specific language governing permissions and limitations
18*6df1ea1fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*6df1ea1fSAndrew Rist  *************************************************************/
21*6df1ea1fSAndrew Rist 
22*6df1ea1fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef ODMA_PROVIDER_HXX
25cdf0e10cSrcweir #define ODMA_PROVIDER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <ucbhelper/providerhelper.hxx>
28cdf0e10cSrcweir #include "odma_lib.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "rtl/ref.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <map>
33cdf0e10cSrcweir #include "odma_contentprops.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace odma {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //=========================================================================
38cdf0e10cSrcweir 
39cdf0e10cSrcweir // UNO service name for the provider. This name will be used by the UCB to
40cdf0e10cSrcweir // create instances of the provider.
41cdf0e10cSrcweir #define ODMA_CONTENT_PROVIDER_SERVICE_NAME \
42cdf0e10cSrcweir 				"com.sun.star.ucb.OdmaContentProvider"
43cdf0e10cSrcweir //	#define ODMA_CONTENT_PROVIDER_SERVICE_NAME_LENGTH	34
44cdf0e10cSrcweir 
45cdf0e10cSrcweir // URL scheme. This is the scheme the provider will be able to create
46cdf0e10cSrcweir // contents for. The UCB will select the provider ( i.e. in order to create
47cdf0e10cSrcweir // contents ) according to this scheme.
48cdf0e10cSrcweir #define ODMA_URL_ODMAID			"::ODMA"
49cdf0e10cSrcweir #define ODMA_URL_SCHEME			"vnd.sun.star.odma"
50cdf0e10cSrcweir #define ODMA_URL_SCHEME_SHORT	"odma"
51cdf0e10cSrcweir #define ODMA_URL_SHORT			":"
52cdf0e10cSrcweir #define ODMA_URL_SHORT_LGTH		5
53cdf0e10cSrcweir #define ODMA_URL_LGTH			18
54cdf0e10cSrcweir #define ODMA_URL_ODMAID_LGTH	6
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // UCB Content Type.
57cdf0e10cSrcweir #define ODMA_CONTENT_TYPE 		"application/" ODMA_URL_SCHEME "-content"
58cdf0e10cSrcweir #define ODMA_ODMA_REGNAME		"sodma"
59cdf0e10cSrcweir #define ODM_NAME_MAX			64		// Max length of a name document including
60cdf0e10cSrcweir 										// the terminating NULL character.
61cdf0e10cSrcweir 
62cdf0e10cSrcweir //=========================================================================
63cdf0e10cSrcweir class ContentProperties;
64cdf0e10cSrcweir class ContentProvider : public ::ucbhelper::ContentProviderImplHelper
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	typedef ::std::map< ::rtl::OString, ::rtl::Reference<ContentProperties> > ContentsMap;
67cdf0e10cSrcweir 	ContentsMap		 m_aContents;  // contains all ContentProperties
68cdf0e10cSrcweir 	static ODMHANDLE m_aOdmHandle; // the one and only ODMA handle to our DMS
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	/** fillDocumentProperties fills the given _rProp with ODMA properties
71cdf0e10cSrcweir 		@param	_rProp	the ContentProperties
72cdf0e10cSrcweir 	*/
73cdf0e10cSrcweir 	void fillDocumentProperties(const ::rtl::Reference<ContentProperties>& _rProp);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	/**
76cdf0e10cSrcweir 	*/
77cdf0e10cSrcweir 	::rtl::Reference<ContentProperties> getContentProperty(const ::rtl::OUString& _sName,
78cdf0e10cSrcweir 													   const ContentPropertiesMemberFunctor& _aFunctor) const;
79cdf0e10cSrcweir public:
80cdf0e10cSrcweir 	ContentProvider( const ::com::sun::star::uno::Reference<
81cdf0e10cSrcweir 						::com::sun::star::lang::XMultiServiceFactory >& rSMgr );
82cdf0e10cSrcweir 	virtual ~ContentProvider();
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	// XInterface
85cdf0e10cSrcweir 	XINTERFACE_DECL()
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	// XTypeProvider
88cdf0e10cSrcweir 	XTYPEPROVIDER_DECL()
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     // XServiceInfo
91cdf0e10cSrcweir 	XSERVICEINFO_DECL()
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	// XContentProvider
94cdf0e10cSrcweir 	virtual ::com::sun::star::uno::Reference<
95cdf0e10cSrcweir 				::com::sun::star::ucb::XContent > SAL_CALL
96cdf0e10cSrcweir 	queryContent( const ::com::sun::star::uno::Reference<
97cdf0e10cSrcweir 					::com::sun::star::ucb::XContentIdentifier >& Identifier )
98cdf0e10cSrcweir 		throw( ::com::sun::star::ucb::IllegalIdentifierException,
99cdf0e10cSrcweir 			   ::com::sun::star::uno::RuntimeException );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
102cdf0e10cSrcweir 	// Additional interfaces
103cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
106cdf0e10cSrcweir 	// Non-interface methods.
107cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
108cdf0e10cSrcweir 	static ODMHANDLE getHandle();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	/** append add an entry to the internal map
111cdf0e10cSrcweir 		@param	_rProp	the content properties
112cdf0e10cSrcweir 	*/
113cdf0e10cSrcweir 	void append(const ::rtl::Reference<ContentProperties>& _rProp);
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	/** closeDocument closes the document
116cdf0e10cSrcweir 		@param	_sDocumentId	the id of the document
117cdf0e10cSrcweir 	*/
118cdf0e10cSrcweir 	void closeDocument(const ::rtl::OString& _sDocumentId);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	/** saveDocument saves the document in DMS
121cdf0e10cSrcweir 		@param	_sDocumentId	the id of the document
122cdf0e10cSrcweir 	*/
123cdf0e10cSrcweir 	void saveDocument(const ::rtl::OString& _sDocumentId);
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	/** queryContentProperty query in the DMS for a content which document name is equal to _sDocumentName
126cdf0e10cSrcweir 		@param	_sDocumentName	the document to query for
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		@return	the content properties for this content or an empty refernce
129cdf0e10cSrcweir 	*/
130cdf0e10cSrcweir 	::rtl::Reference<ContentProperties> queryContentProperty(const ::rtl::OUString& _sDocumentName);
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	/** getContentProperty returns the ContentProperties for the first content with that title
133cdf0e10cSrcweir 		@param	_sTitle	the title of the document
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 		@return	the content properties
136cdf0e10cSrcweir 	*/
137cdf0e10cSrcweir 	::rtl::Reference<ContentProperties> getContentPropertyWithTitle(const ::rtl::OUString& _sTitle) const;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	/** getContentProperty returns the ContentProperties for the first content with that SavedAsName
140cdf0e10cSrcweir 		@param	_sSaveAsName	the SavedAsName of the document
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 		@return	the content properties
143cdf0e10cSrcweir 	*/
144cdf0e10cSrcweir 	::rtl::Reference<ContentProperties> getContentPropertyWithSavedAsName(const ::rtl::OUString& _sSaveAsName) const;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	/** openDoc returns the URL for the temporary file for the specific Content and opens it
147cdf0e10cSrcweir 		@param	_rProp	used for check if already open, the member m_sFileURL will be set if is wan't opened yet
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 		@return the URL of the temporary file
150cdf0e10cSrcweir 	*/
151cdf0e10cSrcweir 	static ::rtl::OUString openDoc(const ::rtl::Reference<ContentProperties>& _rProp) throw (::com::sun::star::uno::Exception);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	/** convertURL converts a normal URL into an ODMA understandable name
154cdf0e10cSrcweir 		@param	_sCanonicURL	the URL from ContentIndentifier
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 		@return	the ODMA name
157cdf0e10cSrcweir 	*/
158cdf0e10cSrcweir 	static ::rtl::OUString convertURL(const ::rtl::OUString& _sCanonicURL);
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 	/** deleteDocument deletes the document inside the DMS and remove the content properties from inside list
161cdf0e10cSrcweir 		@param	_rProp	the ContentProperties
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 		@return true when successful
164cdf0e10cSrcweir 	*/
165cdf0e10cSrcweir 	sal_Bool deleteDocument(const ::rtl::Reference<ContentProperties>& _rProp);
166cdf0e10cSrcweir };
167cdf0e10cSrcweir 
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir #endif
171