1 26 27 29 package de.nava.informa.parsers; 30 31 import java.util.ArrayList ; 32 import java.util.Collection ; 33 import java.util.Date ; 34 import java.util.Iterator ; 35 import java.util.List ; 36 37 import org.apache.commons.logging.Log; 38 import org.apache.commons.logging.LogFactory; 39 import org.jdom.Attribute; 40 import org.jdom.Element; 41 42 import de.nava.informa.core.FeedIF; 43 import de.nava.informa.core.ParseException; 44 import de.nava.informa.impl.basic.Feed; 45 import de.nava.informa.utils.ParserUtils; 46 47 53 class OPML_1_1_Parser { 54 55 private static Log logger = LogFactory.getLog(OPML_1_1_Parser.class); 56 57 static Collection parse(Element root) throws ParseException { 58 59 Collection feedColl = new ArrayList (); 60 61 Date dateParsed = new Date (); 62 logger.debug("start parsing."); 63 64 Element headElem = root.getChild("head"); 66 String title = headElem.getChildTextTrim("title"); 67 68 Element bodyElem = root.getChild("body"); 70 71 List feeds = bodyElem.getChildren("outline"); 73 Iterator i = feeds.iterator(); 74 while (i.hasNext()) { 75 Element feedElem = (Element) i.next(); 76 Attribute attrTitle = feedElem.getAttribute("title"); 78 String strTitle = "[No Title]"; 79 if (attrTitle != null) { 80 strTitle = attrTitle.getValue(); 81 } 82 FeedIF feed = new Feed(strTitle); 83 if (logger.isDebugEnabled()) { 84 logger.debug("Feed element found (" + strTitle + ")."); 85 } 86 Attribute attrText = feedElem.getAttribute("text"); 88 String strText = "[No Text]"; 89 if (attrText != null) { 90 strText = attrText.getValue(); 91 } 92 feed.setText(strText); 93 Attribute attrType = feedElem.getAttribute("type"); 95 String strType = "text/xml"; 96 if (attrType != null) { 97 strType = attrType.getValue(); 98 } 99 feed.setContentType(strType); 100 101 103 Attribute attrXmlUrl = feedElem.getAttribute("xmlUrl"); 105 if (attrXmlUrl != null && attrXmlUrl.getValue() != null) { 106 feed.setLocation(ParserUtils.getURL(attrXmlUrl.getValue())); 107 } 108 Attribute attrHtmlUrl = feedElem.getAttribute("htmlUrl"); 110 if (attrHtmlUrl != null && attrHtmlUrl.getValue() != null) { 111 feed.setSite(ParserUtils.getURL(attrHtmlUrl.getValue())); 112 } 113 feed.setDateFound(dateParsed); 115 feedColl.add(feed); 117 } 118 119 return feedColl; 120 } 121 122 } 123 | Popular Tags |