Coverage Report - org.jaudiotagger.tag.TagOptionSingleton
 
Classes in this File Line Coverage Branch Coverage Complexity
TagOptionSingleton
73%
172/237
50%
19/38
0
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: TagOptionSingleton.java,v 1.16 2008/07/21 10:45:52 paultaylor Exp $
 6  
  *
 7  
  *  MusicTag Copyright (C)2003,2004
 8  
  *
 9  
  *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
 10  
  *  General Public  License as published by the Free Software Foundation; either version 2.1 of the License,
 11  
  *  or (at your option) any later version.
 12  
  *
 13  
  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 14  
  *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 15  
  *  See the GNU Lesser General Public License for more details.
 16  
  *
 17  
  *  You should have received a copy of the GNU Lesser General Public License along with this library; if not,
 18  
  *  you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software
 19  
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 20  
  *
 21  
  * Description:
 22  
  * Options that are used for every datatype and class in this library.
 23  
  *
 24  
  */
 25  
 package org.jaudiotagger.tag;
 26  
 
 27  
 import org.jaudiotagger.tag.id3.framebody.AbstractID3v2FrameBody;
 28  
 import org.jaudiotagger.tag.id3.framebody.FrameBodyCOMM;
 29  
 import org.jaudiotagger.tag.id3.framebody.FrameBodyTIPL;
 30  
 import org.jaudiotagger.tag.id3.framebody.ID3v24FrameBody;
 31  
 import org.jaudiotagger.tag.id3.valuepair.TextEncoding;
 32  
 import org.jaudiotagger.tag.lyrics3.Lyrics3v2Fields;
 33  
 import org.jaudiotagger.tag.reference.GenreTypes;
 34  
 import org.jaudiotagger.tag.reference.Languages;
 35  
 
 36  
 import java.util.HashMap;
 37  
 import java.util.Iterator;
 38  
 import java.util.LinkedList;
 39  
 
 40  
 public class TagOptionSingleton
 41  
 {
 42  
     /**
 43  
      *
 44  
      */
 45  42
     private static HashMap<String, TagOptionSingleton> tagOptionTable = new HashMap<String, TagOptionSingleton>();
 46  
 
 47  
     /**
 48  
      *
 49  
      */
 50  42
     private static String DEFAULT = "default";
 51  
 
 52  
     /**
 53  
      *
 54  
      */
 55  42
     private static String defaultOptions = DEFAULT;
 56  
 
 57  
     /**
 58  
      *
 59  
      */
 60  42
     private HashMap<Class<? extends ID3v24FrameBody>, LinkedList<String>> keywordMap = new HashMap<Class<? extends ID3v24FrameBody>, LinkedList<String>>();
 61  
 
 62  
     /**
 63  
      * Map of lyric ID's to Boolean objects if we should or should not save the
 64  
      * specific Kyrics3 field. Defaults to true.
 65  
      */
 66  42
     private HashMap<String, Boolean> lyrics3SaveFieldMap = new HashMap<String, Boolean>();
 67  
 
 68  
     /**
 69  
      * parenthesis map stuff
 70  
      */
 71  42
     private HashMap<String, String> parenthesisMap = new HashMap<String, String>();
 72  
 
 73  
     /**
 74  
      * <code>HashMap</code> listing words to be replaced if found
 75  
      */
 76  42
     private HashMap<String, String> replaceWordMap = new HashMap<String, String>();
 77  
 
 78  
 
 79  
     /**
 80  
      * default language for any ID3v2 tags frameswhich require it. This string
 81  
      * is in the [ISO-639-2] ISO/FDIS 639-2 definition
 82  
      */
 83  42
     private String language = "eng";
 84  
 
 85  
 
 86  
     /**
 87  
      *
 88  
      */
 89  42
     private boolean filenameTagSave = false;
 90  
 
 91  
     /**
 92  
      * if we should save any fields of the ID3v1 tag or not. Defaults to true.
 93  
      */
 94  42
     private boolean id3v1Save = true;
 95  
 
 96  
     /**
 97  
      * if we should save the album field of the ID3v1 tag or not. Defaults to
 98  
      * true.
 99  
      */
 100  42
     private boolean id3v1SaveAlbum = true;
 101  
 
 102  
     /**
 103  
      * if we should save the artist field of the ID3v1 tag or not. Defaults to
 104  
      * true.
 105  
      */
 106  42
     private boolean id3v1SaveArtist = true;
 107  
 
 108  
     /**
 109  
      * if we should save the comment field of the ID3v1 tag or not. Defaults to
 110  
      * true.
 111  
      */
 112  42
     private boolean id3v1SaveComment = true;
 113  
 
 114  
     /**
 115  
      * if we should save the genre field of the ID3v1 tag or not. Defaults to
 116  
      * true.
 117  
      */
 118  42
     private boolean id3v1SaveGenre = true;
 119  
 
 120  
     /**
 121  
      * if we should save the title field of the ID3v1 tag or not. Defaults to
 122  
      * true.
 123  
      */
 124  42
     private boolean id3v1SaveTitle = true;
 125  
 
 126  
     /**
 127  
      * if we should save the track field of the ID3v1 tag or not. Defaults to
 128  
      * true.
 129  
      */
 130  42
     private boolean id3v1SaveTrack = true;
 131  
 
 132  
     /**
 133  
      * if we should save the year field of the ID3v1 tag or not. Defaults to
 134  
      * true.
 135  
      */
 136  42
     private boolean id3v1SaveYear = true;
 137  
 
 138  
 
 139  
     /**
 140  
      * When adjusting the ID3v2 padding, if should we copy the current ID3v2
 141  
      * tag to the new MP3 file. Defaults to true.
 142  
      */
 143  42
     private boolean id3v2PaddingCopyTag = true;
 144  
 
 145  
     /**
 146  
      * When adjusting the ID3v2 padding, if we should shorten the length of the
 147  
      * ID3v2 tag padding. Defaults to false.
 148  
      */
 149  42
     private boolean id3v2PaddingWillShorten = false;
 150  
 
 151  
     /**
 152  
      * if we should save any fields of the ID3v2 tag or not. Defaults to true.
 153  
      */
 154  42
     private boolean id3v2Save = true;
 155  
 
 156  
 
 157  
     /**
 158  
      * if we should keep an empty Lyrics3 field while we're reading. This is
 159  
      * different from a string of white space. Defaults to false.
 160  
      */
 161  42
     private boolean lyrics3KeepEmptyFieldIfRead = false;
 162  
 
 163  
     /**
 164  
      * if we should save any fields of the Lyrics3 tag or not. Defaults to
 165  
      * true.
 166  
      */
 167  42
     private boolean lyrics3Save = true;
 168  
 
 169  
     /**
 170  
      * if we should save empty Lyrics3 field or not. Defaults to false.
 171  
      * <p/>
 172  
      * todo I don't think this is implemented yet.
 173  
      */
 174  42
     private boolean lyrics3SaveEmptyField = false;
 175  
 
 176  
     /**
 177  
      *
 178  
      */
 179  42
     private boolean originalSavedAfterAdjustingID3v2Padding = true;
 180  
 
 181  
 
 182  
     /**
 183  
      * default time stamp format for any ID3v2 tag frames which require it.
 184  
      */
 185  42
     private byte timeStampFormat = 2;
 186  
 
 187  
     /**
 188  
      * number of frames to sync when trying to find the start of the MP3 frame
 189  
      * data. The start of the MP3 frame data is the start of the music and is
 190  
      * different from the ID3v2 frame data.
 191  
      */
 192  42
     private int numberMP3SyncFrame = 3;
 193  
 
 194  
     /**
 195  
      * Unsynchronize tags/frames this is rarely required these days and can cause more
 196  
      * problems than it solves
 197  
      */
 198  42
     private boolean unsyncTags = false;
 199  
 
 200  
     /**
 201  
      * iTunes needlessly writes null terminators at the end for TextEncodedStringSizeTerminated values,
 202  
      * if this option is enabled these characters are removed
 203  
      */
 204  42
     private boolean removeTrailingTerminatorOnWrite = true;
 205  
 
 206  
     /**
 207  
      * This is the default text encoding to use for new v23 frames, when unicode is required
 208  
      * UTF16 will always be used because that is the only valid option for v23.
 209  
      */
 210  42
     private byte id3v23DefaultTextEncoding = TextEncoding.ISO_8859_1;
 211  
 
 212  
     /**
 213  
      * This is the default text encoding to use for new v24 frames, it defaults to simple ISO8859
 214  
      * but by changing this value you could always used UTF8 for example whether you needed to or not
 215  
      */
 216  42
     private byte id3v24DefaultTextEncoding = TextEncoding.ISO_8859_1;
 217  
 
 218  
     /**
 219  
      * This is text encoding to use for new v24 frames when unicode is required, it defaults to UTF16 just
 220  
      * because this encoding is understand by all ID3 versions
 221  
      */
 222  42
     private byte id3v24UnicodeTextEncoding = TextEncoding.UTF_16;
 223  
 
 224  
 
 225  
     /**
 226  
      * When writing frames if this is set to true then the frame will be written
 227  
      * using the defaults disregarding the text e ncoding originally used to create
 228  
      * the frame.
 229  
      */
 230  42
     private boolean resetTextEncodingForExistingFrames = false;
 231  
 
 232  
     /**
 233  
      * Creates a new TagOptions datatype. All Options are set to their default
 234  
      * values
 235  
      */
 236  
     private TagOptionSingleton()
 237  42
     {
 238  42
         setToDefault();
 239  42
     }
 240  
 
 241  
 
 242  
     /**
 243  
      * @return
 244  
      */
 245  
     public static TagOptionSingleton getInstance()
 246  
     {
 247  4071
         return getInstance(defaultOptions);
 248  
     }
 249  
 
 250  
     /**
 251  
      * @param instanceKey
 252  
      * @return
 253  
      */
 254  
     public static TagOptionSingleton getInstance(String instanceKey)
 255  
     {
 256  4071
         TagOptionSingleton tagOptions = tagOptionTable.get(instanceKey);
 257  
 
 258  4071
         if (tagOptions == null)
 259  
         {
 260  42
             tagOptions = new TagOptionSingleton();
 261  42
             tagOptionTable.put(instanceKey, tagOptions);
 262  
         }
 263  
 
 264  4071
         return tagOptions;
 265  
     }
 266  
 
 267  
     /**
 268  
      * @param filenameTagSave
 269  
      */
 270  
     public void setFilenameTagSave(boolean filenameTagSave)
 271  
     {
 272  0
         this.filenameTagSave = filenameTagSave;
 273  0
     }
 274  
 
 275  
     /**
 276  
      * @return
 277  
      */
 278  
     public boolean isFilenameTagSave()
 279  
     {
 280  0
         return filenameTagSave;
 281  
     }
 282  
 
 283  
 
 284  
     /**
 285  
      * @param instanceKey
 286  
      */
 287  
     public void setInstanceKey(String instanceKey)
 288  
     {
 289  0
         TagOptionSingleton.defaultOptions = instanceKey;
 290  0
     }
 291  
 
 292  
     /**
 293  
      * @return
 294  
      */
 295  
     public static String getInstanceKey()
 296  
     {
 297  0
         return defaultOptions;
 298  
     }
 299  
 
 300  
 
 301  
     /**
 302  
      * @param id3v1Save
 303  
      */
 304  
     public void setId3v1Save(boolean id3v1Save)
 305  
     {
 306  0
         this.id3v1Save = id3v1Save;
 307  0
     }
 308  
 
 309  
     /**
 310  
      * @return
 311  
      */
 312  
     public boolean isId3v1Save()
 313  
     {
 314  261
         return id3v1Save;
 315  
     }
 316  
 
 317  
     /**
 318  
      * @param id3v1SaveAlbum
 319  
      */
 320  
     public void setId3v1SaveAlbum(boolean id3v1SaveAlbum)
 321  
     {
 322  0
         this.id3v1SaveAlbum = id3v1SaveAlbum;
 323  0
     }
 324  
 
 325  
     /**
 326  
      * @return
 327  
      */
 328  
     public boolean isId3v1SaveAlbum()
 329  
     {
 330  64
         return id3v1SaveAlbum;
 331  
     }
 332  
 
 333  
     /**
 334  
      * @param id3v1SaveArtist
 335  
      */
 336  
     public void setId3v1SaveArtist(boolean id3v1SaveArtist)
 337  
     {
 338  0
         this.id3v1SaveArtist = id3v1SaveArtist;
 339  0
     }
 340  
 
 341  
     /**
 342  
      * @return
 343  
      */
 344  
     public boolean isId3v1SaveArtist()
 345  
     {
 346  64
         return id3v1SaveArtist;
 347  
     }
 348  
 
 349  
     /**
 350  
      * @param id3v1SaveComment
 351  
      */
 352  
     public void setId3v1SaveComment(boolean id3v1SaveComment)
 353  
     {
 354  0
         this.id3v1SaveComment = id3v1SaveComment;
 355  0
     }
 356  
 
 357  
     /**
 358  
      * @return
 359  
      */
 360  
     public boolean isId3v1SaveComment()
 361  
     {
 362  64
         return id3v1SaveComment;
 363  
     }
 364  
 
 365  
     /**
 366  
      * @param id3v1SaveGenre
 367  
      */
 368  
     public void setId3v1SaveGenre(boolean id3v1SaveGenre)
 369  
     {
 370  0
         this.id3v1SaveGenre = id3v1SaveGenre;
 371  0
     }
 372  
 
 373  
     /**
 374  
      * @return
 375  
      */
 376  
     public boolean isId3v1SaveGenre()
 377  
     {
 378  64
         return id3v1SaveGenre;
 379  
     }
 380  
 
 381  
     /**
 382  
      * @param id3v1SaveTitle
 383  
      */
 384  
     public void setId3v1SaveTitle(boolean id3v1SaveTitle)
 385  
     {
 386  0
         this.id3v1SaveTitle = id3v1SaveTitle;
 387  0
     }
 388  
 
 389  
     /**
 390  
      * @return
 391  
      */
 392  
     public boolean isId3v1SaveTitle()
 393  
     {
 394  64
         return id3v1SaveTitle;
 395  
     }
 396  
 
 397  
     /**
 398  
      * @param id3v1SaveTrack
 399  
      */
 400  
     public void setId3v1SaveTrack(boolean id3v1SaveTrack)
 401  
     {
 402  0
         this.id3v1SaveTrack = id3v1SaveTrack;
 403  0
     }
 404  
 
 405  
     /**
 406  
      * @return
 407  
      */
 408  
     public boolean isId3v1SaveTrack()
 409  
     {
 410  0
         return id3v1SaveTrack;
 411  
     }
 412  
 
 413  
     /**
 414  
      * @param id3v1SaveYear
 415  
      */
 416  
     public void setId3v1SaveYear(boolean id3v1SaveYear)
 417  
     {
 418  0
         this.id3v1SaveYear = id3v1SaveYear;
 419  0
     }
 420  
 
 421  
     /**
 422  
      * @return
 423  
      */
 424  
     public boolean isId3v1SaveYear()
 425  
     {
 426  64
         return id3v1SaveYear;
 427  
     }
 428  
 
 429  
 
 430  
     /**
 431  
      * @param id3v2PaddingCopyTag
 432  
      */
 433  
     public void setId3v2PaddingCopyTag(boolean id3v2PaddingCopyTag)
 434  
     {
 435  0
         this.id3v2PaddingCopyTag = id3v2PaddingCopyTag;
 436  0
     }
 437  
 
 438  
     /**
 439  
      * @return
 440  
      */
 441  
     public boolean isId3v2PaddingCopyTag()
 442  
     {
 443  0
         return id3v2PaddingCopyTag;
 444  
     }
 445  
 
 446  
 
 447  
     /**
 448  
      * @param id3v2PaddingWillShorten
 449  
      */
 450  
     public void setId3v2PaddingWillShorten(boolean id3v2PaddingWillShorten)
 451  
     {
 452  0
         this.id3v2PaddingWillShorten = id3v2PaddingWillShorten;
 453  0
     }
 454  
 
 455  
     /**
 456  
      * @return
 457  
      */
 458  
     public boolean isId3v2PaddingWillShorten()
 459  
     {
 460  0
         return id3v2PaddingWillShorten;
 461  
     }
 462  
 
 463  
     /**
 464  
      * @param id3v2Save
 465  
      */
 466  
     public void setId3v2Save(boolean id3v2Save)
 467  
     {
 468  0
         this.id3v2Save = id3v2Save;
 469  0
     }
 470  
 
 471  
     /**
 472  
      * @return
 473  
      */
 474  
     public boolean isId3v2Save()
 475  
     {
 476  261
         return id3v2Save;
 477  
     }
 478  
 
 479  
 
 480  
     /**
 481  
      * @return
 482  
      */
 483  
     public Iterator<Class<? extends ID3v24FrameBody>> getKeywordIterator()
 484  
     {
 485  0
         return keywordMap.keySet().iterator();
 486  
     }
 487  
 
 488  
     /**
 489  
      * @param id3v2_4FrameBody
 490  
      * @return
 491  
      */
 492  
     public Iterator<String> getKeywordListIterator(Class<? extends ID3v24FrameBody> id3v2_4FrameBody)
 493  
     {
 494  126
         return keywordMap.get(id3v2_4FrameBody).iterator();
 495  
     }
 496  
 
 497  
     /**
 498  
      * Sets the default language for any ID3v2 tag frames which require it.
 499  
      * While the value will already exist when reading from a file, this value
 500  
      * will be used when a new ID3v2 Frame is created from scratch.
 501  
      *
 502  
      * @param lang language ID, [ISO-639-2] ISO/FDIS 639-2 definition
 503  
      */
 504  
     public void setLanguage(String lang)
 505  
     {
 506  0
         if (Languages.getInstanceOf().getIdToValueMap().containsKey(lang))
 507  
         {
 508  0
             language = lang;
 509  
         }
 510  0
     }
 511  
 
 512  
     /**
 513  
      * Returns the default language for any ID3v2 tag frames which require it.
 514  
      *
 515  
      * @return language ID, [ISO-639-2] ISO/FDIS 639-2 definition
 516  
      */
 517  
     public String getLanguage()
 518  
     {
 519  0
         return language;
 520  
     }
 521  
 
 522  
     /**
 523  
      * @param lyrics3KeepEmptyFieldIfRead
 524  
      */
 525  
     public void setLyrics3KeepEmptyFieldIfRead(boolean lyrics3KeepEmptyFieldIfRead)
 526  
     {
 527  0
         this.lyrics3KeepEmptyFieldIfRead = lyrics3KeepEmptyFieldIfRead;
 528  0
     }
 529  
 
 530  
     /**
 531  
      * @return
 532  
      */
 533  
     public boolean isLyrics3KeepEmptyFieldIfRead()
 534  
     {
 535  0
         return lyrics3KeepEmptyFieldIfRead;
 536  
     }
 537  
 
 538  
     /**
 539  
      * @param lyrics3Save
 540  
      */
 541  
     public void setLyrics3Save(boolean lyrics3Save)
 542  
     {
 543  0
         this.lyrics3Save = lyrics3Save;
 544  0
     }
 545  
 
 546  
     /**
 547  
      * @return
 548  
      */
 549  
     public boolean isLyrics3Save()
 550  
     {
 551  261
         return lyrics3Save;
 552  
     }
 553  
 
 554  
     /**
 555  
      * @param lyrics3SaveEmptyField
 556  
      */
 557  
     public void setLyrics3SaveEmptyField(boolean lyrics3SaveEmptyField)
 558  
     {
 559  0
         this.lyrics3SaveEmptyField = lyrics3SaveEmptyField;
 560  0
     }
 561  
 
 562  
     /**
 563  
      * @return
 564  
      */
 565  
     public boolean isLyrics3SaveEmptyField()
 566  
     {
 567  0
         return lyrics3SaveEmptyField;
 568  
     }
 569  
 
 570  
     /**
 571  
      * Sets if we should save the Lyrics3 field. Defaults to true.
 572  
      *
 573  
      * @param id   Lyrics3 id string
 574  
      * @param save true if you want to save this specific Lyrics3 field.
 575  
      */
 576  
     public void setLyrics3SaveField(String id, boolean save)
 577  
     {
 578  0
         this.lyrics3SaveFieldMap.put(id, save);
 579  0
     }
 580  
 
 581  
     /**
 582  
      * Returns true if we should save the Lyrics3 field asked for in the
 583  
      * argument. Defaults to true.
 584  
      *
 585  
      * @param id Lyrics3 id string
 586  
      * @return true if we should save the Lyrics3 field.
 587  
      */
 588  
     public boolean getLyrics3SaveField(String id)
 589  
     {
 590  0
         return lyrics3SaveFieldMap.get(id);
 591  
     }
 592  
 
 593  
     /**
 594  
      * @return
 595  
      */
 596  
     public HashMap<String, Boolean> getLyrics3SaveFieldMap()
 597  
     {
 598  0
         return lyrics3SaveFieldMap;
 599  
     }
 600  
 
 601  
     /**
 602  
      * @param oldWord
 603  
      * @return
 604  
      */
 605  
     public String getNewReplaceWord(String oldWord)
 606  
     {
 607  0
         return replaceWordMap.get(oldWord);
 608  
     }
 609  
 
 610  
     /**
 611  
      * Sets the number of MP3 frames to sync when trying to find the start of
 612  
      * the MP3 frame data. The start of the MP3 frame data is the start of the
 613  
      * music and is different from the ID3v2 frame data. WinAmp 2.8 seems to
 614  
      * sync 3 frames. Default is 5.
 615  
      *
 616  
      * @param numberMP3SyncFrame number of MP3 frames to sync
 617  
      */
 618  
     public void setNumberMP3SyncFrame(int numberMP3SyncFrame)
 619  
     {
 620  0
         this.numberMP3SyncFrame = numberMP3SyncFrame;
 621  0
     }
 622  
 
 623  
     /**
 624  
      * Returns the number of MP3 frames to sync when trying to find the start
 625  
      * of the MP3 frame data. The start of the MP3 frame data is the start of
 626  
      * the music and is different from the ID3v2 frame data. WinAmp 2.8 seems
 627  
      * to sync 3 frames. Default is 5.
 628  
      *
 629  
      * @return number of MP3 frames to sync
 630  
      */
 631  
     public int getNumberMP3SyncFrame()
 632  
     {
 633  0
         return numberMP3SyncFrame;
 634  
     }
 635  
 
 636  
     /**
 637  
      * @return
 638  
      */
 639  
     public Iterator<String> getOldReplaceWordIterator()
 640  
     {
 641  0
         return replaceWordMap.keySet().iterator();
 642  
     }
 643  
 
 644  
     /**
 645  
      * @param open
 646  
      * @return
 647  
      */
 648  
     public boolean isOpenParenthesis(String open)
 649  
     {
 650  0
         return parenthesisMap.containsKey(open);
 651  
     }
 652  
 
 653  
     /**
 654  
      * @return
 655  
      */
 656  
     public Iterator<String> getOpenParenthesisIterator()
 657  
     {
 658  0
         return parenthesisMap.keySet().iterator();
 659  
     }
 660  
 
 661  
     /**
 662  
      * @param originalSavedAfterAdjustingID3v2Padding
 663  
      *
 664  
      */
 665  
     public void setOriginalSavedAfterAdjustingID3v2Padding(boolean originalSavedAfterAdjustingID3v2Padding)
 666  
     {
 667  0
         this.originalSavedAfterAdjustingID3v2Padding = originalSavedAfterAdjustingID3v2Padding;
 668  0
     }
 669  
 
 670  
     /**
 671  
      * @return
 672  
      */
 673  
     public boolean isOriginalSavedAfterAdjustingID3v2Padding()
 674  
     {
 675  0
         return originalSavedAfterAdjustingID3v2Padding;
 676  
     }
 677  
 
 678  
 
 679  
     /**
 680  
      * Sets the default time stamp format for ID3v2 tags which require it.
 681  
      * While the value will already exist when reading from a file, this value
 682  
      * will be used when a new ID3v2 Frame is created from scratch.
 683  
      * <p/>
 684  
      * <p/>
 685  
      * $01  Absolute time, 32 bit sized, using MPEG frames as unit<br>
 686  
      * $02  Absolute time, 32 bit sized, using milliseconds as unit<br>
 687  
      * </p>
 688  
      *
 689  
      * @param tsf the new default time stamp format
 690  
      */
 691  
     public void setTimeStampFormat(byte tsf)
 692  
     {
 693  0
         if ((tsf == 1) || (tsf == 2))
 694  
         {
 695  0
             timeStampFormat = tsf;
 696  
         }
 697  0
     }
 698  
 
 699  
     /**
 700  
      * Returns the default time stamp format for ID3v2 tags which require it.
 701  
      * <p/>
 702  
      * <p/>
 703  
      * $01  Absolute time, 32 bit sized, using MPEG frames as unit<br>
 704  
      * $02  Absolute time, 32 bit sized, using milliseconds as unit<br>
 705  
      * </p>
 706  
      *
 707  
      * @return the default time stamp format
 708  
      */
 709  
     public byte getTimeStampFormat()
 710  
     {
 711  0
         return timeStampFormat;
 712  
     }
 713  
 
 714  
     /**
 715  
      *
 716  
      */
 717  
     public void setToDefault()
 718  
     {
 719  126
         keywordMap = new HashMap<Class<? extends ID3v24FrameBody>, LinkedList<String>>();
 720  126
         filenameTagSave = false;
 721  126
         id3v1Save = true;
 722  126
         id3v1SaveAlbum = true;
 723  126
         id3v1SaveArtist = true;
 724  126
         id3v1SaveComment = true;
 725  126
         id3v1SaveGenre = true;
 726  126
         id3v1SaveTitle = true;
 727  126
         id3v1SaveTrack = true;
 728  126
         id3v1SaveYear = true;
 729  126
         id3v2PaddingCopyTag = true;
 730  126
         id3v2PaddingWillShorten = false;
 731  126
         id3v2Save = true;
 732  126
         language = "eng";
 733  126
         lyrics3KeepEmptyFieldIfRead = false;
 734  126
         lyrics3Save = true;
 735  126
         lyrics3SaveEmptyField = false;
 736  126
         lyrics3SaveFieldMap = new HashMap<String, Boolean>();
 737  126
         numberMP3SyncFrame = 3;
 738  126
         parenthesisMap = new HashMap<String, String>();
 739  126
         replaceWordMap = new HashMap<String, String>();
 740  126
         timeStampFormat = 2;
 741  126
         unsyncTags = false;
 742  126
         removeTrailingTerminatorOnWrite = true;
 743  126
         id3v23DefaultTextEncoding = TextEncoding.ISO_8859_1;
 744  126
         id3v24DefaultTextEncoding = TextEncoding.ISO_8859_1;
 745  126
         id3v24UnicodeTextEncoding = TextEncoding.UTF_16;
 746  126
         resetTextEncodingForExistingFrames = false;
 747  
 
 748  
         //default all lyrics3 fields to save. id3v1 fields are individual
 749  
         // settings. id3v2 fields are always looked at to save.
 750  126
         Iterator<String> iterator = Lyrics3v2Fields.getInstanceOf().getIdToValueMap().keySet().iterator();
 751  
         String fieldId;
 752  
 
 753  1134
         while (iterator.hasNext())
 754  
         {
 755  1008
             fieldId = iterator.next();
 756  1008
             lyrics3SaveFieldMap.put(fieldId, true);
 757  
         }
 758  
 
 759  
         try
 760  
         {
 761  126
             addKeyword(FrameBodyCOMM.class, "ultimix");
 762  126
             addKeyword(FrameBodyCOMM.class, "dance");
 763  126
             addKeyword(FrameBodyCOMM.class, "mix");
 764  126
             addKeyword(FrameBodyCOMM.class, "remix");
 765  126
             addKeyword(FrameBodyCOMM.class, "rmx");
 766  126
             addKeyword(FrameBodyCOMM.class, "live");
 767  126
             addKeyword(FrameBodyCOMM.class, "cover");
 768  126
             addKeyword(FrameBodyCOMM.class, "soundtrack");
 769  126
             addKeyword(FrameBodyCOMM.class, "version");
 770  126
             addKeyword(FrameBodyCOMM.class, "acoustic");
 771  126
             addKeyword(FrameBodyCOMM.class, "original");
 772  126
             addKeyword(FrameBodyCOMM.class, "cd");
 773  126
             addKeyword(FrameBodyCOMM.class, "extended");
 774  126
             addKeyword(FrameBodyCOMM.class, "vocal");
 775  126
             addKeyword(FrameBodyCOMM.class, "unplugged");
 776  126
             addKeyword(FrameBodyCOMM.class, "acapella");
 777  126
             addKeyword(FrameBodyCOMM.class, "edit");
 778  126
             addKeyword(FrameBodyCOMM.class, "radio");
 779  126
             addKeyword(FrameBodyCOMM.class, "original");
 780  126
             addKeyword(FrameBodyCOMM.class, "album");
 781  126
             addKeyword(FrameBodyCOMM.class, "studio");
 782  126
             addKeyword(FrameBodyCOMM.class, "instrumental");
 783  126
             addKeyword(FrameBodyCOMM.class, "unedited");
 784  126
             addKeyword(FrameBodyCOMM.class, "karoke");
 785  126
             addKeyword(FrameBodyCOMM.class, "quality");
 786  126
             addKeyword(FrameBodyCOMM.class, "uncensored");
 787  126
             addKeyword(FrameBodyCOMM.class, "clean");
 788  126
             addKeyword(FrameBodyCOMM.class, "dirty");
 789  
 
 790  126
             addKeyword(FrameBodyTIPL.class, "f.");
 791  126
             addKeyword(FrameBodyTIPL.class, "feat");
 792  126
             addKeyword(FrameBodyTIPL.class, "feat.");
 793  126
             addKeyword(FrameBodyTIPL.class, "featuring");
 794  126
             addKeyword(FrameBodyTIPL.class, "ftng");
 795  126
             addKeyword(FrameBodyTIPL.class, "ftng.");
 796  126
             addKeyword(FrameBodyTIPL.class, "ft.");
 797  126
             addKeyword(FrameBodyTIPL.class, "ft");
 798  
 
 799  126
             iterator = GenreTypes.getInstanceOf().getValueToIdMap().keySet().iterator();
 800  
 
 801  18774
             while (iterator.hasNext())
 802  
             {
 803  18648
                 addKeyword(FrameBodyCOMM.class, iterator.next());
 804  
             }
 805  
         }
 806  0
         catch (TagException ex)
 807  
         {
 808  
             // this shouldn't happen, indicates coding error
 809  0
             throw new RuntimeException(ex);
 810  126
         }
 811  
 
 812  
 
 813  126
         addReplaceWord("v.", "vs.");
 814  126
         addReplaceWord("vs.", "vs.");
 815  126
         addReplaceWord("versus", "vs.");
 816  126
         addReplaceWord("f.", "feat.");
 817  126
         addReplaceWord("feat", "feat.");
 818  126
         addReplaceWord("featuring", "feat.");
 819  126
         addReplaceWord("ftng.", "feat.");
 820  126
         addReplaceWord("ftng", "feat.");
 821  126
         addReplaceWord("ft.", "feat.");
 822  126
         addReplaceWord("ft", "feat.");
 823  
 
 824  
 
 825  126
         iterator = this.getKeywordListIterator(FrameBodyTIPL.class);
 826  
 
 827  
 
 828  126
         addParenthesis("(", ")");
 829  126
         addParenthesis("[", "]");
 830  126
         addParenthesis("{", "}");
 831  126
         addParenthesis("<", ">");
 832  126
     }
 833  
 
 834  
 
 835  
     /**
 836  
      * @param id3v2FrameBodyClass
 837  
      * @param keyword
 838  
      * @throws TagException
 839  
      */
 840  
     public void addKeyword(Class<? extends ID3v24FrameBody> id3v2FrameBodyClass, String keyword) throws TagException
 841  
     {
 842  23184
         if (AbstractID3v2FrameBody.class.isAssignableFrom(id3v2FrameBodyClass) == false)
 843  
         {
 844  0
             throw new TagException("Invalid class type. Must be AbstractId3v2FrameBody " + id3v2FrameBodyClass);
 845  
         }
 846  
 
 847  23184
         if ((keyword != null) && (keyword.length() > 0))
 848  
         {
 849  
             LinkedList<String> keywordList;
 850  
 
 851  23184
             if (keywordMap.containsKey(id3v2FrameBodyClass) == false)
 852  
             {
 853  252
                 keywordList = new LinkedList<String>();
 854  252
                 keywordMap.put(id3v2FrameBodyClass, keywordList);
 855  
             }
 856  
             else
 857  
             {
 858  22932
                 keywordList = keywordMap.get(id3v2FrameBodyClass);
 859  
             }
 860  
 
 861  23184
             keywordList.add(keyword);
 862  
         }
 863  23184
     }
 864  
 
 865  
     /**
 866  
      * @param open
 867  
      * @param close
 868  
      */
 869  
     public void addParenthesis(String open, String close)
 870  
     {
 871  504
         parenthesisMap.put(open, close);
 872  504
     }
 873  
 
 874  
     /**
 875  
      * @param oldWord
 876  
      * @param newWord
 877  
      */
 878  
     public void addReplaceWord(String oldWord, String newWord)
 879  
     {
 880  1260
         replaceWordMap.put(oldWord, newWord);
 881  1260
     }
 882  
 
 883  
     /**
 884  
      * @return are tags unsynchronized when written if contain bit pattern that could be mistaken for audio marker
 885  
      */
 886  
     public boolean isUnsyncTags()
 887  
     {
 888  603
         return unsyncTags;
 889  
     }
 890  
 
 891  
     /**
 892  
      * Unsync tag where neccessary, currently only applies to IDv23
 893  
      *
 894  
      * @param unsyncTags set whether tags are  unsynchronized when written if contain bit pattern that could
 895  
      *                   be mistaken for audio marker
 896  
      */
 897  
     public void setUnsyncTags(boolean unsyncTags)
 898  
     {
 899  7
         this.unsyncTags = unsyncTags;
 900  7
     }
 901  
 
 902  
     /**
 903  
      * Do we remove unneccessary trailing null characters on write
 904  
      *
 905  
      * @return true if we remove unneccessary trailing null characters on write
 906  
      */
 907  
     public boolean isRemoveTrailingTerminatorOnWrite()
 908  
     {
 909  881
         return removeTrailingTerminatorOnWrite;
 910  
     }
 911  
 
 912  
     /**
 913  
      * Remove unneccessary trailing null characters on write
 914  
      *
 915  
      * @param removeTrailingTerminatorOnWrite
 916  
      *
 917  
      */
 918  
     public void setRemoveTrailingTerminatorOnWrite(boolean removeTrailingTerminatorOnWrite)
 919  
     {
 920  2
         this.removeTrailingTerminatorOnWrite = removeTrailingTerminatorOnWrite;
 921  2
     }
 922  
 
 923  
     /**
 924  
      * Get the default text encoding to use for new v23 frames, when unicode is required
 925  
      * UTF16 will always be used because that is the only valid option for v23/v22
 926  
      *
 927  
      * @return
 928  
      */
 929  
     public byte getId3v23DefaultTextEncoding()
 930  
     {
 931  110
         return id3v23DefaultTextEncoding;
 932  
     }
 933  
 
 934  
     /**
 935  
      * Set the default text encoding to use for new v23 frames, when unicode is required
 936  
      * UTF16 will always be used because that is the only valid option for v23/v22
 937  
      *
 938  
      * @param id3v23DefaultTextEncoding
 939  
      */
 940  
     public void setId3v23DefaultTextEncoding(byte id3v23DefaultTextEncoding)
 941  
     {
 942  6
         if ((id3v23DefaultTextEncoding == TextEncoding.ISO_8859_1) || (id3v23DefaultTextEncoding == TextEncoding.UTF_16))
 943  
         {
 944  6
             this.id3v23DefaultTextEncoding = id3v23DefaultTextEncoding;
 945  
         }
 946  6
     }
 947  
 
 948  
     /**
 949  
      * Get the default text encoding to use for new v24 frames, it defaults to simple ISO8859
 950  
      * but by changing this value you could always used UTF8 for example whether you needed to or not
 951  
      *
 952  
      * @return
 953  
      */
 954  
     public byte getId3v24DefaultTextEncoding()
 955  
     {
 956  193
         return id3v24DefaultTextEncoding;
 957  
     }
 958  
 
 959  
     /**
 960  
      * Set the default text encoding to use for new v24 frames, it defaults to simple ISO8859
 961  
      * but by changing this value you could always used UTF8 for example whether you needed to or not
 962  
      *
 963  
      * @param id3v24DefaultTextEncoding
 964  
      */
 965  
     public void setId3v24DefaultTextEncoding(byte id3v24DefaultTextEncoding)
 966  
     {
 967  1
         if ((id3v24DefaultTextEncoding == TextEncoding.ISO_8859_1) || (id3v24DefaultTextEncoding == TextEncoding.UTF_16) || (id3v24DefaultTextEncoding == TextEncoding.UTF_16BE) || (id3v24DefaultTextEncoding == TextEncoding.UTF_8))
 968  
         {
 969  1
             this.id3v24DefaultTextEncoding = id3v24DefaultTextEncoding;
 970  
         }
 971  
 
 972  1
     }
 973  
 
 974  
     /**
 975  
      * Get the text encoding to use for new v24 frames when unicode is required, it defaults to UTF16 just
 976  
      * because this encoding is understand by all ID3 versions
 977  
      *
 978  
      * @return
 979  
      */
 980  
     public byte getId3v24UnicodeTextEncoding()
 981  
     {
 982  7
         return id3v24UnicodeTextEncoding;
 983  
     }
 984  
 
 985  
     /**
 986  
      * Set the text encoding to use for new v24 frames when unicode is required, it defaults to UTF16 just
 987  
      * because this encoding is understand by all ID3 versions
 988  
      *
 989  
      * @param id3v24UnicodeTextEncoding
 990  
      */
 991  
     public void setId3v24UnicodeTextEncoding(byte id3v24UnicodeTextEncoding)
 992  
     {
 993  1
         if ((id3v24UnicodeTextEncoding == TextEncoding.UTF_16) || (id3v24UnicodeTextEncoding == TextEncoding.UTF_16BE) || (id3v24UnicodeTextEncoding == TextEncoding.UTF_8))
 994  
         {
 995  1
             this.id3v24UnicodeTextEncoding = id3v24UnicodeTextEncoding;
 996  
         }
 997  1
     }
 998  
 
 999  
     /**
 1000  
      * When writing frames if this is set to true then the frame will be written
 1001  
      * using the defaults disregarding the text encoding originally used to create
 1002  
      * the frame.
 1003  
      *
 1004  
      * @return
 1005  
      */
 1006  
     public boolean isResetTextEncodingForExistingFrames()
 1007  
     {
 1008  1001
         return resetTextEncodingForExistingFrames;
 1009  
     }
 1010  
 
 1011  
     /**
 1012  
      * When writing frames if this is set to true then the frame will be written
 1013  
      * using the defaults disregarding the text encoding originally used to create
 1014  
      * the frame.
 1015  
      *
 1016  
      * @param resetTextEncodingForExistingFrames
 1017  
      *
 1018  
      */
 1019  
     public void setResetTextEncodingForExistingFrames(boolean resetTextEncodingForExistingFrames)
 1020  
     {
 1021  8
         this.resetTextEncodingForExistingFrames = resetTextEncodingForExistingFrames;
 1022  8
     }
 1023  
 }