PageRenderTime 123ms CodeModel.GetById 91ms app.highlight 19ms RepoModel.GetById 11ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/pluginmgr/PluginListHandler.java

#
Java | 278 lines | 212 code | 31 blank | 35 comment | 84 complexity | b3ae2df0c75ddb371dc9e5d4be746839 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		{
 87			size = Integer.parseInt(value);
 88			if(size == 0)
 89				Log.log(Log.WARNING,this,"SIZE = 0");
 90		}
 91	}
 92
 93	public void doctypeDecl(String name, String publicId,
 94		String systemId) throws Exception
 95	{
 96		if("PLUGINS".equals(name))
 97			return;
 98
 99		Log.log(Log.ERROR,this,path + ": DOCTYPE must be PLUGINS");
100	}
101
102	public void charData(char[] c, int off, int len)
103	{
104		String tag = peekElement();
105		String text = new String(c, off, len);
106
107		if(tag == "DESCRIPTION")
108		{
109			description = text;
110		}
111		else if(tag == "PLUGIN_SET_ENTRY")
112			pluginSetEntry = text;
113		else if(tag == "AUTHOR")
114		{
115			if(author != null && author.length() != 0)
116				author = author + ", " + text;
117			else
118				author = text;
119		}
120		else if(tag == "DOWNLOAD")
121			download = text;
122		else if(tag == "DOWNLOAD_SOURCE")
123			downloadSource = text;
124	}
125
126	public void startElement(String tag)
127	{
128		tag = pushElement(tag);
129
130		if(tag == "PLUGIN_SET")
131		{
132			description = null;
133			pluginSet = new PluginList.PluginSet();
134			pluginSet.name = name;
135		}
136		else if(tag == "PLUGIN")
137		{
138			description = null;
139			author = null;
140			branch = null;
141			plugin = new PluginList.Plugin();
142		}
143		else if(tag == "BRANCH")
144		{
145			download = null;
146			branch = new PluginList.Branch();
147		}
148		else if(tag == "DOWNLOAD")
149			downloadSize = size;
150		else if(tag == "DOWNLOAD_SOURCE")
151			downloadSourceSize = size;
152	}
153
154	public void endElement(String tag)
155	{
156		if(tag == null)
157			return;
158		else
159			tag = tag.intern();
160
161		popElement();
162
163		if(tag == "PLUGIN_SET")
164		{
165			pluginList.addPluginSet(pluginSet);
166			pluginSet = null;
167			pluginSetEntry = null;
168		}
169		else if(tag == "PLUGIN_SET_ENTRY")
170		{
171			pluginSet.plugins.addElement(pluginSetEntry);
172			pluginSetEntry = null;
173		}
174		else if(tag == "PLUGIN")
175		{
176			plugin.jar = jar;
177			plugin.name = name;
178			plugin.author = author;
179			plugin.description = description;
180			pluginList.addPlugin(plugin);
181			jar = null;
182			name = null;
183			author = null;
184		}
185		else if(tag == "BRANCH")
186		{
187			branch.version = version;
188			branch.date = date;
189			branch.download = download;
190			branch.downloadSize = downloadSize;
191			branch.downloadSource = downloadSource;
192			branch.downloadSourceSize = downloadSourceSize;
193			branch.obsolete = obsolete;
194			plugin.branches.addElement(branch);
195			version = null;
196			download = null;
197			obsolete = false;
198		}
199		else if(tag == "DEPEND")
200		{
201			PluginList.Dependency dep = new PluginList.Dependency(
202				depWhat,depFrom,depTo,depPlugin);
203			branch.deps.addElement(dep);
204			depWhat = null;
205			depFrom = null;
206			depTo = null;
207			depPlugin = null;
208		}
209	}
210
211	public void startDocument()
212	{
213		try
214		{
215			pushElement(null);
216		}
217		catch (Exception e)
218		{
219			e.printStackTrace();
220		}
221	}
222
223	public void endDocument()
224	{
225		pluginList.finished();
226	}
227	// end HandlerBase implementation
228
229	// private members
230	private String path;
231
232	private PluginList pluginList;
233
234	private PluginList.PluginSet pluginSet;
235	private String pluginSetEntry;
236
237	private PluginList.Plugin plugin;
238	private String jar;
239	private String author;
240
241	private PluginList.Branch branch;
242	private boolean obsolete;
243	private String version;
244	private String date;
245	private String download;
246	private int downloadSize;
247	private String downloadSource;
248	private int downloadSourceSize;
249	private int size;
250	private String depWhat;
251	private String depFrom;
252	private String depTo;
253	private String depPlugin;
254
255	private String name;
256	private String description;
257
258	private Stack stateStack;
259
260	private String pushElement(String name)
261	{
262		name = (name == null) ? null : name.intern();
263
264		stateStack.push(name);
265
266		return name;
267	}
268
269	private String peekElement()
270	{
271		return (String) stateStack.peek();
272	}
273
274	private String popElement()
275	{
276		return (String) stateStack.pop();
277	}
278}