/*
 * @(#)Command.java	1.1.1 2002/11/20
 *
 * Copyright 2001-2002 by BeiJing Camelot, Inc., CHINA
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Camelot, Inc.  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with Camelot.
 */
package com.coolservlets.beans.method;

/**import slmagic.log.*;

 /**
 * Class for element check method
 * @author      yulixin
 * @version 	1.1.1, 2001/04/05
 * @since       JDK1.2, JSDK 2.0
 */
public class CheckMethod
{
    /**
     * Check the string is null or not
     *
     * @param        String strVal:string checked
     * @return       boolean true if the string is not null
     */
    static public boolean isNotNull(String strVal)
    {
        if (strVal == null)
            return false;
        if (strVal.trim().equals(""))
            return false;
        return true;
    }

    /**
     * Remove comma from string
     * @param        String strCommaNum:string that want to remove comma out
     * @return       String strResult:string that have no comma
     */
    static public String delCommaFromStr( String strCommaNum )
    {
        int iLen = strCommaNum.length();
        String strResult = "";

        if (!isNotNull(strCommaNum))
        {
            return strCommaNum;
        }

        for( int i = 0; i < iLen; i ++ )
        {
            if( strCommaNum.charAt(i) != ',')
            {
                strResult = strResult + String.valueOf(strCommaNum.charAt(i));
            }
        }
        return strResult;
    }

    /**
     * Remove char from string
     * @param        String strString:string that want to remove char out
     * @param        char chChar:which char will be removed
     * @return       String strResult:string that have removed char out
     */
    static public String delCharFromString( String strString , char chChar )
    {
        int iLen = strString.length();
        String strResult = "";

        if (!isNotNull(strString))
        {
            return strString;
        }

        for( int i = 0; i < iLen; i ++ )
        {
            if( strString.charAt(i) != chChar)
            {
                strResult = strResult + String.valueOf(strString.charAt(i));
            }
        }
        return strResult;
    }

    /**
     * judge the type is long or not
     *
     * @param        String  strVal:data checked
     * @return       boolean true if it is long
     */
    static public boolean isLong(String strVal)
    {
        Long lTemp = null;

        if(!isNotNull(strVal) || ! isHalfNum(strVal) )
        {
            return false;
        }

        strVal = delCommaFromStr(strVal);
        try
        {
            lTemp = new Long(strVal);
        }
        catch(Exception e)
        {
            return false;
        }
        return true;
    }

    /**
     * judge the type is integer or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it is integer
     */
    static public boolean isInteger(String strVal)
    {
        Integer iTemp = null;

        if(!isNotNull(strVal) || ! isHalfNum(strVal) )
        {
            return false;
        }

        strVal = delCommaFromStr(strVal);
        try
        {
            iTemp = new Integer(strVal);
        }
        catch(Exception e)
        {
            return false;
        }
        return true;
    }

    /**
     * judge the type is float or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it is float
     */
    static public boolean isFloat(String strVal)
    {
        Float fTemp = null;

        if(!isNotNull(strVal) )
        {
            return false;
        }

        strVal = delCommaFromStr(strVal);
        try
        {
            fTemp = new Float(strVal);
            if( fTemp.isNaN() == true )
                return false;
        }
        catch(Exception e)
        {
            return false;
        }
        return true;
    }

    /**
     * judge the type is double or not
     * @param        String strVal:data checked
     * @return       boolean true if it is double
     */
    static public boolean isDouble(String strVal)
    {
        Double dTemp = null;

        if(!isNotNull(strVal) )
        {
            return false;
        }

        strVal = delCommaFromStr(strVal);
        try
        {
            dTemp = new Double(strVal);
            if( dTemp.isNaN() == true )
                return false;
        }
        catch(Exception e)
        {
            return false;
        }
        return true;
    }

    /**
     * judge the type is number or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it is Number
     */
    static public boolean isNumber(String strVal)
    {
        if(!isDouble(strVal))
        {
            return false;
        }
        return true;
    }

