fetch feed name

This commit is contained in:
Athou
2013-03-30 20:51:51 +01:00
parent d8b8f6617a
commit 5a4d11c4de
8 changed files with 75 additions and 6 deletions

View File

@@ -32,7 +32,7 @@ public class FeedParser {
try {
SyndFeed rss = new SyndFeedInput().build(new StringReader(xml));
feed.setTitle(rss.getTitle());
List<SyndEntry> items = rss.getEntries();
for (SyndEntry item : items) {
FeedEntry entry = new FeedEntry();

View File

@@ -9,6 +9,7 @@ import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.hibernate.annotations.Index;
@@ -23,6 +24,9 @@ public class Feed extends AbstractModel {
@Index(name = "feed_index")
private String url;
@Transient
private String title;
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdated;
@@ -83,4 +87,12 @@ public class Feed extends AbstractModel {
this.subscriptions = subscriptions;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}

View File

@@ -66,12 +66,17 @@ public class JSONMessageBodyReaderWriter implements MessageBodyWriter<Object>,
OutputStream entityStream) throws IOException,
WebApplicationException {
httpHeaders.putSingle(HttpHeaders.CONTENT_TYPE, mediaType.toString()
+ ";charset=UTF-8");
+ ";charset=" + UTF_8);
httpHeaders.putSingle(HttpHeaders.CACHE_CONTROL, "no-cache");
httpHeaders.putSingle("Pragma", "no-cache");
OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8);
getGson().toJson(t, type, writer);
writer.flush();
if (type == String.class) {
entityStream.write(t.toString().getBytes(UTF_8));
} else {
OutputStreamWriter writer = new OutputStreamWriter(entityStream,
UTF_8);
getGson().toJson(t, type, writer);
writer.flush();
}
}
@Override

View File

@@ -31,6 +31,7 @@ import com.commafeed.backend.dao.FeedSubscriptionService;
import com.commafeed.backend.dao.UserRoleService;
import com.commafeed.backend.dao.UserService;
import com.commafeed.backend.dao.UserSettingsService;
import com.commafeed.backend.feeds.FeedFetcher;
import com.commafeed.backend.feeds.OPMLImporter;
import com.commafeed.backend.model.User;
import com.commafeed.backend.model.UserRole.Role;
@@ -80,6 +81,9 @@ public abstract class AbstractREST {
@Inject
PasswordEncryptionService encryptionService;
@Inject
FeedFetcher feedFetcher;
@PostConstruct
public void init() {
CommaFeedApplication app = CommaFeedApplication.get();

View File

@@ -7,6 +7,7 @@ import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
@@ -25,10 +26,26 @@ import com.commafeed.frontend.model.Category;
import com.commafeed.frontend.model.Subscription;
import com.commafeed.frontend.model.SubscriptionRequest;
import com.google.common.base.Preconditions;
import com.sun.syndication.io.FeedException;
@Path("subscriptions")
public class SubscriptionsREST extends AbstractREST {
@GET
@Path("fetch")
public Feed fetchFeed(@QueryParam("url") String url) {
Preconditions.checkNotNull(url);
Feed feed = null;
try {
feed = feedFetcher.fetch(url);
} catch (FeedException e) {
throw new WebApplicationException(Response
.status(Status.INTERNAL_SERVER_ERROR)
.entity(e.getMessage()).build());
}
return feed;
}
@POST
@Path("subscribe")
public Response subscribe(SubscriptionRequest req) {