Package org.omegat.util
Class StaticUtils
java.lang.Object
org.omegat.util.StaticUtils
Static functions taken from CommandThread to reduce file size.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final charChar which should be used instead protected parts. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> booleanarraysMatchAt(T[] needles, T[] haystack, int offset) Check to see if an array contains another array.static StringdownloadFileToString(URL url, int timeout) Deprecated.static voidEnsure user scripts directory exists and contains scripts.extractFromZip(InputStream in, File destination, Predicate<String> filenameFilter) Extracts files from an InputStream representing a zip archive to the specified destination path.getAllModelFields(Class<?> aClass) Get fields declared in the class and its super classes.static StringGet application data directory.static StringReturns the location of the configuration directory, depending on the user's platform.static String[]Returns the names of all font families available.static Stringstatic StringReturns the path to the log file.static intgetMB(long bytes) Convert bytes into Megabytesstatic StringDetermines and returns the path to the 'script' directory.static Stringstatic StringReturns the user scripts directory for each OS.static PathReturns the user scripts directory for each OS.static StringglobToRegex(String text, boolean spaceMatchesNbsp) Translates a string containing word-processing "glob"-style wildcards (?matches a single non-whitespace character,*matches zero or more non-whitespace characters) to standard regex.static StringReturns OmegaT installation directory.static booleanCheck if specified key pressed.static booleanisProjectDir(File f) static StringmakeFilenameRelative(String filename, String path) Makes the file name relative to the given path.static String[]parseCLICommand(String cmd) Parse a command line string into arguments, interpreting double and single quotes as Bash does.static byte[]Decodes the array of bytes that was stored in a plain text file as a string, back to array of bytes.static Stringuuencode(byte[] buf) Encodes the array of bytes to store them in a plain text file.
-
Field Details
-
TAG_REPLACEMENT_CHAR
public static final char TAG_REPLACEMENT_CHARChar which should be used instead protected parts. It should be non-letter char, to be able to have correct words counter. This char can be placed around protected text for separate words inside protected text and words outside if there are no spaces between they.- See Also:
-
TAG_REPLACEMENT
- See Also:
-
-
Method Details
-
isKey
Check if specified key pressed.- Parameters:
e- pressed key eventcode- required key codemodifiers- required modifiers- Returns:
- true if checked key pressed
-
getFontNames
Returns the names of all font families available. -
installDir
Returns OmegaT installation directory. When running from an IDE or build tool; use CWD. Sometimes running from build/libs/OmegaT.jar on IDE. When running from Java WebStart; use CWD. If running from a JAR, get the enclosing folder (the JAR is assumed to be at the installation root, and there is also "modules" folder). When running from linux installation from package built with jpackage, the JAR is assumed to be at the "lib/app/", and "modules" and "scripts" are in "lib" folder. -
getConfigDir
Returns the location of the configuration directory, depending on the user's platform. Also creates the configuration directory, if necessary. If any problems occur while the location of the configuration directory is being determined, an empty string will be returned, resulting in the current working directory being used.- Windows XP: <Documents and Settings>\<User name>\Application Data\OmegaT
- Windows Vista: User\<User name>\AppData\Roaming
- Linux: ~/.omegat
- Solaris/SunOS: ~/.omegat
- FreeBSD: ~/.omegat
- Mac OS X: ~/Library/Preferences/OmegaT
- Other: User home directory
- Returns:
- The full path of the directory containing the OmegaT configuration files, including trailing path separator.
-
getApplicationDataDir
Get application data directory.- Returns:
- directory path to store application data.
-
getHomeDir
-
getUserScriptsDir
Returns the user scripts directory for each OS. It respects user configuration, then the default.- macOS:
- ~/Library/Application Support/OmegaT/scripts
- Windows:
- %APPDATA%/OmegaT/scripts
- Linux:
- ~/.local/share/OmegaT/scripts
-
getUserScriptsPath
Returns the user scripts directory for each OS.- macOS:
- ~/Library/Application Support/OmegaT/scripts
- Windows:
- %APPDATA%/OmegaT/scripts
- Linux:
- ~/.local/share/OmegaT/scripts
-
ensureUserScriptsDir
public static void ensureUserScriptsDir()Ensure user scripts directory exists and contains scripts. -
getScriptDir
Determines and returns the path to the 'script' directory.This directory is used to communicate user script and OmegaT core. If the directory does not exist, it attempts to create it. In case of failure to create or access the script directory, it defaults to the configuration directory path.
- Returns:
- The absolute path to the script directory, including a trailing path separator.
-
getLogLocation
Returns the path to the log file. -
uuencode
Encodes the array of bytes to store them in a plain text file. -
uudecode
Decodes the array of bytes that was stored in a plain text file as a string, back to array of bytes. -
makeFilenameRelative
Makes the file name relative to the given path. -
globToRegex
Translates a string containing word-processing "glob"-style wildcards (?matches a single non-whitespace character,*matches zero or more non-whitespace characters) to standard regex.If
spaceMatchesNbspistrue, non-breaking spaces (U+00A0) will also be considered whitespace.?is translated to\S(or[^\s ])*is translated to\S*(or[^\s ]*)- If
spaceMatchesNbspistrue, then '' is translated to( | ) - All other special regex characters are escaped as literals
- Parameters:
text- The text to escapespaceMatchesNbsp- Whether to consider regular spaces to also match non-breaking spaces- Returns:
- The escaped text
-
downloadFileToString
Deprecated.Download a file to memory. This method is replaced to HttpConnectionUtils.getURL(url, timeout)- Throws:
IOException
-
extractFromZip
public static List<String> extractFromZip(InputStream in, File destination, Predicate<String> filenameFilter) throws IOException Extracts files from an InputStream representing a zip archive to the specified destination path.- Parameters:
in- InputStream representing a zip archivedestination- Path where archive entries will be savedfilenameFilter- Filter for entry names. Return false to skip extracting an entry- Returns:
- List of extracted entry names
- Throws:
IOException- when I/O error occurred.
-
parseCLICommand
Parse a command line string into arguments, interpreting double and single quotes as Bash does.- Parameters:
cmd- Command string- Returns:
- Array of arguments
-
isProjectDir
-
arraysMatchAt
public static <T> boolean arraysMatchAt(T[] needles, T[] haystack, int offset) Check to see if an array contains another array.- Parameters:
needles- The contained arrayhaystack- The containing arrayoffset- The offset ofhaystackat which to start checking- Returns:
- Whether or not
haystackcontainsneedlesatoffset - Throws:
ArrayIndexOutOfBoundsException- Ifoffsetis not a valid index inhaystack
-
getSupportInfo
-
getMB
public static int getMB(long bytes) Convert bytes into Megabytes -
getAllModelFields
Get fields declared in the class and its super classes.- Parameters:
aClass- target model class.- Returns:
- list of fields.
-