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 2010/02/20 19:02:19 UTC

svn commit: r912166 - in /incubator/jspwiki/trunk: src/java/org/apache/wiki/ui/stripes/ tests/java/org/apache/wiki/parser/ tests/java/org/apache/wiki/ui/stripes/

Author: ajaquith
Date: Sat Feb 20 18:02:19 2010
New Revision: 912166

URL: http://svn.apache.org/viewvc?rev=912166&view=rev
Log:
Fixed 2 failing Scandic page-name URL generation tests. Page names are now encoded as UTF-8. Also patched Group- PageName- and PrincipalTypeConverter to ensure that incoming parameters are properly decoded, which they were not before. Added a Scandic page-name test to ViewActionBeanTest.

Modified:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/EventResolution.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/GroupTypeConverter.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/PrincipalTypeConverter.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiPageTypeConverter.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/IsOneOfTest.java

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/EventResolution.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/EventResolution.java?rev=912166&r1=912165&r2=912166&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/EventResolution.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/EventResolution.java Sat Feb 20 18:02:19 2010
@@ -15,9 +15,22 @@
 import net.sourceforge.stripes.validation.ValidationErrors;
 
 /**
- * Resolution that returns, in JavaScript object notation format, an arbitrary
- * Object result, along with the ActionBeanContext's messages and validation
- * errors.
+ * <p>
+ * Resolution that returns an {@code eval}-able set of JavaScript statements
+ * that builds a variable containing the result of an AJAX call. The object is
+ * called {@code eventResponse} and contains the call results, the
+ * ActionBeanContext messages and validation errors. It has four properties:
+ * </p>
+ * <ul>
+ * <li>{@code results} - the Object that contains the results of the AJAX call.
+ * This can be just about anything that
+ * {@link net.sourceforge.stripes.ajax.JavaScriptBuilder} can encode.</li>
+ * <li>{@code fieldErrors} - any field-level errors</li>
+ * <li>{@code globalErrors} - any global errors</li>
+ * <li>{@code messages} - any messages</li>
+ * <li>{@code isHtml} - whether the results should be treated as HTML (for
+ * example, to inject directly into a {@code div})</li>
+ * </ul>
  */
 public class EventResolution implements Resolution
 {
@@ -38,7 +51,7 @@
          * 
          * @param context the ActionBeanContext that supplies the messages and
          *            validation errors.
-         * @param rootObject
+         * @param rootObject the Object to be encoded
          * @param isHtml whether the results should be interpreted as HTML
          */
         public Result( ActionBeanContext context, Object rootObject, boolean isHtml )
@@ -133,15 +146,15 @@
 
     /**
      * Converts the ActionBean messges, validation errors and root object passed
-     * in to a series of JavaScript statements that reconstruct the {@link Result}
-     * object in JavaScript, and store the object under the variable name
-     * {@code eventResponse}.
+     * in to a series of JavaScript statements that reconstruct the
+     * {@link Result} object in JavaScript, and store the object under the
+     * variable name {@code eventResponse}.
      */
     public void execute( HttpServletRequest request, HttpServletResponse response ) throws Exception
     {
-        response.setContentType("text/javascript");
+        response.setContentType( "text/javascript" );
         m_builder.setRootVariableName( "eventResponse" );
-        m_builder.build(response.getWriter());
+        m_builder.build( response.getWriter() );
         response.flushBuffer();
     }
 }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/GroupTypeConverter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/GroupTypeConverter.java?rev=912166&r1=912165&r2=912166&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/GroupTypeConverter.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/GroupTypeConverter.java Sat Feb 20 18:02:19 2010
@@ -20,6 +20,8 @@
  */
 package org.apache.wiki.ui.stripes;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
 import java.util.Collection;
 import java.util.Locale;
 
@@ -29,6 +31,7 @@
 import net.sourceforge.stripes.validation.TypeConverter;
 import net.sourceforge.stripes.validation.ValidationError;
 
+import org.apache.wiki.InternalWikiException;
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.auth.NoSuchPrincipalException;
 import org.apache.wiki.auth.WikiSecurityException;
@@ -71,6 +74,21 @@
         Configuration config = StripesFilter.getConfiguration();
         WikiEngine engine = WikiEngine.getInstance( config.getServletContext(), null );
         GroupManager mgr = engine.getGroupManager();
