Class LinqContext
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
protected ExpressionManager
protected VariableContainer
-
Constructor Summary
ConstructorDescriptionLinqContext
(ExpressionManager expressionManager, VariableContainer variableContainer) -
Method Summary
Modifier and TypeMethodDescriptionThe 'rich text' component stores its value either as markdown or html.boolean
booleanValue
(String expressionText) Gets a boolean value from an expression.protected String
cleanHtmlForAspose
(String html) protected byte[]
convertContentItemToBytes
(String contentItemId) protected byte[]
convertContentItemToBytes
(ContentItem contentItem) Evaluates a given expression using a specified input parameter.Evaluates a given expression using a specified input parameter.Ability to iterate over a list based on an iterable object.Ability to iterate over a list based on an expression which evaluates to an iterable item.protected ContentService
boolean
Checks if a (nested) value from a map, JSON node, or variable container exists.protected Boolean
hasValueSimple
(Object obj, String key) byte[]
Displays an image within a documentRetrieves a (nested) value from a map, JSON node, or variable container.protected Object
mapValueSimple
(Object obj, String key) markdownAsHtml
(String expressionText) Converts text as a markdown to a HTML text which can be used for rendering with Aspose.protected Object
resolveExpressionOrReturnDefault
(String expressionText, Object defaultValue) protected Object
Gets a value from an expression.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.
-
Field Details
-
CONTEXT_NAME
- See Also:
-
expressionManager
-
variableContainer
-
-
Constructor Details
-
LinqContext
-
-
Method Details
-
valueOrDefault
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 rendereddefaultValue
- 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
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
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
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 returnfalse
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 aMap
, aVariableContainer
or aJsonNode
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
-
mapValue
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 returnnull
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 aMap
, aVariableContainer
or aJsonNode
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
-
evaluate
Evaluates a given expression using a specified input parameter. It takes exactly one
item
which is either aMap
, aVariableContainer
or aJsonNode
. 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 specifieditem
.item
- The item which must be either aMap
, aVariableContainer
or aJsonNode
.- Returns:
- The result of the evaluated expression.
- Since:
- 3.14.0
-
evaluate
Evaluates a given expression using a specified input parameter. This method accepts any type of
item
, which is identified by anitemName
. ThisitemName
provides a way to reference the inputitem
within the expression. The expression has access to all variables present in the document's context.The provided
item
is accessible via itsitemName
, 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 theitem
to conform to any specific type, while the givenitem
can be fully utilized within expressions.- Parameters:
expression
- The JUEL expression to evaluate, considering the current context and specifieditem
.item
- The specific object made available under theitemName
.itemName
- The identifier used to reference theitem
within the expression.- Returns:
- The result of the evaluated expression.
- Since:
- 3.14.0
-
toValue
-
foreach
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
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
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
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
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
-
convertContentItemToBytes
-
convertContentItemToBytes
-
resolveExpressionOrReturnDefault
-
getContentService
-