I think I've a solution for the second problem.

In SourceTransformer.toDOMSourceFromStream():

    public DOMSource toDOMSourceFromStream(StreamSource source) throws
ParserConfigurationException, IOException,
            SAXException {
        DocumentBuilder builder = createDocumentBuilder();
        String systemId = source.getSystemId();
        Document document = null;
        InputStream inputStream = source.getInputStream();
        if (inputStream != null) {
            document = builder.parse(inputStream, systemId);
        }
        else {
            Reader reader = source.getReader();
            if (reader != null) {
                document = builder.parse(new InputSource(reader));
            }
            else {
                throw new IOException("No input stream or reader
available");
            }
        }
        return new DOMSource(document, systemId);
    }

Change to:

    public DOMSource toDOMSourceFromStream(StreamSource source) throws
ParserConfigurationException, IOException,
            SAXException {
        DocumentBuilder builder = createDocumentBuilder();
        String systemId = source.getSystemId();
        Document document = null;
        InputStream inputStream = source.getInputStream();
        if (inputStream != null) {
            InputSource inputsource = new InputSource(inputStream);
            inputsource.setSystemId(systemId);
            inputsource.setEncoding(Charset.defaultCharset().name());
            
            document = builder.parse(inputsource);
        }
        else {
            Reader reader = source.getReader();
            if (reader != null) {
                document = builder.parse(new InputSource(reader));
            }
            else {
                throw new IOException("No input stream or reader
available");
            }
        }
        return new DOMSource(document, systemId);
    }

The block starting with "if (inputStream != null) {" was changed. It no
longers calls the DocumentBuilder.parse() method with the inputstream but
with an input source that has its encoding explicitly set to the default
character set encoding. 

The code above only works with J2SE 5, because it's using the
Charset.defaultCharset() method, which was introduced with J2SE 5. To make
it usable with older J2SE versions, you should add a static member to the
class SourceTransformer, which holds the name of the default character set
encoding and is initialized at class loading. (from
http://www.rgagnon.com/javadetails/java-0505.html):

public class Hello {
 public static void main(String args[]) throws Exception{
  // not crossplateform safe
  System.out.println(System.getProperty("file.encoding"));
  // jdk1.4
  System.out.println(
     new java.io.OutputStreamWriter(
        new java.io.ByteArrayOutputStream()).getEncoding()
     );
  // jdk1.5
  System.out.println(java.nio.charset.Charset.defaultCharset().name());
  }
}

This kind of calling a DocumentBuilder should be used overall in ServiceMix. 

BTW: What about the JIRA? Should I raise one?

Kind regards
Juergen
--
View this message in context: 
http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4121021
Sent from the ServiceMix - User forum at Nabble.com.

Reply via email to