Package com.adito.core

Examples of com.adito.core.CoreException


    private static void validate(String value) throws CoreException {
        int indexOf = value.indexOf(":");
        if (indexOf == -1) {
            if (!isHostNameValid(value)) {
                throw new CoreException(ErrorConstants.ERR_STRING_ISNT_IP_ADDRESS, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value);
            }
        } else {
            String hostName = value.substring(0, indexOf);
            String port = value.substring(indexOf + 1);
            if (!isHostNameValid(hostName) || !isPortValid(port)) {
                throw new CoreException(ErrorConstants.ERR_STRING_ISNT_IP_ADDRESS, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value);
            }
        }
    }
View Full Code Here


                try {
                    ServerSocket socket = new ServerSocket(portInt);
                    socket.close();
                } catch (Exception e) {
                    log.error("Failed to open server socket.", e);
                    throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR, ErrorConstants.CATEGORY_NAME,
                                    ErrorConstants.BUNDLE_NAME, e, value);
                }
            }
        }
    }
View Full Code Here

    try {
      if (properties != null && properties.containsKey("minLength"))
        min = Integer.parseInt(properties.getProperty("minLength"));
    } catch (NumberFormatException nfe) {
      log.error("Failed to get minimum value for validator.", nfe);
      throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR,
              ErrorConstants.CATEGORY_NAME,
              ErrorConstants.BUNDLE_NAME,
              null,
              value);
    }
    int max = maxLength;
    try {
      if (properties != null && properties.containsKey("maxLength"))
        max = Integer.parseInt(properties.getProperty("maxLength"));
    } catch (NumberFormatException nfe) {
      log.error("Failed to get maximum value for validator.", nfe);
      throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR,
              ErrorConstants.CATEGORY_NAME,
              ErrorConstants.BUNDLE_NAME,
              null,
              value);
    }

    // Validate
    if (value.length() < min) {
      throw new CoreException(ErrorConstants.ERR_STRING_TOO_SHORT,
              ErrorConstants.CATEGORY_NAME,
              ErrorConstants.BUNDLE_NAME,
              null,
              String.valueOf(min),
              String.valueOf(max),
              value,
              null);
    }
    if (value.length() > max) {
      throw new CoreException(ErrorConstants.ERR_STRING_TOO_LONG,
              ErrorConstants.CATEGORY_NAME,
              ErrorConstants.BUNDLE_NAME,
              null,
              String.valueOf(min),
              String.valueOf(max),
              value,
              null);
    }

    // Regular expression
    String regExp = properties == null ? this.regExp : Util.trimmedOrBlank(properties.getProperty("regExp", this.regExp));
    if (regExp != null && !regExp.equals("") && !value.matches(regExp)) {
      throw new CoreException(regExpErrCode,
              ErrorConstants.CATEGORY_NAME,
              ErrorConstants.BUNDLE_NAME,
              null,
              String.valueOf(regExp),
              value,
              null,
              null);

    }

    // Simple pattern
    String pattern = Util.trimmedOrBlank(properties == null ? this.pattern : properties.getProperty("pattern", this.pattern));
    if (!pattern.equals("")) {
      pattern = Util.parseSimplePatternToRegExp(pattern);
      if(!value.matches(pattern)) {
        throw new CoreException(ErrorConstants.ERR_STRING_DOESNT_MATCH_SIMPLE_PATTERN,
                ErrorConstants.CATEGORY_NAME,
                ErrorConstants.BUNDLE_NAME,
                null,
                String.valueOf(pattern),
                value,
View Full Code Here

            if(properties != null && properties.containsKey("minValue"))
                min = Integer.parseInt(properties.getProperty("minValue"));
        }
        catch(NumberFormatException nfe) {
            log.error("Failed to get minimum value for validator.", nfe);
            throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value);
        }
        int max = defaultMax;
        try {
            if(properties != null && properties.containsKey("maxValue"))
                max = Integer.parseInt(properties.getProperty("maxValue"));
        }
        catch(NumberFormatException nfe) {
            log.error("Failed to get maximum value for validator.", nfe);
            throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value);
        }

      /* We may support replacement variables so
       * to validate we must replace with the minimum value
       */      
      if(properties != null && "true".equalsIgnoreCase(properties.getProperty("replacementVariables"))) {
        Replacer r = new Replacer() {
        public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
          return replacementPattern;
        }       
        };
        ReplacementEngine re = new ReplacementEngine();
        re.addPattern(VariableReplacement.VARIABLE_PATTERN, r, String.valueOf(min));
        value = re.replace(value);
      }
       
        // Validate
        try {
            int i  = Integer.parseInt(value);
            if(i < min || i > max) {
                throw new CoreException(ErrorConstants.ERR_INTEGER_OUT_OF_RANGE, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, String.valueOf(min), String.valueOf(max), value, null);               
            }
        }
        catch(NumberFormatException nfe) {
            throw new CoreException(ErrorConstants.ERR_NOT_AN_INTEGER, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, String.valueOf(min), String.valueOf(max), value, null);
        }
    }
