| 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 |
#pragma once |
| 21 |
|
| 22 |
#include <map> |
| 23 |
|
| 24 |
#include <osl/mutex.hxx> |
| 25 |
#include <rtl/ref.hxx> |
| 26 |
#include <salhelper/simplereferenceobject.hxx> |
| 27 |
|
| 28 |
#include <com/sun/star/embed/XStorage.hpp> |
| 29 |
#include <com/sun/star/uno/XComponentContext.hpp> |
| 30 |
|
| 31 |
namespace tdoc_ucp { |
| 32 |
|
| 33 |
enum StorageAccessMode |
| 34 |
{ |
| 35 |
READ, // Note: might be writable as well |
| 36 |
READ_WRITE_NOCREATE, |
| 37 |
READ_WRITE_CREATE |
| 38 |
}; |
| 39 |
|
| 40 |
class Storage; |
| 41 |
class OfficeDocumentsManager; |
| 42 |
|
| 43 |
class StorageElementFactory : public salhelper::SimpleReferenceObject |
| 44 |
{ |
| 45 |
public: |
| 46 |
StorageElementFactory( |
| 47 |
css::uno::Reference< css::uno::XComponentContext > xContext, |
| 48 |
rtl::Reference< OfficeDocumentsManager > xDocsMgr ); |
| 49 |
virtual ~StorageElementFactory() override; |
| 50 |
|
| 51 |
/// @throws css::uno::Exception |
| 52 |
/// @throws css::uno::RuntimeException |
| 53 |
css::uno::Reference< css::embed::XStorage > |
| 54 |
createTemporaryStorage(); |
| 55 |
|
| 56 |
/// @throws css::embed::InvalidStorageException |
| 57 |
/// @throws css::lang::IllegalArgumentException |
| 58 |
/// @throws css::io::IOException |
| 59 |
/// @throws css::embed::StorageWrappedTargetException |
| 60 |
/// @throws css::uno::RuntimeException |
| 61 |
css::uno::Reference< css::embed::XStorage > |
| 62 |
createStorage( const OUString & rUri, StorageAccessMode eMode ); |
| 63 |
|
| 64 |
/// @throws css::embed::InvalidStorageException |
| 65 |
/// @throws css::lang::IllegalArgumentException |
| 66 |
/// @throws css::io::IOException |
| 67 |
/// @throws css::embed::StorageWrappedTargetException |
| 68 |
/// @throws css::packages::WrongPasswordException |
| 69 |
/// @throws css::uno::RuntimeException |
| 70 |
css::uno::Reference< css::io::XInputStream > |
| 71 |
createInputStream( const OUString & rUri, |
| 72 |
const OUString & rPassword ); |
| 73 |
|
| 74 |
/// @throws css::embed::InvalidStorageException |
| 75 |
/// @throws css::lang::IllegalArgumentException |
| 76 |
/// @throws css::io::IOException |
| 77 |
/// @throws css::embed::StorageWrappedTargetException |
| 78 |
/// @throws css::packages::WrongPasswordException |
| 79 |
/// @throws css::uno::RuntimeException |
| 80 |
css::uno::Reference< css::io::XOutputStream > |
| 81 |
createOutputStream( const OUString & rUri, |
| 82 |
const OUString & rPassword, |
| 83 |
bool bTruncate ); |
| 84 |
|
| 85 |
/// @throws css::embed::InvalidStorageException |
| 86 |
/// @throws css::lang::IllegalArgumentException |
| 87 |
/// @throws css::io::IOException |
| 88 |
/// @throws css::embed::StorageWrappedTargetException |
| 89 |
/// @throws css::packages::WrongPasswordException |
| 90 |
/// @throws css::uno::RuntimeException |
| 91 |
css::uno::Reference< css::io::XStream > |
| 92 |
createStream( const OUString & rUri, |
| 93 |
const OUString & rPassword, |
| 94 |
bool bTruncate ); |
| 95 |
|
| 96 |
private: |
| 97 |
friend class Storage; |
| 98 |
|
| 99 |
void releaseElement( Storage const * pElement ); |
| 100 |
|
| 101 |
/// @throws css::embed::InvalidStorageException |
| 102 |
/// @throws css::lang::IllegalArgumentException |
| 103 |
/// @throws css::io::IOException |
| 104 |
/// @throws css::embed::StorageWrappedTargetException |
| 105 |
/// @throws css::uno::RuntimeException |
| 106 |
css::uno::Reference< css::embed::XStorage > |
| 107 |
queryParentStorage( const OUString & rUri, |
| 108 |
StorageAccessMode eMode ); |
| 109 |
|
| 110 |
/// @throws css::embed::InvalidStorageException |
| 111 |
/// @throws css::lang::IllegalArgumentException |
| 112 |
/// @throws css::io::IOException |
| 113 |
/// @throws css::embed::StorageWrappedTargetException |
| 114 |
/// @throws css::uno::RuntimeException |
| 115 |
css::uno::Reference< css::embed::XStorage > |
| 116 |
queryStorage( const css::uno::Reference< |
| 117 |
css::embed::XStorage > & xParentStorage, |
| 118 |
const OUString & rUri, |
| 119 |
StorageAccessMode eMode ); |
| 120 |
|
| 121 |
/// @throws css::embed::InvalidStorageException |
| 122 |
/// @throws css::lang::IllegalArgumentException |
| 123 |
/// @throws css::io::IOException |
| 124 |
/// @throws css::embed::StorageWrappedTargetException |
| 125 |
/// @throws css::packages::WrongPasswordException |
| 126 |
/// @throws css::uno::RuntimeException |
| 127 |
css::uno::Reference< css::io::XStream > |
| 128 |
queryStream( const css::uno::Reference< |
| 129 |
css::embed::XStorage > & xParentStorage, |
| 130 |
const OUString & rUri, |
| 131 |
const OUString & rPassword, |
| 132 |
StorageAccessMode eMode, |
| 133 |
bool bTruncate /* ignored for read-only streams */ ); |
| 134 |
|
| 135 |
struct ltstrbool |
| 136 |
{ |
| 137 |
bool operator()( |
| 138 |
const std::pair< OUString, bool > & s1, |
| 139 |
const std::pair< OUString, bool > & s2 ) const |
| 140 |
{ |
| 141 |
if ( s1.first < s2.first ) |
| 142 |
return true; |
| 143 |
else if ( s1.first == s2.first ) |
| 144 |
return ( !s1.second && s2.second ); |
| 145 |
else |
| 146 |
return false; |
| 147 |
} |
| 148 |
}; |
| 149 |
|
| 150 |
// key: pair< storageuri, iswritable > |
| 151 |
typedef std::map< |
| 152 |
std::pair< OUString, bool >, Storage *, ltstrbool > StorageMap; |
| 153 |
|
| 154 |
StorageMap m_aMap; |
| 155 |
osl::Mutex m_aMutex; |
| 156 |
rtl::Reference< OfficeDocumentsManager > m_xDocsMgr; |
| 157 |
css::uno::Reference< css::uno::XComponentContext > m_xContext; |
| 158 |
}; |
| 159 |
|
| 160 |
} // namespace tdoc_ucp |
| 161 |
|
| 162 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |