Juan Pablo Santos Rodríguez created JSPWIKI-1088:
----------------------------------------------------

             Summary: Fallback to default template if jspwiki.templateDir if 
the requested template folder 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


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)

Reply via email to