Re: How to exploit ContentPart attributes (RubyHash) from Java
Posted by
mojavelinux on
Apr 03, 2019; 6:51pm
URL: https://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6828.html
Michaël,
The newer API converts all types as you would expect them to be converted.
Cheers,
-Dan
On Wed, Apr 3, 2019 at 7:03 AM Michaël Melchiore [via Asciidoctor :: Discussion] <
[hidden email]> wrote:
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
--