jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r699812 [2/2] - in /incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH: ./ tests/com/ecyrd/jspwiki/ui/stripes/
Date Sun, 28 Sep 2008 12:59:41 GMT
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspParserTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspParserTest.java?rev=699812&r1=699811&r2=699812&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspParserTest.java
(original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspParserTest.java
Sun Sep 28 05:59:41 2008
@@ -7,13 +7,77 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
-
 public class JspParserTest extends TestCase
 {
     public JspParserTest( String s )
     {
         super( s );
     }
+    
+    public void testCombinedTag() throws Exception
+    {
+        String s = "<foo />";
+        
+        // Parse the contents
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+        
+        // Results in one node
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 1, nodes.size() );
+        Tag node;
+        
+        // Verify HTML combined tag
+        node = (Tag) nodes.get( 0 );
+        assertEquals( "foo", node.getName() );
+        assertEquals( null, node.getValue() );
+        assertEquals( 0, node.getChildren().size() );
+        assertEquals( NodeType.HTML_COMBINED_TAG, node.getType() );
+        assertEquals( "<foo/>", node.toString() );
+    }
+
+    public void testParseHtmlComment() throws Exception
+    {
+        String s = "<!-- This is a comment -->";
+
+        // Parse the contents
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+
+        // Results in one node
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 1, nodes.size() );
+        Markup node;
+
+        // Verify comment
+        node = (Markup) nodes.get( 0 );
+        assertEquals( "(MARKUP)", node.getName() );
+        assertEquals( " This is a comment ", node.getValue() );
+        assertEquals( 0, node.getChildren().size() );
+    }
+    
+    public void testParseDirective() throws Exception
+    {
+        String s = "<%@ page import=\"org.apache.log4j.*\" %>";
+
+        // Parse the contents of the file
+        JspParser parser = new JspParser();
+        JspDocument doc = parser.parse( s );
+
+        // Results in one node
+        List<Node> nodes = doc.getNodes();
+        assertEquals( 1, nodes.size() );
+        JspDirective node;
+        Node attribute;
+
+        // Verify directive
+        node = (JspDirective) nodes.get( 0 );
+        assertEquals( "page", node.getName() );
+        assertEquals( 1, node.getAttributes().size() );
+        attribute = node.getAttributes().get( 0 );
+        assertEquals( "import", attribute.getName() );
+        assertEquals( "org.apache.log4j.*", attribute.getValue() );
+    }
 
     public void testParse() throws Exception
     {
@@ -25,7 +89,8 @@
         JspParser parser = new JspParser();
         JspDocument doc = parser.parse( s );
 
-        // Should result in 18 nodes parsed (10 tags/directives + 8 text/whitespace nodes
+        // Should result in 18 nodes parsed (10 tags/directives + 8
+        // text/whitespace nodes
         Node node;
         Node attribute;
         List<Node> nodes = doc.getNodes();
@@ -44,8 +109,8 @@
         assertEquals( 1, node.getLevel() );
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "page", node.getName() );
-        assertEquals( 1, ((JspDirective)node).getAttributes().size() );
-        attribute = ((JspDirective)node).getAttributes().get( 0 );
+        assertEquals( 1, ((JspDirective) node).getAttributes().size() );
+        attribute = ((JspDirective) node).getAttributes().get( 0 );
         assertEquals( "import", attribute.getName() );
         assertEquals( "org.apache.log4j.*", attribute.getValue() );
         i++;
@@ -61,7 +126,7 @@
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "(TEXT)", node.getName() );
         i++;
-        
+
         // Test line 2 aka nodes 2+3
         node = nodes.get( i );
         assertEquals( 2, node.getLine() );
@@ -74,8 +139,8 @@
         assertEquals( 1, node.getLevel() );
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "page", node.getName() );
-        assertEquals( 1, ((JspDirective)node).getAttributes().size() );
-        attribute = ((JspDirective)node).getAttributes().get( 0 );
+        assertEquals( 1, ((JspDirective) node).getAttributes().size() );
+        attribute = ((JspDirective) node).getAttributes().get( 0 );
         assertEquals( "import", attribute.getName() );
         assertEquals( "com.ecyrd.jspwiki.*", attribute.getValue() );
         i++;
