Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


ID: 22795, MacBsh: Bsh Macros for Use in Code Templates

by Ken Sipe Email: Anonymous


MacBsh provides the ability to configure code template macros through xml. When the macro is invoked the code provided in xml is executed via beanshell.
Download Details
FTP  download also available
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For JBuilder, Version 9.0  to 11.0 46 downloads
Copyright: No significant restrictions


Size: 270,333 bytes
Updated on Tue, 23 Nov 2004 05:42:31 GMT
Originally uploaded on Mon, 22 Nov 2004 14:25:15 GMT
SHA1 Hash: 89AF5BE28BC8D66C64AB25BF331297C3AD9CE66B
MD5 Hash: A1FFAB5E045B3CA7364C0AA45E1F1DA2

    Explore the files in this upload

Description
MacBsh provides the ability to configure code template macros through xml. It configures new macros for the template framework. When the macro is invoked the code provided in xml is executed through the beanshell.

To install:
MacBsh is dependent on Beanshell (Bsh) http://www.beanshell.org/ . The beanshell jar, the MacBsh.jar and the MacBsh.xml must be placed the into your \jbuilder\lib\ext directory and restart JBuilder.

To remove, just delete the jars.

To edit/create a Code Template, go to Tools | Preferences | Editor | Templates and choose the file type (or "Common" if want the template to appear in all file types). The new macros will be among the pre-defined ones when using the "Macro..." button. To insert a Code Template, click in the Editor, do Ctrl+J, and select the template by clicking on it or by typing its name.

In order to configure your own macros there are a number of configuration options. The simplest of which is listed below:


Direct Replacement example

value = "\"JB Rocks\"";




This registers a macro named “$AnotherExample” with the description of “Direct Replacement example”. When configured in a template and the template is executed the value of “JB Rocks” will replace the macro. A more complicated example might look like this:

TodayMonthDayYear
Current date MM/DD/YYYY

[CDATA[
import java.text.*;
import java.util.*;

NumberFormat NF = NumberFormat.getInstance();
Calendar calendar = Calendar.getInstance();

StringBuffer sb = new StringBuffer();
sb.append(NF.format(1 + calendar.get(Calendar.MONTH)));
sb.append("/");
sb.append(NF.format(calendar.get(Calendar.DAY_OF_MONTH)));
sb.append("/");
sb.append(calendar.get(Calendar.YEAR));
value = sb.toString();
]]



Read the xml file more details.

This OT was inspired by a question on the newsgroup by Gil, which was answered by Gillmer. The examples given are taken from Bill Joy’s example. The source is provided.

I would like the following future enhancements if someone else is up for it.
1) An editor to configure the xml.
2) The ability to configure the node type for the macro
3) The ability to pass in the method arguments to the Bsh engine.

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC03