01: /*
02: * $Id: ResourceNameEndpointURIBuilder.java 10489 2008-01-23 17:53:38Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.endpoint;
12:
13: import org.mule.api.endpoint.MalformedEndpointException;
14: import org.mule.util.StringUtils;
15:
16: import java.net.URI;
17: import java.util.Properties;
18:
19: /**
20: * <code>ResourceNameEndpointBuilder</code> extracts a resource name from a uri
21: * endpointUri
22: *
23: */
24: public class ResourceNameEndpointURIBuilder extends
25: AbstractEndpointURIBuilder {
26: public static final String RESOURCE_INFO_PROPERTY = "resourceInfo";
27:
28: protected void setEndpoint(URI uri, Properties props)
29: throws MalformedEndpointException {
30: address = StringUtils.EMPTY;
31: if (uri.getHost() != null && !"localhost".equals(uri.getHost())) {
32: address = uri.getHost();
33: }
34:
35: if (uri.getPath() != null && uri.getPath().length() != 0) {
36: if (address.length() > 0) {
37: address += "/";
38: }
39: address += uri.getPath().substring(1);
40: } else if (uri.getAuthority() != null
41: && !uri.getAuthority().equals(address)) {
42: address += uri.getAuthority();
43: }
44: // is user info specified?
45: int y = address.indexOf("@");
46: if (y > -1) {
47: this .userInfo = address.substring(0, y);
48: }
49: // increment to 0 or one char past the @
50: y++;
51:
52: int x = address.indexOf(":", y);
53: if (x > -1) {
54: String resourceInfo = address.substring(y, x);
55: props.setProperty("resourceInfo", resourceInfo);
56: address = address.substring(x + 1);
57: }
58: }
59: }
|