Author: ajaquith
Date: Mon Oct  6 20:09:19 2008
New Revision: 702333

URL: http://svn.apache.org/viewvc?rev=702333&view=rev
Log:
Fixed counter bug that b0rked line counts. Added <stripes:textarea> transform.

Modified:
    
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspParser.java
    
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspParserTest.java
    
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/StripesJspTransformer.java
    
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/StripesJspTransformerTest.java
    
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/Tag.java

Modified: 
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspParser.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspParser.java?rev=702333&r1=702332&r2=702333&view=diff
==============================================================================
--- 
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspParser.java
 (original)
+++ 
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspParser.java
 Mon Oct  6 20:09:19 2008
@@ -569,6 +569,8 @@
     {
         private int m_pos;
 
+        private final List<Integer> lineBreaks = new ArrayList<Integer>();
+
         Counter()
         {
             m_pos = 0;
@@ -644,8 +646,6 @@
 
         private Parser m_parser = null;
 
-        private final List<Integer> lineBreaks = new ArrayList<Integer>();
-
         private Node m_node = null;
 
         private final Counter m_counter;
@@ -780,13 +780,20 @@
         public void incrementPosition()
         {
             // Reset the line/column counters if we encounter linebreaks
-            char currentChar = m_source.charAt( position() );
-            if( currentChar == '\r' || currentChar == '\n' )
+            int pos = position();
+            char currentChar = m_source.charAt( pos );
+            char nextChar = ( pos +1 ) < m_source.length() ? m_source.charAt( 
pos + 1 ) : currentChar;
+            if( currentChar == '\r' && nextChar == '\n' )
             {
-                lineBreaks.add( position() );
+                m_counter.lineBreaks.add( pos );
+                m_counter.increment();
+            }
+            else if ( currentChar == '\r' || currentChar == '\n' )
+            {
+                m_counter.lineBreaks.add( pos );
             }
-
             m_counter.increment();
+
         }
 
         /**
@@ -936,8 +943,8 @@
         {
             // Set the start, end, linebreak
             node.setStart( pos );
-            int lastLineBreakPos = lineBreaks.size() == 0 ? 
Node.POSITION_NOT_SET : lineBreaks.get( lineBreaks.size() - 1 );
-            node.setLine( lineBreaks.size() + 1 );
+            int lastLineBreakPos = m_counter.lineBreaks.size() == 0 ? 
Node.POSITION_NOT_SET : m_counter.lineBreaks.get( m_counter.lineBreaks.size() - 
1 );
+            node.setLine( m_counter.lineBreaks.size() + 1 );
             node.setColumn( pos - lastLineBreakPos );
         }
 

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=702333&r1=702332&r2=702333&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
 Mon Oct  6 20:09:19 2008
@@ -172,7 +172,7 @@
         assertEquals( null, node.getValue() );
         assertEquals( 0, node.getChildren().size() );
         assertEquals( NodeType.HTML_COMBINED_TAG, node.getType() );
-        assertEquals( "<a b=\"cd\"/>", node.toString() );
+        assertEquals( "<a b=\"cd\" />", node.toString() );
 
         // Verify attributes
         assertEquals( 1, node.getAttributes().size() );
@@ -602,7 +602,7 @@
         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( "  <bar attribute2=\"2\" attribute3=\"3\" />  ", 
node.getValue() );
         assertEquals( 2, node.getStart() );
         assertEquals( 22, node.getEnd() );
 
@@ -630,7 +630,7 @@
         // Check AbstractNode 1, child 1 -- should be <bar>
         node = nodes.get( 1 ).getChildren().get( 1 );
         assertEquals( NodeType.HTML_COMBINED_TAG, node.getType() );
-        assertEquals( "<bar attribute2=\"2\" attribute3=\"3\"/>", 
node.toString() );
+        assertEquals( "<bar attribute2=\"2\" attribute3=\"3\" />", 
node.toString() );
         assertEquals( "bar", node.getName() );
         assertEquals( 0, node.getChildren().size() );
         assertEquals( 24, node.getStart() );
@@ -707,7 +707,7 @@
         assertEquals( 2, node.getStart() );
         assertEquals( 52, node.getEnd() );
         assertEquals( NodeType.HTML_COMBINED_TAG, node.getType() );
-        assertEquals( "<wiki:Include page=\"<%=contentPage%>\" var=\'Foo\'/>", 
node.toString() );
+        assertEquals( "<wiki:Include page=\"<%=contentPage%>\" var=\'Foo\' 
/>", node.toString() );
         assertEquals( "wiki:Include", node.getName() );
         assertEquals( null, node.getValue() );
         assertEquals( NodeType.ROOT, node.getParent().getType() );

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=702333&r1=702332&r2=702333&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
 Mon Oct  6 20:09:19 2008
@@ -11,8 +11,8 @@
 
     public void transform( Map<String, Object> sharedState, JspDocument doc )
     {
-        boolean migratedStuff = false;
-        
+        boolean migrated = false;
+
         // Process HTML nodes
         List<Node> nodes = doc.getNodes();
         for( Node node : nodes )
@@ -20,98 +20,62 @@
             // For all HTML tags...
             if( node.isHtmlNode() )
             {
-                Tag tag = (Tag)node;
-                
+                Tag tag = (Tag) node;
+
                 // Change <form> to <stripes:form>
                 if( "form".equals( tag.getName() ) )
                 {
-                    migrateFormTag( tag );
-                    migratedStuff = true;
+                    migrated = migrateFormTag( tag ) || migrated;
                 }
 
                 // Change <input type="*"> tags to <stripes:*>
                 else if( "input".equals( tag.getName() ) )
                 {
-                    migrateInputTag( tag );
-                    migratedStuff = true;
+                    migrated = migrateInputTag( tag ) || migrated;
+                }
+
+                else if( "textarea".equals( tag.getName() ) )
+                {
+                    migrated = migrateTextArea( tag ) || migrated;
                 }
             }
         }
-        
+
         // If we did any work here, add Stripes taglib entry
-        if ( migratedStuff )
+        if( migrated )
         {
-            verifyStripesTaglib( doc );
+            addStripesTaglib( doc );
         }
     }
 
-    private void verifyStripesTaglib( JspDocument doc )
+    /**
+     * Verifies the presence of the Stripes taglib directive, and adds it to 
the
+     * JspDocument if not present. For the taglib to be considered "present,"
+     * the JspDocument must contain a JSP <code>taglib</code> directive with
+     * the <code>prefix</code> set to <code>stripes</code>; any
+     * <code>uri</code> value is acceptable. If the taglib declaration is
+     * added, it is given the prefix <code>stripes</code> and the URI
+     * <code>/WEB-INF/stripes.tld</code>.
+     * 
+     * @param doc the JspDocument to process
+     */
+    private void addStripesTaglib( JspDocument doc )
     {
         // Add the Stripes taglib declaration if it's not there already
         List<Tag> nodes = doc.getTaglibDirective( "*", "stripes" );
-        if ( nodes.size() == 0 )
+        if( nodes.size() == 0 )
         {
             doc.addTaglibDirective( "/WEB-INF/stripes.tld", "stripes" );
             message( doc.getRoot(), "Added Stripes taglib directive." );
         }
-        
-    }
-
-    /**
-     * Migrates the &lt;input&gt; tag.
-     * @param tag the AbstractNode that represents the form tag being 
processed.
-     */
-    private void migrateInputTag( Tag tag )
-    {
-
-        // Move 'type' attribute value to the localname
-        Attribute attribute = tag.getAttribute( "type" );
-        if( attribute != null )
-        {
-            // If a submit input, tell user to change the "name"
-            // value to something useful for Stripes
-            if( "submit".equals( attribute.getValue() ) )
-            {
-                Node nameAttribute = tag.getAttribute( "name" );
-                String nameValue = nameAttribute == null ? "(not set)" : 
nameAttribute.getName();
-                message( nameAttribute, "NOTE: the \"name\" attribute of 
<input type=\"submit\" is \"" + nameValue
-                                        + "\"" );
-            }
-
-            // Move type attribute to qname
-            String type = attribute.getValue();
-            message( attribute, "Changed <input type=\"" + type + "\"> to 
<stripes:" + type + ">." );
-            tag.setName( "stripes:" + type );
-            tag.removeAttribute( attribute );
-        }
-
-        // If embedded markup in "value" attribute, move to child
-        // nodes
-        attribute = tag.getAttribute( "value" );
-        if( attribute != null )
-        {
-            List<Node> children = attribute.getChildren();
-            if( children.size() > 1 || (children.size() == 1 && children.get( 
0 ).getType() != NodeType.TEXT) )
-            {
-                // Remove the attribute
-                tag.removeAttribute( attribute );
-                // Move all of the attribute's nodes to the
-                // children nodes
-                for( Node valueNode : attribute.getChildren() )
-                {
-                    tag.addChild( valueNode );
-                }
-                message( attribute,
-                         "Moved embedded tag(s) in <input> \"value\" attribute 
to the tag body. These are now child element(s) of <input>." );
-            }
-        }
     }
 
     /**
      * Migrates the &lt;form&gt; tag.
-     * @param tag the AbstractNode that represents the form tag being 
processed.
+     * 
+     * @param tag the Tag that represents the form tag being processed.
      */
-    private void migrateFormTag( Tag tag )
+    private boolean migrateFormTag( Tag tag )
     {
         message( tag, "Changed name to <stripes:form>." );
         tag.setName( "stripes:form" );
@@ -139,7 +103,7 @@
                 {
                     // Change "action" attribute"
                     String trimmedPath = actionUrl.substring( 0, qmark );
-                    message( attribute, "Trimmed value to \"" + trimmedPath + 
"\"");
+                    message( attribute, "Trimmed value to \"" + trimmedPath + 
"\"" );
                     attribute.setValue( trimmedPath );
 
                     // Split the parameters and add a new
@@ -151,7 +115,7 @@
                         {
                             JspDocument doc = tag.getJspDocument();
                             String name = param.substring( 0, param.indexOf( 
'=' ) );
-                            String value = param.substring( name.length() +1 );
+                            String value = param.substring( name.length() + 1 
);
                             Tag stripesParam = new Tag( doc, 
NodeType.HTML_COMBINED_TAG );
                             stripesParam.setName( "stripes:param" );
                             Attribute nameAttribute = new Attribute( doc );
@@ -163,13 +127,111 @@
                             valueAttribute.setValue( value );
                             stripesParam.addAttribute( valueAttribute );
                             tag.addChild( stripesParam );
-                            message( tag, "Created <stripes:form> child 
element <stripes:param name=\"" + name + "\""
-                                           + " value=\"" + value + "\"/>." );
+                            message( tag, "Created <stripes:form> child 
element <stripes:param name=\"" + name + "\"" + " value=\""
+                                          + value + "\"/>." );
                         }
                     }
                 }
             }
         }
+        return true;
+    }
+
+    /**
+     * Migrates the &lt;input&gt; tag.
+     * 
+     * @param tag the Tag that represents the form tag being processed.
+     */
+    private boolean migrateInputTag( Tag tag )
+    {
+        boolean migrated = false;
+        
+        // Move 'type' attribute value to the localname
+        Attribute attribute = tag.getAttribute( "type" );
+        if( attribute != null )
+        {
+            // If a submit input, tell user to change the "name"
+            // value to something useful for Stripes
+            if( "submit".equals( attribute.getValue() ) )
+            {
+                Node nameAttribute = tag.getAttribute( "name" );
+                String nameValue = nameAttribute == null ? "(not set)" : 
nameAttribute.getName();
+                message( nameAttribute, "NOTE: the \"name\" attribute of 
<input type=\"submit\" is \"" + nameValue + "\"" );
+            }
+
+            // Move type attribute to qname
+            String type = attribute.getValue();
+            message( attribute, "Changed <input type=\"" + type + "\"> to 
<stripes:" + type + ">." );
+            tag.setName( "stripes:" + type );
+            tag.removeAttribute( attribute );
+            migrated = true;
+        }
+
+        // If the value attribute contains embedded tags, move to child nodes
+        return migrateValueAttribute( tag ) || migrated;
+    }
+
+    private boolean migrateTextArea( Tag tag )
+    {
+        boolean migrated = false;
+        
+        // Only migrate textarea if 'name' attribute is present
+        Attribute name = tag.getAttribute( "name" );
+        if( name != null )
+        {
+            // Change the name to stripes:textarea
+            tag.setName( "stripes:textarea" );
+            message( tag, "Changed <textarea> to <stripes:textarea>. NOTE: 
Stripes will attempt to bind request parameter \""
+                          + name.getValue() + "\" to this element." );
+
+            // If the value attribute contains embedded tags, move to child
+            // nodes
+            migrateValueAttribute( tag );
+            migrated = true;
+        }
+        else
+        {
+            message( tag, "NOTE: <textarea> did not contain a \"name\" 
attribute, so it was not migrated." );
+        }
+        return migrated;
+    }
+
+    /**
+     * Moves the contents of an HTML form tag with a <code>value</code>
+     * attribute to child nodes of the tag, if <code>value</code> contains
+     * anything other than a simple text string. If the <code>value</code>
+     * attribute is not present, or its contents is a simple text string, this
+     * method leaves the attribute as-is.
+     * 
+     * @param tag the tag to migrate
+     * @return <code>true</code> if this method changed the JspDocument, and 
<code>false</code> if not
+     */
+    private boolean migrateValueAttribute( Tag tag )
+    {
+        boolean migrated = false;
+        
+        // If embedded markup in "value" attribute, move to child
+        // nodes
+        Attribute attribute = tag.getAttribute( "value" );
+        if( attribute != null )
+        {
+            List<Node> attributeNodes = attribute.getChildren();
+            if( attributeNodes.size() > 1 || (attributeNodes.size() == 1 && 
attributeNodes.get( 0 ).getType() != NodeType.TEXT) )
+            {
+                // Remove the attribute
+                tag.removeAttribute( attribute );
+                // Move all of the attribute's nodes to the
+                // children nodes
+                for( Node valueNode : attribute.getChildren() )
+                {
+                    tag.addChild( valueNode );
+                }
+                message( attribute, "Moved embedded tag(s) in <" + 
tag.getName()
+                                    + "> \"value\" attribute to the tag body. 
These are now child element(s)." );
+                migrated = true;
+            }
+        }
+        return migrated;
     }
 
 }

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=702333&r1=702332&r2=702333&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
 Mon Oct  6 20:09:19 2008
@@ -9,6 +9,11 @@
 
 public class StripesJspTransformerTest extends TestCase
 {
+    public static Test suite()
+    {
+        return new TestSuite( StripesJspTransformerTest.class );
+    }
+
     protected Map<String, Object> m_sharedState = new HashMap<String, 
Object>();
 
     protected JspTransformer m_transformer = new StripesJspTransformer();
@@ -20,18 +25,36 @@
         super( s );
     }
 
-    public void testFormWithParams() throws Exception
+    public void testAddStripesTaglib() throws Exception
     {
-        String s = "<form action=\"Login.jsp?tab=profile\"/>";
+        String s = "<form/>";
         JspDocument doc = new JspParser().parse( s );
+        assertEquals( 1, doc.getNodes().size() );
         m_transformer.transform( m_sharedState, doc );
+        Node node;
+        Attribute attribute;
 
-        assertEquals( 5, doc.getNodes().size() );
-        Node node = doc.getNodes().get( 2 ); // First 2 are injected Stripes 
taglib+ llinebreak
+        // 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 = ((Tag) node).getAttribute( "prefix" );
+        assertEquals( "stripes", attribute.getValue() );
+        attribute = ((Tag) 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( "stripes:form", node.getName() );
-        assertEquals( 1, ((Tag) node).getAttributes().size() );
-        Node attribute = ((Tag) node).getAttributes().get( 0 );
-        assertEquals( "Login.jsp", attribute.getValue() );
+        assertEquals( 0, ((Tag) node).getAttributes().size() );
     }
 
     public void testFormCombinedTag() throws Exception
@@ -49,6 +72,31 @@
         assertEquals( "acceptcharset", attribute.getName() );
     }
 
+    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( 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( "Login.jsp", attribute.getValue() );
+    }
+
+    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 void testPasswordTag() throws Exception
     {
         String s = "<input type=\"password\" size=\"24\" value=\"\" 
name=\"j_username\" id=\"j_username\" />";
@@ -63,7 +111,7 @@
 
         // After transformation, the "type" attribute is deleted
         assertEquals( 3, doc.getNodes().size() ); // Added Stripes taglib + 
linebreak
-        node = doc.getNodes().get( 2 ); // First 2 are injected Stripes 
taglib+ llinebreak
+        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() );
@@ -79,7 +127,7 @@
 
         // After transformation, the "type" and "value" attributes are deleted;
         // value becomes child node
-        assertEquals( 5, doc.getNodes().size() ); // Added Stripes taglib + 
linebreak
+        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() );
@@ -92,51 +140,72 @@
         assertEquals( "wiki:Variable", node.getName() );
     }
 
-    public void testAddStripesTaglib() throws Exception
+    public void testTextArea() throws Exception
     {
-        String s = "<foo/>";
+        String s = "<textarea id=\"members\" name=\"members\" rows=\"10\" 
cols=\"30\" value=\"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 = ((Tag) node).getAttribute( "prefix" );
-        assertEquals( "stripes", attribute.getValue() );
-        attribute = ((Tag) node).getAttribute( "uri" );
-        assertEquals( "/WEB-INF/stripes.tld", attribute.getValue() );
+        // After transformation, the tag name is renamed
+        assertEquals( 3, doc.getNodes().size() ); // Added Stripes taglib + 
linebreak
+        Node node = doc.getNodes().get( 2 ); // First 2 are injected Stripes 
taglib+ llinebreak
+        assertEquals( NodeType.HTML_COMBINED_TAG, node.getType() );
+        assertEquals( "stripes:textarea", node.getName() );
+        assertEquals( 5, ((Tag) node).getAttributes().size() );
 
-        // Verify linebreak
-        node  = doc.getNodes().get( 1 );
+        // The value attribute should have stayed as an attribute
+        Attribute attribute = ((Tag) node).getAttribute( "value" );
+        assertNotNull( attribute );
+        assertEquals( 1, attribute.getChildren().size() );
+        node = attribute.getChildren().get( 0 );
         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() );
+        assertEquals( "Foo", node.getValue() );
     }
