1 11 package org.eclipse.team.internal.ui; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.List ; 16 import java.util.Map ; 17 18 import org.xml.sax.Attributes ; 19 import org.xml.sax.SAXException ; 20 import org.xml.sax.helpers.DefaultHandler ; 21 22 public class ProjectSetContentHandler extends DefaultHandler { 23 boolean inPsf = false; 24 boolean inProvider = false; 25 boolean inProject = false; 26 Map map; 27 String id; 28 List references; 29 boolean isVersionOne = false; 30 31 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 32 String elementName = getElementName(namespaceURI, localName, qName); 33 if (elementName.equals("psf")) { map = new HashMap (); 35 inPsf = true; 36 String version = atts.getValue("version"); isVersionOne = version.equals("1.0"); return; 39 } 40 if (isVersionOne) return; 41 if (elementName.equals("provider")) { if (!inPsf) throw new SAXException (TeamUIMessages.ProjectSetContentHandler_Element_provider_must_be_contained_in_element_psf_4); 43 inProvider = true; 44 id = atts.getValue("id"); references = new ArrayList (); 46 return; 47 } 48 if (elementName.equals("project")) { if (!inProvider) throw new SAXException (TeamUIMessages.ProjectSetContentHandler_Element_project_must_be_contained_in_element_provider_7); 50 inProject = true; 51 String reference = atts.getValue("reference"); references.add(reference); 53 return; 54 } 55 } 56 57 public void endElement(String namespaceURI, String localName, String qName) throws SAXException { 58 String elementName = getElementName(namespaceURI, localName, qName); 59 if (elementName.equals("psf")) { inPsf = false; 61 return; 62 } 63 if (isVersionOne) return; 64 if (elementName.equals("provider")) { map.put(id, references); 66 references = null; 67 inProvider = false; 68 return; 69 } 70 if (elementName.equals("project")) { inProject = false; 72 return; 73 } 74 } 75 76 public Map getReferences() { 77 return map; 78 } 79 80 public boolean isVersionOne() { 81 return isVersionOne; 82 } 83 84 89 private String getElementName(String namespaceURI, String localName, String qName) { 90 if (localName != null && localName.length() > 0) { 91 return localName; 92 } else { 93 return qName; 94 } 95 } 96 } 97 | Popular Tags |