1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt;
18
19 import org.apache.commons.betwixt.io.SAXBeanWriter;
20 import org.xml.sax.Attributes;
21 import org.xml.sax.ContentHandler;
22 import org.xml.sax.Locator;
23 import org.xml.sax.SAXException;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 public class TestAttributeQNameProblem extends AbstractTestCase {
54
55 public TestAttributeQNameProblem(String testName) {
56 super(testName);
57 }
58
59 public static class StdOutContentHandler implements ContentHandler {
60
61 public void setDocumentLocator(Locator locator) {}
62
63 public void startDocument() throws SAXException {
64 System.out.println("XML: start document event");
65 }
66
67 public void endDocument() throws SAXException {
68 System.out.println("XML: end document event");
69 }
70
71 public void startPrefixMapping(String prefix, String uri) throws SAXException {
72 System.out.println("XML: start prefix '" + prefix + "' mapping, URI: " + uri);
73 }
74
75 public void endPrefixMapping(String prefix) throws SAXException {
76 System.out.println("XML: end prefix '" + prefix + "' mapping");
77 }
78
79 public void startElement(String uri, String localName, String qName, Attributes atts)
80 throws SAXException {
81 System.out.println("XML: start element qName '" + qName + "', localName '" + localName
82 + "', URI:" + uri);
83 for (int i = 0; i < atts.getLength(); i++) {
84 System.out.println(" - Attribute qName '" + atts.getQName(i) + "', localName '"
85 + atts.getLocalName(i) + "' of " + atts.getType(i) + ": "
86 + atts.getValue(i));
87 assertEquals(atts.getQName(i), atts.getLocalName(i));
88 }
89 }
90
91 public void endElement(String uri, String localName, String qName) throws SAXException {
92 System.out.println("XML: end element '" + qName + "'");
93 }
94
95 public void characters(char[] ch, int start, int length) throws SAXException {
96 System.out.println("XML: characters: from " + start + ", length " + length);
97 }
98
99 public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {}
100
101 public void processingInstruction(String target, String data) throws SAXException {
102 System.out.println("XML: processing instruction, target '" + target + "': " + data);
103 }
104
105 public void skippedEntity(String name) throws SAXException {}
106
107 }
108
109 public void testAttributeOutput() {
110 try {
111 SAXBeanWriter beanWriter = new SAXBeanWriter(new StdOutContentHandler());
112 Object bean = new SimpleClass();
113 beanWriter.write(bean);
114 } catch (Exception ex) {
115 ex.printStackTrace();
116 }
117 }
118
119 }