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 java.io.IOException; 20import java.util.HashMap; 21import java.util.HashSet; 22import java.util.Map; 23import java.util.Set; 24 25import org.xml.sax.InputSource; 26import org.xml.sax.SAXException; 27import org.xml.sax.SAXNotRecognizedException; 28import org.xml.sax.SAXNotSupportedException; 29import org.xml.sax.helpers.XMLFilterImpl; 30 31/** 32 * A helper class that extends XMLFilterImpl, provides dummy feature/property 33 * management, and logs some method calls. 34 */ 35public class MockFilter extends XMLFilterImpl { 36 37 private MethodLogger logger; 38 39 private Set<String> features = new HashSet<String>(); 40 41 private Map<String, Object> properties = new HashMap<String, Object>(); 42 43 public MockFilter(MethodLogger logger) { 44 super(); 45 this.logger = logger; 46 } 47 48 @Override 49 public boolean getFeature(String name) throws SAXNotRecognizedException, 50 SAXNotSupportedException { 51 return features.contains(name); 52 } 53 54 @Override 55 public Object getProperty(String name) throws SAXNotRecognizedException, 56 SAXNotSupportedException { 57 return properties.get(name); 58 } 59 60 @Override 61 public void setFeature(String name, boolean value) { 62 if (value) { 63 features.add(name); 64 } else { 65 features.remove(name); 66 } 67 } 68 69 @Override 70 public void setProperty(String name, Object value) throws SAXNotRecognizedException, 71 SAXNotSupportedException { 72 if (value == null) { 73 properties.remove(name); 74 } else { 75 properties.put(name, value); 76 } 77 } 78 79 @Override 80 public void parse(InputSource input) throws SAXException, IOException { 81 logger.add("parse", input); 82 } 83 84 @Override 85 public void parse(String systemId) throws SAXException, IOException { 86 logger.add("parse", systemId); 87 } 88 89} 90