This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 148771

Summary: Templates Created Using "Save As Template" Cannot Use FreeMarker
Product: platform Reporter: tomwheeler <tomwheeler>
Component: FavoritesAssignee: Jiri Rechtacek <jrechtacek>
Status: RESOLVED FIXED    
Severity: blocker    
Priority: P2    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:
Bug Depends on:    
Bug Blocks: 153941    
Attachments: Proof-of-concept action which lets the user mark a template as a freemarker template

Description tomwheeler 2008-09-30 17:30:35 UTC
This is in response to a thread on the nbdev list
(http://www.netbeans.org/servlets/BrowseList?list=nbdev&by=thread&from=875497).  

Consider the following scenario:

1.  User sees that the File-> New Java Class template has tokens like ${package} and ${name}.  These are replaced at the
time of file creation with their corresponding values (in this case, the package and name of the newly created class).

2.  User wants to create a custom template, for example, for a specific type of Java class and so he creates a source
file with these same tokens.

3.  User right-clicks on the source file's node, chooses "Save As Template" and then saves it into the desired category
(e.g. "Java")

4.  User goes to File -> New File, selects the "Java" category and chooses the template from the previous step.

5.  User specifies the name and location of the file to create and clicks "Finish"

6.  User finds that the tokens are not replaced as expected.  The source file created from the template contains literal
${package} and ${name} instead of having those tokens replaced with the new class' package and name as was done for the
Java source file described in step 1.

The only workaround that I know of involves writing a module that will set the "javax.script.ScriptEngine" attribute to
"freemarker" on the template's FileObject in the system filesystem.  However, it is unreasonable to expect someone who
is merely using the IDE to have to do this.  Therefore, I think the IDE should have some user interface for marking a
template as a freemarker template.

I have written a very simple action which lets you do this and will attach it to this issue momentarily.  It is intended
more as a proof-of-concept than an actual implementation, since the actual implementation could be as simple as a new
action on the existing template node.
Comment 1 tomwheeler 2008-09-30 17:32:26 UTC
Created attachment 70920 [details]
Proof-of-concept action which lets the user mark a template as a freemarker template
Comment 2 tomwheeler 2008-09-30 18:28:19 UTC
I thought of a workaround. It's not ideal, but should suffice until the issue is implemented.  Instead of saving a
source file as a template, do this:

1.  Go to Tools -> Templates
2.  Expand some category (e.g. "Java")
3.  Select an existing template which uses JFreeMarker (e.g. "Java Class")
4.  Click the Duplicate button
5.  Rename the new template as desired (e.g. "Extra Special Java Class")
6.  Click the "Open In Editor" button at the bottom of the dialog
7.  Edit the template as desired, using standard tokens like ${package} and ${class}
8.  Save the changes to the template

You should then find the new template works as expected because the "javax.script.ScriptEngine" attribute should have
been retained when duplicating the template.
Comment 3 Jiri Rechtacek 2008-12-05 15:29:48 UTC
fixed in core-main/rev/e0dacb6e3de2
Comment 4 Quality Engineering 2008-12-07 05:28:58 UTC
Integrated into 'main-golden', will be available in build *200812070201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/d79a9c3c04f3
User: Jiri Rechtacek <jrechtacek@netbeans.org>
Log: #148771: Templates Created Using "Save As Template" Cannot Use FreeMarker