How to exploit ContentPart attributes (RubyHash) from Java
Posted by Michaël Melchiore on Apr 03, 2019; 1:03pm
URL: https://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827.html
Hello,
I am writing a simple tool in Java to parse the content of simple AsciiDoc files using AsciidoctorJ 1.5.6.
The documents define some header attributes which may be overriden later in the document.
In the following code, I initialize an attribute map from the document header. Then, I want to update it with attributes from the current ContentPart.
StructuredDocument document = asciidoctor.readDocumentStructure(file, Collections.emptyMap());
DocumentHeader header = document.getHeader();
// Initialize attributes with header content
Map<String, Object> attributes = new HashMap<>(header.getAttributes());
for (ContentPart part : document.getParts()) {
// Then overwrite with section attributes
attributes.putAll(part.getAttributes());
String id = (String) attributes.get("id");
String title = (String) attributes.get("title");
....
}
Sadly, this does not work. The document header attributes are exposed as a Java HashMap but content part attributes are exposed through a RubyHash object with a surprising structure (at least to me).
Can someone help me convert the RubyHash into a HashMap ?
Kind regards,
Michaël