FrameBodyTDRCpublic class FrameBodyTDRC extends AbstractFrameBodyTextInfo implements ID3v24FrameBody
Fields Summary |
---|
private String | originalIDUsed when converting from v3 tags , these fields should ALWAYS hold the v23 value | private String | year | private String | time | private String | date | private boolean | monthOnly | private boolean | hoursOnly | private static SimpleDateFormat | formatYearIn | private static SimpleDateFormat | formatYearOut | private static SimpleDateFormat | formatDateIn | private static SimpleDateFormat | formatDateOut | private static SimpleDateFormat | formatMonthOut | private static SimpleDateFormat | formatTimeIn | private static SimpleDateFormat | formatTimeOut | private static SimpleDateFormat | formatHoursOut | private static final List | formatters | private static final int | PRECISION_SECOND | private static final int | PRECISION_MINUTE | private static final int | PRECISION_HOUR | private static final int | PRECISION_DAY | private static final int | PRECISION_MONTH | private static final int | PRECISION_YEAR |
Constructors Summary |
---|
public FrameBodyTDRC()Creates a new FrameBodyTDRC datatype.
//This is allowable v24 format , we use UK Locale not because we are restricting to UK
//but because these formats are fixed in ID3 spec, and could possibly get unexpected results if library
//used with a default locale that has Date Format Symbols that interfere with the pattern
formatters.add(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.UK));
formatters.add(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm", Locale.UK));
formatters.add(new SimpleDateFormat("yyyy-MM-dd'T'HH", Locale.UK));
formatters.add(new SimpleDateFormat("yyyy-MM-dd", Locale.UK));
formatters.add(new SimpleDateFormat("yyyy-MM", Locale.UK));
formatters.add(new SimpleDateFormat("yyyy", Locale.UK));
//These are formats used by v23 Frames
formatYearIn = new SimpleDateFormat("yyyy", Locale.UK);
formatDateIn = new SimpleDateFormat("ddMM", Locale.UK);
formatTimeIn = new SimpleDateFormat("HHmm", Locale.UK);
//These are the separate components of the v24 format that the v23 formats map to
formatYearOut = new SimpleDateFormat("yyyy", Locale.UK);
formatDateOut = new SimpleDateFormat("-MM-dd", Locale.UK);
formatMonthOut = new SimpleDateFormat("-MM", Locale.UK);
formatTimeOut = new SimpleDateFormat("'T'HH:mm", Locale.UK);
formatHoursOut = new SimpleDateFormat("'T'HH", Locale.UK);
super();
| public FrameBodyTDRC(FrameBodyTYER body)When converting v3 TYER to v4 TDRC frame
originalID = ID3v23Frames.FRAME_ID_V3_TYER;
year = body.getText();
setObjectValue(DataTypes.OBJ_TEXT_ENCODING, TextEncoding.ISO_8859_1);
setObjectValue(DataTypes.OBJ_TEXT, getFormattedText());
| public FrameBodyTDRC(FrameBodyTIME body)When converting v3 TIME to v4 TDRC frame
originalID = ID3v23Frames.FRAME_ID_V3_TIME;
time = body.getText();
setHoursOnly(body.isHoursOnly());
setObjectValue(DataTypes.OBJ_TEXT_ENCODING, TextEncoding.ISO_8859_1);
setObjectValue(DataTypes.OBJ_TEXT, getFormattedText());
| public FrameBodyTDRC(FrameBodyTDAT body)When converting v3 TDAT to v4 TDRC frame
originalID = ID3v23Frames.FRAME_ID_V3_TDAT;
date = body.getText();
setMonthOnly(body.isMonthOnly());
setObjectValue(DataTypes.OBJ_TEXT_ENCODING, TextEncoding.ISO_8859_1);
setObjectValue(DataTypes.OBJ_TEXT, getFormattedText());
| public FrameBodyTDRC(byte textEncoding, String text)Creates a new FrameBodyTDRC dataType.
Tries to decode the text to find the v24 date mask being used, and store the v3 components of the mask
super(textEncoding, text);
findMatchingMaskAndExtractV3Values();
| public FrameBodyTDRC(ByteBuffer byteBuffer, int frameSize)Creates a new FrameBodyTDRC datatype from File
super(byteBuffer, frameSize);
findMatchingMaskAndExtractV3Values();
| public FrameBodyTDRC(FrameBodyTDRC body)
super(body);
|
Methods Summary |
---|
private void | extractID3v23Formats(java.util.Date dateRecord, int precision)Extract the components ans store the v23 version of the various values
logger.fine("Precision is:"+precision+"for date:"+dateRecord.toString());
Date d = dateRecord;
//Precision Year
if (precision == PRECISION_YEAR)
{
setYear(formatDateAsYear(d));
}
//Precision Month
else if (precision == PRECISION_MONTH)
{
setYear(formatDateAsYear(d));
setDate(formatDateAsDate(d));
monthOnly=true;
}
//Precision Day
else if (precision == PRECISION_DAY)
{
setYear(formatDateAsYear(d));
setDate(formatDateAsDate(d));
}
//Precision Hour
else if (precision == PRECISION_HOUR)
{
setYear(formatDateAsYear(d));
setDate(formatDateAsDate(d));
setTime(formatDateAsTime(d));
hoursOnly =true;
}
//Precision Minute
else if (precision == PRECISION_MINUTE)
{
setYear(formatDateAsYear(d));
setDate(formatDateAsDate(d));
setTime(formatDateAsTime(d));
}
//Precision Minute
else if (precision == PRECISION_SECOND)
{
setYear(formatDateAsYear(d));
setDate(formatDateAsDate(d));
setTime(formatDateAsTime(d));
}
| private void | findMatchingMaskAndExtractV3Values()
//Find the date format of the text
for (int i = 0; i < formatters.size(); i++)
{
try
{
Date d;
synchronized(formatters.get(i))
{
d = formatters.get(i).parse(getText());
}
//If able to parse a date from the text
if (d != null)
{
extractID3v23Formats(d, i);
break;
}
}
//Dont display will occur for each failed format
catch (ParseException e)
{
//Do nothing;
}
catch(NumberFormatException nfe)
{
//Do nothing except log warning because not really expecting this to happen
logger.log(Level.WARNING,"Date Formatter:"+formatters.get(i).toPattern() + "failed to parse:"+getText()+ "with "+nfe.getMessage(),nfe);
}
}
| private static synchronized java.lang.String | formatAndParse(java.text.SimpleDateFormat formatDate, java.text.SimpleDateFormat parseDate, java.lang.String text)Synchronized because SimpleDatFormat aren't thread safe
try
{
Date date = parseDate.parse(text);
String result = formatDate.format(date);
return result;
}
catch (ParseException e)
{
logger.warning("Unable to parse:" + text);
}
return "";
| private static synchronized java.lang.String | formatDateAsDate(java.util.Date d)Format Date
Synchronized because SimpleDateFormat is invalid
return formatDateIn.format(d);
| private static synchronized java.lang.String | formatDateAsTime(java.util.Date d)Format Date
Synchronized because SimpleDateFormat is invalid
return formatTimeIn.format(d);
| private static synchronized java.lang.String | formatDateAsYear(java.util.Date d)Format Date
Synchronized because SimpleDateFormat is invalid
return formatYearIn.format(d);
| public java.lang.String | getDate()
return date;
| public java.lang.String | getFormattedText()
StringBuffer sb = new StringBuffer();
if (originalID == null)
{
return this.getText();
}
else
{
if (year != null && !(year.equals("")))
{
sb.append(formatAndParse(formatYearOut,formatYearIn,year));
}
if (!date.equals(""))
{
if(isMonthOnly())
{
sb.append(formatAndParse(formatMonthOut,formatDateIn,date));
}
else
{
sb.append(formatAndParse(formatDateOut,formatDateIn,date));
}
}
if (!time.equals(""))
{
if(isHoursOnly())
{
sb.append(formatAndParse(formatHoursOut,formatTimeIn,time));
}
else
{
sb.append(formatAndParse(formatTimeOut,formatTimeIn,time));
}
}
return sb.toString();
}
| public java.lang.String | getIdentifier()The ID3v2 frame identifier
return ID3v24Frames.FRAME_ID_YEAR;
| public java.lang.String | getOriginalID()Retrieve the original identifier
return originalID;
| public java.lang.String | getTime()
return time;
| public java.lang.String | getYear()
return year;
| public boolean | isHoursOnly()
return hoursOnly;
| public boolean | isMonthOnly()
return monthOnly;
| public void | setDate(java.lang.String date)
logger.finest("Setting date to:" + date);
this.date = date;
| public void | setHoursOnly(boolean hoursOnly)
this.hoursOnly = hoursOnly;
| public void | setMonthOnly(boolean monthOnly)
this.monthOnly = monthOnly;
| public void | setTime(java.lang.String time)
logger.finest("Setting time to:" + time);
this.time = time;
| public void | setYear(java.lang.String year)
logger.finest("Setting year to" + year);
this.year = year;
|
|