Coverage Report - org.jaudiotagger.audio.generic.GenericTag
 
Classes in this File Line Coverage Branch Coverage Complexity
GenericTag
62%
15/24
N/A
0
GenericTag$GenericTagTextField
37%
7/19
0%
0/4
0
 
 1  
 /*
 2  
  * Entagged Audio Tag library
 3  
  * Copyright (c) 2003-2005 Rapha�l Slinckx <raphael@slinckx.net>
 4  
  * 
 5  
  * This library is free software; you can redistribute it and/or
 6  
  * modify it under the terms of the GNU Lesser General Public
 7  
  * License as published by the Free Software Foundation; either
 8  
  * version 2.1 of the License, or (at your option) any later version.
 9  
  *  
 10  
  * This library is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
  * Lesser General Public License for more details.
 14  
  * 
 15  
  * You should have received a copy of the GNU Lesser General Public
 16  
  * License along with this library; if not, write to the Free Software
 17  
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 18  
  */
 19  
 package org.jaudiotagger.audio.generic;
 20  
 
 21  
 import org.jaudiotagger.tag.*;
 22  
 import org.jaudiotagger.tag.mp4.Mp4FieldKey;
 23  
 import org.jaudiotagger.tag.mp4.field.Mp4TagCoverField;
 24  
 import org.jaudiotagger.tag.datatype.Artwork;
 25  
 
 26  
 import java.util.List;
 27  
 import java.util.ArrayList;
 28  
 import java.util.Collection;
 29  
 import java.util.Collections;
 30  
 
 31  
 /**
 32  
  * This is a complete example implementation of
 33  
  * {@link AbstractTag}.<br>
 34  
  * The identifiers of commonly used fields is defined by {@link #keys}.<br>
 35  
  *
 36  
  * @author Rapha�l Slinckx
 37  
  */
 38  16
 public abstract class GenericTag extends AbstractTag
 39  
 {
 40  
 
 41  
     /**
 42  
      * Implementations of {@link TagTextField} for use with
 43  
      * &quot;ISO-8859-1&quot; strings.
 44  
      *
 45  
      * @author Rapha�l Slinckx
 46  
      */
 47  16
     private class GenericTagTextField implements TagTextField
 48  
     {
 49  
 
 50  
         /**
 51  
          * Stores the string.
 52  
          */
 53  
         private String content;
 54  
 
 55  
         /**
 56  
          * Stores the identifier.
 57  
          */
 58  
         private final String id;
 59  
 
 60  
         /**
 61  
          * Creates an instance.
 62  
          *
 63  
          * @param fieldId        The identifier.
 64  
          * @param initialContent The string.
 65  
          */
 66  
         public GenericTagTextField(String fieldId, String initialContent)
 67  39
         {
 68  39
             this.id = fieldId;
 69  39
             this.content = initialContent;
 70  39
         }
 71  
 
 72  
         /**
 73  
          * (overridden)
 74  
          *
 75  
          * @see org.jaudiotagger.tag.TagField#copyContent(org.jaudiotagger.tag.TagField)
 76  
          */
 77  
         public void copyContent(TagField field)
 78  
         {
 79  0
             if (field instanceof TagTextField)
 80  
             {
 81  0
                 this.content = ((TagTextField) field).getContent();
 82  
             }
 83  0
         }
 84  
 
 85  
         /**
 86  
          * (overridden)
 87  
          *
 88  
          * @see org.jaudiotagger.tag.TagTextField#getContent()
 89  
          */
 90  
         public String getContent()
 91  
         {
 92  33
             return this.content;
 93  
         }
 94  
 
 95  
         /**
 96  
          * (overridden)
 97  
          *
 98  
          * @see org.jaudiotagger.tag.TagTextField#getEncoding()
 99  
          */
 100  
         public String getEncoding()
 101  
         {
 102  0
             return "ISO-8859-1";
 103  
         }
 104  
 
 105  
         /**
 106  
          * (overridden)
 107  
          *
 108  
          * @see org.jaudiotagger.tag.TagField#getId()
 109  
          */
 110  
         public String getId()
 111  
         {
 112  78
             return id;
 113  
         }
 114  
 
 115  
         /**
 116  
          * (overridden)
 117  
          *
 118  
          * @see org.jaudiotagger.tag.TagField#getRawContent()
 119  
          */
 120  
         public byte[] getRawContent()
 121  
         {
 122  0
             return this.content == null ? new byte[]{} : Utils.getDefaultBytes(this.content, getEncoding());
 123  
         }
 124  
 
 125  
         /**
 126  
          * (overridden)
 127  
          *
 128  
          * @see org.jaudiotagger.tag.TagField#isBinary()
 129  
          */
 130  
         public boolean isBinary()
 131  
         {
 132  0
             return false;
 133  
         }
 134  
 
 135  
         /**
 136  
          * (overridden)
 137  
          *
 138  
          * @see org.jaudiotagger.tag.TagField#isBinary(boolean)
 139  
          */
 140  
         public void isBinary(boolean b)
 141  
         {
 142  
             /* not supported */
 143  0
         }
 144  
 
 145  
         /**
 146  
          * (overridden)
 147  
          *
 148  
          * @see org.jaudiotagger.tag.TagField#isCommon()
 149  
          */
 150  
         public boolean isCommon()
 151  
         {
 152  39
             return true;
 153  
         }
 154  
 
 155  
         /**
 156  
          * (overridden)
 157  
          *
 158  
          * @see org.jaudiotagger.tag.TagField#isEmpty()
 159  
          */
 160  
         public boolean isEmpty()
 161  
         {
 162  0
             return this.content.equals("");
 163  
         }
 164  
 
 165  
         /**
 166  
          * (overridden)
 167  
          *
 168  
          * @see org.jaudiotagger.tag.TagTextField#setContent(java.lang.String)
 169  
          */
 170  
         public void setContent(String s)
 171  
         {
 172  0
             this.content = s;
 173  0
         }
 174  
 
 175  
         /**
 176  
          * (overridden)
 177  
          *
 178  
          * @see org.jaudiotagger.tag.TagTextField#setEncoding(java.lang.String)
 179  
          */
 180  
         public void setEncoding(String s)
 181  
         {
 182  
             /* Not allowed */
 183  0
         }
 184  
 
 185  
         /**
 186  
          * (overridden)
 187  
          *
 188  
          * @see java.lang.Object#toString()
 189  
          */
 190  
         public String toString()
 191  
         {
 192  0
             return getId() + " : " + getContent();
 193  
         }
 194  
     }
 195  
 
 196  
     /**
 197  
      * Index for the &quot;album&quot;-identifier in {@link #keys}.
 198  
      */
 199  
     public static final int ALBUM = 1;
 200  
 
 201  
     /**
 202  
      * Index for the &quot;artist&quot;-identifier in {@link #keys}.
 203  
      */
 204  
     public static final int ARTIST = 0;
 205  
 
 206  
     /**
 207  
      * Index for the &quot;comment&quot;-identifier in {@link #keys}.
 208  
      */
 209  
     public static final int COMMENT = 6;
 210  
 
 211  
     /**
 212  
      * Index for the &quot;genre&quot;-identifier in {@link #keys}.
 213  
      */
 214  
     public static final int GENRE = 5;
 215  
 
 216  
     /**
 217  
      * Stores the generic identifiers of commonly used fields.
 218  
      */
 219  3
     private final static String[] keys = {"ARTIST", "ALBUM", "TITLE", "TRACK", "YEAR", "GENRE", "COMMENT",};
 220  
 
 221  
     /**
 222  
      * Index for the &quot;title&quot;-identifier in {@link #keys}.
 223  
      */
 224  
     public static final int TITLE = 2;
 225  
 
 226  
     /**
 227  
      * Index for the &quot;track&quot;-identifier in {@link #keys}.
 228  
      */
 229  
     public static final int TRACK = 3;
 230  
 
 231  
     /**
 232  
      * Index for the &quot;year&quot;-identifier in {@link #keys}.
 233  
      */
 234  
     public static final int YEAR = 4;
 235  
 
 236  
     /**
 237  
      * (overridden)
 238  
      *
 239  
      * @see AbstractTag#createAlbumField(java.lang.String)
 240  
      */
 241  
     public TagField createAlbumField(String content)
 242  
     {
 243  0
         return new GenericTagTextField(keys[ALBUM], content);
 244  
     }
 245  
 
 246  
     /**
 247  
      * (overridden)
 248  
      *
 249  
      * @see AbstractTag#createArtistField(java.lang.String)
 250  
      */
 251  
     public TagField createArtistField(String content)
 252  
     {
 253  13
         return new GenericTagTextField(keys[ARTIST], content);
 254  
     }
 255  
 
 256  
     /**
 257  
      * (overridden)
 258  
      *
 259  
      * @see AbstractTag#createCommentField(java.lang.String)
 260  
      */
 261  
     public TagField createCommentField(String content)
 262  
     {
 263  13
         return new GenericTagTextField(keys[COMMENT], content);
 264  
     }
 265  
 
 266  
     /**
 267  
      * (overridden)
 268  
      *
 269  
      * @see AbstractTag#createGenreField(java.lang.String)
 270  
      */
 271  
     public TagField createGenreField(String content)
 272  
     {
 273  0
         return new GenericTagTextField(keys[GENRE], content);
 274  
     }
 275  
 
 276  
     /**
 277  
      * (overridden)
 278  
      *
 279  
      * @see AbstractTag#createTitleField(java.lang.String)
 280  
      */
 281  
     public TagField createTitleField(String content)
 282  
     {
 283  13
         return new GenericTagTextField(keys[TITLE], content);
 284  
     }
 285  
 
 286  
     /**
 287  
      * (overridden)
 288  
      *
 289  
      * @see AbstractTag#createTrackField(java.lang.String)
 290  
      */
 291  
     public TagField createTrackField(String content)
 292  
     {
 293  0
         return new GenericTagTextField(keys[TRACK], content);
 294  
     }
 295  
 
 296  
     /**
 297  
      * (overridden)
 298  
      *
 299  
      * @see AbstractTag#createYearField(java.lang.String)
 300  
      */
 301  
     public TagField createYearField(String content)
 302  
     {
 303  0
         return new GenericTagTextField(keys[YEAR], content);
 304  
     }
 305  
 
 306  
     /**
 307  
      * (overridden)
 308  
      *
 309  
      * @see AbstractTag#getAlbumId()
 310  
      */
 311  
     protected String getAlbumId()
 312  
     {
 313  1
         return keys[ALBUM];
 314  
     }
 315  
 
 316  
     /**
 317  
      * (overridden)
 318  
      *
 319  
      * @see AbstractTag#getArtistId()
 320  
      */
 321  
     protected String getArtistId()
 322  
     {
 323  12
         return keys[ARTIST];
 324  
     }
 325  
 
 326  
     /**
 327  
      * (overridden)
 328  
      *
 329  
      * @see org.jaudiotagger.audio.generic.AbstractTag#getCommentId()
 330  
      */
 331  
     protected String getCommentId()
 332  
     {
 333  12
         return keys[COMMENT];
 334  
     }
 335  
 
 336  
     /**
 337  
      * (overridden)
 338  
      *
 339  
      * @see org.jaudiotagger.audio.generic.AbstractTag#getGenreId()
 340  
      */
 341  
     protected String getGenreId()
 342  
     {
 343  1
         return keys[GENRE];
 344  
     }
 345  
 
 346  
     /**
 347  
      * (overridden)
 348  
      *
 349  
      * @see org.jaudiotagger.audio.generic.AbstractTag#getTitleId()
 350  
      */
 351  
     protected String getTitleId()
 352  
     {
 353  12
         return keys[TITLE];
 354  
     }
 355  
 
 356  
     /**
 357  
      * (overridden)
 358  
      *
 359  
      * @see org.jaudiotagger.audio.generic.AbstractTag#getTrackId()
 360  
      */
 361  
     protected String getTrackId()
 362  
     {
 363  1
         return keys[TRACK];
 364  
     }
 365  
 
 366  
     /**
 367  
      * (overridden)
 368  
      *
 369  
      * @see org.jaudiotagger.audio.generic.AbstractTag#getYearId()
 370  
      */
 371  
     protected String getYearId()
 372  
     {
 373  1
         return keys[YEAR];
 374  
     }
 375  
 
 376  
     /**
 377  
      * (overridden)
 378  
      *
 379  
      * @see org.jaudiotagger.audio.generic.AbstractTag#isAllowedEncoding(java.lang.String)
 380  
      */
 381  
     protected boolean isAllowedEncoding(String enc)
 382  
     {
 383  0
         return true;
 384  
     }
 385  
 
 386  
     public TagField createTagField(TagFieldKey genericKey, String value) throws KeyNotFoundException, FieldDataInvalidException
 387  
     {
 388  0
         throw new UnsupportedOperationException("Not implemented for this format");
 389  
     }
 390  
 
 391  
     /**
 392  
      * @param genericKey
 393  
      * @return
 394  
      * @throws KeyNotFoundException
 395  
      */
 396  
     public String getFirst(TagFieldKey genericKey) throws KeyNotFoundException
 397  
     {
 398  0
         throw new UnsupportedOperationException("Not implemented for this format");
 399  
     }
 400  
 
 401  
     /**
 402  
      * @param tagFieldKey
 403  
      * @throws KeyNotFoundException
 404  
      */
 405  
     public void deleteTagField(TagFieldKey tagFieldKey) throws KeyNotFoundException
 406  
     {
 407  0
         throw new UnsupportedOperationException("Not implemented for this format");
 408  
     }
 409  
 
 410  
     /**
 411  
      * @param genericKey
 412  
      * @return
 413  
      * @throws KeyNotFoundException
 414  
      */
 415  
     public TagField getFirstField(TagFieldKey genericKey) throws KeyNotFoundException
 416  
     {
 417  0
         throw new UnsupportedOperationException("Not implemented for this format");
 418  
     }
 419  
 
 420  
     public List<Artwork> getArtworkList()
 421  
     {
 422  2
         return Collections.emptyList();
 423  
     }
 424  
 
 425  
     public TagField  createArtworkField(Artwork artwork) throws FieldDataInvalidException
 426  
     {
 427  2
         throw new UnsupportedOperationException("Not implemented for this format");    
 428  
     }
 429  
 }