nss: upgrade to release 3.73
[LibreOffice.git] / svl / source / fsstor / fsfactory.cxx
blob98ec1feb8c65e4bc9b2216521ef7a9a4fd65ac8e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <fsfactory.hxx>
22 #include <cppuhelper/factory.hxx>
23 #include <com/sun/star/embed/ElementModes.hpp>
24 #include <com/sun/star/io/IOException.hpp>
25 #include <comphelper/processfactory.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <cppuhelper/weak.hxx>
28 #include <ucbhelper/content.hxx>
30 #include <unotools/tempfile.hxx>
31 #include <unotools/ucbhelper.hxx>
33 #include "fsstorage.hxx"
36 using namespace ::com::sun::star;
39 uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstance()
41 OUString aTempURL = ::utl::TempFile( nullptr, true ).GetURL();
43 if ( aTempURL.isEmpty() )
44 throw uno::RuntimeException(); // TODO: can not create tempfile
46 ::ucbhelper::Content aResultContent(
47 aTempURL, uno::Reference< ucb::XCommandEnvironment >(),
48 comphelper::getProcessComponentContext() );
50 return uno::Reference< uno::XInterface >(
51 static_cast< OWeakObject* >(
52 new FSStorage( aResultContent,
53 embed::ElementModes::READWRITE,
54 m_xContext ) ),
55 uno::UNO_QUERY );
58 /**
59 * The request for storage can be done with up to three arguments.
60 * The first argument specifies a source for the storage it must be URL.
61 * The second value is a mode the storage should be open in.
62 * The third value is a media descriptor.
64 uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstanceWithArguments(
65 const uno::Sequence< uno::Any >& aArguments )
67 sal_Int32 nArgNum = aArguments.getLength();
68 OSL_ENSURE( nArgNum < 4, "Wrong parameter number" );
70 if ( !nArgNum )
71 return createInstance();
73 // first try to retrieve storage open mode if any
74 // by default the storage will be open in readonly mode
75 sal_Int32 nStorageMode = embed::ElementModes::READ;
76 if ( nArgNum >= 2 )
78 if( !( aArguments[1] >>= nStorageMode ) )
80 throw lang::IllegalArgumentException(
81 ("second argument to css.embed.FileSystemStorageFactory."
82 "createInstanceWithArguments must be a"
83 " css.embed.ElementModes"),
84 static_cast< OWeakObject * >(this), -1);
86 // it's always possible to read written storage in this implementation
87 nStorageMode |= embed::ElementModes::READ;
90 // retrieve storage source URL
91 OUString aURL;
93 if ( !( aArguments[0] >>= aURL ) || aURL.isEmpty() )
95 throw lang::IllegalArgumentException(
96 ("first argument to"
97 " css.embed.FileSystemStorageFactory.createInstanceWithArguments"
98 " must be a (non-empty) URL"),
99 static_cast< OWeakObject * >(this), -1);
102 // allow to use other ucp's
103 // if ( !isLocalNotFile_Impl( aURL ) )
104 if ( aURL.startsWithIgnoreAsciiCase("vnd.sun.star.pkg:")
105 || aURL.startsWithIgnoreAsciiCase("vnd.sun.star.zip:")
106 || ::utl::UCBContentHelper::IsDocument( aURL ) )
108 throw lang::IllegalArgumentException(
109 ("URL \"" + aURL + "\" passed as first argument to"
110 " css.embed.FileSystemStorageFactory.createInstanceWithArguments"
111 " must be a file URL denoting a directory"),
112 static_cast< OWeakObject * >(this), -1);
115 if ( ( nStorageMode & embed::ElementModes::WRITE ) && !( nStorageMode & embed::ElementModes::NOCREATE ) )
116 FSStorage::MakeFolderNoUI( aURL );
117 else if ( !::utl::UCBContentHelper::IsFolder( aURL ) )
118 throw io::IOException(
119 ("URL \"" + aURL + "\" passed to"
120 " css.embed.FileSystemStorageFactory.createInstanceWithArguments"
121 " does not denote an existing directory"),
122 static_cast< OWeakObject * >(this));
124 ::ucbhelper::Content aResultContent(
125 aURL, uno::Reference< ucb::XCommandEnvironment >(),
126 comphelper::getProcessComponentContext() );
128 // create storage based on source
129 return uno::Reference< uno::XInterface >(
130 static_cast< OWeakObject* >( new FSStorage( aResultContent,
131 nStorageMode,
132 m_xContext ) ),
133 uno::UNO_QUERY );
136 OUString SAL_CALL FSStorageFactory::getImplementationName()
138 return "com.sun.star.comp.embed.FileSystemStorageFactory";
141 sal_Bool SAL_CALL FSStorageFactory::supportsService( const OUString& ServiceName )
143 return cppu::supportsService(this, ServiceName);
146 uno::Sequence< OUString > SAL_CALL FSStorageFactory::getSupportedServiceNames()
148 return { "com.sun.star.embed.FileSystemStorageFactory",
149 "com.sun.star.comp.embed.FileSystemStorageFactory" };
154 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
155 svl_FSStorageFactory_get_implementation(
156 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
158 return cppu::acquire(static_cast<cppu::OWeakObject*>(new FSStorageFactory(context)));
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */