Hi,
how can I translate this Java[1] to XQuery according to [2]?
package com.vladsch.flexmark.samples; import com.vladsch.flexmark.util.ast.Node; import com.vladsch.flexmark.html.HtmlRenderer; import com.vladsch.flexmark.parser.Parser; import com.vladsch.flexmark.util.data.MutableDataSet; public class BasicSample { public static void main(String[] args) { MutableDataSet options = new MutableDataSet(); // uncomment to set optional extensions //options.set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create(), StrikethroughExtension.create())); // uncomment to convert soft-breaks to hard breaks //options.set(HtmlRenderer.SOFT_BREAK, "<br />\n"); Parser parser = Parser.builder(options).build(); HtmlRenderer renderer = HtmlRenderer.builder(options).build(); // You can re-use parser and renderer instances Node document = parser.parse("This is *Sparta*"); String html = renderer.render(document); // "<p>This is <em>Sparta</em></p>\n" System.out.println(html); } }
I only get so far as to:
declare namespace Node = "com.vladsch.flexmark.util.ast.Node"; declare namespace HtmlRenderer =" com.vladsch.flexmark.html.HtmlRenderer"; declare namespace Parser = "com.vladsch.flexmark.parser.Parser"; declare namespace MutableDataSet = "com.vladsch.flexmark.util.data.MutableDataSet"; declare option db:checkstrings 'false'; let $mds := MutableDataSet:new() let $builder := Parser:builder($mds) return $builder
which results in
DataSet{dataSet={}}
I found no documentation, on how to translate something as
Parser.builder(options).build()
to XQuery. How do I express the method
build()
of the instance
Parser.builder(options)
I just created?
Also, when I try the other way, by importing, for the following code
import module namespace Node = "java:com.vladsch.flexmark.util.ast.Node"; import module namespace HtmlRenderer = "java:com.vladsch.flexmark.html.HtmlRenderer"; import module namespace Parser = "java:com.vladsch.flexmark.parser.Parser"; import module namespace MutableDataSet = "java:com.vladsch.flexmark.util.data.MutableDataSet"; let $mds := MutableDataSet:new()
I get:
[XQST0059] Could not instantiate com.vladsch.flexmark.util.ast.Node: java.lang.InstantiationException.
Could it be, that it is only possible to call static properties via [1]? Am I right, that I need to write wrapper code in Java and then prepare results in a way, that I can retreive them from my own Java class?
Thank you.
[1]: https://github.com/vsch/flexmark-java/blob/master/flexmark-java-samples/src/... [2]: https://docs.basex.org/wiki/Java_Bindings [3]: https://github.com/vsch/flexmark-java
On 19.09.2020 22:54, Andreas Mixich wrote:
Hi,
how can I translate this Java[1] to XQuery according to [2]?
package com.vladsch.flexmark.samples;
import com.vladsch.flexmark.util.ast.Node; import com.vladsch.flexmark.html.HtmlRenderer; import com.vladsch.flexmark.parser.Parser; import com.vladsch.flexmark.util.data.MutableDataSet;
public class BasicSample { public static void main(String[] args) { MutableDataSet options = new MutableDataSet();
// uncomment to set optional extensions //options.set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create(), StrikethroughExtension.create()));
// uncomment to convert soft-breaks to hard breaks //options.set(HtmlRenderer.SOFT_BREAK, "<br />\n");
Parser parser = Parser.builder(options).build(); HtmlRenderer renderer = HtmlRenderer.builder(options).build();
// You can re-use parser and renderer instances Node document = parser.parse("This is *Sparta*"); String html = renderer.render(document); // "<p>This is <em>Sparta</em></p>\n" System.out.println(html); } }
I only get so far as to:
declare namespace Node = "com.vladsch.flexmark.util.ast.Node"; declare namespace HtmlRenderer =" com.vladsch.flexmark.html.HtmlRenderer"; declare namespace Parser = "com.vladsch.flexmark.parser.Parser"; declare namespace MutableDataSet = "com.vladsch.flexmark.util.data.MutableDataSet";
declare option db:checkstrings 'false';
let $mds := MutableDataSet:new() let $builder := Parser:builder($mds) return $builder
which results in
DataSet{dataSet={}}
I found no documentation, on how to translate something as
Parser.builder(options).build()
to XQuery. How do I express the method
build()
of the instance
Parser.builder(options)
I just created?
Does
import com.vladsch.flexmark.parser.Parser.Builder;
with
$builder => Parser.Builder:build()
work?
Am 19.09.2020 um 23:30 schrieb Martin Honnen:
import com.vladsch.flexmark.parser.Parser.Builder;
with
$builder => Parser.Builder:build()
Hello Martin,
thanks for taking the time!
I am not quite sure I understand. Do you want me to:
import module namespace Parser.Builder = "java:com.vladsch.flexmark.parser.Parser.Builder";
to get the `Parser.Builder` prefix for:
Parser.Builder:build()
?
In any case, I get:
[XQST0059] Java class not found: com.vladsch.flexmark.parser.Parser.Builder.
I forgot to mention, that
import module namespace Parser = "java:com.vladsch.flexmark.parser.Parser";
results in
[XQST0059] Could not instantiate com.vladsch.flexmark.parser.Parser: com.vladsch.flexmark.parser.Parser.<init>().
And that I also tried importing the class hierarchy (minus `java.lang.Object`) for `Parser.Builder` as documented in:
https://javadoc.io/doc/com.vladsch.flexmark/flexmark/latest/com/vladsch/flex...
import module namespace DataSet = "java:com.vladsch.flexmark.util.data.DataSet"; import module namespace MutableDataSet = "java:com.vladsch.flexmark.util.data.MutableDataSet"; import module namespace BuilderBase = "java:com.vladsch.flexmark.util.builder.BuilderBase"; ()
which resulted in:
[XQST0059] Could not instantiate com.vladsch.flexmark.util.builder.BuilderBase: Class org.basex.query.util.pkg.ModuleLoader can not access a member of class com.vladsch.flexmark.util.builder.BuilderBase with modifiers "protected".
On 20.09.2020 01:41, Andreas Mixich wrote:
Am 19.09.2020 um 23:30 schrieb Martin Honnen:
import com.vladsch.flexmark.parser.Parser.Builder;
with
$builder => Parser.Builder:build()
Hello Martin,
thanks for taking the time!
I am not quite sure I understand. Do you want me to:
import module namespace Parser.Builder = "java:com.vladsch.flexmark.parser.Parser.Builder";
I am not sure I have completely understood the reflection and namespace conventions but after some reading and testing it seems the inner class Builder should be accessible by
declare namespace Builder = 'java:com.vladsch.flexmark.parser.Parser$Builder';
and then
$builder => Builder:build()
should work for the variable
let $builder := Parser:builder($mds)
you have, you should be able to chain
MutableDataSet:new() => Parser:builder() => Builder:build()
Hi Andreas,
I think Martin has it right, I have some old code that does it like that [1]. You can try it via[2]
/Andy
[1] https://github.com/expkg-zone58/ex-markdown/blob/master/src/main/content/mar... [2] https://github.com/expkg-zone58/ex-markdown/releases
On Sun, 20 Sep 2020 at 15:30, Martin Honnen martin.honnen@gmx.de wrote:
On 20.09.2020 01:41, Andreas Mixich wrote:
Am 19.09.2020 um 23:30 schrieb Martin Honnen:
import com.vladsch.flexmark.parser.Parser.Builder;
with
$builder => Parser.Builder:build()
Hello Martin,
thanks for taking the time!
I am not quite sure I understand. Do you want me to:
import module namespace Parser.Builder = "java:com.vladsch.flexmark.parser.Parser.Builder";
I am not sure I have completely understood the reflection and namespace conventions but after some reading and testing it seems the inner class Builder should be accessible by
declare namespace Builder = 'java:com.vladsch.flexmark.parser.Parser$Builder';
and then
$builder => Builder:build()
should work for the variable
let $builder := Parser:builder($mds)
you have, you should be able to chain
MutableDataSet:new() => Parser:builder() => Builder:build()
Am 20.09.2020 um 19:18 schrieb Andy Bunce:
Hi Andreas,
I think Martin has it right, I have some old code that does it like that [1]. You can try it via[2]
/Andy
[1] https://github.com/expkg-zone58/ex-markdown/blob/master/src/main/content/mar... [2] https://github.com/expkg-zone58/ex-markdown/releases
Super! Thank you. It's not running out of the box (Flexmark had some major code restructuring some time ago, class paths have changed for example,
java:com.vladsch.flexmark.util.data.MutableDataSet
) but I will try to figure it out, also comparing it to Martin's code, so I can make it flow :-)
Currently I get the error:
[XPTY0004] com.vladsch.flexmark.parser.Parser$Builder:build: Multiple functions with 1.
Anyways, very much appreciated for the code example!
On 20/09/20 22:42, Andreas Mixich wrote:
Currently I get the error:
[XPTY0004] com.vladsch.flexmark.parser.Parser$Builder:build: Multiple functions with 1.
Hi Andreas,
this is because of Java distinguishes method signatures not only by number of parameters but also by type. You have to use the middle-dot notation to clearly define which method you need as in [1].
Regards,
Marco.
[1] https://docs.basex.org/wiki/Java_Bindings#Functions_and_Variables
basex-talk@mailman.uni-konstanz.de