update dev300-m57
[ooovba.git] / svtools / source / misc1 / folderrestriction.cxx
blob8eb05721f3242e6f6d6d44a4e282727698b9e553
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: folderrestriction.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include "folderrestriction.hxx"
35 #include "osl/process.h"
36 #include "tools/urlobj.hxx"
37 #include "unotools/localfilehelper.hxx"
39 //-----------------------------------------------------------------------------
41 static void convertStringListToUrls (
42 const String& _rColonSeparatedList, ::std::vector< String >& _rTokens, bool _bFinalSlash )
44 const sal_Unicode s_cSeparator =
45 #if defined(WNT)
46 ';'
47 #else
48 ':'
49 #endif
51 xub_StrLen nTokens = _rColonSeparatedList.GetTokenCount( s_cSeparator );
52 _rTokens.resize( 0 ); _rTokens.reserve( nTokens );
53 for ( xub_StrLen i=0; i<nTokens; ++i )
55 // the current token in the list
56 String sCurrentToken = _rColonSeparatedList.GetToken( i, s_cSeparator );
57 if ( !sCurrentToken.Len() )
58 continue;
60 INetURLObject aCurrentURL;
62 String sURL;
63 if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sCurrentToken, sURL ) )
64 aCurrentURL = INetURLObject( sURL );
65 else
67 // smart URL parsing, assuming FILE protocol
68 aCurrentURL = INetURLObject( sCurrentToken, INET_PROT_FILE );
71 if ( _bFinalSlash )
72 aCurrentURL.setFinalSlash( );
73 else
74 aCurrentURL.removeFinalSlash( );
75 _rTokens.push_back( aCurrentURL.GetMainURL( INetURLObject::NO_DECODE ) );
79 /** retrieves the value of an environment variable
80 @return <TRUE/> if and only if the retrieved string value is not empty
82 static bool getEnvironmentValue( const sal_Char* _pAsciiEnvName, ::rtl::OUString& _rValue )
84 _rValue = ::rtl::OUString();
85 ::rtl::OUString sEnvName = ::rtl::OUString::createFromAscii( _pAsciiEnvName );
86 osl_getEnvironment( sEnvName.pData, &_rValue.pData );
87 return _rValue.getLength() != 0;
90 //-----------------------------------------------------------------------------
92 namespace svt
95 void getUnrestrictedFolders( ::std::vector< String >& _rFolders )
97 _rFolders.resize( 0 );
98 ::rtl::OUString sRestrictedPathList;
99 if ( getEnvironmentValue( "RestrictedPath", sRestrictedPathList ) )
101 // append a final slash. This ensures that when we later on check
102 // for unrestricted paths, we don't allow paths like "/home/user35" just because
103 // "/home/user3" is allowed - with the final slash, we make it "/home/user3/".
104 convertStringListToUrls( sRestrictedPathList, _rFolders, true );
108 } // namespace svt