Class 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
    • Constructor Detail

      • ImagePath

        public ImagePath()
    • Method Detail

      • 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
      • reset

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

        public static void clear()
      • add

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

        public static boolean add​(String mainPath,
                                  String altPathOrFolder)
        create a new PathEntry from the path 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 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...
        altPathOrFolder - alternative image folder, when not running from jar
        Returns:
        true if successful otherwise false
      • 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​(String mainPath,
                                     String altPathOrFolder)
      • 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)
      • addJar

        public static boolean addJar​(String fpJar)
      • addJar

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

        public static boolean removeJar​(String fpJar)
      • removeJar

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

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

        public static URL get​(Object what)
      • has

        public static boolean has​(Object what)
      • has

        public static boolean has​(Object what,
                                  String folder)
      • insert

        public static URL insert​(Object what)
      • insert

        public static URL insert​(Object what,
                                 URL where)
      • append

        public static URL append​(Object what)
      • append

        public static URL append​(Object what,
                                 URL where)
      • replace

        public static URL replace​(Object what,
                                  URL where)
      • remove

        public static URL remove​(Object what)
      • hasBundlePath

        public static boolean hasBundlePath()
      • 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
      • getBundlePath

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

        public static File setBundleFolder​(File folder)
      • check

        public static URL check​(String name)
      • 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 with extension
        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)