Content Expression Language (CEL)

RICOH ProcessDirector Content Expression Language (CEL) lets you define expressions that specify content and placement of enhancements (barcodes, text, and hidden areas) to documents in AFP files. If you have the Inserter feature, CEL lets you define expressions in inserter rules files that write inserter control files, and analyze and interpret inserter results files.

Operators

This table shows the order of operator precedence from highest to lowest precedence.

Operator name Description
( ) Function parameter delimiter
( ) Grouping
+, - Unary
*, /, % Multiply, divide, modulo
+, - Addition, subtraction
==, !=, >, >=, <, <= Relational
(implicit) Concatenation

Example:f(3+x)*5 is f(3+x) multiplied by 5.

Language

Pattern Template example Real example Result
concatenation 'string1' 'string2' 'a' func 'b' aVARb if func='VAR'
relational expressions func1 [relational_operator] func2 func1 > func2 True if func1=5 and func2=1
or condition or(expr1,expr2,....) or(a>100,a==0,b==1) True if any of the expressions evaluate to true
and condition and(expr1,expr2,...) and(a>3,a<10) True if all of the expressions evaluate to true
not condition not(expr1) not(a==b) True if all of the expressions evaluate to false
decision if(relational_expression,trueexpr,falseexpr) if(a>v,1,0) If the relational expression is true, the value is set to trueexpr. If the relational expression is false, the value is set to falseexpr.
decision if(value,trueexpr,falseexpr) if(func2,'true','false') If func2 has a numeric value not equal to 0 or a string value not equal to the empty string, the string literal is true, otherwise false.

Equivalent statements

Base Equivalent Comments
a a() Variables are functions without ().
'*' a '*'a() Concatenation does not require spaces between inputs, and the function a can be represented either way.

EBNF Language Definition

In this Extended Backus-Naur Form (EBNF), a CEL expression is represented by the expr production. The relational and numeric operations behave as their C-language counterparts. Consecutive expressions are strung together to produce a result.

expr = "(", expr, ")" | catenation | numexpr | relexpr | ("+" | "-"), expr | function call | string | number;catenation = expr, expr;numexpr = expr, ("+" | "-" | "*" | "/" | "%"), expr;relexpr = expr, ("==" | "!=" | "<" | ">" | "<=" | ">="), expr;function call = identifier, [ "(", parameters, ")" ];parameters = expr, { ",", expr };identifier = (alpha | "_"), { (alpha | "_" | digit ) };string = "'", (* sequence of characters, with standard \\ escapes *), "'";number = (digit { digit }) | ({ digit } . {digit});

Note: There are no variables, only function calls; a function call without a parameter specification looks and behaves exactly like a variable.

Built-in context functions

Function name Syntax Description
substr substr(f,start [,length]) start is a position from the end of the string. start is zero based. start can be negative.
trim trim(string [, charsToTrim]) Trim blanks (or the list of characters specified in charsToTrim) from the left and the right of string.
rtrim rtrim(string [, charsToTrim]) Trim blanks (or the list of characters specified in charsToTrim) from the right of string.
ltrim ltrim(string [, charsToTrim]) Trim blanks (or the list of characters specified in charsToTrim) from the left of string.
indexof indexof(string, substr [, start ]) Return the start index location of the substring within the string. If the substr is not found, -1 is returned.
fmt fmt(formatString [,values]... ) Format the values using the formatString.
tr tr(string, fromChars [, toChars]) Translate the characters that match fromChars in the string into the corresponding toChars. If the fromChars character does not have a corresponding character in toChars (position match), the fromChar is removed from the input string. If toChars is omitted, all characters listed in fromChars are removed in the returned value.
bin bin(string [, trueChar ]) Using trueChar as on-bits in the string, the input string is converted into a number. If trueChar is omitted, "1" is the on-bit.
fmtbase fmtbase(value, numChars [, baseString ]) If baseString is omitted, it is assumed to be "0123456789ABCDEF", returning the rightmost numChars after converting value into the base represented by baseString. baseString can be any list of characters, assuming that the leftmost character represents zero and the rightmost represents the highest value of the base system being converted into.
exists exists(value) Evaluates to true if the value evaluates to true. (This function is equivalent to the defined function.)
defined defined(value) Evaluates to true if the value evaluates to true. If the value is a RICOH ProcessDirector property name, this function returns true if the property is defined in the database. If a property is defined in the database, you can refer to it in other CEL functions.
len len(string) Returns the number of characters in the input string.
nil nil Returns a value that you can use in CEL functions to represent a null value.
aggr [aggr=sum] [aggr=max] [aggr=min] Returns the sum, maximum, or minimum value of an expression (expr) evaluated against all documents in the job. If you have the Inserter feature, you can use this function in the rules file for the inserter control file header record.

