PageRenderTime 51ms CodeModel.GetById 29ms app.highlight 19ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/pluginmgr/PluginListHandler.java

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