1 23 24 package org.gjt.sp.jedit; 25 26 import java.io.*; 28 import java.util.Stack ; 29 30 import org.xml.sax.Attributes ; 31 import org.xml.sax.InputSource ; 32 import org.xml.sax.helpers.DefaultHandler ; 33 34 import org.gjt.sp.util.Log; 35 import org.gjt.sp.util.XMLUtilities; 36 38 class ActionListHandler extends DefaultHandler 39 { 40 ActionListHandler(String path, ActionSet actionSet) 42 { 43 this.path = path; 44 this.actionSet = actionSet; 45 stateStack = new Stack (); 46 code = new StringBuffer (); 47 isSelected = new StringBuffer (); 48 } 50 public InputSource resolveEntity(String publicId, String systemId) 52 { 53 return XMLUtilities.findEntity(systemId, "actions.dtd", getClass()); 54 } 56 public void attribute(String aname, String value, boolean isSpecified) 58 { 59 aname = (aname == null) ? null : aname.intern(); 60 value = (value == null) ? null : value.intern(); 61 62 if(aname == "NAME") 63 actionName = value; 64 else if(aname == "NO_REPEAT") 65 noRepeat = (value == "TRUE"); 66 else if(aname == "NO_RECORD") 67 noRecord = (value == "TRUE"); 68 else if(aname == "NO_REMEMBER_LAST") 69 noRememberLast = (value == "TRUE"); 70 } 72 public void characters(char[] c, int off, int len) 74 { 75 String tag = peekElement(); 76 if (tag.equals("CODE")) 77 { 78 code.append(c, off, len); 79 } 80 else if (tag.equals("IS_SELECTED")) 81 { 82 isSelected.append(c, off, len); 83 } 84 } 86 public void startElement(String uri, String localName, 88 String qName, Attributes attrs) 89 { 90 String tag = pushElement(qName); 91 92 if (tag.equals("ACTION")) 93 { 94 actionName = attrs.getValue("NAME"); 95 noRepeat = "TRUE".equals(attrs.getValue("NO_REPEAT")); 96 noRecord = "TRUE".equals(attrs.getValue("NO_RECORD")); 97 noRememberLast = "TRUE".equals(attrs.getValue("NO_REMEMBER_LAST")); 98 code.setLength(0); 99 isSelected.setLength(0); 100 } 101 } 103 public void endElement(String uri, String localName, String qName) 105 { 106 String tag = peekElement(); 107 108 if (qName.equals(tag)) 109 { 110 if (tag.equals("ACTION")) 111 { 112 String selected = (isSelected.length() > 0) ? 113 isSelected.toString() : null; 114 actionSet.addAction(new BeanShellAction(actionName, 115 code.toString(),selected, 116 noRepeat,noRecord,noRememberLast)); 117 noRepeat = noRecord = noRememberLast = false; 118 code.setLength(0); 119 isSelected.setLength(0); 120 } 121 122 popElement(); 123 } 124 else 125 { 126 throw new InternalError (); 128 } 129 } 131 public void startDocument() 133 { 134 try 135 { 136 pushElement(null); 137 } 138 catch (Exception e) 139 { 140 e.printStackTrace(); 141 } 142 } 144 146 private String path; 148 private ActionSet actionSet; 149 150 private String actionName; 151 private StringBuffer code; 152 private StringBuffer isSelected; 153 154 private boolean noRepeat; 155 private boolean noRecord; 156 private boolean noRememberLast; 157 158 private Stack stateStack; 159 161 private String pushElement(String name) 163 { 164 name = (name == null) ? null : name.intern(); 165 166 stateStack.push(name); 167 168 return name; 169 } 171 private String peekElement() 173 { 174 return (String ) stateStack.peek(); 175 } 177 private String popElement() 179 { 180 return (String ) stateStack.pop(); 181 } 183 185 } 186 | Popular Tags |