-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInputVariables.java
More file actions
160 lines (133 loc) · 4.2 KB
/
UserInputVariables.java
File metadata and controls
160 lines (133 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* Copyright (c) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.oauth;
import java.util.HashMap;
import java.util.Map;
/**
* Container for all user input variables related to the OAuth examples. It
* isn't necessary to understand the details of this class in order to
* understand the OAuth examples.
*
*
*/
public class UserInputVariables {
/** The various Google services enabled in this sample. */
public enum GoogleServiceType {
Blogger,
Calendar,
Contacts,
Finance,
Picasa
}
/** The signature methods supported by OAuth in the Java client. */
public enum SignatureMethod {
HMAC,
RSA
}
/** The service the user is accessing. */
private GoogleServiceType serviceType;
/** The authentication scope of the request. */
private String scope;
/** The feed url of the request. */
private String feedUrl;
/** The Google service name for the request. */
private String googleServiceName;
/** The signature method. */
private SignatureMethod signatureMethod;
/**
* The key to use when signing the request. This is either the private key
* when {@link #signatureMethod} equals RSA, or the consumer secret when
* {@link #signatureMethod} equals HMAC.
*/
private String signatureKey;
/** The OAuth consumer key. */
private String consumerKey;
/** A storage area for other example-specific variables. */
private Map<String, String> otherVars = new HashMap<String, String>();
public String getGoogleServiceName() {
return googleServiceName;
}
public String getFeedUrl() {
return feedUrl;
}
public String getScope() {
return scope;
}
public GoogleServiceType getServiceType() {
return serviceType;
}
public void setConsumerKey(String key) {
consumerKey = key;
}
public String getConsumerKey() {
return consumerKey;
}
public void setSignatureKey(String key) {
this.signatureKey = key;
}
public String getSignatureKey() {
return signatureKey;
}
public void setSignatureMethod(SignatureMethod signatureMethod) {
this.signatureMethod = signatureMethod;
}
public SignatureMethod getSignatureMethod() {
return signatureMethod;
}
public void setVariable(String key, String value) {
otherVars.put(key, value);
}
public String getVariable(String key) {
return otherVars.get(key);
}
/**
* Sets the {@link #scope}, {@link #feedUrl} and {@link #googleServiceName}
* for a given {@link GoogleServiceType}.
*/
public void setGoogleService(GoogleServiceType stype) {
this.serviceType = stype;
switch (stype) {
case Contacts:
scope = "http://www.google.com/m8/feeds/";
feedUrl = "http://www.google.com/m8/feeds/contacts/default/base";
googleServiceName = "cp";
break;
case Calendar:
scope = "http://www.google.com/calendar/feeds/";
feedUrl =
"http://www.google.com/calendar/feeds/default/allcalendars/full";
googleServiceName = "cl";
break;
case Blogger:
scope = "http://www.blogger.com/feeds/";
feedUrl = "http://www.blogger.com/feeds/default/blogs";
googleServiceName = "blogger";
break;
case Finance:
scope = "http://finance.google.com/finance/feeds/";
feedUrl =
"http://finance.google.com/finance/feeds/default/portfolios";
googleServiceName = "finance";
break;
case Picasa:
scope = "http://picasaweb.google.com/data/";
feedUrl = "http://picasaweb.google.com/data/feed/api/user/default";
googleServiceName = "lh2";
break;
default:
throw new IllegalArgumentException("Unsupported Google Service");
}
}
}