org.apache.click.util
Class ErrorReport

java.lang.Object
  extended by org.apache.click.util.ErrorReport

public class ErrorReport
extends Object

Provides an HTML <div> error report for the display of page error information. This class is used by ErrorPage and ClickServlet for the display of error information.


Field Summary
protected  int columnNumber
          The column number of the error, or -1 if not defined.
protected  Throwable error
          The cause of the error.
protected  boolean isParseError
          The error is Velocity parsing exception.
protected  boolean isProductionMode
          The application is in "production" mode flag.
protected  int lineNumber
          The line number of the error, or -1 if not defined.
protected  Class<? extends Page> pageClass
          The page class which caused the error.
protected  HttpServletRequest request
          The servlet request.
protected  ServletContext servletContext
          The servlet context.
protected  String sourceName
          The name of the error source.
protected  LineNumberReader sourceReader
          The error source LineNumberReader.
 
Constructor Summary
ErrorReport(Throwable error, Class<? extends Page> pageClass, boolean isProductionMode, HttpServletRequest request, ServletContext servletContext)
          Create a ErrorReport instance from the given error and page.
 
Method Summary
protected  Throwable getCause()
          Return the cause of the error.
protected  int getColumnNumber()
          Return the error source column number, or -1 if not determined.
protected  LineNumberReader getJavaSourceReader(String filename)
          Return Java Source LineNumberReader for the given filename, or null if not found.
protected  int getLineNumber()
          Return the error source line number, or -1 if not determined.
protected  String getMessage()
          Return the error message.
protected  String getRenderedSource()
          Return a HTML rendered section of the source error with the error line highlighted.
protected  String getRenderJavaLine(String line)
          Return a HTML rendered Java source line with keywords highlighted using the given line.
protected  String getSourceName()
          Return the error source name.
protected  LineNumberReader getSourceReader()
          Return a LineNumberReader for the error source file, or null if not defined.
protected  String getStackTrace()
          Return a HTML encode stack trace string from the given error.
protected  boolean isParseError()
          Return true if the error was a Velocity parsing exception.
protected  boolean isProductionMode()
          Return true if the application is in "production" mode.
protected  String renderJavaKeywords(String line, String keyword)
          Render the HTML rendered Java source line with the given keyword highlighted.
protected  boolean skipLine()
          Return true if the current line read from the source line reader, should be skipped, or false if the current line should be rendered.
 String toString()
          Return a error report HTML <div> element for the given error and page.
protected  void writeMap(Map<String,Object> map, HtmlStringBuffer buffer)
          Write out the map name value pairs as name=value lines to the string buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

columnNumber

protected int columnNumber
The column number of the error, or -1 if not defined.


error

protected final Throwable error
The cause of the error.


lineNumber

protected int lineNumber
The line number of the error, or -1 if not defined.


isParseError

protected final boolean isParseError
The error is Velocity parsing exception.


isProductionMode

protected final boolean isProductionMode
The application is in "production" mode flag.


pageClass

protected final Class<? extends Page> pageClass
The page class which caused the error.


request

protected final HttpServletRequest request
The servlet request.


servletContext

protected final ServletContext servletContext
The servlet context.


sourceName

protected final String sourceName
The name of the error source.


sourceReader

protected LineNumberReader sourceReader
The error source LineNumberReader.

Constructor Detail

ErrorReport

public ErrorReport(Throwable error,
                   Class<? extends Page> pageClass,
                   boolean isProductionMode,
                   HttpServletRequest request,
                   ServletContext servletContext)
Create a ErrorReport instance from the given error and page.

Parameters:
error - the cause of the error
pageClass - the Page class which caused the error
isProductionMode - the application is in "production" mode
request - the page request
servletContext - the servlet context
Method Detail

toString

public String toString()
Return a error report HTML <div> element for the given error and page. The HTML <div> element 'id' and 'class' attribute values are 'errorReport'.

Overrides:
toString in class Object
Returns:
a error HTML display string

getCause

protected Throwable getCause()
Return the cause of the error.

Returns:
the cause of the error

getColumnNumber

protected int getColumnNumber()
Return the error source column number, or -1 if not determined.

Returns:
the error source column number, or -1 if not determined

isParseError

protected boolean isParseError()
Return true if the error was a Velocity parsing exception.

Returns:
true if the error was a Velocity parsing exception

isProductionMode

protected boolean isProductionMode()
Return true if the application is in "production" mode.

Returns:
true if the application is in "production" mode

getLineNumber

protected int getLineNumber()
Return the error source line number, or -1 if not determined.

Returns:
the error source line number, or -1 if not determined

getMessage

protected String getMessage()
Return the error message.

Returns:
the error message

getSourceName

protected String getSourceName()
Return the error source name.

Returns:
the error source name

getSourceReader

protected LineNumberReader getSourceReader()
Return a LineNumberReader for the error source file, or null if not defined.

Returns:
LineNumberReader for the error source file, or null if not defined

getJavaSourceReader

protected LineNumberReader getJavaSourceReader(String filename)
                                        throws FileNotFoundException
Return Java Source LineNumberReader for the given filename, or null if not found.

Parameters:
filename - the name of the Java source file, e.g. /examples/Page.java
Returns:
LineNumberReader for the given source filename, or null if not found
Throws:
FileNotFoundException - if file could not be found

getRenderedSource

protected String getRenderedSource()
Return a HTML rendered section of the source error with the error line highlighted.

Returns:
a HTML rendered section of the parsing error page template

getStackTrace

protected String getStackTrace()
Return a HTML encode stack trace string from the given error.

Returns:
a HTML encode stack trace string.

writeMap

protected void writeMap(Map<String,Object> map,
                        HtmlStringBuffer buffer)
Write out the map name value pairs as name=value lines to the string buffer.

Parameters:
map - the Map of name value pairs
buffer - the string buffer to write out the values to

getRenderJavaLine

protected String getRenderJavaLine(String line)
Return a HTML rendered Java source line with keywords highlighted using the given line.

Parameters:
line - the Java source line to render
Returns:
HTML rendered Java source line

renderJavaKeywords

protected String renderJavaKeywords(String line,
                                    String keyword)
Render the HTML rendered Java source line with the given keyword highlighted.

Parameters:
line - the given Java source line to render
keyword - the Java keyword to highlight
Returns:
the HTML rendered Java source line with the given keyword highlighted

skipLine

protected boolean skipLine()
Return true if the current line read from the source line reader, should be skipped, or false if the current line should be rendered.

Returns:
true if the current line from the source reader should be skipped