org.jboss.seam.ui.validator
Class FormattedTextValidator

java.lang.Object
  extended by org.jboss.seam.ui.validator.FormattedTextValidator
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.faces.validator.Validator

public class FormattedTextValidator
extends java.lang.Object
implements javax.faces.validator.Validator, java.io.Serializable

Formatted Text validator Use as a JSF validator on an input control that allows entering Seam Text markup.

The Seam Text parser has a disabled default error handler, catch exceptions as appropriate if you display Seam Text (see http://www.doc.ic.ac.uk/lab/secondyear/Antlr/err.html) and call the static convenience method FormattedTextValidator.getErrorMessage(originalText, recognitionException) if you want to display or log a nice error message.

Uses an instance of SeamTextParser by default, override if you require validation with your customized instance of SeamTextParser.

Author:
matthew.drees, Christian Bauer
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface javax.faces.validator.Validator
NOT_IN_RANGE_MESSAGE_ID
 
Constructor Summary
FormattedTextValidator()
           
 
Method Summary
static java.lang.String getErrorLocation(java.lang.String originalText, antlr.RecognitionException re, int charsBefore, int charsAfter)
          Extracts the error from the RecognitionException and generates a location of the error by extracting the original text at the exceptions line and column.
static java.lang.String getErrorMessage(java.lang.String originalText, antlr.RecognitionException re)
          Extracts the error from the RecognitionException and generates a message including the location of the error.
 java.lang.String getMismatchedTokenErrorMessage(java.lang.String originalMessage, java.lang.String location)
          Override (e.g.
 java.lang.String getNoViableAltErrorMessage(java.lang.String originalMessage, java.lang.String location)
          Override (e.g.
 int getNumberOfCharsAfterErrorLocation()
           
 int getNumberOfCharsBeforeErrorLocation()
           
 java.lang.String getParserErrorMessage(java.lang.String originalText, antlr.RecognitionException re)
           
 org.jboss.seam.text.SeamTextParser getSeamTextParser(java.lang.String text)
          Override to instantiate a custom SeamTextLexer and SeamTextParser.
 java.lang.String getSemanticErrorMessage(java.lang.String originalMessage)
          Override (e.g.
 void validate(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object value)
          Validate the given value as well-formed Seam Text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormattedTextValidator

public FormattedTextValidator()
Method Detail

validate

public void validate(javax.faces.context.FacesContext context,
                     javax.faces.component.UIComponent component,
                     java.lang.Object value)
              throws javax.faces.validator.ValidatorException
Validate the given value as well-formed Seam Text. If there are parse errors, throw a ValidatorException including the first parse error.

Specified by:
validate in interface javax.faces.validator.Validator
Throws:
javax.faces.validator.ValidatorException

getSeamTextParser

public org.jboss.seam.text.SeamTextParser getSeamTextParser(java.lang.String text)
Override to instantiate a custom SeamTextLexer and SeamTextParser.

Parameters:
text - the raw markup text
Returns:
an instance of SeamTextParser

getParserErrorMessage

public java.lang.String getParserErrorMessage(java.lang.String originalText,
                                              antlr.RecognitionException re)

getNumberOfCharsBeforeErrorLocation

public int getNumberOfCharsBeforeErrorLocation()

getNumberOfCharsAfterErrorLocation

public int getNumberOfCharsAfterErrorLocation()

getNoViableAltErrorMessage

public java.lang.String getNoViableAltErrorMessage(java.lang.String originalMessage,
                                                   java.lang.String location)
Override (e.g. for i18n) ANTLR parser error messages.

Parameters:
originalMessage - the ANTLR parser error message of the RecognitionException
location - a snippet that indicates the location in the original markup, might be null
Returns:
a message that is thrown by this validator

getMismatchedTokenErrorMessage

public java.lang.String getMismatchedTokenErrorMessage(java.lang.String originalMessage,
                                                       java.lang.String location)
Override (e.g. for i18n) ANTLR parser error messages.

Parameters:
originalMessage - the ANTLR parser error message of the RecognitionException
location - a snippet that indicates the location in the original markup, might be null
Returns:
a message that is thrown by this validator

getSemanticErrorMessage

public java.lang.String getSemanticErrorMessage(java.lang.String originalMessage)
Override (e.g. for i18n) ANTLR parser error messages.

Parameters:
originalMessage - the ANTLR parser error message of the RecognitionException
Returns:
a message that is thrown by this validator

getErrorLocation

public static java.lang.String getErrorLocation(java.lang.String originalText,
                                                antlr.RecognitionException re,
                                                int charsBefore,
                                                int charsAfter)
Extracts the error from the RecognitionException and generates a location of the error by extracting the original text at the exceptions line and column.

Parameters:
originalText - the original Seam Text markup as fed into the parser
re - an ANTLR RecognitionException thrown by the parser
charsBefore - characters before error location included in message
charsAfter - characters after error location included in message
Returns:
an error message with some helpful context about where the error occured

getErrorMessage

public static java.lang.String getErrorMessage(java.lang.String originalText,
                                               antlr.RecognitionException re)
Extracts the error from the RecognitionException and generates a message including the location of the error.

Parameters:
originalText - the original Seam Text markup as fed into the parser
re - an ANTLR RecognitionException thrown by the parser
Returns:
an error message with some helpful context about where the error occured


Copyright © 2009 JBoss. All Rights Reserved.