1 /************************************************************************* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * Copyright 2000, 2010 Oracle and/or its affiliates. 5 * 6 * OpenOffice.org - a multi-platform office productivity suite 7 * 8 * This file is part of OpenOffice.org. 9 * 10 * OpenOffice.org is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License version 3 12 * only, as published by the Free Software Foundation. 13 * 14 * OpenOffice.org is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Lesser General Public License version 3 for more details 18 * (a copy is included in the LICENSE file that accompanied this code). 19 * 20 * You should have received a copy of the GNU Lesser General Public License 21 * version 3 along with OpenOffice.org. If not, see 22 * <http://www.openoffice.org/license.html> 23 * for a copy of the LGPLv3 License. 24 ************************************************************************/ 25 26 #include "sal/config.h" 27 28 #include "com/sun/star/uno/Reference.hxx" 29 #include "com/sun/star/uno/RuntimeException.hpp" 30 #include "com/sun/star/uno/XInterface.hpp" 31 #include "osl/file.hxx" 32 #include "osl/process.h" 33 #include "rtl/ustring.hxx" 34 #include "test/toabsolutefileurl.hxx" 35 36 namespace { 37 38 namespace css = com::sun::star; 39 40 } 41 42 namespace test { 43 44 rtl::OUString toAbsoluteFileUrl(rtl::OUString const & relativePathname) { 45 rtl::OUString cwd; 46 oslProcessError e1 = osl_getProcessWorkingDir(&cwd.pData); 47 if (e1 != osl_Process_E_None) { 48 throw css::uno::RuntimeException( 49 (rtl::OUString( 50 RTL_CONSTASCII_USTRINGPARAM( 51 "osl_getProcessWorkingDir failed with ")) + 52 rtl::OUString::valueOf(static_cast< sal_Int32 >(e1))), 53 css::uno::Reference< css::uno::XInterface >()); 54 } 55 rtl::OUString url; 56 osl::FileBase::RC e2 = osl::FileBase::getFileURLFromSystemPath( 57 relativePathname, url); 58 if (e2 != osl::FileBase::E_None) { 59 throw css::uno::RuntimeException( 60 (rtl::OUString( 61 RTL_CONSTASCII_USTRINGPARAM( 62 "osl::FileBase::getFileURLFromSystemPath(")) + 63 relativePathname + 64 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(") failed with ")) + 65 rtl::OUString::valueOf(static_cast< sal_Int32 >(e2))), 66 css::uno::Reference< css::uno::XInterface >()); 67 } 68 rtl::OUString absUrl; 69 e2 = osl::FileBase::getAbsoluteFileURL(cwd, url, absUrl); 70 if (e2 != osl::FileBase::E_None) { 71 throw css::uno::RuntimeException( 72 (rtl::OUString( 73 RTL_CONSTASCII_USTRINGPARAM( 74 "osl::FileBase::getAbsoluteFileURL(")) + 75 cwd + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(", ")) + url + 76 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(") failed with ")) + 77 rtl::OUString::valueOf(static_cast< sal_Int32 >(e2))), 78 css::uno::Reference< css::uno::XInterface >()); 79 } 80 return absUrl; 81 } 82 83 } 84