Return-Path: Delivered-To: apmail-tapestry-dev-archive@www.apache.org Received: (qmail 85416 invoked from network); 6 Jan 2010 20:39:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 6 Jan 2010 20:39:05 -0000 Received: (qmail 50863 invoked by uid 500); 6 Jan 2010 20:39:04 -0000 Delivered-To: apmail-tapestry-dev-archive@tapestry.apache.org Received: (qmail 50776 invoked by uid 500); 6 Jan 2010 20:39:04 -0000 Mailing-List: contact commits-help@tapestry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tapestry.apache.org Delivered-To: mailing list commits@tapestry.apache.org Received: (qmail 50767 invoked by uid 99); 6 Jan 2010 20:39:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jan 2010 20:39:04 +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; Wed, 06 Jan 2010 20:39:02 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 2042223889D2; Wed, 6 Jan 2010 20:38:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r896657 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java test/java/org/apache/tapestry5/internal/services/PartialDocumentLinkerImplTest.java Date: Wed, 06 Jan 2010 20:38:40 -0000 To: commits@tapestry.apache.org From: hlship@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100106203841.2042223889D2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: hlship Date: Wed Jan 6 20:38:39 2010 New Revision: 896657 URL: http://svn.apache.org/viewvc?rev=896657&view=rev Log: TAP5-765: Included JavaScript libraries are not properly uniqued within an Ajax partial update response Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PartialDocumentLinkerImplTest.java (with props) Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java?rev=896657&r1=896656&r2=896657&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java Wed Jan 6 20:38:39 2010 @@ -1,10 +1,10 @@ -// Copyright 2008 The Apache Software Foundation +// Copyright 2008, 2010 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -14,6 +14,9 @@ package org.apache.tapestry5.internal.services; +import java.util.Set; + +import org.apache.tapestry5.ioc.internal.util.CollectionFactory; import org.apache.tapestry5.json.JSONArray; import org.apache.tapestry5.json.JSONObject; @@ -25,19 +28,32 @@ private final JSONArray stylesheets = new JSONArray(); + private final Set uniquer = CollectionFactory.newSet(); + public void addScriptLink(String scriptURL) { + if (uniquer.contains(scriptURL)) + return; + scripts.put(scriptURL); + + uniquer.add(scriptURL); } public void addStylesheetLink(String styleURL, String media) { + if (uniquer.contains(styleURL)) + return; + JSONObject object = new JSONObject(); object.put("href", styleURL); - if (media != null) object.put("media", media); + if (media != null) + object.put("media", media); stylesheets.put(object); + + uniquer.add(styleURL); } public void addScript(String script) @@ -48,8 +64,9 @@ /** * Commits changes, adding one or more keys to the reply. - * - * @param reply JSON Object to be sent to client + * + * @param reply + * JSON Object to be sent to client */ public void commit(JSONObject reply) { Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PartialDocumentLinkerImplTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PartialDocumentLinkerImplTest.java?rev=896657&view=auto ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PartialDocumentLinkerImplTest.java (added) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PartialDocumentLinkerImplTest.java Wed Jan 6 20:38:39 2010 @@ -0,0 +1,57 @@ +// Copyright 2010 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.apache.tapestry5.internal.services; + +import org.apache.tapestry5.json.JSONObject; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class PartialDocumentLinkerImplTest extends Assert +{ + @Test + public void script_link_uniqueness() + { + PartialMarkupDocumentLinker linker = new PartialMarkupDocumentLinker(); + + linker.addScriptLink("foo.js"); + linker.addScriptLink("bar.js"); + linker.addScriptLink("foo.js"); + + JSONObject reply = new JSONObject(); + + linker.commit(reply); + + assertEquals(reply.toString(), "{\"scripts\":[\"foo.js\",\"bar.js\"]}"); + } + + @Test + public void stylesheet_link_uniqueness() + { + PartialMarkupDocumentLinker linker = new PartialMarkupDocumentLinker(); + + linker.addStylesheetLink("foo.css", null); + linker.addStylesheetLink("bar.css", "print"); + linker.addStylesheetLink("bar.css", "screen"); + linker.addStylesheetLink("foo.css", null); + + JSONObject reply = new JSONObject(); + + linker.commit(reply); + + assertEquals(reply.toString(), + "{\"stylesheets\":[{\"href\":\"foo.css\"},{\"media\":\"print\",\"href\":\"bar.css\"}]}"); + + } +} Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PartialDocumentLinkerImplTest.java ------------------------------------------------------------------------------ svn:eol-style = native