KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > StringNodeFactory


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Somik Raha
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/StringNodeFactory.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/05/24 16:18:12 $
10
// $Revision: 1.12 $
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;
28
29 import java.io.Serializable JavaDoc;
30 import org.htmlparser.lexer.Page;
31
32 import org.htmlparser.nodeDecorators.DecodingNode;
33 import org.htmlparser.nodeDecorators.EscapeCharacterRemovingNode;
34 import org.htmlparser.nodeDecorators.NonBreakingSpaceConvertingNode;
35
36 public class StringNodeFactory
37     extends
38         PrototypicalNodeFactory
39     implements
40         Serializable JavaDoc
41 {
42     /**
43      * Flag to tell the parser to decode strings returned by StringNode's toPlainTextString.
44      * Decoding occurs via the method, org.htmlparser.util.Translate.decode()
45      */

46     protected boolean mDecode;
47
48
49     /**
50      * Flag to tell the parser to remove escape characters, like \n and \t, returned by StringNode's toPlainTextString.
51      * Escape character removal occurs via the method, org.htmlparser.util.ParserUtils.removeEscapeCharacters()
52      */

53     protected boolean mRemoveEscapes;
54
55     /**
56      * Flag to tell the parser to convert non breaking space (from   to a space " ").
57      * If true, this will happen inside StringNode's toPlainTextString.
58      */

59     protected boolean mConvertNonBreakingSpaces;
60     
61     public StringNodeFactory ()
62     {
63         mDecode = false;
64         mRemoveEscapes = false;
65         mConvertNonBreakingSpaces = false;
66     }
67
68     //
69
// NodeFactory interface override
70
//
71

72     /**
73      * Create a new string node.
74      * @param page The page the node is on.
75      * @param start The beginning position of the string.
76      * @param end The ending positiong of the string.
77      */

78     public Text createStringNode (Page page, int start, int end)
79     {
80         Text ret;
81         
82         ret = super.createStringNode (page, start, end);
83         if (getDecode ())
84             ret = new DecodingNode (ret);
85         if (getRemoveEscapes ())
86             ret = new EscapeCharacterRemovingNode (ret);
87         if (getConvertNonBreakingSpaces ())
88             ret = new NonBreakingSpaceConvertingNode (ret);
89
90         return (ret);
91     }
92
93     /**
94      * Set the decoding state.
95      * @param decode If <code>true</code>, string nodes decode text using {@link org.htmlparser.util.Translate#decode}.
96      */

97     public void setDecode (boolean decode)
98     {
99         mDecode = decode;
100     }
101
102     /**
103      * Get the decoding state.
104      * @return <code>true</code> if string nodes decode text.
105      */

106     public boolean getDecode ()
107     {
108         return (mDecode);
109     }
110
111     /**
112      * Set the escape removing state.
113      * @param remove If <code>true</code>, string nodes remove escape characters.
114      */

115     public void setRemoveEscapes (boolean remove)
116     {
117         mRemoveEscapes = remove;
118     }
119
120     /**
121      * Get the escape removing state.
122      * @return The removing state.
123      */

124     public boolean getRemoveEscapes ()
125     {
126         return (mRemoveEscapes);
127     }
128
129     /**
130      * Set the non-breaking space replacing state.
131      * @param convert If <code>true</code>, string nodes replace &semi;nbsp; characters with spaces.
132      */

133     public void setConvertNonBreakingSpaces (boolean convert)
134     {
135         mConvertNonBreakingSpaces = convert;
136     }
137
138     /**
139      * Get the non-breaking space replacing state.
140      * @return The replacing state.
141      */

142     public boolean getConvertNonBreakingSpaces ()
143     {
144         return (mConvertNonBreakingSpaces);
145     }
146 }
147
Popular Tags