root/trunk/as2/com/jeroenwijering/feeds/XSPFParser.as @ 1

Revision 1, 2.1 kB (checked in by jeroen, 18 months ago)

initial commit of old repository into public one

  • Property svn:executable set to *
Line 
1/**
2* Parses ATOM feeds and returns an indexed array with all elements.
3*
4* @author       Jeroen Wijering
5* @version      1.5
6**/
7
8
9import com.jeroenwijering.feeds.AbstractParser;
10import com.jeroenwijering.utils.StringMagic;
11
12
13class com.jeroenwijering.feeds.XSPFParser extends AbstractParser {
14
15
16        /** Contructor **/
17        function XSPFParser() { super(); };
18
19
20        /** build an array with all regular elements **/
21        private function setElements() {
22                elements = new Object();
23                elements["title"] = "title";
24                elements["creator"] = "author";
25                elements["info"] = "link";
26                elements["image"] = "image";
27                elements["identifier"] = "id";
28                elements["album"] = "category";
29        };
30
31
32        /** Convert ATOM structure to array **/
33        private function parse(xml:XML):Array {
34                var arr = new Array();
35                var tpl = xml.firstChild.firstChild;
36                while(tpl != null) {
37                        if (tpl.nodeName == 'trackList') {
38                                for(var i=0; i<tpl.childNodes.length; i++) {
39                                        var obj = new Object();
40                                        for(var j=0; j<tpl.childNodes[i].childNodes.length; j++) {
41                                                var nod:XMLNode = tpl.childNodes[i].childNodes[j];
42                                                var nnm = nod.nodeName.toLowerCase();
43                                                if(elements[nnm]!=undefined) {
44                                                        obj[elements[nnm]] = nod.firstChild.nodeValue;
45                                                } else if(nnm == "location"  && obj['type']!="flv") {
46                                                        obj["file"] = nod.firstChild.nodeValue;
47                                                        var typ = obj["file"].substr(-3).toLowerCase();
48                                                        if(obj["file"].substr(0,4) == "rtmp") {
49                                                                obj["type"] = "rtmp";
50                                                        } else if(obj['file'].indexOf('youtube.com') > -1) {
51                                                                obj["type"] = "youtube";
52                                                        } else if(mimetypes[typ] != undefined) {
53                                                                obj["type"] = mimetypes[typ];
54                                                        }
55                                                } else if(nnm == "annotation") {
56                                                        obj["description"] = StringMagic.stripTagsBreaks(
57                                                                nod.firstChild.nodeValue);
58                                                } else if(nnm == "link" &&
59                                                        nod.attributes.rel == "captions") {
60                                                        obj["captions"] = nod.firstChild.nodeValue;
61                                                } else if(nnm == "link" &&
62                                                        nod.attributes.rel == "audio") {
63                                                        obj["audio"] = nod.firstChild.nodeValue;
64                                                } else if(nnm == "meta") {
65                                                        obj[nod.attributes.rel] = nod.firstChild.nodeValue;
66                                                }
67                                        }
68                                        arr.push(obj);
69                                }
70                        }
71                        tpl = tpl.nextSibling;
72                }
73                return arr;
74        };
75
76
77}
Note: See TracBrowser for help on using the browser.