Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improving SyndContent as #689 requested #690

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -502,6 +502,12 @@ protected void fillContentElement(final Element contentElement, final Content co
}

}

final String xmlBase = content.getXmlBase();
if (xmlBase != null) {
final Attribute xmlBaseAttribute = new Attribute("base", xmlBase, Namespace.XML_NAMESPACE);
contentElement.setAttribute(xmlBaseAttribute);
}
}

protected Element generateGeneratorElement(final Generator generator) {
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());
}

}

}