Package org.apache.ofbiz.minilang
Class MiniLangValidate
- java.lang.Object
-
- org.apache.ofbiz.minilang.MiniLangValidate
-
public final class MiniLangValidate extends java.lang.Object
Mini-language validation.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
module
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
attributeNames(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... validAttributeNames)
Testselement
for invalid attribute names.static java.lang.String
checkAttribute(java.lang.String attributeValue, java.lang.String defaultValue)
ReturnsattributeValue
if it is not empty, else returnsdefaultValue
.static void
childElements(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... validChildElementNames)
Testselement
for invalid child elements.static void
constantAttributes(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... attributeNames)
Tests if element attributes are constant type.static void
constantPlusExpressionAttributes(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... attributeNames)
Tests if element attributes are constant+expr type.static void
deprecatedAttribute(SimpleMethod method, org.w3c.dom.Element element, java.lang.String attributeName, java.lang.String fixInstruction)
Testselement
for a deprecated attribute.static void
expressionAttributes(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... attributeNames)
Tests if element attributes are expression type.static void
handleError(java.lang.String errorMessage, SimpleMethod method, org.w3c.dom.Element element)
Handles a Mini-language validation error.static boolean
lenientOn()
Returnstrue
ifvalidation.level=lenient
.static void
noChildElements(SimpleMethod method, org.w3c.dom.Element element)
Testselement
for child elements.static void
requireAnyAttribute(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... attributeNames)
Testselement
for any one required attribute from a set of attribute names.static void
requireAnyChildElement(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... elementNames)
Testselement
for any one required child element from a set of tag names.static void
requiredAttributes(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... attributeNames)
Testselement
for required attributes.static void
requiredChildElements(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... elementNames)
Testselement
for required child elements.static void
scriptAttributes(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... attributeNames)
Tests if element attributes are script type.static boolean
strictOn()
Returnstrue
ifvalidation.level=strict
.static boolean
validationOn()
Returnstrue
ifvalidation.level
is set to lenient or strict.
-
-
-
Method Detail
-
attributeNames
public static void attributeNames(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... validAttributeNames) throws ValidationException
Testselement
for invalid attribute names.- Parameters:
method
- The<simple-method>
that containselement
element
- Theelement
to testvalidAttributeNames
- The valid attribute names- Throws:
ValidationException
- If an invalid attribute name is found andvalidation.level=strict
-
checkAttribute
public static java.lang.String checkAttribute(java.lang.String attributeValue, java.lang.String defaultValue)
ReturnsattributeValue
if it is not empty, else returnsdefaultValue
. Nonull
checks are performed.- Parameters:
attributeValue
-defaultValue
-- Returns:
attributeValue
if it is not empty, else returnsdefaultValue
-
childElements
public static void childElements(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... validChildElementNames) throws ValidationException
Testselement
for invalid child elements.- Parameters:
method
- The<simple-method>
that containselement
element
- Theelement
to testvalidChildElementNames
- The valid child element tag names- Throws:
ValidationException
- If an invalid child element is found andvalidation.level=strict
-
constantAttributes
public static void constantAttributes(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... attributeNames) throws ValidationException
Tests if element attributes are constant type.- Parameters:
method
- The<simple-method>
that containselement
element
- Theelement
to testattributeNames
- The attributes to test- Throws:
ValidationException
- If an invalid attribute is found andvalidation.level=strict
-
constantPlusExpressionAttributes
public static void constantPlusExpressionAttributes(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... attributeNames) throws ValidationException
Tests if element attributes are constant+expr type.- Parameters:
method
- The<simple-method>
that containselement
element
- Theelement
to testattributeNames
- The attributes to test- Throws:
ValidationException
- If an invalid attribute is found andvalidation.level=strict
-
deprecatedAttribute
public static void deprecatedAttribute(SimpleMethod method, org.w3c.dom.Element element, java.lang.String attributeName, java.lang.String fixInstruction) throws ValidationException
Testselement
for a deprecated attribute.- Parameters:
method
- The<simple-method>
that containselement
element
- Theelement
to testattributeName
- The name of the deprecated attributefixInstruction
- Instructions to fix the deprecated attribute- Throws:
ValidationException
- If the deprecated attribute is found andvalidation.level=strict
-
expressionAttributes
public static void expressionAttributes(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... attributeNames) throws ValidationException
Tests if element attributes are expression type.- Parameters:
method
- The<simple-method>
that containselement
element
- Theelement
to testattributeNames
- The attributes to test- Throws:
ValidationException
- If an invalid attribute is found andvalidation.level=strict
-
handleError
public static void handleError(java.lang.String errorMessage, SimpleMethod method, org.w3c.dom.Element element) throws ValidationException
Handles a Mini-language validation error.- Parameters:
errorMessage
- The error messagemethod
- The<simple-method>
that containselement
element
- Theelement
that contains the error- Throws:
ValidationException
- Ifvalidation.level=strict
, otherwise a warning is logged
-
lenientOn
public static boolean lenientOn()
Returnstrue
ifvalidation.level=lenient
.- Returns:
true
ifvalidation.level=lenient
-
noChildElements
public static void noChildElements(SimpleMethod method, org.w3c.dom.Element element) throws ValidationException
Testselement
for child elements.- Parameters:
method
- The<simple-method>
that containselement
element
- Theelement
to test- Throws:
ValidationException
- If a child element is found andvalidation.level=strict
-
requireAnyAttribute
public static void requireAnyAttribute(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... attributeNames) throws ValidationException
Testselement
for any one required attribute from a set of attribute names.- Parameters:
method
- The<simple-method>
that containselement
element
- Theelement
to testattributeNames
- The required attribute names- Throws:
ValidationException
- If none of the required attributes are found andvalidation.level=strict
-
requireAnyChildElement
public static void requireAnyChildElement(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... elementNames) throws ValidationException
Testselement
for any one required child element from a set of tag names.- Parameters:
method
- The<simple-method>
that containselement
element
- Theelement
to testelementNames
- The required child element tag names- Throws:
ValidationException
- If none of the required child elements are found andvalidation.level=strict
-
requiredAttributes
public static void requiredAttributes(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... attributeNames) throws ValidationException
Testselement
for required attributes.- Parameters:
method
- The<simple-method>
that containselement
element
- Theelement
to testattributeNames
- The required attribute names- Throws:
ValidationException
- If any of the required attributes are not found andvalidation.level=strict
-
requiredChildElements
public static void requiredChildElements(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... elementNames) throws ValidationException
Testselement
for required child elements.- Parameters:
method
- The<simple-method>
that containselement
element
- Theelement
to testelementNames
- The required child element tag names- Throws:
ValidationException
- If any of the required child elements are not found andvalidation.level=strict
-
scriptAttributes
public static void scriptAttributes(SimpleMethod method, org.w3c.dom.Element element, java.lang.String... attributeNames) throws ValidationException
Tests if element attributes are script type.- Parameters:
method
- The<simple-method>
that containselement
element
- Theelement
to testattributeNames
- The attributes to test- Throws:
ValidationException
- If an invalid attribute is found andvalidation.level=strict
-
strictOn
public static boolean strictOn()
Returnstrue
ifvalidation.level=strict
.- Returns:
true
ifvalidation.level=strict
-
validationOn
public static boolean validationOn()
Returnstrue
ifvalidation.level
is set to lenient or strict.- Returns:
true
ifvalidation.level
is set to lenient or strict
-
-