You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2010/01/06 21:38:40 UTC
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
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<String> 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