Merge pull request #4 from Athou/master
Fixes head generation in OPML10Generator #2
This commit is contained in:
commit
ac9dc0df5c
6 changed files with 95 additions and 54 deletions
6
pom.xml
6
pom.xml
|
@ -76,6 +76,12 @@
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>xmlunit</groupId>
|
||||||
|
<artifactId>xmlunit</artifactId>
|
||||||
|
<version>1.6</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -67,6 +67,7 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe
|
||||||
final Opml opml = (Opml) feed;
|
final Opml opml = (Opml) feed;
|
||||||
final Document doc = new Document();
|
final Document doc = new Document();
|
||||||
final Element root = new Element("opml");
|
final Element root = new Element("opml");
|
||||||
|
root.setAttribute("version", "1.0");
|
||||||
doc.addContent(root);
|
doc.addContent(root);
|
||||||
|
|
||||||
final Element head = generateHead(opml);
|
final Element head = generateHead(opml);
|
||||||
|
@ -110,23 +111,23 @@ public class OPML10Generator extends BaseWireFeedGenerator implements WireFeedGe
|
||||||
boolean hasHead = false;
|
boolean hasHead = false;
|
||||||
|
|
||||||
if (opml.getCreated() != null) {
|
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) {
|
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, "ownerEmail", opml.getOwnerEmail());
|
||||||
hasHead = addNotNullSimpleElement(head, "ownerName", opml.getOwnerName());
|
hasHead |= addNotNullSimpleElement(head, "ownerName", opml.getOwnerName());
|
||||||
hasHead = addNotNullSimpleElement(head, "title", opml.getTitle());
|
hasHead |= addNotNullSimpleElement(head, "title", opml.getTitle());
|
||||||
hasHead = addNotNullSimpleElement(head, "vertScrollState", opml.getVerticalScrollState());
|
hasHead |= addNotNullSimpleElement(head, "vertScrollState", opml.getVerticalScrollState());
|
||||||
hasHead = addNotNullSimpleElement(head, "windowBottom", opml.getWindowBottom());
|
hasHead |= addNotNullSimpleElement(head, "windowBottom", opml.getWindowBottom());
|
||||||
hasHead = addNotNullSimpleElement(head, "windowLeft", opml.getWindowLeft());
|
hasHead |= addNotNullSimpleElement(head, "windowLeft", opml.getWindowLeft());
|
||||||
hasHead = addNotNullSimpleElement(head, "windowRight", opml.getWindowRight());
|
hasHead |= addNotNullSimpleElement(head, "windowRight", opml.getWindowRight());
|
||||||
hasHead = addNotNullSimpleElement(head, "windowTop", opml.getWindowTop());
|
hasHead |= addNotNullSimpleElement(head, "windowTop", opml.getWindowTop());
|
||||||
|
|
||||||
if (hasHead) {
|
if (hasHead) {
|
||||||
return head;
|
return head;
|
||||||
|
|
|
@ -106,7 +106,6 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
|
||||||
opml.setOwnerName(head.getChildTextTrim("ownerName"));
|
opml.setOwnerName(head.getChildTextTrim("ownerName"));
|
||||||
opml.setOwnerEmail(head.getChildTextTrim("ownerEmail"));
|
opml.setOwnerEmail(head.getChildTextTrim("ownerEmail"));
|
||||||
opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState")));
|
opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState")));
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
opml.setWindowBottom(readInteger(head.getChildText("windowBottom")));
|
opml.setWindowBottom(readInteger(head.getChildText("windowBottom")));
|
||||||
|
@ -163,6 +162,7 @@ public class OPML10Parser extends BaseWireFeedParser implements WireFeedParser {
|
||||||
throw new FeedException("Unable to parse expansionState", nfe);
|
throw new FeedException("Unable to parse expansionState", nfe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate, locale));
|
opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate, locale));
|
||||||
opml.setModules(parseFeedModules(root, locale));
|
opml.setModules(parseFeedModules(root, locale));
|
||||||
|
|
|
@ -67,7 +67,8 @@ public class OPML20Generator extends OPML10Generator {
|
||||||
|
|
||||||
retValue = super.generateHead(opml);
|
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);
|
retValue.addContent(docs);
|
||||||
|
|
||||||
return retValue;
|
return retValue;
|
||||||
|
|
|
@ -6,9 +6,18 @@ import java.io.File;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
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.WireFeed;
|
||||||
import com.rometools.rome.feed.synd.SyndFeed;
|
import com.rometools.rome.feed.synd.SyndFeed;
|
||||||
import com.rometools.rome.feed.synd.SyndFeedImpl;
|
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));
|
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
|
// 1.6
|
||||||
public void testWireFeedSyndFeedConversion() throws Exception {
|
public void testWireFeedSyndFeedConversion() throws Exception {
|
||||||
final SyndFeed sFeed1 = getCachedSyndFeed();
|
final SyndFeed sFeed1 = getCachedSyndFeed();
|
||||||
|
|
|
@ -51,14 +51,17 @@ public class TestXmlReader extends TestCase {
|
||||||
InputStream is = getXmlStream("no-bom", "xml", encoding, encoding);
|
InputStream is = getXmlStream("no-bom", "xml", encoding, encoding);
|
||||||
XmlReader xmlReader = new XmlReader(is, false);
|
XmlReader xmlReader = new XmlReader(is, false);
|
||||||
assertEquals(xmlReader.getEncoding(), "UTF-8");
|
assertEquals(xmlReader.getEncoding(), "UTF-8");
|
||||||
|
xmlReader.close();
|
||||||
|
|
||||||
is = getXmlStream("no-bom", "xml-prolog", encoding, encoding);
|
is = getXmlStream("no-bom", "xml-prolog", encoding, encoding);
|
||||||
xmlReader = new XmlReader(is);
|
xmlReader = new XmlReader(is);
|
||||||
assertEquals(xmlReader.getEncoding(), "UTF-8");
|
assertEquals(xmlReader.getEncoding(), "UTF-8");
|
||||||
|
xmlReader.close();
|
||||||
|
|
||||||
is = getXmlStream("no-bom", "xml-prolog-encoding", encoding, encoding);
|
is = getXmlStream("no-bom", "xml-prolog-encoding", encoding, encoding);
|
||||||
xmlReader = new XmlReader(is);
|
xmlReader = new XmlReader(is);
|
||||||
assertEquals(xmlReader.getEncoding(), encoding);
|
assertEquals(xmlReader.getEncoding(), encoding);
|
||||||
|
xmlReader.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue