You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2008/10/12 06:45:51 UTC
svn commit: r703762 - in
/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH: ./
src/com/ecyrd/jspwiki/action/ tests/com/ecyrd/jspwiki/ui/stripes/
Author: ajaquith
Date: Sat Oct 11 21:45:51 2008
New Revision: 703762
URL: http://svn.apache.org/viewvc?rev=703762&view=rev
Log:
Added Stripes SiteStructure feature to Ant script 'migrate' target. Also, added ability to migrate nested fmt:message tags to StripesJspTransformer.
Modified:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/build.xml
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserProfileActionBean.java
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanFactory.java
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JSPWikiJspTransformer.java
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspMigrator.java
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspTransformer.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
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/build.xml
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/build.xml?rev=703762&r1=703761&r2=703762&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/build.xml (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/build.xml Sat Oct 11 21:45:51 2008
@@ -286,6 +286,19 @@
<target name="migrate" depends="jar,jartests">
<mkdir dir="build/migrated" />
+ <pathconvert property="cp" refid="path.tests"/>
+ <path id="srcfiles">
+ <fileset dir="src" includes="**/*.java" excludes="**/NoneActionBean.java" />
+ </path>
+ <pathconvert property="srcfiles" refid="srcfiles" pathsep=" "/>
+ <!-- Generate the Stripes SiteStructure doc -->
+ <exec executable="apt">
+ <arg line="-classpath ${cp} -nocompile"/>
+ <arg line="-factory net.sourceforge.stripes.tools.SiteStructureTool"/>
+ <arg line="-Astripes.output.file=sitemap.xml"/>
+ <arg line="${srcfiles}"/>
+ </exec>
+ <!-- Migrate the JSPs -->
<java classname="com.ecyrd.jspwiki.ui.stripes.JspMigrator" fork="yes" maxmemory="512m">
<classpath>
<path refid="path.tests" />
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserProfileActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserProfileActionBean.java?rev=703762&r1=703761&r2=703762&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserProfileActionBean.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/UserProfileActionBean.java Sat Oct 11 21:45:51 2008
@@ -125,7 +125,7 @@
return new RedirectResolution( builder.toString() );
}
- // Otherwise, return user to source page
+ // Otherwise, send user to source page
UrlBuilder builder = new UrlBuilder( this.getContext().getLocale(), context.getSourcePage(), false );
builder.addParameter( "tab", "profile" );
return new RedirectResolution( builder.toString() );
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanFactory.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanFactory.java?rev=703762&r1=703761&r2=703762&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanFactory.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/action/WikiActionBeanFactory.java Sat Oct 11 21:45:51 2008
@@ -66,13 +66,13 @@
private static final String PROP_SPECIALPAGE = "jspwiki.specialPage.";
/** Default list of packages to search for WikiActionBean implementations. */
- private static final String DEFAULT_ACTIONBEAN_PACKAGES = "com.ecyrd.jspwiki.action";
+ public static final String DEFAULT_ACTIONBEAN_PACKAGES = "com.ecyrd.jspwiki.action";
/**
* Property in jspwiki.properties that specifies packages to search for
* WikiActionBean implementations.
*/
- private static final String PROPS_ACTIONBEAN_PACKAGES = "jspwiki.actionBean.packages";
+ public static final String PROPS_ACTIONBEAN_PACKAGES = "jspwiki.actionBean.packages";
/** Private map with JSPs as keys, Resolutions as values */
private final Map<String, RedirectResolution> m_specialRedirects;
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JSPWikiJspTransformer.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JSPWikiJspTransformer.java?rev=703762&r1=703761&r2=703762&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JSPWikiJspTransformer.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JSPWikiJspTransformer.java Sat Oct 11 21:45:51 2008
@@ -11,8 +11,9 @@
/**
* {@inheritDoc}
*/
- public void initialize( Map<String, Object> sharedState, JspDocument doc )
+ public void initialize( Map<String, Object> sharedState )
{
+ System.out.println( "Initialized JSPWikiJspTransformer." );
}
/**
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspMigrator.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspMigrator.java?rev=703762&r1=703761&r2=703762&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspMigrator.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspMigrator.java Sat Oct 11 21:45:51 2008
@@ -152,6 +152,12 @@
{
// Clear the shared state
m_sharedState.clear();
+
+ // Initialize the transformers
+ for ( JspTransformer transformer: m_transformers )
+ {
+ transformer.initialize( m_sharedState );
+ }
// Find the files we need to migrate
String sourcePath = sourceDir.getPath();
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspTransformer.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspTransformer.java?rev=703762&r1=703761&r2=703762&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspTransformer.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/stripes/JspTransformer.java Sat Oct 11 21:45:51 2008
@@ -14,9 +14,8 @@
* @param sharedState a map containing key/value pairs that represent any
* shared-state information that this method might need during
* transformation.
- * @param doc the JSP to transform
*/
- public void initialize( Map<String, Object> sharedState, JspDocument doc );
+ public void initialize( Map<String, Object> sharedState );
/**
* Executes the transformation on the JSP and returns the result. This
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=703762&r1=703761&r2=703762&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 Sat Oct 11 21:45:51 2008
@@ -1,18 +1,97 @@
package com.ecyrd.jspwiki.ui.stripes;
-import java.util.List;
-import java.util.Map;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.util.*;
+
+import net.sourceforge.stripes.action.ActionBean;
+import net.sourceforge.stripes.action.UrlBinding;
+import net.sourceforge.stripes.util.ResolverUtil;
+
+import com.ecyrd.jspwiki.action.WikiActionBeanFactory;
/**
* Transforms a JspDocument from standard JSP markup to Stripes markup.
*/
public class StripesJspTransformer extends AbstractJspTransformer
{
+ private Map<Class<? extends ActionBean>, Set<String>> beanProperties = new HashMap<Class<? extends ActionBean>, Set<String>>();
+
+ private Map<String, Class<? extends ActionBean>> beanBindings = new HashMap<String, Class<? extends ActionBean>>();
+
/**
* {@inheritDoc}
*/
- public void initialize( Map<String, Object> sharedState, JspDocument doc )
+ public void initialize( Map<String, Object> sharedState )
+ {
+ // Find all ActionBean implementations on the classpath
+ String beanPackagesProp = System.getProperty( WikiActionBeanFactory.PROPS_ACTIONBEAN_PACKAGES,
+ WikiActionBeanFactory.DEFAULT_ACTIONBEAN_PACKAGES ).trim();
+ String[] beanPackages = beanPackagesProp.split( "," );
+ ResolverUtil<ActionBean> resolver = new ResolverUtil<ActionBean>();
+ resolver.findImplementations( ActionBean.class, beanPackages );
+ Set<Class<? extends ActionBean>> beanClasses = resolver.getClasses();
+
+ // Fetch the URL bindings
+ initUrlBindingCache( beanClasses );
+
+ // Initialize properties that "should" bind to each class
+ initActionBeanPropertyCache( beanClasses );
+
+ System.out.println( "Initialized StripesJspTransformer." );
+ }
+
+ private void initUrlBindingCache( Set<Class<? extends ActionBean>> beanClasses )
{
+ for( Class<? extends ActionBean> beanClass : beanClasses )
+ {
+ UrlBinding binding = beanClass.getAnnotation( UrlBinding.class );
+ if( binding != null && binding.value() != null )
+ {
+ beanBindings.put( binding.value(), beanClass );
+ }
+ }
+ }
+
+ private void initActionBeanPropertyCache( Set<Class<? extends ActionBean>> beanClasses )
+ {
+ for( Class<? extends ActionBean> beanClass : beanClasses )
+ {
+ PropertyDescriptor[] pds;
+ Set<String> properties = new HashSet<String>();
+ try
+ {
+ pds = Introspector.getBeanInfo( beanClass ).getPropertyDescriptors();
+ for( PropertyDescriptor pd : pds )
+ {
+ String propertyName = pd.getName();
+ boolean hasSetter = pd.getWriteMethod() != null;
+ boolean hasField = false;
+ try
+ {
+ Field field = beanClass.getDeclaredField( propertyName );
+ hasField = (field != null);
+ }
+ catch( NoSuchFieldException e )
+ {
+ }
+ if( hasSetter || hasField )
+ {
+ properties.add( propertyName );
+ }
+ }
+ if( properties.size() > 0 )
+ {
+ beanProperties.put( beanClass, properties );
+ }
+ }
+ catch( IntrospectionException e )
+ {
+ e.printStackTrace();
+ }
+ }
}
/**
@@ -48,8 +127,8 @@
{
migrated = migrateTextArea( tag ) || migrated;
}
-
- else if ( "label".equals( tag.getName() ) )
+
+ else if( "label".equals( tag.getName() ) )
{
migrated = migrateLabel( tag ) || migrated;
}
@@ -101,8 +180,8 @@
* element whose <code>key</code> attribute contains a value, that value
* will become the <code>name</code> attribute of the
* <code>stripes:label</code>element. </li>
- * <li>In all other cases, the <code>label</code> element is simply re-named to
- * <code>stripes:label</code>.</li>
+ * <li>In all other cases, the <code>label</code> element is simply
+ * re-named to <code>stripes:label</code>.</li>
* </ul>
* <p>
* For example, the ordinary HTML tag <code><label
@@ -119,42 +198,70 @@
{
// Change the name to <stripes:label>
tag.setName( "stripes:label" );
-
+
+ // If child fmt:message, pull into element
+ migrateMessageTag( tag );
+ message( tag, "Changed <label> to <stripes:label>." );
+
+ return true;
+ }
+
+ private boolean migrateMessageTag( Tag tag )
+ {
// Not a start tag, we're done
- if ( tag.getType() != NodeType.START_TAG)
+ if( tag.getType() != NodeType.START_TAG )
{
return false;
}
-
- // Do we have a single child <fmt:message>?
- Node child = tag.getChildren().size() == 1 ? tag.getChildren().get( 0 ) : null;
- if ( child != null && child.getType() == NodeType.EMPTY_ELEMENT_TAG )
+
+ // Do we have children <fmt:message/> or <fmt:message></fmt:message>?
+ List<Node> children = tag.getChildren();
+ boolean hasOneTag = children.size() == 1 && children.get( 0 ).getType() == NodeType.EMPTY_ELEMENT_TAG
+ && "fmt:message".equals( children.get( 0 ).getName() );
+ boolean hasTwoTags = children.size() == 2 && children.get( 0 ).getType() == NodeType.START_TAG
+ && children.get( 1 ).getType() == NodeType.END_TAG
+ && "fmt.message".equals( children.get( 0 ).getName() )
+ && "fmt.message".equals( children.get( 1 ).getName() );
+
+ if( ( hasOneTag || hasTwoTags ) )
{
- if ( "fmt:message".equals( child.getName() ) )
+ if ( tag.hasAttribute( "name" ) )
{
- // Move the fmt:message tag's key attribute to stripes:label name
- Tag message = (Tag)child;
- if ( message.hasAttribute( "key" ) )
+ message( children.get( 0 ), "NOTE: did not migrate <fmt:message> tag because parent <" + tag.getName() + "> already has 'name' attribute. Refactor?" );
+ }
+ else
+ {
+ // Move the fmt:message tag's key attribute to stripes:label
+ // name
+ Tag message = (Tag) children.get( 0 );
+ if( message.hasAttribute( "key" ) )
{
Attribute key = message.getAttribute( "key" );
key.setName( "name" );
message.removeAttribute( key );
tag.addAttribute( key );
- tag.removeChild( message );
+
+ // Delete all of the children
+ for ( Node child : tag.getChildren() )
+ {
+ tag.removeChild( child );
+ }
}
- // Change to an empty end tag
+ // Change parent to an empty end tag
tag.setType( NodeType.EMPTY_ELEMENT_TAG );
-
+
// Delete the matching end tag
int i = tag.getParent().getChildren().indexOf( tag );
Node endTag = tag.getParent().getChildren().get( i + 1 );
tag.getParent().removeChild( endTag );
+
+ // Tell user what we did
+ message( tag, "Moved <fmt:message> tag into parent <" + tag.getName() + ">." );
+ return true;
}
}
- message( tag, "Changed <label> to <stripes:label>." );
-
- return true;
+ return false;
}
/**
@@ -255,7 +362,10 @@
}
// If the value attribute contains embedded tags, move to child nodes
- return migrateValueAttribute( tag ) || migrated;
+ migrated = migrateValueAttribute( tag ) || migrated;
+
+ // If child fmt:message, pull into element
+ return migrateMessageTag( tag ) || migrated;
}
private boolean migrateTextArea( Tag tag )
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=703762&r1=703761&r2=703762&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 Sat Oct 11 21:45:51 2008
@@ -117,6 +117,49 @@
assertEquals( "<stripes:label for=\"assertedName\" name=\"prefs.assertedname\" />", tag.toString() );
}
+
+ public void testLabelConflictingName() throws Exception
+ {
+ String s = "<label for=\"assertedName\" name=\"foo\"><fmt:message key=\"prefs.assertedname\"/></label>";
+ JspDocument doc = new JspParser().parse( s );
+ m_transformer.transform( m_sharedState, doc );
+
+ // Added 2 nodes...
+ List<Node> nodes = doc.getNodes();
+ assertEquals( 5, nodes.size() );
+
+ // First node is the Stripes taglib
+ Node node = nodes.get( 0 );
+ assertEquals( NodeType.JSP_DIRECTIVE, node.getType() );
+
+ // Second node is the injected linebreak
+ node = nodes.get( 1 );
+ assertEquals( NodeType.TEXT, node.getType() );
+
+ // Third node is the re-structured stripes:label
+ Tag tag = (Tag)nodes.get( 2 );
+ assertEquals( NodeType.START_TAG, tag.getType() );
+ assertEquals( "stripes:label", tag.getName() );
+ assertEquals( 2, tag.getAttributes().size() );
+ assertEquals( "for", tag.getAttribute( "for" ).getName() );
+ assertEquals( "assertedName", tag.getAttribute( "for" ).getValue() );
+ assertEquals( "name", tag.getAttribute( "name" ).getName() );
+ assertEquals( "foo", tag.getAttribute( "name" ).getValue() );
+
+ // Fourth node is the fmt:message tag, which did NOT get moved
+ tag = (Tag)nodes.get( 3 );
+ assertEquals( NodeType.EMPTY_ELEMENT_TAG, tag.getType() );
+ assertEquals( "fmt:message", tag.getName() );
+ assertEquals( 1, tag.getAttributes().size() );
+ assertEquals( "key", tag.getAttribute( "key" ).getName() );
+ assertEquals( "prefs.assertedname", tag.getAttribute( "key" ).getValue() );
+
+ // Fifth node is the end tag
+ tag = (Tag)nodes.get( 4 );
+ assertEquals( NodeType.END_TAG, tag.getType() );
+ assertEquals( "stripes:label", tag.getName() );
+ assertEquals( 0, tag.getAttributes().size() );
+ }
public void testLabelNoFmtMessage() throws Exception
{