After hours of tinkering around, reading API documentation and learning Netbeaning, I have put the Netbeans XML hyperlinking project into orbit with the absolute ab-initio implementation of the first phase "Hyperlinking of a sub-element declaration to it's corresponding definition within the same DTD document", which comes under Use Case 2 in DTD use cases as described in our project's
Dzone article.
Take a sneak peak at it in the NBXMLHyperlinking Screencast #1:
For example, in the following element definition:
<!--ELEMENT web-app (icon?, display-name?, description?, distributable?, context-param*, filter*, filter-mapping*, listener*, servlet*, servlet-mapping*, session-config?, mime-mapping*, welcome-file-list?, error-page*, taglib*, resource-env-ref*, resource-ref*, security-constraint*, login-config?, security-role*, env-entry*, ejb-ref*, ejb-local-ref*)-->
Clicking on "icon" takes the user to it's corresponding definition:
<!--ELEMENT icon (small-icon?, large-icon?)-->
I had written a complete explanation of the implementation, with references to the places which proved useful, though that blog post just got cursed due to a system crash and I am in no mood of typing all that again. Anyway, FWIW, the folks over at the
XML-DEV mailing lists were very helpful in providing me the
official specification for DTD, and thanks to Rohan and the Netbeans OpenIDE mailing list for heading me in the right direction to get syntax support for DTD's in Netbeans and other problems that keep cropping up. After a lot of tinkering, in the middle of the night, yesterday, I figured out that the DTD lexer implementation in Netbeans uses Java CC. Take a look at the sources under o.n.m.xml.text.syntax and o.n.m.xml.text.syntax.javacc. If you want to learn how to implement custom hyperlinking in the editor, go through this
nice tutorial.
I've basically implemented the
HyperlinkProvider class. The first step is to determine whether the language element under the mouse cursor should be hyperlinked (isHyperlinkPoint) which is done by simple rule-based inferencing to check if the token in context is a sub-element or not. The biggest hurdle here was to get a
token stream from the editor, since DTD support is kind of non-standard in Netbeans (the older ExtSyntaxSupport). The second step is to perform the actual "jump" action, to take the user to the source element definition, which I've done with regular expression patter matching.
RegExPlugin came in handy again ;)
During the exploration part, when I was going through the DTD specs, XML tutorials, et al, and I've identified a few more use cases for hyperlinking within DTD files. Those will be furnished along with a detailed design document at wiki.netbeans.org soon. This is just a kick-off of the project and the brushed up well documented source code with unit tests will be pushed to the Netbeans HG repository under the /main/contrib folder once the initial phase completes.
Technorati Tags: netbeans,hyperlinking,xml,dtd,screencast
nice work!
Posted by Aditya on June 13, 2008 at 07:18 PM IST #