FileDocCategorySizeDatePackage
FrameBodyTDRC.javaAPI DocJaudiotagger 2.0.413359Wed Mar 30 16:12:02 BST 2011org.jaudiotagger.tag.id3.framebody

FrameBodyTDRC

public class FrameBodyTDRC extends AbstractFrameBodyTextInfo implements ID3v24FrameBody
author
: Paul Taylor
author
: Eric Farng Version @version:$Id: FrameBodyTDRC.java 932 2010-11-26 13:13:15Z paultaylor $ MusicTag Copyright (C)2003,2004 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Description:

Fields Summary
private String
originalID
Used 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

param
body

        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

param
body

        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

param
body

        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

param
textEncoding
param
text

        super(textEncoding, text);
        findMatchingMaskAndExtractV3Values();
    
public FrameBodyTDRC(ByteBuffer byteBuffer, int frameSize)
Creates a new FrameBodyTDRC datatype from File

param
byteBuffer
param
frameSize
throws
InvalidTagException

        super(byteBuffer, frameSize);
        findMatchingMaskAndExtractV3Values();
    
public FrameBodyTDRC(FrameBodyTDRC body)

        super(body);
    
Methods Summary
private voidextractID3v23Formats(java.util.Date dateRecord, int precision)
Extract the components ans store the v23 version of the various values

param
dateRecord
param
precision

        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 voidfindMatchingMaskAndExtractV3Values()

        //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.StringformatAndParse(java.text.SimpleDateFormat formatDate, java.text.SimpleDateFormat parseDate, java.lang.String text)
Synchronized because SimpleDatFormat aren't thread safe

param
formatDate
param
parseDate
param
text
return

        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.StringformatDateAsDate(java.util.Date d)
Format Date Synchronized because SimpleDateFormat is invalid

param
d
return

        return formatDateIn.format(d);
    
private static synchronized java.lang.StringformatDateAsTime(java.util.Date d)
Format Date Synchronized because SimpleDateFormat is invalid

param
d
return

        return formatTimeIn.format(d);
    
private static synchronized java.lang.StringformatDateAsYear(java.util.Date d)
Format Date Synchronized because SimpleDateFormat is invalid

param
d
return

        return formatYearIn.format(d);
    
public java.lang.StringgetDate()

        return date;
    
public java.lang.StringgetFormattedText()

        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.StringgetIdentifier()
The ID3v2 frame identifier

return
the ID3v2 frame identifier for this frame type

        return ID3v24Frames.FRAME_ID_YEAR;
    
public java.lang.StringgetOriginalID()
Retrieve the original identifier

return

        return originalID;
    
public java.lang.StringgetTime()

        return time;
    
public java.lang.StringgetYear()

        return year;
    
public booleanisHoursOnly()

        return hoursOnly;
    
public booleanisMonthOnly()

        return monthOnly;
    
public voidsetDate(java.lang.String date)

        logger.finest("Setting date to:" + date);
        this.date = date;
    
public voidsetHoursOnly(boolean hoursOnly)

        this.hoursOnly = hoursOnly;
    
public voidsetMonthOnly(boolean monthOnly)

        this.monthOnly = monthOnly;
    
public voidsetTime(java.lang.String time)

        logger.finest("Setting time to:" + time);
        this.time = time;
    
public voidsetYear(java.lang.String year)

        logger.finest("Setting year to" + year);
        this.year = year;