jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mets...@apache.org
Subject svn commit: r1756711 - in /jspwiki/trunk: ./ jspwiki-war/src/main/java/org/apache/wiki/ jspwiki-war/src/main/java/org/apache/wiki/ui/ jspwiki-war/src/main/java/org/apache/wiki/util/ jspwiki-war/src/main/resources/ini/ jspwiki-war/src/test/java/org/apac...
Date Thu, 18 Aug 2016 05:38:29 GMT
Author: metskem
Date: Thu Aug 18 05:38:28 2016
New Revision: 1756711

URL: http://svn.apache.org/viewvc?rev=1756711&view=rev
Log:
2016-08-18  Harry Metske (metskem@apache.org)

       * 2.10.3-svn-12

       * Fixed JSPWIKI-396 UTF-8 characters in wiki pages incorrectly rendered if served by
Weblogic
         A rigorous fix by Jürgen Weber, ditched UtilJ2eeCompat, introduced new property
"jspwiki.nofilterencoding".

Removed:
    jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/util/UtilJ2eeCompat.java
    jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/util/UtilJ2eeCompatTest.java
Modified:
    jspwiki/trunk/ChangeLog
    jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java
    jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/WikiEngine.java
    jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/ui/WikiJSPFilter.java
    jspwiki/trunk/jspwiki-war/src/main/resources/ini/jspwiki.properties
    jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/util/AllTests.java

Modified: jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/jspwiki/trunk/ChangeLog?rev=1756711&r1=1756710&r2=1756711&view=diff
==============================================================================
--- jspwiki/trunk/ChangeLog (original)
+++ jspwiki/trunk/ChangeLog Thu Aug 18 05:38:28 2016
@@ -1,3 +1,10 @@
+2016-08-18  Harry Metske (metskem@apache.org)
+
+       * 2.10.3-svn-12
+
+       * Fixed JSPWIKI-396 UTF-8 characters in wiki pages incorrectly rendered if served
by Weblogic
+         A rigorous fix by Jürgen Weber, ditched UtilJ2eeCompat, introduced new property
"jspwiki.nofilterencoding".
+
 2016-04-17  Harry Metske (metskem@apache.org)
 
        * 2.10.3-svn-11

