diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java index 14622df61..669d58e51 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java @@ -6,8 +6,10 @@ import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.servlet.ServletContext; @@ -37,6 +39,8 @@ import freemarker.cache.FileTemplateLoader; import freemarker.cache.MultiTemplateLoader; import freemarker.cache.TemplateLoader; import freemarker.template.Configuration; +import freemarker.template.DefaultObjectWrapper; +import freemarker.template.ObjectWrapper; import freemarker.template.Template; import freemarker.template.TemplateException; import freemarker.template.TemplateModelException; @@ -127,10 +131,24 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet { setLoginInfo(); setCopyrightInfo(); setThemeInfo(themeDir); + setScriptAndStylesheetObjects(themeDir); + + } + + private void setScriptAndStylesheetObjects(String themeDir) { + + // Temporarily switch to an object wrapper that exposes write methods. + // The templates can add files to the script and stylesheet lists + // by calling the add() method. + ObjectWrapper defaultWrapper = config.getObjectWrapper(); + config.setObjectWrapper(new DefaultObjectWrapper()); // Here themeDir SHOULD NOT have the context path already added to it. setSharedVariable("stylesheets", new StylesheetList(themeDir)); setSharedVariable("scripts", new ScriptList()); + + config.setObjectWrapper(defaultWrapper); + } // Define template locations. Template loader will look first in the theme-specific diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerSetup.java index aed8a75bc..14f22dffb 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerSetup.java @@ -11,6 +11,7 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.view.ViewObject; +import freemarker.ext.beans.BeansWrapper; import freemarker.template.Configuration; import freemarker.template.DefaultObjectWrapper; import freemarker.template.TemplateException; @@ -39,10 +40,13 @@ public class FreeMarkerSetup implements ServletContextListener { cfg.setTemplateUpdateDelay(0); // no template caching in development } - // Specify how templates will see the data-model. This is an advanced topic... - // but just use this: - cfg.setObjectWrapper(new DefaultObjectWrapper()); - + // Specify how templates will see the data-model. + // The default wrapper exposes set methods unless exposure level is set. + // By default we want to block exposure of set methods. + // cfg.setObjectWrapper(new DefaultObjectWrapper()); + BeansWrapper wrapper = new DefaultObjectWrapper(); + wrapper.setExposureLevel(BeansWrapper.EXPOSE_PROPERTIES_ONLY); + cfg.setObjectWrapper(wrapper); // Set some formatting defaults. These can be overridden at the template // or environment (template-processing) level, or for an individual diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/IndividualView.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/IndividualView.java index f090bd751..b9de51583 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/IndividualView.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/IndividualView.java @@ -26,25 +26,17 @@ public class IndividualView extends ViewObject { this.individual = individual; } - public String getName() { - return individual.getName(); - } - - // RY However, the moniker should undergo p:process but the class name shouldn't! - // So, it needs to be callable from Java. + /* These methods perform some manipulation of the data returned by the Individual methods */ public String getTagline() { String tagline = individual.getMoniker(); return StringUtils.isEmpty(tagline) ? individual.getVClass().getName() : tagline; } - public String getUri() { - return individual.getURI(); - } - // Return link to individual's profile page. // There may be other urls associated with the individual. E.g., we might need // getEditUrl(), getDeleteUrl() to return the links computed by PropertyEditLinks. // RY **** Need to account for everything in URLRewritingHttpServlet + // Currently this is incorrect for individuals that are not in the default namespace (e.g., geographic individuals). public String getProfileUrl() { return getUrl(PATH + "/" + individual.getLocalName()); } @@ -78,6 +70,9 @@ public class IndividualView extends ViewObject { return primaryLink; } + // RY Here we really want to return List objects. Instead of writing the LinkView class by hand, + // it would be better to use an alternate FreeMarker BeanWrapper that creates a read-only template data object. + // That would also be used to return the lists of object properties and data properties of the individual. public List getLinks() { List additionalLinks = individual.getLinksList(); List links = new ArrayList(additionalLinks.size()+1); @@ -89,4 +84,38 @@ public class IndividualView extends ViewObject { return links; } + /* These methods simply forward to the Individual methods. It would be desirable to implement a scheme + for proxying or delegation so that the methods don't need to be simply listed here. + A Ruby-style method missing method would be ideal. */ + public String getName() { + return individual.getName(); + } + + public String getUri() { + return individual.getURI(); + } + + public String getDescription() { + return individual.getDescription(); + } + + public String getBlurb() { + return individual.getBlurb(); + } + + public String getCitation() { + return individual.getBlurb(); + } + + public List getKeywords() { + return individual.getKeywords(); + } + + public String getImageFile() { + return individual.getImageFile(); + } + + public String getImageThumb() { + return individual.getImageThumb(); + } } diff --git a/webapp/web/templates/freemarker/body/contactForm/form.ftl b/webapp/web/templates/freemarker/body/contactForm/form.ftl index edd3af4b9..a988d45d8 100644 --- a/webapp/web/templates/freemarker/body/contactForm/form.ftl +++ b/webapp/web/templates/freemarker/body/contactForm/form.ftl @@ -55,6 +55,4 @@ -<#-- RY This is temporary. ---> -${scripts.add("/js/commentForm.js")} \ No newline at end of file +${scripts.add("/js/commentForm.js")} diff --git a/webapp/web/templates/freemarker/body/partials/class/view/search/default.ftl b/webapp/web/templates/freemarker/body/partials/class/view/search/default.ftl index 2e308293f..8685b3be3 100644 --- a/webapp/web/templates/freemarker/body/partials/class/view/search/default.ftl +++ b/webapp/web/templates/freemarker/body/partials/class/view/search/default.ftl @@ -9,7 +9,6 @@ <@l.firstLastList>
  • ${individual.tagline}
  • , <#list individual.links as link> - ${link.setAnchor("Changing Anchor Text")}
  • ${link.anchor}
  • ,