    /**
     * Check decimal and length of number
     *
     * @param        String strVal:number checked
     * @param        int iDec:used for decimal check
     * @param        int iRangeLength:used for strVal's length check
     * @return       boolean true if decimal and length is true
     */
    static public boolean chkDec(String strVal, int iDec , int iRangeLength)
    {
        int iLength = 0;

        if( !isNotNull(strVal) || (iRangeLength <= 0) || (iDec <0) )
        {
            return false;
        }

        strVal = delCommaFromStr(strVal);
        iLength = strVal.length();

        if( iLength > iRangeLength )
        {
            return false;
        }

        if (strVal.indexOf(".") == -1)
        {
            if( iLength > (iRangeLength-iDec-1) )
                return false;
            else
                return true;
        }
        else if( strVal.indexOf(".") > iRangeLength - iDec - 1 )
        {
            return false;
        }
        else if( ( iLength - strVal.indexOf(".") - 1 ) > iDec )
        {
            return false;
        }

        return true;
    }

    /**
     * Check the date is valid date ( YYYY/MM/DD ) or not
     *
     * @param        String strVal:date checked
     * @return       boolean true if date is valid
     */
    static public boolean isValidDate(String strVal)
    {
        if( !isNotNull(strVal) )
        {
            return false;
        }

        if( !isLong( delCharFromString(strVal, '/') ) )
        {
            return false;
        }

        int iIndex1,iIndex2;

        iIndex1 = strVal.indexOf("/");
        iIndex2 = strVal.indexOf("/", iIndex1+1);

        if( iIndex1 == -1 || iIndex1 == iIndex2 || iIndex2 != strVal.lastIndexOf("/") )
        {
            return false;
        }

        int iYear, iMonth , iDay;
        try
        {
            iYear   = Integer.parseInt( strVal.substring(0, iIndex1) );
            iMonth  = Integer.parseInt( strVal.substring(iIndex1 + 1, iIndex2) );
            iDay    = Integer.parseInt( strVal.substring(iIndex2 + 1) );
        }
        catch(Exception e)
        {
            return false;
        }

        /**
         * If the year is valid
         */
        if ( ! ( iYear >= 1000 && iYear <= 9999 ) )
        {
            return false;
        }

        /**
         * If the month is valid
         */
        if ( iMonth < 1 || iMonth > 12 )
        {
            return false;
        }

        /**
         * If the day is valid
         */
        if ( iMonth == 1 || iMonth == 3 || iMonth == 5 || iMonth == 7 || iMonth == 8 || iMonth == 10 || iMonth == 12 )
        {
            if ( iDay < 1 || iDay > 31 )
            {
                return false;
            }
        }
        else if ( iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11 )
        {
            if ( iDay < 1 || iDay > 30 )
            {
                return false;
            }
        }
        else if ( iMonth == 2 )
        {
            if ( isLeapYear( iYear ) )
            {
                if ( iDay < 1 || iDay > 29 )
                {
                    return false;
                }
            }
            else
            {
                if ( iDay < 1 || iDay > 28 )
                {
                    return false;
                }
            }
        }
        else
        {
            return false;
        }

        return true;
    }

