LibreOffice Module svl (master) 1
fsfactory.cxx
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
21#include <fsfactory.hxx>
22#include <com/sun/star/embed/ElementModes.hpp>
23#include <com/sun/star/io/IOException.hpp>
26#include <cppuhelper/weak.hxx>
27#include <ucbhelper/content.hxx>
28
29#include <unotools/tempfile.hxx>
31
32#include "fsstorage.hxx"
33
34
35using namespace ::com::sun::star;
36
37
38uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstance()
39{
40 OUString aTempURL = ::utl::CreateTempURL( nullptr, true );
41 if ( aTempURL.isEmpty() )
42 throw uno::RuntimeException("Cannot create tempfile.");
43
44 ::ucbhelper::Content aResultContent(
45 aTempURL, uno::Reference< ucb::XCommandEnvironment >(),
47
48 return cppu::getXWeak(
49 new FSStorage( aResultContent,
50 embed::ElementModes::READWRITE,
51 m_xContext ) );
52}
53
60uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstanceWithArguments(
61 const uno::Sequence< uno::Any >& aArguments )
62{
63 sal_Int32 nArgNum = aArguments.getLength();
64 OSL_ENSURE( nArgNum < 4, "Wrong parameter number" );
65
66 if ( !nArgNum )
67 return createInstance();
68
69 // first try to retrieve storage open mode if any
70 // by default the storage will be open in readonly mode
71 sal_Int32 nStorageMode = embed::ElementModes::READ;
72 if ( nArgNum >= 2 )
73 {
74 if( !( aArguments[1] >>= nStorageMode ) )
75 {
76 throw lang::IllegalArgumentException(
77 ("second argument to css.embed.FileSystemStorageFactory."
78 "createInstanceWithArguments must be a"
79 " css.embed.ElementModes"),
80 getXWeak(), -1);
81 }
82 // it's always possible to read written storage in this implementation
83 nStorageMode |= embed::ElementModes::READ;
84 }
85
86 // retrieve storage source URL
87 OUString aURL;
88
89 if ( !( aArguments[0] >>= aURL ) || aURL.isEmpty() )
90 {
91 throw lang::IllegalArgumentException(
92 ("first argument to"
93 " css.embed.FileSystemStorageFactory.createInstanceWithArguments"
94 " must be a (non-empty) URL"),
95 getXWeak(), -1);
96 }
97
98 // allow to use other ucp's
99 // if ( !isLocalNotFile_Impl( aURL ) )
100 if ( aURL.startsWithIgnoreAsciiCase("vnd.sun.star.pkg:")
101 || aURL.startsWithIgnoreAsciiCase("vnd.sun.star.zip:")
103 {
104 throw lang::IllegalArgumentException(
105 ("URL \"" + aURL + "\" passed as first argument to"
106 " css.embed.FileSystemStorageFactory.createInstanceWithArguments"
107 " must be a file URL denoting a directory"),
108 getXWeak(), -1);
109 }
110
111 if ( ( nStorageMode & embed::ElementModes::WRITE ) && !( nStorageMode & embed::ElementModes::NOCREATE ) )
114 throw io::IOException(
115 ("URL \"" + aURL + "\" passed to"
116 " css.embed.FileSystemStorageFactory.createInstanceWithArguments"
117 " does not denote an existing directory"),
118 getXWeak());
119
120 ::ucbhelper::Content aResultContent(
121 aURL, uno::Reference< ucb::XCommandEnvironment >(),
123
124 // create storage based on source
125 return cppu::getXWeak( new FSStorage( aResultContent,
126 nStorageMode,
127 m_xContext ) );
128}
129
131{
132 return "com.sun.star.comp.embed.FileSystemStorageFactory";
133}
134
135sal_Bool SAL_CALL FSStorageFactory::supportsService( const OUString& ServiceName )
136{
138}
139
140uno::Sequence< OUString > SAL_CALL FSStorageFactory::getSupportedServiceNames()
141{
142 return { "com.sun.star.embed.FileSystemStorageFactory",
143 "com.sun.star.comp.embed.FileSystemStorageFactory" };
144}
145
146
147
148extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
150 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
151{
152 return cppu::acquire(new FSStorageFactory(context));
153}
154
155/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance() override
Definition: fsfactory.cxx:38
virtual OUString SAL_CALL getImplementationName() override
Definition: fsfactory.cxx:130
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments(const css::uno::Sequence< css::uno::Any > &aArguments) override
The request for storage can be done with up to three arguments.
Definition: fsfactory.cxx:60
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: fsfactory.cxx:135
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: fsfactory.cxx:140
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: fsfactory.hxx:32
static bool MakeFolderNoUI(std::u16string_view rFolder)
Definition: fsstorage.cxx:87
URL aURL
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * svl_FSStorageFactory_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: fsfactory.cxx:149
Sequence< PropertyValue > aArguments
SVL_DLLPUBLIC bool IsFolder(const OUString &rURL)
Return if under the URL a folder exist.
Definition: fstathelper.cxx:78
SVL_DLLPUBLIC bool IsDocument(const OUString &rURL)
Return if under the URL a document exist.
Definition: fstathelper.cxx:62
Reference< XComponentContext > getProcessComponentContext()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool