1 | package nu.fw.jeti.jabber.elements; |
---|
2 | |
---|
3 | |
---|
4 | import java.util.*; |
---|
5 | |
---|
6 | import nu.fw.jeti.events.PreferenceListener; |
---|
7 | import nu.fw.jeti.jabber.Backend; |
---|
8 | import nu.fw.jeti.util.I18N; |
---|
9 | import nu.fw.jeti.util.Popups; |
---|
10 | import nu.fw.jeti.util.Preferences; |
---|
11 | |
---|
12 | |
---|
13 | /** |
---|
14 | * Title: im |
---|
15 | * Description: |
---|
16 | * Copyright: Copyright (c) 2001 |
---|
17 | * Company: |
---|
18 | * @author E.S. de Boer |
---|
19 | * @version 1.0 |
---|
20 | */ |
---|
21 | |
---|
22 | public class JetiPrivateExtension extends Extension implements IQXExtension |
---|
23 | { |
---|
24 | private Map map; |
---|
25 | private Map messages ; |
---|
26 | private String xmlVer; |
---|
27 | public final static String XML_VERSION ="v1"; |
---|
28 | |
---|
29 | public JetiPrivateExtension(){} |
---|
30 | |
---|
31 | public JetiPrivateExtension(Map map,Map messages) |
---|
32 | { |
---|
33 | this.messages = messages; |
---|
34 | this.map = map; |
---|
35 | xmlVer = XML_VERSION; |
---|
36 | } |
---|
37 | |
---|
38 | public JetiPrivateExtension(JetiExtensionBuilder builder) |
---|
39 | { |
---|
40 | map = Collections.unmodifiableMap(builder.getMap()); |
---|
41 | messages = Collections.unmodifiableMap(builder.getMapMessages()); |
---|
42 | xmlVer = builder.getXmlVersion(); |
---|
43 | if (xmlVer == null) xmlVer = "v1";//empty private space then newest version |
---|
44 | } |
---|
45 | |
---|
46 | public Map getMap() |
---|
47 | { |
---|
48 | return map; |
---|
49 | } |
---|
50 | |
---|
51 | public Map getMessages() |
---|
52 | { |
---|
53 | return messages; |
---|
54 | } |
---|
55 | |
---|
56 | public String getXmlVersion() |
---|
57 | { |
---|
58 | return xmlVer; |
---|
59 | } |
---|
60 | |
---|
61 | public void execute(InfoQuery iq,Backend backend) |
---|
62 | { |
---|
63 | if (iq.getType().equals("result")) |
---|
64 | { |
---|
65 | Preferences.load(this); |
---|
66 | for (Iterator j = backend.getListeners(PreferenceListener.class); j.hasNext();) |
---|
67 | { |
---|
68 | ((PreferenceListener) j.next()).preferencesChanged(); |
---|
69 | } |
---|
70 | } |
---|
71 | else if (iq.getType().equals("error")) |
---|
72 | { |
---|
73 | System.out.println("Preferences load error"); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | public void appendToXML(StringBuffer retval) |
---|
78 | { |
---|
79 | retval.append("<j2m xmlns=\"j2m:prefs\""); |
---|
80 | if (map == null && messages == null) |
---|
81 | { //short cut |
---|
82 | retval.append("/>"); |
---|
83 | return; |
---|
84 | } |
---|
85 | |
---|
86 | appendAttribute(retval,"xmlVersion",xmlVer); |
---|
87 | if(map != null) |
---|
88 | { |
---|
89 | for (Iterator i=map.entrySet().iterator(); i.hasNext(); ) |
---|
90 | { |
---|
91 | Map.Entry e = (Map.Entry) i.next(); |
---|
92 | appendAttribute(retval,(String)e.getKey(),(String)e.getValue()); |
---|
93 | } |
---|
94 | } |
---|
95 | retval.append(">"); |
---|
96 | |
---|
97 | if(messages != null) |
---|
98 | { |
---|
99 | retval.append("<status>"); |
---|
100 | for (Iterator i=messages.entrySet().iterator(); i.hasNext(); ) |
---|
101 | { |
---|
102 | Map.Entry e = (Map.Entry) i.next(); |
---|
103 | { |
---|
104 | retval.append("<"+ e.getKey()); |
---|
105 | List tempList = (List)e.getValue(); |
---|
106 | for(int tel=0;tel<tempList.size();tel++) |
---|
107 | { |
---|
108 | appendAttribute(retval,"s"+ tel,(String)tempList.get(tel)); |
---|
109 | } |
---|
110 | retval.append("/>"); |
---|
111 | } |
---|
112 | } |
---|
113 | retval.append("</status>"); |
---|
114 | } |
---|
115 | retval.append("</j2m>"); |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | /* |
---|
120 | * Overrides for emacs |
---|
121 | * Local variables: |
---|
122 | * tab-width: 4 |
---|
123 | * End: |
---|
124 | */ |
---|