1 7 package org.ejtools.util.state; 8 9 import java.util.HashMap ; 10 import java.util.Hashtable ; 11 import java.util.Map ; 12 13 import org.xml.sax.Attributes ; 14 import org.xml.sax.SAXException ; 15 import org.xml.sax.helpers.DefaultHandler ; 16 17 18 22 public class LoadHandler extends DefaultHandler 23 { 24 25 private Map context = new HashMap (); 26 27 private String path = ""; 28 29 private Map rules = new Hashtable (); 30 31 32 public final static String ATTRIBUTES = "ATTRIBUTES"; 33 34 public final static String ELEMENT = "ELEMENT"; 35 36 public final static String TEXT = "TEXT"; 37 38 39 40 public LoadHandler() { } 41 42 43 49 public void addRule(String path, Rule rule) 50 { 51 this.rules.put(path, rule); 52 } 53 54 55 63 public void characters(char[] ch, int start, int length) 64 throws SAXException 65 { 66 String text = new String (ch, start, length); 67 this.context.put("TEXT", text); 68 Rule rule = (Rule) this.rules.get(this.path); 69 if (rule != null) 70 { 71 rule.loadBody(this.context); 72 } 73 } 74 75 76 84 public void endElement(String uri, String localName, String qName) 85 throws SAXException 86 { 87 this.context.put("ELEMENT", qName); 88 Rule rule = (Rule) this.rules.get(this.path); 89 if (rule != null) 90 { 91 rule.loadExit(this.context); 92 } 93 this.path = this.path.substring(0, this.path.length() - qName.length() - 1); 94 } 95 96 97 102 public Map getContext() 103 { 104 return this.context; 105 } 106 107 108 117 public void startElement(String uri, String localName, String qName, Attributes attributes) 118 throws SAXException 119 { 120 this.context.put("ELEMENT", qName); 121 this.context.put("ATTRIBUTES", attributes); 122 this.path = path + "/" + qName; 123 Rule rule = (Rule) this.rules.get(this.path); 124 if (rule != null) 125 { 126 rule.loadEnter(this.context); 127 } 128 } 129 } 130 | Popular Tags |