Replace DOMParser with calls to pool or helper class.
authorgilbert <gilbert@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 27 Jan 2005 19:20:42 +0000 (19:20 +0000)
committergilbert <gilbert@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 27 Jan 2005 19:20:42 +0000 (19:20 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1225 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

13 files changed:
src/edu/internet2/middleware/shibboleth/aa/arp/ArpEngine.java
src/edu/internet2/middleware/shibboleth/aa/arp/provider/FileSystemArpRepository.java
src/edu/internet2/middleware/shibboleth/common/Init.java
src/edu/internet2/middleware/shibboleth/common/NameMapper.java
src/edu/internet2/middleware/shibboleth/common/OriginConfig.java
src/edu/internet2/middleware/shibboleth/common/XML.java
src/edu/internet2/middleware/shibboleth/metadata/provider/XMLMetadataLoadWrapper.java
src/edu/internet2/middleware/shibboleth/utils/MetadataTool.java
src/edu/internet2/middleware/shibboleth/utils/ResolverTest.java
tests/edu/internet2/middleware/shibboleth/aa/arp/ArpTests.java
tests/edu/internet2/middleware/shibboleth/common/CredentialsTests.java
tests/edu/internet2/middleware/shibboleth/hs/provider/NameMapperTests.java
tests/edu/internet2/middleware/shibboleth/metadata/MetadataTests.java

index b12f4fd..4a0cc56 100755 (executable)
@@ -37,7 +37,6 @@
 
 package edu.internet2.middleware.shibboleth.aa.arp;
 
 
 package edu.internet2.middleware.shibboleth.aa.arp;
 
-import java.io.StringWriter;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -54,8 +53,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.log4j.Logger;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.log4j.Logger;
-import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.XMLSerializer;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
@@ -63,6 +60,7 @@ import org.w3c.dom.Text;
 
 import edu.internet2.middleware.shibboleth.aa.arp.ArpAttributeSet.ArpAttributeIterator;
 import edu.internet2.middleware.shibboleth.common.ShibbolethOriginConfig;
 
 import edu.internet2.middleware.shibboleth.aa.arp.ArpAttributeSet.ArpAttributeIterator;
 import edu.internet2.middleware.shibboleth.common.ShibbolethOriginConfig;
+import edu.internet2.middleware.shibboleth.xml.Parser;
 
 /**
  * Defines a processing engine for Attribute Release Policies.
 
 /**
  * Defines a processing engine for Attribute Release Policies.
@@ -214,12 +212,8 @@ public class ArpEngine {
                                log.debug("Creating effective ARP from (" + userPolicies.length + ") polic(y|ies).");
                                try {
                                        for (int i = 0; userPolicies.length > i; i++) {
                                log.debug("Creating effective ARP from (" + userPolicies.length + ") polic(y|ies).");
                                try {
                                        for (int i = 0; userPolicies.length > i; i++) {
-                                               StringWriter writer = new StringWriter();
-                                               OutputFormat format = new OutputFormat();
-                                               format.setIndent(4);
-                                               XMLSerializer serializer = new XMLSerializer(writer, format);
-                                               serializer.serialize(userPolicies[i].unmarshall());
-                                               log.debug("Dumping ARP:" + System.getProperty("line.separator") + writer.toString());
+                                               String dump=Parser.serialize(userPolicies[i].unmarshall());
+                                               log.debug("Dumping ARP:" + System.getProperty("line.separator") + dump);
                                        }
                                } catch (Exception e) {
                                        log.error(
                                        }
                                } catch (Exception e) {
                                        log.error(
index fa519a0..68d403e 100755 (executable)
@@ -52,21 +52,17 @@ import java.io.IOException;
 import java.security.Principal;
 
 import org.apache.log4j.Logger;
 import java.security.Principal;
 
 import org.apache.log4j.Logger;
-import org.apache.xerces.parsers.DOMParser;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
 import edu.internet2.middleware.shibboleth.aa.arp.Arp;
 import edu.internet2.middleware.shibboleth.aa.arp.ArpRepository;
 import edu.internet2.middleware.shibboleth.aa.arp.ArpRepositoryException;
 import edu.internet2.middleware.shibboleth.common.ShibResource;
 import edu.internet2.middleware.shibboleth.common.ShibbolethOriginConfig;
 import edu.internet2.middleware.shibboleth.aa.arp.Arp;
 import edu.internet2.middleware.shibboleth.aa.arp.ArpRepository;
 import edu.internet2.middleware.shibboleth.aa.arp.ArpRepositoryException;
 import edu.internet2.middleware.shibboleth.common.ShibResource;
 import edu.internet2.middleware.shibboleth.common.ShibbolethOriginConfig;
+import edu.internet2.middleware.shibboleth.xml.Parser;
 
 /**
  * Simple <code>ArpRepository</code> implementation that uses a filesystem
 
 /**
  * Simple <code>ArpRepository</code> implementation that uses a filesystem
@@ -156,36 +152,7 @@ public class FileSystemArpRepository extends BaseArpRepository implements ArpRep
                                return null;
                        }
 
                                return null;
                        }
 
-                       DOMParser parser = new DOMParser();
-                       parser.setFeature("http://xml.org/sax/features/validation", true);
-                       parser.setFeature("http://apache.org/xml/features/validation/schema", true);
-                       parser.setEntityResolver(new EntityResolver() {
-                               public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
-
-                                       if (systemId.endsWith("shibboleth-arp-1.0.xsd")) {
-                                               try {
-                                                       return new InputSource(
-                                                               new ShibResource("/schemas/shibboleth-arp-1.0.xsd", this.getClass()).getInputStream());
-                                               } catch (IOException e) {
-                                                       throw new SAXException("Could not load entity: " + e);
-                                               }
-                                       } else {
-                                               return null;
-                                       }
-                               }
-                       });
-
-                       parser.setErrorHandler(new ErrorHandler() {
-                               public void error(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                               public void fatalError(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                               public void warning(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                       });
+                       Parser.DOMParser parser = new Parser.DOMParser(true);
                        parser.parse(new InputSource(resource.getInputStream()));
                        return parser.getDocument().getDocumentElement();
 
                        parser.parse(new InputSource(resource.getInputStream()));
                        return parser.getDocument().getDocumentElement();
 
index 734401a..5b288e0 100755 (executable)
@@ -70,7 +70,6 @@ public class Init
 
         initialized = true;
         
 
         initialized = true;
         
-        org.opensaml.XML.parserPool.registerSchema(XML.SHIB_NS, XML.SHIB_SCHEMA_ID, new XML.SchemaResolver());
     }
 
     static
     }
 
     static
index 82b7523..bcc5a43 100644 (file)
@@ -35,13 +35,13 @@ import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
 import java.util.Map;
 
 import org.apache.log4j.Logger;
-import org.apache.xerces.parsers.DOMParser;
 import org.opensaml.SAMLException;
 import org.opensaml.SAMLNameIdentifier;
 import org.w3c.dom.Element;
 import org.xml.sax.InputSource;
 
 import edu.internet2.middleware.shibboleth.hs.provider.SharedMemoryShibHandle;
 import org.opensaml.SAMLException;
 import org.opensaml.SAMLNameIdentifier;
 import org.w3c.dom.Element;
 import org.xml.sax.InputSource;
 
 import edu.internet2.middleware.shibboleth.hs.provider.SharedMemoryShibHandle;
+import edu.internet2.middleware.shibboleth.xml.Parser;
 
 /**
  * Facility for managing mappings from SAML Name Identifiers to local {@link AuthNPrincipal}objects. Mappings are
 
 /**
  * Facility for managing mappings from SAML Name Identifiers to local {@link AuthNPrincipal}objects. Mappings are
@@ -88,7 +88,7 @@ public class NameMapper {
                        //Load the default mapping
                        String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                                        + "<NameMapping format=\"urn:mace:shibboleth:1.0:nameIdentifier\"" + "          handleTTL=\"1800\"/>";
                        //Load the default mapping
                        String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                                        + "<NameMapping format=\"urn:mace:shibboleth:1.0:nameIdentifier\"" + "          handleTTL=\"1800\"/>";
-                       DOMParser parser = new DOMParser();
+                       Parser.DOMParser parser = new Parser.DOMParser(false);
                        parser.parse(new InputSource(new StringReader(rawConfig)));
                        defaultMapping = new SharedMemoryShibHandle(parser.getDocument().getDocumentElement());
 
                        parser.parse(new InputSource(new StringReader(rawConfig)));
                        defaultMapping = new SharedMemoryShibHandle(parser.getDocument().getDocumentElement());
 
index 79f1133..ad4579c 100644 (file)
 
 package edu.internet2.middleware.shibboleth.common;
 
 
 package edu.internet2.middleware.shibboleth.common;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.StringTokenizer;
-
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContext;
-
 import org.apache.log4j.Logger;
 import org.apache.log4j.Logger;
-import org.apache.xerces.parsers.DOMParser;
 import org.w3c.dom.Document;
 import org.w3c.dom.Document;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
+
+import edu.internet2.middleware.shibboleth.xml.Parser;
 
 /**
  * Constructs a DOM tree for the origin configuration XML file.
 
 /**
  * Constructs a DOM tree for the origin configuration XML file.
@@ -82,73 +73,10 @@ public class OriginConfig {
                                        + configFileLocation + "). This probably indicates a bug in shibboleth.");
                        originConfigFile = configFileLocation;
                }
                                        + configFileLocation + "). This probably indicates a bug in shibboleth.");
                        originConfigFile = configFileLocation;
                }
-
-               DOMParser parser = new DOMParser();
-
-               try {
-                       parser.setFeature("http://xml.org/sax/features/validation", true);
-                       parser.setFeature("http://apache.org/xml/features/validation/schema", true);
-
-                       parser.setEntityResolver(new EntityResolver() {
-
-                               public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
-                                       log.debug("Resolving entity for System ID: " + systemId);
-                                       if (systemId != null) {
-                                               StringTokenizer tokenString = new StringTokenizer(systemId, "/");
-                                               String xsdFile = "";
-                                               while (tokenString.hasMoreTokens()) {
-                                                       xsdFile = tokenString.nextToken();
-                                               }
-                                               if (xsdFile.endsWith(".xsd")) {
-                                                       InputStream stream;
-                                                       try {
-                                                               stream = new ShibResource("/schemas/" + xsdFile, OriginConfig.class).getInputStream();
-                                                       } catch (IOException ioe) {
-                                                               log.error("Error loading schema: " + xsdFile + ": " + ioe);
-                                                               return null;
-                                                       }
-                                                       if (stream != null) {
-                                                               return new InputSource(stream);
-                                                       }
-                                               }
-                                       }
-                                       return null;
-                               }
-                       });
-
-                       parser.setErrorHandler(new ErrorHandler() {
-
-                               public void error(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-
-                               public void fatalError(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-
-                               public void warning(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                       });
-
-               } catch (SAXException e) {
-                       log.error("Unable to setup a workable XML parser: " + e);
-                       throw new ShibbolethConfigurationException("Unable to setup a workable XML parser.");
-               }
-
-               log.debug("Loading Configuration from (" + originConfigFile + ").");
-
-               try {
-                       parser.parse(new InputSource(new ShibResource(originConfigFile, OriginConfig.class).getInputStream()));
-               } catch (SAXException e) {
-                       log.error("Error while parsing origin configuration: " + e);
-                       throw new ShibbolethConfigurationException("Error while parsing origin configuration:" + e);
-               } catch (IOException e) {
-                       log.error("Could not load origin configuration: " + e);
-                       throw new ShibbolethConfigurationException("Could not load origin configuration.");
-               }
-
-               originConfig = parser.getDocument();
+               
+               originConfig = Parser.loadDom(configFileLocation, true);
+               if (originConfig==null)
+                   throw new ShibbolethConfigurationException("Problem in "+XML.ORIGIN_SHEMA_ID+" see log");
 
                return originConfig;
        }
 
                return originConfig;
        }
index a3b8f76..d4c22aa 100755 (executable)
 
 package edu.internet2.middleware.shibboleth.common;
 
 
 package edu.internet2.middleware.shibboleth.common;
 
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
 
 /**
 
 /**
- *  Utility class for XML constants and schema handling
+ *  Utility class for XML constants
  *
  * @author     Scott Cantor
  * @created    January 2, 2002
  *
  * @author     Scott Cantor
  * @created    January 2, 2002
@@ -65,10 +60,10 @@ public class XML
 {
     /**  Shibboleth XML namespace */
     public final static String SHIB_NS = "urn:mace:shibboleth:1.0";
 {
     /**  Shibboleth XML namespace */
     public final static String SHIB_NS = "urn:mace:shibboleth:1.0";
-
+    
     /**  Shibboleth XML schema identifier */
     public final static String SHIB_SCHEMA_ID = "shibboleth.xsd";
     /**  Shibboleth XML schema identifier */
     public final static String SHIB_SCHEMA_ID = "shibboleth.xsd";
-
+    
     /**  Shibboleth trust metadata XML namespace */
     public final static String TRUST_NS = "urn:mace:shibboleth:trust:1.0";
     
     /**  Shibboleth trust metadata XML namespace */
     public final static String TRUST_NS = "urn:mace:shibboleth:trust:1.0";
     
@@ -76,69 +71,11 @@ public class XML
     public final static String TRUST_SCHEMA_ID = "shibboleth-trust-1.0.xsd";
     
     public final static String MAIN_SHEMA_ID = "shibboleth-targetconfig-1.0.xsd";
     public final static String TRUST_SCHEMA_ID = "shibboleth-trust-1.0.xsd";
     
     public final static String MAIN_SHEMA_ID = "shibboleth-targetconfig-1.0.xsd";
+    public final static String ORIGIN_SHEMA_ID = "origin.xsd";
     
     
-       public final static String XMLSIG_RETMETHOD_RAWX509    = "http://www.w3.org/2000/09/xmldsig#rawX509Certificate";
+    public final static String XMLSIG_RETMETHOD_RAWX509    = "http://www.w3.org/2000/09/xmldsig#rawX509Certificate";
     public final static String XMLSIG_RETMETHOD_RAWX509CRL = "http://www.w3.org/2000/09/xmldsig-more#rawX509CRL";
     public final static String SHIB_RETMETHOD_PEMX509      = "urn:mace:shibboleth:RetrievalMethod:pemX509Certificate";
     public final static String SHIB_RETMETHOD_PEMX509CRL   = "urn:mace:shibboleth:RetrievalMethod:pemX509CRL";
     
     public final static String XMLSIG_RETMETHOD_RAWX509CRL = "http://www.w3.org/2000/09/xmldsig-more#rawX509CRL";
     public final static String SHIB_RETMETHOD_PEMX509      = "urn:mace:shibboleth:RetrievalMethod:pemX509Certificate";
     public final static String SHIB_RETMETHOD_PEMX509CRL   = "urn:mace:shibboleth:RetrievalMethod:pemX509CRL";
     
-    private static byte[] Shib_schema;
-    private static byte[] Trust_schema;
-
-    /**
-     *  Custom schema resolver class
-     *
-     * @author     Scott Cantor
-     * @created    May 18, 2002
-     */
-    public static class SchemaResolver implements EntityResolver {
-        /**
-         *  A customized entity resolver for the Shibboleth extension schema
-         *
-         * @param  publicId                 The public identifier of the entity
-         * @param  systemId                 The system identifier of the entity
-         * @return                          A source of bytes for the entity or null
-         * @exception  SAXException         Raised if an XML parsing problem occurs
-         * @exception  java.io.IOException  Raised if an I/O problem is detected
-         */
-        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, java.io.IOException {
-            InputSource src = null;
-            if (systemId.endsWith(SHIB_SCHEMA_ID) && Shib_schema != null)
-                src = new InputSource(new ByteArrayInputStream(Shib_schema));
-            else if (systemId.endsWith(TRUST_SCHEMA_ID) && Trust_schema != null)
-                src = new InputSource(new ByteArrayInputStream(Trust_schema));
-            return src;
-        }
-    }
-
-    static {
-        try {
-            StringBuffer buf = new StringBuffer(4096);
-            InputStream xmlin = XML.class.getResourceAsStream("/schemas/" + SHIB_SCHEMA_ID);
-            if (xmlin == null)
-                throw new RuntimeException("XML static initializer unable to locate Shibboleth schema");
-            else {
-                int b;
-                while ((b = xmlin.read()) != -1)
-                    buf.append((char)b);
-                Shib_schema = buf.toString().getBytes();
-                xmlin.close();
-            }
-
-            xmlin = XML.class.getResourceAsStream("/schemas/" + TRUST_SCHEMA_ID);
-            if (xmlin == null)
-                throw new RuntimeException("XML static initializer unable to locate Shibboleth trust schema");
-            else {
-                int b;
-                buf.setLength(0);
-                while ((b = xmlin.read()) != -1)
-                    buf.append((char)b);
-                Trust_schema = buf.toString().getBytes();
-                xmlin.close();
-            }
-        }
-        catch (java.io.IOException e) {
-            throw new RuntimeException("XML static initializer caught an I/O error");
-        }
-    }
 }
 }