Modified: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java?rev=1756711&r1=1756710&r2=1756711&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java (original)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java Thu Aug 18 05:38:28
2016
@@ -72,7 +72,7 @@ public final class Release {
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "11";
+    public static final String     BUILD         = "12";
 
     /**
      *  This is the generic version string you should use when printing out the version.
 It is of 

Modified: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/WikiEngine.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/WikiEngine.java?rev=1756711&r1=1756710&r2=1756711&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/WikiEngine.java (original)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/WikiEngine.java Thu Aug 18 05:38:28
2016
@@ -140,6 +140,10 @@ public class WikiEngine
 
     /** Define the used encoding.  Currently supported are ISO-8859-1 and UTF-8 */
     public static final String PROP_ENCODING     = "jspwiki.encoding";
+    
+    /** Do not use encoding in WikiJSPFilter, default is false for most servers.
+    Double negative, cause for most servers you don't need the property */
+    public static final String PROP_NO_FILTER_ENCODING     = "jspwiki.nofilterencoding";
   
 
     /** The name for the base URL to use in all references. */
     public static final String PROP_BASEURL      = "jspwiki.baseURL";

Modified: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/ui/WikiJSPFilter.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/ui/WikiJSPFilter.java?rev=1756711&r1=1756710&r2=1756711&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/ui/WikiJSPFilter.java (original)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/ui/WikiJSPFilter.java Thu Aug
18 05:38:28 2016
@@ -45,7 +45,7 @@ import org.apache.wiki.event.WikiEventMa
 import org.apache.wiki.event.WikiPageEvent;
 import org.apache.wiki.url.DefaultURLConstructor;
 import org.apache.wiki.util.TextUtil;
-import org.apache.wiki.util.UtilJ2eeCompat;
+
 
 /**
  * This filter goes through the generated page response prior and
@@ -57,7 +57,7 @@ import org.apache.wiki.util.UtilJ2eeComp
  * redirections or sends error codes (such as access control methods).
  * <p>
  * Inclusion markers are placed by the IncludeResourcesTag; the
- * defult content templates (see .../templates/default/commonheader.jsp)
+ * default content templates (see .../templates/default/commonheader.jsp)
  * are configured to do this. As an example, a JavaScript resource marker
  * is added like this:
  * <pre>
@@ -78,16 +78,18 @@ import org.apache.wiki.util.UtilJ2eeComp
  */
 public class WikiJSPFilter extends WikiServletFilter
 {
-    private Boolean m_useOutputStream;
     private String m_wiki_encoding;
+    private boolean useEncoding;
 
     /** {@inheritDoc} */
     public void init( FilterConfig config ) throws ServletException
     {
         super.init( config );
         m_wiki_encoding = m_engine.getWikiProperties().getProperty(WikiEngine.PROP_ENCODING);
+        
+        useEncoding =  !(new Boolean(m_engine.getWikiProperties().getProperty(WikiEngine.PROP_NO_FILTER_ENCODING,
"false").trim()).booleanValue());
+        
         ServletContext context = config.getServletContext();
-        m_useOutputStream = UtilJ2eeCompat.useOutputStream( context.getServerInfo() );
     }
 
     public void doFilter( ServletRequest  request, ServletResponse response, FilterChain
chain )
@@ -101,16 +103,7 @@ public class WikiJSPFilter extends WikiS
             w.enterState("Filtering for URL "+((HttpServletRequest)request).getRequestURI(),
90 );
             HttpServletResponseWrapper responseWrapper;
          
-            if( m_useOutputStream )
-            {
-                log.debug( "Using ByteArrayResponseWrapper" );
-                responseWrapper = new ByteArrayResponseWrapper( (HttpServletResponse)response,
m_wiki_encoding );
-            }
-            else
-            {
-                log.debug( "Using MyServletResponseWrapper" );
-                responseWrapper = new MyServletResponseWrapper( (HttpServletResponse)response,
m_wiki_encoding );
-            }
+            responseWrapper = new MyServletResponseWrapper( (HttpServletResponse)response,
m_wiki_encoding, useEncoding);
         
             // fire PAGE_REQUESTED event
             String pagename = DefaultURLConstructor.parsePageFromURL(
@@ -130,7 +123,7 @@ public class WikiJSPFilter extends WikiS
                 WikiContext wikiContext = getWikiContext( request );
                 String r = filter( wikiContext, responseWrapper );
                 
-                if (m_useOutputStream) 
+                if (useEncoding) 
                 {
                     OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream(),

                                                                     response.getCharacterEncoding());
@@ -265,99 +258,27 @@ public class WikiJSPFilter extends WikiS
         ByteArrayOutputStream m_output;
         private MyServletOutputStream m_servletOut;
         private PrintWriter m_writer;
-
-        public MyServletResponseWrapper( HttpServletResponse r, final String wiki_encoding
)
-                throws UnsupportedEncodingException {
-            super(r);
-            m_output = new ByteArrayOutputStream();
-            m_servletOut = new MyServletOutputStream(m_output);
-            m_writer = new PrintWriter(new OutputStreamWriter(m_servletOut, wiki_encoding),
true);
-        }
-
-        /**
-         *  Returns a writer for output; this wraps the internal buffer
-         *  into a PrintWriter.
-         */
-        public PrintWriter getWriter()
-        {
-            return m_writer;
-        }
-
-        public ServletOutputStream getOutputStream()
-        {
-            return m_servletOut;
-        }
-        
-        public void flushBuffer() throws IOException
-        {
-            m_writer.flush();
-            super.flushBuffer();
-        }
-
-        class MyServletOutputStream extends ServletOutputStream
-        {
-            ByteArrayOutputStream m_buffer;
-
-            public MyServletOutputStream(ByteArrayOutputStream byteArrayOutputStream)
-            {
-                super();
-                m_buffer = byteArrayOutputStream;
-            }
-
-            @Override
-            public void write(int aInt) throws IOException
-            {
-                m_buffer.write( aInt );
-            }
-        }
-        
-        /**
-         *  Returns whatever was written so far into the Writer.
-         */
-        public String toString()
-        {
-            try
-            {
-                flushBuffer();
-            }
-            catch( IOException e )
-            {
-                log.error( MyServletResponseWrapper.class + " toString() flushBuffer() Failed",
e );
-                return StringUtils.EMPTY;
-            }
-            
-            return m_output.toString();
-        }
-    }
-
-    /**
-     *  Response wrapper for application servers which do not work with CharArrayWriter
-     *  Currently only OC4J
-     */
-    private static class ByteArrayResponseWrapper
-        extends HttpServletResponseWrapper
-    {
         private HttpServletResponse m_response;
+        private boolean useEncoding;
         
-        private ByteArrayOutputStream m_output;
-        private MyServletOutputStream m_servletOut;
-        private PrintWriter m_writer;
-      
         /** 
          *  How large the initial buffer should be.  This should be tuned to achieve
          *  a balance in speed and memory consumption.
          */
-        private static final int INIT_BUFFER_SIZE = 4096;
+        private static final int INIT_BUFFER_SIZE = 0x8000;
+   
         
-        public ByteArrayResponseWrapper( HttpServletResponse r, final String wiki_encoding
)
+        public MyServletResponseWrapper( HttpServletResponse r, final String wiki_encoding,
boolean useEncoding)
                 throws UnsupportedEncodingException {
             super(r);
-            m_output = new ByteArrayOutputStream( INIT_BUFFER_SIZE );
+            m_output = new ByteArrayOutputStream(INIT_BUFFER_SIZE);
             m_servletOut = new MyServletOutputStream(m_output);
             m_writer = new PrintWriter(new OutputStreamWriter(m_servletOut, wiki_encoding),
true);
+            this.useEncoding = useEncoding;
+            
             m_response = r;
         }
-        
+
         /**
          *  Returns a writer for output; this wraps the internal buffer
          *  into a PrintWriter.
@@ -380,18 +301,18 @@ public class WikiJSPFilter extends WikiS
 
         class MyServletOutputStream extends ServletOutputStream
         {
-            private OutputStream m_stream;
+            ByteArrayOutputStream m_buffer;
 
-            public MyServletOutputStream( OutputStream aOutput )
+            public MyServletOutputStream(ByteArrayOutputStream byteArrayOutputStream)
             {
                 super();
-                m_stream = aOutput;
+                m_buffer = byteArrayOutputStream;
             }
 
             @Override
             public void write(int aInt) throws IOException
             {
-                m_stream.write( aInt );
+                m_buffer.write( aInt );
             }
         }
         
@@ -401,23 +322,32 @@ public class WikiJSPFilter extends WikiS
         public String toString()
         {
             try
-            {
-                flushBuffer();
-                return m_output.toString( m_response.getCharacterEncoding() );
-            }
-            catch( UnsupportedEncodingException e )
-            {
-                log.error( ByteArrayResponseWrapper.class + " Unsupported Encoding", e );
+			{
+				flushBuffer();
+			} catch (IOException e)
+			{
+                log.error( e );
                 return StringUtils.EMPTY;
-            }
-            catch( IOException e )
+			}
+
+            try
+			{
+				if (useEncoding)
+				{
+					return m_output.toString(m_response.getCharacterEncoding());
+				}
+
+				return m_output.toString();
+			}                
+            catch( UnsupportedEncodingException e )
             {
-                log.error( ByteArrayResponseWrapper.class + " toString() Flush Failed", e
);
+                log.error( e );
                 return StringUtils.EMPTY;
-            }
+             }
         }
     }
 
+
     // events processing .......................................................
 
 

Modified: jspwiki/trunk/jspwiki-war/src/main/resources/ini/jspwiki.properties
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/resources/ini/jspwiki.properties?rev=1756711&r1=1756710&r2=1756711&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/resources/ini/jspwiki.properties (original)
+++ jspwiki/trunk/jspwiki-war/src/main/resources/ini/jspwiki.properties Thu Aug 18 05:38:28
2016
@@ -467,6 +467,12 @@ jspwiki.plugin.externalJars =
 # Markup parser class name; it must be a subclass of org.apache.wiki.parser.MarkupParser
 jspwiki.renderingManager.markupParser=org.apache.wiki.parser.JSPWikiMarkupParser
 
+# Response encoding
+#
+# Whether WikiJSPFilter should use encoding for the response.
+# Most servers don't need this settings, but if your non-Latin chars are not displayed
+# properly, try setting this to true.
+# jspwiki.nofilterencoding = false
 
 #############################################################################
 #

Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/util/AllTests.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/util/AllTests.java?rev=1756711&r1=1756710&r2=1756711&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/util/AllTests.java (original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/util/AllTests.java Thu Aug 18
05:38:28 2016
@@ -46,7 +46,6 @@ public class AllTests extends TestCase {
         suite.addTest( SerializerTest.suite() );
         suite.addTest( TextUtilTest.suite() );
         suite.addTest( TimedCounterListTest.suite() );
-        suite.addTest( UtilJ2eeCompatTest.suite() );
         suite.addTest( XmlUtilTest.suite() );
         
         return suite;



Mime
View raw message