Class MiniLangValidate

java.lang.Object
org.apache.ofbiz.minilang.MiniLangValidate

public final class MiniLangValidate extends Object
Mini-language validation.
  • Method Details

    • attributeNames

      public static void attributeNames(SimpleMethod method, Element element, String... validAttributeNames) throws ValidationException
      Tests element for invalid attribute names.
      Parameters:
      method - The <simple-method> that contains element
      element - The element to test
      validAttributeNames - The valid attribute names
      Throws:
      ValidationException - If an invalid attribute name is found and validation.level=strict
    • checkAttribute

      public static String checkAttribute(String attributeValue, String defaultValue)
      Returns attributeValue if it is not empty, else returns defaultValue. No null checks are performed.
      Parameters:
      attributeValue -
      defaultValue -
      Returns:
      attributeValue if it is not empty, else returns defaultValue
    • childElements

      public static void childElements(SimpleMethod method, Element element, String... validChildElementNames) throws ValidationException
      Tests element for invalid child elements.
      Parameters:
      method - The <simple-method> that contains element
      element - The element to test
      validChildElementNames - The valid child element tag names
      Throws:
      ValidationException - If an invalid child element is found and validation.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 contains element
      element - The element to test
      attributeNames - The attributes to test
      Throws:
      ValidationException - If an invalid attribute is found and validation.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 contains element
      element - The element to test
      attributeNames - The attributes to test
      Throws:
      ValidationException - If an invalid attribute is found and validation.level=strict
    • deprecatedAttribute

      public static void deprecatedAttribute(SimpleMethod method, Element element, String attributeName, String fixInstruction) throws ValidationException
      Tests element for a deprecated attribute.
      Parameters:
      method - The <simple-method> that contains element
      element - The element to test
      attributeName - The name of the deprecated attribute
      fixInstruction - Instructions to fix the deprecated attribute
      Throws:
      ValidationException - If the deprecated attribute is found and validation.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 contains element
      element - The element to test
      attributeNames - The attributes to test
      Throws:
      ValidationException - If an invalid attribute is found and validation.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 message
      method - The <simple-method> that contains element
      element - The element that contains the error
      Throws:
      ValidationException - If validation.level=strict, otherwise a warning is logged
    • lenientOn

      public static boolean lenientOn()
      Returns true if validation.level=lenient.
      Returns:
      true if validation.level=lenient
    • noChildElements

      public static void noChildElements(SimpleMethod method, Element element) throws ValidationException
      Tests element for child elements.
      Parameters:
      method - The <simple-method> that contains element
      element - The element to test
      Throws:
      ValidationException - If a child element is found and validation.level=strict
    • requireAnyAttribute

      public static void requireAnyAttribute(SimpleMethod method, Element element, String... attributeNames) throws ValidationException
      Tests element for any one required attribute from a set of attribute names.
      Parameters:
      method - The <simple-method> that contains element
      element - The element to test
      attributeNames - The required attribute names
      Throws:
      ValidationException - If none of the required attributes are found and validation.level=strict
    • requireAnyChildElement

      public static void requireAnyChildElement(SimpleMethod method, Element element, String... elementNames) throws ValidationException
      Tests element for any one required child element from a set of tag names.
      Parameters:
      method - The <simple-method> that contains element
      element - The element to test
      elementNames - The required child element tag names
      Throws:
      ValidationException - If none of the required child elements are found and validation.level=strict
    • requiredAttributes

      public static void requiredAttributes(SimpleMethod method, Element element, String... attributeNames) throws ValidationException
      Tests element for required attributes.
      Parameters:
      method - The <simple-method> that contains element
      element - The element to test
      attributeNames - The required attribute names
      Throws:
      ValidationException - If any of the required attributes are not found and validation.level=strict
    • requiredChildElements

      public static void requiredChildElements(SimpleMethod method, Element element, String... elementNames) throws ValidationException
      Tests element for required child elements.
      Parameters:
      method - The <simple-method> that contains element
      element - The element to test
      elementNames - The required child element tag names
      Throws:
      ValidationException - If any of the required child elements are not found and validation.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 contains element
      element - The element to test
      attributeNames - The attributes to test
      Throws:
      ValidationException - If an invalid attribute is found and validation.level=strict
    • strictOn

      public static boolean strictOn()
      Returns true if validation.level=strict.
      Returns:
      true if validation.level=strict
    • validationOn

      public static boolean validationOn()
      Returns true if validation.level is set to lenient or strict.
      Returns:
      true if validation.level is set to lenient or strict