GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svl / source / fsstor / fsfactory.cxx
blob2cb491be78e45946837c974e8ac8fac9c183af55
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/ucb/XSimpleFileAccess.hpp>
24 #include <com/sun/star/embed/ElementModes.hpp>
25 #include <com/sun/star/io/XSeekable.hpp>
26 #include <comphelper/processfactory.hxx>
27 #include <cppuhelper/supportsservice.hxx>
29 #include <ucbhelper/fileidentifierconverter.hxx>
30 #include <ucbhelper/content.hxx>
32 #include <unotools/tempfile.hxx>
33 #include <unotools/ucbhelper.hxx>
35 #include "fsstorage.hxx"
38 using namespace ::com::sun::star;
40 uno::Sequence< OUString > SAL_CALL FSStorageFactory::impl_staticGetSupportedServiceNames()
42 uno::Sequence< OUString > aRet(2);
43 aRet[0] = "com.sun.star.embed.FileSystemStorageFactory";
44 aRet[1] = "com.sun.star.comp.embed.FileSystemStorageFactory";
45 return aRet;
48 OUString SAL_CALL FSStorageFactory::impl_staticGetImplementationName()
50 return OUString("com.sun.star.comp.embed.FileSystemStorageFactory");
53 uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::impl_staticCreateSelfInstance(
54 const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
56 return uno::Reference< uno::XInterface >( *new FSStorageFactory( comphelper::getComponentContext(xServiceManager) ) );
59 uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstance()
60 throw ( uno::Exception,
61 uno::RuntimeException )
63 OUString aTempURL;
65 aTempURL = ::utl::TempFile( NULL, sal_True ).GetURL();
67 if ( aTempURL.isEmpty() )
68 throw uno::RuntimeException(); // TODO: can not create tempfile
70 ::ucbhelper::Content aResultContent(
71 aTempURL, uno::Reference< ucb::XCommandEnvironment >(),
72 comphelper::getProcessComponentContext() );
74 return uno::Reference< uno::XInterface >(
75 static_cast< OWeakObject* >(
76 new FSStorage( aResultContent,
77 embed::ElementModes::READWRITE,
78 m_xContext ) ),
79 uno::UNO_QUERY );
82 uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstanceWithArguments(
83 const uno::Sequence< uno::Any >& aArguments )
84 throw ( uno::Exception,
85 uno::RuntimeException )
87 // The request for storage can be done with up to three arguments
89 // The first argument specifies a source for the storage
90 // it must be URL.
91 // The second value is a mode the storage should be open in.
92 // And the third value is a media descriptor.
94 sal_Int32 nArgNum = aArguments.getLength();
95 OSL_ENSURE( nArgNum < 4, "Wrong parameter number" );
97 if ( !nArgNum )
98 return createInstance();
100 // first try to retrieve storage open mode if any
101 // by default the storage will be open in readonly mode
102 sal_Int32 nStorageMode = embed::ElementModes::READ;
103 if ( nArgNum >= 2 )
105 if( !( aArguments[1] >>= nStorageMode ) )
107 throw lang::IllegalArgumentException(
108 ("second argument to css.embed.FileSystemStorageFactory."
109 "createInstanceWithArguments must be a"
110 " css.embed.ElementModes"),
111 static_cast< OWeakObject * >(this), -1);
113 // it's always possible to read written storage in this implementation
114 nStorageMode |= embed::ElementModes::READ;
117 // retrieve storage source URL
118 OUString aURL;
120 if ( !( aArguments[0] >>= aURL ) || aURL.isEmpty() )
122 throw lang::IllegalArgumentException(
123 ("first argument to"
124 " css.embed.FileSystemStorageFactory.createInstanceWithArguments"
125 " must be a (non-empty) URL"),
126 static_cast< OWeakObject * >(this), -1);
129 // allow to use other ucp's
130 // if ( !isLocalNotFile_Impl( aURL ) )
131 if ( aURL.startsWithIgnoreAsciiCase("vnd.sun.star.pkg:")
132 || aURL.startsWithIgnoreAsciiCase("vnd.sun.star.zip:")
133 || ::utl::UCBContentHelper::IsDocument( aURL ) )
135 throw lang::IllegalArgumentException(
136 ("URL \"" + aURL + "\" passed as first argument to"
137 " css.embed.FileSystemStorageFactory.createInstanceWithArguments"
138 " must be a file URL denoting a directory"),
139 static_cast< OWeakObject * >(this), -1);
142 if ( ( nStorageMode & embed::ElementModes::WRITE ) && !( nStorageMode & embed::ElementModes::NOCREATE ) )
143 FSStorage::MakeFolderNoUI( aURL );
144 else if ( !::utl::UCBContentHelper::IsFolder( aURL ) )
145 throw io::IOException(
146 ("URL \"" + aURL + "\" passed to"
147 " css.embed.FileSystemStorageFactory.createInstanceWithArguments"
148 " does not denote an existing directory"),
149 static_cast< OWeakObject * >(this));
151 ::ucbhelper::Content aResultContent(
152 aURL, uno::Reference< ucb::XCommandEnvironment >(),
153 comphelper::getProcessComponentContext() );
155 // create storage based on source
156 return uno::Reference< uno::XInterface >(
157 static_cast< OWeakObject* >( new FSStorage( aResultContent,
158 nStorageMode,
159 m_xContext ) ),
160 uno::UNO_QUERY );
163 OUString SAL_CALL FSStorageFactory::getImplementationName()
164 throw ( uno::RuntimeException )
166 return impl_staticGetImplementationName();
169 sal_Bool SAL_CALL FSStorageFactory::supportsService( const OUString& ServiceName )
170 throw ( uno::RuntimeException )
172 return cppu::supportsService(this, ServiceName);
175 uno::Sequence< OUString > SAL_CALL FSStorageFactory::getSupportedServiceNames()
176 throw ( uno::RuntimeException )
178 return impl_staticGetSupportedServiceNames();
182 extern "C"
184 SAL_DLLPUBLIC_EXPORT void * SAL_CALL fsstorage_component_getFactory (
185 const sal_Char * pImplementationName, void * pServiceManager,
186 SAL_UNUSED_PARAMETER void * /* pRegistryKey */)
188 void * pResult = 0;
189 if (pServiceManager)
191 uno::Reference< lang::XSingleServiceFactory > xFactory;
192 if (FSStorageFactory::impl_staticGetImplementationName().equalsAscii(pImplementationName))
194 xFactory = cppu::createOneInstanceFactory (
195 reinterpret_cast< lang::XMultiServiceFactory* >(pServiceManager),
196 FSStorageFactory::impl_staticGetImplementationName(),
197 FSStorageFactory::impl_staticCreateSelfInstance,
198 FSStorageFactory::impl_staticGetSupportedServiceNames() );
200 if (xFactory.is())
202 xFactory->acquire();
203 pResult = xFactory.get();
206 return pResult;
209 } // extern "C"
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */