Commits

Anonymous committed 3ccf525

Fixed WW-682; current themes not respecting template directory location.
Made some small changes to handling of the file.separator.

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@674573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (27)

src/java/com/opensymphony/webwork/views/jsp/ui/AbstractUITag.java

 
     private static final Log LOG = LogFactory.getLog(AbstractUITag.class);
 
+    private static final String FILE_SEPARATOR = System.getProperty("file.separator");
+
     protected String cssClassAttr;
     protected String cssStyleAttr;
     protected String disabledAttr;
     protected String nameAttr;
     protected String requiredAttr;
     protected String tabindexAttr;
+    protected String valueAttr;
+
+    /** The Velocity template to use, overrides the default one. */
     protected String templateAttr;
-    protected String templateDir;
-    protected String theme;
+
+    // templateDir and theme attributes
+    protected String templateDirAttr;
     protected String themeAttr;
-    protected String valueAttr;
 
     // HTML scripting events attributes
     protected String onclickAttr;
         this.tabindexAttr = tabindex;
     }
 
+    public void setValue(String aValue) {
+        valueAttr = aValue;
+    }
+
     public void setTemplate(String aName) {
         templateAttr = aName;
     }
 
+    public void setTemplateDir(String aName) {
+        templateDirAttr = aName;
+    }
+
     public String getTemplateDir() {
+        String templateDir = null;
+
+        if (templateDirAttr != null) {
+            templateDir = findString(templateDirAttr);
+        }
+
         // If templateDir is not explicitly given,
         // try to find attribute which states the dir set to use
         if ((templateDir == null) || (templateDir == "")) {
-            templateDir = setupPath((String) pageContext.findAttribute("templateDir"), true);
+            templateDir = (String) pageContext.findAttribute("templateDir");
         }
 
         // Default template set
         if ((templateDir == null) || (templateDir == "")) {
-            templateDir = setupPath(Configuration.getString("webwork.ui.templateDir"), true);
+            templateDir = Configuration.getString("webwork.ui.templateDir");
         }
 
+        // Defaults to 'template'
         if ((templateDir == null) || (templateDir == "")) {
-            templateDir = "/template/";
+            templateDir = "template";
         }
 
         return templateDir;
     }
 
     public String getTheme() {
+        String theme = null;
+
         if (themeAttr != null) {
-            theme = setupPath(findString(themeAttr), false);
+            theme = findString(themeAttr);
         }
 
         // If theme set is not explicitly given,
         // try to find attribute which states the theme set to use
         if ((theme == null) || (theme == "")) {
-            theme = setupPath((String) pageContext.findAttribute("theme"), false);
+            theme = (String) pageContext.findAttribute("theme");
         }
 
-        // Default template set
+        // Default theme set
         if ((theme == null) || (theme == "")) {
-            theme = setupPath(Configuration.getString("webwork.ui.theme"), false);
+            theme = Configuration.getString("webwork.ui.theme");
         }
 
         return theme;
     }
 
-    public void setValue(String aValue) {
-        valueAttr = aValue;
-    }
-
     // HTML scripting attribute setters
 
     public void setOnclick(String onclick) {
 
     public int doEndTag() throws JspException {
         try {
-            OgnlValueStack stack = getStack();
-            evaluateParams(stack);
+            evaluateParams(getStack());
 
             try {
-                mergeTemplate(this.getTemplateName());
+                mergeTemplate(getTemplateName());
 
                 return EVAL_PAGE;
             } catch (Exception e) {
             }
         }
 
-        return getTemplateDir() + getTheme() + template;
+        final StringBuffer templateName = new StringBuffer(30);
+
+        final String templateDir = getTemplateDir();
+        if (!templateDir.startsWith(FILE_SEPARATOR)) {
+            templateName.append(FILE_SEPARATOR);
+        }
+        templateName.append(templateDir);
+
+        final String theme = getTheme();
+        if (theme != null && !templateDir.endsWith(FILE_SEPARATOR) && !theme.startsWith(FILE_SEPARATOR) ) {
+            templateName.append(FILE_SEPARATOR);
+        }
+        templateName.append(theme);
+
+        if (template != null && !template.startsWith(FILE_SEPARATOR)) {
+           templateName.append(FILE_SEPARATOR);
+        }
+        templateName.append(template);
+        return templateName.toString();
     }
 
     protected void evaluateExtraParams(OgnlValueStack stack) {
         }
 
         if (evaluateNameValue()) {
-            Class valueClazz = getValueClassType();
+            final Class valueClazz = getValueClassType();
 
             if (valueClazz != null) {
                 if (valueAttr != null) {
             }
         }
 
-        FormTag formTag = (FormTag) findAncestorWithClass(this, FormTag.class);
+        final FormTag formTag = (FormTag) findAncestorWithClass(this, FormTag.class);
 
         if (id != null) {
             addParameter("id", id);
     }
 
     protected void mergeTemplate(String templateName) throws Exception {
-        TemplateEngine engine = TemplateEngineManager.getTemplateEngine(templateName);
+        final TemplateEngine engine = TemplateEngineManager.getTemplateEngine(templateName);
         if (engine == null) {
             throw new ConfigurationException("Unable to find a TemplateEngine for template " + templateName);
         }
+
         String finalTemplateName = engine.getFinalTemplateName(templateName);
         if (LOG.isDebugEnabled()) {
             LOG.debug("Got template engine " + engine.getClass().getName() + " for template '" + templateName + "'" +
                     ((templateName.equals(finalTemplateName)) ? null : " final template name '" + finalTemplateName + "'"));
         }
-        TemplateRenderingContext context = new TemplateRenderingContext(finalTemplateName, pageContext, getStack(), getParameters(), this);
-        engine.renderTemplate(context);
-    }
-
-    private String setupPath(String path, boolean prefix) {
-        if ((path != null) && (path != "")) {
-            if (prefix) {
-                if (!path.startsWith("/")) {
-                    path = "/" + path;
-                }
-            }
 
-            if (!path.endsWith("/")) {
-                path += "/";
-            }
-        }
-
-        return path;
+        final TemplateRenderingContext context = new TemplateRenderingContext(finalTemplateName, pageContext, getStack(), getParameters(), this);
+        engine.renderTemplate(context);
     }
 }

src/java/template/simple/checkbox.vm

 #if ($parameters.id)               id="$!webwork.htmlEncode($parameters.id)"                #end
 #if ($parameters.cssClass)         class="$!webwork.htmlEncode($parameters.cssClass)"       #end
 #if ($parameters.cssStyle)         style="$!webwork.htmlEncode($parameters.cssStyle)"       #end
-#parse("/template/simple/scripting-events.vm")
+#parse("/${tag.templateDir}/simple/scripting-events.vm")
 />

src/java/template/simple/combobox.vm

 #if ($parameters.id)               id="$!webwork.htmlEncode($parameters.id)"                #end
 #if ($parameters.cssClass)         class="$!webwork.htmlEncode($parameters.cssClass)"       #end
 #if ($parameters.cssStyle)         style="$!webwork.htmlEncode($parameters.cssStyle)"       #end
-#parse("/template/simple/scripting-events.vm")
+#parse("/${tag.templateDir}/simple/scripting-events.vm")
 /><br/>
 
 #if ($parameters.list)

src/java/template/simple/file.vm

                                    name="$!webwork.htmlEncode($parameters.name)"
 #if ($parameters.size)             size="$!webwork.htmlEncode($parameters.size)"            #end
 #if ($parameters.nameValue)        value="$!webwork.htmlEncode($parameters.nameValue)"      #end
-#if ($parameters.disabled && $parameters.disabled == true) 
+#if ($parameters.disabled && $parameters.disabled == true)
                                    disabled="disabled"                                      #end
 #if ($parameters.id)               id="$!webwork.htmlEncode($parameters.id)"                #end
 #if ($parameters.accept)           accept="$!webwork.htmlEncode($parameters.accept)"        #end
 #if ($parameters.cssClass)         class="$!webwork.htmlEncode($parameters.cssClass)"       #end
 #if ($parameters.cssStyle)         style="$!webwork.htmlEncode($parameters.cssStyle)"       #end
-#parse("/template/simple/scripting-events.vm")
+#parse("/${tag.templateDir}/simple/scripting-events.vm")
 />

src/java/template/simple/password.vm

 #if ($parameters.tabindex)         tabindex="$!webwork.htmlEncode($parameters.tabindex)"    #end
 #if ($parameters.id)               id="$!webwork.htmlEncode($parameters.id)"                #end
 #if ($parameters.cssClass)         class="$!webwork.htmlEncode($parameters.cssClass)"       #end
-#parse("/template/simple/scripting-events.vm")
+#parse("/${tag.templateDir}/simple/scripting-events.vm")
 />

src/java/template/simple/radiomap.vm

             #if ($parameters.tabindex)  tabindex="$!webwork.htmlEncode($parameters.tabindex)" #end
             #if ($parameters.cssClass)  class="$!webwork.htmlEncode($parameters.cssClass)"    #end
             #if ($parameters.cssStyle)  style="$!webwork.htmlEncode($parameters.cssStyle)"    #end
-            #parse("/template/simple/scripting-events.vm")
+            #parse("/${tag.templateDir}/simple/scripting-events.vm")
         /><label for="$!webwork.htmlEncode($parameters.name)$!webwork.htmlEncode($itemKey)">$!itemValue</label>
 
         #set ($trash = $stack.pop())

src/java/template/simple/select.vm

     #if ($parameters.multiple)         multiple="multiple"                                   #end
     #if ($parameters.cssClass)         class="$!webwork.htmlEncode($parameters.cssClass)"    #end
     #if ($parameters.cssStyle)         style="$!webwork.htmlEncode($parameters.cssStyle)"    #end
-    #parse("/template/simple/scripting-events.vm")
+    #parse("/${tag.templateDir}/simple/scripting-events.vm")
 >
 
 #if ($parameters.headerKey && $parameters.headerValue)

src/java/template/simple/text.vm

 #if ($parameters.id)               id="$!webwork.htmlEncode($parameters.id)"                #end
 #if ($parameters.cssClass)         class="$!webwork.htmlEncode($parameters.cssClass)"       #end
 #if ($parameters.cssStyle)         style="$!webwork.htmlEncode($parameters.cssStyle)"       #end
-#parse("/template/simple/scripting-events.vm")
+#parse("/${tag.templateDir}/simple/scripting-events.vm")
 />

src/java/template/simple/textarea.vm

 #if ($parameters.id)               id="$!webwork.htmlEncode($parameters.id)"                #end
 #if ($parameters.cssClass)         class="$!webwork.htmlEncode($parameters.cssClass)"       #end
 #if ($parameters.cssStyle)         style="$!webwork.htmlEncode($parameters.cssStyle)"       #end
-#parse("/template/simple/scripting-events.vm")
+#parse("/${tag.templateDir}/simple/scripting-events.vm")
 >#if ($parameters.nameValue)$!webwork.htmlEncode($parameters.nameValue)#end</textarea>

src/java/template/xhtml/checkbox.vm

 #* Use an extra table so that the checkbox doesn't align with the other columns. *#
 <table width="100%" border="0" cellpadding="0" cellspacing="0">
     <tr>
-        <td valign="middle">#parse("/template/simple/checkbox.vm")</td>
+        <td valign="middle">#parse("$!{tag.templateDir}/simple/checkbox.vm")</td>
         <td width="100%" valign="middle"><label #if ($parameters.id) for="$!webwork.htmlEncode($parameters.id)"#end#if ($hasFieldErrors) class="checkboxErrorLabel"#else class="checkboxLabel"#end>$!webwork.htmlEncode($parameters.label)</label></td>
     </tr>
 </table>
-#parse("/template/xhtml/controlfooter.vm")
+#parse("/${tag.templateDir}/xhtml/controlfooter.vm")

src/java/template/xhtml/checkboxlist.vm

-#parse( "/template/xhtml/controlheader.vm" )
+#parse( "$!{tag.templateDir}xhtml/controlheader.vm" )
 #set( $items = $parameters.list )
 #if( $items )
     #set( $itemCount = 0 )
 #else
   &nbsp;
 #end
-#parse( "/template/xhtml/controlfooter.vm" )
+#parse( "/${tag.templateDir}/xhtml/controlfooter.vm" )

src/java/template/xhtml/combobox.vm

-#parse("/template/xhtml/controlheader.vm")#parse("/template/simple/combobox.vm")#parse("/template/xhtml/controlfooter.vm")
+#parse("/${tag.templateDir}/xhtml/controlheader.vm")#parse("/${tag.templateDir}/simple/combobox.vm")#parse("/${tag.templateDir}/xhtml/controlfooter.vm")

src/java/template/xhtml/doubleselect.vm

-#parse("/template/xhtml/controlheader.vm")#parse("/template/simple/doubleselect.vm")#parse("/template/xhtml/controlfooter.vm")
+#parse("/${tag.templateDir}/xhtml/controlheader.vm")#parse("/${tag.templateDir}/simple/doubleselect.vm")#parse("/${tag.templateDir}/xhtml/controlfooter.vm")

src/java/template/xhtml/file.vm

-#parse("/template/xhtml/controlheader.vm")#parse("/template/simple/file.vm")#parse("/template/xhtml/controlfooter.vm")
+#parse("/${tag.templateDir}/xhtml/controlheader.vm")#parse("/${tag.templateDir}/simple/file.vm")#parse("/${tag.templateDir}/xhtml/controlfooter.vm")

src/java/template/xhtml/form-close.vm

 </table>
-#parse("/template/simple/form-close.vm")
+#parse("/${tag.templateDir}/simple/form-close.vm")

src/java/template/xhtml/form.vm

-#parse("/template/simple/form.vm")
+#parse("/${tag.templateDir}/simple/form.vm")
 <table class="wwFormTable">

src/java/template/xhtml/hidden.vm

-#parse("/template/simple/hidden.vm")
+#parse("/${tag.templateDir}/simple/hidden.vm")

src/java/template/xhtml/label.vm

-#parse("/template/xhtml/controlheader.vm")#parse("/template/simple/label.vm")#parse("/template/xhtml/controlfooter.vm")
+#parse("/${tag.templateDir}/xhtml/controlheader.vm")#parse("/${tag.templateDir}/simple/label.vm")#parse("/${tag.templateDir}/xhtml/controlfooter.vm")

src/java/template/xhtml/password.vm

-#parse("/template/xhtml/controlheader.vm")#parse("/template/simple/password.vm")#parse("/template/xhtml/controlfooter.vm")
+#parse("/${tag.templateDir}/xhtml/controlheader.vm")#parse("/${tag.templateDir}/simple/password.vm")#parse("/${tag.templateDir}/xhtml/controlfooter.vm")

src/java/template/xhtml/radiomap.vm

-#parse("/template/xhtml/controlheader.vm")#parse("/template/simple/radiomap.vm")#parse("/template/xhtml/controlfooter.vm")
+#parse("/${tag.templateDir}/xhtml/controlheader.vm")#parse("/${tag.templateDir}/simple/radiomap.vm")#parse("/${tag.templateDir}/xhtml/controlfooter.vm")

src/java/template/xhtml/select.vm

-#parse("/template/xhtml/controlheader.vm")#parse("/template/simple/select.vm")#parse("/template/xhtml/controlfooter.vm")
+#parse("/${tag.templateDir}/xhtml/controlheader.vm")#parse("/${tag.templateDir}/simple/select.vm")#parse("/${tag.templateDir}/xhtml/controlfooter.vm")

src/java/template/xhtml/submit.vm

 <tr>
     <td colspan="2"><div #if ($parameters.align) align="$!webwork.htmlEncode($parameters.align)" #end
->#parse("/template/simple/submit.vm")</div>#parse( "/template/xhtml/controlfooter.vm" )
+>#parse("/${tag.templateDir}/simple/submit.vm")</div>#parse( "/${tag.templateDir}/xhtml/controlfooter.vm" )

src/java/template/xhtml/tabbedpane.vm

-#parse("/template/simple/tabbedpane.vm")
+#parse("/${tag.templateDir}/simple/tabbedpane.vm")

src/java/template/xhtml/table.vm

-#parse("/template/simple/table.vm")
+#parse("/${tag.templateDir}/simple/table.vm")

src/java/template/xhtml/text.vm

-#parse("/template/xhtml/controlheader.vm")#parse("/template/simple/text.vm")#parse("/template/xhtml/controlfooter.vm")
+#parse("/${tag.templateDir}/xhtml/controlheader.vm")#parse("/${tag.templateDir}/simple/text.vm")#parse("/${tag.templateDir}/xhtml/controlfooter.vm")

src/java/template/xhtml/textarea.vm

-#parse("/template/xhtml/controlheader.vm")#parse("/template/simple/textarea.vm")#parse("/template/xhtml/controlfooter.vm")
+#parse("/${tag.templateDir}/xhtml/controlheader.vm")#parse("/${tag.templateDir}/simple/textarea.vm")#parse("/${tag.templateDir}/xhtml/controlfooter.vm")
 

src/java/template/xhtml/token.vm

-#parse("/template/simple/token.vm")
+#parse("/${tag.templateDir}/simple/token.vm")