net.liftmodules.widgets.rssfeed.RSSfeed.scala Maven / Gradle / Ivy
/*
* Copyright 2007-2010 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.liftmodules {
package widgets {
package rssfeed {
import _root_.scala.xml._
import _root_.java.net.{URLConnection, URL}
import net.liftweb.util.Helpers._
import scala.collection.mutable.Queue
object RSSFeed {
/**
* Renders an RSS feed using a list
*/
def apply(feedUrl: String) = new RSSFeed().render(feedUrl)
}
class RSSFeed {
/**
* Renders an RSS feed using a list
*/
def render(feedUrl: String): NodeSeq = {
val feed = getFeed(feedUrl)
var src = new Queue[Node]()
src += { ( feed \ "channel" \ "title" ).text }
for (c <- findElems(feed){_.label == "item"}) {
src += {(c \\ "title").text}
}
}
/**
* Returns the feed as a plain XML
*/
def getFeed(feedUrl: String): Elem = {
val u = new URL(feedUrl)
val con = u.openConnection
val is = con.getInputStream
doClose(is) {
XML.load(is)
}
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy