1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.danube.webdav.xml.dav.request;
14
15 import org.abstracthorizon.danube.webdav.xml.XMLParserHandler;
16 import org.abstracthorizon.danube.webdav.xml.dav.HRef;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.xml.sax.Attributes;
22 import org.xml.sax.SAXException;
23
24
25
26
27
28
29 public class KeepAlive extends AbstractSimpleXMLHandler {
30
31
32 protected List<HRef> hrefs;
33
34
35 protected String value;
36
37
38
39
40
41 public KeepAlive(XMLParserHandler parent) {
42 super(parent);
43 }
44
45 @Override
46 public Object start(Object current, String tag, Attributes attributes) throws SAXException {
47 if ("href".equals(tag)) {
48 if (hrefs == null) {
49 hrefs = new ArrayList<HRef>();
50 }
51 HRef href = new HRef(this);
52 hrefs.add(href);
53 return href;
54 }
55 return this;
56 }
57
58 @Override
59 public Object end(Object current, String tag, String value) throws SAXException {
60 if (hrefs == null) {
61 this.value = value;
62 }
63 return super.end(current, tag, value);
64 }
65
66 @Override
67 public String toString() {
68 StringBuffer result = new StringBuffer("KeepAlive[");
69 if (hrefs == null) {
70 if (value == null) {
71 result.append(']');
72 } else {
73 result.append(value).append(']');
74 }
75 } else {
76 boolean first = true;
77 for (HRef href : hrefs) {
78 if (first) {
79 first = false;
80 } else {
81 result.append(',');
82 }
83 result.append(href.toString());
84 }
85 result.append(']');
86 }
87 return result.toString();
88 }
89 }