+
+        // Decode the group name
+        try
+        {
+            String decodedName = URLDecoder.decode( groupName, "UTF-8" );
+            if ( decodedName != null )
+            {
+                groupName = decodedName;
+            }
+        }
+        catch( UnsupportedEncodingException e1 )
+        {
+            throw new InternalWikiException( "Impossible! UTF-8 must be supported." );
+        }
+
         Group group = null;
         try
         {

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/PrincipalTypeConverter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/PrincipalTypeConverter.java?rev=912166&r1=912165&r2=912166&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/PrincipalTypeConverter.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/PrincipalTypeConverter.java Sat Feb 20 18:02:19 2010
@@ -20,10 +20,13 @@
  */
 package org.apache.wiki.ui.stripes;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
 import java.security.Principal;
 import java.util.Collection;
 import java.util.Locale;
 
+import org.apache.wiki.InternalWikiException;
 import org.apache.wiki.auth.WikiPrincipal;
 
 import net.sourceforge.stripes.validation.TypeConverter;
@@ -57,6 +60,20 @@
      */
     public Principal convert( String principalName, Class<? extends Principal> targetType, Collection<ValidationError> errors )
     {
+        // Decode the principal name
+        try
+        {
+            String decodedName = URLDecoder.decode( principalName, "UTF-8" );
+            if ( decodedName != null )
+            {
+                principalName = decodedName;
+            }
+        }
+        catch( UnsupportedEncodingException e1 )
+        {
+            throw new InternalWikiException( "Impossible! UTF-8 must be supported." );
+        }
+        
         return new WikiPrincipal( principalName );
     }
 

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiPageTypeConverter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiPageTypeConverter.java?rev=912166&r1=912165&r2=912166&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiPageTypeConverter.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiPageTypeConverter.java Sat Feb 20 18:02:19 2010
@@ -20,7 +20,9 @@
  */
 package org.apache.wiki.ui.stripes;
 
+import java.io.UnsupportedEncodingException;
 import java.net.URI;
+import java.net.URLDecoder;
 import java.util.Collection;
 import java.util.Locale;
 
@@ -31,6 +33,7 @@
 import net.sourceforge.stripes.validation.TypeConverter;
 import net.sourceforge.stripes.validation.ValidationError;
 
+import org.apache.wiki.InternalWikiException;
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.api.WikiPage;
 import org.apache.wiki.content.ContentManager;
@@ -75,6 +78,20 @@
         WikiEngine engine = WikiEngine.getInstance( config.getServletContext(), null );
         WikiPage page = null;
         
+        // Decode the page name
+        try
+        {
+            String decodedName = URLDecoder.decode( pageName, "UTF-8" );
+            if ( decodedName != null )
+            {
+                pageName = decodedName;
+            }
+        }
+        catch( UnsupportedEncodingException e1 )
+        {
+            throw new InternalWikiException( "Impossible! UTF-8 must be supported." );
+        }
+        
         // Is this a special page?
         URI uri = engine.getSpecialPageReference( pageName );
         if( uri != null )

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java?rev=912166&r1=912165&r2=912166&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java Sat Feb 20 18:02:19 2010
@@ -22,6 +22,7 @@
 
 import java.io.BufferedReader;
 import java.io.StringReader;
+import java.net.URLEncoder;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Properties;
@@ -504,10 +505,11 @@
     public void testCCLinkWithScandics() throws Exception
     {
         newPage("\u00c4itiSy\u00f6\u00d6ljy\u00e4");
+        String encodedName = URLEncoder.encode("\u00c4itiSy\u00f6\u00d6ljy\u00e4", "UTF-8");
 
         String src = "Onko t\u00e4m\u00e4 hyperlinkki: \u00c4itiSy\u00f6\u00d6ljy\u00e4?";
 
-        assertEquals( "Onko t\u00e4m\u00e4 hyperlinkki: <a class=\"wikipage\" href=\"/Wiki.jsp?page=%C4itiSy%F6%D6ljy%E4\">\u00c4itiSy\u00f6\u00d6ljy\u00e4</a>?",
+        assertEquals( "Onko t\u00e4m\u00e4 hyperlinkki: <a class=\"wikipage\" href=\"/Wiki.jsp?page=" + encodedName + "\">\u00c4itiSy\u00f6\u00d6ljy\u00e4</a>?",
                       translate(src) );
     }
 
@@ -825,10 +827,11 @@
     public void testScandicPagename1() throws Exception
     {
         String src = "Link [\u00C5\u00E4Test]";
+        String encodedName = URLEncoder.encode( "\u00C5\u00E4Test", "UTF-8" );
 
         newPage("\u00C5\u00E4Test"); // FIXME: Should be capital
 
-        assertEquals("Link <a class=\"wikipage\" href=\"/Wiki.jsp?page=%C5%E4Test\">\u00c5\u00e4Test</a>",
+        assertEquals("Link <a class=\"wikipage\" href=\"/Wiki.jsp?page=" + encodedName +"\">\u00c5\u00e4Test</a>",
                      translate(src));
     }
 
@@ -898,7 +901,7 @@
         String src = "[{$encoding}]\n\n__File type sniffing__ is a way of identifying the content type of a document.\n\n"+
                      "In UNIX, the file(1) command can be used.";
 
-        assertEquals( "<p>ISO-8859-1\n</p><p><b>File type sniffing</b> is a way of identifying the content type of a document.\n</p>\n"+
+        assertEquals( "<p>UTF-8\n</p><p><b>File type sniffing</b> is a way of identifying the content type of a document.\n</p>\n"+
                       "<p>In UNIX, the file(1) command can be used.</p>",
                       translate(src) );
     }

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/IsOneOfTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/IsOneOfTest.java?rev=912166&r1=912165&r2=912166&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/IsOneOfTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/IsOneOfTest.java Sat Feb 20 18:02:19 2010
@@ -39,7 +39,7 @@
         ResolverUtil.Test test = new IsOneOf( WikiActionBean.class, PageFilter.class, WikiPlugin.class );
         resolver.find( test, "org.apache.wiki" );
         Set<Class<? extends Object>> matches = resolver.getClasses();
-        assertEquals( 73, matches.size() );
+        assertEquals( 74, matches.size() );
     }
 
     public void testActionBeanMatches()
@@ -48,7 +48,7 @@
         ResolverUtil.Test test = new IsOneOf( WikiActionBean.class );
         resolver.find( test, "org.apache.wiki.action" );
         Set<Class<? extends Object>> matches = resolver.getClasses();
-        assertEquals( 26, matches.size() );
+        assertEquals( 27, matches.size() );
     }
 
     public void testPageFilterMatches()