Go to the documentation of this file.00001 package myDataBases;
00002
00003
00004 import java.util.*;
00005
00006 import java.io.File;
00007
00008 import org.jdom.*;
00009 import org.jdom.input.SAXBuilder;
00010
00011
00030 public class MediaBase {
00031
00032
00033
00034
00035
00039 private Map<Integer, Map<String,String> > content;
00040
00041
00042
00043
00044
00045
00055 public MediaBase( String path )
00056 {
00057 this.content = new Hashtable <Integer, Map <String,String>>() ;
00058 SAXBuilder sxb = new SAXBuilder();
00059 org.jdom.Document mediaDocument = null;
00060 try
00061 {
00062 mediaDocument = sxb.build(new File(path));
00063 }
00064 catch(Exception e){ e.printStackTrace(); }
00065 Element rootMedia = mediaDocument.getRootElement();
00066 Iterator it = rootMedia.getChildren().iterator();
00067 String field;
00068 Integer id = 0;
00069 while (it.hasNext())
00070 {
00071 Map<String,String> media = new Hashtable <String,String>();
00072 Element current = (Element)it.next();
00073 Iterator jt = current.getChildren().iterator();
00074 while (jt.hasNext())
00075 {
00076 Element attribute = (Element)jt.next();
00077 field = attribute.getName();
00078 if (field == "id")
00079 id = Integer.parseInt( attribute.getValue() );
00080 else
00081 media.put(field, attribute.getValue() );
00082 }
00083 this.content.put(id,media);
00084 }
00085 }
00086
00087
00088
00089
00090
00091
00099 public List<Integer[]> getAllMedia( )
00100 {
00101 List<Integer[]> result = new ArrayList<Integer[]>();
00102 List<Integer> array = new ArrayList<Integer>();
00103 for(Integer i : this.content.keySet())
00104 array.add(i);
00105 result.add(array.toArray(new Integer[0]));
00106 return result;
00107 }
00108
00109
00115 public Map<Integer, Map<String,String> > getContent()
00116 { return this.content; }
00117
00118
00126 public String getMedia( Integer id )
00127 { return this.content.get(id).get("name"); }
00128
00129 }