PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 173 lines | 124 code | 27 blank | 22 comment | 27 complexity | 9f81554afd2c53127fd075384eb6d6e9 MD5 | raw file
  1/*
  2 * ActionListHandler.java - XML handler for action files
  3 * Copyright (C) 2000, 2001 Slava Pestov
  4 * Portions copyright (C) 1999 mike dillon
  5 *
  6 * This program is free software; you can redistribute it and/or
  7 * modify it under the terms of the GNU General Public License
  8 * as published by the Free Software Foundation; either version 2
  9 * of the License, or any later version.
 10 *
 11 * This program is distributed in the hope that it will be useful,
 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 * GNU General Public License for more details.
 15 *
 16 * You should have received a copy of the GNU General Public License
 17 * along with this program; if not, write to the Free Software
 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 19 */
 20
 21package org.gjt.sp.jedit;
 22
 23import com.microstar.xml.*;
 24import java.io.*;
 25import java.util.Stack;
 26import org.gjt.sp.util.Log;
 27
 28class ActionListHandler extends HandlerBase
 29{
 30	ActionListHandler(String path, ActionSet actionSet)
 31	{
 32		this.path = path;
 33		this.actionSet = actionSet;
 34		stateStack = new Stack();
 35	}
 36
 37	public Object resolveEntity(String publicId, String systemId)
 38	{
 39		if("actions.dtd".equals(systemId))
 40		{
 41			try
 42			{
 43				return new BufferedReader(new InputStreamReader(
 44					getClass().getResourceAsStream("actions.dtd")));
 45			}
 46			catch(Exception e)
 47			{
 48				Log.log(Log.ERROR,this,"Error while opening"
 49					+ " actions.dtd:");
 50				Log.log(Log.ERROR,this,e);
 51			}
 52		}
 53
 54		return null;
 55	}
 56
 57	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	}
 69
 70	public void doctypeDecl(String name, String publicId,
 71		String systemId) throws Exception
 72	{
 73		if("ACTIONS".equals(name))
 74			return;
 75
 76		Log.log(Log.ERROR,this,path + ": DOCTYPE must be ACTIONS");
 77	}
 78
 79	public void charData(char[] c, int off, int len)
 80	{
 81		String tag = peekElement();
 82		String text = new String(c, off, len);
 83
 84		if (tag == "CODE")
 85		{
 86			code = text;
 87		}
 88		else if (tag == "IS_SELECTED")
 89		{
 90			isSelected = text;
 91		}
 92	}
 93
 94	public void startElement(String tag)
 95	{
 96		tag = pushElement(tag);
 97
 98		if (tag == "ACTION")
 99		{
100			code = null;
101			isSelected = null;
102		}
103	}
104
105	public void endElement(String name)
106	{
107		if(name == null)
108			return;
109
110		String tag = peekElement();
111
112		if(name.equals(tag))
113		{
114			if(tag == "ACTION")
115			{
116				actionSet.addAction(new BeanShellAction(actionName,
117					code,isSelected,noRepeat,noRecord));
118			}
119
120			popElement();
121		}
122		else
123		{
124			// can't happen
125			throw new InternalError();
126		}
127	}
128
129	public void startDocument()
130	{
131		try
132		{
133			pushElement(null);
134		}
135		catch (Exception e)
136		{
137			e.printStackTrace();
138		}
139	}
140	// end HandlerBase implementation
141
142	// private members
143	private String path;
144	private ActionSet actionSet;
145
146	private String actionName;
147	private String code;
148	private String isSelected;
149
150	private boolean noRepeat;
151	private boolean noRecord;
152
153	private Stack stateStack;
154
155	private String pushElement(String name)
156	{
157		name = (name == null) ? null : name.intern();
158
159		stateStack.push(name);
160
161		return name;
162	}
163
164	private String peekElement()
165	{
166		return (String) stateStack.peek();
167	}
168
169	private String popElement()
170	{
171		return (String) stateStack.pop();
172	}
173}