001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.schema;
011:
012: import org.xml.sax.Attributes;
013: import org.xml.sax.SAXException;
014:
015: /**
016: * SchemaAnnotationHandler
017: *
018: */
019: public class SchemaAnnotationHandler extends BaseSchemaHandler {
020:
021: private final static String[] DESC_NESTED_ELEM = { "documentation", //$NON-NLS-1$
022: "annotation", "schema" }; //$NON-NLS-1$ //$NON-NLS-2$
023:
024: private final static String META_SCHEMA_ELEM = "meta.schema"; //$NON-NLS-1$
025:
026: private final static String APP_INFO_ELEM = "appInfo"; //$NON-NLS-1$
027:
028: private final static String NAME_ATTR = "name"; //$NON-NLS-1$
029:
030: private StringBuffer fDescription;
031:
032: private String fName;
033:
034: private boolean fMetaSchemaElemFlag;
035:
036: private boolean fAppInfoElemFlag;
037:
038: /**
039: *
040: */
041: public SchemaAnnotationHandler() {
042: super ();
043: }
044:
045: protected void reset() {
046: super .reset();
047: fName = null;
048: fDescription = new StringBuffer();
049: fMetaSchemaElemFlag = false;
050: fAppInfoElemFlag = false;
051: }
052:
053: public void startElement(String uri, String localName,
054: String qName, Attributes attributes) throws SAXException {
055: super .startElement(uri, localName, qName, attributes);
056:
057: if ((fElementList.size() >= 2)
058: && (((String) fElementList.get(1))
059: .compareTo(APP_INFO_ELEM) == 0)) {
060: fAppInfoElemFlag = true;
061: if (qName.compareTo(META_SCHEMA_ELEM) == 0) {
062: // Case: <appInfo><meta.schema>
063: fMetaSchemaElemFlag = true;
064: if (attributes != null) {
065: fName = attributes.getValue(NAME_ATTR);
066: }
067: } else {
068: // Case: <appInfo><xxxxx>
069: fMetaSchemaElemFlag = false;
070: }
071: }
072: }
073:
074: public void characters(char[] ch, int start, int length)
075: throws SAXException {
076:
077: if (onTarget()) {
078: for (int i = 0; i < length; i++) {
079: fDescription.append(ch[start + i]);
080: }
081: }
082: }
083:
084: protected boolean onTarget() {
085: if (fElementList.size() >= DESC_NESTED_ELEM.length) {
086: for (int i = 0; i < DESC_NESTED_ELEM.length; i++) {
087: String currentElement = (String) fElementList.get(i);
088: if (currentElement.compareTo(DESC_NESTED_ELEM[i]) != 0) {
089: return false;
090: }
091: }
092: if (fMetaSchemaElemFlag || !fAppInfoElemFlag) {
093: return true;
094: }
095: }
096: return false;
097: }
098:
099: public String getDescription() {
100: return fDescription.toString();
101: }
102:
103: public String getName() {
104: return fName;
105: }
106: }
|