summaryrefslogtreecommitdiffstats
path: root/js/build/app/services/opmlparser.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/build/app/services/opmlparser.js')
-rw-r--r--js/build/app/services/opmlparser.js111
1 files changed, 111 insertions, 0 deletions
diff --git a/js/build/app/services/opmlparser.js b/js/build/app/services/opmlparser.js
new file mode 100644
index 000000000..b80f67da9
--- /dev/null
+++ b/js/build/app/services/opmlparser.js
@@ -0,0 +1,111 @@
+// Generated by CoffeeScript 1.6.3
+/*
+
+ownCloud - News
+
+@author Bernhard Posselt
+@copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+License as published by the Free Software Foundation; either
+version 3 of the License, or any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+
+You should have received a copy of the GNU Affero General Public
+License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+(function() {
+ angular.module('News').factory('OPMLParser', function() {
+ var Feed, Folder, OPMLParser;
+ Feed = (function() {
+ function Feed(_name, _url) {
+ this._name = _name;
+ this._url = _url;
+ }
+
+ Feed.prototype.getName = function() {
+ return this._name;
+ };
+
+ Feed.prototype.getUrl = function() {
+ return this._url;
+ };
+
+ Feed.prototype.isFolder = function() {
+ return false;
+ };
+
+ return Feed;
+
+ })();
+ Folder = (function() {
+ function Folder(_name) {
+ this._name = _name;
+ this._items = [];
+ }
+
+ Folder.prototype.add = function(feed) {
+ return this._items.push(feed);
+ };
+
+ Folder.prototype.getItems = function() {
+ return this._items;
+ };
+
+ Folder.prototype.getName = function() {
+ return this._name;
+ };
+
+ Folder.prototype.isFolder = function() {
+ return true;
+ };
+
+ return Folder;
+
+ })();
+ OPMLParser = (function() {
+ function OPMLParser() {}
+
+ OPMLParser.prototype.parseXML = function(xml) {
+ var $root, $xml, structure;
+ $xml = $($.parseXML(xml));
+ $root = $xml.find('body');
+ structure = new Folder('root');
+ this._recursivelyParse($root, structure);
+ return structure;
+ };
+
+ OPMLParser.prototype._recursivelyParse = function($xml, structure) {
+ var $outline, feed, folder, outline, title, _i, _len, _ref, _results;
+ _ref = $xml.children('outline');
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ outline = _ref[_i];
+ $outline = $(outline);
+ if (angular.isDefined($outline.attr('xmlUrl'))) {
+ feed = new Feed($outline.attr('text'), $outline.attr('xmlUrl'));
+ _results.push(structure.add(feed));
+ } else {
+ title = $outline.attr('text') || $outline.attr('title');
+ folder = new Folder(title);
+ structure.add(folder);
+ _results.push(this._recursivelyParse($outline, folder));
+ }
+ }
+ return _results;
+ };
+
+ return OPMLParser;
+
+ })();
+ return new OPMLParser();
+ });
+
+}).call(this);