private String extractValue(Object value) {
if (value == null) return "null";
// 1. Handle Bean References (@name)
if (value instanceof BeanReference) {
return "@" + ((BeanReference) value).getBeanName();
}
// 2. Handle TypedStringValue (Strips the "TypedStringValue: value [XX]" noise)
if (value instanceof TypedStringValue) {
String actualValue = ((TypedStringValue) value).getValue();
// Applying trim() directly to the extracted value
return xmlEscape(actualValue != null ? actualValue.trim() : "null");
}
// 3. Handle Inner Bean Definitions (Shows only the short class name)
if (value instanceof BeanDefinition) {
String className = ((BeanDefinition) value).getBeanClassName();
if (className != null) {
String shortName = className.substring(className.lastIndexOf('.') + 1);
return "<i>" + shortName.trim() + "</i>";
}
return "<i>InnerBean</i>";
}
// 4. Handle Lists (Recursive Clean)
if (value instanceof List) {
List<String> cleaned = new ArrayList<>();
int count = 0;
for (Object item : (List<?>) value) {
if (count++ >= 12) {
cleaned.add("...");
break;
}
cleaned.add(extractValue(item));
}
return String.join("<BR ALIGN=\"LEFT\"/>", cleaned);
}
// 5. Handle Maps
if (value instanceof Map) {
StringBuilder mapStr = new StringBuilder();
int count = 0;
for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
if (count++ >= 10) {
mapStr.append("...more...");
break;
}
mapStr.append(extractValue(entry.getKey()))
.append("=")
.append(extractValue(entry.getValue()))
.append("<BR ALIGN=\"LEFT\"/>");
}
return mapStr.toString();
}
// Default fallback for any other objects
String s = value.toString().trim();
return xmlEscape(s.length() > 60 ? s.substring(0, 57).trim() + "..." : s);
}
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)