package daruma.xml.handler;

import daruma.xml.handler.XSAXDefaultHandler;

import org.xml.sax.XMLReader;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import java.io.OutputStream;
import java.io.PrintWriter;


public class DebugEchoHandler extends XSAXDefaultHandler
{
	public	DebugEchoHandler( OutputStream  out ,  XMLReader  parser ,
				  boolean  isTopLevelHandler )

	{
		super( out , parser , isTopLevelHandler );
	}

	public	void	xStartElement( String uri ,
				       String localName ,
				       String qName ,
				       Attributes  attrs ) throws SAXException
	{
		PrintWriter	out = super.getPrintWriter();

		out.print( "<" );
		if ( uri.length() > 0 )
		{
			out.print( uri + ":" );
		}
		out.print( localName );
		out.println( ">" );
		out.flush();
	}


	public	void	xEndElement( String uri ,
				     String localName ,
				     String qName )
	{
		PrintWriter	out = super.getPrintWriter();

		out.print( "</" );
		if ( uri.length() > 0 )
		{
			out.print( uri + ":" );
		}
		out.print( localName );
		out.println( ">" );
		out.flush();
	}


	public  void  xCharacters( char[]  str ,  int  offset ,  int  length )
	{
		super.getPrintWriter()
			.print( new String( str, offset , length ) );
	}
}
