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 .
22 #if !defined WIN32_LEAN_AND_MEAN
23 # define WIN32_LEAN_AND_MEAN
29 #include <osl/module.hxx>
30 #include <rtl/ustring.hxx>
31 #include <osl/file.hxx>
32 #include <sal/log.hxx>
34 #include "framework.hxx"
35 #include <fwkutil.hxx>
44 /** provides a bootstrap class which already knows the values from the
47 const rtl::Bootstrap
* Bootstrap()
49 static const rtl::Bootstrap
* SINGLETON
= []()
51 OUString sIni
= getLibraryLocation() +
53 // For some reason the jvmfwk3rc file is traditionally in
54 // LIBO_URE_ETC_FOLDER
55 "/../" LIBO_URE_ETC_FOLDER
57 SAL_CONFIGFILE("/jvmfwk3");
58 ::rtl::Bootstrap
* bootstrap
= new ::rtl::Bootstrap(sIni
);
59 SAL_INFO("jfw.level2", "Using configuration file " << sIni
);
65 osl::Mutex
& FwkMutex()
67 static osl::Mutex SINGLETON
;
72 rtl::ByteSequence
encodeBase16(const rtl::ByteSequence
& rawData
)
74 static const char EncodingTable
[] =
75 {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
76 sal_Int32 lenRaw
= rawData
.getLength();
77 std::unique_ptr
<char[]> pBuf(new char[lenRaw
* 2]);
78 const sal_Int8
* arRaw
= rawData
.getConstArray();
80 char* pCurBuf
= pBuf
.get();
81 for (int i
= 0; i
< lenRaw
; i
++)
83 unsigned char curChar
= arRaw
[i
];
86 *pCurBuf
= EncodingTable
[curChar
];
92 *pCurBuf
= EncodingTable
[curChar
];
96 rtl::ByteSequence
ret(reinterpret_cast<sal_Int8
*>(pBuf
.get()), lenRaw
* 2);
100 rtl::ByteSequence
decodeBase16(const rtl::ByteSequence
& data
)
102 static const char decodingTable
[] =
103 {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
104 sal_Int32 lenData
= data
.getLength();
105 sal_Int32 lenBuf
= lenData
/ 2; //always divisible by two
106 std::unique_ptr
<unsigned char[]> pBuf(new unsigned char[lenBuf
]);
107 const sal_Int8
* pData
= data
.getConstArray();
108 for (sal_Int32 i
= 0; i
< lenBuf
; i
++)
110 sal_Int8 curChar
= *pData
++;
111 //find the index of the first 4bits
112 // TODO What happens if text is not valid Hex characters?
113 unsigned char nibble
= 0;
114 for (unsigned char j
= 0; j
< 16; j
++)
116 if (curChar
== decodingTable
[j
])
124 //find the index for the next 4bits
125 for (unsigned char j
= 0; j
< 16; j
++)
127 if (curChar
== decodingTable
[j
])
135 rtl::ByteSequence
ret(reinterpret_cast<sal_Int8
*>(pBuf
.get()), lenBuf
);
139 OUString
getDirFromFile(std::u16string_view usFilePath
)
141 size_t index
= usFilePath
.rfind('/');
142 return OUString(usFilePath
.substr(0, index
));
145 OUString
getLibraryLocation()
147 OUString libraryFileUrl
;
149 if (!osl::Module::getUrlFromAddress(
150 reinterpret_cast< oslGenericFunction
>(getLibraryLocation
),
152 throw FrameworkException(JFW_E_ERROR
,
153 "[Java framework] Error in function getLibraryLocation (fwkutil.cxx)."_ostr
);
155 return getDirFromFile(libraryFileUrl
);
158 jfw::FileStatus
checkFileURL(const OUString
& sURL
)
160 jfw::FileStatus ret
= jfw::FILE_OK
;
162 File::RC rc_item
= DirectoryItem::get(sURL
, item
);
163 if (File::E_None
== rc_item
)
165 osl::FileStatus
status(osl_FileStatus_Mask_Validate
);
167 File::RC rc_stat
= item
.getFileStatus(status
);
168 if (File::E_None
== rc_stat
)
172 else if (File::E_NOENT
== rc_stat
)
174 ret
= FILE_DOES_NOT_EXIST
;
181 else if (File::E_NOENT
== rc_item
)
183 ret
= FILE_DOES_NOT_EXIST
;
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */