1 17 18 19 20 package org.apache.fop.render.afp.tools; 21 22 import java.io.IOException ; 23 import java.net.URL ; 24 25 import org.apache.fop.render.afp.exceptions.FontRuntimeException; 26 import org.xml.sax.EntityResolver ; 27 import org.xml.sax.InputSource ; 28 29 37 public class DTDEntityResolver implements EntityResolver { 38 39 40 public static final String AFP_DTD_1_0_ID = "-//APACHE/DTD AFP Installed Font Definition DTD 1.0//EN"; 41 42 43 public static final String AFP_DTD_1_0_RESOURCE = "afp-fonts-1.0.dtd"; 44 45 46 public static final String AFP_DTD_1_1_ID = "-//APACHE/DTD AFP Installed Font Definition DTD 1.1//EN"; 47 48 49 public static final String AFP_DTD_1_1_RESOURCE = "afp-fonts-1.1.dtd"; 50 51 52 public static final String AFP_DTD_1_2_ID = "-//APACHE/DTD AFP Installed Font Definition DTD 1.2//EN"; 53 54 55 public static final String AFP_DTD_1_2_RESOURCE = "afp-fonts-1.2.dtd"; 56 57 68 public InputSource resolveEntity(String publicId, String systemId) 69 throws IOException { 70 71 URL resource = null; 72 if ( AFP_DTD_1_2_ID.equals(publicId) ) { 73 resource = getResource( AFP_DTD_1_2_RESOURCE ); 74 } else if ( AFP_DTD_1_1_ID.equals(publicId) ) { 75 resource = getResource( AFP_DTD_1_1_RESOURCE ); 76 } else if ( AFP_DTD_1_0_ID.equals(publicId) ) { 77 throw new FontRuntimeException( 78 "The AFP Installed Font Definition 1.0 DTD is not longer supported" ); 79 } else if( systemId != null && systemId.indexOf("afp-fonts.dtd") >= 0 ) { 80 throw new FontRuntimeException( 81 "The AFP Installed Font Definition DTD must be specified using the public id" ); 82 } else { 83 return null; 84 } 85 86 InputSource inputSource = new InputSource ( resource.openStream() ); 87 inputSource.setPublicId( publicId ); 88 inputSource.setSystemId( systemId ); 89 90 return inputSource; 91 } 92 93 100 private URL getResource(String resourcePath) { 101 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 102 if (cl == null) { 103 cl = ClassLoader.getSystemClassLoader(); 104 } 105 106 URL resource = cl.getResource( resourcePath ); 107 if (resource == null) { 108 throw new FontRuntimeException( "Resource " + resourcePath + 109 " could not be found on the classpath" ); 110 } 111 112 return resource; 113 } 114 } 115 | Popular Tags |