Class ImagePath

java.lang.Object
org.sikuli.script.ImagePath

public class ImagePath
extends Object
maintain the path list of locations, where images will be searched.
the first entry always is the bundlepath used on the scripting level
Python import automatically adds a sikuli bundle here
supported locations:
- absolute filesystem paths
- inside jars relative to root level given by a class found on classpath
- a location in the web given as string starting with http[s]://
- any location as a valid URL, from where image files can be loaded
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  ImagePath.PathEntry
    represents an imagepath entry
  • Constructor Summary

    Constructors 
    Constructor Description
    ImagePath()  
  • Method Summary

    Modifier and Type Method Description
    static boolean add​(String mainPath)
    create a new PathEntry from the given absolute path name and add it to the end of the current image path
    for usage with jars see; add(String, String)
    static boolean add​(String mainPath, String altPath)
    create a new PathEntry from the given absolute path name and add it to the end of the current image path
    for images stored in jars:
    Set the primary image path to the top folder level of a jar based on the given class name (must be found on class path).
    static void add​(URL pURL)
    add entry to end of list (the given URL is not checked)
    static boolean addHTTP​(String pathHTTP)
    create a new PathEntry from the given net resource folder accessible via HTTP at end of the current image path
    BE AWARE:
    Files stored in the given remote folder must allow HTTP HEAD-requests (checked)
    redirections are not followed (suppressed)
    static boolean addJar​(String fpJar, String fpImage)  
    static void dump​(int lvl)
    print the list of path entries
    static URL find​(String imageFileName)
    try to find the given relative image file name on the image path
    starting from entry 0, the first found existence is taken
    absolute file names are checked for existence
    static String[] get()
    the path list as string array
    static String getBundlePath()
    no trailing path separator
    static List<ImagePath.PathEntry> getPaths()
    get the list of path entries (as PathEntry)
    static boolean hasBundlePath()  
    static boolean isImageBundled​(URL fURL)  
    static BufferedReader open​(String fname)
    given absolute or relative (searched on image path) file name
    is tried to open as a BufferedReader
    BE AWARE: use br.close() when finished
    static boolean remove​(File directory)
    remove entry with given path (same as given with add)
    static boolean remove​(String path)
    remove entry with given path (same as given with add)
    static boolean removeHTTP​(String pathHTTP)  
    static void reset()
    empty path list and keep bundlePath (entry 0)
    Image cache is cleared completely convenience for the scripting level
    static boolean reset​(String path)
    empty path list and add given path as first entry Image cache is cleared completely
    static File setBundleFolder​(File folder)  
    static boolean setBundlePath​(String newBundlePath)
    the given path replaces bundlepath (entry 0)

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getPaths

      public static List<ImagePath.PathEntry> getPaths()
      get the list of path entries (as PathEntry)
      Returns:
      pathentries
    • get

      public static String[] get()
      the path list as string array
      Returns:
      an array of the file path's currently in the path list
    • dump

      public static void dump​(int lvl)
      print the list of path entries
      Parameters:
      lvl - debug level to use
    • reset

      public static void reset()
      empty path list and keep bundlePath (entry 0)
      Image cache is cleared completely convenience for the scripting level
    • add

      public static boolean add​(String mainPath)
      create a new PathEntry from the given absolute path name and add it to the end of the current image path
      for usage with jars see; add(String, String)
      Parameters:
      mainPath - relative or absolute path
      Returns:
      true if successful otherwise false
    • addHTTP

      public static boolean addHTTP​(String pathHTTP)
      create a new PathEntry from the given net resource folder accessible via HTTP at end of the current image path
      BE AWARE:
      Files stored in the given remote folder must allow HTTP HEAD-requests (checked)
      redirections are not followed (suppressed)
      Parameters:
      pathHTTP - folder address like siteaddress or siteaddress/folder/subfolder (e.g. download.sikuli.de/images)
      Returns:
      true if successful otherwise false
    • removeHTTP

      public static boolean removeHTTP​(String pathHTTP)
    • add

      public static boolean add​(String mainPath, String altPath)
      create a new PathEntry from the given absolute path name and add it to the end of the current image path
      for images stored in jars:
      Set the primary image path to the top folder level of a jar based on the given class name (must be found on class path). When not running from a jar (e.g. running in some IDE) the path will be the path to the compiled classes (for Maven based projects this is target/classes that contains all stuff copied from src/run/resources automatically)
      For situations, where the images cannot be found automatically in the non-jar situation, you might give an alternative path either absolute or relative to the working folder.
      Parameters:
      mainPath - absolute path name or a valid classname optionally followed by /subfolder...
      altPath - alternative image folder, when not running from jar
      Returns:
      true if successful otherwise false
    • addJar

      public static boolean addJar​(String fpJar, String fpImage)
    • add

      public static void add​(URL pURL)
      add entry to end of list (the given URL is not checked)
      Parameters:
      pURL - a valid URL (not checked)
    • remove

      public static boolean remove​(String path)
      remove entry with given path (same as given with add)
      Parameters:
      path - relative or absolute path
      Returns:
      true on success, false otherwise
    • remove

      public static boolean remove​(File directory)
      remove entry with given path (same as given with add)
      Parameters:
      directory - relative or absolute path as File
      Returns:
      true on success, false otherwise
    • hasBundlePath

      public static boolean hasBundlePath()
    • reset

      public static boolean reset​(String path)
      empty path list and add given path as first entry Image cache is cleared completely
      Parameters:
      path - absolute path
      Returns:
      true on success, false otherwise
    • setBundlePath

      public static boolean setBundlePath​(String newBundlePath)
      the given path replaces bundlepath (entry 0)
      Parameters:
      newBundlePath - an absolute file path
      Returns:
      true on success, false otherwise
    • setBundleFolder

      public static File setBundleFolder​(File folder)
    • getBundlePath

      public static String getBundlePath()
      no trailing path separator
      Returns:
      the current bundle path
    • find

      public static URL find​(String imageFileName)
      try to find the given relative image file name on the image path
      starting from entry 0, the first found existence is taken
      absolute file names are checked for existence
      Parameters:
      imageFileName - relative or absolute filename
      Returns:
      a valid URL or null if not found/exists
    • open

      public static BufferedReader open​(String fname)
      given absolute or relative (searched on image path) file name
      is tried to open as a BufferedReader
      BE AWARE: use br.close() when finished
      Parameters:
      fname - relative or absolute filename
      Returns:
      the BufferedReader to be used or null if not possible
    • isImageBundled

      public static boolean isImageBundled​(URL fURL)