Skip to content

Commit 34e47c1

Browse files
committed
EQX-211: Added FreeMarker support to AMP.
1 parent e2bc1ed commit 34e47c1

File tree

7 files changed

+225
-7
lines changed

7 files changed

+225
-7
lines changed

plugins/appfuse-maven-plugin/build.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@
7171
<target name="test-spring-light" description="tests plugin with spring light archetype">
7272
<create-gen-basic archetype="appfuse-light-spring" name="light-spring"/>
7373
</target>
74-
74+
75+
<target name="test-spring-freemarker-light" description="tests plugin with spring light freemarker archetype">
76+
<create-gen-basic archetype="appfuse-light-spring-freemarker" name="light-spring-freemarker"/>
77+
</target>
78+
7579
<target name="test-spring-security-light" description="tests plugin with spring security light archetype">
7680
<create-gen-basic archetype="appfuse-light-spring-security" name="light-spring-security"/>
7781
</target>

plugins/appfuse-maven-plugin/src/main/java/org/appfuse/tool/AppFuseExporter.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private void generateWeb() {
133133

134134
// configuration
135135
configureExporter("appfuse/web/jsf/navigation.ftl", "src/main/webapp/WEB-INF/{class-name}-navigation.xml").start();
136-
} else if (webFramework.equalsIgnoreCase("spring") || webFramework.equalsIgnoreCase("spring-security")) {
136+
} else if (webFramework.equalsIgnoreCase("spring") || webFramework.equalsIgnoreCase("spring-security") || webFramework.equalsIgnoreCase("spring-freemarker")) {
137137
// tests
138138
configureExporter("appfuse/web/spring/controller-test.ftl", "src/test/java/{basepkg-name}/webapp/controller/{class-name}ControllerTest.java").start();
139139
configureExporter("appfuse/web/spring/formcontroller-test.ftl", "src/test/java/{basepkg-name}/webapp/controller/{class-name}FormControllerTest.java").start();
@@ -143,8 +143,13 @@ private void generateWeb() {
143143
configureExporter("appfuse/web/spring/formcontroller.ftl", "src/main/java/{basepkg-name}/webapp/controller/{class-name}FormController.java").start();
144144

145145
// views
146-
configureExporter("appfuse/web/spring/list-view.ftl", "src/main/webapp/WEB-INF/pages/{class-name}s.jsp").start();
147-
configureExporter("appfuse/web/spring/form-view.ftl", "src/main/webapp/WEB-INF/pages/{class-name}form.jsp").start();
146+
if (!webFramework.equalsIgnoreCase("spring-freemarker")) {
147+
configureExporter("appfuse/web/spring/list-view.ftl", "src/main/webapp/WEB-INF/pages/{class-name}s.jsp").start();
148+
configureExporter("appfuse/web/spring/form-view.ftl", "src/main/webapp/WEB-INF/pages/{class-name}form.jsp").start();
149+
} else {
150+
configureExporter("appfuse/web/spring-freemarker/list-view.ftl", "src/main/webapp/{class-name}list.ftl").start();
151+
configureExporter("appfuse/web/spring-freemarker/form-view.ftl", "src/main/webapp/{class-name}form.ftl").start();
152+
}
148153

149154
// validation
150155
configureExporter("appfuse/web/spring/form-validation.ftl", "src/main/webapp/WEB-INF/{class-name}-validation.xml").start();
@@ -190,7 +195,11 @@ private void generateWeb() {
190195
// menu
191196
if (!webFramework.equalsIgnoreCase("tapestry")) {
192197
configureExporter("appfuse/web/menu.ftl", "src/main/webapp/common/{class-name}-menu.jsp").start();
193-
configureExporter("appfuse/web/menu-light.ftl", "src/main/webapp/common/{class-name}-menu-light.jsp").start();
198+
if (webFramework.equalsIgnoreCase("spring-freemarker")) {
199+
configureExporter("appfuse/web/menu-light-freemarker.ftl", "src/main/webapp/common/{class-name}-menu-light.ftl").start();
200+
} else {
201+
configureExporter("appfuse/web/menu-light.ftl", "src/main/webapp/common/{class-name}-menu-light.jsp").start();
202+
}
194203
configureExporter("appfuse/web/menu-config.ftl", "src/main/webapp/WEB-INF/{class-name}-menu-config.xml").start();
195204
} else {
196205
configureExporter("appfuse/web/tapestry/menu.ftl", "src/main/webapp/{class-name}-menu.tml").start();
@@ -200,10 +209,14 @@ private void generateWeb() {
200209
configureExporter("appfuse/web/ApplicationResources.ftl", "src/main/resources/{class-name}-ApplicationResources.properties").start();
201210

202211
// canoo tests
203-
if (!webFramework.equals("spring-security")) {
212+
if (!webFramework.equals("spring-security") && !webFramework.equalsIgnoreCase("spring-freemarker")) {
204213
configureExporter("appfuse/web/" + webFramework + "/web-tests.ftl", "src/test/resources/{class-name}-web-tests.xml").start();
205214
}
206215
// jwebunit tests
216+
if (webFramework.equalsIgnoreCase("spring-freemarker")) {
217+
webFramework = "spring";
218+
jwebUnitTemplate = new ClassPathResource("appfuse/web/" + webFramework + "/jwebunit-tests.ftl");
219+
}
207220
if (jwebUnitTemplate.exists()) {
208221
configureExporter("appfuse/web/" + webFramework + "/jwebunit-tests.ftl", "src/test/java/{basepkg-name}/webapp/{class-name}WebTest.java").start();
209222
}

plugins/appfuse-maven-plugin/src/main/java/org/appfuse/tool/ArtifactInstaller.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public void execute() {
9393
log("Installing Spring views and configuring...");
9494
installSpringValidation();
9595
installSpringViews(pagesPath);
96+
} else if ("spring-freemarker".equalsIgnoreCase(webFramework)) {
97+
log("Installing Freemarker views...");
98+
installSpringFreemarkerViews(pagesPath);
9699
} else if ("tapestry".equalsIgnoreCase(webFramework)) {
97100
log("Installing Tapestry views and configuring...");
98101
installTapestryViews();
@@ -261,6 +264,17 @@ private void installSpringViews(String pagesPath) {
261264
copy.execute();
262265
}
263266

267+
private void installSpringFreemarkerViews(String pagesPath) {
268+
Copy copy = (Copy) antProject.createTask("copy");
269+
copy.setFile(new File(sourceDirectory + "/src/main/webapp/" + pojoName + "form.ftl"));
270+
copy.setTofile(new File(destinationDirectory + pagesPath + pojoNameLower + "form.ftl"));
271+
copy.execute();
272+
273+
copy.setFile(new File(sourceDirectory + "/src/main/webapp/" + pojoName + "list.ftl"));
274+
copy.setTofile(new File(destinationDirectory + pagesPath + util.getPluralForWord(pojoNameLower) + ".ftl"));
275+
copy.execute();
276+
}
277+
264278
private void installStrutsViews(String pagesPath) {
265279
Copy copy = (Copy) antProject.createTask("copy");
266280
copy.setFile(new File(sourceDirectory + "/src/main/webapp/WEB-INF/pages/" + pojoName + "Form.jsp"));
@@ -310,13 +324,21 @@ private void installMenu() {
310324

311325
parseXMLFile(existingFile, pojoName, " </Menus>", "menu.config");
312326
} else {
313-
createLoadFileTask("src/main/webapp/common/" + pojoName + "-menu-light.jsp", "menu-light.jsp").execute();
327+
File freemarker = new File(destinationDirectory + "/src/main/webapp/decorators/default.ftl");
328+
if (freemarker.exists()) {
329+
createLoadFileTask("src/main/webapp/common/" + pojoName + "-menu-light.ftl", "menu-light.jsp").execute();
330+
} else {
331+
createLoadFileTask("src/main/webapp/common/" + pojoName + "-menu-light.jsp", "menu-light.jsp").execute();
332+
}
314333

315334
File existingFile = new File(destinationDirectory + "/src/main/webapp/decorators/default.jsp");
316335
File jsfConfig = new File(destinationDirectory + "/src/main/webapp/WEB-INF/faces-config.xml");
317336
if (jsfConfig.exists()) {
318337
existingFile = new File(destinationDirectory + "/src/main/webapp/layouts/default.xhtml");
319338
}
339+
if (freemarker.exists()) {
340+
existingFile = new File(destinationDirectory + "/src/main/webapp/decorators/default.ftl");
341+
}
320342

321343
parseXMLFile(existingFile, pojoName, "<!-- Add new menu items here -->", "menu-light.jsp");
322344
}

plugins/appfuse-maven-plugin/src/main/java/org/appfuse/tool/ArtifactUninstaller.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ private void removeMenu() {
221221
if (jsfConfig.exists()) {
222222
existingFile = new File(installedDirectory + "/src/main/webapp/layouts/default.xhtml");
223223
}
224+
File freemarker = new File(installedDirectory + "/src/main/webapp/decorators/default.ftl");
225+
if (freemarker.exists()) {
226+
existingFile = new File(installedDirectory + "/src/main/webapp/decorators/default.ftl");
227+
}
224228
parseXMLFile(existingFile, pojoName);
225229
}
226230
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<#assign pojoNameLower = pojo.shortName.substring(0,1).toLowerCase()+pojo.shortName.substring(1)>
2+
<!--${pojo.shortName}-START-->
3+
<li><a href="${'$'}{rc.contextPath}/${util.getPluralForWord(pojoNameLower)}" title="View ${util.getPluralForWord(pojo.shortName)}"><span>${util.getPluralForWord(pojo.shortName)}</span></a></li>
4+
<!--${pojo.shortName}-END-->
5+
<!-- Add new menu items here -->
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<#assign pojoNameLower = pojo.shortName.substring(0,1).toLowerCase()+pojo.shortName.substring(1)>
2+
${'<#assign dateExists = false>'}
3+
${'<#import "/spring.ftl" as spring/>'}
4+
${'<#assign xhtmlCompliant = true in spring>'}
5+
6+
<head>
7+
<title>${'<@spring'}.message "${pojoNameLower}Detail.title"/></title>
8+
<meta name="heading" content="${'<@spring'}.message "${pojoNameLower}Detail.heading"/>"/>
9+
</head>
10+
11+
<div class="col-sm-3">
12+
<h2>${'<@spring'}.message "${pojoNameLower}Detail.heading"/></h2>
13+
${'<@spring'}.message "${pojoNameLower}Detail.message"/>
14+
</div>
15+
16+
<div class="col-sm-6">
17+
${'<@spring'}.bind "${pojoNameLower}.*"/>
18+
${'<#if'} spring.status.error>
19+
<div class="alert alert-danger alert-dismissable">
20+
<a href="#" data-dismiss="alert" class="close">&times;</a>
21+
${'<#list'} spring.status.errorMessages as error>
22+
${'$'}{error}<br/>
23+
${'</#list>'}
24+
</div>
25+
${'</#if>'}
26+
27+
<form method="post" action="${'<@spring'}.url '/${pojoNameLower}form'/>" id="${pojoNameLower}Form" class="well" autocomplete="off">
28+
<#rt/>
29+
<#foreach field in pojo.getAllPropertiesIterator()>
30+
<#assign isDate = false>
31+
<#assign isBoolean = false>
32+
<#if field.equals(pojo.identifierProperty)>
33+
<#assign idFieldName = field.name>
34+
<#if field.value.identifierGeneratorStrategy == "assigned">
35+
<#lt/><ul>
36+
${'<@spring'}.bind "${pojoNameLower}.${field.name}"/>
37+
<#if spring.status.error> has-error</#if>
38+
<div class="form-group${'<#if'} spring.status.error> has-error${'</#if>'}">
39+
<label for="${field.name}" class="control-label">${'<@spring'}.message "${pojoNameLower}.${field.name}"/>:</label>
40+
${'<@spring'}.formInput "${pojoNameLower}.${field.name}", 'id="${field.name}" class="form-control"'/>
41+
${'<@spring'}.showErrors "<br/>", "help-block"/>
42+
</div>
43+
<#else>
44+
<#lt/>${'<@spring'}.formHiddenInput "${pojoNameLower}.${field.name}"/>
45+
</#if>
46+
<#elseif !c2h.isCollection(field) && !c2h.isManyToOne(field) && !c2j.isComponent(field)>
47+
<#foreach column in field.getColumnIterator()>
48+
<#if field.value.typeName == "java.util.Date" || field.value.typeName == "date">
49+
<#assign isDate = true>
50+
</#if>
51+
<#if field.value.typeName == "boolean" || field.value.typeName == "java.lang.Boolean">
52+
<#assign isBoolean = true>
53+
</#if>
54+
${'<@spring'}.bind "${pojoNameLower}.${field.name}"/>
55+
<div class="form-group${'<#if'} spring.status.error> has-error${'</#if>'}<#if isBoolean> checkbox</#if>">
56+
<#if isBoolean>
57+
<label for="${field.name}">
58+
<#else>
59+
<label for="${field.name}" class="control-label">${'<@spring'}.message "${pojoNameLower}.${field.name}"/>:</label>
60+
</#if>
61+
<#if isDate>
62+
<#assign dateExists = true/>
63+
${'<@spring'}.formInput "${pojoNameLower}.${field.name}", 'id="${field.name}" size="11" title="date" class="form-control date" datepicker="true"'/>
64+
<#elseif isBoolean>
65+
${'<@spring'}.formCheckbox "${pojoNameLower}.${field.name}", 'id="${field.name}"'/>
66+
<#else>
67+
${'<@spring'}.formInput "${pojoNameLower}.${field.name}", 'id="${field.name}" class="form-control"<#if (column.length > 0)> maxlength="${column.length?c}"</#if>'/>
68+
</#if>
69+
<#if isBoolean>
70+
${'<@spring'}.message "${pojoNameLower}.${field.name}"/></label>
71+
</#if>
72+
${'<@spring'}.showErrors "<br/>", "help-block"/>
73+
</div>
74+
</#foreach>
75+
<#elseif c2h.isManyToOne(field)>
76+
<#foreach column in field.getColumnIterator()>
77+
<#lt/> <!-- todo: change this to read the identifier field from the other pojo -->
78+
<#lt/> <!--@spring.formSingleSelect "${pojoNameLower}.${field.name}", ${pojoNameLower}.${field.name}, 'class="form-control"'/-->
79+
</#foreach>
80+
</#if>
81+
</#foreach>
82+
83+
<div class="form-group">
84+
<button type="submit" class="btn btn-primary" id="save" name="save">
85+
<i class="icon-ok icon-white"></i> ${'<@spring'}.message "button.save"/>
86+
</button>
87+
${'<#if'} ${pojoNameLower}.${idFieldName}?exists>
88+
<button type="submit" class="btn btn-danger" id="delete" name="delete">
89+
<i class="icon-trash icon-white"></i> ${'<@spring'}.message "button.delete"/>
90+
</button>
91+
${'</#if>'}
92+
<a href="${'$'}{rc.contextPath}/${util.getPluralForWord(pojoNameLower)}" class="btn btn-default">
93+
<i class="icon-remove"></i> ${'<@spring'}.message "button.cancel"/></a>
94+
</div>
95+
</form>
96+
</div>
97+
98+
99+
<#if dateExists><#rt/>
100+
<link rel="stylesheet" type="text/css" media="all" href="${'$'}{rc.contextPath}/webjars/bootstrap-datepicker/1.3.1/css/datepicker.css" />
101+
<script type="text/javascript" src="${'$'}{rc.contextPath}/webjars/bootstrap-datepicker/1.3.1/js/bootstrap-datepicker.js"></script>
102+
${'<#if'} rc.locale.language != 'en'>
103+
<script type="text/javascript" src="${'$'}{rc.contextPath}/webjars/bootstrap-datepicker/1.3.1/js/locales/bootstrap-datepicker.${r"${rc.locale.language}"}.js'/>"></script>
104+
${'</#if>'}
105+
</#if><#rt/>
106+
<script type="text/javascript">
107+
$(document).ready(function() {
108+
$("input[type='text']:visible:enabled:first", document.forms['${pojoNameLower}Form']).focus();
109+
<#if dateExists>
110+
${'$'}('.date').datepicker({format: "${'<@spring'}.message "calendar.format"/>", weekStart: "${'<@spring'}.message "calendar.weekstart"/>", language: '${r"${rc.locale.language}"}'});
111+
</#if>
112+
});
113+
</script>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<#assign pojoNameLower = pojo.shortName.substring(0,1).toLowerCase()+pojo.shortName.substring(1)>
2+
3+
<head>
4+
<title>${'$'}{rc.getMessage("${pojoNameLower}List.title")}</title>
5+
<meta name="menu" content="${pojo.shortName}Menu"/>
6+
</head>
7+
8+
<h2>${'$'}{rc.getMessage("${pojoNameLower}List.title")}</h2>
9+
10+
<form method="get" action="${'$'}{rc.contextPath}/${util.getPluralForWord(pojoNameLower)}" id="searchForm" class="form-inline">
11+
<div id="search" class="text-right">
12+
<span class="col-sm-9">
13+
<input type="text" size="20" name="q" id="query" value="${'$'}{RequestParameters.q!''}"
14+
placeholder="${'$'}{rc.getMessage("search.enterTerms")}" class="form-control input-sm"/>
15+
</span>
16+
<button id="button.search" class="btn btn-default btn-sm" type="submit">
17+
<i class="icon-search"></i> ${'$'}{rc.getMessage("button.search")}
18+
</button>
19+
</div>
20+
</form>
21+
22+
<p>${'$'}{rc.getMessage("${pojoNameLower}List.message")}</p>
23+
24+
<div id="actions" class="btn-group">
25+
<a href="${pojoNameLower}form" class="btn btn-primary">
26+
<i class="icon-plus icon-white"></i> ${'$'}{rc.getMessage("button.add")}</a>
27+
<a href="home" class="btn btn-default"><i class="icon-ok"></i> ${'$'}{rc.getMessage("button.done")}</a>
28+
</div>
29+
30+
<table class="table table-condensed table-striped table-hover" id="${pojoNameLower}List">
31+
<thead>
32+
<tr>
33+
<#foreach field in pojo.getAllPropertiesIterator()>
34+
<th>${'$'}{rc.getMessage("${pojoNameLower}.${field.name}")}</th>
35+
</#foreach>
36+
</tr>
37+
</thead>
38+
<tbody>
39+
${'<#'}list ${pojoNameLower}List as ${pojoNameLower}>
40+
<tr>
41+
<#foreach field in pojo.getAllPropertiesIterator()>
42+
<#if field.equals(pojo.identifierProperty)>
43+
<td><a href="${'$'}{rc.contextPath}/${pojoNameLower}form?id=${'$'}{${pojoNameLower}.${field.name}}">${'$'}{${pojoNameLower}.${field.name}}</a></td>
44+
<#elseif !c2h.isCollection(field) && !c2h.isManyToOne(field) && !c2j.isComponent(field)>
45+
<#if field.value.typeName == "java.util.Date" || field.value.typeName == "date">
46+
<#lt/> <td>${'$'}{${pojoNameLower}.${field.name}?html}</td>
47+
<#elseif field.value.typeName == "boolean">
48+
<#lt/> <td><input type="checkbox" disabled="disabled" ${'<#if'} ${pojoNameLower}.${field.name}>checked="checked"${'</#if>'}/></td>
49+
<#else>
50+
<#lt/> <td>${'$'}{${pojoNameLower}.${field.name}?html}</td>
51+
</#if>
52+
</#if>
53+
</#foreach>
54+
</tr>
55+
${'</#list>'}
56+
</tbody>
57+
</table>

0 commit comments

Comments
 (0)