KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > ActionListHandler


1 /*
2  * ActionListHandler.java - XML handler for action files
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 2000, 2001 Slava Pestov
7  * Portions copyright (C) 1999 mike dillon
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  */

23
24 package org.gjt.sp.jedit;
25
26 //{{{ Imports
27
import java.io.*;
28 import java.util.Stack JavaDoc;
29
30 import org.xml.sax.Attributes JavaDoc;
31 import org.xml.sax.InputSource JavaDoc;
32 import org.xml.sax.helpers.DefaultHandler JavaDoc;
33
34 import org.gjt.sp.util.Log;
35 import org.gjt.sp.util.XMLUtilities;
36 //}}}
37

38 class ActionListHandler extends DefaultHandler JavaDoc
39 {
40     //{{{ ActionListHandler constructor
41
ActionListHandler(String JavaDoc path, ActionSet actionSet)
42     {
43         this.path = path;
44         this.actionSet = actionSet;
45         stateStack = new Stack JavaDoc();
46         code = new StringBuffer JavaDoc();
47         isSelected = new StringBuffer JavaDoc();
48     } //}}}
49

50     //{{{ resolveEntity() method
51
public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId)
52     {
53         return XMLUtilities.findEntity(systemId, "actions.dtd", getClass());
54     } //}}}
55

56     //{{{ attribute() method
57
public void attribute(String JavaDoc aname, String JavaDoc 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     } //}}}
71

72     //{{{ characters() method
73
public void characters(char[] c, int off, int len)
74     {
75         String JavaDoc 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     } //}}}
85

86     //{{{ startElement() method
87
public void startElement(String JavaDoc uri, String JavaDoc localName,
88                  String JavaDoc qName, Attributes JavaDoc attrs)
89     {
90         String JavaDoc 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     } //}}}
102

103     //{{{ endElement() method
104
public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName)
105     {
106         String JavaDoc tag = peekElement();
107
108         if (qName.equals(tag))
109         {
110             if (tag.equals("ACTION"))
111             {
112                 String JavaDoc 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             // can't happen
127
throw new InternalError JavaDoc();
128         }
129     } //}}}
130

131     //{{{ startDocument() method
132
public void startDocument()
133     {
134         try
135         {
136             pushElement(null);
137         }
138         catch (Exception JavaDoc e)
139         {
140             e.printStackTrace();
141         }
142     } //}}}
143

144     //{{{ Private members
145

146     //{{{ Instance variables
147
private String JavaDoc path;
148     private ActionSet actionSet;
149
150     private String JavaDoc actionName;
151     private StringBuffer JavaDoc code;
152     private StringBuffer JavaDoc isSelected;
153
154     private boolean noRepeat;
155     private boolean noRecord;
156     private boolean noRememberLast;
157
158     private Stack JavaDoc stateStack;
159     //}}}
160

161     //{{{ pushElement() method
162
private String JavaDoc pushElement(String JavaDoc name)
163     {
164         name = (name == null) ? null : name.intern();
165
166         stateStack.push(name);
167
168         return name;
169     } //}}}
170

171     //{{{ peekElement() method
172
private String JavaDoc peekElement()
173     {
174         return (String JavaDoc) stateStack.peek();
175     } //}}}
176

177     //{{{ popElement() method
178
private String JavaDoc popElement()
179     {
180         return (String JavaDoc) stateStack.pop();
181     } //}}}
182

183     //}}}
184

185 }
186
Popular Tags