KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.pde.internal.core.schema;
13
14 import java.io.StringReader JavaDoc;
15 import java.util.LinkedList JavaDoc;
16
17 import org.xml.sax.Attributes JavaDoc;
18 import org.xml.sax.InputSource JavaDoc;
19 import org.xml.sax.SAXException JavaDoc;
20 import org.xml.sax.helpers.DefaultHandler JavaDoc;
21
22 /**
23  * BaseDescriptionHandler
24  *
25  */

26 public class BaseSchemaHandler extends DefaultHandler JavaDoc {
27
28     protected LinkedList JavaDoc fElementList;
29     
30     public BaseSchemaHandler() {
31         reset();
32     }
33
34     protected void reset() {
35         fElementList = new LinkedList JavaDoc();
36     }
37     
38     public void startDocument() throws SAXException JavaDoc {
39         reset();
40     }
41     
42     public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc attributes) throws SAXException JavaDoc {
43         // Track where we are in the XML document
44
// Note: XML namespaces not utilized, safe to use qualified name
45
fElementList.addFirst(qName);
46     }
47     
48     public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName) throws SAXException JavaDoc {
49         // Track where we are in the XML document
50
if (fElementList.size() != 0) {
51             fElementList.removeFirst();
52         } else {
53             // This should never happened and is ignored in any case
54
throw new SAXException JavaDoc("Serious error. XML document is not well-formed"); //$NON-NLS-1$
55
}
56     }
57
58     public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId) throws SAXException JavaDoc {
59         // Prevent the resolution of external entities in order to
60
// prevent the parser from accessing the Internet
61
// This will prevent huge workbench performance degradations and hangs
62
return new InputSource JavaDoc(new StringReader JavaDoc("")); //$NON-NLS-1$
63
}
64     
65 }
66
Popular Tags