Allows to retrieve the names of the media to sort as well as other characteristics specified in the media.xml
file.
More...
Public Member Functions | |
MediaBase (String path) | |
Creates an instance of MediaBase and sets its attributes. <../..> | |
List< Integer[]> | getAllMedia () |
Returns a List of all the identifier of the media considered. <../..> | |
Map< Integer, Map< String, String > > | getContent () |
Returns content , the map of map containing all the information available in the media.xml file. <../..> | |
String | getMedia (Integer id) |
Returns the name of the media wanted. <../..> | |
Private Attributes | |
Map< Integer, Map< String, String > > | content |
The list of the media contained in the file and their characteristics. <../..> |
Allows to retrieve the names of the media to sort as well as other characteristics specified in the media.xml
file.
The media's names and other characteristics are stored in the '../data/media.xml'
file. The aim of this class is to allow other parts of this program to access quickly and simply to these informations.
The structure of the media.xml file must be :
< content >< media >< id >identifier< /id >< name >the name of the file as used by crowdFlower< /name > < characteristic >a first characteristic< /characteristic >< othercharac >another characteristic< /othercharac > < /media > ... < /content >
IMPORTANT: Identifiers must go from zero to $number_of_media without any gap. For instance, [0,2,1,5,4,3]
works (the order does not matter), but [0,1,1337,42,5] does NOT.
Definition at line 30 of file MediaBase.java.
myDataBases.MediaBase.MediaBase | ( | String | path | ) |
Creates an instance of MediaBase and sets its attributes.
Generates a hashMap containing all the media and their characteristics, content
, by parsing the path
xml file. All the information contained in this file will be in the content
attribute (as long as it is correctly xml formatted).
path | Path to the file containing the data |
Definition at line 55 of file MediaBase.java.
{ this.content = new Hashtable <Integer, Map <String,String>>() ; SAXBuilder sxb = new SAXBuilder(); org.jdom.Document mediaDocument = null; try { mediaDocument = sxb.build(new File(path)); } catch(Exception e){ e.printStackTrace(); } Element rootMedia = mediaDocument.getRootElement(); Iterator it = rootMedia.getChildren().iterator(); String field; Integer id = 0; while (it.hasNext()) { Map<String,String> media = new Hashtable <String,String>(); Element current = (Element)it.next(); Iterator jt = current.getChildren().iterator(); while (jt.hasNext()) { Element attribute = (Element)jt.next(); field = attribute.getName(); if (field == "id") id = Integer.parseInt( attribute.getValue() ); else media.put(field, attribute.getValue() ); } this.content.put(id,media); } }
List<Integer[]> myDataBases.MediaBase.getAllMedia | ( | ) |
Returns a List of all the identifier of the media considered.
Reads the content
attribute and adds every < id >
it founds in a list.
Definition at line 99 of file MediaBase.java.
{ List<Integer[]> result = new ArrayList<Integer[]>(); List<Integer> array = new ArrayList<Integer>(); for(Integer i : this.content.keySet()) array.add(i); result.add(array.toArray(new Integer[0])); return result; }
Map<Integer, Map<String,String> > myDataBases.MediaBase.getContent | ( | ) |
Returns content
, the map of map containing all the information available in the media.xml file.
Definition at line 115 of file MediaBase.java.
{ return this.content; }
String myDataBases.MediaBase.getMedia | ( | Integer | id | ) |
Returns the name of the media wanted.
id | The identifier of the media wanted. |
id
. Definition at line 126 of file MediaBase.java.
{ return this.content.get(id).get("name"); }
Map<Integer, Map<String,String> > myDataBases.MediaBase.content [private] |
The list of the media contained in the file and their characteristics.
Definition at line 39 of file MediaBase.java.