aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaneren2005 <daneren2005@gmail.com>2013-11-05 16:40:48 -0800
committerdaneren2005 <daneren2005@gmail.com>2013-11-05 16:40:48 -0800
commit483780f829911727c5ac433f9c804a6410f6f350 (patch)
tree569e7062513e020c31678e4c53edac592c9f5a5a
parent2fda1e7582b7a377ccb6d69658ba9ee942f4c806 (diff)
downloaddsub-483780f829911727c5ac433f9c804a6410f6f350.tar.gz
dsub-483780f829911727c5ac433f9c804a6410f6f350.tar.bz2
dsub-483780f829911727c5ac433f9c804a6410f6f350.zip
Added BookmarkParser
-rw-r--r--src/github/daneren2005/dsub/service/parser/BookmarkParser.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/github/daneren2005/dsub/service/parser/BookmarkParser.java b/src/github/daneren2005/dsub/service/parser/BookmarkParser.java
new file mode 100644
index 00000000..8af509f0
--- /dev/null
+++ b/src/github/daneren2005/dsub/service/parser/BookmarkParser.java
@@ -0,0 +1,73 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2013 (C) Scott Jackson
+*/
+package github.daneren2005.dsub.service.parser;
+
+import android.content.Context;
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.Bookmark;
+import github.daneren2005.dsub.util.ProgressListener;
+import org.xmlpull.v1.XmlPullParser;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Scott Jackson
+ */
+public class BookmarkParser extends MusicDirectoryEntryParser {
+ public BookmarkParser(Context context) {
+ super(context);
+ }
+
+ public List<Bookmark> parse(Reader reader, ProgressListener progressListener) throws Exception {
+ updateProgress(progressListener, R.string.parser_reading);
+ init(reader);
+
+ List<Bookmark> bookmarks = new ArrayList<Bookmark>();
+ Bookmark bookmark = null;
+ int eventType;
+
+ do {
+ eventType = nextParseEvent();
+
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+
+ if ("bookmark".equals(name)) {
+ bookmark = new Bookmark();
+ bookmark.setChanged(get("changed"));
+ bookmark.setCreated(get("created"));
+ bookmark.setComment(get("comment"));
+ bookmark.setPosition(getInteger("position"));
+ bookmark.setUsername(get("username"));
+ } else if ("entry".equals(name)) {
+ bookmark.setEntry(parseEntry(null));
+ bookmarks.add(bookmark);
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+ updateProgress(progressListener, R.string.parser_reading_done);
+
+ return bookmarks;
+ }
+}