LibreOffice Module ucb (master)  1
tdoc_storage.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STORAGE_HXX
21 #define INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STORAGE_HXX
22 
23 #include <map>
24 
25 #include <osl/mutex.hxx>
26 #include <rtl/ref.hxx>
28 
29 #include <com/sun/star/embed/XStorage.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 
32 namespace tdoc_ucp {
33 
35  {
36  READ, // Note: might be writable as well
39  };
40 
41  class Storage;
42  class OfficeDocumentsManager;
43 
45  {
46  public:
48  const css::uno::Reference< css::uno::XComponentContext > & rxContext,
50  virtual ~StorageElementFactory() override;
51 
54  css::uno::Reference< css::embed::XStorage >
56 
62  css::uno::Reference< css::embed::XStorage >
63  createStorage( const OUString & rUri, StorageAccessMode eMode );
64 
71  css::uno::Reference< css::io::XInputStream >
72  createInputStream( const OUString & rUri,
73  const OUString & rPassword );
74 
81  css::uno::Reference< css::io::XOutputStream >
82  createOutputStream( const OUString & rUri,
83  const OUString & rPassword,
84  bool bTruncate );
85 
92  css::uno::Reference< css::io::XStream >
93  createStream( const OUString & rUri,
94  const OUString & rPassword,
95  bool bTruncate );
96 
97  private:
98  friend class Storage;
99 
100  void releaseElement( Storage const * pElement );
101 
107  css::uno::Reference< css::embed::XStorage >
108  queryParentStorage( const OUString & rUri,
109  StorageAccessMode eMode );
110 
116  css::uno::Reference< css::embed::XStorage >
117  queryStorage( const css::uno::Reference<
118  css::embed::XStorage > & xParentStorage,
119  const OUString & rUri,
120  StorageAccessMode eMode );
121 
128  css::uno::Reference< css::io::XStream >
129  queryStream( const css::uno::Reference<
130  css::embed::XStorage > & xParentStorage,
131  const OUString & rUri,
132  const OUString & rPassword,
133  StorageAccessMode eMode,
134  bool bTruncate /* ignored for read-only streams */ );
135 
136  struct ltstrbool
137  {
139  const std::pair< OUString, bool > & s1,
140  const std::pair< OUString, bool > & s2 ) const
141  {
142  if ( s1.first < s2.first )
143  return true;
144  else if ( s1.first == s2.first )
145  return ( !s1.second && s2.second );
146  else
147  return false;
148  }
149  };
150 
151  // key: pair< storageuri, iswritable >
152  typedef std::map<
153  std::pair< OUString, bool >, Storage *, ltstrbool > StorageMap;
154 
155  StorageMap m_aMap;
156  osl::Mutex m_aMutex;
158  css::uno::Reference< css::uno::XComponentContext > m_xContext;
159  };
160 
161 } // namespace tdoc_ucp
162 
163 #endif // INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STORAGE_HXX
164 
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator()(const std::pair< OUString, bool > &s1, const std::pair< OUString, bool > &s2) const
css::uno::Reference< css::embed::XStorage > createStorage(const OUString &rUri, StorageAccessMode eMode)
StorageElementFactory(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const rtl::Reference< OfficeDocumentsManager > &xDocsMgr)
void releaseElement(Storage const *pElement)
rtl::Reference< OfficeDocumentsManager > m_xDocsMgr
css::uno::Reference< css::io::XStream > createStream(const OUString &rUri, const OUString &rPassword, bool bTruncate)
virtual ~StorageElementFactory() override
std::map< std::pair< OUString, bool >, Storage *, ltstrbool > StorageMap
css::uno::Reference< css::io::XInputStream > createInputStream(const OUString &rUri, const OUString &rPassword)
css::uno::Reference< css::embed::XStorage > createTemporaryStorage()
css::uno::Reference< css::uno::XComponentContext > m_xContext
css::uno::Reference< css::io::XStream > queryStream(const css::uno::Reference< css::embed::XStorage > &xParentStorage, const OUString &rUri, const OUString &rPassword, StorageAccessMode eMode, bool bTruncate)
css::uno::Reference< css::io::XOutputStream > createOutputStream(const OUString &rUri, const OUString &rPassword, bool bTruncate)
css::uno::Reference< css::embed::XStorage > queryStorage(const css::uno::Reference< css::embed::XStorage > &xParentStorage, const OUString &rUri, StorageAccessMode eMode)
css::uno::Reference< css::embed::XStorage > queryParentStorage(const OUString &rUri, StorageAccessMode eMode)