/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* * $Id$ */ /* * * LoggingLexicalHandler.java * */ package org.apache.qetest.xsl; import org.apache.qetest.Logger; import org.apache.qetest.LoggingHandler; import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; /** * Cheap-o LexicalHandler for use by API tests. *

Implements LexicalHandler and dumps simplistic info * everything to a Logger; a way to debug SAX stuff.

* @author shane_curcuru@lotus.com * @version $Id$ */ public class LoggingLexicalHandler extends LoggingHandler implements LexicalHandler { /** No-op sets logger to default. */ public LoggingLexicalHandler() { setLogger(getDefaultLogger()); } /** * Ctor that calls setLogger automatically. * * @param l Logger we should log to */ public LoggingLexicalHandler(Logger l) { setLogger(l); } /** * Our default handler that we pass all events through to. */ protected LexicalHandler defaultHandler = null; /** * Set a default handler for us to wrapper. * Set a LexicalHandler for us to use. * * @param default Object of the correct type to pass-through to; * throws IllegalArgumentException if null or incorrect type */ public void setDefaultHandler(Object defaultH) { try { defaultHandler = (LexicalHandler)defaultH; } catch (Throwable t) { throw new java.lang.IllegalArgumentException("setDefaultHandler illegal type: " + t.toString()); } } /** * Accessor method for our default handler. * * @return default (Object) our default handler; null if unset */ public Object getDefaultHandler() { return (Object)defaultHandler; } /** Prefixed to all logger msg output. */ public static final String prefix = "LLH:"; /** Constant for items returned in getCounters: startDTD. */ public static final int TYPE_STARTDTD = 0; /** Constant for items returned in getCounters: endDTD. */ public static final int TYPE_ENDDTD = 1; /** Constant for items returned in getCounters: startEntity. */ public static final int TYPE_STARTENTITY = 2; /** Constant for items returned in getCounters: endEntity. */ public static final int TYPE_ENDENTITY = 3; /** Constant for items returned in getCounters: startCDATA. */ public static final int TYPE_STARTCDATA = 4; /** Constant for items returned in getCounters: endCDATA. */ public static final int TYPE_ENDCDATA = 5; /** Constant for items returned in getCounters: comment. */ public static final int TYPE_COMMENT = 6; /** * Counters for how many events we've handled. * Index into array are the TYPE_* constants. */ protected int[] counters = { 0, /* startDTD */ 0, /* endDTD */ 0, /* startEntity */ 0, /* endEntity */ 0, /* startCDATA */ 0, /* endCDATA */ 0 /* comment */ }; /** * Get a list of counters of all items we've logged. * Returned in order as startDTD, endDTD, startEntity, * endEntity, startCDATA, endCDATA, comment. * Index into array are the TYPE_* constants. * * @return array of int counters for each item we log */ public int[] getCounters() { return counters; } /** * Really Cheap-o string representation of our state. * * @return String of getCounters() rolled up in minimal space */ public String getQuickCounters() { return (prefix + "(" + counters[TYPE_STARTDTD] + ", " + counters[TYPE_ENDDTD] + "; " + counters[TYPE_STARTENTITY] + ", " + counters[TYPE_ENDENTITY] + "; " + counters[TYPE_STARTCDATA] + ", " + counters[TYPE_ENDCDATA] + "; " + counters[TYPE_COMMENT] + ")"); } /** Expected values for events we may handle, default=ITEM_DONT_CARE. */ protected String[] expected = { ITEM_DONT_CARE, /* startDTD */ ITEM_DONT_CARE, /* endDTD */ ITEM_DONT_CARE, /* startEntity */ ITEM_DONT_CARE, /* endEntity */ ITEM_DONT_CARE, /* startCDATA */ ITEM_DONT_CARE, /* endCDATA */ ITEM_DONT_CARE /* comment */ }; /** Cheap-o string representation of last event we got. */ protected String lastItem = NOTHING_HANDLED; /** * Accessor for string representation of last event we got. * @param s string to set */ protected void setLastItem(String s) { lastItem = s; } /** * Accessor for string representation of last event we got. * @return last event string we had */ public String getLast() { return lastItem; } /** * Ask us to report checkPass/Fail for certain events we handle. * Since we may have to handle many events between when a test * will be able to call us, testers can set this to have us * automatically call checkPass when we see an item that matches, * or to call checkFail when we get an unexpected item. * Generally, we only call check* methods when: *