1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package tests;
21
22 import junit.framework.TestCase;
23 import org.apache.ws.commons.schema.XmlSchema;
24 import org.apache.ws.commons.schema.XmlSchemaCollection;
25 import org.w3c.dom.Document;
26
27 import javax.xml.parsers.DocumentBuilder;
28 import javax.xml.parsers.DocumentBuilderFactory;
29 import javax.xml.transform.OutputKeys;
30
31 import java.io.ByteArrayInputStream;
32 import java.io.ByteArrayOutputStream;
33 import java.util.HashMap;
34 import java.util.Map;
35
36 public class EncodingTest extends TestCase {
37
38
39 public void testExternalAtt() throws Exception{
40
41 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
42 documentBuilderFactory.setNamespaceAware(true);
43 DocumentBuilder newDocumentBuilder = documentBuilderFactory.newDocumentBuilder();
44
45
46 try {
47 Document.class.getMethod("getInputEncoding", new Class[]{});
48 } catch (NoSuchMethodException e) {
49 System.out.println(">>>> Ignoring test as it needs DOM3");
50 return;
51 }
52
53 Document doc = newDocumentBuilder.
54 parse(Resources.asURI("other_encoding/japaneseElementForm.xsd"));
55
56 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
57 XmlSchema s1 = schemaCol.read(doc.getDocumentElement());
58 assertNotNull(s1);
59 assertEquals("EUC-JP", s1.getInputEncoding().toUpperCase());
60
61
62
63 Map options = new HashMap();
64 options.put(OutputKeys.OMIT_XML_DECLARATION, "no");
65
66 ByteArrayOutputStream baos = new ByteArrayOutputStream();
67 s1.write(baos,options);
68
69 schemaCol = new XmlSchemaCollection();
70 Document doc2 = newDocumentBuilder.parse(new ByteArrayInputStream(baos.toByteArray()));
71 XmlSchema s2 = schemaCol.read(doc2.getDocumentElement());
72 assertNotNull(s2);
73 assertEquals("EUC-JP", s2.getInputEncoding().toUpperCase());
74
75
76
77
78 }
79
80 }