PageRenderTime 71ms CodeModel.GetById 59ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/ActionListHandler.java

#
Java | 199 lines | 115 code | 30 blank | 54 comment | 27 complexity | ffdadc542ee1f0da64612f2edc19917a MD5 | raw file
  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
 24package org.gjt.sp.jedit;
 25
 26//{{{ Imports
 27import com.microstar.xml.*;
 28import java.io.*;
 29import java.util.Stack;
 30import org.gjt.sp.util.Log;
 31//}}}
 32
 33class ActionListHandler extends HandlerBase
 34{
 35	//{{{ ActionListHandler constructor
 36	ActionListHandler(String path, ActionSet actionSet)
 37	{
 38		this.path = path;
 39		this.actionSet = actionSet;
 40		stateStack = new Stack();
 41	} //}}}
 42
 43	//{{{ resolveEntity() method
 44	public Object resolveEntity(String publicId, String systemId)
 45	{
 46		if("actions.dtd".equals(systemId))
 47		{
 48			// this will result in a slight speed up, since we
 49			// don't need to read the DTD anyway, as AElfred is
 50			// non-validating
 51			return new StringReader("<!-- -->");
 52
 53			/* try
 54			{
 55				return new BufferedReader(new InputStreamReader(
 56					getClass().getResourceAsStream("actions.dtd")));
 57			}
 58			catch(Exception e)
 59			{
 60				Log.log(Log.ERROR,this,"Error while opening"
 61					+ " actions.dtd:");
 62				Log.log(Log.ERROR,this,e);
 63			} */
 64		}
 65
 66		return null;
 67	} //}}}
 68
 69	//{{{ attribute() method
 70	public void attribute(String aname, String value, boolean isSpecified)
 71	{
 72		aname = (aname == null) ? null : aname.intern();
 73		value = (value == null) ? null : value.intern();
 74
 75		if(aname == "NAME")
 76			actionName = value;
 77		else if(aname == "NO_REPEAT")
 78			noRepeat = (value == "TRUE");
 79		else if(aname == "NO_RECORD")
 80			noRecord = (value == "TRUE");
 81	} //}}}
 82
 83	//{{{ doctypeDecl() method
 84	public void doctypeDecl(String name, String publicId,
 85		String systemId) throws Exception
 86	{
 87		if("ACTIONS".equals(name))
 88			return;
 89
 90		Log.log(Log.ERROR,this,path + ": DOCTYPE must be ACTIONS");
 91	} //}}}
 92
 93	//{{{ charData() method
 94	public void charData(char[] c, int off, int len)
 95	{
 96		String tag = peekElement();
 97		String text = new String(c, off, len);
 98
 99		if (tag == "CODE")
100		{
101			code = text;
102		}
103		else if (tag == "IS_SELECTED")
104		{
105			isSelected = text;
106		}
107	} //}}}
108
109	//{{{ startElement() method
110	public void startElement(String tag)
111	{
112		tag = pushElement(tag);
113
114		if (tag == "ACTION")
115		{
116			code = null;
117			isSelected = null;
118		}
119	} //}}}
120
121	//{{{ endElement() method
122	public void endElement(String name)
123	{
124		if(name == null)
125			return;
126
127		String tag = peekElement();
128
129		if(name.equals(tag))
130		{
131			if(tag == "ACTION")
132			{
133				actionSet.addAction(new BeanShellAction(actionName,
134					code,isSelected,noRepeat,noRecord));
135				noRepeat = noRecord = false;
136			}
137
138			popElement();
139		}
140		else
141		{
142			// can't happen
143			throw new InternalError();
144		}
145	} //}}}
146
147	//{{{ startDocument() method
148	public void startDocument()
149	{
150		try
151		{
152			pushElement(null);
153		}
154		catch (Exception e)
155		{
156			e.printStackTrace();
157		}
158	} //}}}
159
160	//{{{ Private members
161
162	//{{{ Instance variables
163	private String path;
164	private ActionSet actionSet;
165
166	private String actionName;
167	private String code;
168	private String isSelected;
169
170	private boolean noRepeat;
171	private boolean noRecord;
172
173	private Stack stateStack;
174	//}}}
175
176	//{{{ pushElement() method
177	private String pushElement(String name)
178	{
179		name = (name == null) ? null : name.intern();
180
181		stateStack.push(name);
182
183		return name;
184	} //}}}
185
186	//{{{ peekElement() method
187	private String peekElement()
188	{
189		return (String) stateStack.peek();
190	} //}}}
191
192	//{{{ popElement() method
193	private String popElement()
194	{
195		return (String) stateStack.pop();
196	} //}}}
197
198	//}}}
199}