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