Apache FreeMarker - 1.1


Compatibility: v2 v3 Cloud
What's new? Release Notes
ID: com.castsoftware.java.freemarker

Description

This extension provides support for Apache FreeMarker Framework. 

In what situation should you install this extension?

If your Java application uses the Apache FreeMarker Framework.

Technology support

ComponentVersionSupportedSupported Technology
Apache FreeMarker Framework2.3.xJava
spring-context-support<=6.2.5Java
spring-webmvc<=6.2.5Java

Function Point, Quality and Sizing support

  • Function Points (transactions): a green tick indicates that OMG Function Point counting and Transaction Risk Index are supported
  • Quality and Sizing: a green tick indicates that CAST can measure size and that a minimum set of Quality Rules exist
Function Points (transactions)Quality and Sizing

Download and installation instructions

The extension will be automatically downloaded and installed in CAST Console. It can be managed through the Application → Extensions interface.

What results can you expect?

Objects

IconDescriptionCreation Context
Java Freemarker FTL ParameterAn object is created for each execution of template process APIs
Java Freemarker FTL CallAn object is created for each variable interpolation in ftl file
Link TypeSource and destination linkSupported Methods
relyonLinkBetween Java Freemarker FTLParameter and and respective Data Model JAVA classfreemarker.template.Template.process
org.springframework.ui.freemarker.FreeMarkerTemplateUtils.processTemplateIntoString
org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate
callLinkBetween HTML source code objects(.ftl and similar files) and CallToFTL objects.
callLinkBetween CallToFTL objects and JAVA methods.

Code Example of Template Process API

Template Engine: MainTest.java
public static void main(String[] args) throws Exception {

        Configuration cfg = new Configuration();
        String content = null;

        cfg.setClassForTemplateLoading(MainTest.class, "templates");
        cfg.setIncompatibleImprovements(new Version(2, 3, 20));
        cfg.setDefaultEncoding("UTF-8");
        cfg.setLocale(Locale.US);
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

        Map<String, Object> input = new HashMap<String, Object>();

        input.put("title", "Dummy example");

        List<ValueExampleObject> systems = new ArrayList<ValueExampleObject>();
        systems.add(new ValueExampleObject("Android", "Google"));
        systems.add(new ValueExampleObject("iOS States", "Apple"));
        systems.add(new ValueExampleObject("Ubuntu", "Canonical"));
        systems.add(new ValueExampleObject("Windows7", "Microsoft"));
        input.put("systems", systems);

        Cal cal=new Cal();
        input.put("cal", cal);

        input.put("exampleObject", new ValueExampleObject("Java object", "me"));

        Template template = cfg.getTemplate("helloworld.ftl");

        template.process(input, consoleWriter);
}
Data Model Class: Cal.java
public class Cal {
    public int add(int a, int b) {
        return a+b;
    }
    
    public int mul(int a, int b) {
        return a*b;
    }
}
Template: helloworld.ftl
<html>
    
    <head>
      <title>${title}
    </head>
    <body>
      <h1>${title}</h1>
    
      <p>${exampleObject.name} by ${exampleObject.developer}</p>
    
      <ul>
        <#list systems as system>
          <li>${system_index + 1}. ${system.name} from ${system.developer}</li>
        </#list>
      </ul>
    
    <h1>
        2+3= ${cal.add(2,3)}
        10/2= ${cal.mul(10,2)}
    </h1>

    <#assign multiplied = cal.mul(40,20)>
    
    <h1>${multiplied}</h1>
    </body>
</html>