⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configuration.java

📁 欢迎使用 FastJsp 开发框架! 编译说明: * 若要生成Api Javadoc文档
💻 JAVA
字号:
// Copyright 2005-2007 onetsoft.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.onetsoft.fastjsp;

import com.onetsoft.fastjsp.request.multipart.UploadConfig;
import com.onetsoft.fastjsp.util.Constants;
import com.onetsoft.fastjsp.util.StringUtils;
import com.onetsoft.fastjsp.valid.DefaultValidationMessageProvider;
import com.onetsoft.fastjsp.valid.ValidationMessageDecorator;
import com.onetsoft.fastjsp.valid.ValidationMessageProvider;

import java.util.Collections;
import java.util.Locale;
import java.util.Map;

/**
 * 配置FastJsp系统
 * 载入当前模块配置
 *
 * @author <a href="mailto:hgw@onetsoft.com">hgw</a>
 */

public abstract class Configuration { 

    /**
     * 当前配置模块名称
     * Just servlet name in web.xml
     */
    private String module = null;


    public Configuration(String module) {
        this.module = module;
    }

    /**
     * 取得当前模块名称
     *
     * @return
     */
    public String getModule() {
        return module;
    }

    /**
     * 取得验证消息模板pattern
     *
     * @return
     */
    public ValidationMessageProvider getValidationMessageProvider() {
        return new DefaultValidationMessageProvider();
    }


    /**
     * 全局i18n字符串资源
     *
     * @return
     * @see PageModule#getI18nStrings(java.util.Locale)
     */
    public MessagesFactory getMessagesFactory() {
        return new MessagesFactory() {
            public Map getI18nMap(Locale locale) {
                return Collections.EMPTY_MAP;
            }
        };
    }

    /**
     * 取得page service factory
     *
     * @return
     */
    public PageServiceFactory getPageServiceFactory() {
        return new PageServiceFactory() {
            public PageService createPageService(Servicer servicer) {
                return new AbstractPageService(servicer) {
                    protected AbstractPageCycle createCycle(AbstractPageService pageService) {
                        return new AbstractPageCycle(pageService) {
                        };
                    }
                };
            }
        };
    }


    /**
     * 取得系统缺省locale
     *
     * @return
     */
    public Locale getLocale() {
        return Locale.getDefault();
    }

    /**
     * 定义缺省字符集
     * 用于 url 解析等,而表单的encoding只能是UTF-8。
     *
     * @return
     */
    public String getEncoding() {
        return Constants.UTF_8;
    }

    public LocaleStateManagerFactory getLocaleStateManagerFactory() {
        return new LocaleStateManagerFactory() {
            public LocaleStateManager getLocaleStateManager() {
                return new LocaleStateManagerImpl();
            }
        };
    }


    /**
     * 返回的消息修饰
     *
     * @return
     */
    public ValidationMessageDecoratorFactory getValidationMessageDecoratorFactory() {
        return new ValidationMessageDecoratorFactory() {
            public ValidationMessageDecorator getDecorator() {
                return new ValidationMessageDecorator() {
                    public String decorate(String message) {
                        if (message == null || message.length() == 0)
                            return StringUtils.EMPTY;
                        else
                            return new StringBuffer("<span style=\"color:red;\">").append(message).append("</span>").toString();
                    }
                };
            }
        };
    }

    /**
     * 上载配置
     *
     * @return
     */
    public UploadConfig getUploadConfig() {
        return new UploadConfig() {
            public int getMaxSize() {
                return 10000000;    //10M
            }

            public int getThresholdSize() {
                return 1024;
            }

            public String getRepositoryPath() {
                return System.getProperty("java.io.tmpdir");
            }
        };
    }


    public DataSqueezerFactory getDataSqueezerFactory() {
        return new DataSqueezerFactory() {
            public DataSqueezer getDataSqueezer() {
                return new DefaultDataSqueezer();
            }
        };
    }

    /**
     * 取得扩展名
     *
     * @return
     */
    public String getUrlExt() {
        return ".html";
    }

    /**
     * 取得servicer配置
     *
     * @return
     */
    public abstract ServicerFactory getServicerFactory();

    /**
     * Action 名称
     * 缺省:action
     *
     * @return
     */
    public abstract String getActionName();


    /**
     * 定义页面存放(包)位置,如:"com.mycompony.pages"
     *
     * @return
     * @see PageModule
     */
    public abstract String getPagePackageBase();

    /**
     * 模块页面模板Context相对位置:如:template/skin1  若为根路径,则为 ""
     * 每个网站模块都有自己模板位置,缺省情况下为web context根目录
     * 注:此位置下的文件及目录组织与{@link this#getPagePackageBase()}下的组织结构相同
     *
     * @return
     * @see PageModule
     * @since 1.2
     */
    public abstract String getPageTemplateBase();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -