forked from Archives/Athou_commafeed
make sure enclosure urls fit in the database field
This commit is contained in:
@@ -50,8 +50,7 @@ public class FeedFetcher {
|
|||||||
fetchedFeed = parser.parse(feedUrl, result.getContent());
|
fetchedFeed = parser.parse(feedUrl, result.getContent());
|
||||||
Feed feed = fetchedFeed.getFeed();
|
Feed feed = fetchedFeed.getFeed();
|
||||||
feed.setLastModifiedHeader(result.getLastModifiedSince());
|
feed.setLastModifiedHeader(result.getLastModifiedSince());
|
||||||
feed.setEtagHeader(org.apache.commons.lang.StringUtils.substring(
|
feed.setEtagHeader(FeedUtils.truncate(result.geteTag(), 255));
|
||||||
result.geteTag(), 0, 255));
|
|
||||||
fetchedFeed.setFetchDuration(result.getDuration());
|
fetchedFeed.setFetchDuration(result.getDuration());
|
||||||
return fetchedFeed;
|
return fetchedFeed;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,13 @@ import com.google.api.client.util.Lists;
|
|||||||
|
|
||||||
public class FeedUtils {
|
public class FeedUtils {
|
||||||
|
|
||||||
|
public static String truncate(String string, int length) {
|
||||||
|
if (string != null) {
|
||||||
|
string = string.substring(0, Math.min(length, string.length()));
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
public static String guessEncoding(byte[] bytes) {
|
public static String guessEncoding(byte[] bytes) {
|
||||||
String DEFAULT_ENCODING = "UTF-8";
|
String DEFAULT_ENCODING = "UTF-8";
|
||||||
UniversalDetector detector = new UniversalDetector(null);
|
UniversalDetector detector = new UniversalDetector(null);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.commafeed.backend.dao.FeedEntryDAO;
|
|||||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||||
import com.commafeed.backend.feeds.FeedRefreshTaskGiver;
|
import com.commafeed.backend.feeds.FeedRefreshTaskGiver;
|
||||||
|
import com.commafeed.backend.feeds.FeedUtils;
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
import com.commafeed.backend.model.FeedCategory;
|
import com.commafeed.backend.model.FeedCategory;
|
||||||
import com.commafeed.backend.model.FeedEntry;
|
import com.commafeed.backend.model.FeedEntry;
|
||||||
@@ -69,7 +70,7 @@ public class FeedSubscriptionService {
|
|||||||
newSubscription = true;
|
newSubscription = true;
|
||||||
}
|
}
|
||||||
sub.setCategory(category);
|
sub.setCategory(category);
|
||||||
sub.setTitle(title.substring(0, Math.min(128, title.length())));
|
sub.setTitle(FeedUtils.truncate(title, 128));
|
||||||
feedSubscriptionDAO.saveOrUpdate(sub);
|
feedSubscriptionDAO.saveOrUpdate(sub);
|
||||||
|
|
||||||
if (newSubscription) {
|
if (newSubscription) {
|
||||||
|
|||||||
@@ -98,17 +98,12 @@ public class FeedUpdateService {
|
|||||||
private void handleEntry(Feed feed, FeedEntry entry) {
|
private void handleEntry(Feed feed, FeedEntry entry) {
|
||||||
String baseUri = feed.getLink();
|
String baseUri = feed.getLink();
|
||||||
FeedEntryContent content = entry.getContent();
|
FeedEntryContent content = entry.getContent();
|
||||||
|
content.setEnclosureUrl(FeedUtils.truncate(content.getEnclosureUrl(),
|
||||||
|
2048));
|
||||||
content.setContent(FeedUtils.handleContent(content.getContent(),
|
content.setContent(FeedUtils.handleContent(content.getContent(),
|
||||||
baseUri));
|
baseUri));
|
||||||
String title = FeedUtils.handleContent(content.getTitle(), baseUri);
|
String title = FeedUtils.handleContent(content.getTitle(), baseUri);
|
||||||
if (title != null) {
|
content.setTitle(FeedUtils.truncate(title, 2048));
|
||||||
content.setTitle(title.substring(0, Math.min(2048, title.length())));
|
entry.setAuthor(FeedUtils.truncate(entry.getAuthor(), 128));
|
||||||
}
|
|
||||||
String author = entry.getAuthor();
|
|
||||||
if (author != null) {
|
|
||||||
entry.setAuthor(author.substring(0, Math.min(128, author.length())));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user