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 - Templates Created Using "Save As Template" Cannot Use FreeMarker
Summary: Templates Created Using "Save As Template" Cannot Use FreeMarker
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Favorites (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Jiri Rechtacek
URL:
Keywords:
Depends on:
Blocks: 153941
  Show dependency tree
 
Reported: 2008-09-30 17:30 UTC by tomwheeler
Modified: 2009-02-19 22:53 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Proof-of-concept action which lets the user mark a template as a freemarker template (3.75 KB, text/plain)
2008-09-30 17:32 UTC, tomwheeler
Details

Note You need to log in before you can comment on or make changes to this bug.
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