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 INCLUDED_TDOC_PROVIDER_HXX
29 #define INCLUDED_TDOC_PROVIDER_HXX
30 
31 #include "rtl/ref.hxx"
32 #include <com/sun/star/frame/XTransientDocumentsDocumentContentFactory.hpp>
33 #include <com/sun/star/packages/WrongPasswordException.hpp>
34 #include "ucbhelper/providerhelper.hxx"
35 #include "tdoc_uri.hxx" // for TDOC_URL_SCHEME
36 #include "tdoc_docmgr.hxx"
37 #include "tdoc_storage.hxx" // for StorageAccessMode
38 
39 namespace com { namespace sun { namespace star { namespace embed {
40     class XStorage;
41 } } } }
42 
43 namespace com { namespace sun { namespace star { namespace frame {
44     class XModel;
45 } } } }
46 
47 namespace tdoc_ucp {
48 
49 //=========================================================================
50 
51 #define TDOC_CONTENT_PROVIDER_SERVICE_NAME \
52                 "com.sun.star.ucb.TransientDocumentsContentProvider"
53 #define TDOC_CONTENT_PROVIDER_SERVICE_NAME_LENGTH   50
54 
55 #define TDOC_ROOT_CONTENT_TYPE \
56                 "application/" TDOC_URL_SCHEME "-root"
57 #define TDOC_DOCUMENT_CONTENT_TYPE \
58                 "application/" TDOC_URL_SCHEME "-document"
59 #define TDOC_FOLDER_CONTENT_TYPE \
60                 "application/" TDOC_URL_SCHEME "-folder"
61 #define TDOC_STREAM_CONTENT_TYPE \
62                 "application/" TDOC_URL_SCHEME "-stream"
63 
64 //=========================================================================
65 
66 class StorageElementFactory;
67 
68 class ContentProvider :
69     public ::ucbhelper::ContentProviderImplHelper,
70     public com::sun::star::frame::XTransientDocumentsDocumentContentFactory,
71     public OfficeDocumentsEventListener
72 {
73 public:
74     ContentProvider( const com::sun::star::uno::Reference<
75                         com::sun::star::lang::XMultiServiceFactory >& rXSMgr );
76     virtual ~ContentProvider();
77 
78 	// XInterface
79 	XINTERFACE_DECL()
80 
81 	// XTypeProvider
82 	XTYPEPROVIDER_DECL()
83 
84     // XServiceInfo
85 	XSERVICEINFO_DECL()
86 
87 	// XContentProvider
88 	virtual com::sun::star::uno::Reference<
89 				com::sun::star::ucb::XContent > SAL_CALL
90 	queryContent( const com::sun::star::uno::Reference<
91 					com::sun::star::ucb::XContentIdentifier >& Identifier )
92 		throw( com::sun::star::ucb::IllegalIdentifierException,
93 			   com::sun::star::uno::RuntimeException );
94 
95     // XTransientDocumentsDocumentContentFactory
96     virtual com::sun::star::uno::Reference<
97         com::sun::star::ucb::XContent > SAL_CALL
98     createDocumentContent( const ::com::sun::star::uno::Reference<
99                                 com::sun::star::frame::XModel >& Model )
100         throw ( com::sun::star::lang::IllegalArgumentException,
101                 com::sun::star::uno::RuntimeException );
102 
103     // Non-UNO interfaces
104     com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
105     queryStorage( const rtl::OUString & rUri, StorageAccessMode eMode ) const;
106 
107     com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
108     queryStorageClone( const rtl::OUString & rUri ) const;
109 
110     com::sun::star::uno::Reference< com::sun::star::io::XInputStream >
111     queryInputStream( const rtl::OUString & rUri,
112                       const rtl::OUString & rPassword ) const
113         throw ( com::sun::star::packages::WrongPasswordException );
114 
115     com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >
116     queryOutputStream( const rtl::OUString & rUri,
117                        const rtl::OUString & rPassword,
118                        bool bTruncate ) const
119         throw ( com::sun::star::packages::WrongPasswordException );
120 
121     com::sun::star::uno::Reference< com::sun::star::io::XStream >
122     queryStream( const rtl::OUString & rUri,
123                  const rtl::OUString & rPassword,
124                  bool bTruncate ) const
125         throw ( com::sun::star::packages::WrongPasswordException );
126 
127     bool queryNamesOfChildren(
128         const rtl::OUString & rUri,
129         com::sun::star::uno::Sequence< rtl::OUString > & rNames ) const;
130 
131     // storage properties
132     rtl::OUString queryStorageTitle( const rtl::OUString & rUri ) const;
133 
134     com::sun::star::uno::Reference< com::sun::star::frame::XModel >
135     queryDocumentModel( const rtl::OUString & rUri ) const;
136 
137     // interface OfficeDocumentsEventListener
138     virtual void notifyDocumentOpened( const rtl::OUString & rDocId );
139     virtual void notifyDocumentClosed( const rtl::OUString & rDocId );
140 
141 private:
142     rtl::Reference< OfficeDocumentsManager > m_xDocsMgr;
143     rtl::Reference< StorageElementFactory >  m_xStgElemFac;
144 };
145 
146 } // namespace tdoc_ucp
147 
148 #endif /* !INCLUDED_TDOC_PROVIDER_HXX */
149