~ubuntu-branches/ubuntu/utopic/libjaudiotagger-java/utopic

« back to all changes in this revision

Viewing changes to src/org/jaudiotagger/logging/AbstractTagDisplayFormatter.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-04-28 23:52:43 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110428235243-pzalvw6lncis3ukf
Tags: 2.0.3-1
* d/control: Drop Depends on default-jre per Debian Java Policy as its
  a library package.
* d/watch: Fix to directly monitor SVN tags.
* Switch to 3.0 (quilt) format.
* Bump Standards-Version to 3.9.2 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 *  @author : Paul Taylor
3
 
 *  @author : Eric Farng
4
 
 *
5
 
 *  Version @version:$Id: AbstractTagDisplayFormatter.java,v 1.7 2009/11/12 15:42:59 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
 
public abstract class AbstractTagDisplayFormatter
34
 
{
35
 
    protected int level;
36
 
 
37
 
    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
 
     * @param buffer
59
 
     * @return
60
 
     */
61
 
    public static String displayAsBinary(byte buffer)
62
 
    {
63
 
        //Convert buffer to hex representation
64
 
        String hexValue = Integer.toHexString(buffer);
65
 
        String char1 = "";
66
 
        String char2 = "";
67
 
        try
68
 
        {
69
 
            if (hexValue.length() == 8)
70
 
            {
71
 
                char1 = hexValue.substring(6, 7);
72
 
                char2 = hexValue.substring(7, 8);
73
 
            }
74
 
            else if (hexValue.length() == 2)
75
 
            {
76
 
                char1 = hexValue.substring(0, 1);
77
 
                char2 = hexValue.substring(1, 2);
78
 
            }
79
 
            else if (hexValue.length() == 1)
80
 
            {
81
 
                char1 = "0";
82
 
                char2 = hexValue.substring(0, 1);
83
 
            }
84
 
        }
85
 
        catch (StringIndexOutOfBoundsException se)
86
 
        {
87
 
            return "";
88
 
        }
89
 
        return hexBinaryMap.get(char1) + hexBinaryMap.get(char2);
90
 
    }
91
 
 
92
 
    static
93
 
    {
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");
110
 
    }
111
 
}
 
1
/**
 
2
 *  @author : Paul Taylor
 
3
 *  @author : Eric Farng
 
4
 *
 
5
 *  Version @version:$Id: AbstractTagDisplayFormatter.java 836 2009-11-12 15:44:07Z paultaylor $
 
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
public abstract class AbstractTagDisplayFormatter
 
34
{
 
35
    protected int level;
 
36
 
 
37
    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
     * @param buffer
 
59
     * @return
 
60
     */
 
61
    public static String displayAsBinary(byte buffer)
 
62
    {
 
63
        //Convert buffer to hex representation
 
64
        String hexValue = Integer.toHexString(buffer);
 
65
        String char1 = "";
 
66
        String char2 = "";
 
67
        try
 
68
        {
 
69
            if (hexValue.length() == 8)
 
70
            {
 
71
                char1 = hexValue.substring(6, 7);
 
72
                char2 = hexValue.substring(7, 8);
 
73
            }
 
74
            else if (hexValue.length() == 2)
 
75
            {
 
76
                char1 = hexValue.substring(0, 1);
 
77
                char2 = hexValue.substring(1, 2);
 
78
            }
 
79
            else if (hexValue.length() == 1)
 
80
            {
 
81
                char1 = "0";
 
82
                char2 = hexValue.substring(0, 1);
 
83
            }
 
84
        }
 
85
        catch (StringIndexOutOfBoundsException se)
 
86
        {
 
87
            return "";
 
88
        }
 
89
        return hexBinaryMap.get(char1) + hexBinaryMap.get(char2);
 
90
    }
 
91
 
 
92
    static
 
93
    {
 
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");
 
110
    }
 
111
}