KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > schema > SchemaHandler


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.schema;
12
13 import org.eclipse.pde.internal.core.XMLDefaultHandler;
14 import org.w3c.dom.Node JavaDoc;
15 import org.w3c.dom.Text JavaDoc;
16 import org.xml.sax.SAXException JavaDoc;
17
18 public class SchemaHandler extends XMLDefaultHandler {
19
20     public SchemaHandler(boolean abbreviated) {
21         super(abbreviated);
22     }
23     
24     /* (non-Javadoc)
25      * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
26      */

27     public void characters(char[] characters, int start, int length) throws SAXException JavaDoc {
28         if (!fAbbreviated) {
29             super.characters(characters, start, length);
30             return;
31         }
32     
33         if (onAttributeDescription()) {
34             StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
35             buff.append(characters, start, length);
36             Node JavaDoc node = ((Node JavaDoc)fElementStack.peek());
37             Node JavaDoc child = node.getFirstChild();
38             if (child == null)
39                 node.appendChild(getDocument().createTextNode(buff.toString()));
40             else
41                 ((Text JavaDoc)child).appendData(buff.toString());
42         }
43     }
44     
45     private boolean onAttributeDescription() {
46         Node JavaDoc node = (Node JavaDoc)fElementStack.peek();
47         if (node == null)
48             return false;
49         if (!node.getNodeName().equals("documentation")) //$NON-NLS-1$
50
return false;
51         node = node.getParentNode();
52         if (node == null)
53             return false;
54         if (!node.getNodeName().equals("annotation")) //$NON-NLS-1$
55
return false;
56         node = node.getParentNode();
57         if (node == null)
58             return false;
59         return node.getNodeName().equals("attribute"); //$NON-NLS-1$
60
}
61 }
62
Popular Tags