    /**
     * Check the date is valid date ( YYYY/MM/DD HH:MM:DD ) or not
     *
     * @param        String strVal:date checked
     * @return       boolean true if date is valid
     */
    static public boolean isValidTime(String strVal)
    {
        if( !isNotNull(strVal) )
        {
            return false;
        }
        int iIndex1,iIndex2;
        strVal = (strVal.length()> 0 ) ? strVal.trim() : strVal;
        iIndex1 = 0;
        iIndex2 = strVal.indexOf(" ", iIndex1);
        if(iIndex2 < 0) return false;
        if(iIndex2 - 1 == strVal.length()) return false;
        String D_strVal = strVal.substring(iIndex1,iIndex2);
        String S_strVal = strVal.substring(iIndex2+1,strVal.length());
        if(isValidDate(D_strVal)){
            if(isValidHour(S_strVal)){
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }
    }
    /**
     * Check the date is valid date ( YYYY/MM/DD HH:MM:DD ) or not
     *
     * @param        String strVal:date checked
     * @return       boolean true if date is valid
     */
    static public boolean isValidHour(String strVal)
    {
        if( !isNotNull(strVal) )
        {
            return false;
        }

        if( !isLong( delCharFromString(strVal, ':') ) )
        {
            return false;
        }

        int iIndex1,iIndex2;

        iIndex1 = strVal.indexOf(":");
        iIndex2 = strVal.indexOf(":", iIndex1+1);

        if( iIndex1 == -1 || iIndex1 == iIndex2 || iIndex2 != strVal.lastIndexOf(":") )
        {
            return false;
        }
        int iHH, iMM , iDD;
        try
        {
            iHH   = Integer.parseInt( strVal.substring(0, iIndex1) );
            iMM   = Integer.parseInt( strVal.substring(iIndex1 + 1, iIndex2) );
            iDD   = Integer.parseInt( strVal.substring(iIndex2 + 1) );
            /**
             * If the Hour is valid
             */
            if (  iHH >  24 || iHH < 0  )
            {
                return false;
            }

            /**
             * If the MM is valid
             */
            if ( iMM < 0 || iMM >= 60 )
            {
                return false;
            }
            /**
             * If the DD is valid
             */
            if ( iDD < 0 || iDD >= 60 )
            {
                return false;
            }
            return true;
        }
        catch(Exception e)
        {
            return false;
        }

    }
    /**
     * Check the date is valid date ( YYYY/MM/DD HH:MM:DD.fffffffff ) or not
     *
     * @param        String strVal:date checked
     * @return       boolean true if date is valid
     */
    static public boolean isValidTimeStamp(String strVal)
    {
        if( !isNotNull(strVal) )
        {
            return false;
        }
        int iIndex1,iIndex2;
        strVal = (strVal.length()> 0 ) ? strVal.trim() : strVal;
        iIndex1 = 0;
        iIndex2 = strVal.indexOf(".", iIndex1);
        if(iIndex2 < 0) return false;
        if(iIndex2 - 1 == strVal.length()) return false;
        String D_strVal = strVal.substring(iIndex1,iIndex2);
        String F_strVal = strVal.substring(iIndex2+1,strVal.length());
        if(isValidTime(D_strVal)){
            if(isValidFloat(F_strVal)){
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }
    }
    /**
     * Check the date is valid date ( YYYY/MM/DD HH:MM:DD.FFFFFFFFF ) or not
     *
     * @param        String strVal:date checked
     * @return       boolean true if date is valid
     */
    static public boolean isValidFloat(String strVal)
    {
        strVal = (strVal.length()> 0 ) ? strVal.trim() : strVal;
        if(strVal.length() != 9 ) return false;
        if(!isHalfNum(strVal)) return false;
        return true;
    }
    /**
     * Check the year is Leap Year or not
     *
     * @param        int iYear:the year's int value
     * @return       boolean true if the year is the LeapYear
     */
    public static boolean isLeapYear(int iYear)
    {

        boolean bRet = false;

        if( 0 == ( iYear % 100 ) )
        {
            if( 0 == (iYear % 400) )
            {
                bRet = true;
            }
        }
        else
        {
            if( 0 == (iYear % 4) )
            {
                bRet = true;
            }
        }

        return bRet;

    }

    /**
     * Check number range
     *
     * @param        String strData:data checked
     * @param        long lMinNumber:the min data allowed
     * @param        long lMaxNumber:the max data allowed
     * @return       boolean   true if the date is in the special range
     */
    public static boolean chkNumberRange(String strData, long lMinNumber , long lMaxNumber)
    {
        long lTemp = 0;

        if(!isNotNull(strData))
        {
            return false;
        }

        if( isLong(strData) == false )
            return false;

        lTemp = Long.parseLong(strData);

        if( lTemp < lMinNumber || lTemp > lMaxNumber )
        {
            return false;
        }

        return true;

    }

    /**
     * Check string length range
     *
     * @param        String strVal:data checked
     * @param        int iMin:the min length allowed
     * @param        int iMax:the max length allowed
     * @return       boolean   true if the data'length is in this range
     */
    static public boolean CheckStrRange(String strVal,int iMin,int iMax )
    {
        if(!isNotNull(strVal))
        {
            return false;
        }

        int iLength = getByteLength(strVal);

        if ( iLength > iMax || iLength <iMin)
            return false;

        return true;
    }

    /**
     * Check string length
     *
     * @param        String strVal:data checked
     * @param        int iMaxLength:the length of data allowed
     * @return       boolean true if the data'length is  this length
     */
    static public boolean CheckStrLength(String strVal,int iMaxLength)
    {
        if(!isNotNull(strVal))
        {
            return false;
        }

        int iLength = getByteLength(strVal);

        if (iLength != iMaxLength)
            return false;

        return true;
    }

    /**
     * Check length range
     *
     * @param        String strVal:data checked
     * @param        int iMaxLength:the max length of data allowed
     * @return       boolean   true if the data'length is less than or equal to this length
     */
    static public boolean CheckStrMaxLen(String strVal,int iMaxLength)
    {
        if(!isNotNull(strVal))
        {
            return false;
        }

        int iLength = getByteLength(strVal);

        if (iLength > iMaxLength)
            return false;

        return true;
    }

    /**
     * Check length range
     *
     * @param        String strVal:data checked
     * @param        int iMinLength:the min length of data allowed
     * @return       boolean   true if the data'length is bigger than or equal to this length
     */
    static public boolean CheckStrMinLen(String strVal,int iMinLength)
    {
        if(!isNotNull(strVal))
        {
            return false;
        }

        int iLenght = getByteLength(strVal);

        if (iLenght < iMinLength)
            return false;

        return true;
    }

    /**
     * Check the string is fullchar or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it is fullchar
     */
    static public boolean isOnlyFullChar(String strVal)
    {
        String strValue = null;
        char[] cTempArray;
        int iLen = 0;

        if (!isNotNull(strVal))
        {
            return false;
        }

        strValue = strVal;
        iLen = strValue.length();
        cTempArray = new char[iLen];
        strValue.getChars(0, iLen , cTempArray, 0);

        for(int iLoop=0 ; iLoop < iLen ; iLoop++)
        {
            char cTarget = cTempArray[iLoop];
            if ((cTarget >= 0xFF64 && cTarget <= 0xFF9F ) ||
                    (cTarget <= 0xFF))
            {
                return false;
            }
        }

        return true;
    }

    /**
     * Check the string is halfchar or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it is halfchar
     */
    static public boolean isOnlyHalfChar(String strVal)
    {
        String strValue = null;
        char[] cTempArray;
        int iLen = 0;

        if (!isNotNull(strVal))
        {
            return false;
        }

        strValue = strVal;

        iLen = strValue.length();
        cTempArray = new char[iLen];
        strValue.getChars(0, iLen , cTempArray, 0);

        for(int iLoop=0 ; iLoop < iLen ; iLoop++)
        {
            char cTarget = cTempArray[iLoop];
            if (!(((cTarget >= 0xFF64 && cTarget <= 0xFF9F ) ||
                    (cTarget <= 0xFF))))
            {
                return false;
            }
        }
        return true;
    }

    /**
     * Check the string is halfkana or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it is halfkana
     */
    static public boolean isHalfKana(String strVal)
    {
        String strValue = null;
        char[] cTempArray;
        int iLen = 0;

        if (!isNotNull(strVal))
        {
            return false;
        }

        strValue = strVal;
        iLen = strValue.length();
        cTempArray = new char[iLen];
        strValue.getChars(0, iLen , cTempArray, 0);

        for(int iLoop=0 ; iLoop < iLen ; iLoop++)
        {
            char cTarget = cTempArray[iLoop];
            if (cTarget < 0xFF64|| cTarget > 0xFF9F )
                return false;
        }

        return true;
    }

    /**
     * Check the string is fullkana or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it is fullkana
     */
    static public boolean isFullKana(String strVal)
    {
        String strValue = null;
        char[] cTempArray;
        int iLen = 0;

        if (!isNotNull(strVal))
        {
            return false;
        }

        strValue = strVal;
        iLen = strValue.length();
        cTempArray = new char[iLen];
        strValue.getChars(0, iLen , cTempArray, 0);

        for(int iLoop=0 ; iLoop < iLen ; iLoop++)
        {
            char cTarget = cTempArray[iLoop];
            if (((cTarget < 0x30A1)||(cTarget > 0x30FE)) &&
                    ((cTarget < 0x3041)||(cTarget > 0x309E)))
                return false;
        }

        return true;
    }

    /**
     * Check the string is full Hiragana or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it is full Hiragana
     */
    static public boolean isFullHiragana(String strVal)
    {
        String strValue = null;
        char[] cTempArray;
        int iLen = 0;

        if (!isNotNull(strVal))
        {
            return false;
        }

        strValue = strVal;
        iLen = strValue.length();
        cTempArray = new char[iLen];
        strValue.getChars(0, iLen , cTempArray, 0);

        for(int iLoop=0 ; iLoop < iLen ; iLoop++)
        {
            char cTarget = cTempArray[iLoop];
            if ((cTarget < 0x3041)||(cTarget > 0x309E))
                return false;
        }

        return true;
    }

    /**
     * Check the string is full katakana or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it is full katakana
     */
    static public boolean isFullKataKana(String strVal)
    {
        String strValue = null;
        char[] cTempArray;
        int iLen = 0;

        if (!isNotNull(strVal))
        {
            return false;
        }

        strValue = strVal;
        iLen = strValue.length();
        cTempArray = new char[iLen];
        strValue.getChars(0, iLen , cTempArray, 0);

        for(int iLoop=0 ; iLoop < iLen ; iLoop++)
        {
            char cTarget = cTempArray[iLoop];
            if ((cTarget < 0x30A1)||(cTarget > 0x30FE))
                return false;
        }

        return true;
    }

    /**
     * Check the string is hanzi or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it is Hanzi
     */
    static public boolean isHanZi(String strVal)
    {
        String strValue = null;
        char[] cTempArray;
        int iLen = 0;

        if (!isNotNull(strVal))
        {
            return false;
        }

        strValue = strVal;
        iLen = strValue.length();
        cTempArray = new char[iLen];
        strValue.getChars(0, iLen , cTempArray, 0);

        for(int iLoop=0 ; iLoop < iLen ; iLoop++)
        {
            char cTarget = cTempArray[iLoop];
            if (!(((cTarget <= 0x4DB5) && (cTarget >= 0x3400)) ||
                    ((cTarget <= 0x9FFF) && (cTarget >= 0x4E00)) ||
                    ((cTarget <= 0xFAFF) && (cTarget >= 0xF900))))
                return false;
        }

        return true;
    }

    /**
     * Check the string is full alpha or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it is full alpha
     */
    static public boolean isFullAlpha( String strVal )
    {
        String strValue = null;
        char[] cTempArray;
        int iLen = 0;

        if (!isNotNull(strVal))
        {
            return false;
        }

        strValue = strVal;
        iLen = strValue.length();
        cTempArray = new char[iLen];
        strValue.getChars(0, iLen , cTempArray, 0);

        for(int iLoop=0 ; iLoop < iLen ; iLoop++)
        {
            char cTarget = cTempArray[iLoop];
            if (!((cTarget <= 0xFF3A) && (cTarget >= 0xFF21)) ||
                    ((cTarget <= 0xFF5A) && (cTarget >= 0xFF41)))
            {
                return false;
            }
        }

        return true;
    }

    /**
     * Check data form must be NNN-NNNN(N: 0-9)
     *
     * @param        String strVal:data checked
     * @return       boolean true if it's form is NNN-NNNN
     */
    static public  boolean chkZipCode(String strVal)
    {
        if (!isNotNull(strVal))
        {
            return false;
        }

        /*
        int iLength = getByteLength( strVal );
        if(iLength != 8)
        {
            return false;
        }

        if(!(strVal.substring(3,4).equals("-")))
        {
            return false;
        }

        if( !isLong(strVal.substring(0, 3)) || !isLong(strVal.substring(4, 8)) )
        {
            return false;
        }
        */
        if( !isLong(strVal) )
        {
            return false;
        }

        return true;
    }

    /**
     * Check telephone
     *
     * @param        String strVal:data checked
     * @return       boolean true if only contain N(0-9), "-"
     */
    static public  boolean chkTelephone(String strVal)
    {
        if (!isNotNull(strVal))
        {
            return false;
        }

        for(int iLoop = 0; iLoop < strVal.length(); iLoop++)
        {
            char cTemp = strVal.charAt(iLoop);
            if( !((cTemp == '-') || ((cTemp >= 0x30) && (cTemp <= 0x39))) )
                return false;
        }

        return true;
    }

    /**
     * Check char in data  must be  a-z , A-Z  or 0-9
     *
     * @param        String strVal:data checked
     * @return       boolean true if Char in data  is in  a-z , A-Z  or 0-9
     */
    static public  boolean chkAlphaNum(String strVal)
    {
        if (!isNotNull(strVal))
        {
            return false;
        }

        for(int iLoop = 0; iLoop < strVal.length(); iLoop++)
        {
            char cTemp = strVal.charAt(iLoop);
            if(!(((cTemp >= 0x41) && (cTemp <= 0x5A)) ||
                    ((cTemp >= 0x61) && (cTemp <= 0x7A)) ||
                    ((cTemp >= 0x30) && (cTemp <= 0x39))))
                return false;
        }

        return true;
    }

    /**
     * Check the string is half numbers 0-9 or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if Char in data  is in 0-9
     */
    static public  boolean isHalfNum(String strVal)
    {
        if (!isNotNull(strVal))
        {
            return false;
        }

        for(int iLoop = 0; iLoop < strVal.length(); iLoop++)
        {
            char cTemp = strVal.charAt(iLoop);
            if(cTemp < 0x30 || cTemp > 0x39)
                return false;
        }

        return true;
    }

    /**
     * Check it is Email or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it is Email
     */
    static public  boolean chkEmail(String strVal)
    {
        if (!isNotNull(strVal))
        {
            return false;
        }

        String strTemp2 = strVal;
        String strTemp3 = "";
        String strTemp = new String( strVal );

        delCharFromString(strTemp,'@');
        delCharFromString(strTemp,'.');

        strTemp3 = strTemp.toString();

        if( CheckMethod.isOnlyHalfChar(strVal) == false )
            return false;
        else
        {
            int iIndex1 = 0;
            int iIndex2 = 0;
            iIndex1 = strTemp2.indexOf("@");
            iIndex2 = strTemp2.lastIndexOf("@");
            if( iIndex1 == -1 || iIndex1 != iIndex2 )
                return false;

            iIndex1 = strTemp2.indexOf(".");
            if( iIndex1 < 0 )
                return false;
        }

        return true;
    }

    /**
     * Check data contains '@' or not
     *
     * @param        String strVal:data checked
     * @return       boolean true if it doesn't contain '@'
     */
    static public  boolean chkDomain(String strVal)
    {
        if (!isNotNull(strVal))
        {
            return false;
        }

        for(int iLoop = 0; iLoop < strVal.length(); iLoop++)
        {
            char cTemp = strVal.charAt(iLoop);
            if(cTemp == '@')
            {
                return false;
            }
        }

        return true;
    }

    /**
     * Convert halfchar to fullchar
     *
     * @param        String strVal:data that will be converted
     * @return       String if succeed ,return converted data; else return old data
     */
    static public  String HalfchartoWide(String strVal)
    {
        // voice sound katakana array
        final char kataKanaofVoicedArray[] = {'?','?','?','?','?',
                '?','?','?','?','?',
                '?','?','?','?','?',
                '?','?','?','?','?'};

        // half voice sound katakana array
        final char kataKanaofHalfVoicedArray[] = {'?','?','?','?','?'};

        // katakana array
        final char katakanaArray[] =       {'?','?','?','?','?',
                '?','?','?','?','?',
                '?','?','?','?','?',
                '?','?','?','?','?',
                '?','?','?','?','?',
                '?','?','?','?','?',
                '?','?','?','?','?',
                '?','?','?','?','?',
                '?','?','?','?','?'};

        String strResult = null;
        char[] cTempArray;
        int iLen = 0;
        int iRise = 0;  //index of new string converted

        if (!isNotNull(strVal))
        {
            return strVal;
        }

        strResult = strVal;

        try
        {
            iLen = strResult.length();
            cTempArray = new char[iLen];
            strResult.getChars(0, iLen , cTempArray, 0);

            //convert voiced sound and half voiced sound from half to full
            for(int iLoop=0 ; iLoop < iLen ; iLoop++)
            {
                // for voiced sound
                if(cTempArray[iLoop] == 0xFF9E)
                {
                    //for ¶Þ to ÄÞ
                    if(cTempArray[iLoop-1] >= 0xFF76 && cTempArray[iLoop-1] <=0xFF84)
                    {
                        cTempArray[iLoop-1] = kataKanaofVoicedArray[cTempArray[iLoop-1]-0xFF76];
                    }
                    //for ÊÞ to ÎÞ
                    if(cTempArray[iLoop-1] >= 0xFF8A && cTempArray[iLoop-1] <=0xFF8E)
                    {
                        cTempArray[iLoop-1] = kataKanaofVoicedArray[cTempArray[iLoop-1]-0xFF8A + 15];
                    }
                }
                //for half voiced sound
                if(cTempArray[iLoop] == 0xFF9F)
                {
                    if(cTempArray[iLoop-1] >= 0xFF8A && cTempArray[iLoop-1] <=0xFF8E)
                    {
                        cTempArray[iLoop-1] = kataKanaofHalfVoicedArray[cTempArray[iLoop-1]-0xFF8A];
                    }
                }
            }

            //convert all from half to full
            for(int iLoop=0 ; iLoop < iLen ; iLoop++,iRise++)
            {
                char cTarget = cTempArray[iLoop];
                // for ASCII
                if(cTarget < 0x7F)
                {
                    cTempArray[iRise] = (char)((int)cTarget + 0xFEE0);
                }
                // for ????
                else if (cTarget >= 0xFF64 && cTarget <= 0xFF9F )
                {
                    //for "\uFFFD to "\uFFFD
                    if(cTarget >= 0xFF71 && cTarget <= 0xFF9D)
                    {
                        cTempArray[iRise] = katakanaArray[cTarget - 0xFF71];
                    }
                    // for "\uFFFD and "\uFFFD
                    else if(cTarget == 0xFF9E || cTarget == 0xFF9F)
                    {
                        iRise--;
                    }
                    // for the others , for example "\uFFFD,"?","?" and so on
                    else
                    {
                        switch(cTarget)
                        {
                            case 0xFF64: //"\uFFFD
                            {
                                cTempArray[iRise] = '?' ;
                                break;
                            }
                            case 0xFF65:  //"?"
                            {
                                cTempArray[iRise] = '?';
                                break;
                            }
                            case 0xFF70: //"?"
                            {
                                cTempArray[iRise] = '?' ;
                                break;
                            }
                            default:
                            {
                                cTempArray[iRise] = cTarget ;
                            }
                        }
                    }
                }
                // for the other
                else
                {
                    cTempArray[iRise] = cTarget ;
                }
            }

            if(iRise < iLen)
            {
                cTempArray[iRise] = 0 ;
            }

            strResult = new String(cTempArray);
        }
        catch(Exception e)
        {
            return strVal;
        }
        return strResult;
    }

    /**
     * get String's byte length
     *
     * @param  String strVal:the string value
     * @return int    byte length
     */
    public static int getByteLength( String strVal )
    {
        if( strVal == null || strVal.equals("") )
            return 0;
        byte[] bByteArray = strVal.getBytes();
        return bByteArray.length;
    }

    /**
     * check if image file is JPG and JIF file type
     *
     * @param   String strVal:the Full file path
     * @return  boolean true if is the valid file type
     */
    public static boolean isValidImageType( String strVal )
    {
        if( strVal.equals("") )
            return true;
        int nIndex = strVal.lastIndexOf(".");
        if( nIndex < 0 )
            return false;
        String strTemp = strVal.substring(nIndex+1, strVal.length()).toUpperCase();
        if( strTemp.equals("JPG") || strTemp.equals("GIF") )
            return true;
        else
            return false;
    }

    /**
     * check if image file full path is valid
     *
     * @param   String strVal:Full file path
     * @return  boolean true if is the valid file path
     */
    public static boolean isValidImagePath( String strVal )
    {
        if( strVal.equals("") )
            return true;

        for(int iLoop = 0; iLoop < strVal.length(); iLoop++)
        {
            char cTemp = strVal.charAt(iLoop);
            if( cTemp=='/' || cTemp=='\\' || cTemp==':' || cTemp==',' || cTemp==';' || cTemp=='*' || cTemp=='?' || cTemp=='<' || cTemp=='>' || cTemp=='|' )
                return false;
        }

        if( getByteLength( strVal ) > 64 )
            return false;
        return true;
    }

    /**
     * check if filename is valid
     *
     * @param   String strValue:Full file path
     * @return  boolean true if filename is valid
     */
    public static boolean isValidFileName(String strValue)
    {
        if (!isNotNull(strValue))
        {
            return false;
        }

        for(int iLoop = 0; iLoop < strValue.length(); iLoop++)
        {
            char cTemp = strValue.charAt(iLoop);
            if( cTemp=='/' || cTemp=='\\' || cTemp==':' || cTemp==',' || cTemp==';' || cTemp=='*' || cTemp=='?' || cTemp=='<' || cTemp=='>' || cTemp=='|' )
                return false;
        }

        return true;
    }

    /**
     * check user custom type
     *
     * @param   String strValue:check data
     * @param   String strTemplate:user custom template
     * @return  boolean true if check passed
     */
    public static boolean checkCustom(String strValue, String strTemplate)
    {
        boolean bResult = true;

        return bResult;
    }
    public static String addEnter(String strValue,int maxLength)
    {
        int cLength = 0;
        String returnStr ="";
        for(int m = 0;m<strValue.length();m++){
            String curStrValue = strValue.substring(m,m+1);
            if(CheckMethod.getByteLength(curStrValue) == 2){
                cLength = cLength + 2;
            }else{
                cLength = cLength + 1;
            }
            if(cLength > maxLength){
                returnStr = returnStr +"\n"+curStrValue;
                cLength = CheckMethod.getByteLength(curStrValue);
            }else{
                returnStr = returnStr + curStrValue;
            }
        }
        return returnStr;
    }
}
