001: /*
002: * (C) Copyright 2002, Andy Clark. All rights reserved.
003: *
004: * This file is distributed under an Apache style license. Please
005: * refer to the LICENSE file for specific details.
006: */
007:
008: package org.cyberneko.pull.util;
009:
010: import org.cyberneko.pull.XMLEvent;
011: import org.cyberneko.pull.event.CDATAEvent;
012: import org.cyberneko.pull.event.CharactersEvent;
013: import org.cyberneko.pull.event.CommentEvent;
014: import org.cyberneko.pull.event.DoctypeDeclEvent;
015: import org.cyberneko.pull.event.DocumentEvent;
016: import org.cyberneko.pull.event.ElementEvent;
017: import org.cyberneko.pull.event.GeneralEntityEvent;
018: import org.cyberneko.pull.event.PrefixMappingEvent;
019: import org.cyberneko.pull.event.ProcessingInstructionEvent;
020: import org.cyberneko.pull.event.TextDeclEvent;
021:
022: import org.apache.xerces.xni.XNIException;
023:
024: /**
025: *
026: *
027: * @author Andy Clark
028: *
029: * @version $Id$
030: */
031: public class DefaultHandler {
032:
033: //
034: // Public methods
035: //
036:
037: public void handleEvent(XMLEvent event) throws XNIException {
038: switch (event.type) {
039: case XMLEvent.CDATA: {
040: CDATAEvent cdataEvent = (CDATAEvent) event;
041: if (cdataEvent.start) {
042: handleStartCDATA(cdataEvent);
043: } else {
044: handleEndCDATA(cdataEvent);
045: }
046: break;
047: }
048: case XMLEvent.CHARACTERS: {
049: CharactersEvent charsEvent = (CharactersEvent) event;
050: if (charsEvent.ignorable) {
051: handleIgnorableWhitespace(charsEvent);
052: } else {
053: handleCharacters(charsEvent);
054: }
055: break;
056: }
057: case XMLEvent.COMMENT: {
058: CommentEvent commentEvent = (CommentEvent) event;
059: handleComment(commentEvent);
060: break;
061: }
062: case XMLEvent.DOCTYPE_DECL: {
063: DoctypeDeclEvent doctypeEvent = (DoctypeDeclEvent) event;
064: handleDoctypeDecl(doctypeEvent);
065: break;
066: }
067: case XMLEvent.DOCUMENT: {
068: DocumentEvent documentEvent = (DocumentEvent) event;
069: if (documentEvent.start) {
070: handleStartDocument(documentEvent);
071: } else {
072: handleEndDocument(documentEvent);
073: }
074: break;
075: }
076: case XMLEvent.ELEMENT: {
077: ElementEvent elementEvent = (ElementEvent) event;
078: if (elementEvent.start) {
079: handleStartElement(elementEvent);
080: } else {
081: handleEndElement(elementEvent);
082: }
083: break;
084: }
085: case XMLEvent.GENERAL_ENTITY: {
086: GeneralEntityEvent geEvent = (GeneralEntityEvent) event;
087: if (geEvent.start) {
088: handleStartGeneralEntity(geEvent);
089: } else {
090: handleEndGeneralEntity(geEvent);
091: }
092: break;
093: }
094: default: {
095: handleUnknownEvent(event);
096: }
097: }
098: } // handleEvent(XMLEvent)
099:
100: public void handleStartCDATA(CDATAEvent event) throws XNIException {
101: }
102:
103: public void handleEndCDATA(CDATAEvent event) throws XNIException {
104: }
105:
106: public void handleIgnorableWhitespace(CharactersEvent event)
107: throws XNIException {
108: }
109:
110: public void handleCharacters(CharactersEvent event)
111: throws XNIException {
112: }
113:
114: public void handleComment(CommentEvent event) throws XNIException {
115: }
116:
117: public void handleDoctypeDecl(DoctypeDeclEvent event)
118: throws XNIException {
119: }
120:
121: public void handleStartDocument(DocumentEvent event)
122: throws XNIException {
123: }
124:
125: public void handleEndDocument(DocumentEvent event)
126: throws XNIException {
127: }
128:
129: public void handleStartElement(ElementEvent event)
130: throws XNIException {
131: }
132:
133: public void handleEndElement(ElementEvent event)
134: throws XNIException {
135: }
136:
137: public void handleStartGeneralEntity(GeneralEntityEvent event)
138: throws XNIException {
139: }
140:
141: public void handleEndGeneralEntity(GeneralEntityEvent event)
142: throws XNIException {
143: }
144:
145: public void handleUnknownEvent(XMLEvent event) throws XNIException {
146: throw new XNIException("unknown event type (" + event.type
147: + ')');
148: } // handleUnknownEvent(XMLEvent)
149:
150: } // class DefaultHandler
|