Package org.htmlparser.util

Examples of org.htmlparser.util.CharacterReference


    public void testEncodeDecodeAll ()
    {
        CharacterReference[] list;
        StringBuffer stimulus;
        StringBuffer response;
        CharacterReference ref;
        String string;

        list = getReferences ();
        stimulus = new StringBuffer ();
        response = new StringBuffer ();
        for (int i = 0; i < list.length; i++)
        {
            ref = list[i];
            stimulus.append ((char)ref.getCharacter ());
            response.append ("&");
            response.append (ref.getKernel ());
            response.append (";");
        }
        string = Translate.encode (stimulus.toString ());
        if (!string.equals (response.toString ()))
            fail ("encoding incorrect, expected \n\"" + response.toString () + "\", encoded \n\"" + string + "\"");
View Full Code Here


        Random random;
        CharacterReference[] list;
        StringBuffer stimulus;
        StringBuffer response;
        char character;
        CharacterReference ref;
        String string;

        random = new Random ();
        list = getReferences ();
        stimulus = new StringBuffer ();
        response = new StringBuffer ();
        for (int i = 0; i < 1000; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                // some random characters
                for (int k = 0; k < 10; k++)
                {
                    character = (char)random.nextInt (127);
                    if (character >= ' ')
                    {
                        if ('&' == character)
                        {
                            stimulus.append (character);
                            response.append ("&amp;");
                        }
                        else if ('"' == character)
                        {
                            stimulus.append (character);
                            response.append ("&quot;");
                        }
                        else if ('<' == character)
                        {
                            stimulus.append (character);
                            response.append ("&lt;");
                        }
                        else if ('>' == character)
                        {
                            stimulus.append (character);
                            response.append ("&gt;");
                        }
                        else
                        {
                            stimulus.append (character);
                            response.append (character);
                        }
                    }
                }
                ref = list[random.nextInt (list.length)];
                stimulus.append ((char)ref.getCharacter ());
                response.append ("&");
                response.append (ref.getKernel ());
                response.append (";");
                // some more random characters
                for (int k = 0; k < 10; k++)
                {
                    character = (char)random.nextInt (127);
View Full Code Here

        CharacterReference[] list;
        StringBuffer stimulus;
        StringBuffer response;
        char character;
        int index;
        CharacterReference ref;
        String kernel;
        ArrayList forbidden;
        String string;

        random = new Random ();
        list = getReferences ();
        stimulus = new StringBuffer ();
        response = new StringBuffer ();
        for (int i = 0; i < 1000; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                // some random characters
                for (int k = 0; k < 10; k++)
                {
                    character = (char)random.nextInt (127);
                    if (character >= ' ')
                    {
                        if ('&' == character)
                        {
                            stimulus.append (character);
                            response.append ("&amp;");
                        }
                        else if ('"' == character)
                        {
                            stimulus.append (character);
                            response.append ("&quot;");
                        }
                        else if ('<' == character)
                        {
                            stimulus.append (character);
                            response.append ("&lt;");
                        }
                        else if ('>' == character)
                        {
                            stimulus.append (character);
                            response.append ("&gt;");
                        }
                        else
                        {
                            stimulus.append (character);
                            response.append (character);
                        }
                    }
                }
                index = random.nextInt (list.length);
                ref = list[index];
                kernel = ref.getKernel ();
                stimulus.append ((char)ref.getCharacter ());
                response.append ("&");
                response.append (kernel);
                // to be fair, we ensure that the next character isn't valid
                // for a different reference, i.e. &sup shouldn't be followed
                // by a 1, 2, 3 or e
View Full Code Here

TOP

Related Classes of org.htmlparser.util.CharacterReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.