diff --git a/pom.xml b/pom.xml
index 4c225b2..e58c56b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,6 +76,12 @@
junit
test
+
+ xmlunit
+ xmlunit
+ 1.6
+ test
+
diff --git a/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java
index 707b4c5..dfb0368 100644
--- a/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java
+++ b/src/main/java/com/rometools/opml/io/impl/OPML10Generator.java
@@ -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;
diff --git a/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java b/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java
index 7d4f7d6..576182e 100644
--- a/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java
+++ b/src/main/java/com/rometools/opml/io/impl/OPML10Parser.java
@@ -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);
+ }
}
}
diff --git a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java
index 68dacb9..c87dbfe 100644
--- a/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java
+++ b/src/main/java/com/rometools/opml/io/impl/OPML20Generator.java
@@ -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;
diff --git a/src/test/java/com/rometools/opml/FeedOpsTest.java b/src/test/java/com/rometools/opml/FeedOpsTest.java
index 122bc1d..5eb5f61 100644
--- a/src/test/java/com/rometools/opml/FeedOpsTest.java
+++ b/src/test/java/com/rometools/opml/FeedOpsTest.java
@@ -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();
diff --git a/src/test/java/com/rometools/opml/TestXmlReader.java b/src/test/java/com/rometools/opml/TestXmlReader.java
index d2e8ff9..a7137a0 100644
--- a/src/test/java/com/rometools/opml/TestXmlReader.java
+++ b/src/test/java/com/rometools/opml/TestXmlReader.java
@@ -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();
}