PtsCodes.java
上传用户:szyujian
上传日期:2016-09-20
资源大小:320k
文件大小:15k
源码类别:

android开发

开发平台:

C/C++

  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. package com.android.im.imps;
  18. import java.util.ArrayList;
  19. import java.util.HashMap;
  20. import java.util.Map.Entry;
  21. public class PtsCodes {
  22.     private PtsCodes() {
  23.     }
  24.     private static HashMap<String, String> sCodeToTransaction = new HashMap<String, String>();
  25.     private static HashMap<String, String> sCodeToElement = new HashMap<String, String>();
  26.     private static HashMap<String, String> sCodeToCapElement = new HashMap<String, String>();
  27.     private static HashMap<String, String> sCodeToCapValue= new HashMap<String, String>();
  28.     private static HashMap<String, String> sCodeToServiceTree = new HashMap<String, String>();
  29.     private static HashMap<String, String> sCodeToPresenceAttribute = new HashMap<String, String>();
  30.     private static HashMap<String, String> sTransactionToCode = new HashMap<String, String>();
  31.     private static HashMap<String, String> sElementToCode = new HashMap<String, String>();
  32.     /*package*/ static HashMap<String, String> sCapElementToCode = new HashMap<String, String>();
  33.     /*package*/ static HashMap<String, String> sCapValueToCode= new HashMap<String, String>();
  34.     private static HashMap<String, String> sServiceTreeToCode = new HashMap<String, String>();
  35.     static HashMap<String, String> sContactListPropsToCode = new HashMap<String, String>();
  36.     private static HashMap<String, String> sPresenceAttributeToCode = new HashMap<String, String>();
  37.     private static ArrayList<String> sServerRequestTransactionCode = new ArrayList<String>();
  38.     private static HashMap<String, String> sCodeToPAValue = new HashMap<String, String>();
  39.     private static HashMap<String, String> sPAValueToCode = new HashMap<String, String>();
  40.     public static String getTransaction(String type) {
  41.         // not case sensitive
  42.         return sCodeToTransaction.get(type.toUpperCase());
  43.     }
  44.     public static String getElement(String type) {
  45.         // not case sensitive
  46.         return sCodeToElement.get(type.toUpperCase());
  47.     }
  48.     public static String getCapElement(String type) {
  49.         // not case sensitive
  50.         return sCodeToCapElement.get(type.toUpperCase());
  51.     }
  52.     public static String getCapValue(String type) {
  53.         // not case sensitive
  54.         return sCodeToCapValue.get(type.toUpperCase()) == null ?
  55.                 type : sCodeToCapValue.get(type.toUpperCase());
  56.     }
  57.     public static String getServiceTreeValue(String type) {
  58.         // not case sensitive
  59.         return sCodeToServiceTree.get(type.toUpperCase());
  60.     }
  61.     public static String getTxCode(String txType) {
  62.         return sTransactionToCode.get(txType);
  63.     }
  64.     public static String getElementCode(String elemType, String transactionType) {
  65.         if (ImpsTags.PresenceSubList.equals(elemType)) {
  66.             return ImpsTags.UpdatePresence_Request.equals(transactionType) ? "UV" : "PS";
  67.         }
  68.         return sElementToCode.get(elemType);
  69.     }
  70.     public static String getCapElementCode(String elemType) {
  71.         return sCapElementToCode.get(elemType);
  72.     }
  73.     public static String getCapValueCode(String value) {
  74.         return sCapValueToCode.get(value);
  75.     }
  76.     public static String getServiceTreeCode(String elemType) {
  77.         return sServiceTreeToCode.get(elemType);
  78.     }
  79.     public static String getPresenceAttributeCode(String elemType){
  80.         return sPresenceAttributeToCode.get(elemType);
  81.     }
  82.     public static String getPresenceAttributeElement(String code) {
  83.         // not case sensitive
  84.         return sCodeToPresenceAttribute.get(code.toUpperCase());
  85.     }
  86.     public static String getPAValue(String code) {
  87.         // not case sensitive
  88.         String value = sCodeToPAValue.get(code.toUpperCase());
  89.         return value == null ? code : value;
  90.     }
  91.     public static String getPAValueCode(String value) {
  92.         // not case sensitive
  93.         String code = sPAValueToCode.get(value.toUpperCase());
  94.         return code == null ? value : code;
  95.     }
  96.     public static boolean isServerRequestCode(String type) {
  97.         for (String code : sServerRequestTransactionCode) {
  98.             if (code.equals(type)) {
  99.                 return true;
  100.             }
  101.         }
  102.         return false;
  103.     }
  104.     // Fundamental primitives and transactions
  105.     public static final String ClientCapability_Response    = "PC";
  106.     public static final String Disconnect                   = "DI";
  107. //    public static final String GetList_Request              = "GL";
  108.     public static final String GetList_Response             = "LG";
  109. //    public static final String KeepAlive_Request            = "KA";
  110.     public static final String KeepAlive_Response           = "AK";
  111.     public static final String Login_Response               = "RL";
  112. //    public static final String Logout_Request               = "OR";
  113. //    public static final String Polling_Request              = "PO";
  114. //    public static final String Service_Request              = "SQ";
  115.     public static final String Service_Response             = "QS";
  116.     public static final String Status                       = "ST";   // the same for the element "Status"
  117.     public static final String ListManage_Response          = "ML";
  118.     public static final String PresenceNotification         = "PN";
  119.     public static final String GetPresence_Response         = "PG";
  120. //    public static final String Disconnect = "Disconnect";
  121. //    public static final String KeepAlive_Request = "KeepAlive-Request";
  122. //    public static final String KeepAlive_Response = "KeepAlive-Response";
  123. //    public static final String Service_Request = "Service-Request";
  124. //    public static final String Service_Response = "Service-Response";
  125.     // Information elements
  126.     public static final String AllFunctions          = "AF";
  127.     public static final String CapabilityList        = "CA";
  128.     public static final String AgreedCapabilityList  = "AP";
  129.     public static final String CapabilityRequest     = "CR";
  130.     public static final String ClientID              = "CI";
  131.     public static final String ContactList           = "CL";
  132.     public static final String DefaultContactList    = "DC";
  133.     public static final String DigestSchema          = "DI";
  134.     public static final String Nonce                 = "NO";
  135.     public static final String NotAvailableFunctions = "NF";
  136.     public static final String KeepAliveTime         = "KA";
  137.     public static final String SessionID             = "SI";
  138.     public static final String DefaultList           = "DL";
  139.     public static final String UserNickList          = "UN";
  140.     public static final String ContactListProps      = "CP";
  141.     public static final String Presence              = "PR";
  142.     // Contact list properties
  143.     public static final String DisplayName = "DN";
  144.     public static final String Default     = "DE";
  145.     static {
  146.         sTransactionToCode.put(ImpsTags.Login_Request, "LR");
  147.         sTransactionToCode.put(ImpsTags.ClientCapability_Request, "CP");
  148.         sTransactionToCode.put(ImpsTags.Service_Request, "SQ");
  149.         sTransactionToCode.put(ImpsTags.Logout_Request, "OR");
  150.         sTransactionToCode.put(ImpsTags.Status, "ST");
  151.         sTransactionToCode.put(ImpsTags.GetList_Request, "GL");
  152.         sTransactionToCode.put(ImpsTags.CreateList_Request, "CL");
  153.         sTransactionToCode.put(ImpsTags.DeleteList_Request, "DL");
  154.         sTransactionToCode.put(ImpsTags.ListManage_Request, "LM");
  155.         sTransactionToCode.put(ImpsTags.GetPresence_Request, "GP");
  156.         sTransactionToCode.put(ImpsTags.SubscribePresence_Request, "SB");
  157.         sTransactionToCode.put(ImpsTags.GetBlockedList_Request, "GB");
  158.         sTransactionToCode.put(ImpsTags.CreateAttributeList_Request, "CA");
  159.         sTransactionToCode.put(ImpsTags.Polling_Request, "PO");
  160.         sTransactionToCode.put(ImpsTags.UpdatePresence_Request, "UP");
  161.         sElementToCode.put(ImpsTags.ClientID, ClientID);
  162.         sElementToCode.put(ImpsTags.Password, "PW");
  163.         sElementToCode.put(ImpsTags.SessionCookie, "SC");
  164.         sElementToCode.put(ImpsTags.TimeToLive, "TL");
  165.         sElementToCode.put(ImpsTags.UserID, "UI");
  166.         sElementToCode.put(ImpsTags.CapabilityList, CapabilityList);
  167.         sElementToCode.put(ImpsTags.Functions, "RF");
  168.         sElementToCode.put(ImpsTags.AllFunctionsRequest, "AR");
  169.         sElementToCode.put(ImpsTags.Result, "ST");
  170.         sElementToCode.put(ImpsTags.ContactList, "CL");
  171.         sElementToCode.put(ImpsTags.NickList, "UN");
  172.         sElementToCode.put(ImpsTags.AddNickList, "AN");
  173.         sElementToCode.put(ImpsTags.RemoveNickList, "RN");
  174.         sElementToCode.put(ImpsTags.ContactListProperties, "CP");
  175.         sElementToCode.put(ImpsTags.ReceiveList, "RL");
  176.         sElementToCode.put(ImpsTags.PresenceSubList, "PS");
  177.         sElementToCode.put(ImpsTags.DefaultList, DefaultList);
  178.         sElementToCode.put(ImpsTags.AutoSubscribe, "AS");
  179.         sCodeToTransaction.put(ClientCapability_Response, ImpsTags.ClientCapability_Response);
  180.         sCodeToTransaction.put(Disconnect, ImpsTags.Disconnect);
  181.         sCodeToTransaction.put(GetList_Response, ImpsTags.GetList_Response);
  182.         sCodeToTransaction.put(KeepAlive_Response, ImpsTags.KeepAlive_Response);
  183.         sCodeToTransaction.put(Login_Response, ImpsTags.Login_Response);
  184.         sCodeToTransaction.put(Service_Response, ImpsTags.Service_Response);
  185.         sCodeToTransaction.put(Status, ImpsTags.Status);
  186.         sCodeToTransaction.put(ListManage_Response, ImpsTags.ListManage_Response);
  187.         sCodeToTransaction.put(PresenceNotification, ImpsTags.PresenceNotification_Request);
  188.         sCodeToTransaction.put(GetPresence_Response, ImpsTags.GetPresence_Response);
  189.         sCodeToElement.put(AllFunctions, ImpsTags.AllFunctions);
  190.         sCodeToElement.put(CapabilityList, ImpsTags.CapabilityList);
  191.         sCodeToElement.put(CapabilityRequest, ImpsTags.CapabilityRequest);
  192.         sCodeToElement.put(ClientID, ImpsTags.ClientID);
  193.         sCodeToElement.put(ContactList, ImpsTags.ContactList);
  194.         sCodeToElement.put(DigestSchema, ImpsTags.DigestSchema);
  195.         sCodeToElement.put(Nonce, ImpsTags.Nonce);
  196.         sCodeToElement.put(NotAvailableFunctions, ImpsTags.NotAvailableFunctions);
  197.         sCodeToElement.put(KeepAliveTime, ImpsTags.KeepAliveTime);
  198.         sCodeToElement.put(SessionID, ImpsTags.SessionID);
  199.         sCodeToElement.put(Status, ImpsTags.Status);
  200.         sCodeToElement.put(DefaultList, ImpsTags.DefaultContactList);
  201.         sCodeToElement.put(UserNickList, ImpsTags.NickList);
  202.         sCodeToElement.put(Presence, ImpsTags.Presence);
  203.         // Capability element <=> code
  204.         sCodeToCapElement.put("CT", ImpsTags.ClientType);
  205.         sCodeToCapElement.put("CI", ImpsTags.CIRHTTPAddress);
  206.         sCodeToCapElement.put("DL", ImpsTags.DefaultLanguage);
  207.         sCodeToCapElement.put("ID", ImpsTags.InitialDeliveryMethod);
  208.         sCodeToCapElement.put("MT", ImpsTags.MultiTrans);
  209.         sCodeToCapElement.put("PS", ImpsTags.ParserSize);
  210.         sCodeToCapElement.put("PM", ImpsTags.ServerPollMin);
  211.         sCodeToCapElement.put("SB", ImpsTags.SupportedBearer);
  212.         sCodeToCapElement.put("SC", ImpsTags.SupportedCIRMethod);
  213.         sCodeToCapElement.put("TA", ImpsTags.TCPAddress);
  214.         sCodeToCapElement.put("TP", ImpsTags.TCPPort);
  215.         sCodeToCapElement.put("UP", ImpsTags.UDPPort);
  216.         for (Entry<String, String> e : sCodeToCapElement.entrySet()) {
  217.             sCapElementToCode.put(e.getValue(), e.getKey());
  218.         }
  219.         // Capability value <=> code
  220.         sCodeToCapValue.put("SS", "SSMS");
  221.         sCodeToCapValue.put("ST", "STCP");
  222.         sCodeToCapValue.put("SU", "SUDP");
  223.         sCodeToCapValue.put("WS", "WAPSMS");
  224.         sCodeToCapValue.put("WU", "WAPUDP");
  225.         // value of ClientType
  226.         sCodeToCapValue.put("MP", ImpsConstants.PRESENCE_MOBILE_PHONE);
  227.         sCodeToCapValue.put("CO", ImpsConstants.PRESENCE_COMPUTER);
  228.         sCodeToCapValue.put("PD", ImpsConstants.PRESENCE_PDA);
  229.         sCodeToCapValue.put("CL", ImpsConstants.PRESENCE_CLI);
  230.         sCodeToCapValue.put("OT", ImpsConstants.PRESENCE_OTHER);
  231.         for (Entry<String, String> e : sCodeToCapValue.entrySet()) {
  232.             sCapValueToCode.put(e.getValue(), e.getKey());
  233.         }
  234.         // Service Tree <=> code
  235.         sCodeToServiceTree.put("WV", ImpsTags.WVCSPFeat);
  236.         sCodeToServiceTree.put("FF", ImpsTags.FundamentalFeat);
  237.         sCodeToServiceTree.put("PF", ImpsTags.PresenceFeat);
  238.         sCodeToServiceTree.put("IF", ImpsTags.IMFeat);
  239.         sCodeToServiceTree.put("GE", ImpsTags.GroupFeat);
  240.         for (Entry<String, String> e : sCodeToServiceTree.entrySet()) {
  241.             sServiceTreeToCode.put(e.getValue(), e.getKey());
  242.         }
  243.         sContactListPropsToCode.put(ImpsConstants.DisplayName, "DN");
  244.         sContactListPropsToCode.put(ImpsConstants.Default, "DE");
  245.         // Presence Attribute <=> code. Only include the attributes our client supports
  246.         sCodeToPresenceAttribute.put("OS", ImpsTags.OnlineStatus);
  247.         sCodeToPresenceAttribute.put("CF", ImpsTags.ClientInfo);
  248.         sCodeToPresenceAttribute.put("UA", ImpsTags.UserAvailability);
  249.         sCodeToPresenceAttribute.put("ST", ImpsTags.StatusText);
  250.         sCodeToPresenceAttribute.put("SC", ImpsTags.StatusContent);
  251.         // sub-element of ClientInfo
  252.         sCodeToPresenceAttribute.put("CT", ImpsTags.ClientType);
  253.         sCodeToPresenceAttribute.put("CP", ImpsTags.ClientProducer);
  254.         sCodeToPresenceAttribute.put("CV", ImpsTags.ClientVersion);
  255.         // sub-element of StatusContent
  256.         sCodeToPresenceAttribute.put("RC", ImpsTags.ReferredContent);
  257.         sCodeToPresenceAttribute.put("CY", ImpsTags.ContentType);
  258.         for (Entry<String, String> e : sCodeToPresenceAttribute.entrySet()) {
  259.             sPresenceAttributeToCode.put(e.getValue(), e.getKey());
  260.         }
  261.         sServerRequestTransactionCode.add(PresenceNotification);
  262.         // value of UserAvailability
  263.         sCodeToPAValue.put("AV", ImpsConstants.PRESENCE_AVAILABLE);
  264.         sCodeToPAValue.put("DI", ImpsConstants.PRESENCE_DISCREET);
  265.         sCodeToPAValue.put("NA", ImpsConstants.PRESENCE_NOT_AVAILABLE);
  266.         // value of ClientType
  267.         sCodeToPAValue.put("MP", ImpsConstants.PRESENCE_MOBILE_PHONE);
  268.         sCodeToPAValue.put("CO", ImpsConstants.PRESENCE_COMPUTER);
  269.         sCodeToPAValue.put("PD", ImpsConstants.PRESENCE_PDA);
  270.         sCodeToPAValue.put("CL", ImpsConstants.PRESENCE_CLI);
  271.         sCodeToPAValue.put("OT", ImpsConstants.PRESENCE_OTHER);
  272.         for (Entry<String, String> e : sCodeToPAValue.entrySet()) {
  273.             sPAValueToCode.put(e.getValue(), e.getKey());
  274.         }
  275.     }
  276. }