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 2011/09/23 02:41:00 UTC
svn commit: r1174466 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/corelib/components/
main/java/org/apache/tapestry5/dom/
main/java/org/apache/tapestry5/internal/structure/
test/groovy/org/apache/tapestry5/integratio...
Author: hlship
Date: Fri Sep 23 00:40:59 2011
New Revision: 1174466
URL: http://svn.apache.org/viewvc?rev=1174466&view=rev
Log:
TAP5-840: Add Doctype component for greater control of rendered <!DOCTYPE>
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Doctype.java
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/DoctypeTests.groovy
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/DTD.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Document.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/DTDPageElement.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/Border.java
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/components/Border.tml
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Doctype.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Doctype.java?rev=1174466&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Doctype.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Doctype.java Fri Sep 23 00:40:59 2011
@@ -0,0 +1,43 @@
+// Copyright 2011 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.corelib.components;
+
+import org.apache.tapestry5.BindingConstants;
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.annotations.Parameter;
+
+/**
+ * Overrides the DOCTYPE of the rendered document (via {@link org.apache.tapestry5.dom.Document#dtd(String, String, String)}
+ * which can be useful when different component templates that render to the same document disagree about what the correct DOCTYPE
+ * is.
+ *
+ * @tapestrydoc
+ * @since 5.3
+ */
+public class Doctype
+{
+ @Parameter(required = true, allowNull = false, defaultPrefix = BindingConstants.LITERAL)
+ private String name;
+
+ @Parameter(defaultPrefix = BindingConstants.LITERAL)
+ private String publicId, systemId;
+
+ boolean beginRender(MarkupWriter writer)
+ {
+ writer.getDocument().dtd(name, publicId, systemId);
+
+ return false;
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/DTD.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/DTD.java?rev=1174466&r1=1174465&r2=1174466&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/DTD.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/DTD.java Fri Sep 23 00:40:59 2011
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2011 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.
@@ -14,6 +14,8 @@
package org.apache.tapestry5.dom;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+
import java.io.PrintWriter;
/**
@@ -30,6 +32,8 @@ public class DTD
public DTD(String name, String publicId, String systemId)
{
+ assert InternalUtils.isNonBlank(name);
+
this.name = name;
this.publicId = publicId;
this.systemId = systemId;
@@ -42,17 +46,14 @@ public class DTD
if (systemId != null)
{
writer.printf("<!DOCTYPE %s PUBLIC \"%s\" \"%s\">", name, publicId, systemId);
- }
- else
+ } else
{
writer.printf("<!DOCTYPE %s PUBLIC \"%s\">", name, publicId);
}
- }
- else if (systemId != null)
+ } else if (systemId != null)
{
writer.printf("<!DOCTYPE %s SYSTEM \"%s\">", name, systemId);
- }
- else
+ } else
{
writer.printf("<!DOCTYPE %s>", name);
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Document.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Document.java?rev=1174466&r1=1174465&r2=1174466&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Document.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Document.java Fri Sep 23 00:40:59 2011
@@ -14,14 +14,14 @@
package org.apache.tapestry5.dom;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+
import java.io.PrintWriter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
-import org.apache.tapestry5.ioc.internal.util.InternalUtils;
-
/**
* The root node of a DOM.
*/
@@ -73,9 +73,8 @@ public final class Document extends Node
/**
* Finds an element based on a path of element names.
- *
- * @param path
- * slash separated series of element names
+ *
+ * @param path slash separated series of element names
* @return the matching element, or null if not found
* @see Element#find(String)
*/
@@ -121,11 +120,9 @@ public final class Document extends Node
/**
* Creates a new root element within a namespace.
- *
- * @param namespace
- * URI of namespace containing the element
- * @param name
- * name of element with namespace
+ *
+ * @param namespace URI of namespace containing the element
+ * @param name name of element with namespace
* @return the root element
*/
public Element newRootElement(String namespace, String name)
@@ -176,9 +173,8 @@ public final class Document extends Node
/**
* Tries to find an element in this document whose id is specified.
- *
- * @param id
- * the value of the id attribute of the element being looked for
+ *
+ * @param id the value of the id attribute of the element being looked for
* @return the element if found. null if not found.
*/
public Element getElementById(String id)
@@ -186,24 +182,43 @@ public final class Document extends Node
return rootElement.getElementById(id);
}
+ /**
+ * Sets the DTD for the document, overriding any prior DTD.
+ *
+ * @param name non-blank name of document type (i.e., "html")
+ * @param publicId optional
+ * @param systemId optional
+ */
public void dtd(String name, String publicId, String systemId)
{
dtd = new DTD(name, publicId, systemId);
}
+ /**
+ * Returns true if the document has an explicit DTD (set via {@link #dtd(String, String, String)}).
+ *
+ * @since 5.3
+ */
+ public boolean hasDTD()
+ {
+ return dtd != null;
+ }
+
@Override
protected Map<String, String> getNamespaceURIToPrefix()
{
- if (rootElement == null) { return Collections.emptyMap(); }
+ if (rootElement == null)
+ {
+ return Collections.emptyMap();
+ }
return rootElement.getNamespaceURIToPrefix();
}
/**
* Visits the root element of the document.
- *
- * @param visitor
- * callback
+ *
+ * @param visitor callback
* @since 5.1.0.0
*/
void visit(Visitor visitor)
@@ -223,7 +238,7 @@ public final class Document extends Node
/**
* Adds the comment and returns this document for further construction.
- *
+ *
* @since 5.1.0.0
*/
public Document comment(String text)
@@ -235,7 +250,7 @@ public final class Document extends Node
/**
* Adds the raw text and returns this document for further construction.
- *
+ *
* @since 5.1.0.0
*/
public Document raw(String text)
@@ -248,9 +263,8 @@ public final class Document extends Node
/**
* Adds and returns a new text node (the text node is returned so that {@link Text#write(String)} or [@link
* {@link Text#writef(String, Object[])} may be invoked.
- *
- * @param text
- * initial text for the node
+ *
+ * @param text initial text for the node
* @return the new Text node
*/
public Text text(String text)
@@ -260,9 +274,8 @@ public final class Document extends Node
/**
* Adds and returns a new CDATA node.
- *
- * @param content
- * the content to be rendered by the node
+ *
+ * @param content the content to be rendered by the node
* @return the newly created node
*/
public CData cdata(String content)
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/DTDPageElement.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/DTDPageElement.java?rev=1174466&r1=1174465&r2=1174466&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/DTDPageElement.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/DTDPageElement.java Fri Sep 23 00:40:59 2011
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2011 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.
@@ -15,6 +15,7 @@
package org.apache.tapestry5.internal.structure;
import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.dom.Document;
import org.apache.tapestry5.runtime.RenderCommand;
import org.apache.tapestry5.runtime.RenderQueue;
@@ -35,7 +36,12 @@ public class DTDPageElement implements R
public void render(MarkupWriter writer, RenderQueue queue)
{
- writer.getDocument().dtd(name, publicId, systemId);
+ Document document = writer.getDocument();
+
+ if (!document.hasDTD())
+ {
+ document.dtd(name, publicId, systemId);
+ }
}
@Override
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/DoctypeTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/DoctypeTests.groovy?rev=1174466&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/DoctypeTests.groovy (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/DoctypeTests.groovy Fri Sep 23 00:40:59 2011
@@ -0,0 +1,33 @@
+// Copyright 2011 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.integration.app1;
+
+
+import org.apache.tapestry5.integration.TapestryCoreTestCase
+import org.testng.annotations.Test
+
+/**
+ * Tests for the {@link org.apache.tapestry5.corelib.components.Doctype} component.
+ */
+class DoctypeTests extends TapestryCoreTestCase
+{
+ @Test
+ void doctype_overridden_via_component()
+ {
+
+ assert new URL(baseURL).text.startsWith("<!DOCTYPE html>")
+
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/Border.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/Border.java?rev=1174466&r1=1174465&r2=1174466&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/Border.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/components/Border.java Fri Sep 23 00:40:59 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2011 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.
@@ -15,10 +15,8 @@
package org.apache.tapestry5.integration.app1.components;
import org.apache.tapestry5.annotations.Import;
+import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.ioc.services.Builtin;
-import org.apache.tapestry5.ioc.services.ClassFactory;
-import org.apache.tapestry5.services.ComponentLayer;
import org.apache.tapestry5.services.Request;
/**
@@ -26,35 +24,13 @@ import org.apache.tapestry5.services.Req
* T5 naming.
*/
@Import(stylesheet =
-{ "context:layout/style.css", "context:css/app.css" })
+ {"context:layout/style.css", "context:css/app.css"})
public class Border
{
@Inject
- @Builtin
- private ClassFactory iocClassFactory;
-
- @Inject
- @ComponentLayer
- private ClassFactory componentClassFactory;
-
- @Inject
+ @Property
private Request request;
- public ClassFactory getComponentClassFactory()
- {
- return componentClassFactory;
- }
-
- public ClassFactory getIocClassFactory()
- {
- return iocClassFactory;
- }
-
- public Request getRequest()
- {
- return request;
- }
-
public String getSecure()
{
return request.isSecure() ? "secure" : "insecure";
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/components/Border.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/components/Border.tml?rev=1174466&r1=1174465&r2=1174466&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/components/Border.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/components/Border.tml Fri Sep 23 00:40:59 2011
@@ -1,73 +1,70 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
-<head>
- <title>Tapestry Integration Test Application #1</title>
-</head>
-<body>
-<div id="wrap">
-
- <div id="header">
- <h1>Tapestry Integration Test Application</h1>
- </div>
-
- <div id="content">
- <div id="topspread">
- <t:alerts/>
- <t:body/>
- </div>
-
-
- <div id="right">
- <div class="menu">
- <h4>Navigation</h4>
- <ul>
- <li>
- Page:
- <span id="activePageName">${componentResources.pageName}</span>
- </li>
- <li>Access:
- <span id="secure">${secure}</span>
- </li>
- <li>
- <t:pagelink page="index">Back to index</t:pagelink>
- </li>
- </ul>
-
- <h4>Infrastructure</h4>
-
- <dl>
- <dt>IOC Layer: ${iocClassFactory.createdClassCount} classes</dt>
- <dd>Service proxies and interceptors</dd>
-
- <dt>Component Layer: ${componentClassFactory.createdClassCount} classes</dt>
- <dt>Locale:</dt>
- <dd>${componentResources.locale}</dd>
- </dl>
-
- </div>
- </div>
-
- <div id="left">
- <h3>Request info:</h3>
-
- <t:renderobject object="request"/>
-
- </div>
-
-
- <div style="clear:both;"></div>
-
-
- </div>
- <div id="footer">
- © 2008-2010
- <a href="http://apache.org/">Apache Software Foundation</a>
- </div>
-
- <div id="bottom"/>
-
-</div>
-
-
-</body>
-</html>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+<head>
+ <title>Tapestry Integration Test Application #1</title>
+ <t:doctype name="html"/>
+</head>
+<body>
+<div id="wrap">
+
+ <div id="header">
+ <h1>Tapestry Integration Test Application</h1>
+ </div>
+
+ <div id="content">
+ <div id="topspread">
+ <t:alerts/>
+ <t:body/>
+ </div>
+
+
+ <div id="right">
+ <div class="menu">
+ <h4>Navigation</h4>
+ <ul>
+ <li>
+ Page:
+ <span id="activePageName">${componentResources.pageName}</span>
+ </li>
+ <li>Access:
+ <span id="secure">${secure}</span>
+ </li>
+ <li>
+ <t:pagelink page="index">Back to index</t:pagelink>
+ </li>
+ </ul>
+
+ <h4>Infrastructure</h4>
+
+ <dl>
+ <dt>Locale:</dt>
+ <dd>${componentResources.locale}</dd>
+ </dl>
+
+ </div>
+ </div>
+
+ <div id="left">
+ <h3>Request info:</h3>
+
+ <t:renderobject object="request"/>
+
+ </div>
+
+
+ <div style="clear:both;"></div>
+
+
+ </div>
+ <div id="footer">
+ © 2008-2010
+ <a href="http://apache.org/">Apache Software Foundation</a>
+ </div>
+
+ <div id="bottom"/>
+
+</div>
+
+
+</body>
+</html>