// copyright => http://www.jxml.com/mdsax/License.txt

package com.jxml.quick;
import org.xml.sax.*;
import java.io.*;

public class QPE extends SAXParseException
{
    public QPE(String message, QContext context)
    {
	super(message,context.locator);
    }

    public QPE(String message, 
	       String publicId, 
	       String systemId,
	       int lineNumber, 
	       int columnNumber)
    {
	super(message,
	      publicId,
	      systemId,
	      lineNumber,
	      columnNumber);
    }

    public QPE(SAXParseException e, QContext context)
    {
	super(e.getMessage(),e.getPublicId(),e.getSystemId(),e.getLineNumber(),e.getColumnNumber());
    }

    public QPE(Exception exception, QContext context)
    {
	super(exceptionInfo(exception), context.locator);
    }

    private static String exceptionInfo(Exception e) 
    {
	StringWriter stringWriter = new StringWriter();
	e.printStackTrace( new PrintWriter(stringWriter) );
	return stringWriter.toString();
    }

    /**
     * Display QPE Exception
     */
    public void display()
    {
	int line=getLineNumber();
	if (line!=-1)
    	    System.out.println("line="+line);
	int col=getColumnNumber();
	if (col!=-1)
            System.out.println("column="+col);
	String sysId=getSystemId();
	if (sysId!=null)
	    System.out.println("systemId="+sysId);
	System.out.println(getMessage());
    }

    /**
     * Display Exception
     */
    public static void display(SAXParseException e)
    {
	if (e instanceof QPE)
		((QPE)e).display();
	else
	{
	    int line=e.getLineNumber();
	    if (line!=-1)
    	        System.out.println("line="+line);
	    int col=e.getColumnNumber();
	    if (col!=-1)
    	        System.out.println("column="+col);
	    String sysId=e.getSystemId();
	    if (sysId!=null)
	        System.out.println("systemId="+sysId);
	    e.printStackTrace();
	}
    }

    /**
     * Display Exception
     */
    public static void display(Exception e)
    {
	if (e instanceof SAXParseException)
		display((SAXParseException)e);
	else
	    e.printStackTrace();
    }
}
