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 18 22 public class SchemaAnnotationHandler extends BaseSchemaHandler { 23 24 private final static String [] DESC_NESTED_ELEM = { "documentation", "annotation", "schema" }; 27 private final static String META_SCHEMA_ELEM = "meta.schema"; 29 private final static String APP_INFO_ELEM = "appInfo"; 31 private final static String NAME_ATTR = "name"; 33 private StringBuffer fDescription; 34 35 private String fName; 36 37 private boolean fMetaSchemaElemFlag; 38 39 private boolean fAppInfoElemFlag; 40 41 44 public SchemaAnnotationHandler() { 45 super(); 46 } 47 48 protected void reset() { 49 super.reset(); 50 fName = null; 51 fDescription = new StringBuffer (); 52 fMetaSchemaElemFlag = false; 53 fAppInfoElemFlag = false; 54 } 55 56 public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 57 super.startElement(uri, localName, qName, attributes); 58 59 if ((fElementList.size() >= 2) && 60 (((String )fElementList.get(1)).compareTo(APP_INFO_ELEM) == 0)) { 61 fAppInfoElemFlag = true; 62 if (qName.compareTo(META_SCHEMA_ELEM) == 0) { 63 fMetaSchemaElemFlag = true; 65 if (attributes != null) { 66 fName = attributes.getValue(NAME_ATTR); 67 } 68 } else { 69 fMetaSchemaElemFlag = false; 71 } 72 } 73 } 74 75 public void characters(char[] ch, int start, int length) throws SAXException { 76 77 if (onTarget()) { 78 for (int i = 0; i < length; i++) { 79 fDescription.append(ch[start + i]); 80 } 81 } 82 } 83 84 protected boolean onTarget() { 85 if (fElementList.size() >= DESC_NESTED_ELEM.length) { 86 for (int i = 0; i < DESC_NESTED_ELEM.length; i++) { 87 String currentElement = (String )fElementList.get(i); 88 if (currentElement.compareTo(DESC_NESTED_ELEM[i]) != 0) { 89 return false; 90 } 91 } 92 if (fMetaSchemaElemFlag || !fAppInfoElemFlag) { 93 return true; 94 } 95 } 96 return false; 97 } 98 99 public String getDescription() { 100 return fDescription.toString(); 101 } 102 103 public String getName() { 104 return fName; 105 } 106 } 107 | Popular Tags |