PageRenderTime 103ms CodeModel.GetById 60ms app.highlight 17ms RepoModel.GetById 13ms app.codeStats 0ms

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

#
Java | 273 lines | 207 code | 31 blank | 35 comment | 82 complexity | 6c575ea8a32018559d4bbe2e2aa25a32 MD5 | raw file
  1/*
  2 * PluginListHandler.java - XML handler for the plugin list
  3 * Copyright (C) 2001 Slava Pestov
  4 *
  5 * This program is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU General Public License
  7 * as published by the Free Software Foundation; either version 2
  8 * of the License, or any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, write to the Free Software
 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 18 */
 19
 20package org.gjt.sp.jedit.pluginmgr;
 21
 22import com.microstar.xml.*;
 23import java.io.*;
 24import java.util.Stack;
 25import org.gjt.sp.util.Log;
 26
 27class PluginListHandler extends HandlerBase
 28{
 29	PluginListHandler(PluginList pluginList, String path)
 30	{
 31		this.pluginList = pluginList;
 32		this.path = path;
 33		stateStack = new Stack();
 34	}
 35
 36	public Object resolveEntity(String publicId, String systemId)
 37	{
 38		if("plugins.dtd".equals(systemId))
 39		{
 40			// this will result in a slight speed up, since we
 41			// don't need to read the DTD anyway, as AElfred is
 42			// non-validating
 43			return new StringReader("<!-- -->");
 44
 45			/* try
 46			{
 47				return new BufferedReader(new InputStreamReader(
 48					getClass().getResourceAsStream(
 49					"/org/gjt/sp/jedit/pluginmgr/plugins.dtd")));
 50			}
 51			catch(Exception e)
 52			{
 53				Log.log(Log.ERROR,this,"Error while opening"
 54					+ " plugins.dtd:");
 55				Log.log(Log.ERROR,this,e);
 56			} */
 57		}
 58
 59		return null;
 60	}
 61
 62	public void attribute(String aname, String value, boolean isSpecified)
 63	{
 64		aname = (aname == null) ? null : aname.intern();
 65		value = (value == null) ? null : value.intern();
 66
 67		if(aname == "NAME")
 68			name = value;
 69		else if(aname == "JAR")
 70			jar = value;
 71		else if(aname == "VERSION")
 72			version = value;
 73		else if(aname == "DATE")
 74			date = value;
 75		else if(aname == "OBSOLETE")
 76			obsolete = ("TRUE".equals(value));
 77		else if(aname == "WHAT")
 78			depWhat = value;
 79		else if(aname == "FROM")
 80			depFrom = value;
 81		else if(aname == "TO")
 82			depTo = value;
 83		else if(aname == "PLUGIN")
 84			depPlugin = value;
 85		else if(aname == "SIZE")
 86			size = Integer.parseInt(value);
 87	}
 88
 89	public void doctypeDecl(String name, String publicId,
 90		String systemId) throws Exception
 91	{
 92		if("PLUGINS".equals(name))
 93			return;
 94
 95		Log.log(Log.ERROR,this,path + ": DOCTYPE must be PLUGINS");
 96	}
 97
 98	public void charData(char[] c, int off, int len)
 99	{
100		String tag = peekElement();
101		String text = new String(c, off, len);
102
103		if(tag == "DESCRIPTION")
104		{
105			description = text;
106		}
107		else if(tag == "PLUGIN_SET_ENTRY")
108			pluginSetEntry = text;
109		else if(tag == "AUTHOR")
110		{
111			if(author != null && author.length() != 0)
112				author = author + ", " + text;
113			else
114				author = text;
115		}
116		else if(tag == "DOWNLOAD")
117			download = text;
118		else if(tag == "DOWNLOAD_SOURCE")
119			downloadSource = text;
120	}
121
122	public void startElement(String tag)
123	{
124		tag = pushElement(tag);
125
126		if(tag == "PLUGIN_SET")
127		{
128			description = null;
129			pluginSet = new PluginList.PluginSet();
130		}
131		else if(tag == "PLUGIN")
132		{
133			description = null;
134			author = null;
135			branch = null;
136			plugin = new PluginList.Plugin();
137		}
138		else if(tag == "BRANCH")
139		{
140			download = null;
141			branch = new PluginList.Branch();
142		}
143		else if(tag == "DOWNLOAD")
144			downloadSize = size;
145		else if(tag == "DOWNLOAD_SOURCE")
146			downloadSourceSize = size;
147	}
148
149	public void endElement(String tag)
150	{
151		if(tag == null)
152			return;
153		else
154			tag = tag.intern();
155
156		popElement();
157
158		if(tag == "PLUGIN_SET")
159		{
160			pluginList.addPluginSet(pluginSet);
161			pluginSet = null;
162			pluginSetEntry = null;
163		}
164		else if(tag == "PLUGIN_SET_ENTRY")
165		{
166			pluginSet.plugins.addElement(pluginSetEntry);
167			pluginSetEntry = null;
168		}
169		else if(tag == "PLUGIN")
170		{
171			plugin.jar = jar;
172			plugin.name = name;
173			plugin.author = author;
174			plugin.description = description;
175			pluginList.addPlugin(plugin);
176			jar = null;
177			name = null;
178			author = null;
179		}
180		else if(tag == "BRANCH")
181		{
182			branch.version = version;
183			branch.date = date;
184			branch.download = download;
185			branch.downloadSize = downloadSize;
186			branch.downloadSource = downloadSource;
187			branch.downloadSourceSize = downloadSourceSize;
188			branch.obsolete = obsolete;
189			plugin.branches.addElement(branch);
190			version = null;
191			download = null;
192			obsolete = false;
193		}
194		else if(tag == "DEPEND")
195		{
196			PluginList.Dependency dep = new PluginList.Dependency(
197				depWhat,depFrom,depTo,depPlugin);
198			branch.deps.addElement(dep);
199			depWhat = null;
200			depFrom = null;
201			depTo = null;
202			depPlugin = null;
203		}
204	}
205
206	public void startDocument()
207	{
208		try
209		{
210			pushElement(null);
211		}
212		catch (Exception e)
213		{
214			e.printStackTrace();
215		}
216	}
217
218	public void endDocument()
219	{
220		pluginList.finished();
221	}
222	// end HandlerBase implementation
223
224	// private members
225	private String path;
226
227	private PluginList pluginList;
228
229	private PluginList.PluginSet pluginSet;
230	private String pluginSetEntry;
231
232	private PluginList.Plugin plugin;
233	private String jar;
234	private String author;
235
236	private PluginList.Branch branch;
237	private boolean obsolete;
238	private String version;
239	private String date;
240	private String download;
241	private int downloadSize;
242	private String downloadSource;
243	private int downloadSourceSize;
244	private int size;
245	private String depWhat;
246	private String depFrom;
247	private String depTo;
248	private String depPlugin;
249
250	private String name;
251	private String description;
252
253	private Stack stateStack;
254
255	private String pushElement(String name)
256	{
257		name = (name == null) ? null : name.intern();
258
259		stateStack.push(name);
260
261		return name;
262	}
263
264	private String peekElement()
265	{
266		return (String) stateStack.peek();
267	}
268
269	private String popElement()
270	{
271		return (String) stateStack.pop();
272	}
273}