Added parser method that takes a URL to fix metadatatool.
authorcantor <cantor@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 14 Jun 2005 19:07:35 +0000 (19:07 +0000)
committercantor <cantor@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 14 Jun 2005 19:07:35 +0000 (19:07 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1623 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/utils/MetadataTool.java
src/edu/internet2/middleware/shibboleth/xml/Parser.java

index 6c170c7..1d33e0c 100644 (file)
@@ -19,6 +19,7 @@ package edu.internet2.middleware.shibboleth.utils;
 import jargs.gnu.CmdLineParser;
 
 import java.io.*;
+import java.net.URL;
 import java.security.*;
 import java.security.cert.Certificate;
 import java.security.cert.*;
@@ -152,7 +153,7 @@ public class MetadataTool {
                }
 
                // Parse file and verify root element.
-               Document doc = Parser.loadDom(infile, true);
+               Document doc = Parser.loadDom(new URL(new URL("file:"),infile), true);
                if (doc == null) {
                        System.out.println("error: unable to read in file (" + infile + ")");
                        System.exit(-1);
index ce49fe3..c437a64 100644 (file)
@@ -41,6 +41,7 @@ package edu.internet2.middleware.shibboleth.xml;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
+import java.net.URL;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -269,8 +270,7 @@ public class Parser {
      */
     public static Document loadDom(String configFilePath,boolean validate) throws SAMLException, SAXException, IOException 
     {
-        InputSource insrc;
-        String schemaCannonicalFilePath;
+       InputSource insrc;
        try {
             InputStream resourceAsStream = 
  //               Parser.class.getResourceAsStream(configFilePath);
@@ -285,6 +285,29 @@ public class Parser {
         return loadDom(insrc,validate); // Now pass on to the main routine
         
     }
+
+    /**
+     * Version of loadDom where the file is specified as a URL.
+     * 
+     * @param configURL input resource
+     * @param validate if true, use Schema
+     * @return DOM tree
+     */
+    public static Document loadDom(URL configURL, boolean validate) throws SAMLException, SAXException, IOException 
+    {
+       InputSource insrc;
+       try {
+            InputStream resourceAsStream = configURL.openStream();
+            insrc = new InputSource(resourceAsStream);
+            insrc.setSystemId(configURL.toString());
+        } catch (Exception e1) {
+            log.error("Configuration URL "+configURL+" could not be accessed.");
+            return null;
+        }
+        
+        return loadDom(insrc,validate); // Now pass on to the main routine
+        
+    }
     
     /**
      * Override the OpenSAML default schema from SAML 1.1 to