Clover Coverage Report - Subsonic-Android Coverage Report
Coverage timestamp: ven dic 19 2014 17:57:13 EST
../../../../../../img/srcFileCovDistChart8.png 45% of files have more coverage
47   138   27   3,13
16   96   0,57   15
15     1,8  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  AbstractParser       Line # 35 47 27 75,6% 0.75641024
 
No Tests
 
1    /*
2    This file is part of Subsonic.
3   
4    Subsonic is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8   
9    Subsonic is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12    GNU General Public License for more details.
13   
14    You should have received a copy of the GNU General Public License
15    along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
16   
17    Copyright 2009 (C) Sindre Mehus
18    */
19    package net.sourceforge.subsonic.androidapp.service.parser;
20   
21    import java.io.Reader;
22   
23    import org.xmlpull.v1.XmlPullParser;
24   
25    import android.content.Context;
26    import android.util.Xml;
27    import net.sourceforge.subsonic.androidapp.R;
28    import net.sourceforge.subsonic.androidapp.domain.Version;
29    import net.sourceforge.subsonic.androidapp.util.ProgressListener;
30    import net.sourceforge.subsonic.androidapp.util.Util;
31   
32    /**
33    * @author Sindre Mehus
34    */
 
35    public abstract class AbstractParser {
36   
37    private final Context context;
38    private XmlPullParser parser;
39    private boolean rootElementFound;
40   
 
41  36 toggle public AbstractParser(Context context) {
42  36 this.context = context;
43    }
44   
 
45  3 toggle protected Context getContext() {
46  3 return context;
47    }
48   
 
49  8 toggle protected void handleError() throws Exception {
50  8 int code = getInteger("code");
51  8 String message;
52  8 switch (code) {
53  0 case 20:
54  0 message = context.getResources().getString(R.string.parser_upgrade_client);
55  0 break;
56  0 case 30:
57  0 message = context.getResources().getString(R.string.parser_upgrade_server);
58  0 break;
59  0 case 40:
60  0 message = context.getResources().getString(R.string.parser_not_authenticated);
61  0 break;
62  4 case 50:
63  4 message = context.getResources().getString(R.string.parser_not_authorized);
64  4 break;
65  4 default:
66  4 message = get("message");
67  4 break;
68    }
69  8 throw new SubsonicRESTException(code, message);
70    }
71   
 
72  44 toggle protected void updateProgress(ProgressListener progressListener, int messageId) {
73  44 if (progressListener != null) {
74  34 progressListener.updateProgress(messageId);
75    }
76    }
77   
 
78  3 toggle protected void updateProgress(ProgressListener progressListener, String message) {
79  3 if (progressListener != null) {
80  3 progressListener.updateProgress(message);
81    }
82    }
83   
 
84  1 toggle protected String getText() {
85  1 return parser.getText();
86    }
87   
 
88  8530 toggle protected String get(String name) {
89  8530 return parser.getAttributeValue(null, name);
90    }
91   
 
92  466 toggle protected boolean getBoolean(String name) {
93  466 return "true".equals(get(name));
94    }
95   
 
96  816 toggle protected Integer getInteger(String name) {
97  816 String s = get(name);
98  816 return s == null ? null : Integer.valueOf(s);
99    }
100   
 
101  203 toggle protected Long getLong(String name) {
102  203 String s = get(name);
103  203 return s == null ? null : Long.valueOf(s);
104    }
105   
 
106  0 toggle protected Float getFloat(String name) {
107  0 String s = get(name);
108  0 return s == null ? null : Float.valueOf(s);
109    }
110   
 
111  36 toggle protected void init(Reader reader) throws Exception {
112  36 parser = Xml.newPullParser();
113  36 parser.setInput(reader);
114  36 rootElementFound = false;
115    }
116   
 
117  7437 toggle protected int nextParseEvent() throws Exception {
118  7437 return parser.next();
119    }
120   
 
121  2469 toggle protected String getElementName() {
122  2469 String name = parser.getName();
123  2469 if ("subsonic-response".equals(name)) {
124  36 rootElementFound = true;
125  36 String version = get("version");
126  36 if (version != null) {
127  36 Util.setServerRestVersion(context, new Version(version));
128    }
129    }
130  2469 return name;
131    }
132   
 
133  28 toggle protected void validate() throws Exception {
134  28 if (!rootElementFound) {
135  0 throw new Exception(context.getResources().getString(R.string.background_task_parse_error));
136    }
137    }
138    }