Search in sources :

Example 1 with SyndImageImpl

use of com.sun.syndication.feed.synd.SyndImageImpl in project gitblit by gitblit.

the class SyndicationUtils method toRSS.

/**
 * Outputs an RSS feed of the list of entries to the outputstream.
 *
 * @param hostUrl
 * @param feedLink
 * @param title
 * @param description
 * @param entryModels
 * @param os
 * @throws IOException
 * @throws FeedException
 */
public static void toRSS(String hostUrl, String feedLink, String title, String description, List<FeedEntryModel> entryModels, OutputStream os) throws IOException, FeedException {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    feed.setEncoding("UTF-8");
    feed.setTitle(title);
    feed.setLink(feedLink);
    if (StringUtils.isEmpty(description)) {
        feed.setDescription(title);
    } else {
        feed.setDescription(description);
    }
    SyndImageImpl image = new SyndImageImpl();
    image.setTitle(Constants.NAME);
    image.setUrl(hostUrl + "/gitblt_25.png");
    image.setLink(hostUrl);
    feed.setImage(image);
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    for (FeedEntryModel entryModel : entryModels) {
        SyndEntry entry = new SyndEntryImpl();
        entry.setTitle(entryModel.title);
        entry.setAuthor(entryModel.author);
        entry.setLink(entryModel.link);
        entry.setPublishedDate(entryModel.published);
        if (entryModel.tags != null && entryModel.tags.size() > 0) {
            List<SyndCategory> tags = new ArrayList<SyndCategory>();
            for (String tag : entryModel.tags) {
                SyndCategoryImpl cat = new SyndCategoryImpl();
                cat.setName(tag);
                tags.add(cat);
            }
            entry.setCategories(tags);
        }
        SyndContent content = new SyndContentImpl();
        if (StringUtils.isEmpty(entryModel.contentType) || entryModel.contentType.equalsIgnoreCase("text/plain")) {
            content.setType("text/html");
            content.setValue(StringUtils.breakLinesForHtml(entryModel.content));
        } else {
            content.setType(entryModel.contentType);
            content.setValue(entryModel.content);
        }
        entry.setDescription(content);
        entries.add(entry);
    }
    feed.setEntries(entries);
    OutputStreamWriter writer = new OutputStreamWriter(os, "UTF-8");
    SyndFeedOutput output = new SyndFeedOutput();
    output.output(feed, writer);
    writer.close();
}
Also used : SyndCategory(com.sun.syndication.feed.synd.SyndCategory) SyndImageImpl(com.sun.syndication.feed.synd.SyndImageImpl) FeedEntryModel(com.gitblit.models.FeedEntryModel) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndCategoryImpl(com.sun.syndication.feed.synd.SyndCategoryImpl) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) OutputStreamWriter(java.io.OutputStreamWriter)

Example 2 with SyndImageImpl

use of com.sun.syndication.feed.synd.SyndImageImpl in project pentaho-kettle by pentaho.

the class RssOutput method WriteToFile.

private boolean WriteToFile(String title, String link, String description, Date Pubdate, String copyright, String imageTitle, String imageDescription, String imageLink, String imageUrl, String language, String author) {
    boolean retval = false;
    try {
        // Specify Filename
        String fileName = data.filename;
        // Set channel ...
        data.feed = new SyndFeedImpl();
        if (Utils.isEmpty(meta.getVersion())) {
            data.feed.setFeedType("rss_2.0");
        } else {
            data.feed.setFeedType(meta.getVersion());
        }
        // Set encoding ...
        if (Utils.isEmpty(meta.getEncoding())) {
            data.feed.setEncoding("iso-8859-1");
        } else {
            data.feed.setEncoding(meta.getEncoding());
        }
        if (title != null) {
            data.feed.setTitle(title);
        }
        if (link != null) {
            data.feed.setLink(link);
        }
        if (description != null) {
            data.feed.setDescription(description);
        }
        if (Pubdate != null) {
            // data.dateParser.parse(Pubdate.toString()));
            data.feed.setPublishedDate(Pubdate);
        }
        // Set image ..
        if (meta.AddImage()) {
            SyndImage image = new SyndImageImpl();
            if (imageTitle != null) {
                image.setTitle(title);
            }
            if (imageLink != null) {
                image.setLink(link);
            }
            if (imageUrl != null) {
                image.setUrl(imageUrl);
            }
            if (imageDescription != null) {
                image.setDescription(imageDescription);
            }
            data.feed.setImage(image);
        }
        if (language != null) {
            data.feed.setLanguage(language);
        }
        if (copyright != null) {
            data.feed.setCopyright(copyright);
        }
        if (author != null) {
            data.feed.setAuthor(author);
        }
        // Add entries
        data.feed.setEntries(data.entries);
        Writer writer = new FileWriter(fileName);
        SyndFeedOutput output = new SyndFeedOutput();
        output.output(data.feed, writer);
        writer.close();
        if (meta.AddToResult()) {
            // Add this to the result file names...
            ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(fileName, getTransMeta()), getTransMeta().getName(), getStepname());
            resultFile.setComment("This file was created with a RSS Output step");
            addResultFile(resultFile);
        }
        if (log.isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "RssOutput.Log.CreatingFileOK", fileName));
        }
        retval = true;
    } catch (Exception e) {
        logError(BaseMessages.getString(PKG, "RssOutput.Log.ErrorCreatingFile", e.toString()));
        setErrors(1);
        retval = false;
    }
    return retval;
}
Also used : SyndImageImpl(com.sun.syndication.feed.synd.SyndImageImpl) FileWriter(java.io.FileWriter) SyndImage(com.sun.syndication.feed.synd.SyndImage) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) ResultFile(org.pentaho.di.core.ResultFile) XMLWriter(org.dom4j.io.XMLWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Aggregations

SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)2 SyndImageImpl (com.sun.syndication.feed.synd.SyndImageImpl)2 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)2 FeedEntryModel (com.gitblit.models.FeedEntryModel)1 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)1 SyndCategoryImpl (com.sun.syndication.feed.synd.SyndCategoryImpl)1 SyndContent (com.sun.syndication.feed.synd.SyndContent)1 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)1 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)1 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)1 SyndImage (com.sun.syndication.feed.synd.SyndImage)1 FileWriter (java.io.FileWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 XMLWriter (org.dom4j.io.XMLWriter)1 ResultFile (org.pentaho.di.core.ResultFile)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1