1 16 17 package org.apache.commons.betwixt.digester; 18 19 import org.apache.commons.betwixt.Descriptor; 20 import org.apache.commons.digester.Rule; 21 import org.xml.sax.Attributes ; 22 23 30 public class OptionRule extends Rule { 31 32 private String currentValue; 33 private String currentName; 34 35 38 public void begin(String namespace, String name, Attributes attributes) 39 throws Exception { 40 currentValue = null; 41 currentName = null; 42 } 43 44 45 46 49 public void end(String namespace, String name) { 50 if (currentName != null && currentValue != null) { 51 Object top = getDigester().peek(); 52 if (top instanceof Descriptor) { 53 Descriptor descriptor = (Descriptor) top; 54 descriptor.getOptions().addOption(currentName, currentValue); 55 } 56 } 57 } 58 59 64 public Rule getNameRule() { 65 return new Rule() { 66 public void body(String namespace, String name, String text) { 67 currentName = text; 68 } 69 }; 70 } 71 72 77 public Rule getValueRule() { 78 return new Rule() { 79 public void body(String namespace, String name, String text) { 80 currentValue = text; 81 } 82 }; 83 } 84 } 85 | Popular Tags |