01: package dalma.endpoints.irc;
02:
03: import dalma.spi.EndPointFactory;
04: import dalma.EndPoint;
05:
06: import java.text.ParseException;
07: import java.net.URI;
08: import java.net.URISyntaxException;
09:
10: /**
11: * {@link EndPointFactory} for creating "irc://" URL.
12: *
13: * See https://dalma.dev.java.net/nonav/maven/dalma-endpoint-irc/endpointURL.html
14: *
15: * @author Kohsuke Kawaguchi
16: */
17: public class IRCEndPointFactory implements EndPointFactory {
18: // irc://nick@server:port/
19: public EndPoint create(String endPointName, String endpointURL)
20: throws ParseException {
21: try {
22: URI uri = new URI(endpointURL);
23:
24: int port = uri.getPort();
25: if (port == -1)
26: port = 6667;
27:
28: if (uri.getUserInfo() == null)
29: throw new ParseException(
30: "irc:// URL needs to have \"<username>@\" portion",
31: 0);
32:
33: return new IRCEndPoint(endPointName, uri.getHost(), port,
34: uri.getUserInfo());
35: } catch (URISyntaxException e) {
36: ParseException pe = new ParseException(e.getMessage(), 0);
37: pe.initCause(e);
38: throw pe;
39: }
40: }
41: }
|