1 Reply Latest reply on Jan 19, 2016 3:14 AM by darshan_patel

    How to add custom macros in jive-macros.ftl file using plugin for jive8

    darshan_patel

      Hi,

      Ryan King

      we are migrating gamification plug-in from jive 7 to jive 8.

       

      we have created common macros that will use in all jive pages.

      As per our understanding, jive-macros.ftl file contains all common macros. Hence we need to add all that macros in to jive-macro.ftl file.

       

      In jive 7 we did following steps

      1. Created new jive-macros.ftl file with all required common macros,

      2. Included default jive-macros.ftl file in it using  <#include "/template/global/include/jive-macros.ftl"/> code

      3 Load that new macro file  by extending com.jivesoftware.community.web.struts.JiveFreemarkerManager class and overriding configureDefaultConfiguration method

      4. Import new macro file using configuration.addAutoImport("jive", "/plugins/toolkit/resources/templates/global/include/jive-macros.ftl"); code.

       

      This is working in jive 7, But in jive 8 we are getting following exception :

       

      java.io.FileNotFoundException: Template "/plugins/toolkit/resources/templates/global/include/jive-macros.ftl" not found. The quoted name was interpreted by this template loader: org.apache.struts2.views.freemarker.FreemarkerThemeTemplateLoader@54ed6b53.

       

      while debugging free-marker code I found that it  imports jive-macros.ftl source file for two purpose :

      1. loading the login page.

      2. Applying decorator.

      we are getting error while importing jive-macros.ftl file for decorator.

       

      As per my analysis, In jive-7 to achieve above purposes, 4 template loaders have used and com.jivesoftware.community.web.struts.PluginTemplateLoader loads "/plugins/toolkit/resources/templates/global/include/jive-macros.ftl", but in jive 8 only to load login page same 4 template loaders have used but to apply decorator only two template loaders (WebappTemplateLoader,StrutsClassTemplateLoader)are used.

       

      Note: we have followed standard jive-8 plug-in directory structure.

       

      If I change jive-8 plug-in output directory structure by producing jive-macros.ftl file in "classes/plugins/toolkit/resources/templates/global/include/jive-macros.ftl" then it locates jive-macros.ftl file correctly, but I think this is not the correct way... please confirm.

       

      Please help me to resolve this issue.

        • Re: How to add custom macros in jive-macros.ftl file using plugin for jive8
          darshan_patel

          Ryan King, Ryan Rutan

          I have overridden createTemplateLoader method in JiveFreemarkerManager class then "/plugins/toolkit/resources/templates/global/include/jive-macros.ftl not found" issue is resolved.

           

          please find overridden method as below :

           

          @Override

              protected TemplateLoader createTemplateLoader(

                        ServletContext servletContext, String templatePath) {

                 TemplateLoader templatePathLoader = null;

                        try {

                               if (templatePath != null)

                                     if (templatePath.startsWith("class://")) {

                                            templatePathLoader = new ClassTemplateLoader(

                                                          super.getClass(), templatePath.substring(7));

                                     } else if (templatePath.startsWith("file://"))

                                            templatePathLoader = new FileTemplateLoader(new File(

                                                          templatePath.substring(7)));

                        } catch (IOException e) {

                                log.error("Invalid template path specified: #0", e);

                        }

                        if (templatePathLoader != null);

                        return new MultiTemplateLoader(new TemplateLoader[] {

                                     new PluginTemplateLoader(), new ThemeTemplateLoader(),

                                     new JiveClassTemplateLoader(FreemarkerResult.class, "/"),

                                     new WebappTemplateLoader(servletContext),

                                     new StrutsClassTemplateLoader() });

              }

           

          But, Now I am getting following exception :

           

          2016-01-19 14:06:38,373 [http-bio-8080-exec-4] [-1:ANONYMOUS:REGULAR] ERROR com.jivesoftware.community.RefererHelper - Unable to get action class for com.badgeville.configurator.action.ConfigurationAction

          java.lang.ClassNotFoundException: com.badgeville.configurator.action.ConfigurationAction

              at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)

              at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)

              at java.lang.Class.forName0(Native Method)

              at java.lang.Class.forName(Class.java:348)

              at org.apache.commons.lang.ClassUtils.getClass(ClassUtils.java:757)

              at org.apache.commons.lang.ClassUtils.getClass(ClassUtils.java:822)

              at org.apache.commons.lang.ClassUtils.getClass(ClassUtils.java:805)

              at com.jivesoftware.util.ClassUtilsStatic.forName(ClassUtilsStatic.java:53)

              at com.jivesoftware.community.RefererHelper.isValidRefererURL(RefererHelper.java:210)

              at com.jivesoftware.community.RefererHelper.toValidRefererUrl(RefererHelper.java:86)

              at com.jivesoftware.community.RefererHelper.getRefererURL(RefererHelper.java:64)

          ...

           

           

          Note : 1) Everything is working correctly. but in sbs.log file this exception is logged,

                    2) After hitting custom jive plug-in page(added to configure plug-in), if I click any other link on jive admin console page then this exception is thrown.

           

          I found smiler issue here upgrading 7.0.2 plugin to 8.0.1,getting classnotfoundexception. but it is not answered.