3 * This file is part of NixNote
4 * Copyright 2012 Randy Baumgarte
6 * This file may be licensed under the terms of of the
7 * GNU General Public License Version 2 (the ``GPL'').
9 * Software distributed under the License is distributed
10 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
11 * express or implied. See the GPL for the specific language
12 * governing rights and limitations.
14 * You should have received a copy of the GPL along with this
15 * program. If not, go to http://www.gnu.org/licenses/gpl.html
16 * or write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 /* This class is used to parse out the OAuth reply from Evernote */
25 package cx.fbn.nevernote.oauth;
27 import java.util.ArrayList;
29 public class OAuthTokenizer {
31 public String oauth_token;
32 public String edam_shard;
33 public String edam_userId;
34 public String edam_expires;
35 public String edam_noteStoreUrl;
36 public String edam_webApiUrlPrefix;
38 public OAuthTokenizer() {
39 oauth_token = new String();
40 edam_shard = new String();
41 edam_userId = new String();
42 edam_expires = new String();
43 edam_noteStoreUrl = new String();
44 edam_webApiUrlPrefix = new String();
47 public void tokenize(String decoded) {
48 ArrayList<String> tokens = new ArrayList<String>();
49 for (;decoded!=null && decoded.length()>0;) {
50 int i=decoded.indexOf("&");
52 tokens.add(decoded.substring(0,i));
53 decoded=decoded.substring(i+1);
59 System.out.println("Tokens found:" +tokens.size());
60 String oauth_tokenString = "oauth_token=";
61 String edam_shardString = "edam_shard=";
62 String edam_userIdString = "edam_userid=";
63 String edam_expiresString = "edam_expires=";
64 String edam_noteStoreUrlString ="edam_notestoreurl=";
65 String edam_webApiUrlPrefixString = "edam_webapiurlprefix=";
70 edam_noteStoreUrl = "";
71 edam_webApiUrlPrefix = "";
73 for (int i=0; i<tokens.size(); i++) {
74 String token = tokens.get(i);
75 if (token.toLowerCase().startsWith(oauth_tokenString)) {
76 oauth_token = token.substring(oauth_tokenString.length());
78 if (token.toLowerCase().startsWith(edam_shardString)) {
79 edam_shard = token.substring(edam_shardString.length());
81 if (token.toLowerCase().startsWith(edam_userIdString)) {
82 edam_userId = token.substring(edam_userIdString.length());
84 if (token.toLowerCase().startsWith(edam_expiresString)) {
85 edam_expires = token.substring(edam_expiresString.length());
87 if (token.toLowerCase().startsWith(edam_noteStoreUrlString)) {
88 edam_noteStoreUrl = token.substring(edam_noteStoreUrlString.length());
90 if (token.toLowerCase().startsWith(edam_webApiUrlPrefixString)) {
91 edam_webApiUrlPrefix = token.substring(edam_webApiUrlPrefixString.length());