]> granicus.if.org Git - docbook-dsssl/commitdiff
Handle the case where the imageFn is actually a URI. This still needs work.
authorNorman Walsh <ndw@nwalsh.com>
Fri, 16 Sep 2005 12:40:37 +0000 (12:40 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Fri, 16 Sep 2005 12:40:37 +0000 (12:40 +0000)
xsl/extensions/saxon643/com/nwalsh/saxon/ImageIntrinsics.java

index 9dd22294f7325dc6a5b19c9b499a4f7fff605d02..2eb069f5425284151d6fb69cee37900afbd6d6cd 100644 (file)
@@ -1,8 +1,14 @@
 package com.nwalsh.saxon;
 
-import java.io.*;
-import java.awt.*;
-import java.awt.image.*;
+import java.io.File;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.awt.Toolkit;
+import java.awt.Image;
+import java.awt.image.ImageObserver;
 import java.lang.Thread;
 import java.util.StringTokenizer;
 
@@ -41,7 +47,30 @@ public class ImageIntrinsics implements ImageObserver {
    */
   public ImageIntrinsics(String imageFn) {
     System.setProperty("java.awt.headless","true");
-    image = Toolkit.getDefaultToolkit().getImage (imageFn);
+
+    // Hack. I expect the right way to do this is to always use a URL.
+    // However, that means getting the base URI correct and dealing
+    // with the various permutations of the file: URI scheme on different
+    // platforms. So instead, what we're going to do is cheat. If it
+    // starts with http: or ftp:, call it a URI. Otherwise, call it
+    // a file. Also call it a file if the URI is malformed.
+
+    URL imageUrl = null;
+
+    if (imageFn.startsWith("http:") || imageFn.startsWith("ftp:")) {
+       try {
+           imageUrl = new URL(imageFn);
+       } catch (MalformedURLException mue) {
+           imageUrl = null;
+       }
+    }
+
+    if (imageUrl != null) {
+       image = Toolkit.getDefaultToolkit().getImage (imageUrl);
+    } else {
+       image = Toolkit.getDefaultToolkit().getImage (imageFn);
+    }
+
     width = image.getWidth(this);
 
     while (!imageFailed && (width == -1 || depth == -1)) {
@@ -56,7 +85,7 @@ public class ImageIntrinsics implements ImageObserver {
 
     if (imageFailed) {
       // Maybe it's an EPS or PDF?
-      // FIXME: this code is crude
+      // FIXME: this code is crude (and doesn't handle the URL case!!!)
       BufferedReader ir = null;
       String line = null;
       int lineLimit = 100;