1 package com.melloware.jukes.file.tag;
2
3 import java.io.File;
4
5 import org.apache.commons.io.FilenameUtils;
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8
9 import com.melloware.jukes.exception.MusicTagException;
10 import com.melloware.jukes.file.filter.MusicFilter;
11
12
13
14
15
16
17
18
19
20
21 public final class TagFactory {
22
23 private static final Log LOG = LogFactory.getLog(TagFactory.class);
24
25
26
27
28 private TagFactory() {
29 super();
30 }
31
32
33
34
35
36
37
38
39 public static MusicTag getTag(final File aFile) throws MusicTagException {
40
41 MusicTag tag = null;
42 if (LOG.isDebugEnabled()) {
43 LOG.debug("Loading tag: " + aFile.getAbsolutePath());
44 }
45
46 if (FilenameUtils.isExtension(aFile.getName(), MusicFilter.MP3_EXTENSIONS)) {
47 tag = new Mp3Tag(aFile);
48 } else if (FilenameUtils.isExtension(aFile.getName(), MusicFilter.ENTAGGED_EXTENSIONS)) {
49 tag = new AudioFileTag(aFile);
50 } else if (FilenameUtils.isExtension(aFile.getName(), MusicFilter.APE_EXTENSIONS)) {
51 tag = new ApeFileTag(aFile);
52 } else {
53 throw new MusicTagException(aFile + " is not a known music file type.");
54 }
55
56 return tag;
57 }
58
59
60
61
62
63
64
65
66 public static MusicTag getTag(final String aFileLocation) throws MusicTagException {
67 return getTag(new File(aFileLocation));
68 }
69 }