1 11 package org.eclipse.update.internal.model; 12 13 14 import java.io.*; 15 import javax.xml.parsers.*; 16 17 import org.eclipse.update.core.*; 18 import org.eclipse.update.internal.core.*; 19 import org.xml.sax.*; 20 import org.xml.sax.helpers.*; 21 22 25 26 public class DefaultPluginParser extends DefaultHandler { 27 private final static SAXParserFactory parserFactory = 28 SAXParserFactory.newInstance(); 29 private SAXParser parser; 30 private String id = null; 31 private String version = null; 32 private PluginEntry pluginEntry; 33 34 private static final String PLUGIN = "plugin"; private static final String FRAGMENT = "fragment"; 37 private class ParseCompleteException extends SAXException { 38 39 private static final long serialVersionUID = 1L; 40 41 public ParseCompleteException(String arg0) { 42 super(arg0); 43 } 44 } 45 46 49 public DefaultPluginParser() { 50 super(); 51 try { 52 parserFactory.setNamespaceAware(true); 53 this.parser = parserFactory.newSAXParser(); 54 } catch (ParserConfigurationException e) { 55 UpdateCore.log(e); 56 } catch (SAXException e) { 57 UpdateCore.log(e); 58 } 59 } 60 61 64 public synchronized PluginEntry parse(InputStream in) throws SAXException, IOException { 65 try { 66 pluginEntry = new PluginEntry(); 67 parser.parse(new InputSource(in), this); 68 } catch (ParseCompleteException e) { 69 } 72 73 if (id == null || id.trim().length() == 0) 74 id = "_no_id_"; pluginEntry.setVersionedIdentifier(new VersionedIdentifier(id, version)); 76 return pluginEntry; 77 } 78 79 82 public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 83 84 String tag = localName.trim(); 85 86 if (tag.equalsIgnoreCase(PLUGIN)) { 87 pluginEntry.isFragment(false); 88 processPlugin(attributes); 89 return; 90 } 91 92 if (tag.equalsIgnoreCase(FRAGMENT)) { 93 pluginEntry.isFragment(true); 94 processPlugin(attributes); 95 return; 96 } 97 } 98 99 102 private void processPlugin(Attributes attributes) throws ParseCompleteException { 103 id = attributes.getValue("id"); version = attributes.getValue("version"); throw new ParseCompleteException(""); } 107 } 108 | Popular Tags |