PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

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