1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package nl.hippo.client.webdav;
17
18 import java.io.InputStream;
19 import java.util.Properties;
20
21 import nl.hippo.client.api.ClientException;
22
23 import org.apache.commons.lang.builder.EqualsBuilder;
24 import org.apache.commons.lang.builder.HashCodeBuilder;
25
26 /**
27 * Configuration class, each implementation
28 * of WebdavMethod has one constructor with a WebdavConfig as parameter.
29 * <p>
30 * Implemented as a Value Object which means that:
31 * <ul>
32 * <li>
33 * The identity of an instance is solely based on it's property values:
34 * instances with equal values are interchangable.
35 * </li>
36 * <li>
37 * Instances are threadsafe over multiple threads running concurrently,
38 * and may be used multiple times in a given session.
39 * </li>
40 * </ul>
41 */
42 public final class WebdavConfig extends AbstractWebdavConfig {
43
44 private static final long serialVersionUID = 1L;
45
46 /**
47 * Read configuration from an InputStream on a properties file.
48 * @param stream An InputStream on a properties file.
49 * @throws ClientException if something went wrong.
50 */
51 public WebdavConfig(InputStream stream) throws ClientException {
52 super(stream);
53 }
54
55 /**
56 * Read configuration from a Properties object
57 */
58 public WebdavConfig(Properties config) {
59 super(config);
60 }
61
62 /**
63 * Read property values from a WebdavConfigFactory instance
64 * @param config a WebdavConfigFactory instance
65 * @see WebdavConfigFactory
66 */
67 public WebdavConfig(WebdavConfigFactory config) {
68 host = config.getHost() == null ? "" : config.getHost();
69 port = config.getPort();
70 protocol = new String(config.getProtocol() == null ? "" : config.getProtocol());
71 contextroot = config.getContextRoot();
72 username = new String(config.getUsername() == null ? "" : config.getUsername());
73 password = new String(config.getPassword() == null ? "" : config.getPassword());
74 realm = new String(config.getRealm() == null ? "" : config.getRealm());
75 namespace = new String(config.getNamespace() == null ? "" : config.getNamespace());
76 filespath = new String(config.getFilespath() == null ? "" : config.getFilespath());
77 loglabel = new String(config.getLoglabel() == null ? "" : config.getLoglabel());
78 searchNoACL = config.getSearchNoACL();
79 }
80
81 public boolean equals(Object obj) {
82 boolean eq;
83 if (obj == null) {
84 eq = false;
85 } else if (!(obj instanceof WebdavConfig)) {
86 eq = false;
87 } else if (this == obj) {
88 eq = true;
89 } else {
90 WebdavConfig rhs = (WebdavConfig) obj;
91 eq = new EqualsBuilder()
92 .append(getUsername(), rhs.getUsername())
93 .append(getPassword(), rhs.getPassword())
94 .append(getHost(), rhs.getHost())
95 .append(getProtocol(), rhs.getProtocol())
96 .append(getContextRoot(), rhs.getContextRoot())
97 .append(getNamespace(), rhs.getNamespace())
98 .append(getFilespath(), rhs.getFilespath())
99 .append(getRealm(), rhs.getRealm())
100 .append(getPort(), rhs.getPort())
101 .append(getSearchNoACL(), rhs.getSearchNoACL())
102 .isEquals();
103 }
104 return eq;
105 }
106
107 public int hashCode() {
108 int hash = new HashCodeBuilder(23, 79)
109 .append(getUsername())
110 .append(getPassword())
111 .append(getHost())
112 .append(getProtocol())
113 .append(getContextRoot())
114 .append(getNamespace())
115 .append(getFilespath())
116 .append(getRealm())
117 .append(getPort())
118 .append(getLoglabel())
119 .append(getSearchNoACL())
120 .toHashCode();
121 return hash;
122 }
123
124 }