PageRenderTime 97ms CodeModel.GetById 26ms RepoModel.GetById 2ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package org.gjt.sp.jedit.pluginmgr;
  20. import com.microstar.xml.*;
  21. import java.io.*;
  22. import java.util.Stack;
  23. import org.gjt.sp.util.Log;
  24. class PluginListHandler extends HandlerBase
  25. {
  26. PluginListHandler(PluginList pluginList, String path)
  27. {
  28. this.pluginList = pluginList;
  29. this.path = path;
  30. stateStack = new Stack();
  31. }
  32. public Object resolveEntity(String publicId, String systemId)
  33. {
  34. if("plugins.dtd".equals(systemId))
  35. {
  36. // this will result in a slight speed up, since we
  37. // don't need to read the DTD anyway, as AElfred is
  38. // non-validating
  39. return new StringReader("<!-- -->");
  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. return null;
  54. }
  55. public void attribute(String aname, String value, boolean isSpecified)
  56. {
  57. aname = (aname == null) ? null : aname.intern();
  58. value = (value == null) ? null : value.intern();
  59. if(aname == "NAME")
  60. name = value;
  61. else if(aname == "JAR")
  62. jar = value;
  63. else if(aname == "VERSION")
  64. version = value;
  65. else if(aname == "DATE")
  66. date = value;
  67. else if(aname == "OBSOLETE")
  68. obsolete = ("TRUE".equals(value));
  69. else if(aname == "WHAT")
  70. depWhat = value;
  71. else if(aname == "FROM")
  72. depFrom = value;
  73. else if(aname == "TO")
  74. depTo = value;
  75. else if(aname == "PLUGIN")
  76. depPlugin = value;
  77. else if(aname == "SIZE")
  78. {
  79. size = Integer.parseInt(value);
  80. if(size == 0)
  81. Log.log(Log.WARNING,this,"SIZE = 0");
  82. }
  83. }
  84. public void doctypeDecl(String name, String publicId,
  85. String systemId) throws Exception
  86. {
  87. if("PLUGINS".equals(name))
  88. return;
  89. Log.log(Log.ERROR,this,path + ": DOCTYPE must be PLUGINS");
  90. }
  91. public void charData(char[] c, int off, int len)
  92. {
  93. String tag = peekElement();
  94. String text = new String(c, off, len);
  95. if(tag == "DESCRIPTION")
  96. {
  97. description = text;
  98. }
  99. else if(tag == "PLUGIN_SET_ENTRY")
  100. pluginSetEntry = text;
  101. else if(tag == "AUTHOR")
  102. {
  103. if(author != null && author.length() != 0)
  104. author = author + ", " + text;
  105. else
  106. author = text;
  107. }
  108. else if(tag == "DOWNLOAD")
  109. download = text;
  110. else if(tag == "DOWNLOAD_SOURCE")
  111. downloadSource = text;
  112. }
  113. public void startElement(String tag)
  114. {
  115. tag = pushElement(tag);
  116. if(tag == "PLUGIN_SET")
  117. {
  118. description = null;
  119. pluginSet = new PluginList.PluginSet();
  120. pluginSet.name = name;
  121. }
  122. else if(tag == "PLUGIN")
  123. {
  124. description = null;
  125. author = null;
  126. branch = null;
  127. plugin = new PluginList.Plugin();
  128. }
  129. else if(tag == "BRANCH")
  130. {
  131. download = null;
  132. branch = new PluginList.Branch();
  133. }
  134. else if(tag == "DOWNLOAD")
  135. downloadSize = size;
  136. else if(tag == "DOWNLOAD_SOURCE")
  137. downloadSourceSize = size;
  138. }
  139. public void endElement(String tag)
  140. {
  141. if(tag == null)
  142. return;
  143. else
  144. tag = tag.intern();
  145. popElement();
  146. if(tag == "PLUGIN_SET")
  147. {
  148. pluginList.addPluginSet(pluginSet);
  149. pluginSet = null;
  150. pluginSetEntry = null;
  151. }
  152. else if(tag == "PLUGIN_SET_ENTRY")
  153. {
  154. pluginSet.plugins.addElement(pluginSetEntry);
  155. pluginSetEntry = null;
  156. }
  157. else if(tag == "PLUGIN")
  158. {
  159. plugin.jar = jar;
  160. plugin.name = name;
  161. plugin.author = author;
  162. plugin.description = description;
  163. pluginList.addPlugin(plugin);
  164. jar = null;
  165. name = null;
  166. author = null;
  167. }
  168. else if(tag == "BRANCH")
  169. {
  170. branch.version = version;
  171. branch.date = date;
  172. branch.download = download;
  173. branch.downloadSize = downloadSize;
  174. branch.downloadSource = downloadSource;
  175. branch.downloadSourceSize = downloadSourceSize;
  176. branch.obsolete = obsolete;
  177. plugin.branches.addElement(branch);
  178. version = null;
  179. download = null;
  180. obsolete = false;
  181. }
  182. else if(tag == "DEPEND")
  183. {
  184. PluginList.Dependency dep = new PluginList.Dependency(
  185. depWhat,depFrom,depTo,depPlugin);
  186. branch.deps.addElement(dep);
  187. depWhat = null;
  188. depFrom = null;
  189. depTo = null;
  190. depPlugin = null;
  191. }
  192. }
  193. public void startDocument()
  194. {
  195. try
  196. {
  197. pushElement(null);
  198. }
  199. catch (Exception e)
  200. {
  201. e.printStackTrace();
  202. }
  203. }
  204. public void endDocument()
  205. {
  206. pluginList.finished();
  207. }
  208. // end HandlerBase implementation
  209. // private members
  210. private String path;
  211. private PluginList pluginList;
  212. private PluginList.PluginSet pluginSet;
  213. private String pluginSetEntry;
  214. private PluginList.Plugin plugin;
  215. private String jar;
  216. private String author;
  217. private PluginList.Branch branch;
  218. private boolean obsolete;
  219. private String version;
  220. private String date;
  221. private String download;
  222. private int downloadSize;
  223. private String downloadSource;
  224. private int downloadSourceSize;
  225. private int size;
  226. private String depWhat;
  227. private String depFrom;
  228. private String depTo;
  229. private String depPlugin;
  230. private String name;
  231. private String description;
  232. private Stack stateStack;
  233. private String pushElement(String name)
  234. {
  235. name = (name == null) ? null : name.intern();
  236. stateStack.push(name);
  237. return name;
  238. }
  239. private String peekElement()
  240. {
  241. return (String) stateStack.peek();
  242. }
  243. private String popElement()
  244. {
  245. return (String) stateStack.pop();
  246. }
  247. }