Skip to content

Commit 37e2fff

Browse files
author
Devendra
committed
refactoring for json abstraction
1 parent 054f267 commit 37e2fff

75 files changed

Lines changed: 941 additions & 213 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎android/Pubnub-Android-3.7.3.jar‎

3.14 KB
Binary file not shown.

‎android/build.xml‎

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<loadfile property="VERSION" srcFile="../VERSION"><filterchain><striplinebreaks/></filterchain></loadfile>
55
<property name="pubnub_lib_jar" value="Pubnub-Android-${VERSION}.jar"/>
66
<property name="pubnub_debug_lib_jar" value="Pubnub-Android-Debug-${VERSION}.jar"/>
7+
<property name="pubnub_gson_lib_jar" value="Pubnub-Android-Gson-${VERSION}.jar"/>
8+
<property name="pubnub_gson_debug_lib_jar" value="Pubnub-Android-Gson-Debug-${VERSION}.jar"/>
79
<property name="java_core_path" value="../java"/>
810
<property name="src_pubnub_api_path" value="${java_core_path}/srcPubnubApi"/>
911
<property name="src_java_path" value="${java_core_path}/src1"/>
@@ -18,10 +20,12 @@
1820
<property name="sources_pubnub_java1" value="../java/src1/com/pubnub/api"/>
1921
<property name="sources_pubnub_java" value="src/com/pubnub/api"/>
2022
<property name="sources_pubnub_crypto" value="srcCrypto/com/pubnub/api"/>
23+
<property name="sources_pubnub_json" value="../java/srcJson/com/pubnub/api"/>
24+
<property name="sources_pubnub_json2" value="../java/srcJson2/com/pubnub/api"/>
25+
<property name="sources_pubnub_gson" value="../java/srcGson/com/pubnub/api"/>
2126

2227
<path id="PubnubApi.classpath">
23-
<pathelement location="bin"/>
24-
<pathelement location="../java/libs/bcprov-jdk15on-1.47.jar"/>
28+
<pathelement location="../java/libs/gson-2.3.1.jar"/>
2529
<pathelement location="libs/android-8.jar"/>
2630
</path>
2731

@@ -32,6 +36,7 @@
3236
<path id="classpath">
3337
<pathelement location="bin"/>
3438
<pathelement location="${java_core_path}/libs/bcprov-jdk15on-1.47.jar"/>
39+
<pathelement location="${java_core_path}/libs/gson-2.3.1.jar"/>
3540
<pathelement location="libs/android-8.jar"/>
3641
</path>
3742
<target name="test" />
@@ -66,6 +71,23 @@
6671
<copy file="${pubnub_lib_jar}" todir="./examples/SubscribeAtBoot/libs/"/>
6772
</target>
6873

74+
<target name="build-gson" depends="clean">
75+
<delete file="${pubnub_gson_lib_jar}"/>
76+
<antcall target="create-jar-gson">
77+
<param name="jar_name" value="${pubnub_gson_lib_jar}" />
78+
<param name="debug" value="false" />
79+
</antcall>
80+
</target>
81+
82+
<target name="debug-build-gson" depends="clean">
83+
<delete file="${pubnub_gson_debug_lib_jar}"/>
84+
<antcall target="setDebugTrue" />
85+
<antcall target="create-jar-gson">
86+
<param name="jar_name" value="${pubnub_gson_debug_lib_jar}" />
87+
<param name="debug" value="true" />
88+
</antcall>
89+
<antcall target="unsetDebugTrue" />
90+
</target>
6991

7092
<target name="build" depends="clean">
7193
<delete file="${pubnub_lib_jar}"/>
@@ -91,6 +113,13 @@
91113
/>
92114
</target>
93115

