2010-10-14 08:30:07 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-11 19:49:09 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-04-19 14:57:02 +00:00
|
|
|
|
2006-09-16 16:48:18 +00:00
|
|
|
|
2016-02-16 14:14:43 +02:00
|
|
|
#if defined(_WIN32)
|
2017-09-18 17:34:28 +03:00
|
|
|
#if !defined WIN32_LEAN_AND_MEAN
|
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
2004-05-13 10:15:02 +00:00
|
|
|
#include <windows.h>
|
2019-03-09 17:28:06 +01:00
|
|
|
#include <algorithm>
|
2004-05-13 10:15:02 +00:00
|
|
|
#endif
|
2004-04-19 14:57:02 +00:00
|
|
|
|
2017-10-23 22:38:59 +02:00
|
|
|
#include <osl/module.hxx>
|
|
|
|
#include <rtl/ustring.hxx>
|
|
|
|
#include <osl/file.hxx>
|
2018-08-05 00:50:24 +02:00
|
|
|
#include <sal/log.hxx>
|
2004-04-19 14:57:02 +00:00
|
|
|
|
|
|
|
#include "framework.hxx"
|
2017-10-23 22:38:59 +02:00
|
|
|
#include <fwkutil.hxx>
|
2015-06-15 17:58:15 +09:00
|
|
|
#include <memory>
|
2004-04-19 14:57:02 +00:00
|
|
|
|
2004-11-09 13:01:02 +00:00
|
|
|
using namespace osl;
|
2004-04-19 14:57:02 +00:00
|
|
|
|
2011-03-02 21:53:12 +01:00
|
|
|
|
2004-04-19 14:57:02 +00:00
|
|
|
namespace jfw
|
|
|
|
{
|
|
|
|
|
2021-11-15 21:44:42 +02:00
|
|
|
/** provides a bootstrap class which already knows the values from the
|
|
|
|
jvmfkwrc file.
|
|
|
|
*/
|
|
|
|
const rtl::Bootstrap* Bootstrap()
|
|
|
|
{
|
|
|
|
static const rtl::Bootstrap* SINGLETON = []()
|
|
|
|
{
|
|
|
|
OUString sIni = getLibraryLocation() +
|
|
|
|
#ifdef MACOSX
|
|
|
|
// For some reason the jvmfwk3rc file is traditionally in
|
|
|
|
// LIBO_URE_ETC_FOLDER
|
|
|
|
"/../" LIBO_URE_ETC_FOLDER
|
|
|
|
#endif
|
|
|
|
SAL_CONFIGFILE("/jvmfwk3");
|
|
|
|
::rtl::Bootstrap * bootstrap = new ::rtl::Bootstrap(sIni);
|
|
|
|
SAL_INFO("jfw.level2", "Using configuration file " << sIni);
|
|
|
|
return bootstrap;
|
|
|
|
}();
|
|
|
|
return SINGLETON;
|
|
|
|
};
|
|
|
|
|
|
|
|
osl::Mutex& FwkMutex()
|
|
|
|
{
|
|
|
|
static osl::Mutex SINGLETON;
|
|
|
|
return SINGLETON;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-19 14:57:02 +00:00
|
|
|
rtl::ByteSequence encodeBase16(const rtl::ByteSequence& rawData)
|
|
|
|
{
|
2013-07-29 17:38:09 +09:00
|
|
|
static const char EncodingTable[] =
|
2004-04-19 14:57:02 +00:00
|
|
|
{'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
|
|
|
sal_Int32 lenRaw = rawData.getLength();
|
2015-06-15 17:58:15 +09:00
|
|
|
std::unique_ptr<char[]> pBuf(new char[lenRaw * 2]);
|
2004-04-19 14:57:02 +00:00
|
|
|
const sal_Int8* arRaw = rawData.getConstArray();
|
|
|
|
|
2014-04-21 22:29:09 +09:00
|
|
|
char* pCurBuf = pBuf.get();
|
2004-04-19 14:57:02 +00:00
|
|
|
for (int i = 0; i < lenRaw; i++)
|
|
|
|
{
|
2004-11-09 13:01:02 +00:00
|
|
|
unsigned char curChar = arRaw[i];
|
2004-04-19 14:57:02 +00:00
|
|
|
curChar >>= 4;
|
|
|
|
|
|
|
|
*pCurBuf = EncodingTable[curChar];
|
|
|
|
pCurBuf++;
|
|
|
|
|
|
|
|
curChar = arRaw[i];
|
|
|
|
curChar &= 0x0F;
|
|
|
|
|
|
|
|
*pCurBuf = EncodingTable[curChar];
|
|
|
|
pCurBuf++;
|
|
|
|
}
|
|
|
|
|
2015-01-17 18:48:45 +01:00
|
|
|
rtl::ByteSequence ret(reinterpret_cast<sal_Int8*>(pBuf.get()), lenRaw * 2);
|
2004-04-19 14:57:02 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
rtl::ByteSequence decodeBase16(const rtl::ByteSequence& data)
|
|
|
|
{
|
2013-07-29 17:38:09 +09:00
|
|
|
static const char decodingTable[] =
|
2004-04-19 14:57:02 +00:00
|
|
|
{'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
|
|
|
sal_Int32 lenData = data.getLength();
|
2019-12-04 20:22:27 +01:00
|
|
|
sal_Int32 lenBuf = lenData / 2; //always divisible by two
|
2015-06-15 17:58:15 +09:00
|
|
|
std::unique_ptr<unsigned char[]> pBuf(new unsigned char[lenBuf]);
|
2006-06-19 23:11:26 +00:00
|
|
|
const sal_Int8* pData = data.getConstArray();
|
|
|
|
for (sal_Int32 i = 0; i < lenBuf; i++)
|
2004-04-19 14:57:02 +00:00
|
|
|
{
|
2006-06-19 23:11:26 +00:00
|
|
|
sal_Int8 curChar = *pData++;
|
2004-04-19 14:57:02 +00:00
|
|
|
//find the index of the first 4bits
|
2004-09-08 15:03:51 +00:00
|
|
|
// TODO What happens if text is not valid Hex characters?
|
2006-06-19 23:11:26 +00:00
|
|
|
unsigned char nibble = 0;
|
|
|
|
for (unsigned char j = 0; j < 16; j++)
|
2004-04-19 14:57:02 +00:00
|
|
|
{
|
2006-06-19 23:11:26 +00:00
|
|
|
if (curChar == decodingTable[j])
|
2004-04-19 14:57:02 +00:00
|
|
|
{
|
2006-06-19 23:11:26 +00:00
|
|
|
nibble = j;
|
2004-04-19 14:57:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nibble <<= 4;
|
2006-06-19 23:11:26 +00:00
|
|
|
curChar = *pData++;
|
2004-04-19 14:57:02 +00:00
|
|
|
//find the index for the next 4bits
|
2006-06-19 23:11:26 +00:00
|
|
|
for (unsigned char j = 0; j < 16; j++)
|
2004-04-19 14:57:02 +00:00
|
|
|
{
|
2004-04-27 14:22:15 +00:00
|
|
|
if (curChar == decodingTable[j])
|
2004-04-19 14:57:02 +00:00
|
|
|
{
|
2004-04-27 14:22:15 +00:00
|
|
|
nibble |= j;
|
2004-04-19 14:57:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-06-19 23:11:26 +00:00
|
|
|
pBuf[i] = nibble;
|
2004-04-19 14:57:02 +00:00
|
|
|
}
|
2015-01-17 18:48:45 +01:00
|
|
|
rtl::ByteSequence ret(reinterpret_cast<sal_Int8*>(pBuf.get()), lenBuf );
|
2004-04-19 14:57:02 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString getDirFromFile(const OUString& usFilePath)
|
2004-04-19 14:57:02 +00:00
|
|
|
{
|
2017-05-28 19:41:52 +02:00
|
|
|
sal_Int32 index = usFilePath.lastIndexOf('/');
|
|
|
|
return usFilePath.copy(0, index);
|
2004-11-09 13:01:02 +00:00
|
|
|
}
|
2004-04-19 14:57:02 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString getLibraryLocation()
|
2004-04-19 14:57:02 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString libraryFileUrl;
|
2004-04-19 14:57:02 +00:00
|
|
|
|
2006-06-19 23:11:26 +00:00
|
|
|
if (!osl::Module::getUrlFromAddress(
|
|
|
|
reinterpret_cast< oslGenericFunction >(getLibraryLocation),
|
|
|
|
libraryFileUrl))
|
2017-05-29 09:48:54 +02:00
|
|
|
throw FrameworkException(JFW_E_ERROR,
|
|
|
|
"[Java framework] Error in function getLibraryLocation (fwkutil.cxx).");
|
2004-05-14 13:44:10 +00:00
|
|
|
|
2004-11-09 13:01:02 +00:00
|
|
|
return getDirFromFile(libraryFileUrl);
|
2004-05-18 11:51:54 +00:00
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
jfw::FileStatus checkFileURL(const OUString & sURL)
|
2004-05-17 12:55:32 +00:00
|
|
|
{
|
2004-11-09 13:01:02 +00:00
|
|
|
jfw::FileStatus ret = jfw::FILE_OK;
|
2007-06-13 06:58:23 +00:00
|
|
|
DirectoryItem item;
|
|
|
|
File::RC rc_item = DirectoryItem::get(sURL, item);
|
|
|
|
if (File::E_None == rc_item)
|
2004-05-18 14:11:57 +00:00
|
|
|
{
|
2011-04-13 20:54:25 +02:00
|
|
|
osl::FileStatus status(osl_FileStatus_Mask_Validate);
|
2004-05-17 12:55:32 +00:00
|
|
|
|
2007-06-13 06:58:23 +00:00
|
|
|
File::RC rc_stat = item.getFileStatus(status);
|
|
|
|
if (File::E_None == rc_stat)
|
|
|
|
{
|
|
|
|
ret = FILE_OK;
|
2004-11-09 13:01:02 +00:00
|
|
|
}
|
2007-06-13 06:58:23 +00:00
|
|
|
else if (File::E_NOENT == rc_stat)
|
2004-11-09 13:01:02 +00:00
|
|
|
{
|
|
|
|
ret = FILE_DOES_NOT_EXIST;
|
|
|
|
}
|
|
|
|
else
|
2004-05-17 12:55:32 +00:00
|
|
|
{
|
2004-11-09 13:01:02 +00:00
|
|
|
ret = FILE_INVALID;
|
2004-05-17 12:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-13 06:58:23 +00:00
|
|
|
else if (File::E_NOENT == rc_item)
|
2004-05-17 12:55:32 +00:00
|
|
|
{
|
2007-06-13 06:58:23 +00:00
|
|
|
ret = FILE_DOES_NOT_EXIST;
|
2004-05-17 12:55:32 +00:00
|
|
|
}
|
2007-06-13 06:58:23 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = FILE_INVALID;
|
|
|
|
}
|
|
|
|
return ret;
|
2004-05-17 12:55:32 +00:00
|
|
|
}
|
|
|
|
|
2004-04-19 14:57:02 +00:00
|
|
|
}
|
2010-10-14 08:30:07 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|