1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
23 #pragma warning(push, 1)
33 #include "osl/mutex.hxx"
34 #include "osl/module.hxx"
35 #include "osl/thread.hxx"
36 #include "rtl/ustring.hxx"
37 #include "rtl/ustrbuf.hxx"
38 #include "rtl/bootstrap.hxx"
39 #include "osl/file.hxx"
40 #include "osl/process.h"
41 #include "rtl/instance.hxx"
42 #include "rtl/uri.hxx"
43 #include "osl/getglobalmutex.hxx"
44 #include "com/sun/star/lang/IllegalArgumentException.hpp"
45 #include "cppuhelper/bootstrap.hxx"
47 #include "framework.hxx"
48 #include "fwkutil.hxx"
56 bool isAccessibilitySupportDesired()
59 if ((sal_True
== ::rtl::Bootstrap::get(
60 OUString("JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY"), sValue
)) && sValue
== "1"
67 if (RegOpenKeyEx(HKEY_CURRENT_USER
,
68 "Software\\LibreOffice\\Accessibility\\AtToolSupport",
69 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
73 unsigned char arData
[16];
74 if( RegQueryValueEx(hKey
, "SupportAssistiveTechnology", NULL
, &dwType
, arData
,
75 & dwLen
)== ERROR_SUCCESS
)
79 if (strcmp((char*) arData
, "true") == 0
80 || strcmp((char*) arData
, "1") == 0)
82 else if (strcmp((char*) arData
, "false") == 0
83 || strcmp((char*) arData
, "0") == 0)
85 #if OSL_DEBUG_LEVEL > 1
90 else if (dwType
== REG_DWORD
)
94 else if (arData
[0] == 0)
96 #if OSL_DEBUG_LEVEL > 1
107 // use 2 shells to suppress the eventual "gcontool-2 not found" message
108 // of the shell trying to execute the command
109 FILE* fp
= popen( "/bin/sh 2>/dev/null -c \"gconftool-2 -g /desktop/gnome/interface/accessibility\"", "r" );
112 if( fgets( buf
, sizeof(buf
), fp
) )
114 int nCompare
= strncasecmp( buf
, "true", 4 );
115 retVal
= (nCompare
== 0 ? true : false);
124 rtl::ByteSequence
encodeBase16(const rtl::ByteSequence
& rawData
)
126 static char EncodingTable
[] =
127 {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
128 sal_Int32 lenRaw
= rawData
.getLength();
129 char* pBuf
= new char[lenRaw
* 2];
130 const sal_Int8
* arRaw
= rawData
.getConstArray();
132 char* pCurBuf
= pBuf
;
133 for (int i
= 0; i
< lenRaw
; i
++)
135 unsigned char curChar
= arRaw
[i
];
138 *pCurBuf
= EncodingTable
[curChar
];
144 *pCurBuf
= EncodingTable
[curChar
];
148 rtl::ByteSequence
ret((sal_Int8
*) pBuf
, lenRaw
* 2);
153 rtl::ByteSequence
decodeBase16(const rtl::ByteSequence
& data
)
155 static char decodingTable
[] =
156 {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
157 sal_Int32 lenData
= data
.getLength();
158 sal_Int32 lenBuf
= lenData
/ 2; //always divisable by two
159 unsigned char* pBuf
= new unsigned char[lenBuf
];
160 const sal_Int8
* pData
= data
.getConstArray();
161 for (sal_Int32 i
= 0; i
< lenBuf
; i
++)
163 sal_Int8 curChar
= *pData
++;
164 //find the index of the first 4bits
165 // TODO What happens if text is not valid Hex characters?
166 unsigned char nibble
= 0;
167 for (unsigned char j
= 0; j
< 16; j
++)
169 if (curChar
== decodingTable
[j
])
177 //find the index for the next 4bits
178 for (unsigned char j
= 0; j
< 16; j
++)
180 if (curChar
== decodingTable
[j
])
188 rtl::ByteSequence
ret((sal_Int8
*) pBuf
, lenBuf
);
193 OUString
getDirFromFile(const OUString
& usFilePath
)
195 sal_Int32 index
= usFilePath
.lastIndexOf('/');
196 return OUString(usFilePath
.getStr(), index
);
199 OUString
getExecutableDirectory()
201 rtl_uString
* sExe
= NULL
;
202 if (osl_getExecutableFile( & sExe
) != osl_Process_E_None
)
203 throw FrameworkException(
205 "[Java framework] Error in function getExecutableDirectory (fwkutil.cxx)");
207 OUString
ouExe(sExe
, SAL_NO_ACQUIRE
);
208 return getDirFromFile(ouExe
);
212 const OUString
& baseUrl
, const OUString
& plugin
)
214 OUString expandedPlugin
;
217 expandedPlugin
= cppu::bootstrap_expandUri(plugin
);
219 catch (const com::sun::star::lang::IllegalArgumentException
& e
)
221 throw FrameworkException(
224 RTL_CONSTASCII_STRINGPARAM(
225 "[Java framework] IllegalArgumentException in"
227 + OUStringToOString(e
.Message
, osl_getThreadTextEncoding())));
232 sUrl
= rtl::Uri::convertRelToAbs(baseUrl
, expandedPlugin
);
234 catch (const rtl::MalformedUriException
& e
)
236 throw FrameworkException(
239 RTL_CONSTASCII_STRINGPARAM(
240 "[Java framework] rtl::MalformedUriException in"
243 e
.getMessage(), osl_getThreadTextEncoding())));
245 if (checkFileURL(sUrl
) == jfw::FILE_OK
)
250 OUString sProgDir
= getExecutableDirectory();
251 sUrl
= sProgDir
+ OUString("/")
253 jfw::FileStatus s
= checkFileURL(sUrl
);
254 if (s
== jfw::FILE_INVALID
|| s
== jfw::FILE_DOES_NOT_EXIST
)
256 //If only the name of the library is given, then
257 //use PATH, LD_LIBRARY_PATH etc. to locate the plugin
258 if (plugin
.indexOf('/') == -1)
263 OUString path
= OUString("DYLD_LIBRARY_PATH");
265 OUString path
= OUString("LIBPATH");
267 OUString path
= OUString("LD_LIBRARY_PATH");
270 oslProcessError err
= osl_getEnvironment(path
.pData
, &env_path
.pData
);
271 if (err
!= osl_Process_E_None
&& err
!= osl_Process_E_NotFound
)
272 throw FrameworkException(
274 "[Java framework] Error in function findPlugin (fwkutil.cxx).");
275 if (err
== osl_Process_E_NotFound
)
277 if (osl_searchFileURL(plugin
.pData
, env_path
.pData
, &url
.pData
)
280 if (osl_searchFileURL(plugin
.pData
, NULL
, &url
.pData
)
285 throw FrameworkException(
287 "[Java framework] Error in function findPlugin (fwkutil.cxx).");
297 OUString
getLibraryLocation()
299 OString
sExcMsg("[Java framework] Error in function getLibraryLocation "
301 OUString libraryFileUrl
;
303 if (!osl::Module::getUrlFromAddress(
304 reinterpret_cast< oslGenericFunction
>(getLibraryLocation
),
306 throw FrameworkException(JFW_E_ERROR
, sExcMsg
);
308 return getDirFromFile(libraryFileUrl
);
311 jfw::FileStatus
checkFileURL(const OUString
& sURL
)
313 jfw::FileStatus ret
= jfw::FILE_OK
;
315 File::RC rc_item
= DirectoryItem::get(sURL
, item
);
316 if (File::E_None
== rc_item
)
318 osl::FileStatus
status(osl_FileStatus_Mask_Validate
);
320 File::RC rc_stat
= item
.getFileStatus(status
);
321 if (File::E_None
== rc_stat
)
325 else if (File::E_NOENT
== rc_stat
)
327 ret
= FILE_DOES_NOT_EXIST
;
334 else if (File::E_NOENT
== rc_item
)
336 ret
= FILE_DOES_NOT_EXIST
;
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */