/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
* Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Oracle Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package fxpodcastviewer.feed;
import java.io.InputStream;
import javafx.data.pull.PullParser;
import javafx.data.pull.Event;
import java.lang.IllegalArgumentException;
public class PodcastMedia {
public var parentFeed:PodcastFeed;
public var fromStore = false;
public var mediaURL:String;
public var data:String on replace {
if ( data == null ) {
data = "";
}
}
public var publisher:String;
public var pubDate:String;
public var title:String on replace {
if ( title == null ) {
title = "";
}
}
public var type:String ;
public var image:String ;
public var length:Long;
public override function toString(){
"<podcast><mediaURL>{mediaURL}</mediaURL><data>{data}</data><publisher>"
"{publisher}</publisher><pubDate>{pubDate}</pubDate><title>{title}</title>"
"<type>{type}</type><image>{image}</image><length>{length}</length></podcast>"
}
public override function equals(obj:Object):Boolean{
if ( not (obj instanceof PodcastMedia)){
throw new IllegalArgumentException("Expectes PodcastMedia");
}
var pM = obj as PodcastMedia;
return ( pM.mediaURL == mediaURL)
}
public override function clone():PodcastMedia{
PodcastMedia{
title:title
data:data
fromStore:fromStore
image:image
length:length
mediaURL:mediaURL
pubDate:pubDate
publisher:publisher
type:type
}
}
}
public function fromXML(input:InputStream){
var medias:PodcastMedia[];
var media:PodcastMedia;
var parser:PullParser = PullParser{
input:input
documentType:PullParser.XML
onEvent:function(e:Event){
println(e);
if ( e.type == PullParser.TEXT){
if ( e.qname.name == "mediaURL" ){
media.mediaURL = e.text;
}else if (e.qname.name == "data"){
media.data = e.text;
}else if (e.qname.name == "publisher"){
media.publisher = e.text;
}else if (e.qname.name == "pubDate"){
media.pubDate = e.text
}else if (e.qname.name == "title"){
media.title = e.text
}else if (e.qname.name == "type"){
media.type = e.text
}else if (e.qname.name == "image"){
media.image = e.text
}else if (e.qname.name == "length"){
media.length = Long.parseLong(e.text);
}
}else if (e.type == PullParser.START_ELEMENT and e.qname.name == "podcast"){
media = PodcastMedia{fromStore:true};
}else if (e.type == PullParser.END_ELEMENT and e.qname.name == "podcast"){
insert media into medias;
}
}
}
parser.parse();
medias;
}