Added trust schema
[java-idp.git] / src / edu / internet2 / middleware / shibboleth / common / XML.java
index ed55b2f..5727cab 100755 (executable)
@@ -63,13 +63,20 @@ import org.xml.sax.SAXException;
  */
 public class XML
 {
-    /**  Shibboleth extension XML namespace */
+    /**  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 trust metadata XML namespace */
+    public final static String TRUST_NS = "urn:mace:shibboleth:trust:1.0";
+    
+    /**  Shibboleth trust metadata XML schema identifier */
+    public final static String TRUST_SCHEMA_ID = "shibboleth-trust-1.0.xsd";
+    
     private static byte[] Shib_schema;
+    private static byte[] Trust_schema;
 
     /**
      *  Custom schema resolver class
@@ -77,50 +84,53 @@ public class XML
      * @author     Scott Cantor
      * @created    May 18, 2002
      */
-    protected static class SchemaResolver implements EntityResolver
-    {
+    protected 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
+         * @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
-        {
+        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(1024);
+    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
-            {
+            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;
+                while ((b = xmlin.read()) != -1)
+                    buf.append((char)b);
+                Trust_schema = buf.toString().getBytes();
+                xmlin.close();
+            }
         }
-        catch (java.io.IOException e)
-        {
+        catch (java.io.IOException e) {
             throw new RuntimeException("XML static initializer caught an I/O error");
         }
     }
 }
-