index b0f3418..564d180 100644 (file)
@@ -31,6 +31,7 @@ import org.apache.log4j.Logger;
 import org.opensaml.SAMLException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.opensaml.SAMLException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import edu.internet2.middleware.shibboleth.common.ResourceWatchdog;
 import edu.internet2.middleware.shibboleth.common.ResourceWatchdogExecutionException;
 import org.xml.sax.SAXException;
 import edu.internet2.middleware.shibboleth.common.ResourceWatchdog;
 import edu.internet2.middleware.shibboleth.common.ResourceWatchdogExecutionException;
@@ -40,6 +41,7 @@ import edu.internet2.middleware.shibboleth.common.ShibResource.ResourceNotAvaila
 import edu.internet2.middleware.shibboleth.metadata.Metadata;
 import edu.internet2.middleware.shibboleth.metadata.MetadataException;
 import edu.internet2.middleware.shibboleth.metadata.Provider;
 import edu.internet2.middleware.shibboleth.metadata.Metadata;
 import edu.internet2.middleware.shibboleth.metadata.MetadataException;
 import edu.internet2.middleware.shibboleth.metadata.Provider;
+import edu.internet2.middleware.shibboleth.xml.Parser;
 
 /**
  * @author Walter Hoehn (wassa@columbia.edu)
 
 /**
  * @author Walter Hoehn (wassa@columbia.edu)
@@ -56,15 +58,8 @@ public class XMLMetadataLoadWrapper extends ResourceWatchdog implements Metadata
        public XMLMetadataLoadWrapper(String sitesFileLocation) throws MetadataException, ResourceNotAvailableException {
                super(new ShibResource(sitesFileLocation, XMLMetadataLoadWrapper.class));
                try {
        public XMLMetadataLoadWrapper(String sitesFileLocation) throws MetadataException, ResourceNotAvailableException {
                super(new ShibResource(sitesFileLocation, XMLMetadataLoadWrapper.class));
                try {
-                       org.opensaml.XML.parserPool.registerSchema(XML.SHIB_NS, XML.SHIB_SCHEMA_ID, new XML.SchemaResolver());
-                       Document doc = org.opensaml.XML.parserPool.parse(resource.getInputStream());
+                       Document doc = Parser.loadDom(new InputSource(resource.getInputStream()),true);
                        currentMeta = new XMLMetadata(doc.getDocumentElement());
                        currentMeta = new XMLMetadata(doc.getDocumentElement());
-               } catch (SAMLException e) {
-                       log.error("Encountered a problem parsing federation metadata source: " + e);
-                       throw new MetadataException("Unable to parse federation metadata.");
-               } catch (SAXException e) {
-                       log.error("Encountered a problem parsing federation metadata source: " + e);
-                       throw new MetadataException("Unable to parse federation metadata.");
                } catch (IOException e) {
                        log.error("Encountered a problem reading federation metadata source: " + e);
                        throw new MetadataException("Unable to read federation metadata.");
                } catch (IOException e) {
                        log.error("Encountered a problem reading federation metadata source: " + e);
                        throw new MetadataException("Unable to read federation metadata.");
@@ -94,14 +89,8 @@ public class XMLMetadataLoadWrapper extends ResourceWatchdog implements Metadata
 
                //Load new, but keep the old in place
                try {
 
                //Load new, but keep the old in place
                try {
-            newDoc = org.opensaml.XML.parserPool.parse(resource.getInputStream());
-        } catch (SAMLException e) {
-            log.error("Encountered an error parsing updated federation metadata, continuing to use stale copy.");
-            return;
-               } catch (SAXException e) {
-                       log.error("Encountered an error parsing updated federation metadata, continuing to use stale copy.");
-                       return;
-               } catch (IOException e) {
+            newDoc = Parser.loadDom(new InputSource(resource.getInputStream()),true);
+        } catch (IOException e) {
                        log.error("Encountered an error retrieving updated federation metadata, continuing to use stale copy.");
                        return;
                }
                        log.error("Encountered an error retrieving updated federation metadata, continuing to use stale copy.");
                        return;
                }
index afb8d77..db27ab7 100644 (file)
@@ -66,6 +66,7 @@ import org.apache.xml.security.transforms.*;
 import org.w3c.dom.*;
 
 import edu.internet2.middleware.shibboleth.common.XML;
 import org.w3c.dom.*;
 
 import edu.internet2.middleware.shibboleth.common.XML;
+import edu.internet2.middleware.shibboleth.xml.Parser;
 
 /**
  *  Signs/verifies/maintains Shibboleth metadata files
 
 /**
  *  Signs/verifies/maintains Shibboleth metadata files
@@ -180,11 +181,9 @@ public class MetadataTool
             System.exit(1);
         }
         
             System.exit(1);
         }
         
-        org.opensaml.XML.parserPool.registerSchema(XML.SHIB_NS, XML.SHIB_SCHEMA_ID, new XML.SchemaResolver());
-        org.opensaml.XML.parserPool.registerSchema(XML.TRUST_NS, XML.TRUST_SCHEMA_ID, new XML.SchemaResolver());
         
         // Parse file and verify root element.
         
         // Parse file and verify root element.
-        Document doc = org.opensaml.XML.parserPool.parse(infile);
+        Document doc = Parser.loadDom(infile,true);
         Element e = doc.getDocumentElement();
         if (ns != null && name != null && !org.opensaml.XML.isElementNamed(e,ns,name)) {
             System.err.println("error: root element did not match ns and name parameters");
         Element e = doc.getDocumentElement();
         if (ns != null && name != null && !org.opensaml.XML.isElementNamed(e,ns,name)) {
             System.err.println("error: root element did not match ns and name parameters");
index 5f85fde..0032e6d 100644 (file)
@@ -52,7 +52,6 @@ package edu.internet2.middleware.shibboleth.utils;
 import jargs.gnu.CmdLineParser;
 
 import java.io.ByteArrayOutputStream;
 import jargs.gnu.CmdLineParser;
 
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.net.URL;
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.net.URL;
@@ -63,8 +62,6 @@ import org.apache.log4j.ConsoleAppender;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PatternLayout;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PatternLayout;
-import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.XMLSerializer;
 import org.opensaml.SAMLException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.opensaml.SAMLException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -84,6 +81,7 @@ import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
 import edu.internet2.middleware.shibboleth.common.OriginConfig;
 import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
 import edu.internet2.middleware.shibboleth.common.ShibbolethOriginConfig;
 import edu.internet2.middleware.shibboleth.common.OriginConfig;
 import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
 import edu.internet2.middleware.shibboleth.common.ShibbolethOriginConfig;
+import edu.internet2.middleware.shibboleth.xml.Parser;
 
 /**
  * Utility for testing an Attribute Resolver configuration.
 
 /**
  * Utility for testing an Attribute Resolver configuration.
@@ -288,13 +286,7 @@ public class ResolverTest
                                        System.err.println("Received bad Element data from SAML library.");
                                        System.exit(1);
                                }
                                        System.err.println("Received bad Element data from SAML library.");
                                        System.exit(1);
                                }
-                               OutputFormat format = new OutputFormat();
-                               format.setIndenting(true);
-                               format.setIndent(4);
-
-                               new XMLSerializer(xml, format).serialize((Element) node);
-
-                               out.println(xml.toString());
+                               out.println(Parser.serialize(node));
                                out.println();
                        }
                }
                                out.println();
                        }
                }
@@ -302,10 +294,6 @@ public class ResolverTest
                        System.err.println("Error creating SAML attribute: " + e.getMessage());
                        System.exit(1);
                }
                        System.err.println("Error creating SAML attribute: " + e.getMessage());
                        System.exit(1);
                }
-               catch (IOException e) {
-                       System.err.println("Error serializing output from Resolver: " + e.getMessage());
-                       System.exit(1);
-               }
        }
 
        private static void configureLogging(boolean debugEnabled) 
        }
 
        private static void configureLogging(boolean debugEnabled) 
index 1097ac2..109dcc8 100755 (executable)
@@ -71,9 +71,6 @@ import junit.framework.TestCase;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
-import org.apache.xerces.parsers.DOMParser;
-import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.XMLSerializer;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Text;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Text;
@@ -87,6 +84,7 @@ import edu.internet2.middleware.shibboleth.aa.AAAttribute;
 import edu.internet2.middleware.shibboleth.aa.AAAttributeSet;
 import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
 import edu.internet2.middleware.shibboleth.common.ShibbolethOriginConfig;
 import edu.internet2.middleware.shibboleth.aa.AAAttributeSet;
 import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
 import edu.internet2.middleware.shibboleth.common.ShibbolethOriginConfig;
+import edu.internet2.middleware.shibboleth.xml.Parser;
 
 /**
  * Validation suite for <code>Arp</code> processing.
 
 /**
  * Validation suite for <code>Arp</code> processing.
@@ -96,7 +94,7 @@ import edu.internet2.middleware.shibboleth.common.ShibbolethOriginConfig;
 
 public class ArpTests extends TestCase {
 
 
 public class ArpTests extends TestCase {
 
-       private DOMParser parser = new DOMParser();
+       private Parser.DOMParser parser = new Parser.DOMParser(true);
        Element memoryRepositoryElement;
        private String[] arpExamples =
                {
        Element memoryRepositoryElement;
        private String[] arpExamples =
                {
@@ -133,43 +131,6 @@ public class ArpTests extends TestCase {
                super.setUp();
 
                // Setup an xml parser
                super.setUp();
 
                // Setup an xml parser
-               try {
-                       parser.setFeature("http://xml.org/sax/features/validation", true);
-                       parser.setFeature("http://apache.org/xml/features/validation/schema", true);
-                       parser.setEntityResolver(new EntityResolver() {
-                               public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
-
-                                       if (systemId.endsWith("shibboleth-arp-1.0.xsd")) {
-                                               InputStream stream;
-                                               try {
-                                                       stream = new FileInputStream("src/schemas/shibboleth-arp-1.0.xsd");
-                                                       if (stream != null) {
-                                                               return new InputSource(stream);
-                                                       }
-                                                       throw new SAXException("Could not load entity: Null input stream");
-                                               } catch (FileNotFoundException e) {
-                                                       throw new SAXException("Could not load entity: " + e);
-                                               }
-                                       } else {
-                                               return null;
-                                       }
-                               }
-                       });
-
-                       parser.setErrorHandler(new ErrorHandler() {
-                               public void error(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                               public void fatalError(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                               public void warning(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                       });
-               } catch (Exception e) {
-                       fail("Failed to setup xml parser: " + e);
-               }
 
                //Setup a dummy xml config for a Memory-based repository
                DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
 
                //Setup a dummy xml config for a Memory-based repository
                DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
@@ -561,11 +522,9 @@ public class ArpTests extends TestCase {
 
                        InputStream inStream = new FileInputStream("data/arp.site.xml");
                        parser.parse(new InputSource(inStream));
 
                        InputStream inStream = new FileInputStream("data/arp.site.xml");
                        parser.parse(new InputSource(inStream));
-                       ByteArrayOutputStream directXML = new ByteArrayOutputStream();
-                       new XMLSerializer(directXML, new OutputFormat()).serialize(parser.getDocument().getDocumentElement());
+                       String directXML = Parser.serialize(parser.getDocument().getDocumentElement());
 
 
-                       ByteArrayOutputStream processedXML = new ByteArrayOutputStream();
-                       new XMLSerializer(processedXML, new OutputFormat()).serialize(siteArp.unmarshall());
+                       String processedXML = Parser.serialize(siteArp.unmarshall());
 
                        assertTrue(
                                "File-based ARP Repository did not return the correct site ARP.",
 
                        assertTrue(
                                "File-based ARP Repository did not return the correct site ARP.",
@@ -576,11 +535,9 @@ public class ArpTests extends TestCase {
 
                        inStream = new FileInputStream("data/arp.user.test.xml");
                        parser.parse(new InputSource(inStream));
 
                        inStream = new FileInputStream("data/arp.user.test.xml");
                        parser.parse(new InputSource(inStream));
-                       directXML = new ByteArrayOutputStream();
-                       new XMLSerializer(directXML, new OutputFormat()).serialize(parser.getDocument().getDocumentElement());
+                       directXML = Parser.serialize(parser.getDocument().getDocumentElement());
 
 
-                       processedXML = new ByteArrayOutputStream();
-                       new XMLSerializer(processedXML, new OutputFormat()).serialize(userArp.unmarshall());
+                       processedXML = Parser.serialize(userArp.unmarshall());
 
                        assertTrue(
                                "File-based ARP Repository did not return the correct user ARP.",
 
                        assertTrue(
                                "File-based ARP Repository did not return the correct user ARP.",
@@ -713,14 +670,12 @@ public class ArpTests extends TestCase {
 
                                InputStream inStream = new FileInputStream(arpExamples[i]);
                                parser.parse(new InputSource(inStream));
 
                                InputStream inStream = new FileInputStream(arpExamples[i]);
                                parser.parse(new InputSource(inStream));
-                               ByteArrayOutputStream directXML = new ByteArrayOutputStream();
-                               new XMLSerializer(directXML, new OutputFormat()).serialize(parser.getDocument().getDocumentElement());
+                               String directXML = Parser.serialize(parser.getDocument().getDocumentElement());
 
                                Arp arp1 = new Arp();
                                arp1.marshall(parser.getDocument().getDocumentElement());
 
 
                                Arp arp1 = new Arp();
                                arp1.marshall(parser.getDocument().getDocumentElement());
 
-                               ByteArrayOutputStream processedXML = new ByteArrayOutputStream();
-                               new XMLSerializer(processedXML, new OutputFormat()).serialize(arp1.unmarshall());
+                               String processedXML = Parser.serialize(arp1.unmarshall());
 
                                assertTrue(
                                        "Round trip marshall/unmarshall failed for file (" + arpExamples[i] + ")",
 
                                assertTrue(
                                        "Round trip marshall/unmarshall failed for file (" + arpExamples[i] + ")",
@@ -738,7 +693,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: Any value release,
         */
         * Target: Any
         * Attribute: Any value release,
         */
