Package com.ojl.xmlparser

Source Code of com.ojl.xmlparser.sounds$SoundCategory

package com.ojl.xmlparser;
import java.util.ArrayList;

import org.w3c.dom.Element;

import com.ojl.xmlparser.XmlParse;


public class sounds {
 
  public String soundsXml = "";
  public ArrayList <sounds.SoundCategory> soundCats = null;

  public sounds(String soundsXml) {
    this.soundsXml = soundsXml;
    this.soundCats = new ArrayList<sounds.SoundCategory>();   
    prepareSounds();
  }
 
  public void prepareSounds()
  {
   
    XmlParse xp = new XmlParse(this.soundsXml);
   
    //Getting all Categories
    ArrayList<?> catsObj = xp.getElements("Category");

    for (Object catObj: catsObj)
    {
      //Fetch Categories Label and Folder - And add it to main list.
      String id = xp.getAttribute(catObj,"id");
      String label = xp.getAttribute(catObj,"Label");
      String folder = xp.getAttribute(catObj,"Folder");
      SoundCategory sndCat = new SoundCategory(Integer.parseInt(id), label, folder);
      this.soundCats.add(sndCat);
     
      //Now fetch the items
      ArrayList<?> itmsObj = xp.getElements((Element) catObj, "Item");
      for (Object itmObj: itmsObj)
      {
        String itmId = xp.getAttribute(itmObj,"id");
        String itmLabel = xp.getAttribute(itmObj,"Label");
        String itmFile = xp.getAttribute(itmObj,"File");
       
        SoundItem sndItm = new SoundItem(Integer.parseInt(itmId), itmLabel, itmFile);
        sndCat.Items.add(sndItm);
      }     
     
    }
   
  }
 
 
  public ArrayList<sounds.SoundCategory> getSoundCategories()
  {
    return this.soundCats;
  }
 
  public ArrayList<SoundItem> getSoundItems(SoundCategory sndCategory)
  {
    ArrayList<sounds.SoundCategory> sndCats = getSoundCategories();
   
    for (SoundCategory eachSndCat: sndCats)
    {
      if (eachSndCat == sndCategory)
      {
        return eachSndCat.Items;
      }
    }
    return null;
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
  public class SoundCategory{
    public int id = 0;
    public String Label = null;
    public String Folder = null;
    public ArrayList<SoundItem> Items = null;

    public SoundCategory(int id, String label, String folder) {
      this.id = id;
      Label = label;
      Folder = folder;
      this.Items = new ArrayList<sounds.SoundItem>();
    }
  }
 
  public class SoundItem
    public String Label = null;
    public String File = null;
    public int id = 0;
   
    public SoundItem(int id, String label, String file) {
      this.id = id;
      Label = label;
      File = file;
    }
  }
 
}

TOP

Related Classes of com.ojl.xmlparser.sounds$SoundCategory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.