PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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