Class LinqContext

java.lang.Object
com.flowable.template.engine.impl.linq.LinqContext

public class LinqContext extends Object
  • Field Details

  • Constructor Details

  • Method Details

    • valueOrDefault

      public Object valueOrDefault(String expressionText, Object defaultValue)

      Gets a value from an expression or returns a default value in case the value resolves to null or the expression throws an exception. For example, when the value could not be found it will render the default value.

      Example:

      <<[context.valueOrDefault("${location}", "Switzerland")]>>
      Parameters:
      expressionText - Text of a Flowable expression to be rendered
      defaultValue - A value which is used in case there is no other value provided.
      Returns:
      the resolved value to be used in an aspose template
    • value

      public Object value(String expressionText)

      Gets a value from an expression. In case an expression is unable to resolve it will throw an error, and it won't generate the document. This can be useful if the document should not be rendered in case of errors in the expression. However, an alternative approach is to use the valueOrDefault(String, Object) method which is resolving the error case to a default value.

      Example:

      <<[context.value("${location}")]>>
      Parameters:
      expressionText - Text of a Flowable expression to be rendered
      Returns:
      the resolved value to be used in an aspose template
    • booleanValue

      public boolean booleanValue(String expressionText)

      Gets a boolean value from an expression. This is useful for comparison. The expression can be either a direct boolean variable or a comparison based on one or multiple input parameters.

      <<if [context.booleanValue("${validData}")]>>Valid<<else>>Invalid<</if>>
      Parameters:
      expressionText - The expression which must be evaluated to a boolean value
      Returns:
      true or false based on the expression result
    • hasValue

      public boolean hasValue(Object obj, String key)
      Checks if a (nested) value from a map, JSON node, or variable container exists.

      To check if a property exists, use a simple property name. To check nested values, use the . notation, e.g., address.street.

      If a key is provided that cannot be navigated within the provided obj, it will return false for simple keys (without the . notation) to maintain compatibility. However, for more complex keys, an exception is thrown.

      Example usages:

      <<[context.hasValue(context.value("${person}"), "address")]>>
      <<[context.hasValue(context.value("${person}"), "address.street")]>>
      <<[context.hasValue(context.value("${person}"), "unknown")]>> // returns false
      <<[context.hasValue(context.value("${person}"), "unknown.nested")]>> // throws error
      Parameters:
      obj - Can be either a Map, a VariableContainer or a JsonNode
      key - Can be either an attribute or for nested object also a combination of keys separated by .. This allows to check JSON variables available on the process.
      Returns:
      true if the value exists, false otherwise
    • hasValueSimple

      protected Boolean hasValueSimple(Object obj, String key)
    • mapValue

      public Object mapValue(Object obj, String key)
      Retrieves a (nested) value from a map, JSON node, or variable container.

      To retrieve a property, use a simple property name. To retrieve nested values, use the . notation, e.g., address.street.

      If a key is provided that cannot be navigated within the provided obj, it will return null for simple keys (without the . notation) to maintain compatibility. However, for more complex keys, an exception is thrown.

      Example usages:

      <<[context.mapValue(context.value("${person}"), "address")]>>
      <<[context.mapValue(context.value("${person}"), "address.street")]>>
      <<[context.mapValue(context.value("${person}"), "unknown")]>> // returns null
      <<[context.mapValue(context.value("${person}"), "unknown.nested")]>> // throws error
      Parameters:
      obj - Can be either a Map, a VariableContainer or a JsonNode
      key - Can be either an attribute or for nested object also a combination of keys separated by .. This allows to check JSON variables available on the process.
      Returns:
      The mapped value based on the `obj` and `key` provided.
    • mapValueSimple

      protected Object mapValueSimple(Object obj, String key)
    • evaluate

      public Object evaluate(String expression, Object item)

      Evaluates a given expression using a specified input parameter. It takes exactly one item which is either a Map, a VariableContainer or a JsonNode. The item is used as a base for an expression. The expression directly uses the field out of the object which is provided and does not require an additional prefix. The expression has access to all variables present in the document's context.

      Example:

      <<[context.evaluate("${firstName}", person)]>>

      This functionality can be helpful when applied within a loop, allowing for dynamic evaluation of expressions based on the current item.

      Parameters:
      expression - The JUEL expression to evaluate, considering the current context and specified item.
      item - The item which must be either a Map, a VariableContainer or a JsonNode.
      Returns:
      The result of the evaluated expression.
      Since:
      3.14.0
    • evaluate

      public Object evaluate(String expression, Object item, String itemName)

      Evaluates a given expression using a specified input parameter. This method accepts any type of item, which is identified by an itemName. This itemName provides a way to reference the input item within the expression. The expression has access to all variables present in the document's context.

      The provided item is accessible via its itemName, enabling it to serve as an argument for method invocations within the expression. This feature facilitates the production of calculated results.

      Example:

      <<[context.evaluate("${personObj.firstName}", person, "personObj")]>>
      <<[context.evaluate("${exampleService.getSalutation(personObj)}", person, "personObj")]>>

      This functionality can be helpful when applied within a loop, allowing for dynamic evaluation of expressions based on the current item. The advantage of this approach is that it does not require the item to conform to any specific type, while the given item can be fully utilized within expressions.

      Parameters:
      expression - The JUEL expression to evaluate, considering the current context and specified item.
      item - The specific object made available under the itemName.
      itemName - The identifier used to reference the item within the expression.
      Returns:
      The result of the evaluated expression.
      Since:
      3.14.0
    • toValue

      protected Object toValue(Object value)
    • foreach

      public LinqIterable foreach(String expressionText)

      Ability to iterate over a list based on an expression which evaluates to an iterable item. This could be a list coming from a form or created with an Init Variable task or something else.

      Example:

      We're very happy to inform you that your order is ready for shipping:
      
       <<foreach [item in context.foreach("${items}")]>>
       -   <<[context.mapValue(item,"name")]>>, with a business value of <<[context.mapValue(item, "value")]>>
       <</foreach>>
      Parameters:
      expressionText - The expression to be evaluated.
      Returns:
      An iterable cursor which can be used inside Aspose
    • foreach

      public Iterable foreach(Object object)

      Ability to iterate over a list based on an iterable object. This could be a list coming from a form or created with an Init Variable task or something else.

      Example:

      We're very happy to inform you that your order is ready for shipping:
      
       <<foreach [item in context.foreach(context.mapValue("${businessData}", "items"))]>>
       -   <<[context.mapValue(item,"name")]>>, with a business value of <<[context.mapValue(item, "value")]>>
       <</foreach>>
      Parameters:
      object - An iterable object which is used to iterate over.
      Returns:
      An iterable cursor which can be used inside Aspose
    • image

      public byte[] image(String expressionText)

      Displays an image within a document

      Example:

      <<image [context.image("${anImage}")] -fitWidth>>
      Parameters:
      expressionText - Expression resolving to a content item, a list of content items or bytes.
      Returns:
      The bytes of an image to be used with the image tag of the Aspose template language.
    • asHtml

      public String asHtml(String expressionText)

      The 'rich text' component stores its value either as markdown or html.

      When stored as markdown, it's possible to transform this to html using the markdownAsHtml(String) function'.

      When stored as html, the html won't be 100% perfect for using in Aspose with a Word template. Calling this method will change the html that is incompatible with using it in such a template.

      Note that it's always possible to get the 'raw html' by simply calling the value(String) method like any other component.

      Example:

      <<[context.asHtml("${unfilteredHtml}")] -html>>
      Parameters:
      expressionText - A JUEL expression which evaluates to HTML content.
      Returns:
      The text as HTML which can be used to render it in a document.
    • markdownAsHtml

      public String markdownAsHtml(String expressionText)

      Converts text as a markdown to a HTML text which can be used for rendering with Aspose. It is useful when you want to display the result of a Rich text editor within an Aspose document.

      Example:

      <<[context.markdownAsHtml("${myRichText}")] -html>>
      Parameters:
      expressionText - A JUEL expression which evaluates to a markdown field
      Returns:
      The text as HTML which can be used to render it in a document.
    • cleanHtmlForAspose

      protected String cleanHtmlForAspose(String html)
    • convertContentItemToBytes

      protected byte[] convertContentItemToBytes(ContentItem contentItem)
    • convertContentItemToBytes

      protected byte[] convertContentItemToBytes(String contentItemId)
    • resolveExpressionOrReturnDefault

      protected Object resolveExpressionOrReturnDefault(String expressionText, Object defaultValue)
    • getContentService

      protected ContentService getContentService()