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