116+
<target depends="build-project-gson" name="create-jar-gson">
117+
<jar destfile="${jar_name}"
118+
basedir="bin"
119+
includes="**/**"
120+
/>
121+
</target>
122+
94123
<target depends="init" name="build-project">
95124
<echo message="${ant.project.name}: ${ant.file}"/>
96125
<replace dir="${src_pubnub_api_path}" token='static String VERSION = ""' value='static String VERSION = "${VERSION}"' >
@@ -102,13 +131,33 @@
102131
<src path="${src_logging_path}"/>
103132
<src path="${src_android_path}"/>
104133
<src path="${src_crypto_path}"/>
134+
<src path="${sources_pubnub_json}" />
135+
<src path="${sources_pubnub_json2}" />
105136
<classpath refid="classpath"/>
106137
</javac>
107138
<replace dir="${src_pubnub_api_path}" token='static String VERSION = "${VERSION}"' value='static String VERSION = ""'>
108139
<include name="**/*.java"/>
109140
</replace>
110141
</target>
111142

143+
<target depends="init" name="build-project-gson">
144+
<echo message="${ant.project.name}: ${ant.file}"/>
145+
<replace dir="${src_pubnub_api_path}" token='static String VERSION = ""' value='static String VERSION = "${VERSION}"' >
146+
<include name="**/*.java"/>
147+
</replace>
148+
<javac debug="${debug}" destdir="bin" source="${source}" target="${target}">
149+
<src path="${src_pubnub_api_path}"/>
150+
<src path="${src_java_path}"/>
151+
<src path="${src_logging_path}"/>
152+
<src path="${src_android_path}"/>
153+
<src path="${src_crypto_path}"/>
154+
<src path="${sources_pubnub_gson}" />
155+
<classpath refid="classpath"/>
156+
</javac>
157+
<replace dir="${src_pubnub_api_path}" token='static String VERSION = "${VERSION}"' value='static String VERSION = ""'>
158+
<include name="**/*.java"/>
159+
</replace>
160+
</target>
112161

113162

114163
<property name="src" location="src" />
@@ -207,6 +256,8 @@
207256
<fileset dir="${sources_pubnub_logging}" />
208257
<fileset dir="${sources_pubnub_api}" />
209258
<fileset dir="${sources_pubnub_crypto}" />
259+
<fileset dir="${sources_pubnub_json}" />
260+
<fileset dir="${sources_pubnub_json2}" />
210261
</copy>
211262
<mkdir dir="${dist}/lib" />
212263
<antcall target="stage"/>
@@ -222,6 +273,7 @@
222273
<fileset dir="${sources_pubnub_java1}" />
223274
<fileset dir="${sources_pubnub_logging}" />
224275
<fileset dir="${sources_pubnub_api}" />
276+
<fileset dir="${sources_pubnub_json}" />
225277
</copy>
226278
<replace dir="${maven}/src" token="boolean LOGGING = false" value="boolean LOGGING = true">
227279
<include name="**/*.java"/>
3.14 KB
Binary file not shown.
3.14 KB
Binary file not shown.

‎android/src/com/pubnub/api/Pubnub.java‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
import org.json.JSONException;
88

99
/**
10-
* Pubnub object facilitates querying channels for messages and listening on
10+
* PubnubPlatform object facilitates querying channels for messages and listening on
1111
* channels for presence/message events
1212
*
1313
* @author Pubnub
1414
*
1515
*/
1616

