<commit_before># --- ValidatorSRV - Extends Validator ---

class Angles.ValidatorSRV extends Angles.Validator
  constructor: (options) ->
    super(options)
    @$validatorUrl = options.validator

    # If an ajax request to a server and a request handler are provided, set them here.
    # Otherwise use example handlers below.
    @$requestHandler = if options.requestHandler? then options.requestHandler else requestHandler
    @$validationHandler = if options.validationHandler? then options.validationHandler else validationHandler

    @dispatcher.on "validation", =>
      @dispatcher.trigger "validation:start"
      @$requestHandler @

  # Override this, or provide your own validation handler if your validator returns a different response
  requestHandler = (validator) ->
    doc = validator.$angles.getDocument()
    xmlDocument = escape(doc.getValue())
    $.ajax
      url: validator.$validatorUrl
      type: "POST"
      crossDomain: true
      processData: false
      data: "schema="+validator.$schema+"&document="+xmlDocument
      dataType: "json",
      success: (data) ->
        validator.$validationHandler validator, data
      error: (xhr, textStatus, thrownError, data) =>
        @dispatcher.trigger 'notification:clear'
        thrownError = if xhr.status == 0 then "Cannot reach server" else thrownError
        n =
          type: "Server"
          info: xhr.status
          message: thrownError
          location:
            row: 0
            column: 0
        @dispatcher.trigger 'notification:push', n

  # Override this, or provide your own validation handler if your validator returns a different response
  validationHandler = (validator, data) ->
    validator.$errors = []
    for datum in data
      validator.$errors.push
        text: datum.message
        row: datum.line-1
        column: datum.column
        type: datum.type
    validator.displayErrors()<commit_msg>better notification<commit_after># --- ValidatorSRV - Extends Validator ---

class Angles.ValidatorSRV extends Angles.Validator
  constructor: (options) ->
    super(options)
    @$validatorUrl = options.validator

    # If an ajax request to a server and a request handler are provided, set them here.
    # Otherwise use example handlers below.
    @$requestHandler = if options.requestHandler? then options.requestHandler else requestHandler
    @$validationHandler = if options.validationHandler? then options.validationHandler else validationHandler

    @dispatcher.on "validation", =>
      @dispatcher.trigger "validation:start"
      @$requestHandler @

  # Override this, or provide your own validation handler if your validator returns a different response
  requestHandler = (validator) ->
    doc = validator.$angles.getDocument()
    xmlDocument = escape(doc.getValue())
    $.ajax
      url: validator.$validatorUrl
      type: "POST"
      crossDomain: true
      processData: false
      data: "schema="+validator.$schema+"&document="+xmlDocument
      dataType: "json",
      success: (data) ->
        validator.$validationHandler validator, data
      error: (xhr, textStatus, thrownError, data) =>
        @dispatcher.trigger 'notification:clear'
        thrownError = if xhr.status == 0 then "Cannot reach server" else thrownError
        n =
          type: "Server"
          info: "Status: " + xhr.status
          message: thrownError
          location:
            row: -1
            column: -1
        @dispatcher.trigger 'notification:push', n

  # Override this, or provide your own validation handler if your validator returns a different response
  validationHandler = (validator, data) ->
    validator.$errors = []
    for datum in data
      validator.$errors.push
        text: datum.message
        row: datum.line-1
        column: datum.column
        type: datum.type
    validator.displayErrors()
{'fraction_non_alphanumeric': 0.09126263935701322, 'fraction_numerical': 0.002074150894477573, 'mean_word_length': 2.8851963746223563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4976269', 'n_tokens_mistral': 1000, 'n_tokens_neox': 1000, 'n_words': 317}