You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jspwiki.apache.org by "Juan Pablo Santos Rodríguez (JIRA)" <ji...@apache.org> on 2019/02/14 23:39:00 UTC

[jira] [Resolved] (JSPWIKI-1088) Fallback to default template if the requested template folder (jspwiki.templateDir) is not found

     [ https://issues.apache.org/jira/browse/JSPWIKI-1088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Juan Pablo Santos Rodríguez resolved JSPWIKI-1088.
--------------------------------------------------
       Resolution: Fixed
    Fix Version/s: 2.11.0-M2

done on 2.11.0-M2-git-07

the check takes place during {{WikiEngine#initialize}}, which happens only once, as {{WikiContext#setDefaultTemplate}} ends up called several times per request. Also, {{ServletContext#getRealPath}} can return null (f.ex on packaged wars on some containers, so an additional check on {{ServletContext#getResource}}.

Finally {{TestEngine}} also needed a small parametrization, as the mock http request was returning null for {{getServletContext}} and for its {{getRealPath}}.


> Fallback to default template if the requested template folder (jspwiki.templateDir) is not found
> ------------------------------------------------------------------------------------------------
>
>                 Key: JSPWIKI-1088
>                 URL: https://issues.apache.org/jira/browse/JSPWIKI-1088
>             Project: JSPWiki
>          Issue Type: Task
>          Components: Templates and UI
>    Affects Versions: 2.11.0-M1
>            Reporter: Juan Pablo Santos Rodríguez
>            Priority: Major
>             Fix For: 2.11.0-M2
>
>
> 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:
> {quote}
> 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.
> {quote}
> {quote}
> 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:
> {code}
> 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;
>     ...
> {code}
> and the beginning of the setDefaultTemplate() method with:
> {code}
>     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;
>         }
>         ...
> {code}
> and provide this utility method, which returns true if it finds
> ViewTemplate.jsp
> in the template directory specified in the property file:
> {code}
>     /**
>      * 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();
>     }
> {code}
> Would that do?
> {quote}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)