• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007-2008 Esmertec AG.
3  * Copyright (C) 2007-2008 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package com.android.im.imps;
19 
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.Map.Entry;
23 
24 public class PtsCodes {
25 
PtsCodes()26     private PtsCodes() {
27     }
28 
29     private static HashMap<String, String> sCodeToTransaction = new HashMap<String, String>();
30     private static HashMap<String, String> sCodeToElement = new HashMap<String, String>();
31     private static HashMap<String, String> sCodeToCapElement = new HashMap<String, String>();
32     private static HashMap<String, String> sCodeToCapValue= new HashMap<String, String>();
33     private static HashMap<String, String> sCodeToServiceTree = new HashMap<String, String>();
34     private static HashMap<String, String> sCodeToPresenceAttribute = new HashMap<String, String>();
35 
36     private static HashMap<String, String> sTransactionToCode = new HashMap<String, String>();
37     private static HashMap<String, String> sElementToCode = new HashMap<String, String>();
38     /*package*/ static HashMap<String, String> sCapElementToCode = new HashMap<String, String>();
39     /*package*/ static HashMap<String, String> sCapValueToCode= new HashMap<String, String>();
40     private static HashMap<String, String> sServiceTreeToCode = new HashMap<String, String>();
41     static HashMap<String, String> sContactListPropsToCode = new HashMap<String, String>();
42     private static HashMap<String, String> sPresenceAttributeToCode = new HashMap<String, String>();
43 
44     private static ArrayList<String> sServerRequestTransactionCode = new ArrayList<String>();
45     private static HashMap<String, String> sCodeToPAValue = new HashMap<String, String>();
46     private static HashMap<String, String> sPAValueToCode = new HashMap<String, String>();
47 
getTransaction(String type)48     public static String getTransaction(String type) {
49         // not case sensitive
50         return sCodeToTransaction.get(type.toUpperCase());
51     }
52 
getElement(String type)53     public static String getElement(String type) {
54         // not case sensitive
55         return sCodeToElement.get(type.toUpperCase());
56     }
57 
getCapElement(String type)58     public static String getCapElement(String type) {
59         // not case sensitive
60         return sCodeToCapElement.get(type.toUpperCase());
61     }
62 
getCapValue(String type)63     public static String getCapValue(String type) {
64         // not case sensitive
65         return sCodeToCapValue.get(type.toUpperCase()) == null ?
66                 type : sCodeToCapValue.get(type.toUpperCase());
67     }
68 
getServiceTreeValue(String type)69     public static String getServiceTreeValue(String type) {
70         // not case sensitive
71         return sCodeToServiceTree.get(type.toUpperCase());
72     }
73 
getTxCode(String txType)74     public static String getTxCode(String txType) {
75         return sTransactionToCode.get(txType);
76     }
77 
getElementCode(String elemType, String transactionType)78     public static String getElementCode(String elemType, String transactionType) {
79         if (ImpsTags.PresenceSubList.equals(elemType)) {
80             return ImpsTags.UpdatePresence_Request.equals(transactionType) ? "UV" : "PS";
81         }
82 
83         return sElementToCode.get(elemType);
84     }
85 
getCapElementCode(String elemType)86     public static String getCapElementCode(String elemType) {
87         return sCapElementToCode.get(elemType);
88     }
89 
getCapValueCode(String value)90     public static String getCapValueCode(String value) {
91         return sCapValueToCode.get(value);
92     }
93 
getServiceTreeCode(String elemType)94     public static String getServiceTreeCode(String elemType) {
95         return sServiceTreeToCode.get(elemType);
96     }
97 
getPresenceAttributeCode(String elemType)98     public static String getPresenceAttributeCode(String elemType){
99         return sPresenceAttributeToCode.get(elemType);
100     }
101 
getPresenceAttributeElement(String code)102     public static String getPresenceAttributeElement(String code) {
103         // not case sensitive
104         return sCodeToPresenceAttribute.get(code.toUpperCase());
105     }
106 
getPAValue(String code)107     public static String getPAValue(String code) {
108         // not case sensitive
109         String value = sCodeToPAValue.get(code.toUpperCase());
110 
111         return value == null ? code : value;
112     }
113 
getPAValueCode(String value)114     public static String getPAValueCode(String value) {
115         // not case sensitive
116         String code = sPAValueToCode.get(value.toUpperCase());
117         return code == null ? value : code;
118     }
119 
isServerRequestCode(String type)120     public static boolean isServerRequestCode(String type) {
121         for (String code : sServerRequestTransactionCode) {
122             if (code.equals(type)) {
123                 return true;
124             }
125         }
126 
127         return false;
128     }
129 
130     // Fundamental primitives and transactions
131     public static final String ClientCapability_Response    = "PC";
132     public static final String Disconnect                   = "DI";
133 //    public static final String GetList_Request              = "GL";
134     public static final String GetList_Response             = "LG";
135 //    public static final String KeepAlive_Request            = "KA";
136     public static final String KeepAlive_Response           = "AK";
137     public static final String Login_Response               = "RL";
138 //    public static final String Logout_Request               = "OR";
139 //    public static final String Polling_Request              = "PO";
140 //    public static final String Service_Request              = "SQ";
141     public static final String Service_Response             = "QS";
142     public static final String Status                       = "ST";   // the same for the element "Status"
143     public static final String ListManage_Response          = "ML";
144     public static final String PresenceNotification         = "PN";
145     public static final String GetPresence_Response         = "PG";
146 //    public static final String Disconnect = "Disconnect";
147 //    public static final String KeepAlive_Request = "KeepAlive-Request";
148 //    public static final String KeepAlive_Response = "KeepAlive-Response";
149 //    public static final String Service_Request = "Service-Request";
150 //    public static final String Service_Response = "Service-Response";
151 
152     // Information elements
153     public static final String AllFunctions          = "AF";
154     public static final String CapabilityList        = "CA";
155     public static final String AgreedCapabilityList  = "AP";
156     public static final String CapabilityRequest     = "CR";
157     public static final String ClientID              = "CI";
158     public static final String ContactList           = "CL";
159     public static final String DefaultContactList    = "DC";
160     public static final String DigestSchema          = "DI";
161     public static final String Nonce                 = "NO";
162     public static final String NotAvailableFunctions = "NF";
163     public static final String KeepAliveTime         = "KA";
164     public static final String SessionID             = "SI";
165     public static final String DefaultList           = "DL";
166     public static final String UserNickList          = "UN";
167     public static final String ContactListProps      = "CP";
168     public static final String Presence              = "PR";
169 
170     // Contact list properties
171     public static final String DisplayName = "DN";
172     public static final String Default     = "DE";
173 
174     static {
sTransactionToCode.put(ImpsTags.Login_Request, "LR")175         sTransactionToCode.put(ImpsTags.Login_Request, "LR");
sTransactionToCode.put(ImpsTags.ClientCapability_Request, "CP")176         sTransactionToCode.put(ImpsTags.ClientCapability_Request, "CP");
sTransactionToCode.put(ImpsTags.Service_Request, "SQ")177         sTransactionToCode.put(ImpsTags.Service_Request, "SQ");
sTransactionToCode.put(ImpsTags.Logout_Request, "OR")178         sTransactionToCode.put(ImpsTags.Logout_Request, "OR");
sTransactionToCode.put(ImpsTags.Status, "ST")179         sTransactionToCode.put(ImpsTags.Status, "ST");
sTransactionToCode.put(ImpsTags.GetList_Request, "GL")180         sTransactionToCode.put(ImpsTags.GetList_Request, "GL");
sTransactionToCode.put(ImpsTags.CreateList_Request, "CL")181         sTransactionToCode.put(ImpsTags.CreateList_Request, "CL");
sTransactionToCode.put(ImpsTags.DeleteList_Request, "DL")182         sTransactionToCode.put(ImpsTags.DeleteList_Request, "DL");
sTransactionToCode.put(ImpsTags.ListManage_Request, "LM")183         sTransactionToCode.put(ImpsTags.ListManage_Request, "LM");
sTransactionToCode.put(ImpsTags.GetPresence_Request, "GP")184         sTransactionToCode.put(ImpsTags.GetPresence_Request, "GP");
sTransactionToCode.put(ImpsTags.SubscribePresence_Request, "SB")185         sTransactionToCode.put(ImpsTags.SubscribePresence_Request, "SB");
sTransactionToCode.put(ImpsTags.GetBlockedList_Request, "GB")186         sTransactionToCode.put(ImpsTags.GetBlockedList_Request, "GB");
sTransactionToCode.put(ImpsTags.CreateAttributeList_Request, "CA")187         sTransactionToCode.put(ImpsTags.CreateAttributeList_Request, "CA");
sTransactionToCode.put(ImpsTags.Polling_Request, "PO")188         sTransactionToCode.put(ImpsTags.Polling_Request, "PO");
sTransactionToCode.put(ImpsTags.UpdatePresence_Request, "UP")189         sTransactionToCode.put(ImpsTags.UpdatePresence_Request, "UP");
190 
sElementToCode.put(ImpsTags.ClientID, ClientID)191         sElementToCode.put(ImpsTags.ClientID, ClientID);
sElementToCode.put(ImpsTags.DigestSchema, "SH")192         sElementToCode.put(ImpsTags.DigestSchema, "SH");
sElementToCode.put(ImpsTags.DigestBytes, "DB")193         sElementToCode.put(ImpsTags.DigestBytes, "DB");
sElementToCode.put(ImpsTags.Password, "PW")194         sElementToCode.put(ImpsTags.Password, "PW");
sElementToCode.put(ImpsTags.SessionCookie, "SC")195         sElementToCode.put(ImpsTags.SessionCookie, "SC");
sElementToCode.put(ImpsTags.TimeToLive, "TL")196         sElementToCode.put(ImpsTags.TimeToLive, "TL");
sElementToCode.put(ImpsTags.UserID, "UI")197         sElementToCode.put(ImpsTags.UserID, "UI");
sElementToCode.put(ImpsTags.CapabilityList, CapabilityList)198         sElementToCode.put(ImpsTags.CapabilityList, CapabilityList);
sElementToCode.put(ImpsTags.Functions, "RF")199         sElementToCode.put(ImpsTags.Functions, "RF");
sElementToCode.put(ImpsTags.AllFunctionsRequest, "AR")200         sElementToCode.put(ImpsTags.AllFunctionsRequest, "AR");
sElementToCode.put(ImpsTags.Result, "ST")201         sElementToCode.put(ImpsTags.Result, "ST");
sElementToCode.put(ImpsTags.ContactList, "CL")202         sElementToCode.put(ImpsTags.ContactList, "CL");
sElementToCode.put(ImpsTags.NickList, "UN")203         sElementToCode.put(ImpsTags.NickList, "UN");
sElementToCode.put(ImpsTags.AddNickList, "AN")204         sElementToCode.put(ImpsTags.AddNickList, "AN");
sElementToCode.put(ImpsTags.RemoveNickList, "RN")205         sElementToCode.put(ImpsTags.RemoveNickList, "RN");
sElementToCode.put(ImpsTags.ContactListProperties, "CP")206         sElementToCode.put(ImpsTags.ContactListProperties, "CP");
sElementToCode.put(ImpsTags.ReceiveList, "RL")207         sElementToCode.put(ImpsTags.ReceiveList, "RL");
sElementToCode.put(ImpsTags.PresenceSubList, "PS")208         sElementToCode.put(ImpsTags.PresenceSubList, "PS");
sElementToCode.put(ImpsTags.DefaultList, DefaultList)209         sElementToCode.put(ImpsTags.DefaultList, DefaultList);
sElementToCode.put(ImpsTags.AutoSubscribe, "AS")210         sElementToCode.put(ImpsTags.AutoSubscribe, "AS");
211 
sCodeToTransaction.put(ClientCapability_Response, ImpsTags.ClientCapability_Response)212         sCodeToTransaction.put(ClientCapability_Response, ImpsTags.ClientCapability_Response);
sCodeToTransaction.put(Disconnect, ImpsTags.Disconnect)213         sCodeToTransaction.put(Disconnect, ImpsTags.Disconnect);
sCodeToTransaction.put(GetList_Response, ImpsTags.GetList_Response)214         sCodeToTransaction.put(GetList_Response, ImpsTags.GetList_Response);
sCodeToTransaction.put(KeepAlive_Response, ImpsTags.KeepAlive_Response)215         sCodeToTransaction.put(KeepAlive_Response, ImpsTags.KeepAlive_Response);
sCodeToTransaction.put(Login_Response, ImpsTags.Login_Response)216         sCodeToTransaction.put(Login_Response, ImpsTags.Login_Response);
sCodeToTransaction.put(Service_Response, ImpsTags.Service_Response)217         sCodeToTransaction.put(Service_Response, ImpsTags.Service_Response);
sCodeToTransaction.put(Status, ImpsTags.Status)218         sCodeToTransaction.put(Status, ImpsTags.Status);
sCodeToTransaction.put(ListManage_Response, ImpsTags.ListManage_Response)219         sCodeToTransaction.put(ListManage_Response, ImpsTags.ListManage_Response);
sCodeToTransaction.put(PresenceNotification, ImpsTags.PresenceNotification_Request)220         sCodeToTransaction.put(PresenceNotification, ImpsTags.PresenceNotification_Request);
sCodeToTransaction.put(GetPresence_Response, ImpsTags.GetPresence_Response)221         sCodeToTransaction.put(GetPresence_Response, ImpsTags.GetPresence_Response);
222 
sCodeToElement.put(AllFunctions, ImpsTags.AllFunctions)223         sCodeToElement.put(AllFunctions, ImpsTags.AllFunctions);
sCodeToElement.put(CapabilityList, ImpsTags.CapabilityList)224         sCodeToElement.put(CapabilityList, ImpsTags.CapabilityList);
sCodeToElement.put(CapabilityRequest, ImpsTags.CapabilityRequest)225         sCodeToElement.put(CapabilityRequest, ImpsTags.CapabilityRequest);
sCodeToElement.put(ClientID, ImpsTags.ClientID)226         sCodeToElement.put(ClientID, ImpsTags.ClientID);
sCodeToElement.put(ContactList, ImpsTags.ContactList)227         sCodeToElement.put(ContactList, ImpsTags.ContactList);
sCodeToElement.put(DigestSchema, ImpsTags.DigestSchema)228         sCodeToElement.put(DigestSchema, ImpsTags.DigestSchema);
sCodeToElement.put(Nonce, ImpsTags.Nonce)229         sCodeToElement.put(Nonce, ImpsTags.Nonce);
sCodeToElement.put(NotAvailableFunctions, ImpsTags.NotAvailableFunctions)230         sCodeToElement.put(NotAvailableFunctions, ImpsTags.NotAvailableFunctions);
sCodeToElement.put(KeepAliveTime, ImpsTags.KeepAliveTime)231         sCodeToElement.put(KeepAliveTime, ImpsTags.KeepAliveTime);
sCodeToElement.put(SessionID, ImpsTags.SessionID)232         sCodeToElement.put(SessionID, ImpsTags.SessionID);
sCodeToElement.put(Status, ImpsTags.Status)233         sCodeToElement.put(Status, ImpsTags.Status);
sCodeToElement.put(DefaultList, ImpsTags.DefaultContactList)234         sCodeToElement.put(DefaultList, ImpsTags.DefaultContactList);
sCodeToElement.put(UserNickList, ImpsTags.NickList)235         sCodeToElement.put(UserNickList, ImpsTags.NickList);
sCodeToElement.put(Presence, ImpsTags.Presence)236         sCodeToElement.put(Presence, ImpsTags.Presence);
237 
238         // Capability element <=> code
239         sCodeToCapElement.put("CT", ImpsTags.ClientType);
240         sCodeToCapElement.put("CI", ImpsTags.CIRHTTPAddress);
241         sCodeToCapElement.put("DL", ImpsTags.DefaultLanguage);
242         sCodeToCapElement.put("ID", ImpsTags.InitialDeliveryMethod);
243         sCodeToCapElement.put("MT", ImpsTags.MultiTrans);
244         sCodeToCapElement.put("PS", ImpsTags.ParserSize);
245         sCodeToCapElement.put("PM", ImpsTags.ServerPollMin);
246         sCodeToCapElement.put("SB", ImpsTags.SupportedBearer);
247         sCodeToCapElement.put("SC", ImpsTags.SupportedCIRMethod);
248         sCodeToCapElement.put("TA", ImpsTags.TCPAddress);
249         sCodeToCapElement.put("TP", ImpsTags.TCPPort);
250         sCodeToCapElement.put("UP", ImpsTags.UDPPort);
251 
252         for (Entry<String, String> e : sCodeToCapElement.entrySet()) {
e.getValue()253             sCapElementToCode.put(e.getValue(), e.getKey());
254         }
255 
256         // Capability value <=> code
257         sCodeToCapValue.put("SS", "SSMS");
258         sCodeToCapValue.put("ST", "STCP");
259         sCodeToCapValue.put("SU", "SUDP");
260         sCodeToCapValue.put("WS", "WAPSMS");
261         sCodeToCapValue.put("WU", "WAPUDP");
262         // value of ClientType
263         sCodeToCapValue.put("MP", ImpsConstants.PRESENCE_MOBILE_PHONE);
264         sCodeToCapValue.put("CO", ImpsConstants.PRESENCE_COMPUTER);
265         sCodeToCapValue.put("PD", ImpsConstants.PRESENCE_PDA);
266         sCodeToCapValue.put("CL", ImpsConstants.PRESENCE_CLI);
267         sCodeToCapValue.put("OT", ImpsConstants.PRESENCE_OTHER);
268 
269         for (Entry<String, String> e : sCodeToCapValue.entrySet()) {
e.getValue()270             sCapValueToCode.put(e.getValue(), e.getKey());
271         }
272 
273         // Service Tree <=> code
274         sCodeToServiceTree.put("WV", ImpsTags.WVCSPFeat);
275         sCodeToServiceTree.put("FF", ImpsTags.FundamentalFeat);
276         sCodeToServiceTree.put("PF", ImpsTags.PresenceFeat);
277         sCodeToServiceTree.put("IF", ImpsTags.IMFeat);
278         sCodeToServiceTree.put("GE", ImpsTags.GroupFeat);
279 
280         for (Entry<String, String> e : sCodeToServiceTree.entrySet()) {
e.getValue()281             sServiceTreeToCode.put(e.getValue(), e.getKey());
282         }
283 
sContactListPropsToCode.put(ImpsConstants.DisplayName, "DN")284         sContactListPropsToCode.put(ImpsConstants.DisplayName, "DN");
sContactListPropsToCode.put(ImpsConstants.Default, "DE")285         sContactListPropsToCode.put(ImpsConstants.Default, "DE");
286 
287         // Presence Attribute <=> code. Only include the attributes our client supports
288         sCodeToPresenceAttribute.put("OS", ImpsTags.OnlineStatus);
289         sCodeToPresenceAttribute.put("CF", ImpsTags.ClientInfo);
290         sCodeToPresenceAttribute.put("UA", ImpsTags.UserAvailability);
291         sCodeToPresenceAttribute.put("ST", ImpsTags.StatusText);
292         sCodeToPresenceAttribute.put("SC", ImpsTags.StatusContent);
293         // sub-element of ClientInfo
294         sCodeToPresenceAttribute.put("CT", ImpsTags.ClientType);
295         sCodeToPresenceAttribute.put("CP", ImpsTags.ClientProducer);
296         sCodeToPresenceAttribute.put("CV", ImpsTags.ClientVersion);
297         // sub-element of StatusContent
298         sCodeToPresenceAttribute.put("RC", ImpsTags.ReferredContent);
299         sCodeToPresenceAttribute.put("CY", ImpsTags.ContentType);
300 
301         for (Entry<String, String> e : sCodeToPresenceAttribute.entrySet()) {
e.getValue()302             sPresenceAttributeToCode.put(e.getValue(), e.getKey());
303         }
304 
305         sServerRequestTransactionCode.add(PresenceNotification);
306 
307         // value of UserAvailability
308         sCodeToPAValue.put("AV", ImpsConstants.PRESENCE_AVAILABLE);
309         sCodeToPAValue.put("DI", ImpsConstants.PRESENCE_DISCREET);
310         sCodeToPAValue.put("NA", ImpsConstants.PRESENCE_NOT_AVAILABLE);
311         // value of ClientType
312         sCodeToPAValue.put("MP", ImpsConstants.PRESENCE_MOBILE_PHONE);
313         sCodeToPAValue.put("CO", ImpsConstants.PRESENCE_COMPUTER);
314         sCodeToPAValue.put("PD", ImpsConstants.PRESENCE_PDA);
315         sCodeToPAValue.put("CL", ImpsConstants.PRESENCE_CLI);
316         sCodeToPAValue.put("OT", ImpsConstants.PRESENCE_OTHER);
317 
318         for (Entry<String, String> e : sCodeToPAValue.entrySet()) {
e.getValue()319             sPAValueToCode.put(e.getValue(), e.getKey());
320         }
321     }
322 }
323