/*
Postal validation

@param data         The content of the postal letter
485017
function PostalDataValidator(data) {
  MessagingUserStatus.call(this, 'postal validator');

  if (typeof data.to === 'undefined') {
    // No to address given
    this.state.code = this.StatusCodes.MISSING;
    this.state.message = 'No "to" address given';

  } else if (typeof data.from === 'undefined') {
    // No from address given
    this.state.code = this.StatusCodes.MISSING;
    this.state.message = 'No "from" address given';

  } else if (typeof data.file === 'undefined') {
    // No file given
    this.state.code = this.StatusCodes.MISSING;
    this.state.message = 'No file given';

  } else {
    // Input data is valid
    this.state.code = this.StatusCodes.VALID;
    this.state.message = 'Ok';
  }
}
1107673
function formatPostData(data) { //, contentType
    // If it's a string, we assume it's properly encoded
    if (typeof(data) === 'string') return data;

    var queryString = [];

    for (var key in data) {
      queryString.push(
        encodeURIComponent(key) + '=' + encodeURIComponent(data[key])
      );
    }

    return queryString.join('&').replace(/\+/g, '%20');
  }
1304132
private void validateMedia(JsonNode data) throws InvalidInputException {
    for (JsonNode node : data.findParents(INDEX)) {
      JsonNode text = node.path(TEXT);
      if (!text.isMissingNode() && (!text.isArray() || !text.get(0).isArray())) {
        throw new InvalidInputException(String.format("Invalid table payload: %s (index: %s)", text.asText(), node.get(INDEX)));
      }
    }
  }
1150163
function (data) {
            // Convert string to WordArray, else assume WordArray already
            if (typeof data == 'string') {
                data = Utf8.parse(data);
            }

            // Append
            this._data.concat(data);
            this._nDataBytes += data.sigBytes;
        }
1370342
protected void validateAttachmentContentData(String receivedContent, String controlContent, String controlContentId) {
        if (ignoreAllWhitespaces) {
            controlContent = StringUtils.trimAllWhitespace(controlContent);
            receivedContent = StringUtils.trimAllWhitespace(receivedContent);
        }

        Assert.isTrue(receivedContent.equals(controlContent),
                "Values not equal for attachment content '"
                        + controlContentId + "', expected '"
                        + controlContent.trim() + "' but was '"
                        + receivedContent.trim() + "'");
    }
326664
function fixdata(data) {
		var o = '',
			l = 0,
			w = 10240;
		for (; l < data.byteLength / w; ++l)
			o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)));
		o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)));
		return o;
	}
819923
@Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        List<String> emailAddresses = EmailAddressesParser.parse(value);
        List<String> badAddresses = null;
        for (String ea : emailAddresses) {
            if (!EMAIL_VALIDATOR.isValid(ea, null)) {
                if (badAddresses == null) {
                    badAddresses = new LinkedList<String>();
                }

                badAddresses.add(ea);
            }
        }

        if (badAddresses != null) {
            context.disableDefaultConstraintViolation();
            context.buildConstraintViolationWithTemplate(MessageFormat.format(constraintAnnotation.message(),
                                                                              StringUtils.join(badAddresses, ", ")))
                   .addConstraintViolation();
        }
        return (badAddresses == null);
    }
257002
def validate(data):
    
    text = data.get('text')
    if not isinstance(text, _string_types) or len(text) == 0:
        raise ValueError('text field is required and should not be empty')

    if 'markdown' in data and not type(data['markdown']) is bool:
        raise ValueError('markdown field should be bool')

    if 'attachments' in data:
        if not isinstance(data['attachments'], (list, tuple)):
            raise ValueError('attachments field should be list or tuple')

        for attachment in data['attachments']:
            if 'text' not in attachment and 'title' not in attachment:
                raise ValueError('text or title is required in attachment')

    return True
346214
public void checkDataInnerRules(ValidationData data, Object bodyObj) {
        data.getValidationRules().stream().filter(vr -> vr.isUse()).forEach(rule -> {
            if (data.isListChild()) {
                this.checkPointListChild(data, rule, bodyObj, rule.getStandardValue());
            } else {
                this.checkPoint(data, rule, bodyObj, rule.getStandardValue());
            }
        });
    }
19572
private void validateText(String receivedMessagePayload, String controlMessagePayload) {
        if (!StringUtils.hasText(controlMessagePayload)) {
            log.debug("Skip message payload validation as no control message was defined");
            return;
        } else {
            Assert.isTrue(StringUtils.hasText(receivedMessagePayload), "Validation failed - " +
                    "expected message contents, but received empty message!");
        }

        if (!receivedMessagePayload.equals(controlMessagePayload)) {
            if (StringUtils.trimAllWhitespace(receivedMessagePayload).equals(StringUtils.trimAllWhitespace(controlMessagePayload))) {
                throw new ValidationException("Text values not equal (only whitespaces!), expected '" + controlMessagePayload + "' " +
                        "but was '" + receivedMessagePayload + "'");
            } else {
                throw new ValidationException("Text values not equal, expected '" + controlMessagePayload + "' " +
                        "but was '" + receivedMessagePayload + "'");
            }
        }
    }
311083
public function ValidateData($sFormDataName = null)
    {
        if (is_null($sFormDataName)) {
            $sFormDataName = TdbDataExtranetUser::MSG_FORM_FIELD;
        }
        $bIsValid = parent::ValidateData($sFormDataName);
        $oMsgManager = TCMSMessageManager::GetInstance();

        // check postal code for country
        $bHasCountry = (array_key_exists('data_country_id', $this->sqlData) && !empty($this->sqlData['data_country_id']));
        $bHasPostalcode = (array_key_exists('postalcode', $this->sqlData) && !empty($this->sqlData['postalcode']));
        if ($bHasCountry && $bHasPostalcode) {
            $oCountry = TdbDataCountry::GetNewInstance();
            /** @var $oCountry TdbDataCountry */
            if ($oCountry->Load($this->sqlData['data_country_id'])) {
                if (!$oCountry->IsValidPostalcode($this->sqlData['postalcode'])) {
                    $oMsgManager->AddMessage($sFormDataName.'-postalcode', 'ERROR-USER-FIELD-INVALID-POSTALCODE');
                    $bIsValid = false;
                }
            }
        }

        return $bIsValid;
    }
