Skip to content

Commit b12c6ff

Browse files
Prettified code and reverted unnecessary changes
1 parent 29255d8 commit b12c6ff

File tree

3 files changed

+10
-39
lines changed

3 files changed

+10
-39
lines changed

common/src/main/java/com/genexus/IHttpContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ public interface IHttpContext {
6363
boolean isHttpContextNull();
6464
boolean isHttpContextWeb();
6565

66-
66+
String getContextPath();
6767
}

java/src/main/java/com/genexus/GxImageUtil.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,23 @@ private static InputStream getInputStream(String filePathOrUrl) throws IOExcepti
2323

2424
private static BufferedImage createBufferedImageFromURI(String filePathOrUrl) throws IOException
2525
{
26-
InputStream is;
27-
try {
28-
if (PrivateUtilities.isValidURL(filePathOrUrl))
29-
is = new URL(filePathOrUrl).openStream();
30-
else{
26+
IHttpContext httpContext = com.genexus.ModelContext.getModelContext().getHttpContext();
27+
InputStream is = null;
28+
try{
29+
if (filePathOrUrl.toLowerCase().startsWith("http://") || filePathOrUrl.toLowerCase().startsWith("https://") ||
30+
(httpContext.isHttpContextWeb() && filePathOrUrl.startsWith(httpContext.getContextPath())))
31+
is = new URL(GXDbFile.pathToUrl( filePathOrUrl, httpContext)).openStream();
32+
else
3133
is = getGXFile(filePathOrUrl).getStream();
32-
}
3334
return ImageIO.read(is);
34-
}
35-
catch (IOException e) {
35+
} catch (IOException e) {
3636
log.error("Failed to read image stream: " + filePathOrUrl);
3737
throw e;
38-
}
38+
} finally { is.close(); }
3939
}
4040

4141
private static GXFile getGXFile(String filePathOrUrl) {
4242
String basePath = (com.genexus.ModelContext.getModelContext() != null) ? com.genexus.ModelContext.getModelContext().getHttpContext().getDefaultPath(): "";
43-
String environmentName = basePath.substring(basePath.lastIndexOf("\\") + 1);
44-
if (filePathOrUrl.substring(1).startsWith(environmentName)) {
45-
filePathOrUrl = filePathOrUrl.substring(environmentName.length() + 2);
46-
}
4743
return new GXFile(basePath, filePathOrUrl, ResourceAccessControlList.Default, GxFileInfoSourceType.Unknown);
4844
}
4945

java/src/main/java/com/genexus/PrivateUtilities.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
import java.io.PushbackInputStream;
1919
import java.lang.reflect.Field;
2020
import java.net.HttpURLConnection;
21-
import java.net.MalformedURLException;
2221
import java.net.URL;
2322
import java.nio.file.InvalidPathException;
24-
import java.io.FileNotFoundException;
2523
import java.nio.file.Paths;
2624
import java.util.Properties;
2725
import java.util.Random;
@@ -627,29 +625,6 @@ public static boolean isAbsoluteFilePath(String path) {
627625
}
628626
}
629627

630-
631-
/**
632-
* <pre>
633-
* Checks if a string has valid URL syntax and points to a valid resource on the web.
634-
* Null safe.
635-
* </pre>
636-
*/
637-
//Me fijo si la sintaxis del string es la sintaxis de una URL y si
638-
//de verdad existe a lo que esta apuntando
639-
public static boolean isValidURL(String urlString) {
640-
try {
641-
URL url = new URL(urlString);
642-
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
643-
connection.setRequestMethod("HEAD");
644-
int responseCode = connection.getResponseCode();
645-
return (responseCode == HttpURLConnection.HTTP_OK);
646-
} catch (MalformedURLException | FileNotFoundException e) {
647-
return false;
648-
} catch (IOException | NullPointerException e) {
649-
return false;
650-
}
651-
}
652-
653628
public static String addLastPathSeparator(String dir)
654629
{
655630
return addLastChar(dir, File.separator);

0 commit comments

Comments
 (0)