1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.xmpp.config; |
12 | |
|
13 | |
import org.mule.config.spring.handlers.AbstractMuleNamespaceHandler; |
14 | |
import org.mule.config.spring.parsers.PreProcessor; |
15 | |
import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration; |
16 | |
import org.mule.config.spring.parsers.processors.RequireAttribute; |
17 | |
import org.mule.endpoint.URIBuilder; |
18 | |
import org.mule.transport.xmpp.XmppConnector; |
19 | |
import org.mule.util.StringUtils; |
20 | |
|
21 | |
import org.w3c.dom.Element; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | 6 | public class XmppNamespaceHandler extends AbstractMuleNamespaceHandler |
27 | |
{ |
28 | |
|
29 | |
public static final String RECIPIENT = "recipient"; |
30 | 2 | public static final String[] REQUIRED_ADDRESS_ATTRIBUTES = |
31 | |
new String[]{RECIPIENT, URIBuilder.USER, URIBuilder.HOST}; |
32 | |
|
33 | |
public void init() |
34 | |
{ |
35 | 6 | registerStandardTransportEndpoints(XmppConnector.XMPP, REQUIRED_ADDRESS_ATTRIBUTES).addAlias(RECIPIENT, URIBuilder.PATH).registerPreProcessor(new RequireNickname()); |
36 | 6 | this.registerConnectorDefinitionParser(XmppConnector.class); |
37 | 6 | } |
38 | |
|
39 | 6 | public static class RequireNickname implements PreProcessor |
40 | |
{ |
41 | |
|
42 | |
public void preProcess(PropertyConfiguration config, Element element) |
43 | |
{ |
44 | 62 | String groupChat = element.getAttribute(XmppConnector.XMPP_GROUP_CHAT); |
45 | 62 | if (Boolean.valueOf(groupChat).booleanValue()) |
46 | |
{ |
47 | 32 | if (StringUtils.isBlank(element.getAttribute(XmppConnector.XMPP_NICKNAME))) |
48 | |
{ |
49 | 2 | throw new RequireAttribute.RequireAttributeException("Attribute " + |
50 | |
XmppConnector.XMPP_NICKNAME + " must be given if " + |
51 | |
XmppConnector.XMPP_GROUP_CHAT + " is true."); |
52 | |
} |
53 | |
} |
54 | 60 | } |
55 | |
|
56 | |
} |
57 | |
|
58 | |
} |