KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > nodeDecoratorTests > NonBreakingSpaceConvertingNodeTest


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Joshua Kerievsky
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/nodeDecoratorTests/NonBreakingSpaceConvertingNodeTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/01/02 16:24:56 $
10
// $Revision: 1.17 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.tests.nodeDecoratorTests;
28
29 import org.htmlparser.StringNodeFactory;
30 import org.htmlparser.tests.ParserTestCase;
31 import org.htmlparser.util.NodeIterator;
32 import org.htmlparser.util.ParserException;
33
34 public class NonBreakingSpaceConvertingNodeTest extends ParserTestCase {
35     static
36     {
37         System.setProperty ("org.htmlparser.tests.nodeDecoratorTests.NonBreakingSpaceConvertingNodeTest", "NonBreakingSpaceConvertingNodeTest");
38     }
39
40     public NonBreakingSpaceConvertingNodeTest(String JavaDoc name) {
41         super(name);
42     }
43
44     private String JavaDoc parseToObtainDecodedResult(String JavaDoc STRING_TO_DECODE)
45         throws ParserException {
46         StringBuffer JavaDoc decodedContent = new StringBuffer JavaDoc();
47
48         StringNodeFactory stringNodeFactory = new StringNodeFactory();
49         stringNodeFactory.setConvertNonBreakingSpaces (true);
50         createParser(STRING_TO_DECODE);
51         parser.setNodeFactory(stringNodeFactory);
52
53         NodeIterator nodes = parser.elements();
54
55         while (nodes.hasMoreNodes())
56             decodedContent.append(nodes.nextNode().toPlainTextString());
57
58         return decodedContent.toString();
59     }
60
61     public void testOneNonBreakingSpace() throws Exception JavaDoc {
62         String JavaDoc ENCODED_WITH_NON_BREAKING_SPACE =
63             "Here is string with \u00a0 inside of it.";
64
65         String JavaDoc DECODED_WITH_NON_BREAKING_SPACE =
66             "Here is string with inside of it.";
67
68         assertEquals (
69             "\u00a0 was converted to a space correctly",
70             DECODED_WITH_NON_BREAKING_SPACE,
71             parseToObtainDecodedResult(ENCODED_WITH_NON_BREAKING_SPACE));
72     }
73
74     public void testMultipleNonBreakingSpace() throws Exception JavaDoc {
75         String JavaDoc ENCODED_WITH_NON_BREAKING_SPACE =
76             "\u00a0Here is string with \u00a0 inside of it\u00a0.";
77
78         String JavaDoc DECODED_WITH_NON_BREAKING_SPACE =
79             " Here is string with inside of it .";
80
81         assertEquals (
82             "\u00a0 was converted to a space correctly",
83             DECODED_WITH_NON_BREAKING_SPACE,
84             parseToObtainDecodedResult(ENCODED_WITH_NON_BREAKING_SPACE));
85     }
86
87 }
88
Popular Tags