|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.htmlparser.PrototypicalNodeFactory org.htmlparser.StringNodeFactory
A more efficient implementation of affecting all string nodes, is to replace
the Text node prototype in the PrototypicalNodeFactory
with a
custom TextNode that performs the required operation.
For example, if you were using:
StringNodeFactory factory = new StringNodeFactory(); factory.setDecode(true);to decode all text issued from
Text.toPlainTextString()
,
you would instead create a subclass of TextNode
and set it as the prototype for text node generation:
PrototypicalNodeFactory factory = new PrototypicalNodeFactory (); factory.setTextPrototype (new TextNode () { public String toPlainTextString() { return (org.htmlparser.util.Translate.decode (super.toPlainTextString ())); } });Similar constructs apply to removing escapes and converting non-breaking spaces, which were the examples previously provided.
Using a subclass avoids the wrapping and delegation inherent in the decorator pattern, with subsequent improvements in processing speed and memory usage.
Field Summary | |
protected boolean |
mConvertNonBreakingSpaces
Deprecated. Flag to toggle converting non breaking spaces (from to space " "). |
protected boolean |
mDecode
Deprecated. Flag to toggle decoding of strings. |
protected boolean |
mRemoveEscapes
Deprecated. Flag to toggle removal of escape characters, like \n and \t. |
Fields inherited from class org.htmlparser.PrototypicalNodeFactory |
mBlastocyst, mRemark, mTag, mText |
Constructor Summary | |
StringNodeFactory()
Deprecated. Create the default string node factory. |
Method Summary | |
Text |
createStringNode(Page page,
int start,
int end)
Deprecated. Create a new string node. |
boolean |
getConvertNonBreakingSpaces()
Deprecated. Get the non-breaking space replacing state. |
boolean |
getDecode()
Deprecated. Get the decoding state. |
boolean |
getRemoveEscapes()
Deprecated. Get the escape removing state. |
void |
setConvertNonBreakingSpaces(boolean convert)
Deprecated. Set the non-breaking space replacing state. |
void |
setDecode(boolean decode)
Deprecated. Set the decoding state. |
void |
setRemoveEscapes(boolean remove)
Deprecated. Set the escape removing state. |
Methods inherited from class org.htmlparser.PrototypicalNodeFactory |
clear, createRemarkNode, createTagNode, get, getRemarkPrototype, getTagNames, getTagPrototype, getTextPrototype, put, registerTag, registerTags, remove, setRemarkPrototype, setTagPrototype, setTextPrototype, unregisterTag |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected boolean mDecode
protected boolean mRemoveEscapes
protected boolean mConvertNonBreakingSpaces
Constructor Detail |
public StringNodeFactory()
Method Detail |
public Text createStringNode(Page page, int start, int end)
createStringNode
in interface NodeFactory
createStringNode
in class PrototypicalNodeFactory
page
- The page the node is on.start
- The beginning position of the string.end
- The ending positiong of the string.
public void setDecode(boolean decode)
decode
- If true
, string nodes decode text using
Translate.decode(java.lang.String)
.getDecode()
public boolean getDecode()
true
if string nodes decode text.setDecode(boolean)
public void setRemoveEscapes(boolean remove)
remove
- If true
, string nodes remove escape
characters.getRemoveEscapes()
public boolean getRemoveEscapes()
setRemoveEscapes(boolean)
public void setConvertNonBreakingSpaces(boolean convert)
convert
- If true
, string nodes replace ;nbsp;
characters with spaces.getConvertNonBreakingSpaces()
public boolean getConvertNonBreakingSpaces()
setConvertNonBreakingSpaces(boolean)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |