Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

280819_0445PM_addingChangesFromCn1 #31

Merged
merged 20 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5c49795
Minor javadoc fix
shai-almog Aug 26, 2019
350a567
Merge branch 'master' of https://github.com/codenameone/CodenameOne
shai-almog Aug 26, 2019
3712f1f
Updated Javadocs
shai-almog Aug 27, 2019
a1f864e
Fixed ant target
shai-almog Aug 27, 2019
36ca20d
Debugging
shai-almog Aug 27, 2019
e855291
Fixed build jenkins
shai-almog Aug 27, 2019
ada117b
Added sample to show infinite progress with a status message. This s…
shannah Aug 27, 2019
30b517c
Merge branch 'master' of https://github.com/codenameone/CodenameOne
shannah Aug 27, 2019
d9812de
Fixed consistency of adding listeners to MultiButton so that they are…
shannah Aug 27, 2019
712bfe7
Added support for additional date formats when parsing cookie expires…
shannah Aug 27, 2019
a7dee3d
Added removeActionListener method to ComponentSelector. Added suppor…
shannah Aug 27, 2019
400618d
Changed new methods in AsyncResource to take generics as parameters.
shannah Aug 27, 2019
caabf11
Temporary comment out so unit tests pass again.
shannah Aug 27, 2019
7f1579e
Added Jenkinsfile
shai-almog Aug 28, 2019
8daa268
JavaDoc script build improvements
shai-almog Aug 28, 2019
681c7b8
Merge branch 'master' of https://github.com/codenameone/CodenameOne
shai-almog Aug 28, 2019
b2a7b04
Fixes for javadoc
shai-almog Aug 28, 2019
f0a0533
Fixed designer build
shai-almog Aug 28, 2019
daf5cf8
Some improvements to OAuth2 and Login (GoogleConnect and FaceBookConn…
shannah Aug 28, 2019
d9934e2
Merge branch 'master' of https://github.com/codenameone/CodenameOne
shannah Aug 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CodenameOne/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<exclude name="*.java"/>
</fileset>
</javadoc -->
<exec executable="./build_javadoc.sh" />
<exec executable="./build_javadoc.sh" failonerror="false" />

<copy todir="${dist.javadoc.dir}">
<fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
Expand Down
4 changes: 2 additions & 2 deletions CodenameOne/build_javadoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

rm -Rf dist/javadoc
rm -Rf build/tempJavaSources
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java -jar ~/dev/java/JavaDocSourceEmbed/target/JavaDocSourceEmbed-1.0-SNAPSHOT.jar src build/tempJavaSources
java -jar ~/dev/java/JavaDocSourceEmbed/target/JavaDocSourceEmbed-1.0-SNAPSHOT.jar src build/tempJavaSources

/usr/bin/find build/tempJavaSources ../Ports/CLDC11/src -name "*.java" | /usr/bin/grep -v /impl/ | /usr/bin/xargs /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/javadoc -protected -d dist/javadoc -windowtitle "Codename One API"
/usr/bin/find build/tempJavaSources ../Ports/CLDC11/src -name "*.java" | /usr/bin/grep -v /impl/ | /usr/bin/xargs javadoc --allow-script-in-comments -protected -d dist/javadoc -windowtitle "Codename One API"
2 changes: 1 addition & 1 deletion CodenameOne/src/cn1-version-numbers
Original file line number Diff line number Diff line change
@@ -1 +1 @@
84645abedcc66dc23771c32e03b70672c5e1b289
350a567089eed73a23f7666d5385e64ced67002d
53 changes: 53 additions & 0 deletions CodenameOne/src/com/codename1/components/MultiButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public MultiButton(String line1) {
*/
public MultiButton() {
setLayout(new BorderLayout());
setFocusable(true);
BorderLayout bl = new BorderLayout();
//bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
Container iconContainer = new Container(bl);
Expand Down Expand Up @@ -203,6 +204,58 @@ public void addActionListener(ActionListener al) {
public void removeActionListener(ActionListener al) {
emblem.removeActionListener(al);
}

/**
* {@inheritDoc }
* @param l
*/
@Override
public void addLongPressListener(ActionListener l) {
emblem.addLongPressListener(l);
}

/**
* {@inheritDoc}
* @param l
*/
@Override
public void removeLongPressListener(ActionListener l) {
emblem.removeLongPressListener(l);
}

/**
* {@inheritDoc}
* @param l
*/
@Override
public void addPointerPressedListener(ActionListener l) {
emblem.addPointerPressedListener(l);
}

/**
* {@inheritDoc}
* @param l
*/
@Override
public void removePointerPressedListener(ActionListener l) {
emblem.removePointerPressedListener(l);
}

/**
* {@inheritDoc}
* @param l
*/
public void addPointerReleasedListener(ActionListener l) {
emblem.addPointerReleasedListener(l);
}

/**
* {@inheritDoc}
* @param l
*/
public void removePointerReleasedListener(ActionListener l) {
emblem.removePointerReleasedListener(l);
}

/**
* Sets the command for the component, it doesn't affe
Expand Down
136 changes: 135 additions & 1 deletion CodenameOne/src/com/codename1/io/AccessToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Date;
import com.codename1.compat.java.util.Objects;
import com.codename1.util.DateUtil;

/**
* This class represent an access token.
Expand All @@ -37,17 +39,52 @@ public class AccessToken implements Externalizable{

private String token;

/**
* When the token expires. Generally this is a numeric string obtained
* from the "expires" token of an oauth2 request, signifying the number of seconds
* from the time of issue that the token is valid for.
*/
private String expires;

/**
* The expiry date of the token. Prefer this value over the {@link #expires} value
* since the expires value may just be the number of seconds that the access token is good
* for since it was generated - and we may not have that information stored.
* @since 7.0
*/
private Date expiryDate;

/**
* Constructor with parameters
*
* @param token the token string
* @param expires the access token expires date
* @deprecated Use {@link #AccessToken(java.lang.String, java.util.Date) }
*/
public AccessToken(String token, String expires) {
this.token = token;
this.expires = expires;
this.expiryDate = parseDate(expires);
}

/**
*
* @param Token The token.
* @param expiryDate The expiry date.
* @since 7.0
*/
public static AccessToken createWithExpiryDate(String token, Date expiryDate) {
AccessToken out = new AccessToken(token, null);

out.expiryDate = expiryDate;
return out;
}

/**
* @since 7.0
*/
public AccessToken() {

}

/**
Expand All @@ -68,26 +105,123 @@ public String getExpires() {

@Override
public int getVersion() {
return 1;
return 2;
}

@Override
public void externalize(DataOutputStream out) throws IOException {
Util.writeUTF(token, out);
Util.writeUTF(expires, out);
Util.writeObject(expiryDate, out);
}

@Override
public void internalize(int version, DataInputStream in) throws IOException {
token = Util.readUTF(in);
expires = Util.readUTF(in);
if (version >= 2) {
expiryDate = (Date)Util.readObject(in);
}
}

@Override
public String getObjectId() {
return "AccessToken";
}

@Override
public boolean equals(Object obj) {
if (obj instanceof AccessToken) {
AccessToken tok = (AccessToken)obj;
return Objects.equals(token, tok.token) && Objects.equals(expiryDate, tok.expiryDate) ;
}
return super.equals(obj);
}

@Override
public int hashCode() {
int hash = 3;
hash = 53 * hash + (this.token != null ? this.token.hashCode() : 0);
hash = 53 * hash + (this.expiryDate != null ? this.expiryDate.hashCode() : 0);
return hash;
}

/**
* Parses an integer value as a string. Automatically truncates at first
* decimal place.
* @param str A numeric string
* @return The Long value of the string, or null if it couldn't be parsed.
*/
private static Long parseLong(String str) {
if (str == null) {
return null;
}
int decimalPos = str.indexOf('.');
if (decimalPos >= 0) {
str = str.substring(0, decimalPos);
}

char[] chars = str.toCharArray();
int len = chars.length;

for (int i=0; i<len; i++) {
char c = chars[i];
if (!Character.isDigit(c)) {
return null;
}
}
return new Long(Long.parseLong(str));
}

/**
* A utility function that can parse date values received as a string.
* Most often these dates are just numbers of seconds as received from
* "expires" oauth2 tokens, which indicate the number of seconds an access
* token is valid for.
* @param dateStr The date string. Value inputs include "3600", "3600.0", "7200.12345", etc..
* @return A Date, or null if the input can't be parsed.
*/
private static Date parseDate(String dateStr) {
Long longExpires = parseLong(dateStr);
if (longExpires != null) {
// There was an expiry date, but it might have been from an expires_in
// header, which would only hold the number of seconds since
long l = longExpires.longValue();
if (l == 0l) {
return null;
}
return new Date(System.currentTimeMillis() + l * 1000l);
}
return null;

}

/**
* Gets the expiry date of this token.
* @return The expiry date of this token or null.
* @since 7.0
*/
public Date getExpiryDate() {
return expiryDate;
}

/**
* Sets the expiry date of this token.
* @param date The expiry date of this token.
* @since 7.0
*/
public void setExpiryDate(Date date) {
this.expiryDate = date;
}

/**
* Checks to see if this token is expired.
* @return False if no expiry date is set or the expiryDate is before the current time.
* @since 7.0
*/
public boolean isExpired() {
return expiryDate != null && DateUtil.compare(expiryDate, new Date()) < 0;
}


}
4 changes: 3 additions & 1 deletion CodenameOne/src/com/codename1/io/ConnectionRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,9 @@ private Cookie parseCookieHeader(String h) {
"EEE, dd-MMM-yy HH:mm:ss Z",
"EEE dd-MMM-yy HH:mm:ss Z",
"EEE, dd MMM yy HH:mm:ss Z",
"EEE dd MMM yy HH:mm:ss Z"
"EEE dd MMM yy HH:mm:ss Z",
"dd-MMM-yy HH:mm:ss z",
"EEE, dd-MMM-yy HH:mm:ss z"
);
if (dt != null) {
c.setExpires(dt.getTime());
Expand Down
14 changes: 12 additions & 2 deletions CodenameOne/src/com/codename1/io/Oauth2.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static void setBackToParent(boolean aBackToParent) {
}
private String token;
private static String expires;

private String clientId;
private String redirectURI;
private String scope;
Expand Down Expand Up @@ -291,32 +292,41 @@ private void handleURL(String url, WebBrowser web, final ActionListener al, fina
protected void readResponse(InputStream input) throws IOException {
byte[] tok = Util.readInputStream(input);
String t = new String(tok);

boolean expiresRelative = true;
if(t.startsWith("{")){
JSONParser p = new JSONParser();
Map map = p.parseJSON(new StringReader(t));
token = (String) map.get("access_token");
Object ex = map.get("expires_in");
if(ex == null){
ex = map.get("expires");
ex = map.get("expires");
expiresRelative = false;
}
if(ex != null){
expires = ex.toString();
if (expiresRelative) {
expires = String.valueOf(System.currentTimeMillis() + new Double(Double.parseDouble(expires) * 1000).longValue());
}
}
}else{
token = t.substring(t.indexOf("=") + 1, t.indexOf("&"));
int off = t.indexOf("expires=");
int start = 8;
expiresRelative = false;
if(off == -1){
off = t.indexOf("expires_in=");
start = 11;
expiresRelative = true;
}
if (off > -1) {
int end = t.indexOf('&', off);
if (end < 0 || end < off) {
end = t.length();
}
expires = t.substring(off + start, end);
if (expiresRelative) {
expires = String.valueOf(System.currentTimeMillis() + new Double(Double.parseDouble(expires) * 1000).longValue());
}
}
}
if (login != null) {
Expand Down
Loading