2
* @author : Paul Taylor
5
* Version @version:$Id: AbstractTagDisplayFormatter.java,v 1.7 2009/11/12 15:42:59 paultaylor Exp $
7
* MusicTag Copyright (C)2003,2004
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.
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.
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
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.
26
package org.jaudiotagger.logging;
28
import java.util.HashMap;
31
* Abstract class that provides structure to use for displaying a files metadata content
33
public abstract class AbstractTagDisplayFormatter
37
private static HashMap<String, String> hexBinaryMap = new HashMap<String, String>();
39
public abstract void openHeadingElement(String type, String value);
41
public abstract void openHeadingElement(String type, boolean value);
43
public abstract void openHeadingElement(String type, int value);
46
public abstract void closeHeadingElement(String type);
48
public abstract void addElement(String type, String value);
50
public abstract void addElement(String type, int value);
52
public abstract void addElement(String type, boolean value);
54
public abstract String toString();
57
* Use to display headers as their binary representation
61
public static String displayAsBinary(byte buffer)
63
//Convert buffer to hex representation
64
String hexValue = Integer.toHexString(buffer);
69
if (hexValue.length() == 8)
71
char1 = hexValue.substring(6, 7);
72
char2 = hexValue.substring(7, 8);
74
else if (hexValue.length() == 2)
76
char1 = hexValue.substring(0, 1);
77
char2 = hexValue.substring(1, 2);
79
else if (hexValue.length() == 1)
82
char2 = hexValue.substring(0, 1);
85
catch (StringIndexOutOfBoundsException se)
89
return hexBinaryMap.get(char1) + hexBinaryMap.get(char2);
94
hexBinaryMap.put("0", "0000");
95
hexBinaryMap.put("1", "0001");
96
hexBinaryMap.put("2", "0010");
97
hexBinaryMap.put("3", "0011");
98
hexBinaryMap.put("4", "0100");
99
hexBinaryMap.put("5", "0101");
100
hexBinaryMap.put("6", "0110");
101
hexBinaryMap.put("7", "0111");
102
hexBinaryMap.put("8", "1000");
103
hexBinaryMap.put("9", "1001");
104
hexBinaryMap.put("a", "1010");
105
hexBinaryMap.put("b", "1011");
106
hexBinaryMap.put("c", "1100");
107
hexBinaryMap.put("d", "1101");
108
hexBinaryMap.put("e", "1110");
109
hexBinaryMap.put("f", "1111");
2
* @author : Paul Taylor
5
* Version @version:$Id: AbstractTagDisplayFormatter.java 836 2009-11-12 15:44:07Z paultaylor $
7
* MusicTag Copyright (C)2003,2004
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.
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.
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
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.
26
package org.jaudiotagger.logging;
28
import java.util.HashMap;
31
* Abstract class that provides structure to use for displaying a files metadata content
33
public abstract class AbstractTagDisplayFormatter
37
private static HashMap<String, String> hexBinaryMap = new HashMap<String, String>();
39
public abstract void openHeadingElement(String type, String value);
41
public abstract void openHeadingElement(String type, boolean value);
43
public abstract void openHeadingElement(String type, int value);
46
public abstract void closeHeadingElement(String type);
48
public abstract void addElement(String type, String value);
50
public abstract void addElement(String type, int value);
52
public abstract void addElement(String type, boolean value);
54
public abstract String toString();
57
* Use to display headers as their binary representation
61
public static String displayAsBinary(byte buffer)
63
//Convert buffer to hex representation
64
String hexValue = Integer.toHexString(buffer);
69
if (hexValue.length() == 8)
71
char1 = hexValue.substring(6, 7);
72
char2 = hexValue.substring(7, 8);
74
else if (hexValue.length() == 2)
76
char1 = hexValue.substring(0, 1);
77
char2 = hexValue.substring(1, 2);
79
else if (hexValue.length() == 1)
82
char2 = hexValue.substring(0, 1);
85
catch (StringIndexOutOfBoundsException se)
89
return hexBinaryMap.get(char1) + hexBinaryMap.get(char2);
94
hexBinaryMap.put("0", "0000");
95
hexBinaryMap.put("1", "0001");
96
hexBinaryMap.put("2", "0010");
97
hexBinaryMap.put("3", "0011");
98
hexBinaryMap.put("4", "0100");
99
hexBinaryMap.put("5", "0101");
100
hexBinaryMap.put("6", "0110");
101
hexBinaryMap.put("7", "0111");
102
hexBinaryMap.put("8", "1000");
103
hexBinaryMap.put("9", "1001");
104
hexBinaryMap.put("a", "1010");
105
hexBinaryMap.put("b", "1011");
106
hexBinaryMap.put("c", "1100");
107
hexBinaryMap.put("d", "1101");
108
hexBinaryMap.put("e", "1110");
109
hexBinaryMap.put("f", "1111");