Author: hlship
Date: Thu Mar 5 19:10:59 2009
New Revision: 750553
URL: http://svn.apache.org/viewvc?rev=750553&view=rev
Log:
TAP5-92: Add support for server-side only comments
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/comment_element_ignored.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/comment_may_not_contain_elements.tml
Modified:
tapestry/tapestry5/trunk/src/site/apt/guide/templates.apt
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StaxTemplateParser.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
Modified: tapestry/tapestry5/trunk/src/site/apt/guide/templates.apt
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/apt/guide/templates.apt?rev=750553&r1=750552&r2=750553&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/src/site/apt/guide/templates.apt (original)
+++ tapestry/tapestry5/trunk/src/site/apt/guide/templates.apt Thu Mar 5
19:10:59 2009
@@ -211,6 +211,16 @@
<parameter namespace> approach is more concise and readable.
+* \<comment\>
+
+ Delinates a server-side comment. Unlike ordinary XML/HTML comments (\<!-- ....
--\>) which may be includes in the response,
+ server-side comments are not ever part of the response (the are completely
excised from the template). This element
+ provides a way to store development sensitive data inside templates that
will never be exposed to clients.
+
+ Comment elements may contain text and XML/HTML comments, but not any nested
elements.
+
+ Support for the comment element was adding in Tapestry release 5.1.
+
Expansions
Another option when rendering output is the use of <expansions>. Expansions
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StaxTemplateParser.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StaxTemplateParser.java?rev=750553&r1=750552&r2=750553&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StaxTemplateParser.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/StaxTemplateParser.java
Thu Mar 5 19:10:59 2009
@@ -21,7 +21,6 @@
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.internal.util.LocationImpl;
import org.apache.tapestry5.ioc.internal.util.TapestryException;
-import org.codehaus.plexus.util.xml.pull.MXParser;
import org.codehaus.stax2.DTDInfo;
import org.codehaus.stax2.XMLInputFactory2;
import org.codehaus.stax2.XMLStreamReader2;
@@ -186,7 +185,7 @@
int eventType = reader.getEventType();
throw new IllegalStateException(
- String.format("Unexpected XML parse event %s.",
MXParser.TYPES[eventType - 1]));
+ String.format("Unexpected XML parse event %s.",
EVENT_NAMES[eventType]));
}
private void dtd() throws XMLStreamException
@@ -215,12 +214,10 @@
*/
void element(TemplateParserState initialState) throws XMLStreamException
{
-
processTextBuffer(initialState);
TemplateParserState state = checkForXMLSpaceAttribute(initialState);
-
if (!processStartElement(state)) return;
// Now start working through the body of the element, recursively.
@@ -308,6 +305,13 @@
return true;
}
+ if (name.equals("comment"))
+ {
+ ignoredComment();
+
+ return false;
+ }
+
possibleTapestryComponent(null, reader.getLocalName().replace('.',
'/'));
return true;
@@ -336,6 +340,36 @@
return true;
}
+ private void ignoredComment() throws XMLStreamException
+ {
+ while (active)
+ {
+ switch (reader.next())
+ {
+ // The matching end element.
+
+ case END_ELEMENT:
+ return;
+
+ // Ignore any characters or XML comments inside the comment.
+
+ case COMMENT:
+ case CDATA:
+ case CHARACTERS:
+ case SPACE:
+ break;
+
+ default:
+ int eventType = reader.getEventType();
+
+ throw new IllegalStateException(
+ String.format("Unexpected XML parse event %s within a
comment element.",
+ EVENT_NAMES[eventType]));
+
+ }
+ }
+ }
+
private String nullForBlank(String input)
{
return InternalUtils.isBlank(input) ? null : input;
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java?rev=750553&r1=750552&r2=750553&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
Thu Mar 5 19:10:59 2009
@@ -332,6 +332,26 @@
get(tokens, 4);
}
+ /**
+ * @since 5.1.0.1
+ */
+ @Test
+ public void comment_element_ignored()
+ {
+ List<TemplateToken> tokens = tokens("comment_element_ignored.tml");
+
+ assertEquals(tokens.size(), 8);
+
+ get(tokens, 2);
+
+ TextToken t = get(tokens, 3);
+
+ assertEquals(t.getText().trim(), "fred's body");
+
+ EndElementToken end5 = get(tokens, 5);
+ EndElementToken end7 = get(tokens, 7);
+ }
+
@Test
public void root_element_is_component()
{
@@ -654,7 +674,10 @@
{ "invalid_library_namespace_path.tml",
"The path portion of library namespace URI
'tapestry-library:subfolder/' is not valid", 2 },
- { "content_within_body_element.tml", "", 2 }
+ { "content_within_body_element.tml", "", 2 },
+
+ { "comment_may_not_contain_elements.tml",
+ "Unexpected XML parse event START_ELEMENT within a comment
element.", 5 }
};
}
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/comment_element_ignored.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/comment_element_ignored.tml?rev=750553&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/comment_element_ignored.tml
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/comment_element_ignored.tml
Thu Mar 5 19:10:59 2009
@@ -0,0 +1,8 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
xml:space="preserve">
+ <t:Fred t:id="fred">
+ fred's body
+ <t:comment>
+ Comment text, <!-- comments -->, <![CDATA[cdata text]]> and
whitespace are simply excised.
+ </t:comment>
+ </t:Fred>
+</html>
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/comment_may_not_contain_elements.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/comment_may_not_contain_elements.tml?rev=750553&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/comment_may_not_contain_elements.tml
(added)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/comment_may_not_contain_elements.tml
Thu Mar 5 19:10:59 2009
@@ -0,0 +1,7 @@
+<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
+ xmlns:p="tapestry:parameter">
+ <t:comment>
+ Text is ok.
+ <t:pagelink>elements are not</t:pagelink>
+ </t:comment>
+</t:container>
\ No newline at end of file