1 package org.apache.turbine.services.intake.transform; 2 3 18 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.net.URL ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 import org.xml.sax.EntityResolver ; 27 import org.xml.sax.InputSource ; 28 29 40 public class DTDResolver implements EntityResolver 41 { 42 private static final String WEB_SITE_DTD = 43 "http://jakarta.apache.org/turbine/dtd/intake_2_3.dtd"; 44 45 46 private InputSource intakeDTD = null; 47 48 49 private static Log log = LogFactory.getLog(DTDResolver.class); 50 51 54 public DTDResolver() 55 { 56 try 57 { 58 InputStream dtdStream = 59 getClass().getResourceAsStream("intake.dtd"); 60 61 if (dtdStream != null) 65 { 66 intakeDTD = new InputSource (dtdStream); 67 } 68 else 69 { 70 log.warn("Could not located the intake.dtd"); 71 } 72 } 73 catch (Exception ex) 74 { 75 log.error("Could not get stream for dtd", ex); 76 } 77 } 78 79 84 public InputSource resolveEntity(String publicId, String systemId) 85 { 86 if (intakeDTD != null && WEB_SITE_DTD.equals(systemId)) 87 { 88 String pkg = getClass().getName() 89 .substring(0, getClass().getName().lastIndexOf(".")); 90 91 log.info("Resolver: used intake.dtd from " + 92 pkg + " package "); 93 94 return intakeDTD; 95 } 96 else if (systemId == null) 97 { 98 log.info("Resolver: used intake.dtd from Jakarta Web site"); 99 return getInputSource(WEB_SITE_DTD); 100 } 101 else 102 { 103 log.info("Resolver: used System DTD for " + systemId); 104 return getInputSource(systemId); 105 } 106 } 107 108 114 private InputSource getInputSource(String urlString) 115 { 116 try 117 { 118 URL url = new URL (urlString); 119 return new InputSource (url.openStream()); 120 } 121 catch (IOException ex) 122 { 123 log.error("Could not get InputSource for " + urlString, ex); 124 } 125 return new InputSource (); 126 } 127 } 128 | Popular Tags |