Uploaded image for project: 'JSPWiki'
  1. JSPWiki
  2. JSPWIKI-1088

Fallback to default template if the requested template folder (jspwiki.templateDir) is not found

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskConvert to sub-taskLinkCloneLabelsUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments


    • Type: Task
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.11.0-M1
    • Fix Version/s: 2.11.0-M2
    • Component/s: Templates and UI
    • Labels:


      As noted on the 2.11.0.M1 release vote, people migrating from 2.10 to 2.11, with the jspwiki.templateDir property set to haddock will get a template-less result.

      Suggestions on the thread vote:

      1) During this transition moving the haddock template folder, it would be
      wise to still keep an empty template/haddock folder.
      JSPWiki will automatically fall back to the default template when it
      doesn't find the requested JSP; so migrating would become more easy.

      2) As an improvement on the longer run, JSPWiki should also automatically
      fall back to the default template when the requested template folder is
      not found.

      Here's a possible solution. In WikiContext there's a method named
      setDefaultTemplate(HttpServletRequest) that has a FIXME note, to the
      effect that we need to check for the existence of the template directory.

      If we were to replace the beginning of the WikiContext.java file with:

      public class WikiContext
          implements Cloneable, Command
           * The name used for the default template. The value is {@value}.
          public static final String DEFAULT_TEMPLATE_NAME = "default";
          private    String     m_template = DEFAULT_TEMPLATE_NAME;

      and the beginning of the setDefaultTemplate() method with:

          protected void setDefaultTemplate( HttpServletRequest request )
              String defaultTemplate = m_engine.getTemplateDir();
              // check to see if the template directory actually exists
              if ( !templateDirectoryExists( m_engine,  request ) ) {
                  defaultTemplate = DEFAULT_TEMPLATE_NAME;

      and provide this utility method, which returns true if it finds
      in the template directory specified in the property file:

           * A test to see if the template directory specified in the wiki's
      properties actually
           * exists.
           * <p>
           * This checks the existence of the <tt>ViewTemplate.jsp</tt> file,
      which exists in every
           * template.
           * @param engine the WikiEngine
           * @param request the HttpServletRequest used to obtain the real path
           * @return true if the template directory exists on the server
          private boolean templateDirectoryExists( WikiEngine engine,
      HttpServletRequest request )
              File templatesDir = new
      File(request.getServletContext().getRealPath("/"), "templates");
              File templateDir = new File(templatesDir, engine.getTemplateDir());
              File viewTemplateJsp = new File(templateDir, "ViewTemplate.jsp");
              return viewTemplateJsp.exists();

      Would that do?




            • Assignee:
              juanpablo Juan Pablo Santos Rodríguez


              • Created:

                Issue deployment