1 23 24 package com.sun.enterprise.deployment.node; 25 26 import com.sun.enterprise.deployment.util.DOLUtils; 27 import java.io.InputStream ; 28 import java.util.logging.Level ; 29 import org.xml.sax.InputSource ; 30 import org.xml.sax.SAXException ; 31 32 41 public class SaxParserHandlerBundled extends SaxParserHandler { 42 43 44 private static final String BUNDLED_SCHEMA_ROOT = "/schemas"; 45 private static final String BUNDLED_DTD_ROOT = "/dtds"; 46 47 48 public SaxParserHandlerBundled() { 49 } 50 51 62 public InputSource resolveEntity(String publicID, String systemID) throws SAXException { 63 InputSource result = null; 64 65 68 try { 69 if(DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) { 70 DOLUtils.getDefaultLogger().fine("Asked to resolve " + publicID + " system id = " + systemID); 71 } 72 if (publicID==null) { 73 if (systemID==null || systemID.lastIndexOf('/')==systemID.length()) { 75 return null; 76 } 77 78 81 InputStream is = openSchemaStream(systemID); 82 83 if (is != null) { 84 87 result = new InputSource (is); 88 } else { 89 92 result = new InputSource (systemID); 93 } 94 } else { 95 98 if (mapping.containsKey(publicID)) { 99 this.publicID = publicID; 100 InputStream is = openDTDStream(publicID); 101 if (is != null) { 102 result = new InputSource (is); 103 } 104 } else if (systemID != null) { 105 110 InputStream is = openSchemaStream(systemID); 111 if (is != null) { 112 result = new InputSource (is); 113 } 114 } 115 } 116 } catch (Exception exc) { 117 exc.printStackTrace(); 118 throw new SAXException (exc); 119 } 120 return result; 121 } 122 123 128 private InputStream openSchemaStream(String systemID) { 129 String targetID = BUNDLED_SCHEMA_ROOT + "/" + systemID.substring(systemID.lastIndexOf("/") + 1 ); 130 InputStream result = this.getClass().getResourceAsStream(targetID); 131 return result; 132 } 133 134 139 private InputStream openDTDStream(String publicID) { 140 String targetID = BUNDLED_DTD_ROOT + "/" + mapping.get(publicID); 141 InputStream result = this.getClass().getResourceAsStream(targetID); 142 return result; 143 } 144 } 145 | Popular Tags |