@@ -104,8 +169,8 @@
         assertEquals( 1, node.getLevel() );
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "page", node.getName() );
-        assertEquals( 1, ((JspDirective)node).getAttributes().size() );
-        attribute = ((JspDirective)node).getAttributes().get( 0 );
+        assertEquals( 1, ((JspDirective) node).getAttributes().size() );
+        attribute = ((JspDirective) node).getAttributes().get( 0 );
         assertEquals( "import", attribute.getName() );
         assertEquals( "com.ecyrd.jspwiki.action.*", attribute.getValue() );
         i++;
@@ -121,7 +186,7 @@
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "(TEXT)", node.getName() );
         i++;
-        
+
         // Test line 4 aka nodes 6+7
         node = nodes.get( i );
         assertEquals( 4, node.getLine() );
@@ -134,8 +199,8 @@
         assertEquals( 1, node.getLevel() );
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "page", node.getName() );
-        assertEquals( 1, ((JspDirective)node).getAttributes().size() );
-        attribute = ((JspDirective)node).getAttributes().get( 0 );
+        assertEquals( 1, ((JspDirective) node).getAttributes().size() );
+        attribute = ((JspDirective) node).getAttributes().get( 0 );
         assertEquals( "errorPage", attribute.getName() );
         assertEquals( "/Error.jsp", attribute.getValue() );
         i++;
@@ -151,7 +216,7 @@
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "(TEXT)", node.getName() );
         i++;
-        
+
         // Test line 5 aka nodes 8+9
         node = nodes.get( i );
         assertEquals( 5, node.getLine() );
@@ -164,11 +229,11 @@
         assertEquals( 1, node.getLevel() );
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "taglib", node.getName() );
-        assertEquals( 2, ((JspDirective)node).getAttributes().size() );
-        attribute = ((JspDirective)node).getAttributes().get( 0 );
+        assertEquals( 2, ((JspDirective) node).getAttributes().size() );
+        attribute = ((JspDirective) node).getAttributes().get( 0 );
         assertEquals( "uri", attribute.getName() );
         assertEquals( "/WEB-INF/jspwiki.tld", attribute.getValue() );
-        attribute = ((JspDirective)node).getAttributes().get( 1 );
+        attribute = ((JspDirective) node).getAttributes().get( 1 );
         assertEquals( "prefix", attribute.getName() );
         assertEquals( "wiki", attribute.getValue() );
         i++;
@@ -197,11 +262,11 @@
         assertEquals( 1, node.getLevel() );
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "taglib", node.getName() );
-        assertEquals( 2, ((JspDirective)node).getAttributes().size() );
-        attribute = ((JspDirective)node).getAttributes().get( 0 );
+        assertEquals( 2, ((JspDirective) node).getAttributes().size() );
+        attribute = ((JspDirective) node).getAttributes().get( 0 );
         assertEquals( "uri", attribute.getName() );
         assertEquals( "/WEB-INF/stripes.tld", attribute.getValue() );
-        attribute = ((JspDirective)node).getAttributes().get( 1 );
+        attribute = ((JspDirective) node).getAttributes().get( 1 );
         assertEquals( "prefix", attribute.getName() );
         assertEquals( "stripes", attribute.getValue() );
         i++;
@@ -217,7 +282,7 @@
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "(TEXT)", node.getName() );
         i++;
-        
+
         // Test line 7 aka nodes 12+13
         node = nodes.get( i );
         assertEquals( 7, node.getLine() );
@@ -230,16 +295,17 @@
         assertEquals( 1, node.getLevel() );
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "stripes:useActionBean", node.getName() );
-        
-        // AbstractNode 12 should have 1 attribute: beanclass="com.ecyrd.jspwiki.action.LoginActionBean"
-        assertEquals( 1, ((Tag)node).getAttributes().size() );
-        attribute = ((Tag)node).getAttributes().get( 0 );
+
+        // AbstractNode 12 should have 1 attribute:
+        // beanclass="com.ecyrd.jspwiki.action.LoginActionBean"
+        assertEquals( 1, ((Tag) node).getAttributes().size() );
+        attribute = ((Tag) node).getAttributes().get( 0 );
         assertEquals( "beanclass", attribute.getName() );
