KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > pluginmgr > PluginListHandler


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
20 package org.gjt.sp.jedit.pluginmgr;
21
22 import java.util.Stack JavaDoc;
23
24 import org.xml.sax.Attributes JavaDoc;
25 import org.xml.sax.InputSource JavaDoc;
26 import org.xml.sax.helpers.DefaultHandler JavaDoc;
27
28 import org.gjt.sp.util.Log;
29 import org.gjt.sp.util.XMLUtilities;
30
31 /**
32  * @version $Id: PluginListHandler.java 8303 2007-01-02 21:50:43Z kpouer $
33  */

34
35 class PluginListHandler extends DefaultHandler JavaDoc
36 {
37     PluginListHandler(PluginList pluginList, String JavaDoc path)
38     {
39         this.pluginList = pluginList;
40         this.path = path;
41
42         author = new StringBuffer JavaDoc();
43         description = new StringBuffer JavaDoc();
44         pluginSetEntry = new StringBuffer JavaDoc();
45         download = new StringBuffer JavaDoc();
46         downloadSource = new StringBuffer JavaDoc();
47     }
48
49     public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId)
50     {
51         return XMLUtilities.findEntity(systemId, "plugins.dtd", getClass());
52     }
53
54     public void attribute(String JavaDoc aname, String JavaDoc value, boolean isSpecified)
55     {
56         if(aname == "NAME")
57             name = value;
58         else if(aname == "JAR")
59             jar = value;
60         else if(aname == "VERSION")
61             version = value;
62         else if(aname == "DATE")
63             date = value;
64         else if(aname == "OBSOLETE")
65             obsolete = ("TRUE".equals(value));
66         else if(aname == "WHAT")
67             depWhat = value;
68         else if(aname == "FROM")
69             depFrom = value;
70         else if(aname == "TO")
71             depTo = value;
72         else if(aname == "PLUGIN")
73             depPlugin = value;
74         else if(aname == "SIZE")
75         {
76             size = Integer.parseInt(value);
77             if(size == 0)
78                 Log.log(Log.WARNING,this,"SIZE = 0");
79         }
80     }
81
82     public void characters(char[] c, int off, int len)
83     {
84         String JavaDoc tag = peekElement();
85
86         if(tag.equals("DESCRIPTION"))
87         {
88             description.append(c, off, len);
89         }
90         else if(tag.equals("PLUGIN_SET_ENTRY"))
91             pluginSetEntry.append(c, off, len);
92         else if(tag.equals("AUTHOR"))
93         {
94             if(author.length() != 0)
95                 author.append(", ");
96             author.append(c, off, len);
97         }
98         else if(tag.equals("DOWNLOAD"))
99             download.append(c, off, len);
100         else if(tag.equals("DOWNLOAD_SOURCE"))
101             downloadSource.append(c, off, len);
102     }
103
104     public void startElement(String JavaDoc uri, String JavaDoc localName,
105                  String JavaDoc tag, Attributes JavaDoc attrs)
106     {
107         for (int i = 0; i < attrs.getLength(); i++)
108         {
109             String JavaDoc aName = attrs.getQName(i);
110             String JavaDoc aValue = attrs.getValue(i);
111             attribute(aName, aValue, true);
112         }
113
114
115         tag = pushElement(tag);
116
117         if(tag.equals("PLUGIN_SET"))
118         {
119             description.setLength(0);
120             pluginSet = new PluginList.PluginSet();
121             pluginSet.name = name;
122         }
123         else if(tag.equals("PLUGIN"))
124         {
125             description.setLength(0);
126             author.setLength(0);
127             branch = null;
128             plugin = new PluginList.Plugin();
129         }
130         else if(tag.equals("BRANCH"))
131         {
132             download.setLength(0);
133             branch = new PluginList.Branch();
134         }
135         else if(tag.equals("DOWNLOAD"))
136             downloadSize = size;
137         else if(tag.equals("DOWNLOAD_SOURCE"))
138             downloadSourceSize = size;
139     }
140
141     public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc tag)
142     {
143         popElement();
144
145         if(tag.equals("PLUGIN_SET"))
146         {
147             pluginList.addPluginSet(pluginSet);
148             pluginSet = null;
149             pluginSetEntry.setLength(0);
150         }
151         else if(tag.equals("PLUGIN_SET_ENTRY"))
152         {
153             pluginSet.plugins.add(pluginSetEntry.toString());
154             pluginSetEntry.setLength(0);
155         }
156         else if(tag.equals("PLUGIN"))
157         {
158             plugin.jar = jar;
159             plugin.name = name;
160             plugin.author = author.toString();
161             plugin.description = description.toString();
162             pluginList.addPlugin(plugin);
163             jar = null;
164             name = null;
165             author.setLength(0);
166             description.setLength(0);
167         }
168         else if(tag.equals("BRANCH"))
169         {
170             branch.version = version;
171             branch.date = date;
172             branch.download = download.toString();
173             branch.downloadSize = downloadSize;
174             branch.downloadSource = downloadSource.toString();
175             branch.downloadSourceSize = downloadSourceSize;
176             branch.obsolete = obsolete;
177             plugin.branches.add(branch);
178             version = null;
179             download.setLength(0);
180             downloadSource.setLength(0);
181             obsolete = false;
182         }
183         else if(tag.equals("DEPEND"))
184         {
185             PluginList.Dependency dep = new PluginList.Dependency(
186                 depWhat,depFrom,depTo,depPlugin);
187             branch.deps.add(dep);
188             depWhat = null;
189             depFrom = null;
190             depTo = null;
191             depPlugin = null;
192         }
193     }
194
195     public void startDocument()
196     {
197         try
198         {
199             pushElement(null);
200         }
201         catch (Exception JavaDoc e)
202         {
203             e.printStackTrace();
204         }
205     }
206
207     public void endDocument()
208     {
209         pluginList.finished();
210     }
211     // end HandlerBase implementation
212

213     // private members
214
private String JavaDoc path;
215
216     private PluginList pluginList;
217
218     private PluginList.PluginSet pluginSet;
219     private StringBuffer JavaDoc pluginSetEntry;
220
221     private PluginList.Plugin plugin;
222     private String JavaDoc jar;
223     private StringBuffer JavaDoc author;
224
225     private PluginList.Branch branch;
226     private boolean obsolete;
227     private String JavaDoc version;
228     private String JavaDoc date;
229     private StringBuffer JavaDoc download;
230     private int downloadSize;
231     private StringBuffer JavaDoc downloadSource;
232     private int downloadSourceSize;
233     private int size;
234     private String JavaDoc depWhat;
235     private String JavaDoc depFrom;
236     private String JavaDoc depTo;
237     private String JavaDoc depPlugin;
238
239     private String JavaDoc name;
240     private StringBuffer JavaDoc description;
241
242     private final Stack JavaDoc<String JavaDoc> stateStack = new Stack JavaDoc<String JavaDoc>();
243
244     private String JavaDoc pushElement(String JavaDoc name)
245     {
246         stateStack.push(name);
247         return name;
248     }
249
250     private String JavaDoc peekElement()
251     {
252         return stateStack.peek();
253     }
254
255     private String JavaDoc popElement()
256     {
257         return stateStack.pop();
258     }
259 }
260
Popular Tags