myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject [myfaces] branch 2.2.x updated: skip IllegalXmlCharacterFilterWriter in Java1.6
Date Wed, 29 Apr 2020 13:48:56 GMT
This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch 2.2.x
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/2.2.x by this push:
     new f6301f5  skip IllegalXmlCharacterFilterWriter in Java1.6
f6301f5 is described below

commit f6301f59f04f22326bc8289a0550063d17ce77c7
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Wed Apr 29 15:48:05 2020 +0200

    skip IllegalXmlCharacterFilterWriter in Java1.6
---
 .../util/IllegalXmlCharacterFilterWriter.java      | 40 ++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/impl/src/main/java/org/apache/myfaces/util/IllegalXmlCharacterFilterWriter.java
b/impl/src/main/java/org/apache/myfaces/util/IllegalXmlCharacterFilterWriter.java
index 3b6f5e1..46c1d3b 100644
--- a/impl/src/main/java/org/apache/myfaces/util/IllegalXmlCharacterFilterWriter.java
+++ b/impl/src/main/java/org/apache/myfaces/util/IllegalXmlCharacterFilterWriter.java
@@ -21,6 +21,7 @@ package org.apache.myfaces.util;
 import java.io.FilterWriter;
 import java.io.IOException;
 import java.io.Writer;
+import org.apache.myfaces.shared.util.ClassUtils;
 
 /**
  * There are unicodes outside the ranges defined in the
@@ -32,7 +33,28 @@ import java.io.Writer;
 public class IllegalXmlCharacterFilterWriter extends FilterWriter
 {
     private static final char BLANK_CHAR = ' ';
+
+    // Java 1.6 doesnt support Character.isSurrogate
+    private static boolean java16;
     
+    static 
+    {
+        try
+        {
+            java16 = ClassUtils.classForName("java.util.Objects") == null;
+        }
+        catch (Throwable e)
+        {
+            java16 = true;
+        }
+
+        if (java16)
+        {
+            System.err.println("Skip using " + IllegalXmlCharacterFilterWriter.class.getName()
+                    + ", it's only available in Java 1.6+");
+        }
+    }
+
     public IllegalXmlCharacterFilterWriter(Writer out)
     {
         super(out);
@@ -41,6 +63,12 @@ public class IllegalXmlCharacterFilterWriter extends FilterWriter
     @Override
     public void write(int c) throws IOException 
     {
+        if (java16)
+        {
+            super.write(c);
+            return;
+        }
+
         if (isInvalidChar(c))
         {
             super.write((int) BLANK_CHAR);
@@ -54,12 +82,24 @@ public class IllegalXmlCharacterFilterWriter extends FilterWriter
     @Override
     public void write(char[] cbuf, int off, int len) throws IOException 
     {
+        if (java16)
+        {
+            super.write(cbuf, off, len);
+            return;
+        }
+
         super.write(encodeCharArray(cbuf, off, len), off, len);
     }
 
     @Override
     public void write(String str, int off, int len) throws IOException 
     {
+        if (java16)
+        {
+            super.write(str, off, len);
+            return;
+        }
+
         super.write(encodeString(str, off, len), off, len);
     }
 


Mime
View raw message