com.sun.syndication.feed.synd.SyndImageImpl Java Examples

The following examples show how to use com.sun.syndication.feed.synd.SyndImageImpl. 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: 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 #2
Source File: RSSFeed.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
    * Constructor. The identityKey is needed to generate personal URLs for the corresponding user.
    */
protected RSSFeed(final Feed feed, final Identity identity, final Long courseId, final String nodeId,final Translator translator, RepositoryService repositoryService) {
       super();

       // This helper object is required for generating the appropriate URLs for
       // the given user (identity)
	final FeedViewHelper helper = new FeedViewHelper(feed, identity, courseId, nodeId, translator, repositoryService);

       setFeedType("rss_2.0");
       setEncoding(RSSServlet.DEFAULT_ENCODING);
       setTitle(feed.getTitle());
       // According to the rss specification, the feed channel description is not
       // (explicitly) allowed to contain html tags.
       String strippedDescription = FilterFactory.getHtmlTagsFilter().filter(feed.getDescription());
       strippedDescription = strippedDescription.replaceAll(" ", " "); // TODO: remove when filter
       // does it
       setDescription(strippedDescription);
       setLink(helper.getJumpInLink());

       setPublishedDate(feed.getLastModified());
       // The image
       if (feed.getImageName() != null) {
           final SyndImage image = new SyndImageImpl();
           image.setDescription(feed.getDescription());
           image.setTitle(feed.getTitle());
           image.setLink(getLink());
           image.setUrl(helper.getImageUrl());
           setImage(image);
       }

       final List<SyndEntry> episodes = new ArrayList<SyndEntry>();
       for (final Item item : feed.getPublishedItems()) {
           final SyndEntry entry = new SyndEntryImpl();
           entry.setTitle(item.getTitle());

           final SyndContent itemDescription = new SyndContentImpl();
           itemDescription.setType("text/plain");
           itemDescription.setValue(helper.getItemDescriptionForBrowser(item));
           entry.setDescription(itemDescription);

           // Link will also be converted to the rss guid tag. Except if there's an
           // enclosure, then the enclosure url is used.
           // Use jump-in link far all entries. This will be overriden if the item
           // has an enclosure.
           entry.setLink(helper.getJumpInLink() + "#" + item.getGuid());
           entry.setPublishedDate(item.getPublishDate());
           entry.setUpdatedDate(item.getLastModified());

           // The enclosure is the media (audio or video) file of the episode
           final Enclosure media = item.getEnclosure();
           if (media != null) {
               final SyndEnclosure enclosure = new SyndEnclosureImpl();
               enclosure.setUrl(helper.getMediaUrl(item));
               enclosure.setType(media.getType());
               enclosure.setLength(media.getLength());
               // Also set the item link to point to the enclosure
               entry.setLink(helper.getMediaUrl(item));
               final List<SyndEnclosure> enclosures = new ArrayList<SyndEnclosure>();
               enclosures.add(enclosure);
               entry.setEnclosures(enclosures);
           }

           episodes.add(entry);
       }
       setEntries(episodes);
   }
 
Example #3
Source File: RSSFeed.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor. The identityKey is needed to generate personal URLs for the corresponding user.
 */
protected RSSFeed(final Feed feed, final Identity identity, final Long courseId, final String nodeId, final Translator translator, RepositoryService repositoryService) {
    super();

    // This helper object is required for generating the appropriate URLs for
    // the given user (identity)
    final FeedViewHelper helper = new FeedViewHelper(feed, identity, courseId, nodeId, translator, repositoryService);

    setFeedType("rss_2.0");
    setEncoding(DEFAULT_ENCODING);
    setTitle(feed.getTitle());
    // According to the rss specification, the feed channel description is not
    // (explicitly) allowed to contain html tags.
    String strippedDescription = FilterFactory.getHtmlTagsFilter().filter(feed.getDescription());
    strippedDescription = strippedDescription.replaceAll("&nbsp;", " "); // TODO: remove when filter
    // does it
    setDescription(strippedDescription);
    setLink(helper.getJumpInLink());

    setPublishedDate(feed.getLastModified());
    // The image
    if (feed.getImageName() != null) {
        final SyndImage image = new SyndImageImpl();
        image.setDescription(feed.getDescription());
        image.setTitle(feed.getTitle());
        image.setLink(getLink());
        image.setUrl(helper.getImageUrl());
        setImage(image);
    }

    final List<SyndEntry> episodes = new ArrayList<SyndEntry>();
    for (final Item item : feed.getPublishedItems()) {
        final SyndEntry entry = new SyndEntryImpl();
        entry.setTitle(item.getTitle());

        final SyndContent itemDescription = new SyndContentImpl();
        itemDescription.setType("text/plain");
        itemDescription.setValue(helper.getItemDescriptionForBrowser(item));
        entry.setDescription(itemDescription);

        // Link will also be converted to the rss guid tag. Except if there's an
        // enclosure, then the enclosure url is used.
        // Use jump-in link far all entries. This will be overriden if the item
        // has an enclosure.
        entry.setLink(helper.getJumpInLink() + "#" + item.getGuid());
        entry.setPublishedDate(item.getPublishDate());
        entry.setUpdatedDate(item.getLastModified());

        // The enclosure is the media (audio or video) file of the episode
        final Enclosure media = item.getEnclosure();
        if (media != null) {
            final SyndEnclosure enclosure = new SyndEnclosureImpl();
            enclosure.setUrl(helper.getMediaUrl(item));
            enclosure.setType(media.getType());
            enclosure.setLength(media.getLength());
            // Also set the item link to point to the enclosure
            entry.setLink(helper.getMediaUrl(item));
            final List<SyndEnclosure> enclosures = new ArrayList<SyndEnclosure>();
            enclosures.add(enclosure);
            entry.setEnclosures(enclosures);
        }

        episodes.add(entry);
    }
    setEntries(episodes);
}
 
Example #4
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;
}