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 SchemaAttributeHandler extends BaseSchemaHandler { 22 23 private String fElementName; 24 25 private String fAttributeName; 26 27 private String fTargetElementName; 28 29 private String fTargetAttributeName; 30 31 private StringBuffer fDescription; 32 33 private final static String [] DESC_NESTED_ELEM = { "documentation", "annotation", "attribute", "complexType", "element" }; 36 private final static String NAME_ATTR = "name"; 38 41 public SchemaAttributeHandler(String targetElementName, String targetAttributeName) { 42 super(); 43 setTargetElementName(targetElementName); 44 setTargetAttributeName(targetAttributeName); 45 } 46 47 public void setTargetElementName(String targetElementName) { 48 fTargetElementName = targetElementName; 49 } 50 51 public void setTargetAttributeName(String targetAttributeName) { 52 fTargetAttributeName = targetAttributeName; 53 } 54 55 protected void reset() { 56 super.reset(); 57 fDescription = new StringBuffer (); 58 fElementName = null; 59 fAttributeName = null; 60 } 61 62 public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 63 super.startElement(uri, localName, qName, attributes); 64 if (qName.compareTo(DESC_NESTED_ELEM[4]) == 0) { 65 if ((attributes != null) && 69 (attributes.getValue(NAME_ATTR) != null)) { 70 fElementName = attributes.getValue(NAME_ATTR); 71 } 72 } else if (qName.compareTo(DESC_NESTED_ELEM[2]) == 0) { 73 if (attributes != null) { 76 fAttributeName = attributes.getValue(NAME_ATTR); 77 } 78 } 79 } 80 81 public void characters(char[] ch, int start, int length) throws SAXException { 82 83 if (onTarget()) { 84 for (int i = 0; i < length; i++) { 85 fDescription.append(ch[start + i]); 86 } 87 } 88 } 89 90 protected boolean onTarget() { 91 if (fElementList.size() >= DESC_NESTED_ELEM.length) { 92 for (int i = 0; i < DESC_NESTED_ELEM.length; i++) { 93 String currentElement = (String )fElementList.get(i); 94 if (currentElement.compareTo(DESC_NESTED_ELEM[i]) != 0) { 95 return false; 96 } 97 } 98 if ((fElementName == null) || 99 (fElementName.compareTo(fTargetElementName) != 0)) { 100 return false; 101 } 102 if ((fAttributeName == null) || 103 (fAttributeName.compareTo(fTargetAttributeName) != 0)) { 104 return false; 105 } 106 return true; 107 } 108 return false; 109 } 110 111 public String getDescription() { 112 return fDescription.toString(); 113 } 114 115 } 116 | Popular Tags |