Reference: Custom Audit Rule Utility Libraries
Use this reference to obtain details about the utility libraries provided by Oracle JAF. These libraries provide miscellaneous helper functions that can be useful when you write custom audit rules.
| Utility Library | Description |
|---|---|
|
DomUtils is a collection of Document Object Model (DOM) utility functions and helper functions. |
|
|
MetaLib provides Oracle JAF audit metadata access functionality that can be used in a rule. |
|
|
Utils is a collection of non-file system utility functions. |
|
|
FsUtils is a collection of file system utility functions. |
|
|
SemVerUtils is a collection of semantic version (SemVer) utility functions. |
|
|
JafLib is a library of exposed core Oracle JAF lifecycle functions. |
|
|
MsgLib is a namespace property providing access to Oracle JAF internal messaging routines. |
|
|
CssUtils is a library of CSS rule processing functions. |
|
|
AstUtils is a collection of Abstract Syntax Tree (AST) helper functions. |
|
|
SevLib is a library of helper functions that support processing severities that have been remapped via the Oracle JAF configuration property sevMap . |
|
|
TsxUtils is a library of TSX rule processing functions. |
MetaLib: JET Metadata Access Functions
MetaLib provides Oracle JAF audit metadata access functionality that can be used in a rule.
Access these Oracle JET audit metadata interface library functions through rule context object context.utils.metaLib. The methods in this library insulate your rules from changes to the format of Oracle JAF metadata. Use these methods when writing audit rules that require access to metadata.
Oracle JET Audit Metadata Interface Library Metadata Methods
The Oracle JET audit metadata interface library provides the following metadata methods.
| Method | Returns | Description |
|---|---|---|
| getTagMetadata() ( string tag ) |
Object | null |
tag is the HTML element name.
Returns the
|
| getTagPropMetadata ( string tag, string propName) |
Object | null |
tag is the HTML element name (specified with/without the surrounding chevrons). propName is the property/sub-property name.
Returns the user web component property metadata as an object from the
This is a convenience method to reduce the rule code required to check for the existence of the property. |
| getTagSlotMetadata ( string tag, string slotName) |
Object | null |
Returns the 'slot' object from the component metadata |
| getAllCustomMetadata() |
Object |
Returns an object containing all user custom component metadata. The object keys are the component names:
|
| getTagStatus ( string tag, string statusType) | Array |
Returns an array of metadata
tag is the web component name
statusType
is an optional metadata
|
| getPropStatus ( string tag, string prop, string statusType) | Array |
Returns an array of metadata
tag is the web component name prop is a component property name
statusType
is an optional metadata
|
| isTagStatus ( string tag, string statusType) | boolean |
Returns
tag is the web component name
statusType
is an optional metadata
|
Oracle JET Audit Metadata Interface Library Tag Methods
The Oracle JET audit metadata interface library provides the following tag methods.
| Method | Returns | Description |
|---|---|---|
| isWCTag( string tag) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons).
Returns
|
| isJetTag( string tag) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons).
Returns
|
| isJetLegacyTag( string tag) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons).
Returns
|
| isJetCoreTag( string tag) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons).
Returns
|
| isVComponentTag( string tag) | boolean |
tag is the element name (specified with/without the surrounding chevrons).
Returns
|
| isComponentTag( string tag) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons).
Returns
|
| isCoreTag( string tag) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons).
Returns
Deprecated in JAF 11.7.0. Use
|
| isTagDeprecated( string tag) | string | null |
tag is the HTML element name (specified with/without the surrounding chevrons). Tests a JET component for deprecated status, and returns the suggested alternative from the JET JS Doc if it is. Returns null if the element is not deprecated. |
| isTagAttrDeprecated( string tag, string attrName) |
Array. |
tag is the HTML element name. attrName is the attribute name.
Tests the web component attribute for deprecated status and returns information including a suggested alternative and the version when deprecated. Multiple entries might be returned, and each object's
Prior to JAF 3.1.0:
Tests the web component attribute for deprecated status, and returns the suggested alternative. If there is no alternative, the string is empty. Returns null if the attribute is not deprecated. If an object is returned, it will contain one or both of the properties
|
| isTagAttr( string tag, string attrName) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons). attrName is the attribute name.
Returns
|
| isTagAttrTranslatable( string tag, string attrName) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons). attrName is the attribute name.
Returns
|
| isTagAttrValue( string tag, string attrName, string value) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons). attrName is the attribute name. value is the attribute value.
Returns
|
| hasTagAttrValues( string tag, string attrName) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons). attrName is the attribute name. Returns
true
if the custom element attribute has at least one defined value, else
false
.
|
| hasTagSlot( string tag) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons). Returns
true
if the JET component supports the
slot
attribute.
|
| hasTagDefaultSlot( string tag) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons). Returns
true
if the JET component has a default slot.
|
| hasTagDynamicSlot( string tag) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons).
Returns
|
| isTagSlotName( string tag, string slotName) | boolean |
Returns
|
| getPreferredSlotContent() |
Array |
Returns the preferred content (interfaces) for a specified component
tag
and
slot
.
slot
may be defined as
""
for the default slot.
|
| getTagAttrType( string tagName, string attrName) | string | null |
tagName is the web component name (specified without the surrounding chevrons). attrName is the name of the attribute. Returns the web component element property type, for the specified attribute, from the component metadata for the property. |
| isTagSlotValue( string tag, string slotValue) | boolean |
Deprecated in JAF 3.1.0. Use
|
| isTagEvent( string tag, string attrName) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons). attrName is the attribute name.
Returns
|
| isTagSupportedInTheme( string tag ) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons).
Returns
|
| isAttrSupportedInTheme( string tag, string attrName) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons). attrName is the attribute name.
Returns
|
| isTagStyleDeprecated( string tag, string styleName) | string | null |
tag
is the HTML element name (specified with/without the surrounding chevrons).
styleName
is a
Tests the JET component
|
| isTagStyle( string tag, string styleName) | string | null |
tag
is the HTML element name (specified with/without the surrounding chevrons).
styleName
is a
Returns
|
| isStyle( string styleName) | boolean |
styleName
is a
Returns
|
| isGenStyle( string styleName) | boolean |
styleName
is a
Returns
|
| isClassStyle( string styleName) | boolean |
styleName
is a
Returns
|
| isJetStylePrefix( string styleName) | boolean |
styleName
is a
Returns
Note that
|
| hasJetStylePrefixes( ) | boolean |
styleName
is a
Returns
|
| getTagsFromStyle( string styleName) | string[] | null |
styleName
is a
Returns the JET element names using the specified style name. For example, for the style
|
| getClassesFromStyle( string styleName) | string[] | null |
styleName
is a
Returns the classes using the specified style name. For example, for the style
|
| getClassFromTag( string tagName) | string | null |
tagName is the HTML element name (specified with/without the surrounding chevrons).
Returns the class (e.g.,
|
| getTagFromClass( string className) | string | null |
className is a JET class name.
Returns the JET element name (e.g.,
|
| getClassFromModule( string module) | string | null |
module
is a specification such as
Returns the class (e.g.,
|
| getTagPropType( string tagName, string propName) | string | null |
This method is deprecated as of JAF release 7.0.0. You should now use getTagAttrType() .
tagName
is the web component name (specified without the surrounding chevrons).
propName
is the name of the property specified in the
For web components that have been inspected by JAF during startup because they are defined in the Oracle JAF configuration property components .
Returns the property type (
type
sub-property) defined for a property in the Oracle JAF
|
| getTagPropertyFromEvent( string tagName, string eventAttrName) | string | null |
Returns a property name from a tag event attribute. For example:
|
| isBindingTag( string tag) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons).
Returns
|
| isClass( ) | boolean |
Returns
|
| isClassRenamed( string className) | Object | null |
className
is a JET class name (e.g.,
Returns an object with the new name and the JET version in which it was renamed. For example:
Returns null if the class is not renamed. |
| isClassDeleted( string className) | string | null |
className
is a JET class name (e.g.,
Test if a component/class (e.g.,
|
| isClassDeprecated( string className) | string | null |
className
is a JET class name (e.g.,
Test if a component/class (e.g.,
|
| isClassMethodDeleted( string className, string methodName) | string | null |
className
is a JET class name (e.g.,
Test if a component/class (e.g.,
|
| isClassMethodDeprecated( string className, string methodName) |
Array. |
className
is a JET class (e.g.,
Tests if a JET component/class (e.g.,
Prior to JAF 3.1.0
: Tests if a component/class (e.g.,
|
| isClassMemberDeleted( string className, string memName) | string | null |
className
is a JET class name (e.g.,
Test if a component/class (e.g.,
|
| isClassMemberDeprecated( string className, string memName) |
Array. |
className
is a JET class (e.g.,
Tests if a JET component/class (e.g.,
Prior to JAF 3.1.0
: Tests if a component/class (e.g.,
|
| isClassFinal( string className) | boolean |
className
is a JET class name (e.g.,
Returns
|
| isClassMethodFinal( string className, string methodName) | boolean | null |
className
is a JET class name (e.g.,
Returns
|
| getClassMethodScope( string className, string methodName) | string | null |
className
is a JET class name (e.g.,
instance
or
static
. Returns null if the
className
or
methodName
is undefined.
|
| getDeletedMethodList() | Object |
Make a list of deleted methods as a rule helper.
Returns
|
| getDeletedMemberList() | Object |
Make a list of deleted members as a rule helper. Returns
|
| isRuleIgnored( string tag, string ruleName) | boolean |
tag is the HTML element name (specified with/without the surrounding chevrons). ruleName is the name of the rule to be tested for exclusion.
Tests if the rule is excluded for the component by its appearance in the component's optional
The method returns
|
| getRenamedClassList() | Object |
Get a list of JET classes that have been renamed. The following object is returned:
|
| getRevisionInfo() | Object |
Returns an object with the following properties:
|
| getMetaVers() | Object |
Returns an object with the following properties:
|
| getSubcomponentType() | string | Returns the component subcomponentType metadata property as a string (e.g., packPrivate , data , etc.). |
| isInterfaceImplemented() | (string tagName, string interfaceName) | Returns true if the specified interface name is implemented by the tagName component |
| getInterfaces() |
Array |
Returns an array containing the names of the interface(s) implemented by the referenced component
tagName
(e.g.,
oj-button
).
|
| getImplementers() |
Array |
Returns an array of the names of components implementing the specified interface. |
| hasJetWCInterfaces() | boolean |
Tests whether the selected JET metadata (via the config
|
| hasWCInterfaces() | boolean |
Tests whether any web components known to JAF (JET or non-JET ) have implemented interfaces. |
| getWCInterfaces() | Object |
If any web component known to JAF declares an implemented interface, an object is returned of the form:
|
| walkDomStackForOJTag( Object context [ , boolean excludeBindIf ] ) | string | null |
context is the context object passed to the rule.
Convenience method. Walks back up the DOM from the current element to see if there is a containing JET parent element. If found, the name of the JET element is returned. Optional argument
excludeBindIf
can be used to ignore
|
| getStyleOrigin() | string | Returns a code denoting if the style is a JET component style, a JET generic style class, or a non-JET user custom style. |
| isTagPackPrivate() | boolean |
Returns
true
if the web component is marked as
packPrivate
in its metadata.
|
Utils: General Non-File System Functions
Utils is a collection of non-file system utility functions.
Access these non-file system utility functions through the rule context object property context.utils.utils as an instance of a library object. They may be helpful when writing audit rules.
| Method | Returns | Description |
|---|---|---|
| hasAnyProps( Object object) | boolean |
Returns
true
if the object has any non-inherited properties
|
| isProperty( Object object, string name) | boolean |
Returns
true
if the object has the named property. The property name can be a compound dot-separated name, such as
extension.catalog.readme
.
|
| getProperty( Object object, string name) | * |
Returns the object's named property value. The property name can be a compound dot-separated name, such as
extension.catalog.readme.
|
| getType( * varName) | string |
Returns the type of a variable. This function returns a
true
type value. For example: the
typeof
operator returns
object
for an array, whereas this function returns
array. The following values can be returned (all lower-case) :
object
,
array
,
string
,
number
,
boolean
,
null
,
undefined
.
|
| isArrayContentsType ( array[] array, string type) | boolean |
Traverses an array, matching each element's type to the supplied (lower-case) type string. The
type
string can be one of the following :
object
,
array
,
string
,
number
,
boolean
,
null
, or
undefined
|
| eatWhitespace( string string, number startIndex) | number |
Traverses a string, optionally starting at the
startIndex
index, and returns the index to the first non-whitespace character. Returns
1
if no non-whitespace is found. If
startIndex
is omitted or invalid, it defaults to zero.
|
| getIndexToWhitespace( string string, number startIndex) | number |
Traverses a string, optionally starting at the
startIndex
index, and returns the index to the first whitespace character. Returns
-1
if no whitespace is found. If
startIndex
is omitted or invalid, it defaults to zero.
|
| decommentJson() | string |
Replaces the
|
| parseJson() | * | Parses a JSON string and returns the parsed object, or an error object containing a syntax error message together with supplemental position information that may be used to augment the message, if required. |
FsUtils: File System Functions
FsUtils is a collection of file system utility functions.
Access these file system utility functions through the rule context object property context.utils.fsUtils as an instance of a library object. They may be helpful when writing audit rules.
| Method | Returns | Description |
|---|---|---|
| getFileTypeSync( string filePath) | string | Error |
Checks the file at filePath and returns:
If an error occurs, an Error exception object is returned. Note if the path is a symbolic link, the file type of the link target is returned (for example, "f" or "d"). Use isSymLink() to determine if the path represents a symlink. |
| getFileExtSync( string filePath) | string | Returns the file extension for the supplied path. If the path is a symbolic link, the file extension for the link's target file is returned. If the file path cannot be accessed, an empty string is returned. |
| isSymLinkSync( string filePath) | boolean |
Returns
true
if the file path is a symbolic link, else
false. In case there is an error processing the file path,
false
is returned.
|
| pathExistsSync( string filePath) | boolean |
Returns
true
if the file path exists.
|
| fileExistsSync( string filePath [, boolean dir ] ) | boolean |
Returns
true
if file/directory exists, else
false.
|
| readFileSync( string filePath [, boolean error | Function error (string message )] | string | null |
Reads a text file and returns the contents as a string, or null if unsuccessful.
If the file read is unsuccessful, the action taken depends on optional argument
|
| readFileBufSync( string filePath[, boolean error | Function error (string message )] | Buffer | null |
Reads a text file and returns the contents as a Buffer, or null if unsuccessful.
If the file read is unsuccessful, the action taken depends on optional argument
|
| readJsonSync( string filePath[, boolean comments[, boolean | Function error ]] ) | Object | string | null |
Reads a JSON file and returns the object.
If optional argument
comments
is set to
Optional argument error can be used to indicate how errors should be handled:
Error strings are prefixed with
|
| writeJsonSync( Object obj, string filePath[, Object opts[, boolean | Function error ]] ) | boolean | string |
Writes an object to the specified file path as a JSON file, and returns
Optional object opts has the following optional properties:
Optional argument error can be used to indicate how errors should be handled:
If
error
is omitted,
|
| readDirSync( string filePath) | Array | null |
Reads a directory and returns a hierarchical array of objects of the following form:
|
| walkDirSync ( string dirPath, Function cb, [ boolean fwdSlash ]) | none |
Recursively walk a directory tree invoking a callback function with the full path to the file or sub-directory. dirPath is the initial directory path to walk. cb is a callback function that receives the following args:
Optional arg fwdSlash set to true forces the fpath string in the callback to use the forward slash in place of the Windows escaped " \\ " if found. Normally the callback function returns nothing - however it can optionally return
For example, to find all .JS files in a directory tree:
When reading the files in a directory, if a sub-directory is found, that sub-directory is examined next, and so on. |
| createFolderSync( string filePath) | boolean |
Create a folder. The file path can contain multiple folders that also need to be created. For example:
Note: folder3, folder2 and folder1 are created if they don't exist. |
| deleteFolderSync( string filePath [, boolean deleteTarget]) | none |
Deletes the contents (files/directories/sub-directories) of the directory specified by
filePath. If optional argument
deleteTarget
is specified, and is
true, the directory specified by
filePath
is also deleted.
|
| isFolderWritableSync ( string filePath ) | boolean |
Tests if a folder has write access permission. |
| getUniqueFilenameSync( string template) | string |
Returns a unique file name based on a template. All instances of the letter X are replaced. For example:
could return
|
SemVerUtils: Semantic Version Functions
SemVerUtils is a collection of semantic version (SemVer) utility functions.
Access these semantic version utility functions through the rule context object property context.utils.semVerUtils. They may be useful when writing audit rules. All method arguments are strings.
| Method | Returns | Description |
|---|---|---|
| isValid( string semver ) | boolean |
Returns
|
| isValidRange( string semver ) | boolean |
Returns
|
| satisfiesRange( string semver , string range ) | boolean |
Returns
|
| minVersion( string range ) | string | null |
Returns a major.minor.patch string representing the lowest version that can possibly match the given range. Null is returned if range is invalid.
For example:
Requires JAF version 2.9.9 or later. |
| prerelease( string semver ) | Array | null |
Returns an array of prerelease tags extracted from semver . If semver does not contain any prerelease tags (or semver is invalid), null is returned.
For example:
Requires JAF version 2.9.9 or later. |
| eq( string semver1 , string semver2 ) | boolean |
Compares two
semvers
and returns
|
| lt( string semver1 , string semver2 ) | boolean |
Compares two semvers and returns
|
| lte( string semver1 , string semver2 ) | boolean |
Compares two semvers and returns
|
| gt( string semver1 , string semver2 ) | boolean |
Compares two semvers and returns
|
| gte( string semver1 , string semver2 ) | boolean |
Compares two semvers and returns
|
| major( string semver ) | number |
Returns the major version number from the semver . |
| minor( string semver ) | number |
Returns the minor version number from the semver . |
| patch( string semver ) | number |
Returns the patch version number from the semver . |
| parse( string semver ) | Object | null |
Parses semver into an object. Null is returned if semver is invalid.
For example,
Require JAF version 2.9.9 or later. |
DomUtils: Node Object Functions
DomUtils is a collection of Document Object Model (DOM) utility functions and helper functions.
Access these DOM utility function through rule context object property context.utils.DomUtils. Most methods take a node object, which is found in context.node, and some methods require an attribute name or element name string.
| Method | Returns | Description |
|---|---|---|
| getName( Object node) | string | Returns the element name of the supplied node. |
| getType( Object node) | string |
Returns the type of the node (
tag,
directive, or
comment).
|
| getChildren( Object node) | nodes[] | Returns an array of child node objects for the supplied node. |
| getParent( Object node) | node | Returns the parent node object of the supplied node. |
| getSiblings( Object node) | nodes[] | Returns an array of sibling node objects of the supplied node. |
| getAttribs( Object node) | Object | Returns an object containing attribute name/value properties. |
| getAttribValue( Object node, string[] attrName) | string | Returns the specified attributes value. |
| hasAttrib( Object node, string attrName) | boolean |
Returns
true
if the node has the named attribute, else
false.
|
| hasChildren( Object node) | boolean |
Returns
true
if the node has children, else
false.
|
| hasNext( Object node) | boolean |
Returns
true
if there is a next node, else
false.
|
| getNext( Object node) | node | Returns the next node, else null. |
| getFirst() | node | Returns the first (i.e top) node. |
| getFirstElem() | node | Returns the first (i.e. top) tag node. |
| getLast() | node | Returns the last node. |
| getElemsByName( string elemName) | nodes[] |
Returns an array of node objects with the specified element name (such as
div).
|
| getElemById( string id) | node |
Returns the node for the element with specified
id
attribute value.
|
| getBody() | node |
Returns the
<body>
node (or null if not found).
|
| getHead() | node |
Returns the
<head>
node (or null if not found).
|
| getLinks() | node[] |
Returns an array of
<link>
tag nodes in the
<head>
section (or an empty array if none found).
|
| getScripts() | node[] |
Returns an array of
<script>
tag nodes in the
<head>
section (or an empty array if none found).
|
| getElems() | nodes[] | Returns an array of node objects for all elements. (Nodes such as text, comments, directives, etc. are ignored.) |
DomUtils also contains additional non-DOM tree helper functions that are useful when writing rules.
| Method | Returns | Description |
|---|---|---|
| extractAttribsFromDataBind( string attrValue) | Object | null |
Given a
data-bind
with an
attr
property, returns an object where each property is the name/value extracted from the
data-bind
string.
|
| extractComponentFromDataBind( string attrValue) | string | null |
Given a
data-bind
attribute value, returns the JET component name instantiated, or null if not found or not a JET component.
|
| getAttribIndex( string data, Object node, string attrName) | number | Returns the position (relative to zero) in the data of the named attribute for the node. |
| getAttribPosition( string data, Object node, string attrName) | Object |
Returns the position of the named attribute for the node in the data. The object has the following members:
This method is useful when a rule listens to tag node events but needs to report on the position of a particular tag attribute's value. This information can be applied to an
|
| getAttribValuePosition( string data, Object node, string attrName) | Object |
Returns the position of the named attribute's value in the data for the tag node. The object has the following members:
This method is useful when a rule listens to
tag
or
ojtag
events, but needs to report on a particular attribute in the tag. This information can be applied to an
|
| getLineCol( string data, number index number) | Object |
Returns the line and column for a given index into file data. The object has the following members:
|
| getComponentElems() | nodes[] | Returns an array of nodes for JET custom elements. |
| getDataBindAttrs( Object context) |
Object |
null
|
Checks the current
node
in
context
, and if it contains a
data-bind
attribute with a
attr
property, returns an object where each property is the name/value extracted from the data-bind string.
|
| getDataBindComponent( Object context) | string | null |
Checks the current
node
in
context
, and if it contains a
data-bind
attribute, extracts the JET component name if defined in the attribute value,
|
| getElemById( string id [, boolean labelId]) | Object | null |
Searches the DOM for a node with the specified
id
attribute value and returns the DOM tree node if found. If optional argument
labelId
is set to
true
, the search also includes the
label-id
attribute.
|
| hasBody( Object context) | boolean |
Returns
true
if the HTML page has a
<body>
element.
|
| isChildOfElem( string elemName, Object node) | boolean |
Returns
true
if the DOM tree node is a child of the element named
elemName
.
|
| isCommonAttr( string attrName) | boolean |
Returns
true
if the specified attribute is a standard defined xxx. (Note: if
attrName
is prefixed with '
:
', the prefix is ignored).
|
| isCommonElem( string elemName) | boolean |
Returns
true
if the specified element is a standard defined xxx.
|
| isCommonEventAttr( string attrName) | boolean |
Returns
true
if the specified attribute is a standard xxx defined xxx. (Note: if
attrName
is prefixed with '
:
', the prefix is ignored).
|
| isHtml5ObsoleteElem( string elemName) | boolean |
Returns
true
if the specified element is obsolete in HTML5
|
| isHtml5ObsoleteAttr( string elemName, string attrName) | boolean |
Returns
Note: the return value is unconditional. There may be additional exception conditions that need to be evaluated (for example, the
|
| isJetPage( Object context) | boolean |
Returns
true
if there is at least element with a name starting with
oj-
|
| isNamespaceTag( string tagName) | boolean |
Given a Web Component element name starting with
oj-
(e.g.
oj-ext-foo
), this returns
true
, if the prefix (
oj-ext
in this example) is defined in the xxx.
|
| isNamespacePrefix( string tagPrefix) | boolean |
Given a Web Component name prefix starting with
oj-
(for example
oj-ext
), this returns
true
, if the prefix is defined in the xxx .
|
| isNonFragmentJetPage( Object context) | boolean |
Returns
true
if the HTML page has a
<body>
and also has at least one JET component element.
|
| isSvgElem( string elemName) | boolean | Returns true if the element name is an SVG element |
| isValidJson( string json) | boolean | string |
Checks a string to see if it is JSON, and if so, validates it. If the string is valid JSON, or is not JSON,
true
is returned. If it is JSON and is not well formed a message string is returned. (Note: the JSON can contain // and /* . . . */ style comments - these are ignored.)
|
| isValidSvgPath( string svg) | boolean |
If the string appears to be a valid SVG path,
true
is returned. Note this does not validate the path for being syntactically correct SVG.
|
| isExpression( string ) | boolean |
Returns
true
if the string has valid expression delimiters {{. . .}} and [[. . .]] and they are matched correctly.
|
| getExpression( string ) | string|null | Returns the expression contained within the expression delimiters {{. . .}} and [[. . .]]. If not an expression or the expression is not validly delimited, null is returned. |
| camelCase( string prop) | boolean | Returns a camel-cased string from a kebab-cased property string. |
| kebabCase( string prop) | boolean | Returns a kebab-cased string from a camel-cased property string. |
| kebabCaseEvent( string prop) | boolean | Returns a kebab-cased string from a camel-cased event name. |
ConfigLib: Configuration Library
ConfigLib is a context member that provides convenient access to some configuration information.
Access these methods through the rule context object property context.utils.configLib.
| Method | Returns | Description |
|---|---|---|
| getConfig() | Object | Returns a copy of the currently active configuration. See also JafLib.getConfig() . |
| getOrigConfig() | Object | The original configuration supplied to JAF before processing by JAF into the currently active configuration |
| getExtendsProfileName() | string | undefined |
The profile name extended by the initial configuration (from configuration property
extends
).
|
| isBuiltinJetRules() | boolean |
true
if JET built-in rules are enabled (from configuration property
builtinJetRules
).
|
| isBuiltinCspRules() | boolean |
true
if JET built-in CSP rules are enabled (from configuration property
builtinCspRules
).
|
| isBuiltinJetWcRules() | boolean |
true
if extended audits (JETWC) for customer component authors are enabled (from configuration property
builtinJetWcRules
).
|
| isBuiltinJetWcOracleRules() | boolean |
true
if extended Oracle audits (JETWCO) for customer component authors are enabled(from configuration property
builtinJetWcOracleRules
).
|
| isBuiltinOjcMigrationRules() | boolean |
true
if the built-in component migration rules are enabled (from configuration property
builtinJOjcMigrationRules
).
|
| isBuiltinWebDriverTestRules() | boolean |
true
, if the built-in WebDriver test audit rules (from configuration property
builtinWebDriverTestRules
).
|
JafLib: JAF Core Access Methods
JafLib is a library of exposed core Oracle JAF lifecycle methods.
Access these methods through the rule context object property context.utils.jafLib.
| Method | Returns | Description |
|---|---|---|
|
setFileset( Object context, string[] fileset [, string[] exclude]) |
boolean |
Sets the file set to audit. This is a dynamic replacement for the files and exclude properties of the configuration file. fileset and optional exclude specify an array of full file paths. Globs may be used. context is the rule context object.
Returns
This method may be useful when writing hook rules. The method can be used only during the startaudit phase of the audit lifecycle. |
| getFileset( Object context) | Object |
Returns the files and exclude configuration properties in an object with the same property names. context is the rule context object. Do not modify the object property values! To modify either files and/or exclude properties use setFileset() . Note that this can be used in conjunction with setFileset() to merge or remove entries. This method may be useful when writing hook rules. The method can be used only during the startaudit phase of the audit lifecycle. |
| getJafReleaseCount() | number |
Returns the estimated number of JET major public releases since the JET version of the JAF package used. |
| getMajorReleaseCount( string semver | number major) | number |
Returns the estimated number of JET major public releases since the JET major value in the supplied semver argument.
The
|
| getConfig() | Object |
Returns an object with getter methods that return configuration property values. Refer to JafLib: Configuration Object Property Getter Methods . |
| getTsConfig() | Object |
Returns the tsconfig.json as an object. |
| getRunMode() | string | Returns a string representing the JAF run mode. Values are cli , api , or amd . Currently, running in CLI mode only is possible. |
| isCLI() | boolean |
Returns
true
if running in CLI mode (the only mode currently available).
|
| isAPI() | boolean |
Currently returns
false
. Note that API mode is reserved for future support.
|
| isAMD() | boolean |
Currently returns
false
. Note that AMD mode is reserved for future support.
|
| getJafVer() | string | Returns the JAF version semver, for example: 3.12.4. |
| getJetVer() | string | Returns the JET metadata version semver, for example: 9.2.3. |
JafLib: Configuration Object Property Getter Methods
JafLib exposes the getConfig() method to access JAF configuration property values.
The configuration object returned by JafLib.getConfig() contains methods returning configuration property values. Note that due to configuration analysis during startup, property values returned do not necessarily reflect the same values. For example, if the configuration property theme is not defined, Config.getTheme() will return the default value alta and not undefined.
| Method | Configuration Property Returned |
|---|---|
| getComponents() | components |
| getComponentsBase() | componentsBase |
| getComponentsBaseUrl() | componentsBaseUrl |
| getComponentOptions() | componentOptions |
| getDisable() | ruleMods.disable |
| getEcmaVer() | cmaVer |
| getEnable() | ruleMods.enable |
| getExclude() | exclude |
| getFiles() | files |
| getGroups() | groups |
| getJetVer | jetVer |
| getMessages() | messages |
| getOptions() | options |
| getOutPath() | outPath |
| getRuleDescriptions() | ruleDescriptions |
| getRuleMods() | ruleMods |
| getRuleNames() | ruleNames |
| getRulePacks() | rulePacks |
| getTheme() | theme |
| getTypescript() | typescript |
| getTsConfig() | typescript.tsconfig |
| getTsConfigObj() | Returns the tsconfig.json found on the path defined by the typescript.tsconfig sub-property, as an object. |
| isBuiltinJetRules() | builtinJetRules |
| isBuiltinJetWcRules() | builtinJetWcRules |
| isBuiltinSpocRules() | bultinSpocRules |
MsgLib: Message Display Functions
MsgLib is a namespace property providing access to Oracle JAF internal messaging routines.
Access these internal messaging routines through the rule context object property context.utils.msgLib as an instance of a library object. They may be helpful when you need to provide the ability for an audit rule to write conditional and unconditional messages to the output. Refer also to the context property sysOpts.
| Method | Description |
|---|---|
| msg() |
Writes a general message string to the console. For example:
msgLib.msg("this is a message").
|
| info() |
Writes the message string to the console only if verbose mode is on. For example:
msgLib.msg("this is only displayed in verbose mode"). The message is preceded by
[info]:.
|
| debug() |
Writes the message string to the console only if debug mode is on. For example:
msgLib.debug("this is only displayed in debug mode"). The message is preceded by
[debug]:.
|
| error() |
Writes the message to the console. For example:
msgLib.error("this is an error message"). The message is preceded by
[error]:.
|
| assert() |
Writes a message string to the console. For example:
msgLib.assert("this is an assertion message"). The message is preceded by
[ASSERT]:.
|
CssUtils: CSS Utility Functions
CssUtils is a library of CSS rule processing functions.
Access these functions through the context property context.utils.CssUtils on the register context object when the rule is invoked or on the rule context object passed to the registered listener. These functions may be useful when writing CSS rules.
| Method | Returns | Description |
|---|---|---|
| isColorName( string name ) | boolean |
Returns
|
| isCommonElem( string tagName ) | boolean |
Returns
|
| isMarkerstyle( string style ) | boolean |
Returns
|
| getPosition( Object context, Object loc) | Object |
Converts a
loc
position node in the CSS Abstract Syntax Tree (AST) to a position object suitable to pass to
|
AstUtils: JavaScript File Helper Functions
AstUtils is a collection of Abstract Syntax Tree (AST) helper functions.
Access these functions through the rule context object property context.utils.AstUtils. They may be useful when writing audit rules for JavaScript files. For example:
var node = ruleContext.utils.AstUtils.getBody(); // get the array of program body nodes
| Name | Returns | Description |
|---|---|---|
| getBlock( Object node) | node | Returns the block node in which the specified node resides. If node is not specified, the outer program block is returned. |
| getBody( Object node) | Array[] |
Returns the
body
array of nodes containing the specified node. If node is not specified, the body of the program is returned.
|
| getProgram() | node | Returns the Program node. |
| isFuncArg( Object node, string var) |
true
if the variable is an argument to the function, else
false.
|
Tests if a variable found in an expression in any node in the body of a function is declared as an argument to that function. |
| isCommonDocApi( string methodName) |
true
if the method is a common
Document
method.
|
Tests if a method is a common
Document
method (for example,
getElementById()).
|
| parseDefine( Object node) |
An an object with members of the form:
|
Parses a KO
define
statement.
|
| getNodeTypes( ) |
An an object with members of the form:
|
Returns an object mapping abbreviated node types for JavaScript. For details, see the list of node type constants in Listener Types for JavaScript/TypeScript Rules. |
SevLib: Severity Support Helper Functions
SevLib is a collection of helper functions that provides support to process severity levels that have been remapped via the Oracle JAF configuration property sevMap.
Access these functions through the rule context object property context.utils.SevLib. They may be useful when writing audit.
| Name | Returns | Description |
|---|---|---|
| map( string sev) | string |
Maps a severity. If severity is not mapped, the unmapped severity is returned. For example,
map("major")
will return the mapped value, or
major
if not remapped.
|
| unmap( string sev) | Array.< string > |
Unmaps a severity. If the severity does not represent a mapped severity value, the supplied severity is returned. If there more than one severity has been unmapped, it returns all unmapped severity strings in an arrary. For example, given the following:
Then
|
| isMapped( string sev) | boolean | Test if a severity is a remapped severity. |
| getList() | Array.< string > | Returns an array of JAF default severities. For example, blocker, critical, and so on in ascending order of priority. |
| getMap() | Object |
Returns an object whose properties are the JAF default properties, and the corresponding values are the user mapped severities. If severities have not been remapped,
null
is returned.
|
| getInvertedMap() | Object |
Returns an inverted form of the object returned by
getMap(), whose properties are the remapped properties, and the corresponding values are the JAF default properties. If severities have not been remapped,
null
is returned.
|
| isSev( string sev) | boolean |
Returns
true
if the supplied severity is a valid value. May be a core severity or a remapped value.
|
| getMsgSev( string msgId) | string | null |
Returns the severity for the
msgId
(for example, JET-2000), or
null
if the
msgId
is not defined.
|
| matchSeverityLevel( string sev) | boolean | Tests if the supplied severity is matched by the JAF configuration property severity value/expression. |
| isBlocker( string sev) | boolean |
Returns
true
if the severity (mapped or unmapped) represents
blocker.
|
| isCritical( string sev) | boolean |
Returns
true
if the severity (mapped or unmapped) represents
critical.
|
| isMajor( string sev) | boolean |
Returns
true
if the severity (mapped or unmapped) represents
major.
|
| isMinor( string sev) | boolean |
Returns
true
if the severity (mapped or unmapped) represents
minor.
|
| isInfo( string sev) | boolean |
Returns
true
if the severity (mapped or unmapped) represents
info.
|
TsxUtils: TSX Utility Functions
TsxUtils is a utility library available through the rule and registration contexts as context.utils.tsxUtils.
| Method | Returns | Description |
|---|---|---|
| extractTsxProperties ( Object ruleCtx, Object TsxRenderComponent, Function callback ) | nothing |
Given a TsxRenderComponent object, the callback function is called for each tag attribute found in the TsxRenderComponent object.
where TsxComponent is a TsxComponent object, and Prop is a property object (a member of TsxComponent) Note:
|
|
getExpressionObject ( TsxProperty prop ) |
Object | null |
Returns an object derived from a Preact object expression. For example, given the following snippet:
Then using the TsxProperty object for myProp
returns the following object:
The method returns null if the outer-braces of the property value do not contain an object expression. |
|
isPropertyObjectExpr ( TsxProperty | tsxComponent propOrComp, [ string propName ] ) |
boolean |
Returns true if the property value of the TsxProperty, or the value of the TsxComponent with the named property, is an Object expression. For example:
where argument propOrComp is a TsxProperty or a TsxComponent object. If the first argument is a TsxComponent, the second argument, propName, is required. It is not used for a TsxProperty. |
|
isPropertyPreactExpr ( TsxProperty | TsxComponent propOrComp, [ string propName ] ) |
boolean |
Returns true if the property value of the TsxProperty, or the value of the TsxComponent with the named property, is a Preact expression. For example:
where argument propOrComp is a TsxProperty or a TsxComponent object. If the first argument is a TsxComponent, the second argument, propName, is required. It is not used for a TsxProperty. |
|
isPropertyString ( TsxProperty | TsxComponent propOrComp, [ string propName ] ) |
boolean |
Returns true if the value of TsxProperty, or the value of a TsxComponent with the named property, is a string value Where argument propOrComp is a TsxProperty or a TsxComponent object. If the first argument is a TsxComponent, the second argument, propName, is required. It is not used for a TsxProperty. |
|
setIssuePosition ( Object issue, Object compOrProp ) |
nothing |
Updates the supplied Issue instance, with the positional information in the supplied TsxComponent or TsxProperty object. issue is the instantiated Issue object, and compOrProp is a TsxComponent or TsxProperty object. |
|
setIssuePropValuePosition ( Object issue, Object tsxProp ) |
nothing |
Updates the supplied Issue instance, with the property value positional information in the supplied TsxProperty object. issue is the instantiated Issue object, and tsxProp is a TsxProperty object. |
| getChildren ( Object tsxComp ) | Object|null |
Returns an array of child TsxComponent objects. tsxComp is the TsxComponent whose children are required. |
| getAncestor ( Object tsxComp [ string compName ] ) | Object|null |
Returns the first found named ancestor component of the supplied component. where:
Returns the found TsxComponent, or null if not found. |
| getDescendant ( Object tsxComp [ string compName ] ) | Object|null |
Returns the first found named descendant component of the supplied component. where:
Returns the found TsxComponent, or null if not found. |
| getProperty ( TsxProperty | TsxComponent propOrComp, string propName ) | Object| null | Returns the TsxProperty object for the named property from a TsxComponent. If a TsxProperty object is supplied, the argument is returned (and the property name is ignored if supplied). |
| getPropertyValue ( Object tsxComp, string propName ) | Object | Returns the value node for the named property from a TsxComponent. |
| getPropertyRawValue ( Object tsxComp, string propName, boolean stripDelims) | string | Returns the raw value of the named property from a TsxComponent. Note: if the property value is a string, this will include the delimiting quotes unless the optional stripDelims argument is set to true. |
| getPropertyStringValue ( TsxProperty | TsxComponent propOrComp, [ string propName ] | string | null | undefined |
Returns the string value of the property if the property type is a string. If the property is empty and has no value (e.g. the HTML 'disabled' attribute) the returned value is undefined. If the value type is not a string or the property is not found, null is returned. Argument propOrComp may be a TsxProperty or a TsxComponent object. If propOrComp is a TsxComponent, the second argument, propName, is required. It is not used for a TsxProperty. |
| getRawText ( Object ruleCtx, Object tsxRC ) | string | Returns the raw text used to create the TsxRenderComponent. |
| getSlotParent ( Object ruleCtx, TsxProperty tsxProp, string slotName ) | TsxComponent | null | Returns the parent TsxComponent that resolves the specified slot name. |
The following additional methods (normally exported by DomUtils for HTML rules) can also be found in TsxUtils, since DomUtils is not available in the rule/registration context for TSX rules.
| Method | Returns | Description |
|---|---|---|
| isAriaAttr( string attrName) | boolean |
Returns
true
if the specified attribute is a known ARIA attribute.
|
| isCommonAttr( string attrName) | boolean |
Returns
true
if the specified attribute is a standard defined xxx. (Note: if
attrName
is prefixed with '
:
', the prefix is ignored).
|
| isCommonElem( string elemName) | boolean |
Returns
true
if the specified element is a standard defined xxx.
|
| isCommonEventAttr( string attrName) | boolean |
Returns
true
if the specified attribute is a standard xxx defined xxx. (Note: if
attrName
is prefixed with '
:
', the prefix is ignored).
|
| isHtml5ObsoleteElem( string elemName) | boolean |
Returns
true
if the specified element is obsolete in HTML5
|
| isHtml5ObsoleteAttr( string elemName, string attrName) | boolean |
Returns
Note: the return value is unconditional. There may be additional exception conditions that need to be evaluated (for example, the
|
| isNamespacePrefix( string tagPrefix) | boolean |
Given a Web Component name prefix starting with
oj-
(for example
oj-ext
), this returns
true
, if the prefix is defined in the xxx .
|
| isNamespaceTag( string tagName) | boolean |
Given a Web Component element name starting with
oj-
(e.g.
oj-ext-foo
), this returns
true
, if the prefix (
oj-ext
in this example) is defined in the xxx.
|
| isSelfClosingTag( string tagName) | boolean |
Returns true if the tag is a self-closing tag (such as <br> or <hr>, and so on).
|
| isSvgElem( string elemName) | boolean | Returns true if the element name is an SVG element. |
| isSvgPath( string svg) | boolean | Returns true if the string appears to be a valid SVG path. Note: This method does not validate the path for being syntactically correct SVG. |
Use TSX Functions
The following example uses the extractTsxProperties() utility method to inspect all tag attributes in the TsxRenderComponent structure. It provides a callback mechanism and iterates over the entire TsxRenderComponent.
function register() {
// listen for .tsx renderable content sets
return { "TsxRenderComponent": _onTsxRC };
};
/**
* Listener for Web Component tags. Iterate over the tag's properties.
* @param {Object} ruleCtx the rule context
* @param {Object} tsxRC the TsxRenderComponent tag
*/
function _onTsxRC(ruleCtx, tsxRC) {
// Extract the attributes and invoke callback _onProperty for each attribute
ruleCtx.utils.tsxUtils.extractTsxProperties(ruleCtx, tsxRC, _onProperty);
}
/**
* Check an attribute and emit an Issue if necessary.
* @param {Object} ruleCtx the rule context
* @param {Object} tsxComponent the TsxComponent object
* @param {*Object} tsxProp the TsxProperty object
*/
function _onProperty(ruleCtx, tsxComponent, tsxProp) {
// if tsxProp is null, the iteration is complete, and
// this is the final callback.
if (!tsxProp) { return; }
// Inspect tsxProp object
. . .
}
As another example, the TsxUtils method getExpressionObject() is useful when you need to examine sub-properties declared in a TSX expression. Consider the two sub-properties one and two of the following property:
<xxx someProp={{ one: "left", two: "top" }}
The sub-properties can be acquired from the TsxProperty object someProp without inspecting the AST nodes by using getExpressionObject():
let subprops = ruleCtx.utils.tsxUtils.getExpressionObject(someProp);
Where the returned value in subprops will be:
{
one: "left",
two: "top"
}