1 | package nu.fw.jeti.jabber.elements; |
---|
2 | import java.util.Iterator; |
---|
3 | import java.util.Map; |
---|
4 | |
---|
5 | import nu.fw.jeti.events.RegisterListener; |
---|
6 | import nu.fw.jeti.jabber.Backend; |
---|
7 | import nu.fw.jeti.util.I18N; |
---|
8 | import nu.fw.jeti.util.Popups; |
---|
9 | |
---|
10 | |
---|
11 | /** |
---|
12 | * @author E.S. de Boer |
---|
13 | * @version 1.0 |
---|
14 | */ |
---|
15 | |
---|
16 | public class IQRegister extends Extension implements IQExtension |
---|
17 | { |
---|
18 | private boolean remove =false; |
---|
19 | private Map fields; |
---|
20 | private XData xdata; |
---|
21 | private String password; |
---|
22 | private String username; |
---|
23 | |
---|
24 | |
---|
25 | public IQRegister(){} |
---|
26 | |
---|
27 | public IQRegister(String username,String password) |
---|
28 | { |
---|
29 | this.password = password; |
---|
30 | this.username = username; |
---|
31 | } |
---|
32 | |
---|
33 | public IQRegister(XData xdata){this.xdata = xdata;} |
---|
34 | |
---|
35 | public IQRegister(boolean remove,Map fields,XData xdata) |
---|
36 | { |
---|
37 | this.remove = remove; |
---|
38 | this.fields =fields; |
---|
39 | this.xdata = xdata; |
---|
40 | } |
---|
41 | |
---|
42 | public IQRegister(boolean remove,Map fields) |
---|
43 | { |
---|
44 | this.remove = remove; |
---|
45 | this.fields =fields; |
---|
46 | } |
---|
47 | |
---|
48 | public boolean getRemove(){return remove;} |
---|
49 | |
---|
50 | public Map getFields(){return fields;} |
---|
51 | |
---|
52 | public XData getXData(){return xdata;} |
---|
53 | |
---|
54 | public void execute(InfoQuery iq,Backend backend) |
---|
55 | { |
---|
56 | if (iq.getType().equals("result")) |
---|
57 | { |
---|
58 | for (Iterator j = backend.getListeners(RegisterListener.class); j.hasNext();) |
---|
59 | { |
---|
60 | ((RegisterListener) j.next()).register(this,iq.getID()); |
---|
61 | } |
---|
62 | |
---|
63 | } |
---|
64 | else if (iq.getType().equals("error")) |
---|
65 | { |
---|
66 | Popups.errorPopup(iq.getErrorDescription(), I18N.gettext("main.error.Register_Error")); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | public void appendToXML(StringBuffer xml) |
---|
72 | { |
---|
73 | xml.append("<query xmlns=\"jabber:iq:register\""); |
---|
74 | if(username==null && fields == null && !remove && xdata == null) |
---|
75 | { //short cut |
---|
76 | xml.append("/>"); |
---|
77 | return; |
---|
78 | } |
---|
79 | xml.append('>'); |
---|
80 | if(username!=null) |
---|
81 | { |
---|
82 | appendElement(xml,"username",username); |
---|
83 | appendElement(xml,"password",password); |
---|
84 | } |
---|
85 | else |
---|
86 | { |
---|
87 | appendElement(xml,fields); |
---|
88 | appendElement(xml,"remove",remove); |
---|
89 | if(xdata != null) xdata.appendToXML(xml); |
---|
90 | } |
---|
91 | xml.append("</query>"); |
---|
92 | } |
---|
93 | } |
---|
94 | /* |
---|
95 | * Overrides for emacs |
---|
96 | * Local variables: |
---|
97 | * tab-width: 4 |
---|
98 | * End: |
---|
99 | */ |
---|