1 11 package org.eclipse.update.internal.configurator; 12 13 14 import java.io.*; 15 import java.net.*; 16 import java.util.ResourceBundle ; 17 18 import javax.xml.parsers.*; 19 20 import org.eclipse.osgi.util.NLS; 21 import org.xml.sax.*; 22 import org.xml.sax.helpers.*; 23 24 27 public class FullFeatureParser extends DefaultHandler implements IConfigurationConstants{ 28 29 private SAXParser parser; 30 private FeatureEntry feature; 31 private URL url; 32 private boolean isDescription; 33 private StringBuffer description = new StringBuffer (); 34 35 private final static SAXParserFactory parserFactory = 36 SAXParserFactory.newInstance(); 37 38 41 public FullFeatureParser(FeatureEntry feature) { 42 super(); 43 this.feature = feature; 44 try { 45 parserFactory.setNamespaceAware(true); 46 this.parser = parserFactory.newSAXParser(); 47 } catch (ParserConfigurationException e) { 48 System.out.println(e); 49 } catch (SAXException e) { 50 System.out.println(e); 51 } 52 } 53 55 public void parse(){ 56 InputStream in = null; 57 try { 58 if (feature.getSite() == null) 59 return; 60 this.url = new URL(feature.getSite().getResolvedURL(), feature.getURL() + FEATURE_XML); 61 in = url.openStream(); 62 parser.parse(new InputSource(in), this); 63 } catch (SAXException e) { 64 } catch (IOException e) { 65 } finally { 66 if (in != null) 67 try { 68 in.close(); 69 } catch (IOException e1) { 70 Utils.log(e1.getLocalizedMessage()); 71 } 72 } 73 } 74 75 80 public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 81 82 Utils.debug("Start Element: uri:" + uri + " local Name:" + localName + " qName:" + qName); 84 if ("plugin".equals(localName)) { processPlugin(attributes); 86 } else if ("description".equals(localName)){ isDescription = true; 88 } else if ("license".equals(localName)) { processLicense(attributes); 90 } 91 } 92 93 96 private void processPlugin(Attributes attributes) { 97 98 String id = attributes.getValue("id"); String ver = attributes.getValue("version"); 102 if (id == null || id.trim().equals("") || ver == null || ver.trim().equals("")) { System.out.println(NLS.bind(Messages.FeatureParser_IdOrVersionInvalid, (new String [] { id, ver}))); 105 } else { 106 String nl = attributes.getValue("nl"); String os = attributes.getValue("os"); String ws = attributes.getValue("ws"); String arch = attributes.getValue("arch"); if (!Utils.isValidEnvironment(os, ws, arch,nl)) 113 return; 114 115 PluginEntry plugin = new PluginEntry(); 116 plugin.setPluginIdentifier(id); 117 plugin.setPluginVersion(ver); 118 feature.addPlugin(plugin); 119 120 Utils. 121 debug("End process DefaultFeature tag: id:" +id + " ver:" +ver + " url:" + feature.getURL()); } 123 } 124 125 private void processLicense(Attributes attributes ){ 126 feature.setLicenseURL(attributes.getValue("url")); } 128 129 132 public void characters(char[] ch, int start, int length) 133 throws SAXException { 134 if (!isDescription) 135 return; 136 description.append(ch, start, length); 137 } 138 141 public void endElement(String uri, String localName, String qName) 142 throws SAXException { 143 if ("description".equals(localName)) { isDescription = false; 145 String d = description.toString().trim(); 146 ResourceBundle bundle = feature.getResourceBundle(); 147 feature.setDescription(Utils.getResourceString(bundle, d)); 148 } 149 } 150 } 151 | Popular Tags |