1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: odma_provider.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef ODMA_PROVIDER_HXX
32 #define ODMA_PROVIDER_HXX
34 #include <ucbhelper/providerhelper.hxx>
35 #include <tools/prewin.h>
36 #include <tools/postwin.h>
37 #include "odma_lib.hxx"
39 #include "rtl/ref.hxx"
42 #include "odma_contentprops.hxx"
46 //=========================================================================
48 // UNO service name for the provider. This name will be used by the UCB to
49 // create instances of the provider.
50 #define ODMA_CONTENT_PROVIDER_SERVICE_NAME \
51 "com.sun.star.ucb.ODMAContentProvider"
52 // #define ODMA_CONTENT_PROVIDER_SERVICE_NAME_LENGTH 34
54 // URL scheme. This is the scheme the provider will be able to create
55 // contents for. The UCB will select the provider ( i.e. in order to create
56 // contents ) according to this scheme.
57 #define ODMA_URL_ODMAID "::ODMA"
58 #define ODMA_URL_SCHEME "vnd.sun.star.odma"
59 #define ODMA_URL_SCHEME_SHORT "odma"
60 #define ODMA_URL_SHORT ":"
61 #define ODMA_URL_SHORT_LGTH 5
62 #define ODMA_URL_LGTH 18
63 #define ODMA_URL_ODMAID_LGTH 6
66 #define ODMA_CONTENT_TYPE "application/" ODMA_URL_SCHEME "-content"
67 #define ODMA_ODMA_REGNAME "sodma"
68 #define ODM_NAME_MAX 64 // Max length of a name document including
69 // the terminating NULL character.
71 //=========================================================================
72 class ContentProperties
;
73 class ContentProvider
: public ::ucbhelper::ContentProviderImplHelper
75 typedef ::std::map
< ::rtl::OString
, ::rtl::Reference
<ContentProperties
> > ContentsMap
;
76 ContentsMap m_aContents
; // contains all ContentProperties
77 static ODMHANDLE m_aOdmHandle
; // the one and only ODMA handle to our DMS
79 /** fillDocumentProperties fills the given _rProp with ODMA properties
80 @param _rProp the ContentProperties
82 void fillDocumentProperties(const ::rtl::Reference
<ContentProperties
>& _rProp
);
86 ::rtl::Reference
<ContentProperties
> getContentProperty(const ::rtl::OUString
& _sName
,
87 const ContentPropertiesMemberFunctor
& _aFunctor
) const;
89 ContentProvider( const ::com::sun::star::uno::Reference
<
90 ::com::sun::star::lang::XMultiServiceFactory
>& rSMgr
);
91 virtual ~ContentProvider();
103 virtual ::com::sun::star::uno::Reference
<
104 ::com::sun::star::ucb::XContent
> SAL_CALL
105 queryContent( const ::com::sun::star::uno::Reference
<
106 ::com::sun::star::ucb::XContentIdentifier
>& Identifier
)
107 throw( ::com::sun::star::ucb::IllegalIdentifierException
,
108 ::com::sun::star::uno::RuntimeException
);
110 //////////////////////////////////////////////////////////////////////
111 // Additional interfaces
112 //////////////////////////////////////////////////////////////////////
114 //////////////////////////////////////////////////////////////////////
115 // Non-interface methods.
116 //////////////////////////////////////////////////////////////////////
117 static ODMHANDLE
getHandle();
119 /** append add an entry to the internal map
120 @param _rProp the content properties
122 void append(const ::rtl::Reference
<ContentProperties
>& _rProp
);
124 /** closeDocument closes the document
125 @param _sDocumentId the id of the document
127 void closeDocument(const ::rtl::OString
& _sDocumentId
);
129 /** saveDocument saves the document in DMS
130 @param _sDocumentId the id of the document
132 void saveDocument(const ::rtl::OString
& _sDocumentId
);
134 /** queryContentProperty query in the DMS for a content which document name is equal to _sDocumentName
135 @param _sDocumentName the document to query for
137 @return the content properties for this content or an empty refernce
139 ::rtl::Reference
<ContentProperties
> queryContentProperty(const ::rtl::OUString
& _sDocumentName
);
141 /** getContentPropertyWithTitle returns the ContentProperties for the first content with that title
142 @param _sTitle the title of the document
144 @return the content properties
146 ::rtl::Reference
<ContentProperties
> getContentPropertyWithTitle(const ::rtl::OUString
& _sTitle
) const;
148 /** getContentPropertyWithDocumentId returns the ContentProperties for the first content with that title
149 @param _sTitle the title of the document
151 @return the content properties
153 ::rtl::Reference
<ContentProperties
> getContentPropertyWithDocumentId(const ::rtl::OUString
& _sDocumentId
) const;
155 /** getContentPropertyWithSavedAsName returns the ContentProperties for the first content with that SavedAsName
156 @param _sSaveAsName the SavedAsName of the document
158 @return the content properties
160 ::rtl::Reference
<ContentProperties
> getContentPropertyWithSavedAsName(const ::rtl::OUString
& _sSaveAsName
) const;
162 /** openDoc returns the URL for the temporary file for the specific Content and opens it
163 @param _rProp used for check if already open, the member m_sFileURL will be set if is wan't opened yet
165 @return the URL of the temporary file
167 static ::rtl::OUString
openDoc(const ::rtl::Reference
<ContentProperties
>& _rProp
) throw (::com::sun::star::uno::Exception
);
169 /** convertURL converts a normal URL into an ODMA understandable name
170 @param _sCanonicURL the URL from ContentIndentifier
172 @return the ODMA name
174 static ::rtl::OUString
convertURL(const ::rtl::OUString
& _sCanonicURL
);
176 /** deleteDocument deletes the document inside the DMS and remove the content properties from inside list
177 @param _rProp the ContentProperties
179 @return true when successful
181 sal_Bool
deleteDocument(const ::rtl::Reference
<ContentProperties
>& _rProp
);