Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 20 additions & 5 deletions src/main/java/fr/vidal/oss/jaxb/atom/core/Author.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ public class Author {
private final String name;
@XmlElement
private final String email;
@XmlElement
private final String uri;

@SuppressWarnings("unused") //jaxb
private Author() {
this(null, null);
this(null, null, null);
}

private Author(String name, String email) {
private Author(String name, String email, String uri) {
this.name = name;
this.email = email;
this.uri = uri;
}

public static Builder builder(String name) {
Expand All @@ -34,9 +37,13 @@ public String getEmail() {
return email;
}

public String getUri() {
return uri;
}

@Override
public int hashCode() {
return Objects.hash(name, email);
return Objects.hash(name, email, uri);
}

@Override
Expand All @@ -49,14 +56,16 @@ public boolean equals(Object obj) {
}
final Author other = (Author) obj;
return Objects.equals(this.name, other.name)
&& Objects.equals(this.email, other.email);
&& Objects.equals(this.email, other.email)
&& Objects.equals(this.uri, other.uri);
}

@Override
public String toString() {
return "Author{" +
"name='" + name + '\'' +
", email='" + email + '\'' +
", uri='" + uri + '\'' +
'}';
}

Expand All @@ -65,6 +74,7 @@ public static class Builder {

private final String name;
private String email;
private String uri;

private Builder(String name) {
this.name = name;
Expand All @@ -75,9 +85,14 @@ public Builder withEmail(String email) {
return this;
}

public Builder withUri(String uri) {
this.uri = uri;
return this;
}

public Author build() {
checkState(name != null, "name is mandatory");
return new Author(name, email);
return new Author(name, email, uri);
}
}
}
25 changes: 20 additions & 5 deletions src/main/java/fr/vidal/oss/jaxb/atom/core/Contents.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ public class Contents {

@XmlAttribute(name = "type")
private final ContentType type;
@XmlAttribute(name = "src")
private final String src;
@XmlValue
private final String contents;

//jaxb
private Contents() {
this(null, null);
this(null, null, null);
}

private Contents(ContentType type, String contents) {
private Contents(ContentType type, String contents, String src) {
this.type = type;
this.contents = contents;
this.src = src;
}

public static Builder builder() {
Expand All @@ -35,9 +38,13 @@ public String getContents() {
return contents;
}

public String getSrc() {
return src;
}

@Override
public int hashCode() {
return Objects.hash(type, contents);
return Objects.hash(type, contents, src);
}

@Override
Expand All @@ -50,20 +57,23 @@ public boolean equals(Object obj) {
}
final Contents other = (Contents) obj;
return Objects.equals(this.type, other.type)
&& Objects.equals(this.contents, other.contents);
&& Objects.equals(this.contents, other.contents)
&& Objects.equals(this.src, other.src);
}

@Override
public String toString() {
return "Contents{" +
"type=" + type +
",src=" + src +
", contents='" + contents + '\'' +
'}';
}

public static class Builder {

private ContentType type;
private String src;
private String contents;

private Builder() {
Expand All @@ -74,13 +84,18 @@ public Builder withType(ContentType type) {
return this;
}

public Builder withSrc(String src) {
this.src = src;
return this;
}

public Builder withContents(String contents) {
this.contents = contents;
return this;
}

public Contents build() {
return new Contents(type, contents);
return new Contents(type, contents, src);
}
}
}
51 changes: 41 additions & 10 deletions src/main/java/fr/vidal/oss/jaxb/atom/core/Entry.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.vidal.oss.jaxb.atom.core;

import fr.vidal.oss.jaxb.atom.core.validation.EntryValidation;

import static fr.vidal.oss.jaxb.atom.core.Preconditions.checkState;
import static java.util.Collections.unmodifiableCollection;

Expand All @@ -16,7 +18,7 @@
import javax.xml.namespace.QName;

@XmlType(propOrder = {
"title", "links", "categories", "author", "contributors", "id", "publishedDate", "updateDate", "summary", "contents", "additionalElements"
"title", "links", "categories", "authors", "contributors", "id", "publishedDate", "updateDate", "summary", "contents", "rights", "source", "additionalElements"
})
public class Entry {

Expand All @@ -33,11 +35,15 @@ public class Entry {
@XmlElement(name = "updated", required = true)
private final Date updateDate;
@XmlElement(name = "author")
private final Author author;
private final Collection<Author> authors;
@XmlElement(name = "contributor")
private final Collection<Contributor> contributors;
@XmlElement(name = "content")
private final Contents contents;
@XmlElement(name = "source")
private final Source source;
@XmlElement(name = "rights")
private final String rights;
@XmlElement(name = "link", required = true)
private final Collection<Link> links;
@XmlAnyElement
Expand All @@ -52,17 +58,19 @@ private Entry() {

private Entry(Builder builder) {
additionalElements = builder.additionalElements;
author = builder.author;
authors = builder.authors;
contributors = builder.contributors;
categories = builder.categories;
contents = builder.contents;
rights = builder.rights;
id = builder.id;
links = builder.links;
summary = builder.summary;
title = builder.title;
publishedDate = builder.publishedDate;
updateDate = builder.updateDate;
additionalAttributes = index(builder.additionalAttributes);
source = builder.source;
}

public static Builder builder() {
Expand Down Expand Up @@ -93,8 +101,8 @@ public Date getUpdateDate() {
return updateDate;
}

public Author getAuthor() {
return author;
public Collection<Author> getAuthors() {
return authors;
}

public Collection<Contributor> getContributors() {
Expand All @@ -105,6 +113,14 @@ public Contents getContents() {
return contents;
}

public String getRights() {
return rights;
}

public Source getSource() {
return source;
}

public Collection<Link> getLinks() {
return unmodifiableCollection(links);
}
Expand Down Expand Up @@ -143,11 +159,13 @@ public String toString() {
", id='" + id + '\'' +
", publishedDate=" + publishedDate +
", updateDate=" + updateDate +
", author=" + author +
", authors=" + authors +
", contributors=" + contributors +
", contents=" + contents +
", rights=" + rights +
", links=" + links +
", additionalElements=" + additionalElements +
", source=" + source +
'}';
}

Expand All @@ -169,12 +187,14 @@ public static class Builder {
private String id;
private Date publishedDate;
private Date updateDate;
private Author author;
private Collection<Author> authors = new LinkedHashSet<>();
private Collection<Contributor> contributors = new LinkedHashSet<>();
private Contents contents = Contents.EMPTY;
private Collection<Link> links = new LinkedHashSet<>();
private Collection<SimpleElement> additionalElements = new LinkedHashSet<>();
public Collection<Attribute> additionalAttributes = new LinkedHashSet<>();
private Collection<Attribute> additionalAttributes = new LinkedHashSet<>();
private String rights;
private Source source;

private Builder() {
}
Expand Down Expand Up @@ -209,8 +229,8 @@ public Builder withUpdateDate(Date updateDate){
return this;
}

public Builder withAuthor(Author author) {
this.author = author;
public Builder addAuthor(Author author) {
this.authors.add(author);
return this;
}

Expand All @@ -224,6 +244,11 @@ public Builder withContents(Contents contents) {
return this;
}

public Builder withRights(String rights) {
this.rights = rights;
return this;
}

public Builder addLink(Link link) {
this.links.add(link);
return this;
Expand All @@ -239,11 +264,17 @@ public Builder addAttribute(Attribute attribute) {
return this;
}

public Builder withSource(Source source) {
this.source = source;
return this;
}

public Entry build() {
checkState(title != null, "title is mandatory");
checkState(id != null, "id is mandatory");
checkState(updateDate != null, "updateDate is mandatory");
checkState(!links.isEmpty(), "links cannot be empty");
checkState(EntryValidation.summaryIsMandatory(contents, summary), "Summary is mandatory");
return new Entry(this);
}
}
Expand Down
Loading