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

📄 uploadpolicyfactory.java

📁 [linux.rar] - 嵌入式linux开发教程
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }

    /**
     * Get a String parameter value from applet properties or System properties.
     * 
     * @param theApplet The current applet
     * @param key The parameter name
     * @param def The default value
     * @param uploadPolicy The current upload policy
     * 
     * @return the parameter value, or the default, if the system is not set.
     */
    static public float getParameter(JUploadApplet theApplet, String key,
            float def, UploadPolicy uploadPolicy) {
        String paramStr;
        String paramDef = Float.toString(def);

        // First, read the parameter as a String
        if (theApplet == null) {
            paramStr = System.getProperty(key) != null ? System
                    .getProperty(key) : paramDef;
        } else {
            paramStr = theApplet.getParameter(key) != null ? theApplet
                    .getParameter(key) : paramDef;
        }

        displayDebugParameterValue(uploadPolicy, key, paramStr);

        return parseFloat(paramStr, def, uploadPolicy);
    }

    /**
     * Get a String parameter value from applet properties or System properties.
     * 
     * @param theApplet The current applet
     * @param key The parameter name
     * @param def The default value
     * @param uploadPolicy The current upload policy
     * 
     * @return the parameter value, or the default, if the system is not set.
     */
    static public long getParameter(JUploadApplet theApplet, String key,
            long def, UploadPolicy uploadPolicy) {
        String paramStr;
        String paramDef = Long.toString(def);

        // First, read the parameter as a String
        if (theApplet == null) {
            paramStr = System.getProperty(key) != null ? System
                    .getProperty(key) : paramDef;
        } else {
            paramStr = theApplet.getParameter(key) != null ? theApplet
                    .getParameter(key) : paramDef;
        }

        displayDebugParameterValue(uploadPolicy, key, paramStr);

        return parseLong(paramStr, def, uploadPolicy);
    }// getParameter(int)

    /**
     * Get a boolean parameter value from applet properties or System
     * properties.
     * 
     * @param theApplet The current applet
     * @param key The parameter name
     * @param def The default value
     * @param uploadPolicy The current upload policy
     * 
     * @return the parameter value, or the default, if the system is not set.
     */
    static public boolean getParameter(JUploadApplet theApplet, String key,
            boolean def, UploadPolicy uploadPolicy) {
        String paramStr;
        String paramDef = (def ? "true" : "false");

        // First, read the parameter as a String
        if (theApplet == null) {
            paramStr = System.getProperty(key) != null ? System
                    .getProperty(key) : paramDef;
        } else {
            paramStr = theApplet.getParameter(key) != null ? theApplet
                    .getParameter(key) : paramDef;
        }

        displayDebugParameterValue(uploadPolicy, key, paramStr);

        return parseBoolean(paramStr, def, uploadPolicy);
    }// getParameter(boolean)

    /**
     * This function try to parse value as an integer. If value is not a correct
     * integer, def is returned.
     * 
     * @param value The string value, that must be parsed
     * @param def The default value
     * @param uploadPolicy The current upload policy
     * @return The integer value of value, or def if value is not valid.
     */
    static public int parseInt(String value, int def, UploadPolicy uploadPolicy) {
        int ret = def;
        // Then, parse it as an integer.
        try {
            ret = Integer.parseInt(value);
        } catch (NumberFormatException e) {
            ret = def;
            if (uploadPolicy != null) {
                uploadPolicy.displayWarn("Invalid int value: " + value
                        + ", using default value: " + def);
            }
        }

        return ret;
    }

    /**
     * This function try to parse value as a float number. If value is not a
     * correct float, def is returned.
     * 
     * @param value The string value, that must be parsed
     * @param def The default value
     * @param uploadPolicy The current upload policy
     * @return The float value of value, or def if value is not valid.
     */
    static public float parseFloat(String value, float def,
            UploadPolicy uploadPolicy) {
        float ret = def;
        // Then, parse it as an integer.
        try {
            ret = Float.parseFloat(value);
        } catch (NumberFormatException e) {
            ret = def;
            if (uploadPolicy != null) {
                uploadPolicy.displayWarn("Invalid float value: " + value
                        + ", using default value: " + def);
            }
        }

        return ret;
    }

    /**
     * This function try to parse value as a Long. If value is not a correct
     * long, def is returned.
     * 
     * @param value The string value, that must be parsed
     * @param def The default value
     * @param uploadPolicy The current upload policy
     * @return The integer value of value, or def if value is not valid.
     */
    static public long parseLong(String value, long def,
            UploadPolicy uploadPolicy) {
        long ret = def;
        // Then, parse it as an integer.
        try {
            ret = Long.parseLong(value);
        } catch (NumberFormatException e) {
            ret = def;
            if (uploadPolicy != null) {
                uploadPolicy.displayWarn("Invalid long value: " + value
                        + ", using default value: " + def);
            }
        }

        return ret;
    }

    /**
     * This function try to parse value as a boolean. If value is not a correct
     * boolean, def is returned.
     * 
     * @param value The new value for this property. If invalid, the default
     *            value is used.
     * @param def The default value: used if value is invalid.
     * @param uploadPolicy If not null, it will be used to display a warning
     *            when the value is invalid.
     * @return The boolean value of value, or def if value is not a valid
     *         boolean.
     */
    static public boolean parseBoolean(String value, boolean def,
            UploadPolicy uploadPolicy) {
        // Then, parse it as a boolean.
        if (value.toUpperCase().equals("FALSE")) {
            return false;
        } else if (value.toUpperCase().equals("TRUE")) {
            return true;
        } else {
            if (uploadPolicy != null) {
                uploadPolicy.displayWarn("Invalid boolean value: " + value
                        + ", using default value: " + def);
            }
            return def;
        }
    }

    /**
     * Displays the debug information for the current parameter.
     */
    private static void displayDebugParameterValue(UploadPolicy uploadPolicy,
            String key, String value) {
        if (uploadPolicy != null && uploadPolicy.getDebugLevel() >= 80) {
            uploadPolicy.displayDebug("Parameter '" + key + "' loaded. Value: "
                    + value, 80);
        }
    }

    /**
     * Help to log debug information to the user. Use of log4j, one day in the
     * future, would help.
     * 
     * @param currentDebugLevel
     */
    private static void logDebug(String msg, int currentDebugLevel) {
        if (currentDebugLevel > 0) {
            System.out.println("[DEBUG] " + msg);
        }
    }
}

⌨️ 快捷键说明

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