-    
-    public void testNoAddStripesTaglib() throws Exception
+
+    public void testTextAreaComplex() throws Exception
     {
-        String s = "<%@ taglib uri=\"/WEB-INF/stripes.tld\" prefix=\"stripes\" 
%>\n<foo/>";
+        String s = "<textarea id=\"members\" name=\"members\" rows=\"10\" 
cols=\"30\" value=\"<%=foo%>\" />";
         JspDocument doc = new JspParser().parse( s );
-        assertEquals( 3, doc.getNodes().size() );
+        assertEquals( 1, doc.getNodes().size() );
         m_transformer.transform( m_sharedState, doc );
 
-        // Verify Stripes taglib was NOT added
-        assertEquals( 3, doc.getNodes().size() );
+        // After transformation, the tag name is renamed & tag is split
+        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:textarea", node.getName() );
+        assertEquals( 4, ((Tag) node).getAttributes().size() ); // Value 
attribute vanishes...
+
+        // Verify newly created end tag
+        node = doc.getNodes().get( 4 );
+        assertEquals( NodeType.HTML_END_TAG, node.getType() );
+        assertEquals( "stripes:textarea", node.getName() );
+
+        // The value attribute should have moved to child nodes
+        node = doc.getNodes().get( 2 );
+        Attribute attribute = ((Tag) node).getAttribute( "value" );
+        assertNull( attribute );
+        
+        assertEquals( 1, node.getChildren().size() );
+        node = node.getChildren().get( 0 );
+        assertEquals( NodeType.JSP_EXPRESSION, node.getType() );
+        assertEquals( "foo", node.getValue() );
+        assertEquals( "<%=foo%>", node.toString() );
     }
 
