make sure enclosure urls fit in the database field

This commit is contained in:
Athou
2013-05-23 10:03:15 +02:00
parent c9f2b545c9
commit f9cfea4f79
4 changed files with 14 additions and 12 deletions

View File

@@ -50,8 +50,7 @@ public class FeedFetcher {
fetchedFeed = parser.parse(feedUrl, result.getContent());
Feed feed = fetchedFeed.getFeed();
feed.setLastModifiedHeader(result.getLastModifiedSince());
feed.setEtagHeader(org.apache.commons.lang.StringUtils.substring(
result.geteTag(), 0, 255));
feed.setEtagHeader(FeedUtils.truncate(result.geteTag(), 255));
fetchedFeed.setFetchDuration(result.getDuration());
return fetchedFeed;
}

View File

@@ -20,6 +20,13 @@ import com.google.api.client.util.Lists;
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) {
String DEFAULT_ENCODING = "UTF-8";
UniversalDetector detector = new UniversalDetector(null);

View File

@@ -9,6 +9,7 @@ import com.commafeed.backend.dao.FeedEntryDAO;
import com.commafeed.backend.dao.FeedEntryStatusDAO;
import com.commafeed.backend.dao.FeedSubscriptionDAO;
import com.commafeed.backend.feeds.FeedRefreshTaskGiver;
import com.commafeed.backend.feeds.FeedUtils;
import com.commafeed.backend.model.Feed;
import com.commafeed.backend.model.FeedCategory;
import com.commafeed.backend.model.FeedEntry;
@@ -69,7 +70,7 @@ public class FeedSubscriptionService {
newSubscription = true;
}
sub.setCategory(category);
sub.setTitle(title.substring(0, Math.min(128, title.length())));
sub.setTitle(FeedUtils.truncate(title, 128));
feedSubscriptionDAO.saveOrUpdate(sub);
if (newSubscription) {

View File

@@ -98,17 +98,12 @@ public class FeedUpdateService {
private void handleEntry(Feed feed, FeedEntry entry) {
String baseUri = feed.getLink();
FeedEntryContent content = entry.getContent();
content.setEnclosureUrl(FeedUtils.truncate(content.getEnclosureUrl(),
2048));
content.setContent(FeedUtils.handleContent(content.getContent(),
baseUri));
String title = FeedUtils.handleContent(content.getTitle(), baseUri);
if (title != null) {
content.setTitle(title.substring(0, Math.min(2048, title.length())));
}
String author = entry.getAuthor();
if (author != null) {
entry.setAuthor(author.substring(0, Math.min(128, author.length())));
}
content.setTitle(FeedUtils.truncate(title, 2048));
entry.setAuthor(FeedUtils.truncate(entry.getAuthor(), 128));
}
}