Moved custom error handler into matching digester class.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 19 Jun 2002 21:23:28 +0000 (21:23 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Wed, 19 Jun 2002 21:23:28 +0000 (21:23 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@153 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/common/ServletDigester.java
src/edu/internet2/middleware/shibboleth/wayf/PassThruErrorHandler.java [deleted file]
src/edu/internet2/middleware/shibboleth/wayf/WayfService.java

index 4688327..25a9690 100755 (executable)
@@ -8,8 +8,10 @@ import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.commons.digester.Digester;
+import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 import org.xml.sax.XMLReader;
 
 /**
@@ -20,8 +22,8 @@ import org.xml.sax.XMLReader;
  */
 
 public class ServletDigester extends Digester {
-       
-       ServletContext context;
+
+       private ServletContext context;
 
        public ServletDigester() {
                super();
@@ -30,25 +32,27 @@ public class ServletDigester extends Digester {
 
        public ServletDigester(ServletContext context) {
                super();
+               super.setErrorHandler(new PassThruErrorHandler());
                this.context = context;
 
        }
 
        public ServletDigester(SAXParser parser) {
                super(parser);
+               super.setErrorHandler(new PassThruErrorHandler());
                configure();
        }
 
        public ServletDigester(XMLReader reader) {
                super(reader);
+               super.setErrorHandler(new PassThruErrorHandler());
                configure();
        }
 
        /**
         * @see org.xml.sax.EntityResolver#resolveEntity(String, String)
         */
-       public InputSource resolveEntity(String publicId, String systemId)
-               throws SAXException {
+       public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
 
                if (context != null && systemId != null) {
                        StringTokenizer tokenString = new StringTokenizer(systemId, "/");
@@ -57,8 +61,7 @@ public class ServletDigester extends Digester {
                                xsdFile = tokenString.nextToken();
                        }
                        if (xsdFile.endsWith(".xsd")) {
-                               InputStream stream =
-                                       context.getResourceAsStream("/WEB-INF/classes/schemas/" + xsdFile);
+                               InputStream stream = context.getResourceAsStream("/WEB-INF/classes/schemas/" + xsdFile);
                                if (stream != null) {
                                        return new InputSource(stream);
                                }
@@ -67,38 +70,70 @@ public class ServletDigester extends Digester {
                return null;
 
        }
-       
-        /**
-     * Return the SAXParser we will use to parse the input stream.  If there
-     * is a problem creating the parser, return <code>null</code>.
-     */
-    public SAXParser getParser() {
-
-        // Return the parser we already created (if any)
-        if (parser != null) {
-            return (parser);
-        }
-
-        // Create and return a new parser
-        synchronized (this) {
-            try {
-                if (factory == null) {
-                    factory = SAXParserFactory.newInstance();
-                }
-                factory.setNamespaceAware(namespaceAware);
-                factory.setValidating(validating);
-                if (validating) {
-                               factory.setFeature("http://xml.org/sax/features/namespaces", true);
+
+       /**
+       * Return the SAXParser we will use to parse the input stream.  If there
+       * is a problem creating the parser, return <code>null</code>.
+       */
+       public SAXParser getParser() {
+
+               // Return the parser we already created (if any)
+               if (parser != null) {
+                       return (parser);
+               }
+
+               // Create and return a new parser
+               synchronized (this) {
+                       try {
+                               if (factory == null) {
+                                       factory = SAXParserFactory.newInstance();
+                               }
+                               factory.setNamespaceAware(namespaceAware);
+                               factory.setValidating(validating);
+                               if (validating) {
+                                       factory.setFeature("http://xml.org/sax/features/namespaces", true);
                                        factory.setFeature("http://xml.org/sax/features/validation", true);
                                        factory.setFeature("http://apache.org/xml/features/validation/schema", true);
-                                       factory.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
-                }
-                parser = factory.newSAXParser();
-                return (parser);
-            } catch (Exception e) {
-                return (null);
-            }
-        }
-
-    }
+                                       factory.setFeature(
+                                               "http://apache.org/xml/features/validation/schema-full-checking",
+                                               true);
+                               }
+                               parser = factory.newSAXParser();
+                               return (parser);
+                       } catch (Exception e) {
+                               return (null);
+                       }
+               }
+
+       }
+
+       /**
+       * Sax <code>ErrorHandler</code> that passes all errors up as new 
+       * exceptions.
+       */
+
+       public class PassThruErrorHandler implements ErrorHandler {
+
+               /**
+                * @see org.xml.sax.ErrorHandler#error(SAXParseException)
+                */
+               public void error(SAXParseException arg0) throws SAXException {
+                       throw new SAXException("Error parsing xml file: " + arg0);
+               }
+
+               /**
+                * @see org.xml.sax.ErrorHandler#fatalError(SAXParseException)
+                */
+               public void fatalError(SAXParseException arg0) throws SAXException {
+                       throw new SAXException("Error parsing xml file: " + arg0);
+               }
+
+               /**
+                * @see org.xml.sax.ErrorHandler#warning(SAXParseException)
+                */
+               public void warning(SAXParseException arg0) throws SAXException {
+                       throw new SAXException("Error parsing xml file: " + arg0);
+               }
+
+       }
 }
diff --git a/src/edu/internet2/middleware/shibboleth/wayf/PassThruErrorHandler.java b/src/edu/internet2/middleware/shibboleth/wayf/PassThruErrorHandler.java
deleted file mode 100755 (executable)
index f661deb..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-package edu.internet2.middleware.shibboleth.wayf;
-
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-/**
- * Sax <code>ErrorHandler</code> that simply passes all errors up as new 
- * exceptions.
- */
-
-public class PassThruErrorHandler implements ErrorHandler {
-
-       /**
-        * @see org.xml.sax.ErrorHandler#error(SAXParseException)
-        */
-       public void error(SAXParseException arg0) throws SAXException {
-               throw new SAXException("Error parsing xml file: " + arg0);
-       }
-
-       /**
-        * @see org.xml.sax.ErrorHandler#fatalError(SAXParseException)
-        */
-       public void fatalError(SAXParseException arg0) throws SAXException {
-               throw new SAXException("Error parsing xml file: " + arg0);
-       }
-
-       /**
-        * @see org.xml.sax.ErrorHandler#warning(SAXParseException)
-        */
-       public void warning(SAXParseException arg0) throws SAXException {
-               throw new SAXException("Error parsing xml file: " + arg0);
-       }
-
-}
-
index 1eb2c49..fd930aa 100755 (executable)
@@ -56,7 +56,6 @@ public class WayfService extends HttpServlet {
 
                try {
                        digester.setValidating(true);
-                       digester.setErrorHandler(new PassThruErrorHandler());
                        config = (WayfConfig) digester.parse(is);
 
                } catch (SAXException se) {
@@ -69,7 +68,6 @@ public class WayfService extends HttpServlet {
 
                try {
                        siteDigester.setValidating(true);
-                       siteDigester.setErrorHandler(new PassThruErrorHandler());
                        originConfig = (WayfOrigins) siteDigester.parse(siteIs);
 
                } catch (SAXException se) {