NIHVIVO-649 Add freemarker template flattening to build. Includes flattening of template directory structure in vivo theme, and renaming of templates as needed for clarity.

This commit is contained in:
rjy7 2010-07-08 17:10:31 +00:00
parent f71ef30358
commit 5a11344775
27 changed files with 54 additions and 52 deletions

View file

@ -188,8 +188,17 @@ deploy - Deploy the application directly into the Tomcat webapps directory.
set this property and they will be skipped.
-->
<exclude name="themes/**/*" if="skip.core.themes" />
<!--
Don't copy the freemarker templates; we need to flatten them.
-->
<exclude name="templates/freemarker/" />
</fileset>
</copy>
<!-- Flatten the freemarker templates and copy them. -->
<copy todir="${build.dir}/war/templates/freemarker" includeemptydirs="false">
<fileset dir="${webapp.dir}/web/templates/freemarker" />
<flattenmapper />
</copy>
<copy todir="${build.dir}/war/WEB-INF">
<fileset file="${webapp.dir}/config/web.xml" />

View file

@ -54,10 +54,10 @@ public class Authenticate extends FreeMarkerHttpServlet {
private static final String PARAMETER_CONFIRM_PASSWORD = "confirmPassword";
/** If they are logging in, show them this form. */
public static final String TEMPLATE_LOGIN = "login/login.ftl";
public static final String TEMPLATE_LOGIN = "login-form.ftl";
/** If they are changing their password on first login, show them this form. */
public static final String TEMPLATE_FORCE_PASSWORD_CHANGE = "login/forcedPasswordChange.ftl";
public static final String TEMPLATE_FORCE_PASSWORD_CHANGE = "login-forcedPasswordChange.ftl";
public static final String BODY_LOGIN_NAME = "loginName";
public static final String BODY_FORM_ACTION = "formAction";

View file

@ -44,13 +44,13 @@ public class ContactFormController extends FreeMarkerHttpServlet {
body.put("errorMessage",
"This application has not yet been configured to send mail. " +
"An smtp host has not been specified in the configuration properties file.");
bodyTemplate = "contactForm/error.ftl";
bodyTemplate = "contactForm-error.ftl";
}
else if (StringUtils.isEmpty(portal.getContactMail())) {
body.put("errorMessage",
"The site administrator has not configured an email address to receive the form submission.");
bodyTemplate = "contactForm/error.ftl";
bodyTemplate = "contactForm-error.ftl";
}
else {
@ -83,7 +83,7 @@ public class ContactFormController extends FreeMarkerHttpServlet {
vreq.getSession().setAttribute("contactFormReferer",vreq.getHeader("Referer"));
}
bodyTemplate = "contactForm/form.ftl";
bodyTemplate = "contactForm-form.ftl";
}
return mergeBodyToTemplate(bodyTemplate, body, config);

View file

@ -81,7 +81,7 @@ public class ContactMailController extends FreeMarkerHttpServlet {
body.put("errorMessage",
"This application has not yet been configured to send mail. " +
"An smtp host has not been specified in the configuration properties file.");
bodyTemplate = "contactForm/error.ftl";
bodyTemplate = "contactForm-error.ftl";
}
else {
@ -97,7 +97,7 @@ public class ContactMailController extends FreeMarkerHttpServlet {
// rjy7 We should reload the form, not go to the error page!
body.put("errorMessage",
"Invalid submission");
bodyTemplate = "contactForm/error.ftl";
bodyTemplate = "contactForm-error.ftl";
}
else {
@ -204,10 +204,10 @@ public class ContactMailController extends FreeMarkerHttpServlet {
// Message was sent successfully
if (statusMsg == null && spamReason == null) {
bodyTemplate = "contactForm/confirmation.ftl";
bodyTemplate = "contactForm-confirmation.ftl";
} else {
body.put("errorMessage", statusMsg);
bodyTemplate = "contactForm/error.ftl";
bodyTemplate = "contactForm-error.ftl";
}
}
}
@ -230,7 +230,7 @@ public class ContactMailController extends FreeMarkerHttpServlet {
String originalReferer, String ipAddr, Configuration config) {
Map<String, Object> email = new HashMap<String, Object>();
String template = "contactForm/email.ftl";
String template = "contactForm-email.ftl";
email.put("subject", deliveryfrom);
email.put("name", webusername);
@ -248,7 +248,7 @@ public class ContactMailController extends FreeMarkerHttpServlet {
String spamReason, Configuration config) {
Map<String, Object> backup = new HashMap<String, Object>();
String template = "contactForm/backup.ftl";
String template = "contactForm-backup.ftl";
Calendar cal = Calendar.getInstance();
backup.put("datetime", cal.getTime().toString());

View file

@ -43,8 +43,8 @@ public class FreeMarkerComponentGenerator extends FreeMarkerHttpServlet {
}
private String get(String templateName, Map<String, Object> root, Configuration config) {
String template = "page/partials/" + templateName + ".ftl";
return mergeToTemplate(template, root, config).toString();
templateName += ".ftl";
return mergeToTemplate(templateName, root, config).toString();
}
// RY We need the servlet context in getConfig(). For some reason using the method inherited from

View file

@ -385,22 +385,14 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
}
protected String mergeBodyToTemplate(String templateName, Map<String, Object> map, Configuration config) {
templateName = "body/" + templateName; // Remove once we flatten template directory
String body = mergeToTemplate(templateName, map, config).toString();
return body;
return mergeToTemplate(templateName, map, config).toString();
}
protected void writePage(Map<String, Object> root, Configuration config, HttpServletResponse response) {
String templateName = "page/" + getPageTemplateName(); // Remove the directory once we flatten template directory
String templateName = getPageTemplateName();
writeTemplate(templateName, root, config, response);
}
// Remove this method once we flatten template directory
protected void ajaxWrite(String templateName, Map<String, Object> map, Configuration config, HttpServletResponse response) {
templateName = "ajax/" + templateName;
writeTemplate(templateName, map, config, response);
}
protected void writeTemplate(String templateName, Map<String, Object> map, Configuration config, HttpServletResponse response) {
StringWriter sw = mergeToTemplate(templateName, map, config);
write(sw, response);
@ -418,7 +410,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
// Can be overridden by individual controllers to use a different basic page layout.
protected String getPageTemplateName() {
return "default.ftl";
return "page.ftl";
}
// TEMPORARY method for transition from JSP to FreeMarker.

View file

@ -72,9 +72,9 @@ public class ImageUploadController extends FreeMarkerHttpServlet {
public static final String BODY_FORM_ACTION = "formAction";
public static final String BODY_ERROR_MESSAGE = "errorMessage";
public static final String TEMPLATE_NEW = "imageUpload/newImage.ftl";
public static final String TEMPLATE_REPLACE = "imageUpload/replaceImage.ftl";
public static final String TEMPLATE_CROP = "imageUpload/cropImage.ftl";
public static final String TEMPLATE_NEW = "imageUpload-newImage.ftl";
public static final String TEMPLATE_REPLACE = "imageUpload-replaceImage.ftl";
public static final String TEMPLATE_CROP = "imageUpload-cropImage.ftl";
public static final String TEMPLATE_ERROR = "error.ftl";
private static final String URL_HERE = UrlBuilder.getUrl("/uploadImages");

View file

@ -33,10 +33,10 @@ public class LoginTemplateHelper extends LoginTemplateHelperBase {
private static final Log log = LogFactory.getLog(LoginTemplateHelper.class);
/** If they are logging in, show them this form. */
public static final String TEMPLATE_LOGIN = "login/login.ftl";
public static final String TEMPLATE_LOGIN = "login-form.ftl";
/** If they are changing their password on first login, show them this form. */
public static final String TEMPLATE_FORCE_PASSWORD_CHANGE = "login/forcedPasswordChange.ftl";
public static final String TEMPLATE_FORCE_PASSWORD_CHANGE = "login-forcedPasswordChange.ftl";
public static final String BODY_LOGIN_NAME = "loginName";
public static final String BODY_FORM_ACTION = "formAction";

View file

@ -96,7 +96,8 @@ public class AutocompleteController extends FreeMarkerHttpServlet implements Sea
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String templateName = request.getServletPath().equals("/autocomplete") ? "autocompleteResults.ftl" : "selectResults.ftl";
// String templateName = request.getServletPath().equals("/autocomplete") ? "autocompleteResults.ftl" : "selectResults.ftl";
String templateName = "autocompleteResults.ftl";
Map<String, Object> map = new HashMap<String, Object>();
VitroRequest vreq = new VitroRequest(request);
@ -188,7 +189,7 @@ public class AutocompleteController extends FreeMarkerHttpServlet implements Sea
Collections.sort(results);
map.put("results", results);
ajaxWrite(templateName, map, config, response);
writeTemplate(templateName, map, config, response);
} catch (Throwable e) {
log.error("AutocompleteController(): " + e);
@ -411,17 +412,17 @@ public class AutocompleteController extends FreeMarkerHttpServlet implements Sea
private void doNoQuery(String templateName, Map<String, Object> map, Configuration config, HttpServletResponse response) {
ajaxWrite(templateName, map, config, response);
writeTemplate(templateName, map, config, response);
}
private void doFailedSearch(String templateName, Map<String, Object> map, Configuration config, HttpServletResponse response) {
ajaxWrite(templateName, map, config, response);
writeTemplate(templateName, map, config, response);
}
private void doSearchError(String templateName, Map<String, Object> map, Configuration config, HttpServletResponse response) {
// For now, we are not sending an error message back to the client because with the default autocomplete configuration it
// chokes.
ajaxWrite(templateName, map, config, response);
writeTemplate(templateName, map, config, response);
}
public static final int MAX_QUERY_LENGTH = 500;

View file

@ -26,13 +26,13 @@ public class ViewFinder {
private static final Log log = LogFactory.getLog(ViewFinder.class.getName());
public enum ClassView {
DISPLAY("getCustomDisplayView", "/view/display"),
DISPLAY("getCustomDisplayView", "/view-display"),
// NB this is not the value currently used for custom forms - we use the value on the object property
FORM("getCustomEntryForm", "/form"),
SEARCH("getCustomSearchView", "/view/search"),
SHORT("getCustomShortView", "/view/short");
SEARCH("getCustomSearchView", "/view-search"),
SHORT("getCustomShortView", "/view-short");
private static String TEMPLATE_PATH = "/templates/freemarker/body/partials/class";
private static String TEMPLATE_PATH = "/templates/freemarker";
private Method method = null;
private String path = null;
@ -85,7 +85,7 @@ public class ViewFinder {
try {
String v = (String) method.invoke(vc);
if (!StringUtils.isEmpty(v)) {
String pathToView = context.getRealPath(view.getPath() + "/" + v);
String pathToView = context.getRealPath(view.getPath() + "-" + v);
File viewFile = new File(pathToView);
if (viewFile.isFile() && viewFile.canRead()) {
viewName = v;

View file

@ -3,7 +3,7 @@
<#-- Template for autocomplete results. -->
<#--
<#import "/lib/json.ftl" as json>
<#import "json.ftl" as json>
<@json.array results />
-->

View file

@ -16,7 +16,7 @@
<#list individuals as individual>
<li>
<#-- Currently we just use the search view here; there's no custom list view defined. -->
<#include "partials/class/view/search/${individual.searchView}">
<#include "${individual.searchView}">
</li>
</#list>
</ul>

View file

@ -2,7 +2,7 @@
<#-- Default individual search view -->
<#import "/lib/list.ftl" as l>
<#import "listMacros.ftl" as l>
<a href="${individual.profileUrl}">${individual.name}</a>
<ul class="individualData">

View file

@ -1,22 +1,22 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#include "partials/doctype.html">
<#include "doctype.html">
<#include "partials/head.ftl">
<#include "head.ftl">
<body>
<div id="wrap" class="container">
<div id="header">
<#include "partials/identity.ftl">
<#include "identity.ftl">
<#-- Note to UI team: do not change this div without also making the corresponding change in menu.jsp -->
<div id="navAndSearch" class="block">
<#include "partials/menu.ftl">
<#include "partials/search.ftl">
<#include "menu.ftl">
<#include "search.ftl">
</div> <!-- navAndSearch -->
<#include "partials/breadcrumbs.ftl">
<#include "breadcrumbs.ftl">
</div> <!-- header -->
<hr class="hidden" />
@ -29,11 +29,11 @@
</div> <!-- content -->
</div> <!-- contentwrap -->
<#include "partials/footer.ftl">
<#include "footer.ftl">
</div> <!-- wrap -->
<#include "partials/scripts.ftl">
<#include "scripts.ftl">
</body>
</html>

View file

@ -1,6 +1,6 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#import "/lib/list.ftl" as l>
<#import "listMacros.ftl" as l>
<div id="footer">

View file

@ -1,6 +1,6 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#import "/lib/list.ftl" as l>
<#import "listMacros.ftl" as l>
<div id="identity">