onMessageAdded()

onMessageAdded()

This function is called AFTER a message has been successfully added (and has passed all the checks for addition/acceptance). The message itself cannot be changed here. (New v11.9942)

$oma_message.id - the message ID

$oma_message.category - the message category (or an empty string if there is no message category)

$oma_message.charloc - the character location on the line (or -1 if not available or not applicable)

$oma_message.charloclength - how many characters after the character location is relevant to the message (or -1 if not available or not applicable)

$oma_message.lineloc - the line location (or -1 if not available or not applicable)

$oma_message.sourcehighlight - the portion of the source line that is highlighted when using the editor

$oma_message.subtypetext - the message subtype (as text), like one of the following: "Accessibility", "CSS", "JSLint", "PHP", etc. (an empty string if not available)

$oma_message.text - the message text (with flags in square brackets removed)

$oma_message.typeid - the message type (as a number)

$oma_message.typetext - the message type (as text), one of the following: "ERROR", "WARNING", "MESSAGE", or "COMMENT"

$oma_message.wcag2conflevel1, $oma_message.wcag2criterion1, $oma_message.wcag2technique1 - the WCAG conformance level, criterion, and technique information extracted from the first WCAG 2.0 info block in square brackets (like "[AAA, 3.2.5; H83]"), if available, else an empty string.

$oma_message.wcag2conflevel2, $oma_message.wcag2criterion2, $oma_message.wcag2technique2 - the WCAG conformance level, criterion, and technique information extracted from the second WCAG 2.0 info block in square brackets (like "[AAA, 3.2.5; H83]"), if available, else an empty string.

NOTE: To prevent recursion problems, any additional messages generated in this function do not cause another call to onMessageAdded().

Example 1:

These functions create a CSV (comma separated values) file by adding each message to the $csvfilearray array and then appending it to a file at the end of the validation.

Values that may contain commas are enclosed in double quotes, and when doing so, double quote characters in the values are changed to two double quote characters using replaceStringCase().

function onMessageAdded() {
 $csvfilearray[]=
  '"'+getValueString(5)+'",'
  +$oma_message.typetext+','
  +$oma_message.subtypetext+','
  +$oma_message.lineloc+','
  +$oma_message.charloc+','
  +$oma_message.id+',"'
  +replaceStringCase($oma_message.text,'"','""')+'","'
  +replaceStringCase($oma_message.sourcehighlight,'"','""')+'","'
  +replaceStringCase(getSourceLine($oma_message.lineloc),'"','""')+'"';
}
 
function onEndedValidation() {
 writeFile('T:\validation_output.csv','csvfilearray',1); // append
}

Example 2:

This builds upon the previous example, showing code that you can use to alter the message text if you feel that it should be changed.

function onMessageAdded() {
 // change the message text of a message with a given ID
 if $oma_message.id==2012030805 {
  $oma_message.text='A scripting attribute has been used but a default scripting language has not been defined.';
 }
 
 // simply cut the end off any messages greater than 100 characters
 if $oma_message.text.stringLength()>100 {
  $oma_message.text=getMidString($oma_message.text,0,100)+'...'; // chop message
 }
 
 ...
 the rest of the code from the previous example goes here
 ...
}