FileDocCategorySizeDatePackage
ParseNumberSupport.javaAPI DocGlassfish v2 API7234Sat May 05 19:17:52 BST 2007org.apache.taglibs.standard.tag.common.fmt

ParseNumberSupport

public abstract class ParseNumberSupport extends javax.servlet.jsp.tagext.BodyTagSupport
Support for tag handlers for <parseNumber>, the number parsing tag in JSTL 1.0.
author
Jan Luehe

Fields Summary
private static final String
NUMBER
private static final String
CURRENCY
private static final String
PERCENT
protected String
value
protected boolean
valueSpecified
protected String
type
protected String
pattern
protected Locale
parseLocale
protected boolean
isIntegerOnly
protected boolean
integerOnlySpecified
private String
var
private int
scope
Constructors Summary
public ParseNumberSupport()

                           // 'scope' attribute


    //*********************************************************************
    // Constructor and initialization

      
	super();
	init();
    
Methods Summary
private java.text.NumberFormatcreateParser(java.util.Locale loc)

	NumberFormat parser = null;

	if ((type == null) || NUMBER.equalsIgnoreCase(type)) {
	    parser = NumberFormat.getNumberInstance(loc);
	} else if (CURRENCY.equalsIgnoreCase(type)) {
	    parser = NumberFormat.getCurrencyInstance(loc);
	} else if (PERCENT.equalsIgnoreCase(type)) {
	    parser = NumberFormat.getPercentInstance(loc);
	} else {
	    throw new JspException(
                    Resources.getMessage("PARSE_NUMBER_INVALID_TYPE", 
					 type));
	}

	return parser;
    
public intdoEndTag()

	String input = null;

        // determine the input by...
	if (valueSpecified) {
	    // ... reading 'value' attribute
	    input = value;
	} else {
	    // ... retrieving and trimming our body
	    if (bodyContent != null && bodyContent.getString() != null)
	        input = bodyContent.getString().trim();
	}

	if ((input == null) || input.equals("")) {
	    if (var != null) {
		pageContext.removeAttribute(var, scope);
	    }
	    return EVAL_PAGE;
	}

	/*
	 * Set up parsing locale: Use locale specified via the 'parseLocale'
	 * attribute (if present), or else determine page's locale.
	 */
	Locale loc = parseLocale;
	if (loc == null)
	    loc = SetLocaleSupport.getFormattingLocale(pageContext,
                                                       this,
                                                       false,
                                                       false);
	if (loc == null) {
	    throw new JspException(
                    Resources.getMessage("PARSE_NUMBER_NO_PARSE_LOCALE"));
	}

	// Create parser
	NumberFormat parser = null;
	if ((pattern != null) && !pattern.equals("")) {
	    // if 'pattern' is specified, 'type' is ignored
	    DecimalFormatSymbols symbols = new DecimalFormatSymbols(loc);
	    parser = new DecimalFormat(pattern, symbols);
	} else {
	    parser = createParser(loc);
	}

	// Configure parser
	if (integerOnlySpecified)
	    parser.setParseIntegerOnly(isIntegerOnly);

	// Parse number
	Number parsed = null;
	try {
	    parsed = parser.parse(input);
	} catch (ParseException pe) {
	    throw new JspException(
	            Resources.getMessage("PARSE_NUMBER_PARSE_ERROR", input),
		    pe);
	}

	if (var != null) {
	    pageContext.setAttribute(var, parsed, scope);	
	} else {
	    try {
		pageContext.getOut().print(parsed);
	    } catch (IOException ioe) {
		throw new JspTagException(ioe.toString(), ioe);
	    }
	}

	return EVAL_PAGE;
    
private voidinit()

	value = type = pattern = var = null;
	valueSpecified = false;
	parseLocale = null;
	integerOnlySpecified = false;
	scope = PageContext.PAGE_SCOPE;
    
public voidrelease()

	init();
    
public voidsetScope(java.lang.String scope)

	this.scope = Util.getScope(scope);
    
public voidsetVar(java.lang.String var)

        this.var = var;