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

📄 typeconverter.java

📁 jsp中 urlRewrite的源代码 很有用的喔
💻 JAVA
字号:
/**
 * Copyright (c) 2005, Paul Tuckey
 * All rights reserved.
 *
 * Each copy or derived work must preserve the copyright notice and this
 * notice unmodified.
 *
 * This program 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
package org.tuckey.web.filters.urlrewrite;

import org.tuckey.web.filters.urlrewrite.utils.StringUtils;

/**
 * Assists with the setting of variable type names for condition types and rule to variables.
 *
 * @author Paul Tuckey
 * @version $Revision: 1.2 $ $Date: 2005/12/07 10:27:04 $
 */
public class TypeConverter {

    /**
     * Type of condition ie, header, port etc.
     */
    protected short type;

    /**
     * Error message from the regular expression compilation.
     */
    protected String error = null;

    // Type statics
    public static final short TYPE_TIME = 4;
    public static final short TYPE_TIME_YEAR = 5;
    public static final short TYPE_TIME_MONTH = 6;
    public static final short TYPE_TIME_DAY_OF_MONTH = 7;
    public static final short TYPE_TIME_DAY_OF_WEEK = 8;
    public static final short TYPE_TIME_AMPM = 9;
    public static final short TYPE_TIME_HOUR_OF_DAY = 10;
    public static final short TYPE_TIME_MINUTE = 11;
    public static final short TYPE_TIME_SECOND = 12;
    public static final short TYPE_TIME_MILLISECOND = 13;
    public static final short TYPE_ATTRIBUTE = 14;
    public static final short TYPE_AUTH_TYPE = 15;
    public static final short TYPE_CHARACTER_ENCODING = 16;
    public static final short TYPE_CONTENT_LENGTH = 17;
    public static final short TYPE_CONTENT_TYPE = 18;
    public static final short TYPE_CONTEXT_PATH = 19;
    public static final short TYPE_COOKIE = 20;
    public static final short TYPE_HEADER = 1;
    public static final short TYPE_LOCAL_PORT = 39;
    public static final short TYPE_METHOD = 21;
    public static final short TYPE_PARAMETER = 22;
    public static final short TYPE_PATH_INFO = 23;
    public static final short TYPE_PATH_TRANSLATED = 24;
    public static final short TYPE_PROTOCOL = 25;
    public static final short TYPE_QUERY_STRING = 26;
    public static final short TYPE_REMOTE_ADDR = 27;
    public static final short TYPE_REMOTE_HOST = 28;
    public static final short TYPE_REMOTE_USER = 29;
    public static final short TYPE_REQUESTED_SESSION_ID = 30;
    public static final short TYPE_REQUEST_URI = 31;
    public static final short TYPE_REQUEST_URL = 32;
    public static final short TYPE_SESSION_ATTRIBUTE = 33;
    public static final short TYPE_SESSION_IS_NEW = 34;
    public static final short TYPE_SERVER_PORT = 35;
    public static final short TYPE_SERVER_NAME = 36;
    public static final short TYPE_SCHEME = 37;
    public static final short TYPE_USER_IN_ROLE = 38;

    /**
     * Will get the type code ie, method, port, header etc.
     *
     * @return String
     */
    public String getType() {
        switch (type) {

            case TYPE_TIME:
                return "time";
            case TYPE_TIME_YEAR:
                return "year";
            case TYPE_TIME_MONTH:
                return "month";
            case TYPE_TIME_DAY_OF_MONTH:
                return "dayofmonth";
            case TYPE_TIME_DAY_OF_WEEK:
                return "dayofweek";

            case TYPE_TIME_AMPM:
                return "ampm";
            case TYPE_TIME_HOUR_OF_DAY:
                return "hourofday";
            case TYPE_TIME_MINUTE:
                return "minute";
            case TYPE_TIME_SECOND:
                return "second";
            case TYPE_TIME_MILLISECOND:
                return "millisecond";

            case TYPE_ATTRIBUTE:
                return "attribute";
            case TYPE_AUTH_TYPE:
                return "auth-type";
            case TYPE_CHARACTER_ENCODING:
                return "character-encoding";
            case TYPE_CONTENT_LENGTH:
                return "content-length";
            case TYPE_CONTENT_TYPE:
                return "content-type";

            case TYPE_CONTEXT_PATH:
                return "context-path";
            case TYPE_COOKIE:
                return "cookie";
            case TYPE_HEADER:
                return "header";
            case TYPE_LOCAL_PORT:
                return "local-port";
            case TYPE_METHOD:
                return "method";
            case TYPE_PARAMETER:
                return "parameter";

            case TYPE_PATH_INFO:
                return "path-info";
            case TYPE_PATH_TRANSLATED:
                return "path-translated";
            case TYPE_PROTOCOL:
                return "protocol";
            case TYPE_QUERY_STRING:
                return "query-string";
            case TYPE_REMOTE_ADDR:
                return "remote-addr";

            case TYPE_REMOTE_HOST:
                return "remote-host";
            case TYPE_REMOTE_USER:
                return "remote-user";
            case TYPE_REQUESTED_SESSION_ID:
                return "requested-session-id";
            case TYPE_REQUEST_URI:
                return "request-uri";
            case TYPE_REQUEST_URL:
                return "request-url";

            case TYPE_SESSION_ATTRIBUTE:
                return "session-attribute";
            case TYPE_SESSION_IS_NEW:
                return "session-isnew";
            case TYPE_SERVER_PORT:
                return "port";
            case TYPE_SERVER_NAME:
                return "server-name";
            case TYPE_SCHEME:
                return "scheme";

            case TYPE_USER_IN_ROLE:
                return "user-in-role";
            default:
                return "";
        }
    }

