Re: How to exploit ContentPart attributes (RubyHash) from Java
Posted by
Michaël Melchiore on
Apr 04, 2019; 3:36pm
URL: https://discuss.asciidoctor.org/How-to-exploit-ContentPart-attributes-RubyHash-from-Java-tp6827p6830.html
Dan,
I have switched to AsciidoctorJ 1.6.0 to use the new API.
Thank you for your input.
Michaël
Le mer. 3 avr. 2019 à 20:51, mojavelinux [via Asciidoctor :: Discussion] <
[hidden email]> a écrit :
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
--
To unsubscribe from How to exploit ContentPart attributes (RubyHash) from Java,
click here.
NAML