You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by gv...@apache.org on 2005/08/30 05:00:23 UTC
svn commit: r264681 - in /struts/shale/trunk/clay-plugin/src:
java/org/apache/shale/clay/Bundle.properties
java/org/apache/shale/clay/parser/Parser.java
test/org/apache/shale/clay/parser/ParserTestCase.java
Author: gvanmatre
Date: Mon Aug 29 20:00:05 2005
New Revision: 264681
URL: http://svn.apache.org/viewcvs?rev=264681&view=rev
Log:
Bug#: 35839 Templates with a DOCTYPE are not useable
Modified:
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties?rev=264681&r1=264680&r2=264681&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties Mon Aug 29 20:00:05 2005
@@ -26,7 +26,7 @@
parser.load.file=Loading file "{0}".
parser.load.error=Exception parsing file "{0}".
parser.load.rules=Loading digester rules.
-parser.unmatched.endtoken=Unmatched ending non-option token: {0}
+parser.unmatched.endtoken=Unmatched ending non-optional token: {0}
parser.unmatched.begintoken=Unmatched begining token: {0}
#org.apache.shale.clay.parser.NodeTokenizer
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java?rev=264681&r1=264680&r2=264681&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java Mon Aug 29 20:00:05 2005
@@ -425,96 +425,130 @@
* </p>
*/
protected Node buildNode(Token token) {
- boolean isBeginTag = false;
- boolean isEndTag = false;
- boolean isComment = false;
- String nodeName = null;
- String qname = null;
+ Node node = new Node(token);
+
+ discoverNodeShape(node);
+ discoverNodeName(node);
+ discoverNodeAttributes(node);
+ discoverNodeOverrides(node);
+
+ return node;
+ }
+
+ /**
+ * <p>Determine if the {@link Node} is a starting, ending, or body text
+ * tag.</p>
+ */
+ protected void discoverNodeShape(Node node) {
+ Token token = node.getToken();
if (token.getDocument().charAt(token.getBeginOffset()) == '<'
- && token.getDocument().charAt(token.getBeginOffset() + 1) == '/'
+ && token.getDocument().charAt(token.getBeginOffset() + 1) == '/'
&& token.getDocument().charAt(token.getEndOffset() - 1) == '>') {
// ending tag found
- isEndTag = true;
- isBeginTag = false;
+ node.setEnd(true);
+ node.setStart(false);
} else if (token.getDocument().charAt(token.getBeginOffset()) == '<'
- && token.getDocument().charAt(token.getEndOffset() - 2) == '/'
+ && token.getDocument().charAt(token.getEndOffset() - 2) == '/'
&& token.getDocument().charAt(token.getEndOffset() - 1) == '>') {
// self ending tag found
- isEndTag = true;
- isBeginTag = true;
+ node.setEnd(true);
+ node.setStart(true);
} else if (token.getDocument().charAt(token.getBeginOffset()) == '<'
&& token.getDocument().charAt(token.getBeginOffset() + 1) == '!'
- && token.getDocument().charAt(token.getEndOffset() - 2) == '-'
- && token.getDocument().charAt(token.getEndOffset() - 1) == '>') {
+ && token.getDocument().charAt(token.getEndOffset() - 2) == '-'
+ && token.getDocument().charAt(token.getEndOffset() - 1) == '>') {
// self contained comment tag found
- isEndTag = true;
- isBeginTag = true;
- isComment = true;
+ node.setEnd(true);
+ node.setStart(true);
+ node.setComment(true);
} else if (token.getDocument().charAt(token.getBeginOffset()) == '<'
&& token.getDocument().charAt(token.getBeginOffset() + 1) == '!'
- && token.getDocument().charAt(token.getBeginOffset() + 2) == '-') {
+ && token.getDocument().charAt(token.getBeginOffset() + 2) == '-') {
// begin comment tag found
- isEndTag = false;
- isBeginTag = true;
- isComment = true;
+ node.setEnd(false);
+ node.setStart(true);
+ node.setComment(true);
} else if (token.getDocument().charAt(token.getEndOffset() - 2) == '-'
&& token.getDocument().charAt(token.getEndOffset() - 1) == '>') {
// ending comment tag found
- isEndTag = true;
- isBeginTag = false;
- isComment = true;
+ node.setEnd(true);
+ node.setStart(false);
+ node.setComment(true);
} else if (token.getDocument().charAt(token.getBeginOffset()) == '<'
- && (token.getDocument().charAt(token.getBeginOffset() + 1) != '/'
- && token.getDocument().charAt(token.getBeginOffset() + 1) != '?'
- && token.getDocument().charAt(token.getBeginOffset() + 1) != '%')
+ && token.getDocument().charAt(token.getBeginOffset() + 1) == '!'
&& token.getDocument().charAt(token.getEndOffset() - 1) == '>') {
+ // DOCTYPE is treated like a self contained comment
+ node.setEnd(true);
+ node.setStart(true);
+ node.setComment(true);
+ } else if (token.getDocument().charAt(token.getBeginOffset()) == '<'
+ && (token.getDocument().charAt(token.getBeginOffset() + 1) != '/'
+ && token.getDocument().charAt(token.getBeginOffset() + 1) != '?'
+ && token.getDocument().charAt(token.getBeginOffset() + 1) != '%')
+ && token.getDocument().charAt(token.getEndOffset() - 1) == '>') {
// beginning tag found
- isEndTag = false;
- isBeginTag = true;
+ node.setEnd(false);
+ node.setStart(true);
}
- // find the node name
- if (isBeginTag || isEndTag) {
+ }
+
+ /**
+ * <p>Extracts the node name from the {@link Token} if the {@link Node}
+ * is a starting or ending tag.</p>
+ */
+ protected void discoverNodeName(Node node) {
+ Token token = node.getToken();
+
+ if (node.isStart() || node.isEnd()) {
// comments are treated special because and ending comment may will not
// have a node name <!-- <input > -->
- if (isComment) {
+ if (node.isComment()) {
+
+ node.setName("--");
- nodeName = "--";
-
} else {
// find the node name delimiter
int e = token.getDocument().indexOf(" ", token.getBeginOffset() + 2);
// end of token is the delimiter
if (e == -1 || e >= token.getEndOffset())
- e = (isBeginTag && isEndTag) ? (token.getEndOffset() - 2)
+ e = (node.isStart() && node.isEnd()) ? (token.getEndOffset() - 2)
: (token.getEndOffset() - 1);
// find the start of the node attribute body
- int s = (!isBeginTag && isEndTag) ? token.getBeginOffset() + 2
+ int s = (!node.isStart() && node.isEnd()) ? token.getBeginOffset() + 2
: token.getBeginOffset() + 1;
// return the full node name
- nodeName = token.getDocument().substring(s, e);
+ String nodeName = token.getDocument().substring(s, e);
// separate the namespace
e = nodeName.indexOf(':');
if (e > -1)
- qname = nodeName.substring(0, e);
- nodeName = nodeName.substring(e + 1);
-
+ node.setQname(nodeName.substring(0, e));
+ node.setName(nodeName.substring(e + 1));
}
}
+ }
+
+ /**
+ * <p>If the {@link Node} is a starting tag and not a comment,
+ * use the {@link AttributeTokenizer} to realize the node attributes.</p>
+ */
+ protected void discoverNodeAttributes(Node node) {
+ Token token = node.getToken();
Attributes attributes = this.new Attributes();
+ node.setAttributes(attributes);
// look for attribute in a beginning tag only
- if (isBeginTag && !isComment) {
+ if (node.isStart() && !node.isComment()) {
int s = token.getDocument()
.indexOf(" ", token.getBeginOffset() + 2);
- int e = (isBeginTag && isEndTag) ? (token.getEndOffset() - 2)
- : (token.getEndOffset() - 1);
+ int e = (node.isStart() && node.isEnd()) ? (token.getEndOffset() - 2)
+ : (token.getEndOffset() - 1);
if (s > -1 && s < e) {
// find the tokens and load them into the attributes map
@@ -529,27 +563,23 @@
}
- // add some exception here. check for html elements that are assumed
- // self terminating
- if (isBeginTag && isSelfTerminating(nodeName)) {
- isEndTag = true;
- }
-
- // build a new node
- Node node = new Node(token);
- node.setEnd(isEndTag);
- node.setStart(isBeginTag);
- node.setComment(isComment);
- node.setAttributes((Map) attributes);
+ }
+
+ /**
+ * <p>Explicitly sets the <code>isEnd</code> {@link Node} property to <code>true</code> for
+ * self terminating tags. Sets the {@Node}'s <code>isWellFormed</code> property
+ * to <code>true</code> if the <code>isStart</code> and <code>isEnd</code>
+ * {@link Node} properties are <code>true</code>.</p>
+ */
+ protected void discoverNodeOverrides(Node node) {
+ //look for self terminating tags
+ if (node.isStart() && isSelfTerminating(node.getName()))
+ node.setEnd(true);
// begin and end tag found on a self terminating node <xxx/>
- if (isBeginTag && isEndTag)
+ if (node.isStart() && node.isEnd())
node.setWellFormed(true);
- node.setQname(qname);
- node.setName(nodeName);
-
- return node;
}
-
+
}
Modified: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java?rev=264681&r1=264680&r2=264681&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java (original)
+++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java Mon Aug 29 20:00:05 2005
@@ -327,9 +327,6 @@
* Aserts that two trees of parsed HTML have the same number children and
* the same attributes. Verifies that the structure is the same
* </p>
- *
- * @param tree1
- * @param tree2
*/
protected void compareTrees(List tree1, List tree2) {
@@ -371,6 +368,30 @@
}
}
+ }
+
+ /**
+ * <p>Test parsing a DOCTYPE Tag.</p>
+ */
+ public void testDoctype() {
+ Parser p = new Parser();
+ StringBuffer doc = new StringBuffer();
+ doc.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" ")
+ .append("\"http://www.w3.org/TR/html4/strict.dtd\">")
+ .append("<HTML>")
+ .append("<HEAD>")
+ .append("<TITLE>My first HTML document</TITLE>")
+ .append("</HEAD>")
+ .append("<BODY>")
+ .append("<P>Hello world!</p>")
+ .append("</BODY>")
+ .append("</HTML>");
+
+
+ List nodes = p.parse(doc);
+ assertTrue("Well-formed DOCTYPE, 2 root nodes",
+ nodes.size() == 2);
+
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org