1 11 12 package org.eclipse.pde.internal.core.schema; 13 14 import org.xml.sax.Attributes ; 15 import org.xml.sax.SAXException ; 16 17 21 public class SchemaElementHandler extends BaseSchemaHandler { 22 23 private String fElementName; 24 25 private String fTargetElementName; 26 27 private StringBuffer fDescription; 28 29 private final static String [] DESC_NESTED_ELEM = { "documentation", "annotation", "element" }; 32 private final static String NAME_ATTR = "name"; 34 37 public SchemaElementHandler(String targetElementName) { 38 super(); 39 setTargetElementName(targetElementName); 40 } 41 42 public void setTargetElementName(String targetElement) { 43 fTargetElementName = targetElement; 44 } 45 46 protected void reset() { 47 super.reset(); 48 fDescription = new StringBuffer (); 49 fElementName = null; 50 } 51 52 public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 53 super.startElement(uri, localName, qName, attributes); 54 55 if (qName.compareTo(DESC_NESTED_ELEM[2]) == 0) { 56 fElementName = attributes.getValue(NAME_ATTR); 61 } 62 } 63 64 public void characters(char[] ch, int start, int length) throws SAXException { 65 66 if (onTarget()) { 67 for (int i = 0; i < length; i++) { 68 fDescription.append(ch[start + i]); 69 } 70 } 71 } 72 73 protected boolean onTarget() { 74 if (fElementList.size() >= DESC_NESTED_ELEM.length) { 75 for (int i = 0; i < DESC_NESTED_ELEM.length; i++) { 76 String currentElement = (String )fElementList.get(i); 77 if (currentElement.compareTo(DESC_NESTED_ELEM[i]) != 0) { 78 return false; 79 } 80 } 81 if ((fElementName == null) || 82 (fElementName.compareTo(fTargetElementName) != 0)) { 83 return false; 84 } 85 return true; 86 } 87 return false; 88 } 89 90 public String getDescription() { 91 return fDescription.toString(); 92 } 93 } 94 | Popular Tags |