1 16 package nl.hippo.cms.repositorylocation; 17 18 26 public class RepositoryInformation 27 { 28 29 34 private String m_host; 35 36 41 private int m_port; 42 43 48 private String m_realm; 49 50 55 private String m_username; 56 57 62 private String m_password; 63 64 70 private String m_rootUri; 71 72 78 private String m_baseUri; 79 80 102 public RepositoryInformation(String host, int port, String realm, String username, 103 String password, String rootUri, String baseUri) 104 { 105 super(); 106 107 m_host = host; 108 m_port = port; 109 m_realm = realm; 110 m_username = username; 111 m_password = password; 112 m_rootUri = trimSlashes(rootUri); 113 m_baseUri = trimSlashes(baseUri); 114 } 115 116 public String getHost() 117 { 118 return m_host; 119 } 120 121 public int getPort() 122 { 123 return m_port; 124 } 125 126 public String getRealm() 127 { 128 return m_realm; 129 } 130 131 public String getUsername() 132 { 133 return m_username; 134 } 135 136 public String getPassword() 137 { 138 return m_password; 139 } 140 141 public String getRootUri() 142 { 143 return m_rootUri; 144 } 145 146 public String getBaseUri() 147 { 148 return m_baseUri; 149 } 150 151 158 public String getAbsoluteBaseUri() 159 { 160 return getAbsoluteBaseUri(false); 161 } 162 163 173 public String getAbsoluteUri(String uri) 174 { 175 StringBuffer absoluteUri = new StringBuffer (1000); 176 177 absoluteUri.append(getAbsoluteBaseUri()); 178 absoluteUri.append('/'); 179 absoluteUri.append(trimSlashes(uri)); 180 181 return absoluteUri.toString(); 182 } 183 184 194 private String getAbsoluteBaseUri(boolean includeCredentials) 195 { 196 StringBuffer absoluteBaseUri = new StringBuffer (1000); 197 198 absoluteBaseUri.append("http://"); 199 if (includeCredentials) 200 { 201 absoluteBaseUri.append(m_username); 202 absoluteBaseUri.append(':'); 203 absoluteBaseUri.append(m_password); 204 absoluteBaseUri.append('@'); 205 } 206 absoluteBaseUri.append(m_host); 207 absoluteBaseUri.append(':'); 208 absoluteBaseUri.append(m_port); 209 absoluteBaseUri.append('/'); 210 String rootUriWithoutSurroundingSlashes = m_rootUri; 211 if (!rootUriWithoutSurroundingSlashes.equals("")) 212 { 213 absoluteBaseUri.append(rootUriWithoutSurroundingSlashes); 214 absoluteBaseUri.append('/'); 215 } 216 String baseUriWithoutSurroundingSlashes = m_baseUri; 217 absoluteBaseUri.append(baseUriWithoutSurroundingSlashes); 218 219 return absoluteBaseUri.toString(); 220 } 221 222 229 public int hashCode() 230 { 231 int result; 232 233 result = m_host.hashCode(); 234 result |= m_port; 235 result |= m_realm.hashCode(); 236 result |= m_username.hashCode(); 237 result |= m_password.hashCode(); 238 result |= m_rootUri.hashCode(); 239 result |= m_baseUri.hashCode(); 240 241 return result; 242 } 243 244 254 public boolean equals(Object other) 255 { 256 boolean result; 257 258 if (other == null || !(other instanceof RepositoryInformation)) 259 { 260 result = false; 261 } 262 else if (other == this) 263 { 264 result = true; 265 } 266 else 267 { 268 RepositoryInformation otherRepoInfo = (RepositoryInformation) other; 269 270 result = otherRepoInfo.getHost().equals(m_host); 271 result = result && otherRepoInfo.getPort() == m_port; 272 result = result && otherRepoInfo.getRealm().equals(m_realm); 273 result = result && otherRepoInfo.getUsername().equals(m_username); 274 result = result && otherRepoInfo.getPassword().equals(m_password); 275 result = result && otherRepoInfo.getRootUri().equals(m_rootUri); 276 result = result && otherRepoInfo.getBaseUri().equals(m_baseUri); 277 } 278 279 return result; 280 } 281 282 289 public String toString() 290 { 291 return "Repository: " + getAbsoluteBaseUri(true); 292 } 293 294 304 private String trimSlashes(String text) 305 { 306 int indexOfNonSlash = 0; 307 while (indexOfNonSlash < text.length() && text.charAt(indexOfNonSlash) == '/') 308 { 309 indexOfNonSlash += 1; 310 } 311 text = text.substring(indexOfNonSlash); 312 313 indexOfNonSlash = text.length() - 1; 314 while (indexOfNonSlash >= 0 && text.charAt(indexOfNonSlash) == '/') 315 { 316 indexOfNonSlash -= 1; 317 } 318 text = text.substring(0, indexOfNonSlash + 1); 319 320 return text; 321 } 322 } | Popular Tags |