Package org.apache.ofbiz.minilang
Class MiniLangValidate
java.lang.Object
org.apache.ofbiz.minilang.MiniLangValidate
Mini-language validation.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
attributeNames
(SimpleMethod method, Element element, String... validAttributeNames) Testselement
for invalid attribute names.static String
checkAttribute
(String attributeValue, String defaultValue) ReturnsattributeValue
if it is not empty, else returnsdefaultValue
.static void
childElements
(SimpleMethod method, Element element, String... validChildElementNames) Testselement
for invalid child elements.static void
constantAttributes
(SimpleMethod method, Element element, String... attributeNames) Tests if element attributes are constant type.static void
constantPlusExpressionAttributes
(SimpleMethod method, Element element, String... attributeNames) Tests if element attributes are constant+expr type.static void
deprecatedAttribute
(SimpleMethod method, Element element, String attributeName, String fixInstruction) Testselement
for a deprecated attribute.static void
expressionAttributes
(SimpleMethod method, Element element, String... attributeNames) Tests if element attributes are expression type.static void
handleError
(String errorMessage, SimpleMethod method, Element element) Handles a Mini-language validation error.static boolean
Returnstrue
ifvalidation.level=lenient
.static void
noChildElements
(SimpleMethod method, Element element) Testselement
for child elements.static void
requireAnyAttribute
(SimpleMethod method, Element element, String... attributeNames) Testselement
for any one required attribute from a set of attribute names.static void
requireAnyChildElement
(SimpleMethod method, Element element, String... elementNames) Testselement
for any one required child element from a set of tag names.static void
requiredAttributes
(SimpleMethod method, Element element, String... attributeNames) Testselement
for required attributes.static void
requiredChildElements
(SimpleMethod method, Element element, String... elementNames) Testselement
for required child elements.static void
scriptAttributes
(SimpleMethod method, Element element, String... attributeNames) Tests if element attributes are script type.static boolean
strictOn()
Returnstrue
ifvalidation.level=strict
.static boolean
Returnstrue
ifvalidation.level
is set to lenient or strict.
-
Method Details
-
attributeNames
public static void attributeNames(SimpleMethod method, Element element, 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
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, Element element, 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, Element element, 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, Element element, 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, Element element, String attributeName, 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, Element element, 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(String errorMessage, SimpleMethod method, 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
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, Element element, 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, Element element, 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, Element element, 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, Element element, 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, Element element, 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
-