1 package org.apache.fulcrum.intake.transform; 2 3 56 57 import java.io.IOException ; 58 import java.io.InputStream ; 59 import java.net.URL ; 60 import org.xml.sax.EntityResolver ; 61 import org.xml.sax.InputSource ; 62 63 72 public class DTDResolver implements EntityResolver 73 { 74 75 InputSource databaseDTD = null; 76 77 80 public DTDResolver() 81 { 82 try 83 { 84 InputStream dtdStream = 85 getClass().getResourceAsStream("intake.dtd"); 86 87 if (dtdStream != null) 91 { 92 databaseDTD = new InputSource (dtdStream); 93 } 94 } 95 catch (Exception ex) 96 { 97 ex.printStackTrace(); 98 } 99 } 100 101 106 public InputSource resolveEntity(String publicId, String systemId) 107 { 108 if (databaseDTD != null && 109 "http://jakarta.apache.org/turbine/dtd/intake.dtd".equals(systemId)) 110 { 111 System.out.println("Resolver: used intake.dtd"); 112 return databaseDTD; 113 } 114 else 115 { 116 System.out.println("Resolver: used " + systemId); 117 return getInputSource(systemId); 118 } 119 } 120 121 127 public InputSource getInputSource(String urlString) 128 { 129 try 130 { 131 URL url = new URL (urlString); 132 return new InputSource (url.openStream()); 133 } 134 catch (IOException ex) 135 { 136 ex.printStackTrace(); 137 } 138 return new InputSource (); 139 } 140 } 141 142 143 144 145 146 | Popular Tags |