mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
fetch feed name
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user