private String extractValue(Object value) {
if (value == null) return "null";
if (value instanceof BeanReference) return "@" + ((BeanReference) value).getBeanName();
if (value instanceof BeanDefinition) {
String className = ((BeanDefinition) value).getBeanClassName();
return className != null ? className.substring(className.lastIndexOf('.') + 1) : "InnerBean";
}
if (value instanceof TypedStringValue) return xmlEscape(((TypedStringValue) value).getValue());
if (value instanceof List) {
List<String> cleaned = new ArrayList<>();
int count = 0;
for (Object item : (List<?>) value) {
if (count++ >= 10) { cleaned.add("..."); break; }
cleaned.add(extractValue(item));
}
// Use the RAW tag here; we will ensure it isn't escaped later
return String.join("<BR ALIGN=\"LEFT\"/>", cleaned);
}
String s = value.toString();
return xmlEscape(s.length() > 60 ? s.substring(0, 57) + "..." : s);
}
// UPDATED: This now builds the table string carefully
private void writeToDotFile(String name, String color, List<PropertyValue> props, ConstructorArgumentValues cav) {
StringBuilder label = new StringBuilder("<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" BGCOLOR=\"" + color + "\">");
label.append("<TR><TD COLSPAN=\"2\"><B>").append(xmlEscape(name)).append("</B></TD></TR>");
for (PropertyValue pv : props) {
String cleanVal = extractValue(pv.getValue());
label.append("<TR><TD ALIGN=\"LEFT\">").append(xmlEscape(pv.getName())).append("</TD>");
// IMPORTANT: cleanVal already contains <BR/> tags and escaped text
label.append("<TD ALIGN=\"LEFT\">").append(cleanVal).append("</TD></TR>");
}
// Process Constructor Args
for (Map.Entry<Integer, ConstructorArgumentValues.ValueHolder> entry : cav.getIndexedArgumentValues().entrySet()) {
String cleanVal = extractValue(entry.getValue().getValue());
label.append("<TR><TD ALIGN=\"LEFT\"><I>arg[").append(entry.getKey()).append("]</I></TD>");
label.append("<TD ALIGN=\"LEFT\">").append(cleanVal).append("</TD></TR>");
}
label.append("</TABLE>");
// Output to DOT file with SINGLE brackets for HTML labels
// Format: "beanName" [label=< ...HTML... >];
dotFileWriter.append(String.format(" \"%s\" [label=<%s>];\n", name, label.toString()));
}
private String xmlEscape(String input) {
if (input == null) return "";
// Only escape characters that break HTML, but do NOT escape our intentional tags
return input.replace("&", "&")
.replace("<", "<")
.replace(">", ">")
.replace("\"", """)
.replace("'", "'")
// Reverse the escape for our specific BR tag so it remains functional
.replace("<BR ALIGN="LEFT"/>", "<BR ALIGN=\"LEFT\"/>");
}
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)