} else if (item instanceof Reference) {
Object oldReferenceAttribute = null;
Map<String, Object> oldAttributes = new LinkedHashMap<String, Object>();
try {
Reference itemReference = (Reference) item;
Object object = itemReference.getObject();
if (object != null && !(object instanceof ReferentialTextMarker)) {
oldReferenceAttribute = request.getAttribute(REFERENCE_ATTRIBUTE);
request.setAttribute(REFERENCE_ATTRIBUTE, itemReference);
// For backward compatibility, ensure these field values are set directly as request attributes
for (ObjectField field : ObjectType.getInstance(RichTextReference.class).getFields()) {
String fieldName = field.getInternalName();
String fieldNamePc = StringUtils.toCamelCase(fieldName);
oldAttributes.put(fieldName, request.getAttribute(fieldName));
oldAttributes.put(fieldNamePc, request.getAttribute(fieldNamePc));
request.setAttribute(fieldName, itemReference.getState().get(fieldName));
request.setAttribute(fieldNamePc, itemReference.getState().get(fieldName));
}
PageFilter.renderObject(request, response, writer, object);
}