1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 package org.apache.qetest.xsl;
  21 
  22 import org.xml.sax.SAXException;
  23 import org.xml.sax.ext.LexicalHandler;
  24 
  25 /**
  26  * Cheap-o LexicalHandler for use by API tests. This is a wrapper LexicalHandler.
  27  * It always delegate the lexical analysis to wrapped LexicalHandler.
  28  */
  29 public class CheckingLexicalHandler implements LexicalHandler {
  30     /**
  31      * Default handler
  32      */
  33     private final LexicalHandler defaultHandler;
  34     
  35     /**
  36      * Default constructor.
  37      */
  38     public CheckingLexicalHandler() {
  39         defaultHandler = null;
  40     } 
  41     
  42     /**
  43      * Constructor by setting LexicalHandler.
  44      * @param lh a delegated LexicalHandler.
  45      */
  46     public CheckingLexicalHandler(LexicalHandler lh) {
  47         defaultHandler = lh;
  48     } 
  49     
  50     ////////////////// Implement LexicalHandler //////////////////
  51     @Override
  52     public void startDTD(String name, String publicId, String systemId) throws SAXException {
  53         if(null != defaultHandler)
  54             defaultHandler.startDTD(name, publicId, systemId);
  55     }
  56 
  57     @Override
  58     public void endDTD() throws SAXException {
  59         if(null != defaultHandler)
  60             defaultHandler.endDTD();
  61     }
  62 
  63     @Override
  64     public void startEntity(String name) throws SAXException {
  65         if(null != defaultHandler)
  66             defaultHandler.startEntity(name);
  67     }
  68 
  69     @Override
  70     public void endEntity(String name) throws SAXException {
  71         if(null != defaultHandler)
  72             defaultHandler.endEntity(name);
  73     }
  74 
  75     @Override
  76     public void startCDATA() throws SAXException {
  77         if(null != defaultHandler)
  78             defaultHandler.startCDATA();
  79     }
  80 
  81     @Override
  82     public void endCDATA() throws SAXException {
  83         if(null != defaultHandler)
  84             defaultHandler.endCDATA();
  85     }
  86 
  87     @Override
  88     public void comment(char ch[], int start, int length) throws SAXException {
  89         if(null != defaultHandler)
  90             defaultHandler.comment(ch, start, length);
  91     }
  92 }