1 19 20 package org.gjt.sp.jedit.pluginmgr; 21 22 import java.util.Stack ; 23 24 import org.xml.sax.Attributes ; 25 import org.xml.sax.InputSource ; 26 import org.xml.sax.helpers.DefaultHandler ; 27 28 import org.gjt.sp.util.Log; 29 import org.gjt.sp.util.XMLUtilities; 30 31 34 35 class PluginListHandler extends DefaultHandler 36 { 37 PluginListHandler(PluginList pluginList, String path) 38 { 39 this.pluginList = pluginList; 40 this.path = path; 41 42 author = new StringBuffer (); 43 description = new StringBuffer (); 44 pluginSetEntry = new StringBuffer (); 45 download = new StringBuffer (); 46 downloadSource = new StringBuffer (); 47 } 48 49 public InputSource resolveEntity(String publicId, String systemId) 50 { 51 return XMLUtilities.findEntity(systemId, "plugins.dtd", getClass()); 52 } 53 54 public void attribute(String aname, String 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 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 uri, String localName, 105 String tag, Attributes attrs) 106 { 107 for (int i = 0; i < attrs.getLength(); i++) 108 { 109 String aName = attrs.getQName(i); 110 String 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 uri, String localName, String 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 e) 202 { 203 e.printStackTrace(); 204 } 205 } 206 207 public void endDocument() 208 { 209 pluginList.finished(); 210 } 211 213 private String path; 215 216 private PluginList pluginList; 217 218 private PluginList.PluginSet pluginSet; 219 private StringBuffer pluginSetEntry; 220 221 private PluginList.Plugin plugin; 222 private String jar; 223 private StringBuffer author; 224 225 private PluginList.Branch branch; 226 private boolean obsolete; 227 private String version; 228 private String date; 229 private StringBuffer download; 230 private int downloadSize; 231 private StringBuffer downloadSource; 232 private int downloadSourceSize; 233 private int size; 234 private String depWhat; 235 private String depFrom; 236 private String depTo; 237 private String depPlugin; 238 239 private String name; 240 private StringBuffer description; 241 242 private final Stack <String > stateStack = new Stack <String >(); 243 244 private String pushElement(String name) 245 { 246 stateStack.push(name); 247 return name; 248 } 249 250 private String peekElement() 251 { 252 return stateStack.peek(); 253 } 254 255 private String popElement() 256 { 257 return stateStack.pop(); 258 } 259 } 260 | Popular Tags |