Class StaticUtils

java.lang.Object
org.omegat.util.StaticUtils

public final class StaticUtils extends Object
Static functions taken from CommandThread to reduce file size.
  • Field Details

    • TAG_REPLACEMENT_CHAR

      public static final char TAG_REPLACEMENT_CHAR
      Char 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

      public static final String TAG_REPLACEMENT
      See Also:
  • Method Details

    • isKey

      public static boolean isKey(KeyEvent e, int code, int modifiers)
      Check if specified key pressed.
      Parameters:
      e - pressed key event
      code - required key code
      modifiers - required modifiers
      Returns:
      true if checked key pressed
    • getFontNames

      public static String[] getFontNames()
      Returns the names of all font families available.
    • installDir

      public static String 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

      public static String 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

      public static String getApplicationDataDir()
      Get application data directory.
      Returns:
      directory path to store application data.
    • getHomeDir

      public static String getHomeDir()
    • getUserScriptsDir

      public static String 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

      public static Path 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

      public static String 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

      public static String getLogLocation()
      Returns the path to the log file.
    • uuencode

      public static String uuencode(byte[] buf)
      Encodes the array of bytes to store them in a plain text file.
    • uudecode

      public static byte[] uudecode(String buf)
      Decodes the array of bytes that was stored in a plain text file as a string, back to array of bytes.
    • makeFilenameRelative

      public static String makeFilenameRelative(String filename, String path)
      Makes the file name relative to the given path.
    • globToRegex

      public static String globToRegex(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.

      If spaceMatchesNbsp is true, non-breaking spaces (U+00A0) will also be considered whitespace.

      • ? is translated to \S (or [^\s ])
      • * is translated to \S* (or [^\s ]*)
      • If spaceMatchesNbsp is true, then ' ' is translated to ( | )
      • All other special regex characters are escaped as literals
      Parameters:
      text - The text to escape
      spaceMatchesNbsp - Whether to consider regular spaces to also match non-breaking spaces
      Returns:
      The escaped text
    • downloadFileToString

      @Deprecated public static String downloadFileToString(URL url, int timeout) throws IOException
      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 archive
      destination - Path where archive entries will be saved
      filenameFilter - 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

      public static String[] parseCLICommand(String cmd)
      Parse a command line string into arguments, interpreting double and single quotes as Bash does.
      Parameters:
      cmd - Command string
      Returns:
      Array of arguments
    • isProjectDir

      public static boolean isProjectDir(File f)
    • 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 array
      haystack - The containing array
      offset - The offset of haystack at which to start checking
      Returns:
      Whether or not haystack contains needles at offset
      Throws:
      ArrayIndexOutOfBoundsException - If offset is not a valid index in haystack
    • getSupportInfo

      public static String getSupportInfo()
    • getMB

      public static int getMB(long bytes)
      Convert bytes into Megabytes
    • getAllModelFields

      public static List<Field> getAllModelFields(Class<?> aClass)
      Get fields declared in the class and its super classes.
      Parameters:
      aClass - target model class.
      Returns:
      list of fields.