Examples of BadInputException


Examples of net.naijatek.myalumni.framework.exceptions.BadInputException

    }


    public static void checkGoodEmail(final String input) throws BadInputException {
        if (input == null) {
      throw new BadInputException("Sorry, null string is not a good email.");
    }
        int atIndex = input.indexOf('@');
        int dotIndex = input.lastIndexOf('.');
        if (atIndex == -1 || dotIndex == -1 || atIndex >= dotIndex) {
      throw new BadInputException("Error: '" + input + "' is not a valid email value. Please try again.");
    }
        // now check for content of the string
        byte[] s = input.getBytes();
        int length = s.length;
        byte b = 0;

        for (int i = 0; i < length; i++) {
            b = s[i];
            if (b >= 'a' && b <= 'z') {
                // lower char
            } else if (b >= 'A' && b <= 'Z') {
                // upper char
            } else if (b >= '0' && b <= '9' && i != 0) {
                // numeric char
            } else if ( ( b=='_' || b=='-' || b=='.' || b=='@' ) && i != 0 ) {
                // _ char
            } else {
                // not good char, throw an BadInputException
                throw new BadInputException(input + " is not a valid email. Reason: character '" + (char)b + "' is not accepted in an email.");
            }
        }// for

        // last check
        try {
            new javax.mail.internet.InternetAddress(input);
        } catch (Exception ex) {
            logger.error("Error when running checkGoodEmail", ex);
            throw new BadInputException("Assertion: dont want to occur in Util.checkGoodEmail");
        }
    }
View Full Code Here

Examples of net.naijatek.myalumni.framework.exceptions.BadInputException

        if (ret == null) {
          ret = "";
        }
        ret = ret.trim();
        if ( checkEmpty && ret.length() == 0 ){
          throw new BadInputException("The parameter '" + param +
              "' is not allowed to be empty! Please try again.");
        }
        return ret;
    }
View Full Code Here

Examples of net.naijatek.myalumni.framework.exceptions.BadInputException

   */
  public static String getParameterSafe(final HttpServletRequest request, final String param, final boolean checkEmpty) throws BadInputException {
        String ret = getParameter(request, param, checkEmpty);
        if ( ret.indexOf('<') != -1 ||
             ret.indexOf('>') != -1) {
            throw new BadInputException("The parameter '" + param + "' is not allowed to contain '<' or '>'! Please try again.");
        }
        return ret;
    }
View Full Code Here

Examples of net.naijatek.myalumni.framework.exceptions.BadInputException

        String inputStr = getParameter(request, param, true);
        int ret;
        try {
            ret = Integer.parseInt(inputStr);
        } catch (NumberFormatException e) {
            throw new BadInputException("Cannot parse the parameter \"" + param + "\" to an integer value!. Please try again.");
        }
        return ret;
    }
View Full Code Here

Examples of net.naijatek.myalumni.framework.exceptions.BadInputException

        }
        int ret;
        try {
            ret = Integer.parseInt(inputStr);
        } catch (NumberFormatException e) {
            throw new BadInputException("Cannot parse the parameter \"" + param + "\" to an integer value!. Please try again.");
        }
        return ret;
    }
View Full Code Here

Examples of net.naijatek.myalumni.framework.exceptions.BadInputException

        }
        int ret;
        try {
            ret = Integer.parseInt(value);
        } catch (NumberFormatException e) {
            throw new BadInputException("Cannot parse \"" + value + "\" to an integer value!. Please try again.");
        }
        return ret;
    }
View Full Code Here

Examples of net.naijatek.myalumni.framework.exceptions.BadInputException

        String inputStr = getParameter(request, param, true);
        long ret;
        try {
            ret = Long.parseLong(inputStr);
        } catch (NumberFormatException e) {
            throw new BadInputException("Cannot parse the parameter \"" + param + "\" to an long value!. Please try again.");
        }
        return ret;
    }
View Full Code Here

Examples of net.naijatek.myalumni.framework.exceptions.BadInputException

        long ret;
        try {
            ret = Long.parseLong(inputStr);
        } catch (NumberFormatException e) {
            throw new BadInputException("Cannot parse the parameter \"" + param + "\" to an long value!. Please try again.");
        }
        return ret;
    }
View Full Code Here

Examples of net.naijatek.myalumni.framework.exceptions.BadInputException

        String inputStr = getParameter(request, param, true);
        byte ret;
        try {
            ret = Byte.parseByte(inputStr);
        } catch (NumberFormatException e) {
            throw new BadInputException("Cannot parse the parameter \"" + param + "\" to an Byte value!. Please try again.");
        }
        return ret;
    }
View Full Code Here

Examples of net.naijatek.myalumni.framework.exceptions.BadInputException

        String inputStr = getParameter(request, param, true);
        double ret;
        try {
            ret = Double.parseDouble(inputStr);
        } catch (NumberFormatException e) {
            throw new BadInputException("Cannot parse the parameter \"" + param + "\" to an double value!. Please try again.");
        }
        return ret;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.