MockHandler.java revision f6c387128427e121477c1b32ad35cdcaa5101ba3
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package tests.api.org.xml.sax.support; 18 19import org.xml.sax.AttributeList; 20import org.xml.sax.Attributes; 21import org.xml.sax.ContentHandler; 22import org.xml.sax.DTDHandler; 23import org.xml.sax.DocumentHandler; 24import org.xml.sax.ErrorHandler; 25import org.xml.sax.Locator; 26import org.xml.sax.SAXException; 27import org.xml.sax.SAXParseException; 28import org.xml.sax.ext.LexicalHandler; 29 30/** 31 * A helper class that implements the various SAX callback interfaces and logs 32 * method calls. 33 */ 34@SuppressWarnings("deprecation") 35public class MockHandler implements ContentHandler, DTDHandler, DocumentHandler, 36 ErrorHandler, LexicalHandler { 37 38 private MethodLogger logger; 39 40 public MockHandler(MethodLogger logger) { 41 super(); 42 this.logger = logger; 43 } 44 45 public void characters(char[] ch, int start, int length) throws SAXException { 46 logger.add("characters", ch, start, length); 47 } 48 49 public void endDocument() throws SAXException { 50 logger.add("endDocument"); 51 } 52 53 public void endElement(String name) throws SAXException { 54 logger.add("endElement", name); 55 } 56 57 public void endElement(String uri, String localName, String name) throws SAXException { 58 logger.add("endElement", uri, localName, name); 59 } 60 61 public void endPrefixMapping(String prefix) throws SAXException { 62 logger.add("endPrefixMapping", prefix); 63 } 64 65 public void error(SAXParseException exception) throws SAXException { 66 logger.add("error", exception); 67 } 68 69 public void fatalError(SAXParseException exception) throws SAXException { 70 logger.add("fatalError", exception); 71 } 72 73 public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException { 74 logger.add("ignorableWhitespace", ch, start, length); 75 } 76 77 public void notationDecl(String name, String publicId, String systemId) throws SAXException { 78 logger.add("notationDecl", name, publicId, systemId); 79 } 80 81 public void processingInstruction(String target, String data) throws SAXException { 82 logger.add("processingInstruction", target, data); 83 } 84 85 public void setDocumentLocator(Locator locator) { 86 logger.add("setDocumentLocator", locator); 87 } 88 89 public void skippedEntity(String name) throws SAXException { 90 logger.add("skippedEntity", name); 91 } 92 93 public void startDocument() throws SAXException { 94 logger.add("startDocument"); 95 } 96 97 public void startElement(String name, AttributeList atts) throws SAXException { 98 logger.add("startElement", name, atts); 99 } 100 101 public void startElement(String uri, String localName, String name, Attributes atts) 102 throws SAXException { 103 logger.add("startElement", uri, localName, name, atts); 104 } 105 106 public void startPrefixMapping(String prefix, String uri) throws SAXException { 107 logger.add("startPrefixMapping", prefix, uri); 108 } 109 110 public void unparsedEntityDecl(String name, String publicId, String systemId, 111 String notationName) throws SAXException { 112 logger.add("unparsedEntityDecl", name, publicId, systemId, notationName); 113 } 114 115 public void warning(SAXParseException exception) throws SAXException { 116 logger.add("warning", exception); 117 } 118 119 public void comment(char[] ch, int start, int length) throws SAXException { 120 logger.add("comment", ch, start, length); 121 } 122 123 public void endCDATA() throws SAXException { 124 logger.add("endCDATA"); 125 } 126 127 public void endDTD() throws SAXException { 128 logger.add("endDTD"); 129 } 130 131 public void endEntity(String name) throws SAXException { 132 logger.add("endEntity", name); 133 } 134 135 public void startCDATA() throws SAXException { 136 logger.add("startCDATA"); 137 } 138 139 public void startDTD(String name, String publicId, String systemId) throws SAXException { 140 logger.add("startDTD", name, publicId, systemId); 141 } 142 143 public void startEntity(String name) throws SAXException { 144 logger.add("startEntity", name); 145 } 146 147} 148