com.sun.syndication.io.SyndFeedOutput Java Examples

The following examples show how to use com.sun.syndication.io.SyndFeedOutput. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StubbornJavaRss.java    From StubbornJava with MIT License 5 votes vote down vote up
private static String getFeed(HttpUrl host) {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    feed.setTitle("StubbornJava");
    feed.setLink(host.toString());
    feed.setDescription("Unconventional guides, examples, and blog utilizing modern Java");

    List<PostRaw> posts = Posts.getAllRawPosts();
    List<SyndEntry> entries = Seq.seq(posts)
        .map(p -> {
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle(p.getTitle());
            entry.setLink(host.newBuilder().encodedPath(p.getUrl()).build().toString());
            entry.setPublishedDate(Date.from(p.getDateCreated()
                                              .toLocalDate()
                                              .atStartOfDay(ZoneId.systemDefault())
                                              .toInstant()));
            entry.setUpdatedDate(Date.from(p.getDateUpdated()
                                            .toLocalDate()
                                            .atStartOfDay(ZoneId.systemDefault())
                                            .toInstant()));
            SyndContentImpl description = new SyndContentImpl();
            description.setType("text/plain");
            description.setValue(p.getMetaDesc());
            entry.setDescription(description);
            return entry;
        }).toList();
    feed.setEntries(entries);

    StringWriter writer = new StringWriter();
    SyndFeedOutput output = new SyndFeedOutput();

    return Unchecked.supplier(() -> {
        output.output(feed, writer);
        return writer.toString();
    }).get();
}
 
Example #2
Source File: StubbornJavaRss.java    From StubbornJava with MIT License 5 votes vote down vote up
private static String getFeed(HttpUrl host) {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    feed.setTitle("StubbornJava");
    feed.setLink(host.toString());
    feed.setDescription("Unconventional guides, examples, and blog utilizing modern Java");

    List<PostRaw> posts = Posts.getAllRawPosts();
    List<SyndEntry> entries = Seq.seq(posts)
        .map(p -> {
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle(p.getTitle());
            entry.setLink(host.newBuilder().encodedPath(p.getUrl()).build().toString());
            entry.setPublishedDate(Date.from(p.getDateCreated()
                                              .toLocalDate()
                                              .atStartOfDay(ZoneId.systemDefault())
                                              .toInstant()));
            entry.setUpdatedDate(Date.from(p.getDateUpdated()
                                            .toLocalDate()
                                            .atStartOfDay(ZoneId.systemDefault())
                                            .toInstant()));
            SyndContentImpl description = new SyndContentImpl();
            description.setType("text/plain");
            description.setValue(p.getMetaDesc());
            entry.setDescription(description);
            return entry;
        }).toList();
    feed.setEntries(entries);

    StringWriter writer = new StringWriter();
    SyndFeedOutput output = new SyndFeedOutput();

    return Unchecked.supplier(() -> {
        output.output(feed, writer);
        return writer.toString();
    }).get();
}
 
Example #3
Source File: SyndFeedMediaResource.java    From olat with Apache License 2.0 5 votes vote down vote up
public SyndFeedMediaResource(final SyndFeed feed) {
    this.feed = feed;

    feedString = null;
    try {
        final SyndFeedOutput output = new SyndFeedOutput();
        feedString = output.outputString(feed);
    } catch (final FeedException e) {
        /* TODO: ORID-1007 ExceptionHandling */
        log.error(e.getMessage());
    }
}
 
Example #4
Source File: SyndFeedMediaResource.java    From olat with Apache License 2.0 5 votes vote down vote up
public SyndFeedMediaResource(final SyndFeed feed) {
    this.feed = feed;

    feedString = null;
    try {
        final SyndFeedOutput output = new SyndFeedOutput();
        feedString = output.outputString(feed);
    } catch (final FeedException e) {
        /* TODO: ORID-1007 ExceptionHandling */
        log.error(e.getMessage());
    }
}
 
Example #5
Source File: RomeRssWriter.java    From megatron-java with Apache License 2.0 5 votes vote down vote up
@Override
public void writeRss(Writer out, IRssChannel rssChannel) throws RssException, IOException {
    SyndFeed syndFeed = ((RomeRssChannel)rssChannel).getSyndFeed();
    SyndFeedOutput syndFeedOutput = new SyndFeedOutput();
    try {
        syndFeedOutput.output(syndFeed, out);
    } catch (FeedException e) {
        String msg = "Cannot write RSS feed.";
        log.error(msg, e);
        throw new RssException(msg, e);
    }
}
 
Example #6
Source File: RssOutput.java    From hop with Apache License 2.0 4 votes vote down vote up
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.feed.setPublishedDate( Pubdate ); // data.dateParser.parse(Pubdate.toString()));
    }
    // 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, HopVFS.getFileObject( fileName, getPipelineMeta() ), getPipelineMeta()
          .getName(), getTransformName() );
      resultFile.setComment( "This file was created with a RSS Output transform" );
      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;
}
 
Example #7
Source File: RSSRomeExample.java    From tutorials with MIT License 4 votes vote down vote up
private static void publishFeed(SyndFeed feed) throws IOException, FeedException {
    Writer writer = new FileWriter("xyz.txt");
    SyndFeedOutput syndFeedOutput = new SyndFeedOutput();
    syndFeedOutput.output(feed, writer);
    writer.close();
}
 
Example #8
Source File: PublisherServlet.java    From fuchsia with Apache License 2.0 4 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    Thread.currentThread().setContextClassLoader(SyndFeed.class.getClassLoader());

    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("atom_1.0");
    feed.setTitle("Sample Feed (created with ROME)");
    feed.setLink("http://www.example.com");

    List<SyndLink> links = new ArrayList<SyndLink>();

    SyndLinkImpl hubLink = new SyndLinkImpl();
    hubLink.setRel("hub");
    hubLink.setHref("http://localhost:8080/hub/main");

    links.add(hubLink);

    feed.setLinks(links);
    feed.setDescription("This feed has been created using ROME");
    feed.setFeedType("atom_0.3");//rss_2.0

    List entries = new ArrayList();
    SyndEntry entry;
    SyndContent description;

    entry = new SyndEntryImpl();
    entry.setTitle("ROME v1.0");
    entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome01");
    entry.setPublishedDate(new Date());
    description = new SyndContentImpl();
    description.setType(MediaType.TEXT_PLAIN);
    description.setValue("Initial release of ROME");
    entry.setDescription(description);
    entries.add(entry);

    feed.setEntries(entries);

    SyndFeedOutput output = new SyndFeedOutput();

    try {
        output.output(feed, resp.getWriter());
        resp.getWriter().close();
    } catch (FeedException e) {
        LOG.error("Failed to create feed", e);
    }

    resp.getWriter().write(feed.createWireFeed().toString());

}
 
Example #9
Source File: RssOutput.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
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.feed.setPublishedDate( Pubdate ); // data.dateParser.parse(Pubdate.toString()));
    }
    // 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;
}