jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r702278 - in /incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes: JspDocument.java StripesJspTransformer.java StripesJspTransformerTest.java Tag.java
Date Mon, 06 Oct 2008 21:42:13 GMT
Author: ajaquith
Date: Mon Oct  6 14:42:13 2008
New Revision: 702278

URL: http://svn.apache.org/viewvc?rev=702278&view=rev
Log:
JspDocument enhancements.

Modified:
    incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspDocument.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/JspDocument.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspDocument.java?rev=702278&r1=702277&r2=702278&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspDocument.java
(original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspDocument.java
Mon Oct  6 14:42:13 2008
@@ -52,9 +52,80 @@
         }
         return typeNodes;
     }
+    
+    public void addTaglibDirective( String uri, String prefix )
+    {
+        // Create new directive
+        Tag directive = new Tag( this, NodeType.JSP_DIRECTIVE );
+        directive.setName( "taglib" );
+        Attribute attribute = new Attribute( this );
+        attribute.setName( "uri" );
+        attribute.setValue( "/WEB-INF/stripes.tld" );
+        directive.addAttribute( attribute );
+        attribute = new Attribute( this );
+        attribute.setName( "prefix" );
+        attribute.setValue( "stripes" );
+        directive.addAttribute( attribute );
+        
+        // Create linebreak
+        Text linebreak = new Text( this );
+        linebreak.setValue( System.getProperty( "line.separator" ) );
+        linebreak.setParent( root );
+        
+        // Figure out where to put it
+        List<Node> directives = getNodes( NodeType.JSP_DIRECTIVE );
+        if ( directives.size() == 0 )
+        {
+            root.addChild( linebreak, 0 );
+            root.addChild( directive, 0 );
+        }
+        else
+        {
+            Node lastDirective = directives.get( directives.size() - 1 );
+            lastDirective.addSibling( directive );
+            lastDirective.addSibling( linebreak );
+        }
+        
+    }
+
+    /**
+     * Returns a list of Tags that match a taglib URI and/or prefix. The tablib
+     * directive searched for based on a supplied URI and prefix, which may be
+     * "*" to denote any URI or prefix.
+     * 
+     * @param uri the URI to search for
+     * @param prefix the prefix to search for
+     * @return a list of all matching tags, which may be a zero-length list
+     */
+    public List<Tag> getTaglibDirective( String uri, String prefix )
+    {
+        if( uri == null || prefix == null )
+        {
+            throw new IllegalArgumentException( "URI or prefix cannot be null." );
+        }
+        List<Node> directives = getNodes( NodeType.JSP_DIRECTIVE );
+        List<Tag> matchingDirectives = new ArrayList<Tag>();
+        for( Node node : directives )
+        {
+            Tag directive = (Tag)node;
+            if ( "taglib".equals( directive.getName() ) )
+            {
+                String nodeUri = directive.getAttribute( "uri" ).getValue();
+                String nodePrefix = directive.getAttribute( "prefix" ).getValue();
+                boolean uriMatch = "*".equals( uri ) || nodeUri.equals( uri );
+                boolean prefixMatch = "*".equals( prefix ) || nodePrefix.equals( prefix );
+                if( uriMatch && prefixMatch )
+                {
+                    matchingDirectives.add( directive );
+                }
+            }
+        }
+        return matchingDirectives;
+    }
 
     /**
      * Returns all of the child nodes for a supplied Tag, recursively.
+     * 
      * @param start
      * @return the list of tags
      */
@@ -64,7 +135,7 @@
         visitChildren( allChildren, start.getChildren() );
         return allChildren;
     }
-    
+
     public AbstractNode getRoot()
     {
         return root;
@@ -81,15 +152,16 @@
             }
         }
     }
