// {layout:get[Format]Instance('stem',index,...)} which evaluates into a
// FormatReferenceValue. Otherwise, the expression is assumed to result
// in a string which holds the old style iterated format reference such
// as 'title.1' or 'title.2.3' in which case the string is treated in
// the same way as before.
FormatReference ref = null;
if (formatRef.startsWith("{") && formatRef.endsWith("}")) {
stem = formatRef.substring(1, formatRef.length() - 1);
MarinerRequestContext mrc = pageContext.getRequestContext();
ExpressionContext ec =
MCSExpressionHelper.getExpressionContext(mrc);
try {
Expression expr = MCSExpressionHelper.createUnquotedExpression(
stem, mrc);
if (expr != null) {
Value value = expr.evaluate(ec);
if (value instanceof FormatReferenceValue) {
ref = ((FormatReferenceValue)value).
asFormatReference();
} else {
formatRef = value.stringValue().asJavaString();
}
}
} catch (ExpressionException e) {
logger.error("unexpected-exception");
}
}
// If we have a reference, then the pipeline expression used for the
// format name was a {layout:get[Format]Instance()} expression. Otherwise we
// have a 'Normal' format name or a pipeline expression that resulted
// in a string... in either case we process this as a format name and
// build a format reference from it.
if (ref == null) {
if (namespace != null) {
if (pageContext.getFormat(formatRef, namespace) != null) {
stem = formatRef;
} else {
stem = getFormatReferenceStem(formatRef);
}
int layoutDim = getFormatDimensions(stem, namespace, pageContext);
// When layoutDim == -1 the formats doesn't exist. When layoutDim == 0
// it's a regular format. In either case the number of dimensions is 0.
if (layoutDim <= 0) {
ref = new FormatReference(
stem,
NDimensionalIndex.ZERO_DIMENSIONS);
} else {
NDimensionalIndex tail =
createIndex(formatRef, layoutDim);
ref = new FormatReference(stem, tail);
}
} else {
ref = new FormatReference(formatRef,
NDimensionalIndex.ZERO_DIMENSIONS);
}
}
return ref;