[
https://issues.apache.org/jira/browse/WW-4335?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13984310#comment-13984310
]
recyclebin5385 edited comment on WW-4335 at 4/29/14 2:02 PM:
-------------------------------------------------------------
I overrode method findTemplateSource, whose logic is almost the same as the
original FreemarkerThemeTemplateLoader's method, except one point: the
direction of searching a separator between the theme name and the template name.
In the original method, a slash is searched from the head to the tail and the
nearest slash after the theme expansion token is regarded as the separator
between the theme name and the template name.
For example, if name is "template/\~\~\~foo/bar/css.ftl", the theme name is
"foo" and the template name is "bar/css.ftl". That does not work well if the
theme name contains a slash.
In MyFreemarkerThemeTemplateLoader's method, a slash is searched from the tail
to the head, so the last slash is regarded as the separator between the theme
name and the template name.
If name is "template/\~\~\~foo/bar/css.ftl", the theme name is "foo/bar" and
the template name is "css.ftl".
I understand this method also does not work if a theme contains a directory in
it, so I added a trial and error loop.
First, it regards the last slash as the theme/template name separator and
checks if it can get the theme property.
If it fails to get the theme property, then it regards the second last slash as
the theme/template separator and does the same thing.
If it fails again, it tries with the third last slash, ... until it succeeds to
get the theme property.
I think this algorithm is sufficient for almost every case, but I think the
theme expansion token should be added not only before the theme name but also
after it, like "template/\~\~\~foo/bar\~\~\~/css.ftl", in order to completely
deal with every possible case.
was (Author: [email protected]):
I overrode method findTemplateSource, whose logic is almost the same as the
original FreemarkerThemeTemplateLoader's method, except one point: the
direction of searching a separator between the theme name and the template name.
In the original method, a slash is searched from the head to the tail and the
nearest slash after the theme expansion token is regarded as the separator
between the theme name and the template name.
For example, if name is "template/~~~foo/bar/css.ftl", the theme name is "foo"
and the template name is "bar/css.ftl". That does not work well if the theme
name contains a slash.
In MyFreemarkerThemeTemplateLoader's method, a slash is searched from the tail
to the head, so the last slash is regarded as the separator between the theme
name and the template name.
If name is "template/~~~foo/bar/css.ftl", the theme name is "foo/bar" and the
template name is "css.ftl".
I understand this method also does not work if a theme contains a directory in
it, so I added a trial and error loop.
First, it regards the last slash as the theme/template name separator and
checks if it can get the theme property.
If it fails to get the theme property, then it regards the second last slash as
the theme/template separator and does the same thing.
If it fails again, it tries with the third last slash, ... until it succeeds to
get the theme property.
I think this algorithm is sufficient for almost every case, but I think the
theme expansion token should be added not only before the theme name but also
after it, like "template/~~~foo/bar~~~/css.ftl", in order to completely deal
with every possible case.
> Error while extending a theme if located in a deep hierarchy
> ------------------------------------------------------------
>
> Key: WW-4335
> URL: https://issues.apache.org/jira/browse/WW-4335
> Project: Struts 2
> Issue Type: Bug
> Components: Core Actions
> Affects Versions: 2.3.16, 2.3.16.1, 2.3.16.2
> Environment: Windows Vista, Java 7, Tomcat 7
> Reporter: recyclebin5385
> Priority: Minor
> Fix For: 2.3.18
>
> Attachments: ww4335test.zip
>
>
> When I create a theme named "foo/bar" which extends the default theme
> "simple" and use the theme in a JSP file, an error saying "Error reading
> included file template/~~~foo/bar/css.ftl" occurs and the web page cannot be
> rendered.
> How to reproduce:
> 1. Create a theme folder "/themes/foo/bar" in a resource folder.
> The point is there are more than two folders nested under /themes.
> 2. Create a property file theme.properties in "/themes/foo/bar", whose
> content is like below.
> parent = simple
> 3. In struts.xml, set constant "struts.ui.theme" as "foo/bar".
> 4. Access to any pages in the web application which contains a <s:textfield>
> tag.
> It worked with Struts 2.3.15.3, but no longer works with Struts 2.3.16.
> New tag templates in Struts 2.3.16 contains codes like
> {{/$\{parameters.templateDir\}/$\{parameters.expandTheme\}/css.ftl}}.
> If the name of the theme is "foo/bar", this code is translated into
> {{template/~~~foo/bar/css.ftl}}.
> The translated string is passed to method
> {{org.apache.struts2.views.freemarker.FreemarkerThemeTemplateLoader#findTemplateSource(String)}}
> But this method cannot handle a theme name containing a slash like "foo/bar".
> I am not sure whether such a theme is permitted or not by the Struts 2
> specification, so I reported it as a bug.
> A workaround is not to create such a theme when creating a new web
> application, but if an existing one already uses a theme like this, it will
> be affected.
> Another workaround is to replace the original FreemarkerThemeTemplateLoader
> with a fixed one, but it is a little bit too complicated.
--
This message was sent by Atlassian JIRA
(v6.2#6252)