Constructs a string representation of this URLName.
()
| 166 | * Constructs a string representation of this URLName. |
| 167 | */ |
| 168 | @Override |
| 169 | public String toString() { |
| 170 | if (fullURL == null) { |
| 171 | // add the "protocol:" |
| 172 | StringBuilder tempURL = new StringBuilder(); |
| 173 | if (protocol != null) { |
| 174 | tempURL.append(protocol); |
| 175 | tempURL.append(":"); |
| 176 | } |
| 177 | |
| 178 | if (username != null || host != null) { |
| 179 | // add the "//" |
| 180 | tempURL.append("//"); |
| 181 | |
| 182 | // add the user:password@ |
| 183 | // XXX - can you just have a password? without a username? |
| 184 | if (username != null) { |
| 185 | tempURL.append(username); |
| 186 | |
| 187 | if (password != null){ |
| 188 | tempURL.append(":"); |
| 189 | tempURL.append(password); |
| 190 | } |
| 191 | |
| 192 | tempURL.append("@"); |
| 193 | } |
| 194 | |
| 195 | // add host |
| 196 | if (host != null) { |
| 197 | tempURL.append(host); |
| 198 | } |
| 199 | |
| 200 | // add port (if needed) |
| 201 | if (port != -1) { |
| 202 | tempURL.append(":"); |
| 203 | tempURL.append(Integer.toString(port)); |
| 204 | } |
| 205 | if (file != null) |
| 206 | tempURL.append("/"); |
| 207 | } |
| 208 | |
| 209 | // add the file |
| 210 | if (file != null) { |
| 211 | tempURL.append(file); |
| 212 | } |
| 213 | |
| 214 | // add the ref |
| 215 | if (ref != null) { |
| 216 | tempURL.append("#"); |
| 217 | tempURL.append(ref); |
| 218 | } |
| 219 | |
| 220 | // create the fullURL now |
| 221 | fullURL = tempURL.toString(); |
| 222 | } |
| 223 | |
| 224 | return fullURL; |
| 225 | } |