Wednesday April 11, 2007
Module of the Century: Sandip's Regular Expression Highlighter
It's not often that I post more than one blog entry in a day, so this means that what I have to share is pretty significant. I'm no hero when it comes to regular expressions, so I installed the NBM file from http://www.nbextras.org and then installed Sandip's Regular Expression Highlighter from the newly installed nbextras update center. I needed to construct a regular expression that would capture a "class" attribute in an xwork.xml file, together with its value. After that, even more challenging, I needed to construct a regular expression that would capture everything from an opening <action> tag to a closing </action> tag. So, I started typing in the text field that you see in the toolbar in the screenshot below. As I typed regular expressions, everything in the document that was captured by the expression was highlighted, while I was typing. Not soon after, through trial and error, I had my expression:
Result: class="[a-z."]*
Similarly, I constructed a regular expression for capturing my <action> tags, across multiple lines:
Result: <action [a-z0-9A-Z=" .>]*|<r[a-z=" .></]*|</action>
I realize the results do not cover all possibilities, nor are they perfectly formulated. But clearly they're a good start. Thanks Sandip! Very useful. It really is ideal for learning how regular expressions work. I hope it will be part of 6.0.
Apr 11 2007, 10:37:32 AM PDT Permalink
Show/Hide Menu Items Based on Deployment Descriptor Content
Something I'm pretty proud of... two new menu items, which only appear on a Java node if the web.xml file registers certain WebWork artifacts, such as its filter:
Really cool bit of code. When the menu item is selected, an Action element is added to the xwork.xml file. The unregistering isn't complete yet, I'll have to look for a regular expression and then remove it. But being able to show/hide a menu item on a Java node depending on the presence/absence of something in web.xml is pretty useful. It makes complete sense to assume that the WebWork artifacts are registered in the web.xml, because that's what happens when you complete the New Project wizard for WebWork, i.e., by the end of the wizard you'll have selected 'WebWork', and then the wizard adds the WebWork filter to the web.xml file. Struts and JSF have a similar approach in NetBeans IDE, for detecting whether or not they are supported by the current application, in the Project Properties dialog box, to show/hide the possibility of adding them, which implies that something shouldn't be there, otherwise you shouldn't be able to add it. Fun, fun.
A different (better?) approach might be to check the classpath for the presence of the WebWork JAR file. (Or to write a .webwork file to the home directory, or to the NetBeans user directory, when the wizard finishes and "WebWork" was selected and to then check for the presence of that file when determining whether to show/hide the menu items.)
Apr 11 2007, 06:01:47 AM PDT Permalink


