001 /* 002 * Copyright (c) 2005 Henri Sivonen 003 * Copyright (c) 2007 Mozilla Foundation 004 * 005 * Permission is hereby granted, free of charge, to any person obtaining a 006 * copy of this software and associated documentation files (the "Software"), 007 * to deal in the Software without restriction, including without limitation 008 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 009 * and/or sell copies of the Software, and to permit persons to whom the 010 * Software is furnished to do so, subject to the following conditions: 011 * 012 * The above copyright notice and this permission notice shall be included in 013 * all copies or substantial portions of the Software. 014 * 015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 018 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 020 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 021 * DEALINGS IN THE SOFTWARE. 022 */ 023 024 package nu.validator.xml; 025 026 import org.xml.sax.Attributes; 027 import org.xml.sax.ContentHandler; 028 import org.xml.sax.SAXException; 029 030 /** 031 * @version $Id: SaxEmitter.java 13 2007-09-20 12:47:56Z hsivonen $ 032 * @author hsivonen 033 */ 034 public class SaxEmitter { 035 protected ContentHandler contentHandler; 036 037 /** 038 * @param contentHandler 039 */ 040 public SaxEmitter(ContentHandler contentHandler) { 041 this.contentHandler = contentHandler; 042 } 043 public void startElement(String ns, String name, Attributes attrs) throws SAXException { 044 this.contentHandler.startElement(ns, name, name, attrs); 045 } 046 047 public void startElement(String ns, String name) throws SAXException { 048 this.contentHandler.startElement(ns, name, name, EmptyAttributes.EMPTY_ATTRIBUTES); 049 } 050 051 public void endElement(String ns, String name) throws SAXException { 052 this.contentHandler.endElement(ns, name, name); 053 } 054 055 public void characters(String content) throws SAXException { 056 this.contentHandler.characters(content.toCharArray(), 0, content.length()); 057 } 058 059 public void characters(char[] content) throws SAXException { 060 this.contentHandler.characters(content, 0, content.length); 061 } 062 063 public void characters(char[] buffer, int offset, int length) throws SAXException { 064 this.contentHandler.characters(buffer, offset, length); 065 } 066 }