1 23 24 package com.sun.enterprise.tools.admingui; 25 26 import org.xml.sax.EntityResolver ; 27 import org.xml.sax.InputSource ; 28 29 import java.io.Serializable ; 30 import java.io.InputStream ; 31 import java.net.URLDecoder ; 32 33 import com.iplanet.jato.util.NonSyncStringBuffer; 34 import com.sun.web.ui.common.CCSystem; 35 36 37 74 public class LockhartEntityResolver implements EntityResolver , Serializable { 75 76 private static final String COM_SUN_WEB_UI = "com_sun_web_ui"; 78 private static final String DTD_DIR = "dtd"; 79 private static final String DEFAULT_XML_ENCODING = "UTF-8"; 80 81 private static String xmlEncoding = DEFAULT_XML_ENCODING; 85 86 92 93 107 108 public InputSource resolveEntity(String publicId, String systemId) { 109 110 137 String fileName = getSystemId(systemId); 138 if (fileName == null) { 139 return (null); 140 } 141 142 InputSource isrc = null; 143 try { 144 isrc = buildInputSource(fileName); 145 } catch (Exception e) { 146 System.out.println("cannot convert DTD, using default behaviour: " 147 + e.getMessage()); 148 isrc = null; 149 } 150 return (isrc); 151 152 } 154 160 174 protected String getSystemId(String systemId) { 175 176 if (systemId == null) { 177 return (null); 178 } 179 String path; 181 try { 182 path = URLDecoder.decode(systemId, xmlEncoding); 183 } catch (Exception ex) { 184 path = systemId; 186 } 187 188 int index = path.lastIndexOf('/'); 189 path = path.substring(index+1); 190 return (path); 191 192 } 194 200 203 private InputSource buildInputSource(String fileName) { 204 205 String str; 206 NonSyncStringBuffer buffer = 207 new NonSyncStringBuffer(128); 208 buffer.append(COM_SUN_WEB_UI); 209 buffer.append(CCSystem.URL_SEPARATOR + DTD_DIR); 210 buffer.append(CCSystem.URL_SEPARATOR + fileName); 211 212 String url = buffer.toString(); 213 InputStream is = getClass().getClassLoader().getResourceAsStream(url); 214 return (new InputSource (is)); 215 216 } 218 } | Popular Tags |