    /**
     * Will set the type.
     *
     * @param strType the type
     */
    public void setType(final String strType) {
        if ("time".equals(strType)) {
            this.type = TYPE_TIME;
        } else if ("year".equals(strType)) {
            this.type = TYPE_TIME_YEAR;
        } else if ("month".equals(strType)) {
            this.type = TYPE_TIME_MONTH;
        } else if ("dayofmonth".equals(strType)) {
            this.type = TYPE_TIME_DAY_OF_MONTH;
        } else if ("dayofweek".equals(strType)) {
            this.type = TYPE_TIME_DAY_OF_WEEK;

        } else if ("ampm".equals(strType)) {
            this.type = TYPE_TIME_AMPM;
        } else if ("hourofday".equals(strType)) {
            this.type = TYPE_TIME_HOUR_OF_DAY;
        } else if ("minute".equals(strType)) {
            this.type = TYPE_TIME_MINUTE;
        } else if ("second".equals(strType)) {
            this.type = TYPE_TIME_SECOND;
        } else if ("millisecond".equals(strType)) {
            this.type = TYPE_TIME_MILLISECOND;

        } else if ("attribute".equals(strType)) {
            this.type = TYPE_ATTRIBUTE;
        } else if ("auth-type".equals(strType)) {
            this.type = TYPE_AUTH_TYPE;
        } else if ("character-encoding".equals(strType)) {
            this.type = TYPE_CHARACTER_ENCODING;
        } else if ("content-length".equals(strType)) {
            this.type = TYPE_CONTENT_LENGTH;
        } else if ("content-type".equals(strType)) {
            this.type = TYPE_CONTENT_TYPE;

        } else if ("context-path".equals(strType)) {
            this.type = TYPE_CONTEXT_PATH;
        } else if ("cookie".equals(strType)) {
            this.type = TYPE_COOKIE;
        } else if ("header".equals(strType) || StringUtils.isBlank(strType)) {
            this.type = TYPE_HEADER;
        } else if ("local-port".equals(strType)) {
            this.type = TYPE_LOCAL_PORT;
        } else if ("method".equals(strType)) {
            this.type = TYPE_METHOD;
        } else if ("parameter".equals(strType)) {
            this.type = TYPE_PARAMETER;

        } else if ("path-info".equals(strType)) {
            this.type = TYPE_PATH_INFO;
        } else if ("path-translated".equals(strType)) {
            this.type = TYPE_PATH_TRANSLATED;
        } else if ("protocol".equals(strType)) {
            this.type = TYPE_PROTOCOL;
        } else if ("query-string".equals(strType)) {
            this.type = TYPE_QUERY_STRING;
        } else if ("remote-addr".equals(strType)) {
            this.type = TYPE_REMOTE_ADDR;

        } else if ("remote-host".equals(strType)) {
            this.type = TYPE_REMOTE_HOST;
        } else if ("remote-user".equals(strType)) {
            this.type = TYPE_REMOTE_USER;
        } else if ("requested-session-id".equals(strType)) {
            this.type = TYPE_REQUESTED_SESSION_ID;
        } else if ("request-uri".equals(strType)) {
            this.type = TYPE_REQUEST_URI;
        } else if ("request-url".equals(strType)) {
            this.type = TYPE_REQUEST_URL;

        } else if ("session-attribute".equals(strType)) {
            this.type = TYPE_SESSION_ATTRIBUTE;
        } else if ("session-isnew".equals(strType)) {
            this.type = TYPE_SESSION_IS_NEW;
        } else if ("port".equals(strType)) {
            this.type = TYPE_SERVER_PORT;
        } else if ("server-name".equals(strType)) {
            this.type = TYPE_SERVER_NAME;
        } else if ("scheme".equals(strType)) {
            this.type = TYPE_SCHEME;

        } else if ("user-in-role".equals(strType)) {
            this.type = TYPE_USER_IN_ROLE;

        } else {
            setError("Type " + strType + " is not valid");
        }
    }


    /**
     * Will get the description of the error.
     *
     * @return String
     */
    public final String getError() {
        return error;
    }

    protected void setError(String error) {
        this.error = error;
    }

    public int getTypeShort() {
        return type;
    }
}

⌨️ 快捷键说明

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