1 26 27 package org.objectweb.jonas_lib.deployment.digester; 28 29 import java.io.IOException ; 30 import java.io.Reader ; 31 32 import org.apache.commons.digester.Digester; 33 34 import org.objectweb.jonas_lib.deployment.api.DTDs; 35 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 36 import org.objectweb.jonas_lib.deployment.api.Schemas; 37 import org.objectweb.jonas_lib.deployment.rules.JRuleSetBase; 38 import org.objectweb.jonas_lib.deployment.xml.TopLevelElement; 39 40 41 47 48 public class JDigester extends Digester { 49 50 64 65 public JDigester(JRuleSetBase ruleSet, 66 boolean parsingWithValidation, 67 boolean namespaceAware, 68 DTDs dtds, 69 Schemas schemas) 70 throws DeploymentDescException { 71 super(); 72 73 74 String packageName = ruleSet.getClass().getPackage().getName(); 75 String rootPackageName = packageName.substring(0, packageName.lastIndexOf('.')); 76 77 78 setNamespaceAware(namespaceAware); 80 setValidating(parsingWithValidation); 81 82 setErrorHandler(new JErrorHandler()); 84 85 JEntityResolver jEntityResolver = new JEntityResolver(this); 87 jEntityResolver.addDtds(dtds); 88 jEntityResolver.addSchemas(schemas); 89 setEntityResolver(jEntityResolver); 90 91 92 if (parsingWithValidation) { 94 try { 95 setFeature("http://apache.org/xml/features/validation/schema", 96 true); 97 } catch (Exception ee) { 98 throw new DeploymentDescException("Error setting feature", ee); 99 } 100 } 101 102 org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(rootPackageName + ".digester"); 103 setLogger(log); 104 105 try { 107 setFeature("http://apache.org/xml/features/allow-java-encodings", 108 true); 109 } catch (Exception ee) { 110 throw new DeploymentDescException("Error setting feature", ee); 111 } 112 113 setUseContextClassLoader(true); 115 116 addRuleSet(ruleSet); 118 } 119 120 121 130 public void parse(Reader reader, 131 String fileName, 132 TopLevelElement element) 133 throws DeploymentDescException { 134 try { 135 clear(); 136 push(element); 137 parse(reader); 138 } catch (Exception ioe) { 139 throw new DeploymentDescException("Error when parsing XML document " + fileName, ioe); 140 } finally { 141 if (reader != null) { 142 try { 143 reader.close(); 144 } catch (IOException ignored) { 145 getLogger().warn("Can't close '" + fileName + "'"); 146 } 147 } 148 push(null); 149 } 150 } 151 152 } 153 | Popular Tags |