Author: vmassol
Date: 2007-09-05 21:57:31 +0200 (Wed, 05 Sep 2007)
New Revision: 4731
Modified:
xwiki-platform/core/trunk/xwiki-core/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).
Modified:
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/pdf/impl/XWikiURIResolver.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/pdf/impl/XWikiURIResolver.java
2007-09-05 18:03:56 UTC (rev 4730)
+++
xwiki-platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/pdf/impl/XWikiURIResolver.java
2007-09-05 19:57:31 UTC (rev 4731)
@@ -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