-    public static Test suite()
+    public void testTextAreaNoNameAttribute() throws Exception
     {
-        return new TestSuite( StripesJspTransformerTest.class );
+        String s = "<textarea id=\"members\" rows=\"10\" cols=\"30\" 
value=\"Foo\" />";
+        JspDocument doc = new JspParser().parse( s );
+        assertEquals( 1, doc.getNodes().size() );
+        m_transformer.transform( m_sharedState, doc );
+
+        // After transformation, the tag name is stays the same (no name 
attribute...)
+        assertEquals( 1, doc.getNodes().size() ); // NO Stripes taglib or  
linebreak
+        Node node = doc.getNodes().get( 0 );
+        assertEquals( NodeType.HTML_COMBINED_TAG, node.getType() );
+        assertEquals( "textarea", node.getName() );
+        assertEquals( 4, ((Tag) node).getAttributes().size() );
     }
 }

Modified: 
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/Tag.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/Tag.java?rev=702333&r1=702332&r2=702333&view=diff
==============================================================================
--- 
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/Tag.java
 (original)
+++ 
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/Tag.java
 Mon Oct  6 20:09:19 2008
@@ -133,7 +133,7 @@
                 m_parent.addChild( endNode, startTagPos + 1 );
             }
         }
-        
+
         // Finally add the child to the parent
         super.addChild( node, index );
     }