17-
public class Pubnub extends PubnubCoreShared {
17+
class PubnubPlatform extends PubnubCoreShared {
1818

1919
/**
20-
* Pubnub Constructor
20+
* PubnubPlatform Constructor
2121
*
2222
* @param publish_key
2323
* Publish Key
@@ -30,13 +30,13 @@ public class Pubnub extends PubnubCoreShared {
3030
* @param ssl_on
3131
* SSL on ?
3232
*/
33-
public Pubnub(String publish_key, String subscribe_key, String secret_key,
33+
public PubnubPlatform(String publish_key, String subscribe_key, String secret_key,
3434
String cipher_key, boolean ssl_on) {
3535
super(publish_key, subscribe_key, secret_key, cipher_key, ssl_on);
3636
}
3737

3838
/**
39-
* Pubnub Constructor
39+
* PubnubPlatform Constructor
4040
*
4141
* @param publish_key
4242
* Publish key
@@ -47,20 +47,20 @@ public Pubnub(String publish_key, String subscribe_key, String secret_key,
4747
* @param ssl_on
4848
* SSL on ?
4949
*/
50-
public Pubnub(String publish_key, String subscribe_key, String secret_key,
50+
public PubnubPlatform(String publish_key, String subscribe_key, String secret_key,
5151
boolean ssl_on) {
5252
super(publish_key, subscribe_key, secret_key, "", ssl_on);
5353
}
5454

5555
/**
56-
* Pubnub Constructor
56+
* PubnubPlatform Constructor
5757
*
5858
* @param publish_key
5959
* Publish Key
6060
* @param subscribe_key
6161
* Subscribe Key
6262
*/
63-
public Pubnub(String publish_key, String subscribe_key) {
63+
public PubnubPlatform(String publish_key, String subscribe_key) {
6464
super(publish_key, subscribe_key, "", "", false);
6565
}
6666

@@ -71,7 +71,7 @@ public Pubnub(String publish_key, String subscribe_key) {
7171
* Subscribe Key
7272
* @param ssl
7373
*/
74-
public Pubnub(String publish_key, String subscribe_key, boolean ssl) {
74+
public PubnubPlatform(String publish_key, String subscribe_key, boolean ssl) {
7575
super(publish_key, subscribe_key, "", "", ssl);
7676
}
7777

@@ -80,7 +80,7 @@ public Pubnub(String publish_key, String subscribe_key, boolean ssl) {
8080
* @param subscribe_key
8181
* @param secret_key
8282
*/
83-
public Pubnub(String publish_key, String subscribe_key, String secret_key) {
83+
public PubnubPlatform(String publish_key, String subscribe_key, String secret_key) {
8484
super(publish_key, subscribe_key, secret_key, "", false);
8585
}
8686

@@ -90,13 +90,13 @@ public Pubnub(String publish_key, String subscribe_key, String secret_key) {
9090
* @param secret_key
9191
* @param cipher_key
9292
*/
93-
public Pubnub(String publish_key, String subscribe_key, String secret_key, String cipher_key) {
93+
public PubnubPlatform(String publish_key, String subscribe_key, String secret_key, String cipher_key) {
9494
super(publish_key, subscribe_key, secret_key, cipher_key, false);
9595
}
9696

9797
/**
9898
*
99-
* Constructor for Pubnub Class
99+
* Constructor for PubnubPlatform Class
100100
*
101101
* @param publish_key
102102
* Publish Key
@@ -112,7 +112,7 @@ public Pubnub(String publish_key, String subscribe_key, String secret_key, Strin
112112
* Initialization vector
113113
*/
114114

115-
public Pubnub(String publish_key, String subscribe_key,
115+
public PubnubPlatform(String publish_key, String subscribe_key,
116116
String secret_key, String cipher_key, boolean ssl_on, String initialization_vector) {
117117
super(publish_key, subscribe_key, secret_key, cipher_key, ssl_on, initialization_vector);
118118
}
821 Bytes
Binary file not shown.

‎blackberry/build.xml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
<target name="build-all" depends="clean, debug-build, clean, build" />
2222
<target name="deploy-all" />
2323
<target name="setJsonMeJar" >
24-
<replace dir="${srcPubnubApi.link}" token="org.json" value="org.json.me">
24+
<replace dir="../java/srcJson" token="org.json" value="org.json.me">
2525
<include name="**/*.java"/>
2626
</replace>
2727
</target>
2828
<target name="unsetJsonMeJar" >
29-
<replace dir="${srcPubnubApi.link}" token="org.json.me" value="org.json">
29+
<replace dir="../java/srcJson" token="org.json.me" value="org.json">
3030
<include name="**/*.java"/>
3131
</replace>
3232
</target>
@@ -93,6 +93,7 @@
9393
<src path="${j2me.link}/src1"/>
9494
<src path="${j2me.link}/srcLogging"/>
9595
<src path="../java/srcCrypto"/>
96+
<src path="../java/srcJson"/>
9697
<classpath refid="PubnubApi.classpath"/>
9798
</javac>
9899
<replace dir="${srcPubnubApi.link}" token='static String VERSION = "${VERSION}"' value='static String VERSION = ""'>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.pubnub.api;
2+
3+
import org.bouncycastle.util.SecureRandom;
4+
5+
6+
public class PubnubPlatform extends PubnubCore {
7+
8+
public PubnubPlatform(String publish_key, String subscribe_key, String secret_key,
9+
String cipher_key, boolean ssl_on) {
10+
super(publish_key, subscribe_key, secret_key, cipher_key, ssl_on);
11+
}
12+
13+
public PubnubPlatform(String publish_key, String subscribe_key, String secret_key,
14+
boolean ssl_on) {
15+
super(publish_key, subscribe_key, secret_key, "", ssl_on);
16+
}
17+
18+
19+
public PubnubPlatform(String publish_key, String subscribe_key) {
20+
super(publish_key, subscribe_key, "", "", false);
21+
}
22+
23+
public PubnubPlatform(String publish_key, String subscribe_key, boolean ssl) {
24+
super(publish_key, subscribe_key, "", "", ssl);
25+
}
26+
27+
public PubnubPlatform(String publish_key, String subscribe_key, String secret_key) {
28+
super(publish_key, subscribe_key, secret_key, "", false);
29+
}
30+
31+
public PubnubPlatform(String publish_key, String subscribe_key,
32+
String secret_key, String cipher_key, boolean ssl_on, String initialization_vector) {
33+
super(publish_key, subscribe_key, secret_key, cipher_key, ssl_on, initialization_vector);
34+
}
35+
36+
/**
37+
* UUID
38+
*
39+
* 32 digit UUID generation at client side.
40+
*
41+
* @return String uuid.
42+
*/
43+
public String uuid() {
44+
45+
String valueBeforeMD5;
46+
String valueAfterMD5;
47+
SecureRandom mySecureRand = new SecureRandom();
48+
String s_id = String.valueOf(PubnubCore.class.hashCode());
49+
StringBuffer sbValueBeforeMD5 = new StringBuffer();
50+
try {
51+
long time = System.currentTimeMillis();
52+
long rand = 0;
53+
rand = mySecureRand.nextLong();
54+
sbValueBeforeMD5.append(s_id);
55+
sbValueBeforeMD5.append(":");
56+
sbValueBeforeMD5.append(Long.toString(time));
57+
sbValueBeforeMD5.append(":");
58+
sbValueBeforeMD5.append(Long.toString(rand));
59+
valueBeforeMD5 = sbValueBeforeMD5.toString();
60+
byte[] array = PubnubCrypto.md5(valueBeforeMD5);
61+
StringBuffer sb = new StringBuffer();
62+
for (int j = 0; j < array.length; ++j) {
63+
int b = array[j] & 0xFF;
64+
if (b < 0x10) {
65+
sb.append('0');
66+
}
67+
sb.append(Integer.toHexString(b));
68+
}
69+
valueAfterMD5 = sb.toString();
70+
String raw = valueAfterMD5.toUpperCase();
71+
sb = new StringBuffer();
72+
sb.append(raw.substring(0, 8));
73+
sb.append("-");
74+
sb.append(raw.substring(8, 12));
75+
sb.append("-");
76+
sb.append(raw.substring(12, 16));
77+
sb.append("-");
78+
sb.append(raw.substring(16, 20));
79+
sb.append("-");
80+
sb.append(raw.substring(20));
81+
return sb.toString();
82+
} catch (Exception e) {
83+
return null;
84+
}
85+
}
86+
87+
protected String getUserAgent() {
88+
return "Blackberry/" + VERSION;
89+
}
90+
91+
}
63 Bytes
Binary file not shown.
60 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)