예제 #1
0
 // Override
 public boolean startElementHandler(String tag, ZLStringMap attributes) {
   if ((tag == "subgenre") || (tag == "genre-alt")) {
     final String id = attributes.getValue("value");
     if (id != null) {
       myGenreIds.add(id);
     }
   } else if (tag == "root-descr") {
     if (myLanguage == attributes.getValue("lang")) {
       myCategoryTag = Tag.getTag(null, attributes.getValue("genre-title"));
     }
   } else if (tag == "genre-descr") {
     if (myLanguage == attributes.getValue("lang")) {
       mySubCategoryTag = Tag.getTag(myCategoryTag, attributes.getValue("title"));
     }
   }
   return false;
 }
 private Tag getTagById(long id) {
   Tag tag = myTagById.get(id);
   if (tag == null) {
     final Cursor cursor =
         myDatabase.rawQuery(
             "SELECT parent_id,name FROM Tags WHERE tag_id = ?", new String[] {"" + id});
     if (cursor.moveToNext()) {
       final Tag parent = cursor.isNull(0) ? null : getTagById(cursor.getLong(0));
       tag = Tag.getTag(parent, cursor.getString(1));
       myIdByTag.put(tag, id);
       myTagById.put(id, tag);
     }
     cursor.close();
   }
   return tag;
 }
  private void initTagCache() {
    if (myTagCacheIsInitialized) {
      return;
    }
    myTagCacheIsInitialized = true;

    Cursor cursor =
        myDatabase.rawQuery("SELECT tag_id,parent_id,name FROM Tags ORDER BY tag_id", null);
    while (cursor.moveToNext()) {
      long id = cursor.getLong(0);
      if (myTagById.get(id) == null) {
        final Tag tag = Tag.getTag(myTagById.get(cursor.getLong(1)), cursor.getString(2));
        myIdByTag.put(tag, id);
        myTagById.put(id, tag);
      }
    }
    cursor.close();
  }