joerg 2003/07/03 16:34:38
Modified: src/java/org/apache/cocoon/generation
MP3DirectoryGenerator.java
Log:
made it more robust:
at least MusicMatch Jukebox does not replace all characters with 0x00
if the new value for an ID3 tag is shorter than the old value, but only the first one
Revision Changes Path
1.2 +17 -8
cocoon-2.1/src/java/org/apache/cocoon/generation/MP3DirectoryGenerator.java
Index: MP3DirectoryGenerator.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/MP3DirectoryGenerator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MP3DirectoryGenerator.java 9 Mar 2003 00:09:31 -0000 1.1
+++ MP3DirectoryGenerator.java 3 Jul 2003 23:34:38 -0000 1.2
@@ -101,7 +101,7 @@
protected static String MP3_VBR_ATTR_NAME = "variable-rate";
protected static String MP3_TITLE_ATTR_NAME = "title";
- protected static String MP3_ARTITST_ATTR_NAME = "artist";
+ protected static String MP3_ARTIST_ATTR_NAME = "artist";
protected static String MP3_ALBUM_ATTR_NAME = "album";
protected static String MP3_YEAR_ATTR_NAME = "year";
protected static String MP3_COMMENT_ATTR_NAME = "comment";
@@ -147,19 +147,19 @@
// Check TAG presence
if(buf[0] != 'T' || buf[1] != 'A' || buf[2] != 'G') return;
- s = new String(buf, 3, 30).trim();
+ s = getID3TagValue(buf, 3, 30);
if(s.length() > 0)
attributes.addAttribute("", MP3_TITLE_ATTR_NAME, MP3_TITLE_ATTR_NAME,
"CDATA", s);
- s = new String(buf, 33,30).trim();
+ s = getID3TagValue(buf, 33,30);
if(s.length() > 0)
- attributes.addAttribute("", MP3_ARTITST_ATTR_NAME,
MP3_ARTITST_ATTR_NAME, "CDATA", s);
- s = new String(buf, 63,30).trim();
+ attributes.addAttribute("", MP3_ARTIST_ATTR_NAME, MP3_ARTIST_ATTR_NAME,
"CDATA", s);
+ s = getID3TagValue(buf, 63,30);
if(s.length() > 0)
attributes.addAttribute("", MP3_ALBUM_ATTR_NAME, MP3_ALBUM_ATTR_NAME,
"CDATA", s);
- s = new String(buf, 93, 4).trim();
+ s = getID3TagValue(buf, 93, 4);
if(s.length() > 0)
attributes.addAttribute("", MP3_YEAR_ATTR_NAME, MP3_YEAR_ATTR_NAME,
"CDATA", s);
- s = new String(buf, 97,29).trim();
+ s = getID3TagValue(buf, 97,29);
if(s.length() > 0)
attributes.addAttribute("", MP3_COMMENT_ATTR_NAME,
MP3_COMMENT_ATTR_NAME, "CDATA", s);
if(buf[126] > 0)
@@ -168,6 +168,15 @@
if(buf[127] > 0)
attributes.addAttribute("", MP3_GENRE_ATTR_NAME, MP3_GENRE_ATTR_NAME,
"CDATA",
Byte.toString(buf[127]));
+ }
+
+ private String getID3TagValue(byte[] buf, int offset, int length) {
+ String s = new String(buf, offset, length).trim();
+ int index = s.indexOf(0x00);
+ if (index != -1) {
+ s = s.substring(0, index);
+ }
+ return s;
}
private void setID3HeaderAttributes(RandomAccessFile in) throws IOException