You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2009/01/12 00:18:22 UTC
svn commit: r733538 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/dom/
main/java/org/apache/tapestry5/internal/services/
test/java/org/apache/tapestry5/dom/ test/resources/org/apache/tapestry5/dom/
Author: hlship
Date: Sun Jan 11 15:18:21 2009
New Revision: 733538
URL: http://svn.apache.org/viewvc?rev=733538&view=rev
Log:
TAP5-100: When rendering a partial markup response, Tapestry should quote attributes with single quotes (so that each quote doesn't have to be escaped in the JSON)
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/dom/quote_using_apostrophes.txt
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/AbstractMarkupModel.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/DefaultMarkupModel.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/MarkupModel.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/XMLMarkupModel.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/AbstractMarkupModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/AbstractMarkupModel.java?rev=733538&r1=733537&r2=733538&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/AbstractMarkupModel.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/AbstractMarkupModel.java Sun Jan 11 15:18:21 2009
@@ -1,4 +1,4 @@
-// Copyright 2008 The Apache Software Foundation
+// Copyright 2008, 2009 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.
@@ -16,6 +16,18 @@
public abstract class AbstractMarkupModel implements MarkupModel
{
+ private final boolean useApostropheForAttributes;
+
+ protected AbstractMarkupModel(boolean useApostropheForAttributes)
+ {
+ this.useApostropheForAttributes = useApostropheForAttributes;
+ }
+
+ public char getAttributeQuote()
+ {
+ return useApostropheForAttributes ? '\'' : '"';
+ }
+
/**
* Passes all characters but '<', '>' and '&' through unchanged.
*/
@@ -104,9 +116,26 @@
case '"':
- builder.append(""");
+ if (!useApostropheForAttributes)
+ {
+ builder.append(""");
+ continue;
+ }
+
+ builder.append(ch);
continue;
+ case '\'':
+
+ if (useApostropheForAttributes)
+ {
+ builder.append("'");
+ continue;
+ }
+
+
+ // Fall through
+
default:
builder.append(ch);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/DefaultMarkupModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/DefaultMarkupModel.java?rev=733538&r1=733537&r2=733538&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/DefaultMarkupModel.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/DefaultMarkupModel.java Sun Jan 11 15:18:21 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 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.
@@ -28,6 +28,16 @@
{
private final Set<String> ALWAYS_EMPTY = CollectionFactory.newSet("hr", "br", "img");
+ public DefaultMarkupModel()
+ {
+ this(false);
+ }
+
+ public DefaultMarkupModel(boolean useApostropheForAttributes)
+ {
+ super(useApostropheForAttributes);
+ }
+
public EndTagStyle getEndTagStyle(String element)
{
boolean alwaysEmpty = ALWAYS_EMPTY.contains(element);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java?rev=733538&r1=733537&r2=733538&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java Sun Jan 11 15:18:21 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 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.
@@ -48,9 +48,10 @@
{
builder.append(" ");
builder.append(toPrefixedName(namespaceURIToPrefix, namespace, name));
- builder.append("=\"");
+ builder.append("=");
+ builder.append(model.getAttributeQuote());
model.encodeQuoted(value, builder);
- builder.append('"');
+ builder.append(model.getAttributeQuote());
}
}
@@ -323,11 +324,12 @@
builder.append(":").append(prefix);
}
- builder.append("=\"");
+ builder.append("=");
+ builder.append(markupModel.getAttributeQuote());
markupModel.encodeQuoted(namespace, builder);
- builder.append('"');
+ builder.append(markupModel.getAttributeQuote());
}
EndTagStyle style = markupModel.getEndTagStyle(name);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/MarkupModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/MarkupModel.java?rev=733538&r1=733537&r2=733538&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/MarkupModel.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/MarkupModel.java Sun Jan 11 15:18:21 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 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.
@@ -54,4 +54,13 @@
* @return true for XML output, false for HTML output
*/
boolean isXML();
+
+ /**
+ * What character is used when generating quotes around attribute values? This will be either a single or double
+ * quote.
+ *
+ * @return single (') or double (") quote
+ * @since 5.1.0.0
+ */
+ char getAttributeQuote();
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/XMLMarkupModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/XMLMarkupModel.java?rev=733538&r1=733537&r2=733538&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/XMLMarkupModel.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/XMLMarkupModel.java Sun Jan 11 15:18:21 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2008 The Apache Software Foundation
+// Copyright 2006, 2008, 2009 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.
@@ -19,6 +19,16 @@
*/
public final class XMLMarkupModel extends AbstractMarkupModel
{
+ public XMLMarkupModel()
+ {
+ this(false);
+ }
+
+ public XMLMarkupModel(boolean useApostropheForAttributes)
+ {
+ super(useApostropheForAttributes);
+ }
+
/**
* Always returns ABBREVIATE.
*/
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java?rev=733538&r1=733537&r2=733538&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MarkupWriterFactoryImpl.java Sun Jan 11 15:18:21 2009
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2009 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.
@@ -32,6 +32,10 @@
private final MarkupModel xmlModel = new XMLMarkupModel();
+ private final MarkupModel htmlPartialModel = new DefaultMarkupModel(true);
+
+ private final MarkupModel xmlPartialModel = new XMLMarkupModel(true);
+
public MarkupWriterFactoryImpl(PageContentTypeAnalyzer analyzer, RequestPageCache cache)
{
this.analyzer = analyzer;
@@ -53,7 +57,9 @@
{
boolean isHTML = contentType.getMimeType().equalsIgnoreCase("text/html");
- MarkupModel model = isHTML ? htmlModel : xmlModel;
+ MarkupModel model = partial
+ ? (isHTML ? htmlPartialModel : xmlPartialModel)
+ : (isHTML ? htmlModel : xmlModel);
// The charset parameter sets the encoding attribute of the XML declaration, if
// not null and if using the XML model.
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java?rev=733538&r1=733537&r2=733538&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java Sun Jan 11 15:18:21 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 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.
@@ -55,12 +55,31 @@
Element nested = root.elementNS("fredns", "nested");
- Element deepest = nested.elementNS("barneyns", "deepest");
+ nested.elementNS("barneyns", "deepest");
assertEquals(d.toString(), readFile("namespaced_elements.txt"));
}
@Test
+ public void quote_using_apostrophes() throws Exception
+ {
+ Document d = new Document(new XMLMarkupModel(true));
+
+ Element root = d.newRootElement("fredns", "root");
+
+ root.defineNamespace("fredns", "f");
+ root.defineNamespace("barneyns", "b");
+
+ Element nested = root.elementNS("fredns", "nested");
+
+ nested.attribute("attribute", "value");
+
+ nested.elementNS("barneyns", "deepest");
+
+ assertEquals(d.toString(), readFile("quote_using_apostrophes.txt"));
+ }
+
+ @Test
public void namespace_element_without_a_prefix() throws Exception
{
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/dom/quote_using_apostrophes.txt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/dom/quote_using_apostrophes.txt?rev=733538&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/dom/quote_using_apostrophes.txt (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/dom/quote_using_apostrophes.txt Sun Jan 11 15:18:21 2009
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<f:root xmlns:b='barneyns' xmlns:f='fredns'><f:nested attribute='value'><b:deepest/></f:nested></f:root>