@@ -154,18 +154,20 @@
     public String toString()
     {
         // Root node is easy!
-        if ( m_type == NodeType.ROOT )
+        if( m_type == NodeType.ROOT )
         {
             return "ROOT";
         }
-        
+
         StringBuilder sb = new StringBuilder();
-        
+
         // Calculate start and end nodes
-        String tagStart= m_type.getTagStart();
+        String tagStart = m_type.getTagStart();
         String tagEnd = m_type.getTagEnd();
-        if ( tagStart == null ) tagStart = "?";
-        if ( tagEnd == null ) tagEnd = "?";
+        if( tagStart == null )
+            tagStart = "?";
+        if( tagEnd == null )
+            tagEnd = "?";
 
         // Print tag start
         sb.append( tagStart );
@@ -176,18 +178,29 @@
             sb.append( m_name );
             if( m_attributes.size() > 0 )
             {
-                sb.append( ' ' );
+                int dynamicAttributeLevels = 0;
                 NodeType lastType = null;
                 for( Attribute attr : m_attributes )
                 {
-                    if ( attr.getType() == lastType )
+                    if( dynamicAttributeLevels == 0 )
                     {
                         sb.append( ' ' );
                     }
                     sb.append( attr.toString() );
                     lastType = attr.getType();
+                    if( lastType == NodeType.DYNAMIC_ATTRIBUTE  && 
attr.getValue().length() > 3 )
+                    {
+                        if( attr.getValue().charAt( 1 ) != '/' )
+                        {
+                            dynamicAttributeLevels++;
+                        }
+                        else if ( attr.getValue().charAt( 
attr.getValue().length() - 2 ) != '/' )
+                        {
+                            dynamicAttributeLevels--;
+                        }
+                    }
                 }
-                if ( lastType == NodeType.DYNAMIC_ATTRIBUTE  || m_type == 
NodeType.JSP_DIRECTIVE  )
+                if( lastType == NodeType.DYNAMIC_ATTRIBUTE || m_type == 
NodeType.JSP_DIRECTIVE || m_type == NodeType.HTML_COMBINED_TAG )
                 {
                     sb.append( ' ' );
                 }


Reply via email to