1 11 package org.eclipse.pde.internal.core.plugin; 12 13 import java.util.*; 14 15 import org.eclipse.pde.core.plugin.*; 16 import org.xml.sax.*; 17 import org.xml.sax.helpers.*; 18 19 23 public class ExtensionsParser extends DefaultHandler { 24 25 private Vector fExtensions; 26 private Vector fExtensionPoints; 27 28 private Stack fOpenElements; 29 private Locator fLocator; 30 private boolean fIsLegacy = true; 31 private ISharedPluginModel fModel; 32 33 36 public ExtensionsParser(ISharedPluginModel model) { 37 super(); 38 fExtensionPoints = new Vector(); 39 fExtensions = new Vector(); 40 fModel = model; 41 } 42 43 46 public void processingInstruction(String target, String data) 47 throws SAXException { 48 if ("eclipse".equals(target)) { fIsLegacy = false; 50 } 51 } 52 53 56 public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 57 if (fOpenElements == null) { 58 if (qName.equals("plugin") || qName.equals("fragment")) { fOpenElements = new Stack(); 60 } 61 } else if (fOpenElements.size() == 0) { 62 if (qName.equals("extension")) { createExtension(attributes); 64 } else if (qName.equals("extension-point")) { createExtensionPoint(attributes); 66 } 67 } else { 68 createElement(qName, attributes); 69 } 70 } 71 72 75 private void createExtension(Attributes attributes) { 76 PluginExtension extension = new PluginExtension(); 77 if (extension.load(attributes, fLocator.getLineNumber())) { 78 extension.setModel(fModel); 79 extension.setInTheModel(true); 80 fExtensions.add(extension); 81 String point = extension.getPoint(); 82 if ("org.eclipse.pde.core.source".equals(point) || "org.eclipse.core.runtime.products".equals(point)) fOpenElements.push(extension); 84 } 85 } 86 87 90 private void createExtensionPoint(Attributes attributes) { 91 PluginExtensionPoint extPoint = new PluginExtensionPoint(); 92 if (extPoint.load(attributes, fLocator.getLineNumber())) { 93 extPoint.setModel(fModel); 94 extPoint.setInTheModel(true); 95 fExtensionPoints.add(extPoint); 96 } 97 } 98 99 private void createElement(String tagName, Attributes attributes) { 100 PluginElement element = new PluginElement(); 101 PluginParent parent = (PluginParent)fOpenElements.peek(); 102 element.setParent(parent); 103 element.setInTheModel(true); 104 element.setModel(fModel); 105 element.load(tagName, attributes); 106 parent.appendChild(element); 107 fOpenElements.push(element); 108 } 109 110 113 public void endElement(String uri, String localName, String qName) 114 throws SAXException { 115 if (fOpenElements != null && !fOpenElements.isEmpty()) 116 fOpenElements.pop(); 117 } 118 119 122 public void setDocumentLocator(Locator locator) { 123 fLocator = locator; 124 } 125 126 public boolean isLegacy() { 127 return fIsLegacy; 128 } 129 130 public Vector getExtensions() { 131 return fExtensions; 132 } 133 134 public Vector getExtensionPoints() { 135 return fExtensionPoints; 136 } 137 } 138 | Popular Tags |