Fixed method RSS20Generator#populateHannel - Added ability to create custom fields in the channel. Expanded model SyndImage

This commit is contained in:
Dmitry Rygalov 2014-10-25 19:08:10 +07:00
parent 0b9df0e84a
commit 097a217b41
5 changed files with 99 additions and 1 deletions

View file

@ -63,6 +63,42 @@ public interface SyndImage extends Cloneable, CopyFrom {
*/ */
void setUrl(String url); void setUrl(String url);
/**
* Returns the image width.
* <p>
*
* @return the image width, <b>null</b> if none.
*
*/
public Integer getWidth();
/**
* Sets the image width.
* <p>
*
* @param width the image width to set, <b>null</b> if none.
*
*/
public void setWidth(Integer width);
/**
* Returns the image height.
* <p>
*
* @return the image height, <b>null</b> if none.
*
*/
public Integer getHeight();
/**
* Sets the image height.
* <p>
*
* @param height the image height to set, <b>null</b> if none.
*
*/
public void setHeight(Integer height);
/** /**
* Returns the image link. * Returns the image link.
* <p> * <p>

View file

@ -42,6 +42,8 @@ public class SyndImageImpl implements Serializable, SyndImage {
private String title; private String title;
private String url; private String url;
private Integer width;
private Integer height;
private String link; private String link;
private String description; private String description;
@ -50,6 +52,8 @@ public class SyndImageImpl implements Serializable, SyndImage {
basePropInterfaceMap.put("title", String.class); basePropInterfaceMap.put("title", String.class);
basePropInterfaceMap.put("url", String.class); basePropInterfaceMap.put("url", String.class);
basePropInterfaceMap.put("link", String.class); basePropInterfaceMap.put("link", String.class);
basePropInterfaceMap.put("width", Integer.class);
basePropInterfaceMap.put("height", Integer.class);
basePropInterfaceMap.put("description", String.class); basePropInterfaceMap.put("description", String.class);
final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom>, Class<?>> emptyMap(); final Map<Class<? extends CopyFrom>, Class<?>> basePropClassImplMap = Collections.<Class<? extends CopyFrom>, Class<?>> emptyMap();
@ -143,6 +147,7 @@ public class SyndImageImpl implements Serializable, SyndImage {
this.title = title; this.title = title;
} }
/** /**
* Returns the image URL. * Returns the image URL.
* <p> * <p>
@ -167,6 +172,54 @@ public class SyndImageImpl implements Serializable, SyndImage {
this.url = url; this.url = url;
} }
/**
* Returns the image width.
* <p>
*
* @return the image width, <b>null</b> if none.
*
*/
@Override
public Integer getWidth() {
return width;
}
/**
* Sets the image width.
* <p>
*
* @param width the image width to set, <b>null</b> if none.
*
*/
@Override
public void setWidth(Integer width) {
this.width = width;
}
/**
* Returns the image height.
* <p>
*
* @return the image height, <b>null</b> if none.
*
*/
@Override
public Integer getHeight() {
return height;
}
/**
* Sets the image height.
* <p>
*
* @param height the image height to set, <b>null</b> if none.
*
*/
@Override
public void setHeight(Integer height) {
this.height = height;
}
/** /**
* Returns the image link. * Returns the image link.
* <p> * <p>

View file

@ -90,6 +90,8 @@ public class ConverterForRSS090 implements Converter {
syndImage.setTitle(rssImage.getTitle()); syndImage.setTitle(rssImage.getTitle());
syndImage.setUrl(rssImage.getUrl()); syndImage.setUrl(rssImage.getUrl());
syndImage.setLink(rssImage.getLink()); syndImage.setLink(rssImage.getLink());
syndImage.setWidth(rssImage.getWidth());
syndImage.setHeight(rssImage.getHeight());
return syndImage; return syndImage;
} }

View file

@ -62,6 +62,8 @@ public class RSS20Generator extends RSS094Generator {
eChannel.addContent(generateCategoryElement(category)); eChannel.addContent(generateCategoryElement(category));
} }
generateForeignMarkup(eChannel, channel.getForeignMarkup());
} }
@Override @Override

View file

@ -7,6 +7,7 @@ import java.util.Locale;
import com.rometools.rome.feed.synd.SyndEntry; import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndImage; import com.rometools.rome.feed.synd.SyndImage;
import com.rometools.rome.io.impl.DateParser; import com.rometools.rome.io.impl.DateParser;
import org.junit.Assert;
/** /**
* @author pat * @author pat
@ -34,6 +35,9 @@ public abstract class SyndFeedTest extends FeedTest {
protected void assertEqualsStr(final String expected, final String actual) { protected void assertEqualsStr(final String expected, final String actual) {
assertEquals(prefix + "." + expected, actual); assertEquals(prefix + "." + expected, actual);
} }
protected void assertEqualsInt(final int expected, final int actual) {
Assert.assertEquals(expected, actual);
}
public void testPreserveWireFeed() throws Exception { public void testPreserveWireFeed() throws Exception {
assertNotNull(this.getCachedSyndFeed(true).originalWireFeed()); assertNotNull(this.getCachedSyndFeed(true).originalWireFeed());
@ -73,13 +77,14 @@ public abstract class SyndFeedTest extends FeedTest {
assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT", Locale.US), this.getCachedSyndFeed().getPublishedDate()); assertEquals(DateParser.parseRFC822("Mon, 01 Jan 2001 00:00:00 GMT", Locale.US), this.getCachedSyndFeed().getPublishedDate());
} }
// how do i get height and width?
public void testImage() throws Exception { public void testImage() throws Exception {
final SyndImage img = this.getCachedSyndFeed().getImage(); final SyndImage img = this.getCachedSyndFeed().getImage();
assertEqualsStr("channel.image.description", img.getDescription()); assertEqualsStr("channel.image.description", img.getDescription());
assertEqualsStr("channel.image.link", img.getLink()); assertEqualsStr("channel.image.link", img.getLink());
assertEqualsStr("channel.image.title", img.getTitle()); assertEqualsStr("channel.image.title", img.getTitle());
assertEqualsStr("channel.image.url", img.getUrl()); assertEqualsStr("channel.image.url", img.getUrl());
assertEqualsInt(100, img.getWidth());
assertEqualsInt(200, img.getHeight());
} }
public void testEntries() throws Exception { public void testEntries() throws Exception {