Skip to content

Commit

Permalink
Merge pull request #18 from AugustNagro/gus-entry-setters
Browse files Browse the repository at this point in the history
Added Expiration Time Setters
  • Loading branch information
jorabin authored Jan 24, 2018
2 parents dcc3dab + b9232a4 commit 8b469ca
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
8 changes: 8 additions & 0 deletions database/src/main/java/org/linguafranca/pwdb/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,15 @@ interface Matcher {

boolean getExpires();

void setExpires(boolean expires);

Date getExpiryTime();

/**
* Sets the expiration date of this element. See {@link org.linguafranca.pwdb.Entry#setExpires(boolean)}
* @throws IllegalArgumentException if expiryTime is null.
*/
void setExpiryTime(Date expiryTime) throws IllegalArgumentException;

Date getLastModificationTime();
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ public boolean getExpires() {
return content != null && content.equalsIgnoreCase("true");
}

@Override
public void setExpires(boolean expires) {
DomHelper.setElementContent(DomHelper.EXPIRES_ELEMENT_NAME, element, expires ? "True" : "False");
}

@Override
public Date getExpiryTime() {
try {
Expand All @@ -189,6 +194,13 @@ public Date getExpiryTime() {
}
}

@Override
public void setExpiryTime(Date expiryTime) throws IllegalArgumentException {
if (expiryTime == null) throw new IllegalArgumentException("expiryTime may not be null");
String formatted = DomHelper.dateFormatter.format(expiryTime);
DomHelper.setElementContent(DomHelper.EXPIRY_TIME_ELEMENT_NAME, element, formatted);
}

@Override
public Date getLastModificationTime() {
try {
Expand Down
11 changes: 11 additions & 0 deletions jaxb/src/main/java/org/linguafranca/pwdb/kdbx/jaxb/JaxbEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,22 @@ public boolean getExpires() {
return delegate.getTimes().getExpires();
}

@Override
public void setExpires(boolean expires) {
delegate.getTimes().setExpires(true);
}

@Override
public Date getExpiryTime() {
return delegate.getTimes().getExpiryTime();
}

@Override
public void setExpiryTime(Date expiryTime) throws IllegalArgumentException {
if (expiryTime == null) throw new IllegalArgumentException("expiryTime may not be null");
delegate.getTimes().setExpiryTime(expiryTime);
}

@Override
public Date getLastModificationTime() {
return delegate.getTimes().getLastModificationTime();
Expand Down
11 changes: 9 additions & 2 deletions kdb/src/main/java/org/linguafranca/pwdb/kdb/KdbEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class KdbEntry extends AbstractEntry<KdbDatabase, KdbGroup, KdbEntry, Kdb
private Date creationTime = new Date();
private Date lastModificationTime = new Date();
private Date lastAccessTime = new Date(Long.MIN_VALUE);
private boolean expires = false;
private Date expiryTime = new Date(Long.MAX_VALUE);
private String binaryDescription = "";
private byte[] binaryData = new byte[0];
Expand Down Expand Up @@ -174,7 +175,8 @@ public Date getLastAccessTime() {
return lastAccessTime;
}

void setExpiryTime(Date expiryTime) {
public void setExpiryTime(Date expiryTime) {
if (expiryTime == null) throw new IllegalArgumentException("expiryTime may not be null");
this.expiryTime = expiryTime;
}

Expand Down Expand Up @@ -223,9 +225,14 @@ public List<String> getBinaryPropertyNames() {
throw new UnsupportedOperationException();
}

@Override
public void setExpires(boolean expires) {
this.expires = expires;
}

@Override
public boolean getExpires() {
return false;
return expires;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,22 @@ public boolean getExpires() {
return times.getExpires();
}

@Override
public void setExpires(boolean expires) {
times.setExpires(expires);
}

@Override
public Date getExpiryTime() {
return times.getExpiryTime();
}

@Override
public void setExpiryTime(Date expiryTime) throws IllegalArgumentException {
if (expiryTime == null) throw new IllegalArgumentException("expiryTime may not be null");
times.setExpiryTime(expiryTime);
}

@Override
public Date getLastModificationTime() {
return times.getLastModificationTime();
Expand Down

0 comments on commit 8b469ca

Please sign in to comment.