Branch data Line data Source code
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 "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 : :
27 : :
28 : : #include <ucbhelper/fileidentifierconverter.hxx>
29 : : #include <ucbhelper/contentbroker.hxx>
30 : : #include <ucbhelper/content.hxx>
31 : :
32 : : #include <unotools/tempfile.hxx>
33 : : #include <unotools/ucbhelper.hxx>
34 : :
35 : : #include "fsstorage.hxx"
36 : :
37 : :
38 : : using namespace ::com::sun::star;
39 : :
40 : : //-------------------------------------------------------------------------
41 : 113 : uno::Sequence< ::rtl::OUString > SAL_CALL FSStorageFactory::impl_staticGetSupportedServiceNames()
42 : : {
43 : 113 : uno::Sequence< ::rtl::OUString > aRet(2);
44 [ + - ]: 113 : aRet[0] = ::rtl::OUString("com.sun.star.embed.FileSystemStorageFactory");
45 [ + - ]: 113 : aRet[1] = ::rtl::OUString("com.sun.star.comp.embed.FileSystemStorageFactory");
46 : 113 : return aRet;
47 : : }
48 : :
49 : : //-------------------------------------------------------------------------
50 : 226 : ::rtl::OUString SAL_CALL FSStorageFactory::impl_staticGetImplementationName()
51 : : {
52 : 226 : return ::rtl::OUString("com.sun.star.comp.embed.FileSystemStorageFactory");
53 : : }
54 : :
55 : : //-------------------------------------------------------------------------
56 : 113 : uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::impl_staticCreateSelfInstance(
57 : : const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
58 : : {
59 [ + - ]: 113 : return uno::Reference< uno::XInterface >( *new FSStorageFactory( xServiceManager ) );
60 : : }
61 : :
62 : : //-------------------------------------------------------------------------
63 : 0 : uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstance()
64 : : throw ( uno::Exception,
65 : : uno::RuntimeException )
66 : : {
67 : 0 : ::rtl::OUString aTempURL;
68 : :
69 [ # # ][ # # ]: 0 : aTempURL = ::utl::TempFile( NULL, sal_True ).GetURL();
[ # # ][ # # ]
[ # # ]
70 : :
71 [ # # ]: 0 : if ( aTempURL.isEmpty() )
72 [ # # ]: 0 : throw uno::RuntimeException(); // TODO: can not create tempfile
73 : :
74 : : ::ucbhelper::Content aResultContent(
75 [ # # ]: 0 : aTempURL, uno::Reference< ucb::XCommandEnvironment >() );
76 : :
77 : : return uno::Reference< uno::XInterface >(
78 : : static_cast< OWeakObject* >(
79 : : new FSStorage( aResultContent,
80 : : embed::ElementModes::READWRITE,
81 [ # # ][ # # ]: 0 : m_xFactory ) ),
82 [ # # # # ]: 0 : uno::UNO_QUERY );
83 : : }
84 : :
85 : : //-------------------------------------------------------------------------
86 : 226 : uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstanceWithArguments(
87 : : const uno::Sequence< uno::Any >& aArguments )
88 : : throw ( uno::Exception,
89 : : uno::RuntimeException )
90 : : {
91 : : // The request for storage can be done with up to three arguments
92 : :
93 : : // The first argument specifies a source for the storage
94 : : // it must be URL.
95 : : // The second value is a mode the storage should be open in.
96 : : // And the third value is a media descriptor.
97 : :
98 : 226 : sal_Int32 nArgNum = aArguments.getLength();
99 : : OSL_ENSURE( nArgNum < 4, "Wrong parameter number" );
100 : :
101 [ - + ]: 226 : if ( !nArgNum )
102 [ # # ]: 0 : return createInstance();
103 : :
104 : : // first try to retrieve storage open mode if any
105 : : // by default the storage will be open in readonly mode
106 : 226 : sal_Int32 nStorageMode = embed::ElementModes::READ;
107 [ + - ]: 226 : if ( nArgNum >= 2 )
108 : : {
109 [ - + ]: 226 : if( !( aArguments[1] >>= nStorageMode ) )
110 : : {
111 : : OSL_FAIL( "Wrong second argument!\n" );
112 [ # # ]: 0 : throw uno::Exception(); // TODO: Illegal argument
113 : : }
114 : : // it's allways possible to read written storage in this implementation
115 : 226 : nStorageMode |= embed::ElementModes::READ;
116 : : }
117 : :
118 : : // retrieve storage source URL
119 : 226 : ::rtl::OUString aURL;
120 : :
121 [ + - ]: 226 : if ( aArguments[0] >>= aURL )
122 : : {
123 [ - + ]: 226 : if ( aURL.isEmpty() )
124 : : {
125 : : OSL_FAIL( "Empty URL is provided!\n" );
126 [ # # ]: 0 : throw uno::Exception(); // TODO: illegal argument
127 : : }
128 : : }
129 : : else
130 : : {
131 : : OSL_FAIL( "Wrong first argument!\n" );
132 [ # # ]: 0 : throw uno::Exception(); // TODO: Illegal argument
133 : : }
134 : :
135 : : // allow to use other ucp's
136 : : // if ( !isLocalNotFile_Impl( aURL ) )
137 [ + - + - ]: 678 : if ( aURL.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.pkg"))
[ - + ][ - + ]
138 : 226 : || aURL.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.zip"))
139 [ + - ]: 226 : || ::utl::UCBContentHelper::IsDocument( aURL ) )
140 : : {
141 : : OSL_FAIL( "File system storages can be based only on file URLs!\n" ); // ???
142 [ # # ]: 0 : throw uno::Exception(); // TODO: illegal argument
143 : : }
144 : :
145 [ + + ][ + - ]: 226 : if ( ( nStorageMode & embed::ElementModes::WRITE ) && !( nStorageMode & embed::ElementModes::NOCREATE ) )
146 [ + - ]: 113 : FSStorage::MakeFolderNoUI( aURL );
147 [ + - ][ - + ]: 113 : else if ( !::utl::UCBContentHelper::IsFolder( aURL ) )
148 [ # # ]: 0 : throw io::IOException(); // there is no such folder
149 : :
150 : : ::ucbhelper::Content aResultContent(
151 [ + - ]: 226 : aURL, uno::Reference< ucb::XCommandEnvironment >() );
152 : :
153 : : // create storage based on source
154 : : return uno::Reference< uno::XInterface >(
155 : : static_cast< OWeakObject* >( new FSStorage( aResultContent,
156 : : nStorageMode,
157 [ + - ][ + - ]: 452 : m_xFactory ) ),
158 [ + - + - ]: 452 : uno::UNO_QUERY );
159 : : }
160 : :
161 : : //-------------------------------------------------------------------------
162 : 0 : ::rtl::OUString SAL_CALL FSStorageFactory::getImplementationName()
163 : : throw ( uno::RuntimeException )
164 : : {
165 : 0 : return impl_staticGetImplementationName();
166 : : }
167 : :
168 : : //-------------------------------------------------------------------------
169 : 0 : sal_Bool SAL_CALL FSStorageFactory::supportsService( const ::rtl::OUString& ServiceName )
170 : : throw ( uno::RuntimeException )
171 : : {
172 [ # # ]: 0 : uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
173 : :
174 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
175 [ # # ][ # # ]: 0 : if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
176 : 0 : return sal_True;
177 : :
178 [ # # ]: 0 : return sal_False;
179 : : }
180 : :
181 : : //-------------------------------------------------------------------------
182 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL FSStorageFactory::getSupportedServiceNames()
183 : : throw ( uno::RuntimeException )
184 : : {
185 : 0 : return impl_staticGetSupportedServiceNames();
186 : : }
187 : :
188 : : //-------------------------------------------------------------------------
189 : :
190 : : extern "C"
191 : : {
192 : 113 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL fsstorage_component_getFactory (
193 : : const sal_Char * pImplementationName, void * pServiceManager,
194 : : SAL_UNUSED_PARAMETER void * /* pRegistryKey */)
195 : : {
196 : 113 : void * pResult = 0;
197 [ + - ]: 113 : if (pServiceManager)
198 : : {
199 : 113 : uno::Reference< lang::XSingleServiceFactory > xFactory;
200 [ + - ][ + - ]: 113 : if (FSStorageFactory::impl_staticGetImplementationName().compareToAscii (pImplementationName) == 0)
201 : : {
202 : : xFactory = cppu::createOneInstanceFactory (
203 : : reinterpret_cast< lang::XMultiServiceFactory* >(pServiceManager),
204 : : FSStorageFactory::impl_staticGetImplementationName(),
205 : : FSStorageFactory::impl_staticCreateSelfInstance,
206 [ + - ][ + - ]: 113 : FSStorageFactory::impl_staticGetSupportedServiceNames() );
[ + - ][ + - ]
[ + - ][ + - ]
207 : : }
208 [ + - ]: 113 : if (xFactory.is())
209 : : {
210 [ + - ]: 113 : xFactory->acquire();
211 [ + - ]: 113 : pResult = xFactory.get();
212 : 113 : }
213 : : }
214 : 113 : return pResult;
215 : : }
216 : :
217 : : } // extern "C"
218 : :
219 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|