【仅供内部供应商使用,不提供对外解答和培训】

Page tree

【仅供内部供应商使用,不提供对外解答和培训】

Skip to end of metadata
Go to start of metadata

FileType

用于表示JS或者CSS的的文件内容,是通过普通的文本方式输出的,还是通过程序代码输出的。

枚举值含义

com.fr.web.struct.category.FileType.PLAIN

直接路径对应的文件的内容
com.fr.web.struct.category.FileType.CLASS输出路径对应的class文件中产生的内容,该class需要继承com.fr.gen.TextGenerator接口


ParserType

用于表示在将JS或者CSS的内容输出到浏览器端的时候,是否需要把文件内部形如${fineServletURL}的内容替换成实际的值。

枚举值含义

com.fr.web.struct.category.ParserType.PLAIN

不替换,原样输出文本内容
com.fr.web.struct.category.ParserType.DYNAMIC替换 

TextGenerator

package com.fr.gen;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 文本生成器
 */
public interface TextGenerator {

    /**
     * 生成文本内容
     *
     * @param req HTTP请求
     * @param res HTTP响应
     * @return 返回的文本内容
     * @throws Exception 生成文本内容失败时抛出此异常
     */
    String text(HttpServletRequest req, HttpServletResponse res) throws Exception;

    /**
     * 文件的媒体类型
     * @return 媒体类型
     */
    String mimeType();
}

以前端国际化文件为例子,就是采用的FileType.CLASS来输出国际化文件的:

I18nTextGenerator
public class I18nTextGenerator implements TextGenerator {
    @Override
    public String text(HttpServletRequest req, HttpServletResponse res) throws Exception {
        Locale locale = WebUtils.getLocale(req);
        Map<String, String> map = InterProviderFactory.getClientProvider().getEntireKV(locale);
        String originText = new ObjectMapper().writeValueAsString(map);
        Map<String, Object> renderMap = new HashMap<String, Object>();
        renderMap.put("value", originText);
        return TemplateUtils.renderTemplate("/com/fr/decision/web/i18n/i18n.tpl", renderMap);
    }

    @Override
    public String mimeType() {
        return "text/javascript";
    }
}
  • No labels