package com.apobates.forum.thrones.tag;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class PostsFloorTag extends SimpleTagSupport {
    // 楼层数值
    private int value;
    private final static String[] floorAlias = {"楼主", "沙发", "藤椅", "板凳", "报纸", "地板"};
    
    public void setValue(int value) {
        this.value = value;
    }
    
    @Override
    public void doTag() throws JspException, IOException {
        String sb = value + "";
        if(value>=1){
            try{
                sb = floorAlias[value-1];
            }catch(ArrayIndexOutOfBoundsException e){}
        }
        getJspContext().getOut().print(sb);
    }
    
    /*
     * 回复楼层的别名
     *
     * @author xiaofanku
     * @since 20190325
     *
    enum PostsFloorAliasEnum {
        LORD(1, "楼主"),
        SOFA(2, "沙发"),
        CHAIR(3, "藤椅"),
        STOOL(4, "板凳"),
        PAPER(5, "报纸"),
        DECK(6, "地板");
        
        private final int symbol;
        private final String title;
        
        private PostsFloorAliasEnum(int symbol, String title) {
            this.symbol = symbol;
            this.title = title;
        }
        
        public int getSymbol() {
            return symbol;
        }
        
        public String getTitle() {
            return title;
        }
        public static PostsFloorAliasEnum getInstance(int floor){
            PostsFloorAliasEnum ins = null;
            for(PostsFloorAliasEnum fa : PostsFloorAliasEnum.values()){
                if(fa.getSymbol() == floor){
                    ins = fa;
                    break;
                }
            }
            return ins;
        }
    }*/
}