Author: ajith
Date: Mon Oct 22 13:14:12 2007
New Revision: 587229

URL: http://svn.apache.org/viewvc?rev=587229&view=rev
Log:
1. Added a non UTF xml file and tested the reading and writing of that file. 
This file is of euc-jp (Japanese characters) encoding

Added:
    
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/EncodingTest.java
    
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/other_encoding/
    
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/other_encoding/japaneseElementForm.xsd
Modified:
    
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
    
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
    
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java

Modified: 
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java?rev=587229&r1=587228&r2=587229&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
 (original)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
 Mon Oct 22 13:14:12 2007
@@ -397,4 +397,7 @@
 
         return true;
     }
+       public String getInputEncoding() {
+               return inputEncoding;
+       }
 }

Modified: 
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java?rev=587229&r1=587228&r2=587229&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
 (original)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
 Mon Oct 22 13:14:12 2007
@@ -381,10 +381,11 @@
         return builder.build(doc, null, veh);
     }
 
+   
     public XmlSchema read(Element elem) {
         SchemaBuilder builder = new SchemaBuilder(this, null);
         XmlSchema xmlSchema = builder.handleXmlSchemaElement(elem, null);
-        
xmlSchema.setInputEncoding(DOMUtil.getInputEncoding(elem.getOwnerDocument()));
+        
xmlSchema.setInputEncoding(DOMUtil.getXmlEncoding(elem.getOwnerDocument()));
         return xmlSchema;
     }
 
@@ -395,7 +396,9 @@
     public XmlSchema read(Document doc, String uri, ValidationEventHandler veh,
             TargetNamespaceValidator validator) {
         SchemaBuilder builder = new SchemaBuilder(this, validator);
-        return builder.build(doc, uri, veh);
+        XmlSchema schema = builder.build(doc, uri, veh);
+        schema.setInputEncoding(doc.getInputEncoding());
+               return schema;
     }
 
     public XmlSchema read(Element elem, String uri) {

Modified: 
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java?rev=587229&r1=587228&r2=587229&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java
 (original)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java
 Mon Oct 22 13:14:12 2007
@@ -588,10 +588,20 @@
         return node.getNamespaceURI();
     }
 
+    //why do we need to use reflection here??
     public static String getInputEncoding(Document doc) {
         try {
             Method m = Document.class.getMethod("getInputEncoding", new 
Class[]{});
             return (String) m.invoke(doc, new Object[]{});
+        } catch (Exception e) {
+            return "UTF-8";
+        }
+    }
+    
+    //why do we need to use reflection here??
+    public static String getXmlEncoding(Document doc) {
+        try {
+            return doc.getXmlEncoding();
         } catch (Exception e) {
             return "UTF-8";
         }

Added: 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/EncodingTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/EncodingTest.java?rev=587229&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/EncodingTest.java
 (added)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/test/java/tests/EncodingTest.java
 Mon Oct 22 13:14:12 2007
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.constants.Constants;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+public class EncodingTest extends TestCase {
+
+
+    public void testExternalAtt() throws Exception{
+             //create a DOM document
+           DocumentBuilderFactory documentBuilderFactory = 
DocumentBuilderFactory.newInstance();
+           documentBuilderFactory.setNamespaceAware(true);
+           DocumentBuilder newDocumentBuilder = 
documentBuilderFactory.newDocumentBuilder();
+           
+                  Document doc = newDocumentBuilder.
+                   
parse(Resources.asURI("other_encoding/japaneseElementForm.xsd"));
+           
+           System.out.println(doc.getXmlEncoding());
+
+           XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+           XmlSchema s1 = schemaCol.read(doc.getDocumentElement());
+           assertNotNull(s1);
+           assertEquals("EUC-JP", s1.getInputEncoding().toUpperCase());
+           
+          //write it back to a stream - re read it and check the encoding
+           //we need to explicitly say to have the xml header
+           Map options = new HashMap();
+           options.put(OutputKeys.OMIT_XML_DECLARATION, "no");
+           
+           ByteArrayOutputStream baos = new ByteArrayOutputStream();
+           s1.write(baos,options);
+           
+          
+           
+           Document doc2 = newDocumentBuilder.parse(new 
ByteArrayInputStream(baos.toByteArray()));
+           XmlSchema s2 = schemaCol.read(doc2.getDocumentElement());
+           assertNotNull(s2);
+           assertEquals("EUC-JP", s2.getInputEncoding().toUpperCase());
+            
+           
+           
+
+       }
+
+}

Added: 
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/other_encoding/japaneseElementForm.xsd
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/other_encoding/japaneseElementForm.xsd?rev=587229&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/other_encoding/japaneseElementForm.xsd
 (added)
+++ 
webservices/commons/trunk/modules/XmlSchema/src/test/test-resources/other_encoding/japaneseElementForm.xsd
 Mon Oct 22 13:14:12 2007
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="euc-jp"?>
+<!--
+  ~ 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.
+  -->
+<!--  
+       Note - this document contains japanese characters!
+       The japanese words come from the example at 
http://java.sun.com/developer/earlyAccess/xml/examples/samples/weekly-euc-jp.xml.
+       I have no knowledge of japanese and apologies to the japanese users if 
this contains somewhat ambigous terms
+       The idea of this is to use a non ascii - non UTF characterset for 
testing
+ -->
+<schema
+    xmlns="http://www.w3.org/2001/XMLSchema";
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+    xmlns:tns="http://unqualified-elements.example.com";
+    targetNamespace="http://unqualified-elements.example.com";>
+
+    <element name="¶È̳Êó¹ð¥ê¥¹¥È">
+        <complexType>
+            <sequence>
+                <element name="¶È̳Êó¹ð" type="xsd:string"/>
+                <element name="»á̾"  type="xsd:string"/>
+            </sequence>
+        </complexType>
+    </element>
+
+</schema>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to