View Javadoc

1   package org.astrogrid.community.common.util;
2   
3   
4   /***
5    * Small util class for handling a small snippet of xml to be sent between the systems.
6    * @author Kevin Benson
7    *
8    * To change the template for this generated type comment go to
9    * Window>Preferences>Java>Code Generation>Code and Comments
10   */
11  public class CommunityMessage {
12   
13     /***
14      * returns a snippet of xml.
15      * @param token
16      * @param account
17      * @param credential
18      * @return
19      */
20     public static String getMessage(String token,String account,String credential)  {
21        StringBuffer buff = new StringBuffer(100);
22        buff.append("<community>");
23           buff.append("<token>");
24              buff.append(token);
25           buff.append("</token>");
26           buff.append("<credentials>");
27              buff.append("<account>");
28                 buff.append(account);
29              buff.append("</account>");
30              buff.append("<group>");
31                 buff.append(credential);
32              buff.append("</group>");
33          buff.append("</credentials>");
34        buff.append("</community>");
35  
36        return buff.toString();
37     }   
38     
39     public static String getToken(String xmlMessage) {
40        int index = -1;
41        index = xmlMessage.indexOf("<token>");
42        if(index != -1) {
43           return xmlMessage.substring(index + "<token>".length(),xmlMessage.indexOf("</token>"));
44        }
45        return null;
46     }
47  
48     public static String getAccount(String xmlMessage) {
49        int index = -1;
50        index = xmlMessage.indexOf("<account>");
51        if(index != -1) {
52           return xmlMessage.substring(index + "<account>".length(),xmlMessage.indexOf("</account>"));
53        }
54        return null;
55     }
56  
57     public static String getGroup(String xmlMessage) {
58        int index = -1;
59        index = xmlMessage.indexOf("<group>");
60        if(index != -1) {
61           return xmlMessage.substring(index + "<group>".length(),xmlMessage.indexOf("</group>"));
62        }
63        return null;
64     }   
65  }