-        assertEquals ( NodeType.ATTRIBUTE, attribute.getType());
+        assertEquals( NodeType.ATTRIBUTE, attribute.getType() );
         assertEquals( "com.ecyrd.jspwiki.action.LoginActionBean", attribute.getValue() );
-        assertEquals( 'c', ((Tag)node).getAttributes().get( 0 ).getValue().charAt( 0 ) );
+        assertEquals( 'c', ((Tag) node).getAttributes().get( 0 ).getValue().charAt( 0 ) );
         i++;
-        
+
         // Test line 7, node 13 (line break)
         node = nodes.get( i );
         assertEquals( 7, node.getLine() );
@@ -264,7 +330,7 @@
         assertEquals( NodeType.ROOT, node.getParent().getType() );
         assertEquals( 1, node.getLevel() );
         assertEquals( 17, node.getSiblings().size() );
-        assertEquals( null, node.getName() );
+        assertEquals( "(MARKUP)", node.getName() );
         i++;
         node = nodes.get( i );
         assertEquals( 19, node.getLine() );
@@ -278,7 +344,7 @@
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "(TEXT)", node.getName() );
         i++;
-        
+
         // Test line 20-33 aka node 16
         node = nodes.get( i );
         assertEquals( 20, node.getLine() );
@@ -290,9 +356,9 @@
         assertEquals( NodeType.ROOT, node.getParent().getType() );
         assertEquals( 1, node.getLevel() );
         assertEquals( 17, node.getSiblings().size() );
-        assertEquals( null, node.getName() );
+        assertEquals( "(MARKUP)", node.getName() );
         i++;
-        
+
         // Test second tag on line 33 aka node 17
         node = nodes.get( i );
         assertEquals( 33, node.getLine() );
@@ -305,33 +371,35 @@
         assertEquals( 1, node.getLevel() );
         assertEquals( 17, node.getSiblings().size() );
         assertEquals( "wiki:Include", node.getName() );
-        
-        // AbstractNode 17 should have 1 attribute: page="<%=contentPage%>" 
-        assertEquals( 1, ((Tag)node).getAttributes().size() );
-        attribute = ((Tag)node).getAttributes().get( 0 );
+
+        // AbstractNode 17 should have 1 attribute: page="<%=contentPage%>"
+        assertEquals( 1, ((Tag) node).getAttributes().size() );
+        attribute = ((Tag) node).getAttributes().get( 0 );
         assertEquals( "page", attribute.getName() );
-        assertEquals ( NodeType.ATTRIBUTE, attribute.getType());
+        assertEquals( NodeType.ATTRIBUTE, attribute.getType() );
         assertEquals( "<%=contentPage%>", attribute.getValue() );
         assertEquals( 1, attribute.getChildren().size() );
-        assertEquals ( NodeType.JSP_EXPRESSION, attribute.getChildren().get( 0 ).getType()
);
-        assertEquals ( "contentPage", attribute.getChildren().get( 0 ).getValue() );
+        assertEquals( NodeType.JSP_EXPRESSION, attribute.getChildren().get( 0 ).getType()
);
+        assertEquals( "contentPage", attribute.getChildren().get( 0 ).getValue() );
         i++;
     }
