package com.jfinal.club.common.doc.convert;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;

public class DocKit {

    /**
     * 根据文件名或文件类型转成对应的图标
     * @return
     */
    public static String typeToHtml(Integer fileType){
        switch (fileType){
            case 1:
                return "<i class=\"icon_pdf\"></i>";
            case 2:
            return "<i class=\"icon_word\"></i>";
            case 3:
                return "<i class=\"icon_p\"></i>";
            default:
                return "<i class=\"icon_word2\"></i>";
        }
    }

    /**
     * 根据文件名或文件类型转成对应的图标
     * @return
     */
    public static String typeToHtml(String fileName){
        if(StringUtils.isBlank(fileName)){
            return typeToHtml(0);
        }else {
            String extName = FilenameUtils.getExtension(fileName);
            int fileType = 0;
            switch (extName){
                case "pdf":
                    fileType = 1;
                    break;
                case "doc":
                    fileType = 2;
                    break;
                case "docx":
                    fileType = 2;
                    break;
                case "ppt":
                    fileType = 3;
                    break;
                case "pptx":
                    fileType = 3;
                    break;
                default:
                    break;
            }
            return typeToHtml(fileType);
        }
    }


}
