1 17 18 19 package org.apache.catalina.startup; 20 21 import java.net.URL ; 22 23 import org.apache.catalina.util.SchemaResolver; 24 import org.apache.tomcat.util.digester.Digester; 25 import org.apache.tomcat.util.digester.RuleSet; 26 27 32 public class DigesterFactory { 33 36 protected static org.apache.commons.logging.Log log = 37 org.apache.commons.logging.LogFactory.getLog(DigesterFactory.class); 38 39 42 private static SchemaResolver schemaResolver; 43 44 45 49 public static Digester newDigester(){ 50 return newDigester(false, false, null); 51 } 52 53 54 58 public static Digester newDigester(RuleSet rule){ 59 return newDigester(false,false,rule); 60 } 61 62 63 69 public static Digester newDigester(boolean xmlValidation, 70 boolean xmlNamespaceAware, 71 RuleSet rule) { 72 Digester digester = new Digester(); 73 digester.setNamespaceAware(xmlNamespaceAware); 74 digester.setValidating(xmlValidation); 75 digester.setUseContextClassLoader(true); 76 77 if (xmlValidation || xmlNamespaceAware){ 78 configureSchema(digester); 79 } 80 81 schemaResolver = new SchemaResolver(digester); 82 registerLocalSchema(); 83 84 digester.setEntityResolver(schemaResolver); 85 if ( rule != null ) { 86 digester.addRuleSet(rule); 87 } 88 89 return (digester); 90 } 91 92 93 97 protected static void registerLocalSchema(){ 98 register(Constants.J2eeSchemaResourcePath_14, 100 Constants.J2eeSchemaPublicId_14); 101 register(Constants.W3cSchemaResourcePath_10, 103 Constants.W3cSchemaPublicId_10); 104 register(Constants.JspSchemaResourcePath_20, 106 Constants.JspSchemaPublicId_20); 107 register(Constants.TldDtdResourcePath_11, 109 Constants.TldDtdPublicId_11); 110 111 register(Constants.TldDtdResourcePath_12, 112 Constants.TldDtdPublicId_12); 113 114 register(Constants.TldSchemaResourcePath_20, 115 Constants.TldSchemaPublicId_20); 116 117 register(Constants.WebDtdResourcePath_22, 119 Constants.WebDtdPublicId_22); 120 121 register(Constants.WebDtdResourcePath_23, 122 Constants.WebDtdPublicId_23); 123 124 register(Constants.WebSchemaResourcePath_24, 125 Constants.WebSchemaPublicId_24); 126 127 register(Constants.J2eeWebServiceSchemaResourcePath_11, 129 Constants.J2eeWebServiceSchemaPublicId_11); 130 131 register(Constants.J2eeWebServiceClientSchemaResourcePath_11, 132 Constants.J2eeWebServiceClientSchemaPublicId_11); 133 134 } 135 136 137 140 protected static void register(String resourceURL, String resourcePublicId){ 141 URL url = DigesterFactory.class.getResource(resourceURL); 142 143 if(url == null) { 144 log.warn("Could not get url for " + resourceURL); 145 } else { 146 schemaResolver.register(resourcePublicId , url.toString() ); 147 } 148 } 149 150 151 154 protected static void configureSchema(Digester digester){ 155 URL url = DigesterFactory.class 156 .getResource(Constants.WebSchemaResourcePath_24); 157 158 if(url == null) { 159 log.error("Could not get url for " 160 + Constants.WebSchemaResourcePath_24); 161 } else { 162 digester.setSchema(url.toString()); 163 } 164 } 165 } 166 | Popular Tags |