use of org.olat.modules.webFeed.Enclosure in project openolat by klemens.
the class FeedManagerImpl method replaceEnclosure.
/**
* Save or delete the media file to the file system and get the appropriate
* Enclosure.
*
* @param item
* @param file
* @return
*/
private Enclosure replaceEnclosure(Item item, FileElement file) {
Enclosure enclosure = item.getEnclosure();
if (file != null) {
if (file.isUploadSuccess()) {
if (enclosure != null && enclosure.getFileName() != null) {
feedFileStorage.deleteItemMedia(item, enclosure.getFileName());
}
// New uploaded file
enclosure = new EnclosureImpl();
enclosure.setLength(file.getUploadSize());
enclosure.setType(file.getUploadMimeType());
String saveFileName = feedFileStorage.saveItemMedia(item, file);
enclosure.setFileName(saveFileName);
} else if (file.getInitialFile() == null) {
// If no or deleted initial file, delete the media file
if (enclosure != null && enclosure.getFileName() != null) {
feedFileStorage.deleteItemMedia(item, enclosure.getFileName());
}
enclosure = null;
}
}
return enclosure;
}
use of org.olat.modules.webFeed.Enclosure in project openolat by klemens.
the class FeedManagerImpl method updateItem.
@Override
public Item updateItem(Item item, FileElement file) {
if (item == null)
return null;
Item updatedItem = itemDAO.loadItem(item.getKey());
if (updatedItem != null) {
Enclosure enclosure = replaceEnclosure(item, file);
item.setEnclosure(enclosure);
updatedItem = itemDAO.updateItem(item);
markPublisherNews(updatedItem.getFeed());
}
return updatedItem;
}
use of org.olat.modules.webFeed.Enclosure in project OpenOLAT by OpenOLAT.
the class FeedManagerImpl method createItem.
@Override
public Feed createItem(Feed feed, Item item, FileElement file) {
if (feed == null || item == null || !feed.isInternal())
return null;
// Set the current date as published date.
if (item.getPublishDate() == null) {
item.setPublishDate(new Date());
}
// Save the Enclosure
Enclosure enclosure = replaceEnclosure(item, file);
item.setEnclosure(enclosure);
// Save the Item
itemDAO.createItem(feed, item);
// Set the modification date of the feed
Feed reloadedFeed = feedDAO.loadFeed(feed.getKey());
reloadedFeed.setLastModified(new Date());
reloadedFeed = feedDAO.updateFeed(reloadedFeed);
markPublisherNews(reloadedFeed);
return reloadedFeed;
}
use of org.olat.modules.webFeed.Enclosure in project OpenOLAT by OpenOLAT.
the class FeedManagerImpl method updateItem.
@Override
public Item updateItem(Item item, FileElement file) {
if (item == null)
return null;
Item updatedItem = itemDAO.loadItem(item.getKey());
if (updatedItem != null) {
Enclosure enclosure = replaceEnclosure(item, file);
item.setEnclosure(enclosure);
updatedItem = itemDAO.updateItem(item);
markPublisherNews(updatedItem.getFeed());
}
return updatedItem;
}
use of org.olat.modules.webFeed.Enclosure in project OpenOLAT by OpenOLAT.
the class RomeFeedFetcher method convertEnclosures.
/**
* Converts a List of <code>SyndEnclosures</code> into an <code>Enclosure</code>.
* Only one media file is supported. If the List has more than one entry, the
* first entry is taken.
* SyndEnclosures without an URL are not converted, because it is necessary to
* fetch the enclosure.
*
* @param enclosures
* @return the enclosure or null
*/
protected Enclosure convertEnclosures(List<SyndEnclosure> enclosures) {
if (enclosures == null || enclosures.isEmpty())
return null;
SyndEnclosure syndEnclosure = enclosures.get(0);
Enclosure enclosure = null;
if (StringHelper.containsNonWhitespace(syndEnclosure.getUrl())) {
enclosure = new EnclosureImpl();
enclosure.setExternalUrl(syndEnclosure.getUrl());
enclosure.setLength(syndEnclosure.getLength());
enclosure.setType(syndEnclosure.getType());
}
return enclosure;
}
Aggregations