Coverage Report - org.jaudiotagger.logging.AbstractTagDisplayFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractTagDisplayFormatter
94%
33/35
83%
5/6
0
 
 1  
 /**
 2  
  *  @author : Paul Taylor
 3  
  *  @author : Eric Farng
 4  
  *
 5  
  *  Version @version:$Id: AbstractTagDisplayFormatter.java,v 1.5 2008/07/21 10:46:14 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  
  *  This abstract class defines methods for writing out the contents of a tag in a user-friendly way
 23  
  * Concrete subclasses could implement different versions such as XML Output, PDF and so on. The tag
 24  
  * in all cases is diaplyed as a sort of tree hierachy.
 25  
  */
 26  
 package org.jaudiotagger.logging;
 27  
 
 28  
 import java.util.HashMap;
 29  
 
 30  
 /**
 31  
  * Abstract class that provides structure to use for displaying a files metadata content
 32  
  */
 33  5
 public abstract class AbstractTagDisplayFormatter
 34  
 {
 35  
     protected int level;
 36  
 
 37  7
     private static HashMap<String, String> hexBinaryMap = new HashMap<String, String>();
 38  
 
 39  
     public abstract void openHeadingElement(String type, String value);
 40  
 
 41  
     public abstract void openHeadingElement(String type, boolean value);
 42  
 
 43  
     public abstract void openHeadingElement(String type, int value);
 44  
 
 45  
 
 46  
     public abstract void closeHeadingElement(String type);
 47  
 
 48  
     public abstract void addElement(String type, String value);
 49  
 
 50  
     public abstract void addElement(String type, int value);
 51  
 
 52  
     public abstract void addElement(String type, boolean value);
 53  
 
 54  
     public abstract String toString();
 55  
 
 56  
     /**
 57  
      * Use to display headers as their binary representation
 58  
      */
 59  
     public static String displayAsBinary(byte buffer)
 60  
     {
 61  
         //Convert buffer to hex representation
 62  100
         String hexValue = Integer.toHexString(buffer);
 63  100
         String char1 = "";
 64  100
         String char2 = "";
 65  
         try
 66  
         {
 67  100
             if (hexValue.length() == 8)
 68  
             {
 69  74
                 char1 = hexValue.substring(6, 7);
 70  74
                 char2 = hexValue.substring(7, 8);
 71  
             }
 72  26
             else if (hexValue.length() == 2)
 73  
             {
 74  25
                 char1 = hexValue.substring(0, 1);
 75  25
                 char2 = hexValue.substring(1, 2);
 76  
             }
 77  1
             else if (hexValue.length() == 1)
 78  
             {
 79  1
                 char1 = "0";
 80  1
                 char2 = hexValue.substring(0, 1);
 81  
             }
 82  
         }
 83  0
         catch (StringIndexOutOfBoundsException se)
 84  
         {
 85  0
             return "";
 86  100
         }
 87  100
         return hexBinaryMap.get(char1) + hexBinaryMap.get(char2);
 88  
     }
 89  
 
 90  
     static
 91  
     {
 92  7
         hexBinaryMap.put("0", "0000");
 93  7
         hexBinaryMap.put("1", "0001");
 94  7
         hexBinaryMap.put("2", "0010");
 95  7
         hexBinaryMap.put("3", "0011");
 96  7
         hexBinaryMap.put("4", "0100");
 97  7
         hexBinaryMap.put("5", "0101");
 98  7
         hexBinaryMap.put("6", "0110");
 99  7
         hexBinaryMap.put("7", "0111");
 100  7
         hexBinaryMap.put("8", "1000");
 101  7
         hexBinaryMap.put("9", "1001");
 102  7
         hexBinaryMap.put("a", "1010");
 103  7
         hexBinaryMap.put("b", "1011");
 104  7
         hexBinaryMap.put("c", "1100");
 105  7
         hexBinaryMap.put("d", "1101");
 106  7
         hexBinaryMap.put("e", "1110");
 107  7
         hexBinaryMap.put("f", "1111");
 108  7
     }
 109  
 }