public static int parsePositiveInt(String str) {
        if (str == null || (str = str.trim()).length() == 0) {
            return 0;
        }

        int result;
        try {
            result = Integer.parseInt(str);
        } catch (NumberFormatException ex) {
            return 0;
        }
        return (result > 0) ? result : 0;
    }