-       void arpApplicationTest1(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest1(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -786,7 +741,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: Any value release, implicit deny
         */
         * Target: Any
         * Attribute: Any value release, implicit deny
         */
-       void arpApplicationTest2(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest2(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -841,7 +796,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: One value release
         */
         * Target: Any
         * Attribute: One value release
         */
-       void arpApplicationTest3(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest3(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -888,7 +843,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: Any value except one release, canonical representation
         */
         * Target: Any
         * Attribute: Any value except one release, canonical representation
         */
-       void arpApplicationTest4(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest4(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -936,7 +891,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: Any value except one release, expanded representation
         */
         * Target: Any
         * Attribute: Any value except one release, expanded representation
         */
-       void arpApplicationTest5(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest5(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -986,7 +941,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: Any value except two release, expanded representation
         */
         * Target: Any
         * Attribute: Any value except two release, expanded representation
         */
-       void arpApplicationTest6(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest6(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1039,7 +994,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: Two value release, canonical representation
         */
         * Target: Any
         * Attribute: Two value release, canonical representation
         */
-       void arpApplicationTest7(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest7(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1087,7 +1042,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: Two value release, expanded representation
         */
         * Target: Any
         * Attribute: Two value release, expanded representation
         */
-       void arpApplicationTest8(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest8(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1137,7 +1092,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: Any value deny
         */
         * Target: Any
         * Attribute: Any value deny
         */
-       void arpApplicationTest9(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest9(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1179,7 +1134,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: Any value deny trumps explicit permit expanded representation
         */
         * Target: Any
         * Attribute: Any value deny trumps explicit permit expanded representation
         */
-       void arpApplicationTest10(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest10(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1224,7 +1179,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: Any value deny trumps explicit permit canonical representation
         */
         * Target: Any
         * Attribute: Any value deny trumps explicit permit canonical representation
         */
-       void arpApplicationTest11(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest11(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1267,7 +1222,7 @@ public class ArpTests extends TestCase {
         * Target: Specific shar, Any Resource
         * Attribute: Any value release
         */
         * Target: Specific shar, Any Resource
         * Attribute: Any value release
         */
-       void arpApplicationTest12(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest12(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1315,7 +1270,7 @@ public class ArpTests extends TestCase {
         * Target: Specific shar, Any Resource (another example)
         * Attribute: Any value release
         */
         * Target: Specific shar, Any Resource (another example)
         * Attribute: Any value release
         */
-       void arpApplicationTest13(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest13(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1363,7 +1318,7 @@ public class ArpTests extends TestCase {
         * Target: Specific shar (no match), Any Resource
         * Attribute: Any value release
         */
         * Target: Specific shar (no match), Any Resource
         * Attribute: Any value release
         */
-       void arpApplicationTest14(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest14(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1406,7 +1361,7 @@ public class ArpTests extends TestCase {
         * Target: Specific shar, Specific resource
         * Attribute: Any value release
         */
         * Target: Specific shar, Specific resource
         * Attribute: Any value release
         */
-       void arpApplicationTest15(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest15(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1454,7 +1409,7 @@ public class ArpTests extends TestCase {
         * Target: Specific shar, Specific resource (no match)
         * Attribute: Any value release
         */
         * Target: Specific shar, Specific resource (no match)
         * Attribute: Any value release
         */
-       void arpApplicationTest16(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest16(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1497,7 +1452,7 @@ public class ArpTests extends TestCase {
         * Target: Multiple matching rules
         * Attribute: various
         */
         * Target: Multiple matching rules
         * Attribute: various
         */
-       void arpApplicationTest17(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest17(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1573,7 +1528,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: Any value release of two attributes in one rule
         */
         * Target: Any
         * Attribute: Any value release of two attributes in one rule
         */
-       void arpApplicationTest18(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest18(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1634,7 +1589,7 @@ public class ArpTests extends TestCase {
         * Target: Any
         * Attribute: Any value release,
         */
         * Target: Any
         * Attribute: Any value release,
         */
-       void arpApplicationTest19(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest19(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1682,7 +1637,7 @@ public class ArpTests extends TestCase {
         * Target: various
         * Attribute: various combinations
         */
         * Target: various
         * Attribute: various combinations
         */
-       void arpApplicationTest20(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest20(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawSiteArp =
 
                //Gather the Input
                String rawSiteArp =
@@ -1819,7 +1774,7 @@ public class ArpTests extends TestCase {
         * Target: various
         * Attribute: various combinations (same ARPs as 20, different requester)
         */
         * Target: various
         * Attribute: various combinations (same ARPs as 20, different requester)
         */
-       void arpApplicationTest21(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest21(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawSiteArp =
 
                //Gather the Input
                String rawSiteArp =
@@ -1952,7 +1907,7 @@ public class ArpTests extends TestCase {
         * Target: Specific shar, Specific resource
         * Attribute: Release values by regex
         */
         * Target: Specific shar, Specific resource
         * Attribute: Release values by regex
         */
-       void arpApplicationTest22(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest22(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -1999,7 +1954,7 @@ public class ArpTests extends TestCase {
         * Target: Specific shar, Specific resource
         * Attribute: Deny specific values by regex
         */
         * Target: Specific shar, Specific resource
         * Attribute: Deny specific values by regex
         */
-       void arpApplicationTest23(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest23(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
@@ -2048,7 +2003,7 @@ public class ArpTests extends TestCase {
         * Target: Specific shar, Specific resource
         * Attribute: No matches on specific values should yield no attribute
         */
         * Target: Specific shar, Specific resource
         * Attribute: No matches on specific values should yield no attribute
         */
-       void arpApplicationTest24(ArpRepository repository, DOMParser parser) throws Exception {
+       void arpApplicationTest24(ArpRepository repository, Parser.DOMParser parser) throws Exception {
 
                //Gather the Input
                String rawArp =
 
                //Gather the Input
                String rawArp =
index 2698d9c..d96c177 100644 (file)
@@ -38,7 +38,6 @@
 package edu.internet2.middleware.shibboleth.common;
 
 import java.io.FileInputStream;
 package edu.internet2.middleware.shibboleth.common;
 
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.InputStream;
 
 import junit.framework.TestCase;
 import java.io.InputStream;
 
 import junit.framework.TestCase;
@@ -46,12 +45,8 @@ import junit.framework.TestCase;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
-import org.apache.xerces.parsers.DOMParser;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
+import edu.internet2.middleware.shibboleth.xml.Parser;
 
 /**
  * Validation suite for the <code>Credentials</code> interface.
 
 /**
  * Validation suite for the <code>Credentials</code> interface.
@@ -61,7 +56,7 @@ import org.xml.sax.SAXParseException;
 
 public class CredentialsTests extends TestCase {
 
 
 public class CredentialsTests extends TestCase {
 
-       private DOMParser parser = new DOMParser();
+       private Parser.DOMParser parser = new Parser.DOMParser(true);
 
        public CredentialsTests(String name) {
                super(name);
 
        public CredentialsTests(String name) {
                super(name);
@@ -81,55 +76,6 @@ public class CredentialsTests extends TestCase {
         */
        protected void setUp() throws Exception {
                super.setUp();
         */
        protected void setUp() throws Exception {
                super.setUp();
-               try {
-                       parser.setFeature("http://xml.org/sax/features/validation", true);
-                       parser.setFeature("http://apache.org/xml/features/validation/schema", true);
-                       parser.setEntityResolver(new EntityResolver() {
-                               public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
-
-                                       if (systemId.endsWith("credentials.xsd")) {
-                                               InputStream stream;
-                                               try {
-                                                       stream = new FileInputStream("src/schemas/credentials.xsd");
-                                                       if (stream != null) {
-                                                               return new InputSource(stream);
-                                                       }
-                                                       throw new SAXException("Could not load entity: Null input stream");
-                                               } catch (FileNotFoundException e) {
-                                                       throw new SAXException("Could not load entity: " + e);
-                                               }
-                                       } else if (systemId.endsWith("xmldsig-core-schema.xsd")) {
-                                               InputStream stream;
-                                               try {
-                                                       stream = new FileInputStream("src/schemas/xmldsig-core-schema.xsd");
-                                                       if (stream != null) {
-                                                               return new InputSource(stream);
-                                                       }
-                                                       throw new SAXException("Could not load entity: Null input stream");
-                                               } catch (FileNotFoundException e) {
-                                                       throw new SAXException("Could not load entity: " + e);
-                                               }
-                                       } else {
-                                               return null;
-                                       }
-                               }
-                       });
-
-                       parser.setErrorHandler(new ErrorHandler() {
-                               public void error(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                               public void fatalError(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                               public void warning(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                       });
-               } catch (Exception e) {
-                       fail("Failed to setup xml parser: " + e);
-               }
-
        }
 
        public void testKeyStoreX509CompleteChain() {
        }
 
        public void testKeyStoreX509CompleteChain() {
index eb65a7d..65cbfba 100644 (file)
@@ -37,7 +37,6 @@ import junit.framework.TestCase;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
-import org.apache.xerces.parsers.DOMParser;
 import org.opensaml.SAMLNameIdentifier;
 import org.xml.sax.EntityResolver;
 import org.xml.sax.ErrorHandler;
 import org.opensaml.SAMLNameIdentifier;
 import org.xml.sax.EntityResolver;
 import org.xml.sax.ErrorHandler;
@@ -52,6 +51,8 @@ import edu.internet2.middleware.shibboleth.common.NameIdentifierMapping;
 import edu.internet2.middleware.shibboleth.common.NameIdentifierMappingException;
 import edu.internet2.middleware.shibboleth.common.NameMapper;
 import edu.internet2.middleware.shibboleth.common.ServiceProvider;
 import edu.internet2.middleware.shibboleth.common.NameIdentifierMappingException;
 import edu.internet2.middleware.shibboleth.common.NameMapper;
 import edu.internet2.middleware.shibboleth.common.ServiceProvider;
+import edu.internet2.middleware.shibboleth.xml.Parser;
+
 
 
 /**
 
 
 /**
@@ -62,7 +63,7 @@ import edu.internet2.middleware.shibboleth.common.ServiceProvider;
 
 public class NameMapperTests extends TestCase {
 
 
 public class NameMapperTests extends TestCase {
 
-       private DOMParser parser = new DOMParser();
+       private Parser.DOMParser parser = new Parser.DOMParser(true);
 
        public NameMapperTests(String name) {
 
 
        public NameMapperTests(String name) {
 
@@ -82,49 +83,7 @@ public class NameMapperTests extends TestCase {
        protected void setUp() throws Exception {
 
                super.setUp();
        protected void setUp() throws Exception {
 
                super.setUp();
-               try {
-
-                       parser.setFeature("http://xml.org/sax/features/validation", true);
-                       parser.setFeature("http://apache.org/xml/features/validation/schema", true);
-                       parser.setEntityResolver(new EntityResolver() {
-
-                               public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
-
-                                       if (systemId.endsWith("namemapper.xsd")) {
-                                               InputStream stream;
-                                               try {
-                                                       stream = new FileInputStream("src/schemas/namemapper.xsd");
-                                                       if (stream != null) { return new InputSource(stream); }
-                                                       throw new SAXException("Could not load entity: Null input stream");
-                                               } catch (FileNotFoundException e) {
-                                                       throw new SAXException("Could not load entity: " + e);
-                                               }
-                                       } else {
-                                               return null;
-                                       }
-                               }
-                       });
-
-                       parser.setErrorHandler(new ErrorHandler() {
-
-                               public void error(SAXParseException arg0) throws SAXException {
 
 
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-
-                               public void fatalError(SAXParseException arg0) throws SAXException {
-
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-
-                               public void warning(SAXParseException arg0) throws SAXException {
-
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                       });
-               } catch (Exception e) {
-                       fail("Failed to setup xml parser: " + e);
-               }
        }
 
        public void testCryptoMapping() {
        }
 
        public void testCryptoMapping() {
index b36a836..5cd2a46 100644 (file)
@@ -27,9 +27,6 @@
 package edu.internet2.middleware.shibboleth.metadata;
 
 import java.io.File;
 package edu.internet2.middleware.shibboleth.metadata;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
 import java.util.Arrays;
 
 import junit.framework.TestCase;
 import java.util.Arrays;
 
 import junit.framework.TestCase;
@@ -37,12 +34,6 @@ import junit.framework.TestCase;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
-import org.apache.xerces.parsers.DOMParser;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
 
 import edu.internet2.middleware.shibboleth.metadata.provider.XMLMetadataLoadWrapper;
 
 
 import edu.internet2.middleware.shibboleth.metadata.provider.XMLMetadataLoadWrapper;
 
@@ -54,7 +45,6 @@ import edu.internet2.middleware.shibboleth.metadata.provider.XMLMetadataLoadWrap
 
 public class MetadataTests extends TestCase {
 
 
 public class MetadataTests extends TestCase {
 
-       private DOMParser       parser  = new DOMParser();
 
        public MetadataTests(String name) {
                super(name);
 
        public MetadataTests(String name) {
                super(name);
@@ -71,58 +61,6 @@ public class MetadataTests extends TestCase {
 
        protected void setUp() throws Exception {
                super.setUp();
 
        protected void setUp() throws Exception {
                super.setUp();
-               try {
-                       parser.setFeature("http://xml.org/sax/features/validation", true);
-                       parser.setFeature("http://apache.org/xml/features/validation/schema", true);
-                       parser.setEntityResolver(new EntityResolver() {
-
-                               public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
-
-                                       if (systemId.endsWith("credentials.xsd")) {
-                                               InputStream stream;
-                                               try {
-                                                       stream = new FileInputStream("src/schemas/shibboleth.xsd");
-                                                       if (stream != null) {
-                                                               return new InputSource(stream);
-                                                       }
-                                                       throw new SAXException("Could not load entity: Null input stream");
-                                               } catch (FileNotFoundException e) {
-                                                       throw new SAXException("Could not load entity: " + e);
-                                               }
-                                       } else if (systemId.endsWith("xmldsig-core-schema.xsd")) {
-                                               InputStream stream;
-                                               try {
-                                                       stream = new FileInputStream("src/schemas/xmldsig-core-schema.xsd");
-                                                       if (stream != null) {
-                                                               return new InputSource(stream);
-                                                       }
-                                                       throw new SAXException("Could not load entity: Null input stream");
-                                               } catch (FileNotFoundException e) {
-                                                       throw new SAXException("Could not load entity: " + e);
-                                               }
-                                       } else {
-                                               return null;
-                                       }
-                               }
-                       });
-
-                       parser.setErrorHandler(new ErrorHandler() {
-
-                               public void error(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-
-                               public void fatalError(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-
-                               public void warning(SAXParseException arg0) throws SAXException {
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                       });
-               } catch (Exception e) {
-                       fail("Failed to setup xml parser: " + e);
-               }
 
        }
 
 
        }