diff --git a/serializer/src/main/java/org/apache/xml/serializer/ToHTMLStream.java b/serializer/src/main/java/org/apache/xml/serializer/ToHTMLStream.java index 38e4632fd..d80839f14 100644 --- a/serializer/src/main/java/org/apache/xml/serializer/ToHTMLStream.java +++ b/serializer/src/main/java/org/apache/xml/serializer/ToHTMLStream.java @@ -1281,6 +1281,13 @@ else if (escapingNotNeeded(ch)) { writer.write(ch); } + else if (Encodings.isHighUTF16Surrogate(ch)) + { + writeUTF16Surrogate(ch, chars, i, end); + i++; // two input characters processed + // this increments by one and the for() + // loop itself increments by another one. + } else { writer.write("&#"); @@ -1427,17 +1434,15 @@ else if ( { i = pos - 1; } - else + else if (Encodings.isHighUTF16Surrogate(ch)) { - if (Encodings.isHighUTF16Surrogate(ch)) - { - - writeUTF16Surrogate(ch, chars, i, end); - i++; // two input characters processed - // this increments by one and the for() - // loop itself increments by another one. - } - + + writeUTF16Surrogate(ch, chars, i, end); + i++; // two input characters processed + // this increments by one and the for() + // loop itself increments by another one. + } else { + // The next is kind of a hack to keep from escaping in the case // of Shift_JIS and the like. @@ -2333,4 +2338,6 @@ public int getLongestKeyLength() return m_charBuffer.length; } } + + } diff --git a/serializer/src/main/java/org/apache/xml/serializer/ToStream.java b/serializer/src/main/java/org/apache/xml/serializer/ToStream.java index 6340f2416..6d94582c9 100644 --- a/serializer/src/main/java/org/apache/xml/serializer/ToStream.java +++ b/serializer/src/main/java/org/apache/xml/serializer/ToStream.java @@ -1594,13 +1594,24 @@ else if (m_encodingInfo.isInEncoding(ch)) { // If the character is in the encoding, and // not in the normal ASCII range, we also // just leave it get added on to the clean characters - } - else { - // This is a fallback plan, we should never get here - // but if the character wasn't previously handled - // (i.e. isn't in the encoding, etc.) then what - // should we do? We choose to write out an entity + else if (Encodings.isHighUTF16Surrogate(ch) && i < end-1 && Encodings.isLowUTF16Surrogate(chars[i+1])) { + // So, this is a (valid) surrogate pair + if (! m_encodingInfo.isInEncoding(ch, chars[i+1])) { + int codepoint = Encodings.toCodePoint(ch, chars[i+1]); + writeOutCleanChars(chars, i, lastDirtyCharProcessed); + writer.write("&#"); + writer.write(Integer.toString(codepoint)); + writer.write(';'); + lastDirtyCharProcessed = i+1; + } + i++; // skip the low surrogate, too + } + else { + // This is a fallback plan, we get here if the + // encoding doesn't contain ch and it's not part + // of a surrogate pair + // The right thing is to write out an entity writeOutCleanChars(chars, i, lastDirtyCharProcessed); writer.write("&#"); writer.write(Integer.toString(ch)); @@ -2166,6 +2177,11 @@ else if (m_encodingInfo.isInEncoding(ch)) { // just write it out writer.write(ch); } + else if (Encodings.isHighUTF16Surrogate(ch)) + { + writeUTF16Surrogate(ch, stringChars, i, len); + i++ ; // process two input characters + } else { // This is a fallback plan, we should never get here // but if the character wasn't previously handled diff --git a/xalansamples/src/main/java/samples/extensions/sql/extConnection/#ExternalConnection.java# b/xalansamples/src/main/java/samples/extensions/sql/extConnection/#ExternalConnection.java# deleted file mode 100644 index d8fbb587f..000000000 --- a/xalansamples/src/main/java/samples/extensions/sql/extConnection/#ExternalConnection.java# +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* - * $Id$ - */ -package extensions.sql.extConnection; - -// Imported TraX classes -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.Transformer; -import javax.xml.transform.stream.StreamSource; -import javax.xml.transform.stream.StreamResult; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerConfigurationException; - -import org.apache.xalan.lib.sql.DefaultConnectionPool; -import org.apache.xalan.lib.sql.ConnectionPoolManager; - - -// Imported java classes -import java.io.StringReader; -import java.io.FileOutputStream; -import java.io.FileNotFoundException; -import java.io.IOException; - -/** - * Use the TraX interface to perform a transformation in the simplest manner possible - * (3 statements). - */ -public class ExternalConnection -{ - public static void main(String[] args) - throws TransformerException, TransformerConfigurationException, - FileNotFoundException, IOException - { - - // Create a connection to the database server - // Up the connection pool count for testing - DefaultConnectionPool cp = new DefaultConnectionPool(); - cp.setDriver("org.apache.derby.jdbc.EmbeddedDriver"); - cp.setURL("jdbc:derby:sampleDB"); - //cp.setUser("sa"); - //cp.setPassword(""); - cp.setMinConnections(10); - cp.setPoolEnabled(true); - - // Now let's register our connection pool so we can use - // in a stylesheet - ConnectionPoolManager pm = new ConnectionPoolManager(); - pm.registerPool("extpool", cp); - - - // Use the static TransformerFactory.newInstance() method to instantiate - // a TransformerFactory. The javax.xml.transform.TransformerFactory - // system property setting determines the actual class to instantiate -- - // org.apache.xalan.transformer.TransformerImpl. - TransformerFactory tFactory = TransformerFactory.newInstance(); - - // Grab the Name of the Stylesheet from the command line - if (args.length == 0) - { - System.out.println("You must provide the path and name to a stylesheet to process"); - System.exit(0); - } - - String stylesheet = args[0]; - System.out.println("Transforming Stylesheet " + stylesheet); - - // Use the TransformerFactory to instantiate a Transformer that will work with - // the stylesheet you specify. This method call also processes the stylesheet - // into a compiled Templates object. - Transformer transformer = tFactory.newTransformer( - new StreamSource(stylesheet)); - - // For this transformation, all the required information is in the - // stylesheet, so generate a minimal XML source document for the - // input. Note: the command-line processor - // (org.apache.xalan.xslt.Process) uses this strategy when the user - // does not provide an -IN parameter. - StringReader reader = - new StringReader(" "); - - // Use the Transformer to apply the associated Templates object to - // an XML document and write the output to a file. - transformer.transform( - new StreamSource(reader), - new StreamResult(new FileOutputStream("dbtest-out.html"))); - - System.out.println("************* The result is in dbtest-out.html *************"); - - cp.setPoolEnabled(false); - } -}