533820
protected void buildData(String[] data, boolean validateOnly) {

        if (data == null) {
            return;
        }

        int length = data.length;

        for (int i = 0; i < length; i++) {
            addAddressToList(data[i], validateOnly);
        }

    }
599805
@Override
  public final boolean isValid(final Object pvalue, final ConstraintValidatorContext pcontext) {
    if (pvalue == null) {
      return true;
    }
    try {
      String countryCode =
          BeanPropertyReaderUtil.getNullSaveStringProperty(pvalue, fieldCountryCode);
      final String postalCode =
          BeanPropertyReaderUtil.getNullSaveStringProperty(pvalue, fieldPostalCode);
      if (StringUtils.isEmpty(postalCode)) {
        return true;
      }

      if (allowLowerCaseCountryCode) {
        countryCode = StringUtils.upperCase(countryCode);
      }

      final String regExCheck = POSTAL_CODE_MAP.postalCodes().get(countryCode);
      if (regExCheck == null) {
        return true;
      }
      if (postalCode.matches(regExCheck)) {
        return true;
      }
      switchContext(pcontext);
      return false;
    } catch (final Exception ignore) {
      switchContext(pcontext);
      return false;
    }
  }
372716
function validateRequest (data, requestMethod) {
  if (!data.data) {
    return 'JSON API resource object must contain `data` property'
  }

  if (!data.data.type) {
    return 'JSON API resource object must contain `data.type` property'
  }

  if (['PATCH', 'PUT'].indexOf(requestMethod) > -1 && !data.data.id) {
    return 'JSON API resource object must contain `data.id` property'
  }

  return false
}
575684
private function __applyValidationRules($data)
    {
        $rule = $this->get('validator');

        return ($rule ? General::validateString($data, $rule) : true);
    }
333997
void validateAndPrepare(Message message, Address[] addresses) throws MessagingException {
        if (message.getFrom() == null || message.getFrom().length == 0) {
            fail(message, addresses, "No or empty FROM address set!");
        }
        if (addresses.length == 0) {
            fail(message, addresses, "No RECIPIENTS set!");
        }
        Address[] messageAddresses = message.getAllRecipients();
        if (messageAddresses == null) {
            for(Address address : addresses) {
                message.addRecipient(Message.RecipientType.TO, address);
            }
        } else {
            out:
            for(Address address : addresses) {
                for(Address a : messageAddresses) {
                    if (a == null) {
                        continue;
                    }
                    if (a.equals(address)) {
                        continue out;
                    }
                }
                message.addRecipient(Message.RecipientType.TO, address);
            }
        }
    }
623661
public static void removeIndexData(ValidationData data, ValidationDataIndex index) {

        String key = index.getKey(data);
        List<ValidationData> datas = index.get(key);

        if (!datas.isEmpty()) {
            datas = datas.stream().filter(d -> !d.getId().equals(data.getId())).collect(Collectors.toList());
        }
        if (datas.isEmpty()) {
            index.getMap().remove(key);
        } else {
            index.getMap().put(key, datas);
        }
    }