Skip to content
This repository has been archived by the owner on Oct 13, 2019. It is now read-only.

Commit

Permalink
Add support for RSS pubDate
Browse files Browse the repository at this point in the history
Closes #15
  • Loading branch information
mishako committed Mar 23, 2019
1 parent 2171aea commit b3c0989
Show file tree
Hide file tree
Showing 21 changed files with 378 additions and 217 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.rometools.rome.common.parser;

import com.rometools.rome.common.value.DateTimeValue;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class DateTimeParser implements Parser<DateTimeValue> {

public static final DateTimeParser INSTANCE = new DateTimeParser();

private static DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss z");

@Override
public Class<DateTimeValue> getResultClass() {
return DateTimeValue.class;
}

@Override
public DateTimeValue parse(String input) {
if (input.isEmpty()) {
return DateTimeValue.none();
}

return DateTimeValue.of(ZonedDateTime.parse(input, formatter));
}

@Override
public DateTimeValue none() {
return DateTimeValue.none();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

public class IntParser implements Parser<IntValue> {

public static final IntParser INSTANCE = new IntParser();

@Override
public Class<IntValue> getResultClass() {
return IntValue.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

public class StringParser implements Parser<StringValue> {

public static final StringParser INSTANCE = new StringParser();

@Override
public Class<StringValue> getResultClass() {
return StringValue.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

public class XmlPath {
public class XmlPath implements Comparable<XmlPath> {

private static final Comparator<XmlPath> COMPARATOR = Comparator.comparing(XmlPath::toString);

public static final XmlPath ROOT = new XmlPath(Collections.emptyList(), false);

Expand Down Expand Up @@ -88,4 +91,9 @@ public String toString() {
return "/" + String.join("/", hierarchy);
}
}

@Override
public int compareTo(XmlPath other) {
return COMPARATOR.compare(this, other);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@

@Generated(
value = "com.rometools.rome.factory.generator.EntityGenerator",
date = "2019-03-22T07:00:47.743Z"
date = "2019-03-23T07:02:53.931Z"
)
public class Enclosure {
private final String url;
private final Integer length;

private final String type;

private final Integer length;
private final String url;

Enclosure(final String url, final String type, final Integer length) {
this.url = url;
this.type = type;
Enclosure(final Integer length, final String type, final String url) {
this.length = length;
this.type = type;
this.url = url;
}

public StringValue getUrl() {
return StringValue.ofNullable(url);
public IntValue getLength() {
return IntValue.ofNullable(length);
}

public boolean hasUrl() {
return url != null;
public boolean hasLength() {
return length != null;
}

public StringValue getType() {
Expand All @@ -43,12 +43,12 @@ public boolean hasType() {
return type != null;
}

public IntValue getLength() {
return IntValue.ofNullable(length);
public StringValue getUrl() {
return StringValue.ofNullable(url);
}

public boolean hasLength() {
return length != null;
public boolean hasUrl() {
return url != null;
}

public static Builder builder() {
Expand All @@ -66,39 +66,39 @@ public boolean equals(final Object other) {
}

Enclosure that = (Enclosure) other;
return Objects.equals(url, that.url)
return Objects.equals(length, that.length)
&& Objects.equals(type, that.type)
&& Objects.equals(length, that.length);
&& Objects.equals(url, that.url);
}

@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append("{");
result.append("\"url\":");
result.append("\"" + url + "\"");
result.append("\"length\":");
result.append(String.valueOf(length));
result.append(",\"type\":");
result.append("\"" + type + "\"");
result.append(",\"length\":");
result.append(String.valueOf(length));
result.append(",\"url\":");
result.append("\"" + url + "\"");
result.append("}");
return result.toString();
}

public static class Builder {
private String url;
private Integer length;

private String type;

private Integer length;
private String url;

public Builder setUrl(final String url) {
this.url = url;
public Builder setLength(final Integer length) {
this.length = length;
return this;
}

public Builder clearUrl() {
this.url = null;
public Builder clearLength() {
this.length = null;
return this;
}

Expand All @@ -112,21 +112,21 @@ public Builder clearType() {
return this;
}

public Builder setLength(final Integer length) {
this.length = length;
public Builder setUrl(final String url) {
this.url = url;
return this;
}

public Builder clearLength() {
this.length = null;
public Builder clearUrl() {
this.url = null;
return this;
}

public Enclosure build() {
return new Enclosure(
url,
length,
type,
length
url
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
package com.rometools.rome.model;

import com.rometools.rome.common.value.DateTimeValue;
import com.rometools.rome.common.value.StringValue;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;
import java.lang.StringBuilder;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.Generated;

@Generated(
value = "com.rometools.rome.factory.generator.EntityGenerator",
date = "2019-03-22T07:00:47.695Z"
date = "2019-03-23T07:02:53.899Z"
)
public class Feed {
private final String description;

private final Image image;

private final List<Item> itemList;

private final String title;
private final ZonedDateTime published;

private final String description;
private final String title;

Feed(final Image image, final List<Item> itemList, final String title, final String description) {
Feed(final String description, final Image image, final List<Item> itemList,
final ZonedDateTime published, final String title) {
this.description = description;
this.image = image;
this.itemList = itemList;
this.published = published;
this.title = title;
this.description = description;
}

public StringValue getDescription() {
return StringValue.ofNullable(description);
}

public boolean hasDescription() {
return description != null;
}

public Image getImage() {
Expand Down Expand Up @@ -59,20 +73,20 @@ public Item getFirstItem() {
return itemList.get(0);
}

public StringValue getTitle() {
return StringValue.ofNullable(title);
public DateTimeValue getPublished() {
return DateTimeValue.ofNullable(published);
}

public boolean hasTitle() {
return title != null;
public boolean hasPublished() {
return published != null;
}

public StringValue getDescription() {
return StringValue.ofNullable(description);
public StringValue getTitle() {
return StringValue.ofNullable(title);
}

public boolean hasDescription() {
return description != null;
public boolean hasTitle() {
return title != null;
}

public static Builder builder() {
Expand All @@ -90,36 +104,51 @@ public boolean equals(final Object other) {
}

Feed that = (Feed) other;
return Objects.equals(image, that.image)
return Objects.equals(description, that.description)
&& Objects.equals(image, that.image)
&& Objects.equals(itemList, that.itemList)
&& Objects.equals(title, that.title)
&& Objects.equals(description, that.description);
&& Objects.equals(published, that.published)
&& Objects.equals(title, that.title);
}

@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append("{");
result.append("\"image\":");
result.append("\"description\":");
result.append("\"" + description + "\"");
result.append(",\"image\":");
result.append(String.valueOf(image));
result.append(",\"itemList\":");
result.append(String.valueOf(itemList));
result.append(",\"published\":");
result.append(String.valueOf(published));
result.append(",\"title\":");
result.append("\"" + title + "\"");
result.append(",\"description\":");
result.append("\"" + description + "\"");
result.append("}");
return result.toString();
}

public static class Builder {
private String description;

private Image image;

private List<Item> itemList;

private ZonedDateTime published;

private String title;

private String description;
public Builder setDescription(final String description) {
this.description = description;
return this;
}

public Builder clearDescription() {
this.description = null;
return this;
}

public Builder setImage(final Image image) {
this.image = image;
Expand Down Expand Up @@ -154,32 +183,33 @@ public Builder clearItemList() {
return this;
}

public Builder setTitle(final String title) {
this.title = title;
public Builder setPublished(final ZonedDateTime published) {
this.published = published;
return this;
}

public Builder clearTitle() {
this.title = null;
public Builder clearPublished() {
this.published = null;
return this;
}

public Builder setDescription(final String description) {
this.description = description;
public Builder setTitle(final String title) {
this.title = title;
return this;
}

public Builder clearDescription() {
this.description = null;
public Builder clearTitle() {
this.title = null;
return this;
}

public Feed build() {
return new Feed(
description,
image,
itemList,
title,
description
published,
title
);
}
}
Expand Down
Loading

0 comments on commit b3c0989

Please sign in to comment.