Print

Print


Commit in GeomConverter/src/org/lcsim/util/xml on MAIN
ClasspathEntityResolver.java+48added 1.1
JM: simple classpath EntityResolver

GeomConverter/src/org/lcsim/util/xml
ClasspathEntityResolver.java added at 1.1
diff -N ClasspathEntityResolver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ClasspathEntityResolver.java	14 Dec 2007 21:59:00 -0000	1.1
@@ -0,0 +1,48 @@
+package org.lcsim.util.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Finds an XML schema in a jar file.
+ *
+ * @author Jeremy McCormick
+ * @version $Id: ClasspathEntityResolver.java,v 1.1 2007/12/14 21:59:00 jeremy Exp $
+ */
+// FIXME: Duplicates functionality of freehep's ClasspathEntityResolver.
+public class ClasspathEntityResolver
+implements EntityResolver
+{    
+    String basePath;
+    
+    public ClasspathEntityResolver(String basePath)
+    {
+        this.basePath = basePath;
+    }
+    
+    /**
+     * Resolves the <tt>systemId</tt> by stripping out the base URL and then
+     * looking for the remaining path under a base package name.
+     * 
+     * ex. - http://www.lcsim.org/schemas/compact/1.0/compact.xsd -> /org/lcsim/schemas/compact/1.0/compact.xsd
+     * 
+     */
+    public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
+    {                        
+        // Strip out the base URL.
+        String path = systemId.substring(systemId.indexOf("/", systemId.indexOf("//") + 1));
+                
+        // Resolve the path component.
+        InputStream in = this.getClass().getResourceAsStream(basePath + "/" + path);
+        
+        // Make an InputSource from the stream.
+        InputSource src = new InputSource(in);
+        src.setSystemId(systemId);
+        
+        return src;
+    }
+}
CVSspam 0.2.8