intermediate: ImagePath revision

This commit is contained in:
RaiMan
2021-03-01 17:02:45 +01:00
parent 039b500d50
commit c6908f3cc8
2 changed files with 23 additions and 34 deletions

View File

@@ -192,6 +192,7 @@ public class ImagePath {
public String toString() {
return getPath();
}
public boolean isValid() {
return pathURL != null;
}
@@ -436,19 +437,12 @@ public class ImagePath {
}
private static URL makeNetURL(String pathHTTP) {
URL url = null;
try {
String proto = "http://";
String protos = "https://";
if (!pathHTTP.startsWith(proto) && !pathHTTP.startsWith(protos)) {
pathHTTP = proto + pathHTTP;
}
url = new URL(pathHTTP);
} catch (MalformedURLException e) {
log(-1, "addHTTP: invalid: %s (%s)", pathHTTP, e);
String proto = "http://";
String protos = "https://";
if (!pathHTTP.startsWith(proto) && !pathHTTP.startsWith(protos)) {
pathHTTP = proto + pathHTTP;
}
return url;
return Commons.makeURL(pathHTTP);
}
public static boolean removeHTTP(String pathHTTP) {
@@ -456,14 +450,14 @@ public class ImagePath {
}
public static boolean addJar(String fpJar) {
return removeJar(fpJar, null);
return addJar(fpJar, null);
}
public static boolean addJar(String fpJar, String fpImage) {
if (!fpJar.endsWith(".jar") && !fpJar.contains(".jar!")) {
fpJar += ".jar";
}
return remove(fpJar, fpImage);
return null != append(fpJar, fpImage);
}
public static boolean removeJar(String fpJar) {
@@ -667,13 +661,16 @@ public class ImagePath {
//</editor-fold>
//<editor-fold desc="10 find image">
public static URL check(String name) {
return find(Image.getValidImageFilename(name));
}
/**
* try to find the given relative image file name on the image path<br>
* starting from entry 0, the first found existence is taken<br>
* absolute file names are checked for existence
*
* @param imageFileName relative or absolute filename
* @param imageFileName relative or absolute filename with extension
* @return a valid URL or null if not found/exists
*/
public static URL find(String imageFileName) {
@@ -695,7 +692,7 @@ public class ImagePath {
proto = entry.pathURL.getProtocol();
if ("file".equals(proto)) {
if (new File(entry.getPath(), imageFileName).exists()) {
fURL = Commons.makeURL(entry.getPath(), imageFileName);
return Commons.makeURL(entry.getPath(), imageFileName);
}
} else if ("jar".equals(proto) || proto.startsWith("http")) {
URL url = Commons.makeURL(entry.getPath(), imageFileName);
@@ -711,16 +708,13 @@ public class ImagePath {
}
}
if (check > 0) {
fURL = url;
break;
return url;
}
}
}
}
if (fURL == null) {
log(-1, "find: not there: %s", imageFileName);
dump(lvl);
}
log(-1, "find: not there: %s", imageFileName);
dump(lvl);
return fURL;
}
}

View File

@@ -265,12 +265,8 @@ def addImagePath(*args):
return ImagePath.append(args[0], args[1])
return None
def addHTTPImagePath(*args):
if (len(args) == 1):
return ImagePath.addHTTP(args[0])
elif (len(args) == 2):
return ImagePath.addHTTP(args[0], args[1])
return None
def addHTTPImagePath(arg):
return ImagePath.addHTTP(arg)
def addJarImagePath(*args):
if (len(args) == 1):
@@ -289,12 +285,8 @@ def removeImagePath(*args):
return ImagePath.remove(args[0], args[1])
return None
def removeHTTPImagePath(*args):
if (len(args) == 1):
return ImagePath.removeHTTP(args[0])
elif (len(args) == 2):
return ImagePath.removeHTTP(args[0], args[1])
return None
def removeHTTPImagePath(arg):
return ImagePath.removeHTTP(arg)
def removeJarImagePath(*args):
if (len(args) == 1):
@@ -315,6 +307,9 @@ def getImagePath():
def resetImagePath(path=None):
ImagePath.reset(path)
def checkImage(image):
return ImagePath.check(image)
## ----------------------------------------------------------------------
# Sets the path for searching images in all Sikuli Script methods. <br/>
# Sikuli IDE sets this to the path of the bundle of source code (.sikuli)