Package br.net.woodstock.rockframework.web.jsp.taglib.util

Source Code of br.net.woodstock.rockframework.web.jsp.taglib.util.FormatTag

/*
* This file is part of rockframework.
*
* rockframework is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* rockframework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>;.
*/
package br.net.woodstock.rockframework.web.jsp.taglib.util;

import java.io.IOException;
import java.io.Writer;

import br.net.woodstock.rockframework.core.RockFrameworkLogger;
import br.net.woodstock.rockframework.core.string.StringFormatter;
import br.net.woodstock.rockframework.core.utils.Strings;
import br.net.woodstock.rockframework.web.jsp.taglib.AbstractTag;

public class FormatTag extends AbstractTag {

  private static final String  ERROR_VALUE  = "??ERROR??";

  private String        format;

  private Object        value;

  private char        character;

  public FormatTag() {
    super();
    this.character = StringFormatter.DEFAULT_CHARACTER;
  }

  @Override
  public void doTag() throws IOException {
    if (this.value == null) {
      return;
    }

    StringFormatter format = new StringFormatter(this.format, this.character);
    String value = this.value.toString();
    Writer writer = this.getJspContext().getOut();
    String formated = "";

    try {
      formated = format.format(value);
      formated = Strings.escapeHTML(formated);
    } catch (ArrayIndexOutOfBoundsException e) {
      RockFrameworkLogger.getLogger().warn("Error formating '" + value + "'  with mask '" + this.format + "'");
      formated = FormatTag.ERROR_VALUE;
    }

    writer.write(formated);
  }

  public String getFormat() {
    return this.format;
  }

  public void setFormat(final String format) {
    this.format = format;
  }

  public Object getValue() {
    return this.value;
  }

  public void setValue(final Object value) {
    this.value = value;
  }

  public char getCharacter() {
    return this.character;
  }

  public void setCharacter(final char character) {
    this.character = character;
  }

}
TOP

Related Classes of br.net.woodstock.rockframework.web.jsp.taglib.util.FormatTag

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.