Skip to content

Commit

Permalink
fix issue with embedded svg images added like data-URL (#1604) (#1605)
Browse files Browse the repository at this point in the history
* fix issue with embedded svg images added like data-URL (#1604)
  • Loading branch information
speckyspooky committed Mar 24, 2024
1 parent 03aec8a commit b70b714
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public String onDocImage(IImage image, Object context) {
public String onURLImage(IImage image, Object context) {
assert (image != null);
String uri = image.getID();
if (uri.startsWith("http:") || uri.startsWith("https:")) {
if (uri.startsWith("http:") || uri.startsWith("https:") || uri.startsWith("data:")) {
return uri;
}
return handleImage(image, context, "uri", true); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class FileUtil {
* The <code>HashMap</code> object that stores image type/file extension
* mapping.
*/
private static HashMap fileExtension = new HashMap();
private static HashMap mimeType = new HashMap();
private static HashMap<String, String> fileExtension = new HashMap<String, String>();
private static HashMap<String, String> mimeType = new HashMap<String, String>();

static {
// initialize fileExtension
Expand Down Expand Up @@ -183,7 +183,7 @@ public static String getExtFromFileName(String fileName) {
* resource.
*/
public static boolean isLocalResource(String uri) {
return uri != null && uri.length() > 0 && !uri.toLowerCase().startsWith("http"); //$NON-NLS-1$
return uri != null && uri.length() > 0 && !uri.toLowerCase().startsWith("http") && !uri.toLowerCase().startsWith("data"); //$NON-NLS-1$
}

/**
Expand Down Expand Up @@ -264,17 +264,17 @@ public static boolean saveFile(File targetFile, byte[] data) {
* @return File extension string say, ".jpg".
*/
public static String getExtFromType(String fileType) {
return (String) fileExtension.get(fileType);
return fileExtension.get(fileType);
}

/**
* Gets the Image file mime type according to the given file extension.
*
* @param fileType The image file type say, ".jpg".
* @param imgExt The image file type say, ".jpg".
* @return File extension string say, "image/jpg".
*/
public static String getTypeFromExt(String imgExt) {
return (String) mimeType.get(imgExt);
return mimeType.get(imgExt);
}

/**
Expand Down Expand Up @@ -346,6 +346,11 @@ public static byte[] getFileContent(String fileName) {
return null;
}

/**
* Delete the directory content
*
* @param file name of the directory
*/
public static void deleteDir(File file) {
if (file.isDirectory()) {
String[] list = file.list();
Expand All @@ -358,6 +363,11 @@ public static void deleteDir(File file) {
file.delete();
}

/**
* Get the java directory of temporary files
*
* @return Return the java directory of temporary files
*/
public static String getJavaTmpDir() {
return System.getProperty("java.io.tmpdir");
}
Expand Down

0 comments on commit b70b714

Please sign in to comment.