1 11 package org.eclipse.update.internal.configurator; 12 13 14 import java.io.*; 15 import java.net.*; 16 17 import javax.xml.parsers.*; 18 19 import org.eclipse.osgi.util.NLS; 20 import org.xml.sax.*; 21 import org.xml.sax.helpers.*; 22 23 29 public class FeatureParser extends DefaultHandler { 30 31 private SAXParser parser; 32 private FeatureEntry feature; 33 private URL url; 34 35 private final static SAXParserFactory parserFactory = 36 SAXParserFactory.newInstance(); 37 38 41 public FeatureParser() { 42 super(); 43 try { 44 parserFactory.setNamespaceAware(true); 45 this.parser = parserFactory.newSAXParser(); 46 } catch (ParserConfigurationException e) { 47 System.out.println(e); 48 } catch (SAXException e) { 49 System.out.println(e); 50 } 51 } 52 55 public FeatureEntry parse(URL featureURL){ 56 feature=null; 57 InputStream in = null; 58 try { 59 this.url = featureURL; 60 in = featureURL.openStream(); 61 parser.parse(new InputSource(in), this); 62 } catch (SAXException e) { 63 } catch (IOException e) { 64 } finally { 65 if (in != null) 66 try { 67 in.close(); 68 } catch (IOException e1) { 69 Utils.log(e1.getLocalizedMessage()); 70 } 71 } 72 return feature; 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 ("feature".equals(localName)) { processFeature(attributes); 86 throw new SAXException(""); } 89 } 90 91 94 private void processFeature(Attributes attributes) { 95 96 String id = attributes.getValue("id"); String ver = attributes.getValue("version"); 100 if (id == null || id.trim().equals("") || ver == null || ver.trim().equals("")) { System.out.println(NLS.bind(Messages.FeatureParser_IdOrVersionInvalid, (new String [] { id, ver}))); 103 } else { 104 String os = attributes.getValue("os"); String ws = attributes.getValue("ws"); String nl = attributes.getValue("nl"); String arch = attributes.getValue("arch"); if (!Utils.isValidEnvironment(os, ws, arch, nl)) 112 return; 113 116 String primary = attributes.getValue("primary"); boolean isPrimary = "true".equals(primary); String application = attributes.getValue("application"); String plugin = attributes.getValue("plugin"); 121 feature = new FeatureEntry(id, ver, plugin, "", isPrimary, application, null ); if ("file".equals(url.getProtocol())) { File f = new File(url.getFile().replace('/', File.separatorChar)); 125 feature.setURL("features" + "/" + f.getParentFile().getName() + "/"); } else { 127 feature.setURL(Utils.makeAbsolute(Utils.getInstallURL(), url).toExternalForm()); 129 } 130 131 Utils. 132 debug("End process DefaultFeature tag: id:" +id + " ver:" +ver + " url:" + feature.getURL()); } 134 } 135 } 136 | Popular Tags |