Author: vmassol
Date: 2007-09-05 21:58:43 +0200 (Wed, 05 Sep 2007)
New Revision: 4732

Modified:
   
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/pdf/impl/XWikiURIResolver.java
Log:
Small refactoring and added logs so that we know when an entity is not present 
locally (they should be present locally so that PDF export works even when 
offline).

Merged from trunk (rev 4731)

Modified: 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/pdf/impl/XWikiURIResolver.java
===================================================================
--- 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/pdf/impl/XWikiURIResolver.java
      2007-09-05 19:57:31 UTC (rev 4731)
+++ 
xwiki-platform/core/branches/xwiki-core-1.1/src/main/java/com/xpn/xwiki/pdf/impl/XWikiURIResolver.java
      2007-09-05 19:58:43 UTC (rev 4732)
@@ -24,6 +24,8 @@
 import org.xml.sax.EntityResolver;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import java.io.File;
 import java.io.IOException;
@@ -31,7 +33,9 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 
-public class XWikiURIResolver implements EntityResolver {
+public class XWikiURIResolver implements EntityResolver
+{
+    private static final Log LOG = LogFactory.getLog(XWikiURIResolver.class);
 
     /**
      * Allow the application to resolve external entities.
@@ -67,22 +71,30 @@
      *                                  or Reader for the InputSource.
      * @see org.xml.sax.InputSource
      */
-    public InputSource resolveEntity(String publicId, String systemId) throws 
SAXException, IOException {
+    public InputSource resolveEntity(String publicId, String systemId) throws 
SAXException, IOException
+    {
+        InputSource source = null;
+        
         try {
             URI uri = new URI(systemId);
 
-            if ("http".equals(uri.getScheme())) {
+            if ("http".equals(uri.getScheme()) || 
"file".equals(uri.getScheme())) {
                 String filename = (new File(uri.getPath())).getName();
                 InputStream istream =  
getClass().getClassLoader().getResourceAsStream(filename);
-                return new InputSource(istream);
-            } else if ("file".equals(uri.getScheme())) {
-                String filename = (new File(uri.getPath())).getName();
-                InputStream istream =  
getClass().getClassLoader().getResourceAsStream(filename);
-                return new InputSource(istream);                
+                if (istream != null) {
+                    source = new InputSource(istream);
+                } else {
+                    LOG.warn("Failed to load resource [" + filename
+                        + "] locally. Will try to get it online at [" + 
systemId + "]");
+                }
+            } else {
+                LOG.warn("Unknown URI scheme [" + uri.getScheme() + "] for 
entity ["
+                    + systemId + "].");
             }
         } catch (URISyntaxException e) {
+            LOG.warn("Invalid URI [" + systemId + "].", e);
         }
-        // Returning null causes the caller to try accessing the href
-        return null;
+        // Returning null causes the caller to try accessing the entity online
+        return source;
     }
 }
\ No newline at end of file

_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to