Utility classes
There are several utilitity classes which you can use at anywhere you want.
HTTP connection utility
When you need to interact with web servers, you can use HTTP connection utility.
If you want remote resource as String, HttpConnectionUtils#getURL
is what you need.
There are two variants;
getURL(URL url)
and
getURL(URL url, int timeout)
A default timeout is 10 seconds.
When you need to download binary file from remote, you can use downloadBinary
utility method.
downloadBinaryFile(URL fileURL, Map<String, String> headers,
Set<String> expectedMime, File saveFilePath)
It will return true
when successfully download the file.
You should provide headers, and expected MIME types.
When you need to download zip file from remote and extract its contents, use can use downloadZipAndExtract
downloadZipFileAndExtract(URL url, File dir, List<String> expectedFiles)
It takes target directory and expected filename list.
These utilities use URL#openConnection
method. It looks system property for proxy connections.
There are also some primitive connection utilities.
There are get
, post
, and postJson
.
HTML Utilities
When you handle HTML text, you will need to convert HTML excape characters into UTF-8.
HTMLUtils#entitiesToChars
is what you want.
There is also a HTMLUtils#charsToEntities
which does reverse things.
Encoding Detector
When we read arbitrary text files from disk, we sometimes need to detect character encodings.
EncodingDetector#detectEncoding
is one we used in glossary reader.
When there are enough characters, it detects an encoding correctly.
There are also a variant detectEndocingDefault
that accept default encoding.
Json Parser
There is a json parser based on Java internal Nashorn javascript scripting engine. Because Java 17 removes javascript engine from JVM, the parser is deprecated. You are recommended to use Jackson JSON parser instead.
StaticUtils
There are some small utilities in StaticUtils
class.
getConfigDir
: get omegat configuration directory such as$HOME/.omegat/
installDir
: get omegat installation directory whereOmegaT.jar
exists.getScriptDir
: get directory where scripts are installed.
StringUtil
There are several must use utility methods in StringUtil
class.
isEmpty(@Nullable String str)
: check string is null or empty string("")isLowerCase
isUpperCase
isMixedCase
isTitleCase
isWhiteSpace
isCJK
: return true when string has characters in Chinese, Japanese, or Korean.capitalizeFirst
: convert string with First character as upper case.toTitleCase:
convert string as title case.
Platform
When you need to detect platform such as Windows, macOS or Linux, there is a class for the purpose.
It is an enum to express platform types.
public enum OsType {
// os.arch=amd64, os.name=Linux, os.version=3.0.0-12-generic
LINUX64,
// os.arch=i386, os.name=Linux, os.version=3.0.0-12-generic
LINUX32,
// os.arch=x86_64, os.name=Mac OS X, os.version=10.6.8
MAC64,
// os.arch=i386, os.name=Mac OS X, os.version=10.6.8
MAC32,
// os.arch=amd64, os.name=Windows 7, os.version=6.1
WIN64,
// os.arch=x86, os.name=Windows 7, os.version=6.1
WIN32,
// unknown system
OTHER
}
getOsType
: return OS type where OmegaT running in enum.isMacOSX
: true when OmegaT run on macOS.isLinux
: true when OmegaT run on Linux.is64Bit
: true when OemgaT run on 64bit OS platform.