KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > parse > mp3 > MetadataCollector


1 package net.nutch.parse.mp3;
2
3 import net.nutch.parse.Outlink;
4
5 import java.net.MalformedURLException JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Properties JavaDoc;
8
9 /**
10  * This class allows meta data to be collected and manipulated
11  * @author Andy Hedges
12  */

13 public class MetadataCollector {
14
15   private Properties JavaDoc metadata = new Properties JavaDoc();
16   private String JavaDoc title = null;
17   private String JavaDoc artist = null;
18   private String JavaDoc album = null;
19   private ArrayList JavaDoc links = new ArrayList JavaDoc();
20   private String JavaDoc text = "";
21
22   public void notifyProperty(String JavaDoc name, String JavaDoc value) throws MalformedURLException JavaDoc {
23     if (name.equals("TIT2-Text"))
24       setTitle(value);
25     if (name.equals("TALB-Text"))
26       setAlbum(value);
27     if (name.equals("TPE1-Text"))
28       setArtist(value);
29
30     if (name.indexOf("URL Link") > -1) {
31       links.add(new Outlink(value, ""));
32     } else if (name.indexOf("Text") > -1) {
33       text += value + "\n";
34     }
35
36     metadata.setProperty(name, value);
37   }
38
39   public void putAll(Properties JavaDoc properties) {
40     metadata.putAll(properties);
41   }
42
43   public Properties JavaDoc getData() {
44     return metadata;
45   }
46
47   public Outlink[] getOutlinks() {
48     return (Outlink[]) links.toArray(new Outlink[links.size()]);
49   }
50
51   public String JavaDoc getTitle() {
52     String JavaDoc text = "";
53     if (title != null) {
54       text = title;
55     }
56     if (album != null) {
57       if (!text.equals("")) {
58         text += " - " + album;
59       } else {
60         text = title;
61       }
62     }
63     if (artist != null) {
64       if (!text.equals("")) {
65         text += " - " + artist;
66       } else {
67         text = artist;
68       }
69     }
70     return text;
71   }
72
73   public void setTitle(String JavaDoc title) {
74     this.title = title;
75   }
76
77   public void setArtist(String JavaDoc artist) {
78     this.artist = artist;
79   }
80
81   public void setAlbum(String JavaDoc album) {
82     this.album = album;
83   }
84
85   public String JavaDoc getText() {
86     return text;
87   }
88
89 }
Popular Tags