1 26 package com.bull.eclipse.jonas.utils.xml; 27 28 import java.io.IOException ; 29 import java.io.Reader ; 30 31 import org.apache.commons.digester.Digester; 32 33 import com.bull.eclipse.jonas.utils.xml.desc.DTDs; 34 import com.bull.eclipse.jonas.utils.xml.desc.Schemas; 35 36 37 43 44 public class JDigester extends Digester { 45 46 60 61 public JDigester(JRuleSetBase ruleSet, 62 boolean parsingWithValidation, 63 boolean namespaceAware, 64 DTDs dtds, 65 Schemas schemas) 66 throws DeploymentDescException { 67 super(); 68 69 70 String packageName = ruleSet.getClass().getPackage().getName(); 71 String rootPackageName = packageName.substring(0, packageName.lastIndexOf('.')); 72 73 74 setNamespaceAware(namespaceAware); 76 setValidating(parsingWithValidation); 77 78 setErrorHandler(new JErrorHandler()); 80 81 JEntityResolver jEntityResolver = new JEntityResolver(this); 83 jEntityResolver.addDtds(dtds); 84 jEntityResolver.addSchemas(schemas); 85 setEntityResolver(jEntityResolver); 86 87 88 if (parsingWithValidation) { 90 try { 91 setFeature("http://apache.org/xml/features/validation/schema", 92 true); 93 } catch (Exception ee) { 94 throw new DeploymentDescException("Error setting feature", ee); 95 } 96 } 97 98 try { 100 setFeature("http://apache.org/xml/features/allow-java-encodings", 101 true); 102 } catch (Exception ee) { 103 throw new DeploymentDescException("Error setting feature", ee); 104 } 105 106 setUseContextClassLoader(true); 108 109 addRuleSet(ruleSet); 111 } 112 113 114 123 public void parse(Reader reader, 124 String fileName, 125 TopLevelElement element) 126 throws DeploymentDescException { 127 try { 128 clear(); 129 push(element); 130 parse(reader); 131 } catch (Exception ioe) { 132 throw new DeploymentDescException("Error when parsing XML document " + fileName, ioe); 133 } finally { 134 if (reader != null) { 135 try { 136 reader.close(); 137 } catch (IOException ignored) { 138 ; 139 } 140 } 141 push(null); 142 } 143 } 144 145 } 146 | Popular Tags |