Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #if defined WNT
22 : #if defined _MSC_VER
23 : #pragma warning(push, 1)
24 : #endif
25 : #include <windows.h>
26 : #if defined _MSC_VER
27 : #pragma warning(pop)
28 : #endif
29 : #endif
30 :
31 : #include <string>
32 : #include <string.h>
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"
46 :
47 : #include "framework.hxx"
48 : #include "fwkutil.hxx"
49 : #include <boost/scoped_array.hpp>
50 :
51 : using namespace osl;
52 :
53 :
54 : namespace jfw
55 : {
56 :
57 4 : bool isAccessibilitySupportDesired()
58 : {
59 4 : OUString sValue;
60 4 : if (::rtl::Bootstrap::get( "JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY", sValue) &&
61 0 : sValue == "1" )
62 0 : return false;
63 :
64 4 : bool retVal = false;
65 : #ifdef WNT
66 : HKEY hKey = 0;
67 : if (RegOpenKeyEx(HKEY_CURRENT_USER,
68 : "Software\\LibreOffice\\Accessibility\\AtToolSupport",
69 : 0, KEY_READ, &hKey) == ERROR_SUCCESS)
70 : {
71 : DWORD dwType = 0;
72 : DWORD dwLen = 16;
73 : unsigned char arData[16];
74 : if( RegQueryValueEx(hKey, "SupportAssistiveTechnology", NULL, &dwType, arData,
75 : & dwLen)== ERROR_SUCCESS)
76 : {
77 : if (dwType == REG_SZ)
78 : {
79 : if (strcmp((char*) arData, "true") == 0
80 : || strcmp((char*) arData, "1") == 0)
81 : retVal = true;
82 : else if (strcmp((char*) arData, "false") == 0
83 : || strcmp((char*) arData, "0") == 0)
84 : retVal = false;
85 : #if OSL_DEBUG_LEVEL > 1
86 : else
87 : OSL_ASSERT(0);
88 : #endif
89 : }
90 : else if (dwType == REG_DWORD)
91 : {
92 : if (arData[0] == 1)
93 : retVal = true;
94 : else if (arData[0] == 0)
95 : retVal = false;
96 : #if OSL_DEBUG_LEVEL > 1
97 : else
98 : OSL_ASSERT(0);
99 : #endif
100 : }
101 : }
102 : }
103 : RegCloseKey(hKey);
104 :
105 : #elif defined UNX
106 : // Java is no longer required for a11y - we use atk directly.
107 4 : retVal = ::rtl::Bootstrap::get( "JFW_PLUGIN_FORCE_ACCESSIBILITY", sValue) && sValue == "1";
108 : #endif
109 :
110 4 : return retVal;
111 : }
112 :
113 1 : rtl::ByteSequence encodeBase16(const rtl::ByteSequence& rawData)
114 : {
115 : static const char EncodingTable[] =
116 : {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
117 1 : sal_Int32 lenRaw = rawData.getLength();
118 1 : boost::scoped_array<char> pBuf(new char[lenRaw * 2]);
119 1 : const sal_Int8* arRaw = rawData.getConstArray();
120 :
121 1 : char* pCurBuf = pBuf.get();
122 537 : for (int i = 0; i < lenRaw; i++)
123 : {
124 536 : unsigned char curChar = arRaw[i];
125 536 : curChar >>= 4;
126 :
127 536 : *pCurBuf = EncodingTable[curChar];
128 536 : pCurBuf++;
129 :
130 536 : curChar = arRaw[i];
131 536 : curChar &= 0x0F;
132 :
133 536 : *pCurBuf = EncodingTable[curChar];
134 536 : pCurBuf++;
135 : }
136 :
137 1 : rtl::ByteSequence ret(reinterpret_cast<sal_Int8*>(pBuf.get()), lenRaw * 2);
138 1 : return ret;
139 : }
140 :
141 1 : rtl::ByteSequence decodeBase16(const rtl::ByteSequence& data)
142 : {
143 : static const char decodingTable[] =
144 : {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
145 1 : sal_Int32 lenData = data.getLength();
146 1 : sal_Int32 lenBuf = lenData / 2; //always divisable by two
147 1 : boost::scoped_array<unsigned char> pBuf(new unsigned char[lenBuf]);
148 1 : const sal_Int8* pData = data.getConstArray();
149 537 : for (sal_Int32 i = 0; i < lenBuf; i++)
150 : {
151 536 : sal_Int8 curChar = *pData++;
152 : //find the index of the first 4bits
153 : // TODO What happens if text is not valid Hex characters?
154 536 : unsigned char nibble = 0;
155 1798 : for (unsigned char j = 0; j < 16; j++)
156 : {
157 1798 : if (curChar == decodingTable[j])
158 : {
159 536 : nibble = j;
160 536 : break;
161 : }
162 : }
163 536 : nibble <<= 4;
164 536 : curChar = *pData++;
165 : //find the index for the next 4bits
166 2726 : for (unsigned char j = 0; j < 16; j++)
167 : {
168 2726 : if (curChar == decodingTable[j])
169 : {
170 536 : nibble |= j;
171 536 : break;
172 : }
173 : }
174 536 : pBuf[i] = nibble;
175 : }
176 1 : rtl::ByteSequence ret(reinterpret_cast<sal_Int8*>(pBuf.get()), lenBuf );
177 1 : return ret;
178 : }
179 :
180 78 : OUString getDirFromFile(const OUString& usFilePath)
181 : {
182 78 : sal_Int32 index= usFilePath.lastIndexOf('/');
183 78 : return OUString(usFilePath.getStr(), index);
184 : }
185 :
186 77 : OUString getLibraryLocation()
187 : {
188 : OString sExcMsg("[Java framework] Error in function getLibraryLocation "
189 77 : "(fwkutil.cxx).");
190 154 : OUString libraryFileUrl;
191 :
192 77 : if (!osl::Module::getUrlFromAddress(
193 : reinterpret_cast< oslGenericFunction >(getLibraryLocation),
194 77 : libraryFileUrl))
195 0 : throw FrameworkException(JFW_E_ERROR, sExcMsg);
196 :
197 154 : return getDirFromFile(libraryFileUrl);
198 : }
199 :
200 164 : jfw::FileStatus checkFileURL(const OUString & sURL)
201 : {
202 164 : jfw::FileStatus ret = jfw::FILE_OK;
203 164 : DirectoryItem item;
204 164 : File::RC rc_item = DirectoryItem::get(sURL, item);
205 164 : if (File::E_None == rc_item)
206 : {
207 155 : osl::FileStatus status(osl_FileStatus_Mask_Validate);
208 :
209 155 : File::RC rc_stat = item.getFileStatus(status);
210 155 : if (File::E_None == rc_stat)
211 : {
212 155 : ret = FILE_OK;
213 : }
214 0 : else if (File::E_NOENT == rc_stat)
215 : {
216 0 : ret = FILE_DOES_NOT_EXIST;
217 : }
218 : else
219 : {
220 0 : ret = FILE_INVALID;
221 155 : }
222 : }
223 9 : else if (File::E_NOENT == rc_item)
224 : {
225 9 : ret = FILE_DOES_NOT_EXIST;
226 : }
227 : else
228 : {
229 0 : ret = FILE_INVALID;
230 : }
231 164 : return ret;
232 : }
233 :
234 : }
235 :
236 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|