1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.danube.webdav.xml;
14
15
16 import org.abstracthorizon.danube.webdav.util.NamespacesProvider;
17
18 import java.io.IOException;
19
20 import org.xml.sax.Attributes;
21 import org.xml.sax.InputSource;
22 import org.xml.sax.SAXException;
23 import org.xml.sax.helpers.DefaultHandler;
24
25
26
27
28
29
30 public class WebDAVXMLHandler extends DefaultHandler {
31
32
33 protected Object currentObject;
34
35
36 protected NamespacesProvider namespacesProvider;
37
38
39 protected StringBuffer buffer = new StringBuffer();
40
41
42
43
44
45 public WebDAVXMLHandler(NamespacesProvider namespacesProvider) {
46 this.namespacesProvider = namespacesProvider;
47 }
48
49
50
51
52
53
54 public WebDAVXMLHandler(NamespacesProvider namespacesProvider, Object startObject) {
55 this.currentObject = startObject;
56 this.namespacesProvider = namespacesProvider;
57 }
58
59
60
61
62
63 public Object getResultObject() {
64 return currentObject;
65 }
66
67 @Override
68 public void startPrefixMapping(String prefix, String uri) throws SAXException {
69 }
70
71 @Override
72 public void endPrefixMapping(String prefix) throws SAXException {
73 }
74
75 @Override
76 public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
77 XMLParserHandler handler = namespacesProvider.getParserHandler(uri);
78 if (handler != null) {
79 buffer.delete(0, buffer.length());
80 currentObject = handler.start(currentObject, localName, attributes);
81 }
82 }
83
84 @Override
85 public void endElement(String uri, String localName, String qName) throws SAXException {
86 XMLParserHandler handler = namespacesProvider.getParserHandler(uri);
87 if (handler != null) {
88 currentObject = handler.end(currentObject, localName, buffer.toString().trim());
89 buffer.delete(0, buffer.length());
90 }
91 }
92
93 @Override
94 public InputSource resolveEntity(String publicId, String systemId) throws IOException, SAXException {
95 return null;
96 }
97
98 @Override
99 public void characters(char[] chars, int start, int len) throws SAXException {
100 buffer.append(chars, start, len);
101 }
102 }