()
| 251 | } |
| 252 | |
| 253 | private void loadBookmarks() throws IOException, BookException { |
| 254 | |
| 255 | if (bookmarksFile == null) { |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | /* |
| 260 | * Loading bookmarks |
| 261 | */ |
| 262 | InputStream in = bookmarksFile.openInputStream(); |
| 263 | |
| 264 | KXmlParser parser = null; |
| 265 | Document doc = null; |
| 266 | Element root; |
| 267 | Element kid; |
| 268 | |
| 269 | try { |
| 270 | parser = new KXmlParser(); |
| 271 | parser.setInput(new InputStreamReader(in, "UTF-8")); |
| 272 | |
| 273 | doc = new Document(); |
| 274 | doc.parse(parser); |
| 275 | parser = null; |
| 276 | } catch (XmlPullParserException e) { |
| 277 | parser = null; |
| 278 | doc = null; |
| 279 | throw new BookException("Wrong XML data."); |
| 280 | } |
| 281 | |
| 282 | try { |
| 283 | |
| 284 | /* |
| 285 | * root element |
| 286 | */ |
| 287 | root = doc.getRootElement(); |
| 288 | |
| 289 | int childCount = root.getChildCount(); |
| 290 | |
| 291 | for (int i = 0; i < childCount ; i++ ) { |
| 292 | if (root.getType(i) != Node.ELEMENT) { |
| 293 | continue; |
| 294 | } |
| 295 | |
| 296 | kid = root.getElement(i); |
| 297 | |
| 298 | final int chapter = |
| 299 | readIntFromXML(kid, USERDATA_CHAPTER_ATTRIB); |
| 300 | |
| 301 | int position = |
| 302 | readIntFromXML(kid, USERDATA_POSITION_ATTRIB); |
| 303 | |
| 304 | if (position < 0) { |
| 305 | position = 0; |
| 306 | } |
| 307 | |
| 308 | if (kid.getName().equals(USERDATA_BOOKMARK_TAG)) { |
| 309 | |
| 310 | String text = kid.getText(0); |
no test coverage detected