Record context functions

Function name Syntax Description
field_name field_name or field_name() The value of the field for the current record in the context.
recnum recnum or recnum() The record number of the current record being used in the context.

Record caching context functions

Function name Syntax Description
field_name field_name or field_name(offset) If offset is 0 or missing, the value of the field for the current record in the context. If offset is a positive number, the value of the field for the record offset ahead. If offset is a negative number, the value of the field for the record offset behind. The maximum number of records currently cached behind is 10. The number of records cached ahead can be any value and is dynamically determined during processing.
recnum recnum or recnum() The record number of the current record being used in the context.

Examples

Expression Explanation
if(or(a>100,a==0),1,0) If the value of a is either greater than 100 or equal to 0, this expression evaluates to 1; otherwise it evaluates to 0.
if(and(a>3,a<10),1,0) If the value of a is greater than 3 and less than 10, this expression evaluates to 1; otherwise it evaluates to 0.
if(fld,fld,'') Treats a missing value as an empty string; otherwise, treats the missing value as undefined, which is different from a blank value.
fmtbase(if(output_bin=='2',1,0) + if(output_bin=='3',2,0) + if(meter == '1', 4,0) , 1) Returns a hexadecimal number, where the low-order bit (from the right) indicates whether output_bin is set to 2, the second bit indicates whether output_bin is set to 3, and the third bit indicates whether meter is set to 1.
fmtbase(if(meter=='2',1,0) + if(substr(mch_isrt_bins,0,1)=='Y',2,0) + if(substr(mch_isrt_bins,1,1)=='Y',4,0) , 1 ) Returns a hexadecimal number, where the low-order bit (from the right) indicates whether meter is set to 2, the second bit indicates whether the first character of mch_isrt_bins is set to 'Y', and the third bit indicates whether the second character of mch_isrt_bins is set to 'Y'.
fmtbase(63,2,"0123456789ABCDFGHJKLMNPQRSTVWXYZ") Converts 63 into "1Z". Any string can be used as the base.
tr('abc', 'b') Removes all 'b' characters.
tr('00101', '01', 'NY') Converts '0' to 'N' and '1' to 'Y'. Results in 'NNYNY'.
tr('00101', '0123456789Y', 'YYYYYYYYYYN') == 'YYYYY' Evaluates to true if all the characters in '00101' are digits. '00101' can be replaced by a function value of 5 characters.
len(tr('00101','0')) Evaluates to 2. Removes all '0's from the input string, and returns the length of the remaining characters. Effectively counts the number of '1's in the input string.
[expr=Doc.TotalSheets] [aggr=sum] Returns the sum of all the values in the Doc.TotalSheets property in all documents in the job.
[expr=Doc.TotalSheets] [aggr=max] Returns the maximum value in the Doc.TotalSheets property in all documents in the job.
[expr=Doc.TotalSheets] [aggr=min] Returns the minimum value in the Doc.TotalSheets property in all documents in the job.
[expr=recnum>1] Ignore the first line of the file. (Read only record numbers greater than 1.)