Skip to content

Commit

Permalink
improving SyndContent as rometools#689 requested
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio <antoniosanct@gmail.com>
  • Loading branch information
antoniosanct committed May 10, 2024
1 parent f6a38ae commit 17bf0d2
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
23 changes: 23 additions & 0 deletions rome/src/main/java/com/rometools/rome/feed/atom/Content.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Content implements Cloneable, Serializable {
private String type;
private String value;
private String src;
private String xmlBase;

/** @since Atom 1.0 */
public static final String TEXT = "text";
Expand Down Expand Up @@ -219,4 +220,26 @@ public String getSrc() {
public void setSrc(final String src) {
this.src = src;
}

/**
* Returns the xmlBase
*
* @return Returns the xmlBase.
* @since Atom 1.0
*/
public String getXmlBase() {
return xmlBase;
}

/**
* Set the xmlBase
*
* @param xmlBase The xmlBase to set.
* @since Atom 1.0
*/
public void setXmlBase(final String xmlBase) {
this.xmlBase = xmlBase;
}
}
18 changes: 18 additions & 0 deletions rome/src/main/java/com/rometools/rome/feed/synd/SyndContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ public interface SyndContent extends Cloneable, CopyFrom {
*/
void setValue(String value);

/**
* Returns the content xmlBase.
* <p>
*
* @return the content xmlBase, <b>null</b> if none.
*
*/
String getXmlBase();

/**
* Sets the content xmlBase.
* <p>
*
* @param xmlBase the content xmlBase to set, <b>null</b> if none.
*
*/
void setXmlBase(String xmlBase);

/**
* Creates a deep clone of the object.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class SyndContentImpl implements Serializable, SyndContent {
private String type;
private String value;
private String mode;
private String xmlBase;

static {
final Map<String, Class<?>> basePropInterfaceMap = new HashMap<String, Class<?>>();
Expand Down Expand Up @@ -179,6 +180,35 @@ public void setValue(final String value) {
this.value = value;
}

/**
* Returns the content xmlBase.
* <p>
*
* @return the content xmlBase, <b>null</b> if none.
*
*/
@Override
public String getXmlBase() {
return this.xmlBase;
}

/**
* Sets the content xmlBase.
* <p>
*
* @param xmlBase the content xmlBase to set, <b>null</b> if none.
*
*/
@Override
public void setXmlBase(final String xmlBase) {
this.xmlBase = xmlBase;
}

/**
* Return the Class interface
*
* @return the class interface.
*/
@Override
public Class<SyndContent> getInterface() {
return SyndContent.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ protected SyndContent createSyndContent(final Content content) {
final SyndContent sContent = new SyndContentImpl();
sContent.setType(content.getType());
sContent.setValue(content.getValue());
sContent.setXmlBase(content.getXmlBase());
return sContent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,13 @@ private Content parseContent(final Element e) {
final String value = parseTextConstructToString(e);
final String src = getAttributeValue(e, "src");
final String type = getAttributeValue(e, "type");
final String xmlBase = e.getAttributeValue("base", Namespace.XML_NAMESPACE);

final Content content = new Content();
content.setSrc(src);
content.setType(type);
content.setValue(value);
content.setXmlBase(xmlBase);
return content;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
import org.junit.Test;

import com.rometools.rome.feed.atom.Entry;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.XmlReader;

public class Atom10ParserTest {

Expand Down Expand Up @@ -41,4 +45,14 @@ public void testParseEntryCatchingXxe() throws IllegalArgumentException, JDOMExc

}

@Test
public void testIssue689() throws Exception {
String url = "http://feeds.kottke.org/main";
SyndFeed feed = new SyndFeedInput().build(new XmlReader(new java.net.URL(url)));
for (SyndEntry e : feed.getEntries()) {
assertEquals("https://kottke.org/", e.getContents().iterator().next().getXmlBase());
}

}

}

0 comments on commit 17bf0d2

Please sign in to comment.