Return-Path: Delivered-To: apmail-click-commits-archive@www.apache.org Received: (qmail 68559 invoked from network); 18 Jul 2010 12:55:26 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 18 Jul 2010 12:55:26 -0000 Received: (qmail 35997 invoked by uid 500); 18 Jul 2010 12:55:26 -0000 Delivered-To: apmail-click-commits-archive@click.apache.org Received: (qmail 35971 invoked by uid 500); 18 Jul 2010 12:55:25 -0000 Mailing-List: contact commits-help@click.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: click-dev@click.apache.org Delivered-To: mailing list commits@click.apache.org Received: (qmail 35963 invoked by uid 99); 18 Jul 2010 12:55:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Jul 2010 12:55:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Jul 2010 12:55:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7AC4D2388A36; Sun, 18 Jul 2010 12:54:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r965221 - in /click/trunk/click/extras/src/org/apache/click/extras/control: Menu.java MenuFactory.java Date: Sun, 18 Jul 2010 12:54:28 -0000 To: commits@click.apache.org From: sabob@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100718125428.7AC4D2388A36@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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);