View Full Code Here

    }
   
    private static void assertIsAscii (String value) throws CodedException {
        try {
            if (!value.equals(URLEncoder.encode(value, UTF_8))) {
                throw new CoreException(ErrorConstants.ERR_STRING_NON_ASCII, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value);
            }
        } catch (UnsupportedEncodingException e) {
            // ignore, this just isn't going to happen
        }
    }
View Full Code Here

            if(properties != null && properties.containsKey("minValue"))
                min = Integer.parseInt(properties.getProperty("minValue"));
        }
        catch(NumberFormatException nfe) {
            log.error("Failed to get minimum value for validator.", nfe);
            throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value);
        }
        int max = defaultMax;
        try {
            if(properties != null && properties.containsKey("maxValue"))
                max = Integer.parseInt(properties.getProperty("maxValue"));
        }
        catch(NumberFormatException nfe) {
            log.error("Failed to get maximum value for validator.", nfe);
            throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value);
        }

      /* We may support replacement variables so
       * to validate we must replace with the minimum value
       */      
      if(properties != null && "true".equalsIgnoreCase(properties.getProperty("replacementVariables"))) {
        Replacer r = new Replacer() {
        public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
          return replacementPattern;
        }       
        };
        ReplacementEngine re = new ReplacementEngine();
        re.addPattern(VariableReplacement.VARIABLE_PATTERN, r, String.valueOf(min));
        value = re.replace(value);
      }
       
        // Validate
        try {
            int i  = Integer.parseInt(value);
            if(i < min || i > max) {
                throw new CoreException(ErrorConstants.ERR_INTEGER_OUT_OF_RANGE, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, String.valueOf(min), String.valueOf(max), value, null);               
            }
        }
        catch(NumberFormatException nfe) {
            throw new CoreException(ErrorConstants.ERR_NOT_AN_INTEGER, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, String.valueOf(min), String.valueOf(max), value, null);
        }
    }
View Full Code Here

    private static final String COMMON_NAME = "cn=";
    private static final String ORGANISATIONAL_UNIT = "ou=";
   
    public void validate(PropertyDefinition definition, String value, Properties properties) throws CodedException {
        if (!startsWith(value, COMMON_NAME) && !startsWith(value, ORGANISATIONAL_UNIT)) {
            throw new CoreException(ErrorConstants.ERR_STRING_NON_DN, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value);
        }
    }
View Full Code Here

    @Override
    public void validate(PropertyDefinition definition, String value, Properties properties) throws CodedException {
        super.validate(definition, value, properties);
        if (!isIpAddressExpressionValid(value)) {
            throw new CoreException(ErrorConstants.ERR_STRING_ISNT_IP_ADDRESS, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value);
        }
    }
View Full Code Here

    catch(CoreException ce) {
      throw ce;
    }
    catch(Exception e) {
            log.error("Invalid or missing class name", e);
            throw new CoreException(ErrorConstants.ERR_INTERNAL_ERROR, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value);
    }
  }
View Full Code Here

   */
  public void validate(PropertyDefinition definition, String value, Properties properties) throws CodedException {
    try {
      super.validate(definition, value, properties);
    } catch (CoreException ce) {
      throw new CoreException(ErrorConstants.ERR_EMPTY_THEME,
              ErrorConstants.CATEGORY_NAME,
              ErrorConstants.BUNDLE_NAME,
              null,
              value,
              PropertyClassManager.getInstance()
                      .getPropertyClass(ProfileProperties.NAME)
                      .getDefinition("ui.theme")
                      .getDefaultValue(),
              null,
              null);
    }
    File themeDirectory = new File(new File("webapp"), value.replace('/', File.separatorChar).replace('\\', File.separatorChar));
    if (!themeDirectory.isDirectory()) {
      throw new CoreException(ErrorConstants.ERR_INVALID_THEME,
              ErrorConstants.CATEGORY_NAME,
              ErrorConstants.BUNDLE_NAME,
              null,
              value);
    }
View Full Code Here

TOP

Related Classes of com.adito.core.CoreException

Copyright © 2018 www.massapicom. 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.