Package org.sikuli.script
Class ImagePath
- java.lang.Object
-
- org.sikuli.script.ImagePath
-
public class ImagePath extends java.lang.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
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
SCREENSHOT_DIRECTORY
-
Constructor Summary
Constructors Constructor Description ImagePath()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
add(java.lang.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(java.lang.String mainPath, java.lang.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(java.net.URL pURL)
add entry to end of list (the given URL is not checked)static boolean
addHTTP(java.lang.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(java.lang.String fpJar, java.lang.String fpImage)
static void
dump(int lvl)
print the list of path entriesstatic java.net.URL
find(java.io.File imageFile)
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 existencestatic java.net.URL
find(java.lang.String imageFileName)
static java.lang.String[]
get()
the path list as string arraystatic java.lang.String
getBundlePath()
no trailing path separatorstatic java.util.List<ImagePath.PathEntry>
getPaths()
get the list of path entries (as PathEntry)static boolean
hasBundlePath()
static boolean
isImageBundled(java.net.URL fURL)
static java.io.BufferedReader
open(java.lang.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 finishedstatic boolean
remove(java.io.File directory)
remove entry with given path (same as given with add)static boolean
remove(java.lang.String path)
remove entry with given path (same as given with add)static boolean
removeHTTP(java.lang.String pathHTTP)
static void
reset()
empty path list and keep bundlePath (entry 0)
Image cache is cleared completely convenience for the scripting levelstatic boolean
reset(java.lang.String path)
empty path list and add given path as first entry Image cache is cleared completelystatic java.io.File
setBundleFolder(java.io.File folder)
static boolean
setBundlePath(java.lang.String newBundlePath)
the given path replaces bundlepath (entry 0)
-
-
-
Field Detail
-
SCREENSHOT_DIRECTORY
public static final java.lang.String SCREENSHOT_DIRECTORY
- See Also:
- Constant Field Values
-
-
Method Detail
-
getPaths
public static java.util.List<ImagePath.PathEntry> getPaths()
get the list of path entries (as PathEntry)- Returns:
- pathentries
-
get
public static java.lang.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(java.lang.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(java.lang.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(java.lang.String pathHTTP)
-
add
public static boolean add(java.lang.String mainPath, java.lang.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(java.lang.String fpJar, java.lang.String fpImage)
-
add
public static void add(java.net.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(java.lang.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(java.io.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(java.lang.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(java.lang.String newBundlePath)
the given path replaces bundlepath (entry 0)- Parameters:
newBundlePath
- an absolute file path- Returns:
- true on success, false otherwise
-
setBundleFolder
public static java.io.File setBundleFolder(java.io.File folder)
-
getBundlePath
public static java.lang.String getBundlePath()
no trailing path separator- Returns:
- the current bundle path
-
find
public static java.net.URL find(java.io.File imageFile)
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:
imageFile
- relative or absolute file- Returns:
- a valid URL or null if not found/exists
-
find
public static java.net.URL find(java.lang.String imageFileName)
-
open
public static java.io.BufferedReader open(java.lang.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(java.net.URL fURL)
-
-