-    
-    public void testParseNestedTags() {
-        String s= "  <foo attribute1=\"1\">  <bar attribute2=\"2\" attribute3=\"3\"/>
 </foo>  ";
+
+    public void testParseNestedTags()
+    {
+        String s = "  <foo attribute1=\"1\">  <bar attribute2=\"2\" attribute3=\"3\"/>
 </foo>  ";
         JspDocument doc = new JspParser().parse( s );
-        
+
         // Total number of nodes (depth-first search) is 7
         List<Node> nodes = doc.getNodes();
         Node node;
         Node attribute;
-        assertEquals( 7, nodes.size());
-        
-        // First, check the root node. Should have 4 children (2 text nodes + 2 html nodes)
+        assertEquals( 7, nodes.size() );
+
+        // First, check the root node. Should have 4 children (2 text nodes + 2
+        // html nodes)
         node = doc.getRoot();
         assertEquals( 4, node.getChildren().size() );
-        
+
         // AbstractNode 0 is whitespace
         node = nodes.get( 0 );
         assertEquals( NodeType.TEXT, node.getType() );
@@ -340,36 +408,37 @@
         assertEquals( doc.getRoot(), node.getParent() );
         assertEquals( 0, node.getStart() );
         assertEquals( 2, node.getEnd() );
-        
+
         // AbstractNode 1 is <foo> with 1 attribute
         node = nodes.get( 1 );
         assertEquals( NodeType.HTML_START_TAG, node.getType() );
-        assertEquals( "<foo attribute1=\"1\">",  node.toString() );
-        assertEquals( "foo",  node.getName() );
-        assertEquals( "  <bar attribute2=\"2\" attribute3=\"3\"/>  ",  node.getValue()
);
+        assertEquals( "<foo attribute1=\"1\">", node.toString() );
+        assertEquals( "foo", node.getName() );
+        assertEquals( "  <bar attribute2=\"2\" attribute3=\"3\"/>  ", node.getValue()
);
         assertEquals( 2, node.getStart() );
         assertEquals( 22, node.getEnd() );
-        
+
         // AbstractNode 1: attributes test
-        assertEquals( 1, ((Tag)node).getAttributes().size() );
-        attribute = ((Tag)node).getAttributes().get( 0 );
+        assertEquals( 1, ((Tag) node).getAttributes().size() );
+        attribute = ((Tag) node).getAttributes().get( 0 );
         assertEquals( "attribute1", attribute.getName() );
         assertEquals( "1", attribute.getValue() );
         assertEquals( 7, attribute.getStart() );
         assertEquals( 21, attribute.getEnd() );
-        
-        // AbstractNode 1 also has 3 child elements: <bar> plus two whitespace nodes
+
+        // AbstractNode 1 also has 3 child elements: <bar> plus two whitespace
+        // nodes
         assertEquals( 3, node.getChildren().size() );
-        
+
         // Check AbstractNode 1, child 0 -- should be whitespace
         node = nodes.get( 1 ).getChildren().get( 0 );
         assertEquals( NodeType.TEXT, node.getType() );
-        assertEquals( "(TEXT)",  node.getName() );
+        assertEquals( "(TEXT)", node.getName() );
         assertEquals( "  ", node.getValue() );
         assertEquals( nodes.get( 1 ), node.getParent() );
         assertEquals( 22, node.getStart() );
         assertEquals( 24, node.getEnd() );
-        
+
         // Check AbstractNode 1, child 1 -- should be <bar>
         node = nodes.get( 1 ).getChildren().get( 1 );
         assertEquals( NodeType.HTML_COMBINED_TAG, node.getType() );
@@ -378,16 +447,16 @@
         assertEquals( 0, node.getChildren().size() );
         assertEquals( 24, node.getStart() );
         assertEquals( 60, node.getEnd() );
-        assertEquals( 2, ((Tag)node).getAttributes().size() );
-        assertEquals( "attribute2", ((Tag)node).getAttributes().get( 0 ).getName() );
-        assertEquals( "2", ((Tag)node).getAttributes().get( 0 ).getValue() );
-        assertEquals( "attribute3", ((Tag)node).getAttributes().get( 1 ).getName() );
-        assertEquals( "3", ((Tag)node).getAttributes().get( 1 ).getValue() );
-        
+        assertEquals( 2, ((Tag) node).getAttributes().size() );
+        assertEquals( "attribute2", ((Tag) node).getAttributes().get( 0 ).getName() );
+        assertEquals( "2", ((Tag) node).getAttributes().get( 0 ).getValue() );
+        assertEquals( "attribute3", ((Tag) node).getAttributes().get( 1 ).getName() );
+        assertEquals( "3", ((Tag) node).getAttributes().get( 1 ).getValue() );
+
         // Check AbstractNode 1, child 2 -- should be whitespace
         node = nodes.get( 1 ).getChildren().get( 2 );
         assertEquals( NodeType.TEXT, node.getType() );
-        assertEquals( "(TEXT)",  node.getName() );
+        assertEquals( "(TEXT)", node.getName() );
         assertEquals( "  ", node.getValue() );
         assertEquals( nodes.get( 1 ), node.getParent() );
         assertEquals( 60, node.getStart() );
@@ -396,39 +465,40 @@
         // AbstractNode 5 (</foo) has no attributes
         node = nodes.get( 5 );
         assertEquals( NodeType.HTML_END_TAG, node.getType() );
-        assertEquals( null,  node.getValue() );
-        assertEquals( "foo",  node.getName() );
-        assertEquals( 0, ((Tag)node).getAttributes().size() );
+        assertEquals( null, node.getValue() );
+        assertEquals( "foo", node.getName() );
+        assertEquals( 0, ((Tag) node).getAttributes().size() );
         assertEquals( 0, node.getChildren().size() );
         assertEquals( 62, node.getStart() );
         assertEquals( 68, node.getEnd() );
-        
+
         // AbstractNode 6 is whitespace
         node = nodes.get( 6 );
         assertEquals( NodeType.TEXT, node.getType() );
-        assertEquals( "(TEXT)",  node.getName() );
+        assertEquals( "(TEXT)", node.getName() );
         assertEquals( "  ", node.getValue() );
         assertEquals( doc.getRoot(), node.getParent() );
         assertEquals( 68, node.getStart() );
         assertEquals( 70, node.getEnd() );
 
-        // The children of AbstractNode 1 == Nodes 2, 3 and 4 from doc.getNodes()
+        // The children of AbstractNode 1 == Nodes 2, 3 and 4 from
+        // doc.getNodes()
         node = nodes.get( 1 );
         assertEquals( nodes.get( 2 ), node.getChildren().get( 0 ) );
         assertEquals( nodes.get( 3 ), node.getChildren().get( 1 ) );
         assertEquals( nodes.get( 4 ), node.getChildren().get( 2 ) );
-        
+
     }
-    
+
     public void testParseNestedExpression()
     {
         String s = "  <wiki:Include page=\"<%=contentPage%>\" var=\'Foo\' />
 ";
         JspDocument doc = new JspParser().parse( s );
-        
+
         List<Node> nodes = doc.getNodes();
         Node node;
-        assertEquals( 3, nodes.size());
-        
+        assertEquals( 3, nodes.size() );
+
         // AbstractNode 1: text node
         node = nodes.get( 0 );
         assertEquals( 1, node.getLine() );
@@ -442,7 +512,7 @@
         assertEquals( 1, node.getLevel() );
         assertEquals( 2, node.getSiblings().size() );
         assertEquals( 0, node.getChildren().size() );
-        
+
         // AbstractNode 2: HTML tag with attribute containing JSP expression
         node = nodes.get( 1 );
         assertEquals( 1, node.getLine() );
@@ -457,26 +527,26 @@
         assertEquals( 1, node.getLevel() );
         assertEquals( 2, node.getSiblings().size() );
         assertEquals( 0, node.getChildren().size() );
-        
+
         // AbstractNode 2: test attributes
-        assertEquals( 2, ((Tag)node).getAttributes().size() );
+        assertEquals( 2, ((Tag) node).getAttributes().size() );
         Node attribute;
-        attribute = ((Tag)node).getAttributes().get( 0 );
+        attribute = ((Tag) node).getAttributes().get( 0 );
         assertEquals( NodeType.ATTRIBUTE, attribute.getType() );
         assertEquals( "page", attribute.getName() );
         assertEquals( "<%=contentPage%>", attribute.getValue() );
         assertEquals( 1, attribute.getChildren().size() );
         assertEquals( NodeType.JSP_EXPRESSION, attribute.getChildren().get( 0 ).getType()
);
         assertEquals( "contentPage", attribute.getChildren().get( 0 ).getValue() );
-        
-        attribute = ((Tag)node).getAttributes().get( 1 );
+
+        attribute = ((Tag) node).getAttributes().get( 1 );
         assertEquals( NodeType.ATTRIBUTE, attribute.getType() );
         assertEquals( "var", attribute.getName() );
         assertEquals( "Foo", attribute.getValue() );
         assertEquals( 1, attribute.getChildren().size() );
         assertEquals( NodeType.TEXT, attribute.getChildren().get( 0 ).getType() );
         assertEquals( "Foo", attribute.getChildren().get( 0 ).getValue() );
-        
+
         // AbstractNode 3: text
         node = nodes.get( 2 );
         assertEquals( 1, node.getLine() );

Copied: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/Markup.java
(from r696723, incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspMarkup.java)
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/Markup.java?p2=incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/Markup.java&p1=incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspMarkup.java&r1=696723&r2=699812&rev=699812&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspMarkup.java
(original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/Markup.java
Sun Sep 28 05:59:41 2008
@@ -4,34 +4,44 @@
 package com.ecyrd.jspwiki.ui.stripes;
 
 /**
- * Node implementation representing a JSP comment, declaration, scriptlet or expression.
+ * Node implementation representing an HTML comment, JSP comment, declaration,
+ * scriptlet or expression.
  */
-public class JspMarkup extends AbstractNode
+public class Markup extends AbstractNode
 {
     /**
-     * 
      * @param doc the parent JspDocument
      * @param type
      */
-    public JspMarkup ( JspDocument doc, NodeType type )
+    public Markup( JspDocument doc, NodeType type )
     {
         super( doc, type );
     }
+
+    /**
+     * Always returns \"(MARKUP)\".
+     */
+    @Override
+    public String getName()
+    {
+        return "(MARKUP)";
+    }
     
     private String m_value;
-    
-    public String  getValue()
+
+    public String getValue()
     {
         return m_value;
     }
-    
+
     public void setValue( String value )
     {
         m_value = value;
     }
-    
+
     /**
-     * Returns the string that represents the JSP comment, declaration, scriptlet or expression.
+     * Returns the string that represents the JSP comment, declaration,
+     * scriptlet or expression.
      */
     public String toString()
     {

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/NodeType.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/NodeType.java?rev=699812&r1=699811&r2=699812&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/NodeType.java
(original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/NodeType.java
Sun Sep 28 05:59:41 2008
@@ -11,6 +11,8 @@
     ATTRIBUTE(null,null),
     /** Text node */
     TEXT("", ""),
+    /** HTML comment tag */
+    HTML_COMMENT("<!--", "-->"),
     /** HTML start tag */
     HTML_START_TAG("<", ">"),
     /** HTML end tag */
@@ -37,11 +39,7 @@
      * JSP page, import or taglib directive, e.g., &lt;%@ include... %&gt;
      * &lt;%@ page... %&gt; &lt;%@ taglib... %&gt;
      */
-    JSP_DIRECTIVE("<%@", "%>"),
-    /** JSP tag, but not sure what kind.. */
-    UNRESOLVED_JSP_TAG(null, null),
-    /** Parser has seen &lt;, but hasn't figured out what it is yet. */
-    UNRESOLVED(null, null);
+    JSP_DIRECTIVE("<%@", "%>");
     private final String m_tagStart;
 
     private final String m_tagEnd;

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/StripesJspTransformer.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/StripesJspTransformer.java?rev=699812&r1=699811&r2=699812&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/StripesJspTransformer.java
(original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/StripesJspTransformer.java
Sun Sep 28 05:59:41 2008
@@ -46,11 +46,11 @@
         Node lastTaglib = null;
         for ( Node node : nodes )
         {
-            Tag tag = (Tag)node;
+            JspDirective directive = (JspDirective)node;
             if ( "taglib".equals( node.getName() ) )
             {
                 lastTaglib = node;
-                Attribute attribute = tag.getAttribute( "prefix" );
+                Attribute attribute = directive.getAttribute( "prefix" );
                 if ( attribute != null && "stripes".equals( attribute.getValue()
) )
                 {
                     declaresStripesTaglib = true;
@@ -60,23 +60,27 @@
         }
         if ( !declaresStripesTaglib )
         {
-            Tag tag = new Tag( doc, NodeType.JSP_DIRECTIVE );
-            tag.setName( "taglib" );
+            Text linebreak = new Text( doc );
+            linebreak.setValue( System.getProperty( "line.separator" ) );
+            JspDirective directive = new JspDirective( doc );
+            directive.setName( "taglib" );
             Attribute attribute = new Attribute( doc );
             attribute.setName( "uri" );
             attribute.setValue( "/WEB-INF/stripes.tld" );
-            tag.addAttribute( attribute );
+            directive.addAttribute( attribute );
             attribute = new Attribute( doc );
             attribute.setName( "prefix" );
             attribute.setValue( "stripes" );
-            tag.addAttribute( attribute );
+            directive.addAttribute( attribute );
             if ( lastTaglib == null )
             {
-                doc.getRoot().addChild( tag, 0 );
+                doc.getRoot().addChild( directive, 0 );
+                directive.addSibling( linebreak );
             }
             else
             {
-                lastTaglib.addSibling( tag );
+                linebreak.addSibling( directive );
+                lastTaglib.addSibling( linebreak );
             }
             message( doc.getRoot(), "Added Stripes taglib directive." );
         }

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/StripesJspTransformerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/StripesJspTransformerTest.java?rev=699812&r1=699811&r2=699812&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/StripesJspTransformerTest.java
(original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/StripesJspTransformerTest.java
Sun Sep 28 05:59:41 2008
@@ -7,29 +7,30 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
-
 public class StripesJspTransformerTest extends TestCase
 {
-    protected Map<String,Object> m_sharedState = new HashMap<String,Object>();
+    protected Map<String, Object> m_sharedState = new HashMap<String, Object>();
+
     protected JspTransformer m_transformer = new StripesJspTransformer();
+
     protected JspDocument m_doc = new JspDocument();
-    
+
     public StripesJspTransformerTest( String s )
     {
         super( s );
     }
-    
+
     public void testFormWithParams() throws Exception
     {
         String s = "<form action=\"Login.jsp?tab=profile\"/>";
         JspDocument doc = new JspParser().parse( s );
         m_transformer.transform( m_sharedState, doc );
-        
-        assertEquals( 4, doc.getNodes().size() );
-        Node node = doc.getNodes().get( 1 );            // First line is the injected Stripes
taglib declaration
+
+        assertEquals( 5, doc.getNodes().size() );
+        Node node = doc.getNodes().get( 2 ); // First 2 are injected Stripes taglib+ llinebreak
         assertEquals( "stripes:form", node.getName() );
-        assertEquals( 1, ((Tag)node).getAttributes().size() );
-        Node attribute = ((Tag)node).getAttributes().get( 0 );
+        assertEquals( 1, ((Tag) node).getAttributes().size() );
+        Node attribute = ((Tag) node).getAttributes().get( 0 );
         assertEquals( "Login.jsp", attribute.getValue() );
     }
 
@@ -39,12 +40,12 @@
         JspDocument doc = new JspParser().parse( s );
         m_transformer.transform( m_sharedState, doc );
 
-        assertEquals( 2, doc.getNodes().size() );       // Added Stripes taglib
-        Node node = doc.getNodes().get( 1 );            // Node 0 is injected Stripes taglib
+        assertEquals( 3, doc.getNodes().size() ); // Added Stripes taglib + linebreak
+        Node node = doc.getNodes().get( 2 ); // First 2 are injected Stripes taglib+ llinebreak
         assertEquals( "stripes:form", node.getName() );
-        
-        assertEquals( 2, ((Tag)node).getAttributes().size() );
-        Node attribute = ((Tag)node).getAttributes().get( 0 );
+
+        assertEquals( 2, ((Tag) node).getAttributes().size() );
+        Node attribute = ((Tag) node).getAttributes().get( 0 );
         assertEquals( "acceptcharset", attribute.getName() );
     }
 
@@ -53,22 +54,22 @@
         String s = "<input type=\"password\" size=\"24\" value=\"\" name=\"j_username\"
id=\"j_username\" />";
         JspDocument doc = new JspParser().parse( s );
         Node node;
-        
+
         // Before transformation, 1 node, with 5 attributes
         node = doc.getNodes().get( 0 );
         assertEquals( 1, doc.getNodes().size() );
-        assertEquals( 5, ((Tag)node).getAttributes().size() );
+        assertEquals( 5, ((Tag) node).getAttributes().size() );
         m_transformer.transform( m_sharedState, doc );
 
         // After transformation, the "type" attribute is deleted
-        assertEquals( 2, doc.getNodes().size() );           // Added Stripes taglib
-        node = doc.getNodes().get( 1 );
+        assertEquals( 3, doc.getNodes().size() ); // Added Stripes taglib + linebreak
+        node = doc.getNodes().get( 2 ); // First 2 are injected Stripes taglib+ llinebreak
         assertEquals( NodeType.HTML_COMBINED_TAG, node.getType() );
         assertEquals( "stripes:password", node.getName() );
-        assertEquals( 4, ((Tag)node).getAttributes().size() );
+        assertEquals( 4, ((Tag) node).getAttributes().size() );
         assertEquals( 0, node.getChildren().size() );
     }
-    
+
     public void testPasswordTagComplex() throws Exception
     {
         String s = "<input type=\"password\" size=\"24\" value=\"<wiki:Variable var='uid'
default='' />\" name=\"j_username\" id=\"j_username\" />";
@@ -76,20 +77,64 @@
         assertEquals( 1, doc.getNodes().size() );
         m_transformer.transform( m_sharedState, doc );
 
-        // After transformation, the "type" and "value" attributes are deleted; value becomes
child node
-        assertEquals( 4, doc.getNodes().size() );           // Added Stripes taglib
-        Node node = doc.getNodes().get( 1 );
+        // After transformation, the "type" and "value" attributes are deleted;
+        // value becomes child node
+        assertEquals( 5, doc.getNodes().size() ); // Added Stripes taglib + linebreak
+        Node node = doc.getNodes().get( 2 ); // First 2 are injected Stripes taglib+ llinebreak
         assertEquals( NodeType.HTML_START_TAG, node.getType() );
         assertEquals( "stripes:password", node.getName() );
-        assertEquals( 3, ((Tag)node).getAttributes().size() );
-        
+        assertEquals( 3, ((Tag) node).getAttributes().size() );
+
         // The value attribute should show up as a child node
         assertEquals( 1, node.getChildren().size() );
         node = node.getChildren().get( 0 );
         assertEquals( NodeType.HTML_COMBINED_TAG, node.getType() );
         assertEquals( "wiki:Variable", node.getName() );
     }
+
+    public void testAddStripesTaglib() throws Exception
+    {
+        String s = "<foo/>";
+        JspDocument doc = new JspParser().parse( s );
+        assertEquals( 1, doc.getNodes().size() );
+        m_transformer.transform( m_sharedState, doc );
+        Node node;
+        Attribute attribute;
+
+        // Verify Stripes taglib + linebreak were added
+        assertEquals( 3, doc.getNodes().size() );
+        
+        // Verify Stripes taglib
+        node = doc.getNodes().get( 0 );
+        assertEquals( NodeType.JSP_DIRECTIVE, node.getType() );
+        assertEquals( "taglib", node.getName() );
+        attribute = ((JspDirective) node).getAttribute( "prefix" );
+        assertEquals( "stripes", attribute.getValue() );
+        attribute = ((JspDirective) node).getAttribute( "uri" );
+        assertEquals( "/WEB-INF/stripes.tld", attribute.getValue() );
+
+        // Verify linebreak
+        node  = doc.getNodes().get( 1 );
+        assertEquals( NodeType.TEXT, node.getType() );
+        
+        // Verify old tag is still there too
+        node = doc.getNodes().get( 2 );
+        assertEquals( NodeType.HTML_COMBINED_TAG, node.getType() );
+        assertEquals( "foo", node.getName() );
+        assertEquals( 0, ((Tag)node).getAttributes().size() );
+    }
     
+    public void testNoAddStripesTaglib() throws Exception
+    {
+        String s = "<%@ taglib uri=\"/WEB-INF/stripes.tld\" prefix=\"stripes\" %>\n<foo/>";
+        JspDocument doc = new JspParser().parse( s );
+        assertEquals( 3, doc.getNodes().size() );
+        m_transformer.transform( m_sharedState, doc );
+
+        // Verify Stripes taglib was NOT added
+        assertEquals( 3, doc.getNodes().size() );
+    }
+
     public static Test suite()
     {
         return new TestSuite( StripesJspTransformerTest.class );



Mime
View raw message