-    
+
     /**
-     * Returns the JspDocument as a String, reconstructed from the Nodes it contains.
+     * Returns the JspDocument as a String, reconstructed from the Nodes it
+     * contains.
      */
     public String toString()
     {
         StringBuilder builder = new StringBuilder();
         List<Node> allNodes = getNodes();
-        for ( Node node : allNodes )
+        for( Node node : allNodes )
         {
             builder.append( node.toString() );
         }

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=702278&r1=702277&r2=702278&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 14:42:13 2008
@@ -11,8 +11,7 @@
 
     public void transform( Map<String, Object> sharedState, JspDocument doc )
     {
-        // Add Stripes taglib entry
-        verifyStripesTaglib( doc );
+        boolean migratedStuff = false;
         
         // Process HTML nodes
         List<Node> nodes = doc.getNodes();
@@ -27,62 +26,32 @@
                 if( "form".equals( tag.getName() ) )
                 {
                     migrateFormTag( tag );
+                    migratedStuff = true;
                 }
 
                 // Change <input type="*"> tags to <stripes:*>
                 else if( "input".equals( tag.getName() ) )
                 {
                     migrateInputTag( tag );
+                    migratedStuff = true;
                 }
             }
         }
+        
+        // If we did any work here, add Stripes taglib entry
+        if ( migratedStuff )
+        {
+            verifyStripesTaglib( doc );
+        }
     }
 
     private void verifyStripesTaglib( JspDocument doc )
     {
         // Add the Stripes taglib declaration if it's not there already
-        List<Node> nodes = doc.getNodes( NodeType.JSP_DIRECTIVE );
-        boolean declaresStripesTaglib = false;
-        Node lastTaglib = null;
-        for ( Node node : nodes )
+        List<Tag> nodes = doc.getTaglibDirective( "*", "stripes" );
+        if ( nodes.size() == 0 )
         {
-            Tag directive = (Tag)node;
-            if ( "taglib".equals( node.getName() ) )
-            {
-                lastTaglib = node;
-                Attribute attribute = directive.getAttribute( "prefix" );
-                if ( attribute != null && "stripes".equals( attribute.getValue()
) )
-                {
-                    declaresStripesTaglib = true;
-                    break;
-                }
-            }
-        }
-        if ( !declaresStripesTaglib )
-        {
-            Text linebreak = new Text( doc );
-            linebreak.setValue( System.getProperty( "line.separator" ) );
-            linebreak.setParent( doc.getRoot() );
-            Tag directive = new Tag( doc, NodeType.JSP_DIRECTIVE );
-            directive.setName( "taglib" );
-            Attribute attribute = new Attribute( doc );
-            attribute.setName( "uri" );
-            attribute.setValue( "/WEB-INF/stripes.tld" );
-            directive.addAttribute( attribute );
-            attribute = new Attribute( doc );
-            attribute.setName( "prefix" );
-            attribute.setValue( "stripes" );
-            directive.addAttribute( attribute );
-            if ( lastTaglib == null )
-            {
-                doc.getRoot().addChild( directive, 0 );
-                directive.addSibling( linebreak );
-            }
-            else
-            {
-                linebreak.addSibling( directive );
-                lastTaglib.addSibling( linebreak );
-            }
+            doc.addTaglibDirective( "/WEB-INF/stripes.tld", "stripes" );
             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=702278&r1=702277&r2=702278&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 14:42:13 2008
@@ -1,6 +1,5 @@
 package com.ecyrd.jspwiki.ui.stripes;
 
-import java.io.File;
 import java.util.HashMap;
 import java.util.Map;
 

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=702278&r1=702277&r2=702278&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 14:42:13 2008
@@ -187,7 +187,7 @@
                     sb.append( attr.toString() );
                     lastType = attr.getType();
                 }
-                if ( lastType == NodeType.DYNAMIC_ATTRIBUTE )
+                if ( lastType == NodeType.DYNAMIC_ATTRIBUTE  || m_type == NodeType.JSP_DIRECTIVE
 )
                 {
                     sb.append( ' ' );
                 }



Mime
View raw message