[Kde-java] XSLT to generate Java sources
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Mon May 26 13:19:34 CEST 2003
On Sunday 25 May 2003 10:11, Marco Ladermann wrote:
> after several month of work (okay, to be honest, I coded only at the
> weekend), I have here some XSLT stylesheets that can read UI files
> generated by the designer and write some Java code. In the moment I have
> focused primarily on pure Qt elements, but it should be no big thing to
> also include KDE elements.
>
> In the "bin" subdirectory of the distribution is a shellscript (juic) to
> start the transformation. The script tries to find xsltproc as processor
> but the transformation can also be run with saxon or xalan.
>
> I found some problems with the latest libxml2.so causing an error in some
> for-each. Currently I'm using:
>
> xsltproc -V:
> : Using libxml 20503, libxslt 10026 and libexslt 717
> : xsltproc was compiled against libxml 20503, libxslt 10026 and libexslt
> : 717 libxslt 10026 was compiled against libxml 20503
> : libexslt 717 was compiled against libxml 20503
>
> The jar files for saxon and xalan are not included in the tar file. They
> can be found at:
>
> saxon: http://prdownloads.sourceforge.net/saxon/saxon6_5.zip?download
> (Saxon 7 does not work!) Copy saxon.jar to lib/saxon
>
> xalan: http://xml.apache.org/xalan-j/downloads.html
> (Xalan versions less than 2.5.0 do not work) Copy xalan.jar,
> xercesImpl.jar, and xml-apis.jar to lib/xalan.
>
> Because you can't read arbitrary files with XSLT (only xml) the stylesheets
> ignore any code written for the slots in the xyz.ui.h files. All slots (and
> the class itself) are declared "abstract". If you want a dummy
> implementation for the slots you can run the script with:
>
> juic -abstract false xyz.ui
>
> The usage pattern for the script is
> Usage: juic [options] uifile
> Where options can be:
> -proc (xsltproc | xalan | saxon) : Processor to use, defaults to
> "xsltproc"
> -package "the.package.for.the.class" : Generates a package
> declaration -abstract (true | false) : Slots are declared
> abstract, defaults to "true"
> -images dir : Path to images, defaults to
> "images"
> -os (unix | msdos | mac) : Selects newline characters
>
> I hope this stylesheets are of some use for some people out there and will
> help to popularize the java-bindings.
>
> Any comments to improve the stylesheets are welcome!
I've just been having a look through the juic stylesheets - this is really
interesting stuff! And good it works with both xalan and xsltproc and
doesn't need extensions.
One minor thing - the <classname>EventHandling.java classes are no longer
generated - the event handling methods are generated as normal java methods
in the classes now, so those interfaces aren't needed anymore. The virtual
method callbacks for Widget::polish() aren't implemented yet, I don't know if
that causes a big problem.
When you first mentioned that you were using XSLT with the uic, I didn't
really know in detail what XSLT was all about. But since then I've got a few
books and tried it out, and I think that the whole QtJava bindings can be
generated that way. Just need to parse the headers with the kalyptus, and
write out .xml files for each C++ class. Or alternatively there is some
discussion on the kde-bindings list about extracting .xml C++ class info
directly from gcc compiled code, without needing to parse the headers.
Then it might be possible to derive a juic stylesheet like 'QtClasses.xml'
which lists all the Qt and KDE classnames, from the same XML database that
would be used as the input to the main QtJava bindings generation.
Anyway I can study how your code works for now, and try it out - it looks like
an ideal way to get up to speed with this XSLT stuff..
-- Richard
More information about the Kde-java
mailing list