FileDocCategorySizeDatePackage
XMLTagDisplayFormatter.javaAPI DocJaudiotagger 2.0.45933Wed Mar 30 16:11:54 BST 2011org.jaudiotagger.logging

XMLTagDisplayFormatter

public class XMLTagDisplayFormatter extends AbstractTagDisplayFormatter
author
: Paul Taylor Version @version:$Id: XMLTagDisplayFormatter.java 836 2009-11-12 15:44:07Z paultaylor $ MusicTag Copyright (C)2003,2004 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, you can get a copy from http://www.opensource.org/licenses/lgpl-license.php or write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Fields Summary
private static XMLTagDisplayFormatter
formatter
protected static final String
xmlOpenStart
protected static final String
xmlOpenEnd
protected static final String
xmlCloseStart
protected static final String
xmlCloseEnd
protected static final String
xmlSingleTagClose
protected static final String
xmlCDataTagOpen
protected static final String
xmlCDataTagClose
StringBuffer
sb
Constructors Summary
public XMLTagDisplayFormatter()


     
    

    
Methods Summary
public voidaddElement(java.lang.String type, java.lang.String value)

        sb.append(xmlFullTag(type, replaceXMLCharacters(value)));
    
public voidaddElement(java.lang.String type, int value)

        addElement(type, String.valueOf(value));
    
public voidaddElement(java.lang.String type, boolean value)

        addElement(type, String.valueOf(value));
    
public voidcloseHeadingElement(java.lang.String type)

        sb.append(xmlClose(type));
    
public voidopenHeadingElement(java.lang.String type, int value)

        openHeadingElement(type, String.valueOf(value));
    
public voidopenHeadingElement(java.lang.String type, java.lang.String value)

        if (value.length() == 0)
        {
            sb.append(xmlOpen(type));
        }
        else
        {
            sb.append(xmlOpenHeading(type, replaceXMLCharacters(value)));
        }
    
public voidopenHeadingElement(java.lang.String type, boolean value)

        openHeadingElement(type, String.valueOf(value));
    
public static java.lang.StringreplaceXMLCharacters(java.lang.String xmlData)
Replace any special xml characters with the appropiate escape sequences required to be done for the actual element names

param
xmlData
return

        StringBuffer sb = new StringBuffer();
        StringCharacterIterator sCI = new StringCharacterIterator(xmlData);
        for (char c = sCI.first(); c != CharacterIterator.DONE; c = sCI.next())
        {
            switch (c)
            {
                case'&":
                    sb.append("&");
                    break;
                case'<":
                    sb.append("<");
                    break;
                case'>":
                    sb.append(">");
                    break;
                case'"":
                    sb.append(""");
                    break;
                case'\'":
                    sb.append("'");
                    break;


                default:
                    sb.append(c);
            }
        }
        return sb.toString();
    
public java.lang.StringtoString()

        return sb.toString();
    
public static java.lang.StringxmlCData(java.lang.String xmlData)
Return CDATA tag around xml data e.g We also need to deal with special chars

param
xmlData
return

        char tempChar;
        StringBuffer replacedString = new StringBuffer();
        for (int i = 0; i < xmlData.length(); i++)
        {
            tempChar = xmlData.charAt(i);
            if ((Character.isLetterOrDigit(tempChar)) || (Character.isSpaceChar(tempChar)))
            {
                replacedString.append(tempChar);
            }
            else
            {
                replacedString.append("#x").append(Character.digit(tempChar, 16));
            }
        }
        return xmlCDataTagOpen + replacedString + xmlCDataTagClose;
    
public static java.lang.StringxmlClose(java.lang.String xmlName)
Return xml close tag around a string e.g

param
xmlName
return

        return xmlCloseStart + xmlName + xmlCloseEnd;
    
public static java.lang.StringxmlFullTag(java.lang.String xmlName, java.lang.String data)

        return xmlOpen(xmlName) + xmlCData(data) + xmlClose(xmlName);
    
public static java.lang.StringxmlOpen(java.lang.String xmlName)
Return xml open tag round a string e.g

param
xmlName
return

        return xmlOpenStart + xmlName + xmlOpenEnd;
    
public static java.lang.StringxmlOpenHeading(java.lang.String name, java.lang.String data)

        return (xmlOpen(name + " id=\"" + data + "\""));
    
public static java.lang.StringxmlSingleTag(java.lang.String data)

        return xmlOpenStart + data + xmlSingleTagClose;