[jboss-svn-commits] JBL Code SVN: r19514 - labs/jbosslabs/trunk/other.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Apr 10 06:57:06 EDT 2008
Author: wrzep
Date: 2008-04-10 06:57:06 -0400 (Thu, 10 Apr 2008)
New Revision: 19514
Added:
labs/jbosslabs/trunk/other/informaAtomEnclosure.patch
Log:
informa patch to make it work with atom 1.0 enclosures
Added: labs/jbosslabs/trunk/other/informaAtomEnclosure.patch
===================================================================
--- labs/jbosslabs/trunk/other/informaAtomEnclosure.patch (rev 0)
+++ labs/jbosslabs/trunk/other/informaAtomEnclosure.patch 2008-04-10 10:57:06 UTC (rev 19514)
@@ -0,0 +1,122 @@
+Index: src/de/nava/informa/parsers/Atom_1_0_Parser.java
+===================================================================
+RCS file: /cvsroot/informa/informa/src/de/nava/informa/parsers/Atom_1_0_Parser.java,v
+retrieving revision 1.11
+diff -u -r1.11 Atom_1_0_Parser.java
+--- src/de/nava/informa/parsers/Atom_1_0_Parser.java 24 Jun 2007 19:06:06 -0000 1.11
++++ src/de/nava/informa/parsers/Atom_1_0_Parser.java 10 Apr 2008 10:36:01 -0000
+@@ -32,6 +32,7 @@
+ import org.apache.commons.logging.LogFactory;
+ import org.jdom.Element;
+ import org.jdom.Namespace;
++import org.jdom.Attribute;
+
+ import de.nava.informa.core.*;
+ import de.nava.informa.utils.AtomParserUtils;
+@@ -316,7 +317,40 @@
+ ItemIF curItem = cBuilder.createItem(item, chnl, strTitle, strDesc,
+ ParserUtils.getURL(strLink));
+
+- //TODO enclosure data
++ // get enclosure element
++ // Atom allows more than one enclosure per item. In such a case
++ // item.getEnclosure() will retreive the first one.
++ Element elEnclosure = AtomParserUtils.getItemLinkElement(item,
++ defNS,
++ "enclosure");
++
++ if (elEnclosure != null) {
++ URL location = null;
++ String type = null;
++ int length = -1;
++ Attribute urlAttribute = elEnclosure.getAttribute("href");
++
++ if (urlAttribute != null) {
++ location = ParserUtils.getURL(urlAttribute.getValue().trim());
++ }
++ Attribute typeAttribute = elEnclosure.getAttribute("type");
++ if (typeAttribute != null) {
++ type = typeAttribute.getValue().trim();
++ }
++ Attribute lengthAttribute = elEnclosure.getAttribute("length");
++ if (lengthAttribute != null) {
++ try {
++ length = Integer.parseInt(lengthAttribute.getValue().trim());
++ } catch (NumberFormatException e) {
++ LOGGER.warn(e);
++ }
++ }
++
++ ItemEnclosureIF itemEnclosure = cBuilder.createItemEnclosure(curItem,
++ location, type, length);
++ curItem.setEnclosure(itemEnclosure);
++ }
++
+ curItem.setFound(dateParsed);
+
+ List itemAuthors = item.getChildren("author", defNS);
+Index: src/de/nava/informa/utils/AtomParserUtils.java
+===================================================================
+RCS file: /cvsroot/informa/informa/src/de/nava/informa/utils/AtomParserUtils.java,v
+retrieving revision 1.6
+diff -u -r1.6 AtomParserUtils.java
+--- src/de/nava/informa/utils/AtomParserUtils.java 6 Jan 2007 21:33:45 -0000 1.6
++++ src/de/nava/informa/utils/AtomParserUtils.java 10 Apr 2008 10:36:01 -0000
+@@ -169,6 +169,36 @@
+ }
+
+ /**
++ * Looks for link sub-elements of type "link" and selects the first one with
++ * given "rel" attribute.
++ *
++ * @param item item element.
++ * @param defNS default namespace.
++ * @param rel desired link rel attribute
++ *
++ * @return link in string or <code>null</code>.
++ */
++ public static Element getItemLinkElement(Element item, Namespace defNS, String rel) {
++
++ List links = item.getChildren("link", defNS);
++
++ for (int i = 0; i < links.size(); i++) {
++ Element link = (Element) links.get(i);
++
++ String linkRel = link.getAttributeValue("rel");
++
++ if (rel.equalsIgnoreCase(linkRel)) {
++ LOGGER.debug("link element read : " + link.getAttributeValue("href") + " rel : " + rel);
++ return link;
++ }
++ }
++
++ LOGGER.debug("link element not found, rel : " + rel);
++
++ return null;
++ }
++
++ /**
+ * Returns value of the element.
+ * @param elt the element to retrieve the value from.
+ * @param mode can be one of "escaped", "base64" or "xml". If null, "xml" is assumed.
+Index: test/src/de/nava/informa/parsers/TestAtom_1_0_Parser.java
+===================================================================
+RCS file: /cvsroot/informa/informa/test/src/de/nava/informa/parsers/TestAtom_1_0_Parser.java,v
+retrieving revision 1.10
+diff -u -r1.10 TestAtom_1_0_Parser.java
+--- test/src/de/nava/informa/parsers/TestAtom_1_0_Parser.java 24 Jun 2007 19:54:25 -0000 1.10
++++ test/src/de/nava/informa/parsers/TestAtom_1_0_Parser.java 10 Apr 2008 10:36:03 -0000
+@@ -206,6 +206,13 @@
+ .contains("<li>00:15:00 -- Talking about Atom 1.0</li>"));
+ assertTrue(item.getDescription().contains("<li>00:30:00 -- Wrapping up</li>"));
+ assertEquals("http://www.example.org/entries/1", item.getLink().toString());
++
++ //test enclosure
++ ItemEnclosureIF enclosure = item.getEnclosure();
++ assertEquals(enclosure.getType(), "audio/mpeg");
++ assertNotNull(enclosure.getLocation());
++ assertEquals(enclosure.getLocation().toString(), "http://www.example.org/myaudiofile.mp3");
++ assertEquals(enclosure.getLength(), 1234);
+ }
+
+ public void testPreferenceOrder() {
More information about the jboss-svn-commits
mailing list