You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/07/18 14:54:28 UTC

svn commit: r965221 - in /click/trunk/click/extras/src/org/apache/click/extras/control: Menu.java MenuFactory.java

Author: sabob
Date: Sun Jul 18 12:54:28 2010
New Revision: 965221

URL: http://svn.apache.org/viewvc?rev=965221&view=rev
Log:
fixed race condition while intializing cached menu. CLK-713

Modified:
    click/trunk/click/extras/src/org/apache/click/extras/control/Menu.java
    click/trunk/click/extras/src/org/apache/click/extras/control/MenuFactory.java

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/Menu.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/Menu.java?rev=965221&r1=965220&r2=965221&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/Menu.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/Menu.java Sun Jul 18 12:54:28 2010
@@ -565,7 +565,7 @@ public class Menu extends AbstractContro
      * @return true if the menu contains any child submenus
      */
     public boolean hasChildren() {
-        if (children == null || children.size() == 0) {
+        if (children == null || children.isEmpty()) {
             return false;
         }
         return true;
@@ -688,16 +688,16 @@ public class Menu extends AbstractContro
             return label;
         }
 
-        String name = getName();
+        String localName = getName();
 
-        if (name != null) {
+        if (localName != null) {
             Menu root = findRootMenu();
 
             // Use root menu messages to lookup the label
-            String i18nLabel = root.getMessage(name + ".label");
+            String i18nLabel = root.getMessage(localName + ".label");
 
             if (i18nLabel == null) {
-                i18nLabel = ClickUtils.toLabel(name);
+                i18nLabel = ClickUtils.toLabel(localName);
             }
 
             // NOTE: don't cache the i18nLabel, since menus are often cached
@@ -802,10 +802,10 @@ public class Menu extends AbstractContro
             selected = true;
 
         } else {
-            String path = getPath();
-            if (path != null) {
-                path = path.startsWith("/") ? path : "/" + path;
-                selected = path.equals(pageToView);
+            String localPath = getPath();
+            if (localPath != null) {
+                localPath = localPath.startsWith("/") ? localPath : "/" + localPath;
+                selected = localPath.equals(pageToView);
             } else {
                 selected = false;
             }
@@ -966,15 +966,15 @@ public class Menu extends AbstractContro
             return title;
         }
 
-        String name = getName();
+        String localName = getName();
 
-        if (name != null) {
+        if (localName != null) {
             // Use root menu messages to lookup the title
             Menu root = findRootMenu();
 
             // NOTE: don't cache the i18nTitle, since menus are often cached
             // statically
-            return root.getMessage(name + ".title");
+            return root.getMessage(localName + ".title");
         }
 
         return null;
@@ -1003,21 +1003,21 @@ public class Menu extends AbstractContro
      * @return the menu anchor HREF attribute
      */
     public String getHref() {
-        String path = getPath();
+        String localPath = getPath();
         if (isExternal()) {
-            return path;
+            return localPath;
         }
 
-        if ("#".equals(path)) {
-            return getContext().getResponse().encodeURL(path);
+        if ("#".equals(localPath)) {
+            return getContext().getResponse().encodeURL(localPath);
 
         } else {
             Context context = getContext();
-            if (path == null) {
+            if (localPath == null) {
                 // Guard against rendering "null" in the href
-                path = "";
+                localPath = "";
             }
-            return context.getResponse().encodeURL(context.getRequest().getContextPath() + "/" + path);
+            return context.getResponse().encodeURL(context.getRequest().getContextPath() + "/" + localPath);
         }
     }
 
@@ -1057,14 +1057,10 @@ public class Menu extends AbstractContro
             jsImport = new JsImport("/click/menu-fix-ie6.js", versionIndicator);
             jsImport.setConditionalComment(JsImport.IF_LESS_THAN_IE7);
             headElements.add(jsImport);
-        }
 
-        // Note: the setup script is recreated and checked if it is contained in
-        // the headElement. This check cater for when the menu is used by another
-        // Control using the fly-weight pattern eg. FormTable.
-        JsScript script = new JsScript();
-        script.setId(id + "-js-setup");
-        if (!headElements.contains(script)) {
+            JsScript script = new JsScript();
+            script.setId(id + "-js-setup");
+
             // Script must be executed as soon as browser dom is ready
             script.setExecuteOnDomReady(true);
             script.setConditionalComment(JsImport.IF_LESS_THAN_IE7);

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/MenuFactory.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/MenuFactory.java?rev=965221&r1=965220&r2=965221&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/MenuFactory.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/MenuFactory.java Sun Jul 18 12:54:28 2010
@@ -301,6 +301,10 @@ public class MenuFactory implements Seri
 
         Menu rootMenu = loadFromMenuXml(name, fileName, accessController, menuClass);
 
+        // Retrieve headElements to guard against race conditions when initializing
+        // menus from multiple threads. CLK-713
+        rootMenu.getHeadElements();
+
         ServletContext servletContext = Context.getThreadLocalContext().getServletContext();
         ConfigService configService = ClickUtils.getConfigService(servletContext);