Merge pull request #4 from Athou/master

Fixes head generation in OPML10Generator #2
This commit is contained in:
Patrick Gotthard 2016-01-08 17:54:20 +01:00
commit ac9dc0df5c
6 changed files with 95 additions and 54 deletions

View file

@ -76,6 +76,12 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.6</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View file

@ -67,6 +67,7 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe
final Opml opml = (Opml) feed;
final Document doc = new Document();
final Element root = new Element("opml");
root.setAttribute("version", "1.0");
doc.addContent(root);
final Element head = generateHead(opml);
@ -110,23 +111,23 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe
boolean hasHead = false;
if (opml.getCreated() != null) {
hasHead = addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated(), Locale.US));
hasHead |= addNotNullSimpleElement(head, "dateCreated", DateParser.formatRFC822(opml.getCreated(), Locale.US));
}
hasHead = addNotNullSimpleElement(head, "expansionState", intArrayToCsvString(opml.getExpansionState()));
hasHead |= addNotNullSimpleElement(head, "expansionState", intArrayToCsvString(opml.getExpansionState()));
if (opml.getModified() != null) {
hasHead = addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified(), Locale.US));
hasHead |= addNotNullSimpleElement(head, "dateModified", DateParser.formatRFC822(opml.getModified(), Locale.US));
}
hasHead = addNotNullSimpleElement(head, "ownerEmail", opml.getOwnerEmail());
hasHead = addNotNullSimpleElement(head, "ownerName", opml.getOwnerName());
hasHead = addNotNullSimpleElement(head, "title", opml.getTitle());
hasHead = addNotNullSimpleElement(head, "vertScrollState", opml.getVerticalScrollState());
hasHead = addNotNullSimpleElement(head, "windowBottom", opml.getWindowBottom());
hasHead = addNotNullSimpleElement(head, "windowLeft", opml.getWindowLeft());
hasHead = addNotNullSimpleElement(head, "windowRight", opml.getWindowRight());
hasHead = addNotNullSimpleElement(head, "windowTop", opml.getWindowTop());
hasHead |= addNotNullSimpleElement(head, "ownerEmail", opml.getOwnerEmail());
hasHead |= addNotNullSimpleElement(head, "ownerName", opml.getOwnerName());
hasHead |= addNotNullSimpleElement(head, "title", opml.getTitle());
hasHead |= addNotNullSimpleElement(head, "vertScrollState", opml.getVerticalScrollState());
hasHead |= addNotNullSimpleElement(head, "windowBottom", opml.getWindowBottom());
hasHead |= addNotNullSimpleElement(head, "windowLeft", opml.getWindowLeft());
hasHead |= addNotNullSimpleElement(head, "windowRight", opml.getWindowRight());
hasHead |= addNotNullSimpleElement(head, "windowTop", opml.getWindowTop());
if (hasHead) {
return head;

View file

@ -106,61 +106,61 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
opml.setOwnerName(head.getChildTextTrim("ownerName"));
opml.setOwnerEmail(head.getChildTextTrim("ownerEmail"));
opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState")));
}
try {
opml.setWindowBottom(readInteger(head.getChildText("windowBottom")));
} catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowBottom", nfe);
try {
opml.setWindowBottom(readInteger(head.getChildText("windowBottom")));
} catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowBottom", nfe);
if (validate) {
throw new FeedException("Unable to parse windowBottom", nfe);
if (validate) {
throw new FeedException("Unable to parse windowBottom", nfe);
}
}
}
try {
opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
} catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowLeft", nfe);
}
try {
opml.setWindowRight(readInteger(head.getChildText("windowRight")));
} catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowRight", nfe);
if (validate) {
throw new FeedException("Unable to parse windowRight", nfe);
try {
opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
} catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowLeft", nfe);
}
}
try {
opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
} catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowLeft", nfe);
try {
opml.setWindowRight(readInteger(head.getChildText("windowRight")));
} catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowRight", nfe);
if (validate) {
throw new FeedException("Unable to parse windowLeft", nfe);
if (validate) {
throw new FeedException("Unable to parse windowRight", nfe);
}
}
}
try {
opml.setWindowTop(readInteger(head.getChildText("windowTop")));
} catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowTop", nfe);
try {
opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
} catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowLeft", nfe);
if (validate) {
throw new FeedException("Unable to parse windowTop", nfe);
if (validate) {
throw new FeedException("Unable to parse windowLeft", nfe);
}
}
}
try {
opml.setExpansionState(readIntArray(head.getChildText("expansionState")));
} catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse expansionState", nfe);
try {
opml.setWindowTop(readInteger(head.getChildText("windowTop")));
} catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse windowTop", nfe);
if (validate) {
throw new FeedException("Unable to parse expansionState", nfe);
if (validate) {
throw new FeedException("Unable to parse windowTop", nfe);
}
}
try {
opml.setExpansionState(readIntArray(head.getChildText("expansionState")));
} catch (final NumberFormatException nfe) {
LOG.warn("Unable to parse expansionState", nfe);
if (validate) {
throw new FeedException("Unable to parse expansionState", nfe);
}
}
}

View file

@ -67,7 +67,8 @@ public class OPML20Generator extends OPML10Generator {
retValue = super.generateHead(opml);
final Element docs = new Element("docs", opml.getDocs());
final Element docs = new Element("docs");
docs.setText(opml.getDocs());
retValue.addContent(docs);
return retValue;

View file

@ -6,9 +6,18 @@ import java.io.File;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
import org.jdom2.Document;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import com.rometools.rome.feed.WireFeed;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.feed.synd.SyndFeedImpl;
import com.rometools.rome.io.WireFeedOutput;
/**
*
@ -64,6 +73,27 @@ public abstract class FeedOpsTest extends FeedTest {
assertTrue(feed1.equals(feed2));
}
// 1.5
public void testWireFeedJDOMSerialization() throws Exception {
Document inputDoc = getCachedJDomDoc();
final WireFeed feed = getCachedWireFeed();
WireFeedOutput output = new WireFeedOutput();
Document outputDoc = output.outputJDom(feed);
XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat());
String inputString = outputter.outputString(inputDoc);
String outputString = outputter.outputString(outputDoc);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreAttributeOrder(true);
Diff diff = XMLUnit.compareXML(inputString, outputString);
// ignore elements order
diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
XMLAssert.assertXMLEqual(diff, true);
}
// 1.6
public void testWireFeedSyndFeedConversion() throws Exception {
final SyndFeed sFeed1 = getCachedSyndFeed();

View file

@ -51,14 +51,17 @@ public class TestXmlReader extends TestCase {
InputStream is = getXmlStream("no-bom", "xml", encoding, encoding);
XmlReader xmlReader = new XmlReader(is, false);
assertEquals(xmlReader.getEncoding(), "UTF-8");
xmlReader.close();
is = getXmlStream("no-bom", "xml-prolog", encoding, encoding);
xmlReader = new XmlReader(is);
assertEquals(xmlReader.getEncoding(), "UTF-8");
xmlReader.close();
is = getXmlStream("no-bom", "xml-prolog-encoding", encoding, encoding);
xmlReader = new XmlReader(is);
assertEquals(xmlReader.getEncoding(), encoding);
xmlReader.close();
}