xref: /aoo41x/main/ucb/source/ucp/file/prov.cxx (revision 2f86921c)
1*2f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2f86921cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2f86921cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2f86921cSAndrew Rist  * distributed with this work for additional information
6*2f86921cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2f86921cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2f86921cSAndrew Rist  * "License"); you may not use this file except in compliance
9*2f86921cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2f86921cSAndrew Rist  *
11*2f86921cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2f86921cSAndrew Rist  *
13*2f86921cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2f86921cSAndrew Rist  * software distributed under the License is distributed on an
15*2f86921cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2f86921cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2f86921cSAndrew Rist  * specific language governing permissions and limitations
18*2f86921cSAndrew Rist  * under the License.
19*2f86921cSAndrew Rist  *
20*2f86921cSAndrew Rist  *************************************************************/
21*2f86921cSAndrew Rist 
22*2f86921cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir #include <osl/security.hxx>
27cdf0e10cSrcweir #include <osl/file.hxx>
28cdf0e10cSrcweir #include <osl/socket.h>
29cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
30cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_
31cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include <com/sun/star/ucb/FileSystemNotation.hpp>
34cdf0e10cSrcweir #include <com/sun/star/beans/PropertyState.hpp>
35cdf0e10cSrcweir #include "filglob.hxx"
36cdf0e10cSrcweir #include "filid.hxx"
37cdf0e10cSrcweir #include "shell.hxx"
38cdf0e10cSrcweir #include "bc.hxx"
39cdf0e10cSrcweir #include "prov.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using namespace fileaccess;
43cdf0e10cSrcweir using namespace com::sun::star;
44cdf0e10cSrcweir using namespace com::sun::star::uno;
45cdf0e10cSrcweir using namespace com::sun::star::lang;
46cdf0e10cSrcweir using namespace com::sun::star::beans;
47cdf0e10cSrcweir using namespace com::sun::star::ucb;
48cdf0e10cSrcweir using namespace com::sun::star::container;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //=========================================================================
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)51cdf0e10cSrcweir extern "C" void SAL_CALL component_getImplementationEnvironment(
52cdf0e10cSrcweir 	const sal_Char ** ppEnvTypeName, uno_Environment ** )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //=========================================================================
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void *)58cdf0e10cSrcweir extern "C" void * SAL_CALL component_getFactory(
59cdf0e10cSrcweir 	const sal_Char * pImplName, void * pServiceManager, void * )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	void * pRet = 0;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xSMgr(
64cdf0e10cSrcweir 			reinterpret_cast< XMultiServiceFactory * >( pServiceManager ) );
65cdf0e10cSrcweir 	Reference< XSingleServiceFactory > xFactory;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
68cdf0e10cSrcweir 	// File Content Provider.
69cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	if ( fileaccess::shell::getImplementationName_static().
72cdf0e10cSrcweir 			compareToAscii( pImplName ) == 0 )
73cdf0e10cSrcweir 	{
74cdf0e10cSrcweir 		xFactory = FileProvider::createServiceFactory( xSMgr );
75cdf0e10cSrcweir 	}
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	if ( xFactory.is() )
80cdf0e10cSrcweir 	{
81cdf0e10cSrcweir 		xFactory->acquire();
82cdf0e10cSrcweir 		pRet = xFactory.get();
83cdf0e10cSrcweir 	}
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	return pRet;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir /****************************************************************************/
89cdf0e10cSrcweir /*                                                                          */
90cdf0e10cSrcweir /*                                                                          */
91cdf0e10cSrcweir /*                        FileProvider                                      */
92cdf0e10cSrcweir /*                                                                          */
93cdf0e10cSrcweir /*                                                                          */
94cdf0e10cSrcweir /****************************************************************************/
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 
FileProvider(const Reference<XMultiServiceFactory> & xMultiServiceFactory)98cdf0e10cSrcweir FileProvider::FileProvider( const Reference< XMultiServiceFactory >& xMultiServiceFactory )
99cdf0e10cSrcweir 	: m_xMultiServiceFactory( xMultiServiceFactory ),
100cdf0e10cSrcweir 	  m_pMyShell( 0 )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 
~FileProvider()105cdf0e10cSrcweir FileProvider::~FileProvider()
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	if( m_pMyShell )
108cdf0e10cSrcweir 		delete m_pMyShell;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 
112cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
113cdf0e10cSrcweir // XInterface
114cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
115cdf0e10cSrcweir 
116cdf0e10cSrcweir void SAL_CALL
acquire(void)117cdf0e10cSrcweir FileProvider::acquire(
118cdf0e10cSrcweir 	void )
119cdf0e10cSrcweir 	throw()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir   OWeakObject::acquire();
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 
125cdf0e10cSrcweir void SAL_CALL
release(void)126cdf0e10cSrcweir FileProvider::release(
127cdf0e10cSrcweir 	void )
128cdf0e10cSrcweir   throw()
129cdf0e10cSrcweir {
130cdf0e10cSrcweir   OWeakObject::release();
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 
134cdf0e10cSrcweir Any SAL_CALL
queryInterface(const Type & rType)135cdf0e10cSrcweir FileProvider::queryInterface(
136cdf0e10cSrcweir 	const Type& rType )
137cdf0e10cSrcweir 	throw( RuntimeException )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir 	Any aRet = cppu::queryInterface(
140cdf0e10cSrcweir         rType,
141cdf0e10cSrcweir         SAL_STATIC_CAST( XContentProvider*, this ),
142cdf0e10cSrcweir         SAL_STATIC_CAST( XInitialization*, this ),
143cdf0e10cSrcweir         SAL_STATIC_CAST( XContentIdentifierFactory*, this ),
144cdf0e10cSrcweir         SAL_STATIC_CAST( XServiceInfo*,     this ),
145cdf0e10cSrcweir         SAL_STATIC_CAST( XTypeProvider*,    this ),
146cdf0e10cSrcweir         SAL_STATIC_CAST( XFileIdentifierConverter*,this ),
147cdf0e10cSrcweir         SAL_STATIC_CAST( XPropertySet*, this ) );
148cdf0e10cSrcweir 	return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
152cdf0e10cSrcweir // XInitialization
153cdf0e10cSrcweir 
init()154cdf0e10cSrcweir void SAL_CALL FileProvider::init()
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     if( ! m_pMyShell )
157cdf0e10cSrcweir         m_pMyShell = new shell( m_xMultiServiceFactory, this, sal_True );
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 
161cdf0e10cSrcweir void SAL_CALL
initialize(const Sequence<Any> & aArguments)162cdf0e10cSrcweir FileProvider::initialize(
163cdf0e10cSrcweir     const Sequence< Any >& aArguments )
164cdf0e10cSrcweir     throw (Exception, RuntimeException)
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     if( ! m_pMyShell ) {
167cdf0e10cSrcweir         rtl::OUString config;
168cdf0e10cSrcweir         if( aArguments.getLength() > 0 &&
169cdf0e10cSrcweir             (aArguments[0] >>= config) &&
170cdf0e10cSrcweir             config.compareToAscii("NoConfig") == 0 )
171cdf0e10cSrcweir             m_pMyShell = new shell( m_xMultiServiceFactory, this, sal_False );
172cdf0e10cSrcweir         else
173cdf0e10cSrcweir             m_pMyShell = new shell( m_xMultiServiceFactory, this, sal_True );
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 
178cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
179cdf0e10cSrcweir //
180cdf0e10cSrcweir // XTypeProvider methods.
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 
XTYPEPROVIDER_IMPL_7(FileProvider,XTypeProvider,XServiceInfo,XInitialization,XContentIdentifierFactory,XPropertySet,XFileIdentifierConverter,XContentProvider)183cdf0e10cSrcweir XTYPEPROVIDER_IMPL_7( FileProvider,
184cdf0e10cSrcweir 				   	  XTypeProvider,
185cdf0e10cSrcweir 				   	  XServiceInfo,
186cdf0e10cSrcweir                       XInitialization,
187cdf0e10cSrcweir                       XContentIdentifierFactory,
188cdf0e10cSrcweir 					  XPropertySet,
189cdf0e10cSrcweir   					  XFileIdentifierConverter,
190cdf0e10cSrcweir   				   	  XContentProvider )
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 
193cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
194cdf0e10cSrcweir // XServiceInfo methods.
195cdf0e10cSrcweir 
196cdf0e10cSrcweir rtl::OUString SAL_CALL
197cdf0e10cSrcweir FileProvider::getImplementationName()
198cdf0e10cSrcweir 	throw( RuntimeException )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	return fileaccess::shell::getImplementationName_static();
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 
204cdf0e10cSrcweir sal_Bool SAL_CALL
supportsService(const rtl::OUString & ServiceName)205cdf0e10cSrcweir FileProvider::supportsService(
206cdf0e10cSrcweir 			      const rtl::OUString& ServiceName )
207cdf0e10cSrcweir   throw( RuntimeException )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir   return ServiceName == rtl::OUString::createFromAscii( "com.sun.star.ucb.FileContentProvider" );
210cdf0e10cSrcweir }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 
213cdf0e10cSrcweir Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames(void)214cdf0e10cSrcweir FileProvider::getSupportedServiceNames(
215cdf0e10cSrcweir 				       void )
216cdf0e10cSrcweir   throw( RuntimeException )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir 	return fileaccess::shell::getSupportedServiceNames_static();
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 
223cdf0e10cSrcweir Reference< XSingleServiceFactory > SAL_CALL
createServiceFactory(const Reference<XMultiServiceFactory> & rxServiceMgr)224cdf0e10cSrcweir FileProvider::createServiceFactory(
225cdf0e10cSrcweir 				   const Reference< XMultiServiceFactory >& rxServiceMgr )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir   /**
228cdf0e10cSrcweir    * Create a single service factory.<BR>
229cdf0e10cSrcweir    * Note: The function pointer ComponentInstantiation points to a function throws Exception.
230cdf0e10cSrcweir    *
231cdf0e10cSrcweir    * @param rServiceManager		the service manager used by the implementation.
232cdf0e10cSrcweir    * @param rImplementationName	the implementation name. An empty string is possible.
233cdf0e10cSrcweir    * @param ComponentInstantiation the function pointer to create an object.
234cdf0e10cSrcweir    * @param rServiceNames			the service supported by the implementation.
235cdf0e10cSrcweir    * @return a factory that support the interfaces XServiceProvider, XServiceInfo
236cdf0e10cSrcweir    *			XSingleServiceFactory and XComponent.
237cdf0e10cSrcweir    *
238cdf0e10cSrcweir    * @see createOneInstanceFactory
239cdf0e10cSrcweir    */
240cdf0e10cSrcweir   /*
241cdf0e10cSrcweir    *  Reference< ::com::sun::star::XSingleServiceFactory > createSingleFactory
242cdf0e10cSrcweir    *  (
243cdf0e10cSrcweir    *  const ::com::sun::star::Reference< ::com::sun::star::XMultiServiceFactory > & rServiceManager,
244cdf0e10cSrcweir    *  const ::rtl::OUString & rImplementationName,
245cdf0e10cSrcweir    *  ComponentInstantiation pCreateFunction,
246cdf0e10cSrcweir 
247cdf0e10cSrcweir    *  const ::com::sun::star::Sequence< ::rtl::OUString > & rServiceNames
248cdf0e10cSrcweir    *  );
249cdf0e10cSrcweir    */
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 	return Reference< XSingleServiceFactory > ( cppu::createSingleFactory(
252cdf0e10cSrcweir 		rxServiceMgr,
253cdf0e10cSrcweir 		fileaccess::shell::getImplementationName_static(),
254cdf0e10cSrcweir 		FileProvider::CreateInstance,
255cdf0e10cSrcweir 		fileaccess::shell::getSupportedServiceNames_static() ) );
256cdf0e10cSrcweir }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir Reference< XInterface > SAL_CALL
CreateInstance(const Reference<XMultiServiceFactory> & xMultiServiceFactory)259cdf0e10cSrcweir FileProvider::CreateInstance(
260cdf0e10cSrcweir 	const Reference< XMultiServiceFactory >& xMultiServiceFactory )
261cdf0e10cSrcweir {
262cdf0e10cSrcweir 	XServiceInfo* xP = (XServiceInfo*) new FileProvider( xMultiServiceFactory );
263cdf0e10cSrcweir 	return Reference< XInterface >::query( xP );
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 
268cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
269cdf0e10cSrcweir // XContent
270cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 
273cdf0e10cSrcweir Reference< XContent > SAL_CALL
queryContent(const Reference<XContentIdentifier> & xIdentifier)274cdf0e10cSrcweir FileProvider::queryContent(
275cdf0e10cSrcweir 	const Reference< XContentIdentifier >& xIdentifier )
276cdf0e10cSrcweir 	throw( IllegalIdentifierException,
277cdf0e10cSrcweir 		   RuntimeException)
278cdf0e10cSrcweir {
279cdf0e10cSrcweir     init();
280cdf0e10cSrcweir 	rtl::OUString aUnc;
281cdf0e10cSrcweir 	sal_Bool err = m_pMyShell->getUnqFromUrl( xIdentifier->getContentIdentifier(),
282cdf0e10cSrcweir 											  aUnc );
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 	if(  err )
285cdf0e10cSrcweir 		throw IllegalIdentifierException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
286cdf0e10cSrcweir 
287cdf0e10cSrcweir     return Reference< XContent >( new BaseContent( m_pMyShell,xIdentifier,aUnc ) );
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 
292cdf0e10cSrcweir sal_Int32 SAL_CALL
compareContentIds(const Reference<XContentIdentifier> & Id1,const Reference<XContentIdentifier> & Id2)293cdf0e10cSrcweir FileProvider::compareContentIds(
294cdf0e10cSrcweir 				const Reference< XContentIdentifier >& Id1,
295cdf0e10cSrcweir 				const Reference< XContentIdentifier >& Id2 )
296cdf0e10cSrcweir   throw( RuntimeException )
297cdf0e10cSrcweir {
298cdf0e10cSrcweir     init();
299cdf0e10cSrcweir 	rtl::OUString aUrl1 = Id1->getContentIdentifier();
300cdf0e10cSrcweir 	rtl::OUString aUrl2 = Id2->getContentIdentifier();
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 	sal_Int32	iComp = aUrl1.compareTo( aUrl2 );
303cdf0e10cSrcweir 
304cdf0e10cSrcweir 	if ( 0 != iComp )
305cdf0e10cSrcweir 	{
306cdf0e10cSrcweir         rtl::OUString aPath1, aPath2;
307cdf0e10cSrcweir 
308cdf0e10cSrcweir         m_pMyShell->getUnqFromUrl( aUrl1, aPath1 );
309cdf0e10cSrcweir         m_pMyShell->getUnqFromUrl( aUrl2, aPath2 );
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 		osl::FileBase::RC	error;
312cdf0e10cSrcweir 		osl::DirectoryItem	aItem1, aItem2;
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 		error = osl::DirectoryItem::get( aPath1, aItem1 );
315cdf0e10cSrcweir 		if ( error == osl::FileBase::E_None )
316cdf0e10cSrcweir 			error = osl::DirectoryItem::get( aPath2, aItem2 );
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 		if ( error != osl::FileBase::E_None )
319cdf0e10cSrcweir 			return iComp;
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 		osl::FileStatus	aStatus1( FileStatusMask_FileURL );
322cdf0e10cSrcweir 		osl::FileStatus	aStatus2( FileStatusMask_FileURL );
323cdf0e10cSrcweir 		error = aItem1.getFileStatus( aStatus1 );
324cdf0e10cSrcweir 		if ( error == osl::FileBase::E_None )
325cdf0e10cSrcweir 			error = aItem2.getFileStatus( aStatus2 );
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 		if ( error == osl::FileBase::E_None )
328cdf0e10cSrcweir 		{
329cdf0e10cSrcweir 			iComp = aStatus1.getFileURL().compareTo( aStatus2.getFileURL() );
330cdf0e10cSrcweir 
331cdf0e10cSrcweir // Quick hack for Windows to threat all file systems as case insensitive
332cdf0e10cSrcweir #ifdef	WNT
333cdf0e10cSrcweir 			if ( 0 != iComp )
334cdf0e10cSrcweir 			{
335cdf0e10cSrcweir 				error = osl::FileBase::getSystemPathFromFileURL( aStatus1.getFileURL(), aPath1 );
336cdf0e10cSrcweir 				if ( error == osl::FileBase::E_None )
337cdf0e10cSrcweir 					error = osl::FileBase::getSystemPathFromFileURL( aStatus2.getFileURL(), aPath2 );
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 				if ( error == osl::FileBase::E_None )
340cdf0e10cSrcweir 					iComp = rtl_ustr_compareIgnoreAsciiCase( aPath1.getStr(), aPath2.getStr() );
341cdf0e10cSrcweir 			}
342cdf0e10cSrcweir #endif
343cdf0e10cSrcweir 		}
344cdf0e10cSrcweir 	}
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	return iComp;
347cdf0e10cSrcweir }
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 
351cdf0e10cSrcweir Reference< XContentIdentifier > SAL_CALL
createContentIdentifier(const rtl::OUString & ContentId)352cdf0e10cSrcweir FileProvider::createContentIdentifier(
353cdf0e10cSrcweir 				      const rtl::OUString& ContentId )
354cdf0e10cSrcweir   throw( RuntimeException )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir     init();
357cdf0e10cSrcweir 	FileContentIdentifier* p = new FileContentIdentifier( m_pMyShell,ContentId,false );
358cdf0e10cSrcweir 	return Reference< XContentIdentifier >( p );
359cdf0e10cSrcweir }
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 
363cdf0e10cSrcweir //XPropertySetInfoImpl
364cdf0e10cSrcweir 
365cdf0e10cSrcweir class XPropertySetInfoImpl2
366cdf0e10cSrcweir 	: public cppu::OWeakObject,
367cdf0e10cSrcweir 	  public XPropertySetInfo
368cdf0e10cSrcweir {
369cdf0e10cSrcweir public:
370cdf0e10cSrcweir 	XPropertySetInfoImpl2();
371cdf0e10cSrcweir 	~XPropertySetInfoImpl2();
372cdf0e10cSrcweir 
373cdf0e10cSrcweir 	// XInterface
374cdf0e10cSrcweir 	virtual Any SAL_CALL
375cdf0e10cSrcweir 	queryInterface(
376cdf0e10cSrcweir 		const Type& aType )
377cdf0e10cSrcweir 		throw( RuntimeException);
378cdf0e10cSrcweir 
379cdf0e10cSrcweir 	virtual void SAL_CALL
380cdf0e10cSrcweir 	acquire(
381cdf0e10cSrcweir 		void )
382cdf0e10cSrcweir 		throw();
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 	virtual void SAL_CALL
385cdf0e10cSrcweir 	release(
386cdf0e10cSrcweir 		void )
387cdf0e10cSrcweir 		throw();
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 	virtual Sequence< Property > SAL_CALL
391cdf0e10cSrcweir 	getProperties(
392cdf0e10cSrcweir 		void )
393cdf0e10cSrcweir 		throw( RuntimeException );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	virtual Property SAL_CALL
396cdf0e10cSrcweir 	getPropertyByName(
397cdf0e10cSrcweir 		const rtl::OUString& aName )
398cdf0e10cSrcweir 		throw( UnknownPropertyException,
399cdf0e10cSrcweir 			   RuntimeException);
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL
402cdf0e10cSrcweir 	hasPropertyByName( const rtl::OUString& Name )
403cdf0e10cSrcweir 		throw( RuntimeException );
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 
406cdf0e10cSrcweir private:
407cdf0e10cSrcweir 	Sequence< Property > m_seq;
408cdf0e10cSrcweir };
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 
XPropertySetInfoImpl2()411cdf0e10cSrcweir XPropertySetInfoImpl2::XPropertySetInfoImpl2()
412cdf0e10cSrcweir 	: m_seq( 3 )
413cdf0e10cSrcweir {
414cdf0e10cSrcweir 	m_seq[0] = Property( rtl::OUString::createFromAscii( "HostName" ),
415cdf0e10cSrcweir 						 -1,
416cdf0e10cSrcweir 						 getCppuType( static_cast< rtl::OUString* >( 0 ) ),
417cdf0e10cSrcweir 						 PropertyAttribute::READONLY );
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 	m_seq[1] = Property( rtl::OUString::createFromAscii( "HomeDirectory" ),
420cdf0e10cSrcweir 						 -1,
421cdf0e10cSrcweir 						 getCppuType( static_cast< rtl::OUString* >( 0 ) ),
422cdf0e10cSrcweir 						 PropertyAttribute::READONLY );
423cdf0e10cSrcweir 
424cdf0e10cSrcweir 	m_seq[2] = Property( rtl::OUString::createFromAscii( "FileSystemNotation" ),
425cdf0e10cSrcweir 						 -1,
426cdf0e10cSrcweir 						 getCppuType( static_cast< sal_Int32* >( 0 ) ),
427cdf0e10cSrcweir 						 PropertyAttribute::READONLY );
428cdf0e10cSrcweir }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 
~XPropertySetInfoImpl2()431cdf0e10cSrcweir XPropertySetInfoImpl2::~XPropertySetInfoImpl2()
432cdf0e10cSrcweir {
433cdf0e10cSrcweir 	// nothing
434cdf0e10cSrcweir }
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 
437cdf0e10cSrcweir void SAL_CALL
acquire(void)438cdf0e10cSrcweir XPropertySetInfoImpl2::acquire(
439cdf0e10cSrcweir 	void )
440cdf0e10cSrcweir 	throw()
441cdf0e10cSrcweir {
442cdf0e10cSrcweir 	OWeakObject::acquire();
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir 
446cdf0e10cSrcweir void SAL_CALL
release(void)447cdf0e10cSrcweir XPropertySetInfoImpl2::release(
448cdf0e10cSrcweir 	void )
449cdf0e10cSrcweir 	throw()
450cdf0e10cSrcweir {
451cdf0e10cSrcweir 	OWeakObject::release();
452cdf0e10cSrcweir }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir 
455cdf0e10cSrcweir Any SAL_CALL
queryInterface(const Type & rType)456cdf0e10cSrcweir XPropertySetInfoImpl2::queryInterface(
457cdf0e10cSrcweir 	const Type& rType )
458cdf0e10cSrcweir 	throw( RuntimeException )
459cdf0e10cSrcweir {
460cdf0e10cSrcweir 	Any aRet = cppu::queryInterface( rType,
461cdf0e10cSrcweir 										  SAL_STATIC_CAST( XPropertySetInfo*,this) );
462cdf0e10cSrcweir 	return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 
466cdf0e10cSrcweir Property SAL_CALL
getPropertyByName(const rtl::OUString & aName)467cdf0e10cSrcweir XPropertySetInfoImpl2::getPropertyByName(
468cdf0e10cSrcweir 	const rtl::OUString& aName )
469cdf0e10cSrcweir 	throw( UnknownPropertyException,
470cdf0e10cSrcweir 		   RuntimeException)
471cdf0e10cSrcweir {
472cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < m_seq.getLength(); ++i )
473cdf0e10cSrcweir 		if( m_seq[i].Name == aName )
474cdf0e10cSrcweir 			return m_seq[i];
475cdf0e10cSrcweir 
476cdf0e10cSrcweir 	throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
477cdf0e10cSrcweir }
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 
481cdf0e10cSrcweir Sequence< Property > SAL_CALL
getProperties(void)482cdf0e10cSrcweir XPropertySetInfoImpl2::getProperties(
483cdf0e10cSrcweir 	void )
484cdf0e10cSrcweir 	throw( RuntimeException )
485cdf0e10cSrcweir {
486cdf0e10cSrcweir 	return m_seq;
487cdf0e10cSrcweir }
488cdf0e10cSrcweir 
489cdf0e10cSrcweir 
490cdf0e10cSrcweir sal_Bool SAL_CALL
hasPropertyByName(const rtl::OUString & aName)491cdf0e10cSrcweir XPropertySetInfoImpl2::hasPropertyByName(
492cdf0e10cSrcweir 	const rtl::OUString& aName )
493cdf0e10cSrcweir 	throw( RuntimeException )
494cdf0e10cSrcweir {
495cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < m_seq.getLength(); ++i )
496cdf0e10cSrcweir 		if( m_seq[i].Name == aName )
497cdf0e10cSrcweir 			return true;
498cdf0e10cSrcweir 	return false;
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 
initProperties(void)505cdf0e10cSrcweir void SAL_CALL FileProvider::initProperties( void )
506cdf0e10cSrcweir {
507cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
508cdf0e10cSrcweir 	if( ! m_xPropertySetInfo.is() )
509cdf0e10cSrcweir 	{
510cdf0e10cSrcweir 		osl_getLocalHostname( &m_HostName.pData );
511cdf0e10cSrcweir 
512cdf0e10cSrcweir #if defined ( UNX )
513cdf0e10cSrcweir 		m_FileSystemNotation = FileSystemNotation::UNIX_NOTATION;
514cdf0e10cSrcweir #elif defined( WNT ) || defined( OS2 )
515cdf0e10cSrcweir 		m_FileSystemNotation = FileSystemNotation::DOS_NOTATION;
516cdf0e10cSrcweir #else
517cdf0e10cSrcweir 		m_FileSystemNotation = FileSystemNotation::UNKNOWN_NOTATION;
518cdf0e10cSrcweir #endif
519cdf0e10cSrcweir         osl::Security aSecurity;
520cdf0e10cSrcweir         aSecurity.getHomeDir( m_HomeDirectory );
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 		// static const sal_Int32 UNKNOWN_NOTATION = (sal_Int32)0;
523cdf0e10cSrcweir 		// static const sal_Int32 UNIX_NOTATION = (sal_Int32)1;
524cdf0e10cSrcweir 		// static const sal_Int32 DOS_NOTATION = (sal_Int32)2;
525cdf0e10cSrcweir 		// static const sal_Int32 MAC_NOTATION = (sal_Int32)3;
526cdf0e10cSrcweir 
527cdf0e10cSrcweir 		XPropertySetInfoImpl2* p = new XPropertySetInfoImpl2();
528cdf0e10cSrcweir 		m_xPropertySetInfo = Reference< XPropertySetInfo >( p );
529cdf0e10cSrcweir 	}
530cdf0e10cSrcweir }
531cdf0e10cSrcweir 
532cdf0e10cSrcweir 
533cdf0e10cSrcweir // XPropertySet
534cdf0e10cSrcweir 
535cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL
getPropertySetInfo()536cdf0e10cSrcweir FileProvider::getPropertySetInfo(  )
537cdf0e10cSrcweir 	throw( RuntimeException )
538cdf0e10cSrcweir {
539cdf0e10cSrcweir 	initProperties();
540cdf0e10cSrcweir 	return m_xPropertySetInfo;
541cdf0e10cSrcweir }
542cdf0e10cSrcweir 
543cdf0e10cSrcweir 
544cdf0e10cSrcweir void SAL_CALL
setPropertyValue(const rtl::OUString & aPropertyName,const Any &)545cdf0e10cSrcweir FileProvider::setPropertyValue( const rtl::OUString& aPropertyName,
546cdf0e10cSrcweir 								const Any& )
547cdf0e10cSrcweir 	throw( UnknownPropertyException,
548cdf0e10cSrcweir 		   PropertyVetoException,
549cdf0e10cSrcweir 		   IllegalArgumentException,
550cdf0e10cSrcweir 		   WrappedTargetException,
551cdf0e10cSrcweir 		   RuntimeException )
552cdf0e10cSrcweir {
553cdf0e10cSrcweir 	if( aPropertyName.compareToAscii( "FileSystemNotation" ) == 0 ||
554cdf0e10cSrcweir 		aPropertyName.compareToAscii( "HomeDirectory" ) == 0      ||
555cdf0e10cSrcweir 		aPropertyName.compareToAscii( "HostName" ) == 0 )
556cdf0e10cSrcweir 		return;
557cdf0e10cSrcweir 	else
558cdf0e10cSrcweir 		throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
559cdf0e10cSrcweir }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 
562cdf0e10cSrcweir 
563cdf0e10cSrcweir Any SAL_CALL
getPropertyValue(const rtl::OUString & aPropertyName)564cdf0e10cSrcweir FileProvider::getPropertyValue(
565cdf0e10cSrcweir 	const rtl::OUString& aPropertyName )
566cdf0e10cSrcweir 	throw( UnknownPropertyException,
567cdf0e10cSrcweir 		   WrappedTargetException,
568cdf0e10cSrcweir 		   RuntimeException )
569cdf0e10cSrcweir {
570cdf0e10cSrcweir 	initProperties();
571cdf0e10cSrcweir 	if( aPropertyName.compareToAscii( "FileSystemNotation" ) == 0 )
572cdf0e10cSrcweir 	{
573cdf0e10cSrcweir 		Any aAny;
574cdf0e10cSrcweir 		aAny <<= m_FileSystemNotation;
575cdf0e10cSrcweir 		return aAny;
576cdf0e10cSrcweir 	}
577cdf0e10cSrcweir 	else if( aPropertyName.compareToAscii( "HomeDirectory" ) == 0 )
578cdf0e10cSrcweir 	{
579cdf0e10cSrcweir 		Any aAny;
580cdf0e10cSrcweir 		aAny <<= m_HomeDirectory;
581cdf0e10cSrcweir 		return aAny;
582cdf0e10cSrcweir 	}
583cdf0e10cSrcweir 	else if( aPropertyName.compareToAscii( "HostName" ) == 0 )
584cdf0e10cSrcweir 	{
585cdf0e10cSrcweir 		Any aAny;
586cdf0e10cSrcweir 		aAny <<= m_HostName;
587cdf0e10cSrcweir 		return aAny;
588cdf0e10cSrcweir 	}
589cdf0e10cSrcweir 	else
590cdf0e10cSrcweir 		throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
591cdf0e10cSrcweir }
592cdf0e10cSrcweir 
593cdf0e10cSrcweir 
594cdf0e10cSrcweir void SAL_CALL
addPropertyChangeListener(const rtl::OUString &,const Reference<XPropertyChangeListener> &)595cdf0e10cSrcweir FileProvider::addPropertyChangeListener(
596cdf0e10cSrcweir 	const rtl::OUString&,
597cdf0e10cSrcweir 	const Reference< XPropertyChangeListener >& )
598cdf0e10cSrcweir 	throw( UnknownPropertyException,
599cdf0e10cSrcweir 		   WrappedTargetException,
600cdf0e10cSrcweir 		   RuntimeException)
601cdf0e10cSrcweir {
602cdf0e10cSrcweir 	return;
603cdf0e10cSrcweir }
604cdf0e10cSrcweir 
605cdf0e10cSrcweir 
606cdf0e10cSrcweir void SAL_CALL
removePropertyChangeListener(const rtl::OUString &,const Reference<XPropertyChangeListener> &)607cdf0e10cSrcweir FileProvider::removePropertyChangeListener(
608cdf0e10cSrcweir 	const rtl::OUString&,
609cdf0e10cSrcweir 	const Reference< XPropertyChangeListener >& )
610cdf0e10cSrcweir 	throw( UnknownPropertyException,
611cdf0e10cSrcweir 		   WrappedTargetException,
612cdf0e10cSrcweir 		   RuntimeException )
613cdf0e10cSrcweir {
614cdf0e10cSrcweir 	return;
615cdf0e10cSrcweir }
616cdf0e10cSrcweir 
617cdf0e10cSrcweir void SAL_CALL
addVetoableChangeListener(const rtl::OUString &,const Reference<XVetoableChangeListener> &)618cdf0e10cSrcweir FileProvider::addVetoableChangeListener(
619cdf0e10cSrcweir 	const rtl::OUString&,
620cdf0e10cSrcweir 	const Reference< XVetoableChangeListener >& )
621cdf0e10cSrcweir 	throw( UnknownPropertyException,
622cdf0e10cSrcweir 		   WrappedTargetException,
623cdf0e10cSrcweir 		   RuntimeException )
624cdf0e10cSrcweir {
625cdf0e10cSrcweir 	return;
626cdf0e10cSrcweir }
627cdf0e10cSrcweir 
628cdf0e10cSrcweir 
629cdf0e10cSrcweir void SAL_CALL
removeVetoableChangeListener(const rtl::OUString &,const Reference<XVetoableChangeListener> &)630cdf0e10cSrcweir FileProvider::removeVetoableChangeListener(
631cdf0e10cSrcweir 	const rtl::OUString&,
632cdf0e10cSrcweir 	const Reference< XVetoableChangeListener >& )
633cdf0e10cSrcweir 	throw( UnknownPropertyException,
634cdf0e10cSrcweir 		   WrappedTargetException,
635cdf0e10cSrcweir 		   RuntimeException)
636cdf0e10cSrcweir {
637cdf0e10cSrcweir 	return;
638cdf0e10cSrcweir }
639cdf0e10cSrcweir 
640cdf0e10cSrcweir 
641cdf0e10cSrcweir 
642cdf0e10cSrcweir // XFileIdentifierConverter
643cdf0e10cSrcweir 
644cdf0e10cSrcweir sal_Int32 SAL_CALL
getFileProviderLocality(const rtl::OUString & BaseURL)645cdf0e10cSrcweir FileProvider::getFileProviderLocality( const rtl::OUString& BaseURL )
646cdf0e10cSrcweir 	throw( RuntimeException )
647cdf0e10cSrcweir {
648cdf0e10cSrcweir 	// If the base URL is a 'file' URL, return 10 (very 'local'), otherwise
649cdf0e10cSrcweir 	// return -1 (missmatch).  What is missing is a fast comparison to ASCII,
650cdf0e10cSrcweir 	// ignoring case:
651cdf0e10cSrcweir 	return BaseURL.getLength() >= 5
652cdf0e10cSrcweir 		   && (BaseURL[0] == 'F' || BaseURL[0] == 'f')
653cdf0e10cSrcweir 		   && (BaseURL[1] == 'I' || BaseURL[1] == 'i')
654cdf0e10cSrcweir 		   && (BaseURL[2] == 'L' || BaseURL[2] == 'l')
655cdf0e10cSrcweir 		   && (BaseURL[3] == 'E' || BaseURL[3] == 'e')
656cdf0e10cSrcweir 		   && BaseURL[4] == ':' ?
657cdf0e10cSrcweir 		       10 : -1;
658cdf0e10cSrcweir }
659cdf0e10cSrcweir 
getFileURLFromSystemPath(const rtl::OUString &,const rtl::OUString & SystemPath)660cdf0e10cSrcweir rtl::OUString SAL_CALL FileProvider::getFileURLFromSystemPath( const rtl::OUString&,
661cdf0e10cSrcweir 															   const rtl::OUString& SystemPath )
662cdf0e10cSrcweir 	throw( RuntimeException )
663cdf0e10cSrcweir {
664cdf0e10cSrcweir 	rtl::OUString aNormalizedPath;
665cdf0e10cSrcweir 	if ( osl::FileBase::getFileURLFromSystemPath( SystemPath,aNormalizedPath ) != osl::FileBase::E_None )
666cdf0e10cSrcweir 		return rtl::OUString();
667cdf0e10cSrcweir 
668cdf0e10cSrcweir     return aNormalizedPath;
669cdf0e10cSrcweir }
670cdf0e10cSrcweir 
getSystemPathFromFileURL(const rtl::OUString & URL)671cdf0e10cSrcweir rtl::OUString SAL_CALL FileProvider::getSystemPathFromFileURL( const rtl::OUString& URL )
672cdf0e10cSrcweir 	throw( RuntimeException )
673cdf0e10cSrcweir {
674cdf0e10cSrcweir 	rtl::OUString aSystemPath;
675cdf0e10cSrcweir     if (osl::FileBase::getSystemPathFromFileURL( URL,aSystemPath ) != osl::FileBase::E_None )
676cdf0e10cSrcweir 		return rtl::OUString();
677cdf0e10cSrcweir 
678cdf0e10cSrcweir 	return aSystemPath;
679cdf0e10cSrcweir }
680cdf0e10cSrcweir 
681