1 22 23 28 29 package org.xquark.schema; 30 31 import java.net.URL ; 32 import java.util.*; 33 34 import javax.xml.parsers.ParserConfigurationException ; 35 import javax.xml.parsers.SAXParser ; 36 import javax.xml.parsers.SAXParserFactory ; 37 38 import org.xml.sax.InputSource ; 39 import org.xml.sax.SAXException ; 40 import org.xml.sax.XMLReader ; 41 42 public class DefaultSchemaLocator implements SchemaLocator { 43 private static final String RCSRevision = "$Revision: 1.1 $"; 44 private static final String RCSName = "$Name: $"; 45 46 private static SAXParserFactory factory = null; 47 48 static { 49 try { 50 factory = SAXParserFactory.newInstance(); 51 factory.setNamespaceAware(true); 52 factory.setValidating(false); 53 } 54 catch ( Exception ee ) { 55 factory = null; 56 } 57 } 58 59 private HashMap schemaLocations = new HashMap(); 60 61 public XMLReader getSchemaReader() throws SAXException 62 { 63 if ( factory == null ) return null; 64 try { 65 SAXParser parser = factory.newSAXParser(); 66 return parser.getXMLReader(); 67 } catch (ParserConfigurationException e) { 68 e.fillInStackTrace(); 69 throw new SAXException (e); 70 } 71 } 72 73 public InputSource resolveLocation(String namespace, String location) 74 { 75 return null; 76 } 77 78 public InputSource resolveLocation(String namespace, URL location) 79 { 80 try { 81 InputSource source = new InputSource (location.openStream()); 82 source.setSystemId(location.toString()); 83 return source; 84 } catch (java.io.IOException ex) { 85 return null; 86 } 87 } 88 89 public String resolveInclude(String location) { 90 return location; 91 } 92 93 public void clearSchemaLocations() { 94 schemaLocations.clear(); 95 } 96 97 public Iterator getSchemaLocations(String namespace) { 98 List locs = (List)schemaLocations.get(namespace); 99 if (locs != null) return locs.iterator(); 100 else return null; 101 } 102 103 public void addSchemaLocation(String uri, String location) { 104 List list = (List)schemaLocations.get(uri); 105 if ( list == null ) { 106 list = new ArrayList(); 107 schemaLocations.put(uri, list); 108 } 109 list.add(location); 110 } 111 112 } 113 | Popular Tags |