use of com.sun.syndication.io.SyndFeedOutput 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;
}
Aggregations