org.htmlparser
Class StringNodeFactory

java.lang.Object
  extended byorg.htmlparser.PrototypicalNodeFactory
      extended byorg.htmlparser.StringNodeFactory
All Implemented Interfaces:
NodeFactory, java.io.Serializable

Deprecated. Use PrototypicalNodeFactory#setTextPrototype(Text)

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.

public class StringNodeFactory
extends PrototypicalNodeFactory
implements java.io.Serializable

See Also:
Serialized Form

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

mDecode

protected boolean mDecode
Deprecated. 
Flag to toggle decoding of strings. Decoding occurs via the method, org.htmlparser.util.Translate.decode()


mRemoveEscapes

protected boolean mRemoveEscapes
Deprecated. 
Flag to toggle removal of escape characters, like \n and \t. Escape character removal occurs via the method, org.htmlparser.util.ParserUtils.removeEscapeCharacters()


mConvertNonBreakingSpaces

protected boolean mConvertNonBreakingSpaces
Deprecated. 
Flag to toggle converting non breaking spaces (from   to space " "). If true, this will happen inside StringNode's toPlainTextString.

Constructor Detail

StringNodeFactory

public StringNodeFactory()
Deprecated. 
Create the default string node factory.

Method Detail

createStringNode

public Text createStringNode(Page page,
                             int start,
                             int end)
Deprecated. 
Create a new string node.

Specified by:
createStringNode in interface NodeFactory
Overrides:
createStringNode in class PrototypicalNodeFactory
Parameters:
page - The page the node is on.
start - The beginning position of the string.
end - The ending positiong of the string.
Returns:
The text node for the page and range given.

setDecode

public void setDecode(boolean decode)
Deprecated. 
Set the decoding state.

Parameters:
decode - If true, string nodes decode text using Translate.decode(java.lang.String).
See Also:
getDecode()

getDecode

public boolean getDecode()
Deprecated. 
Get the decoding state.

Returns:
true if string nodes decode text.
See Also:
setDecode(boolean)

setRemoveEscapes

public void setRemoveEscapes(boolean remove)
Deprecated. 
Set the escape removing state.

Parameters:
remove - If true, string nodes remove escape characters.
See Also:
getRemoveEscapes()

getRemoveEscapes

public boolean getRemoveEscapes()
Deprecated. 
Get the escape removing state.

Returns:
The removing state.
See Also:
setRemoveEscapes(boolean)

setConvertNonBreakingSpaces

public void setConvertNonBreakingSpaces(boolean convert)
Deprecated. 
Set the non-breaking space replacing state.

Parameters:
convert - If true, string nodes replace ;nbsp; characters with spaces.
See Also:
getConvertNonBreakingSpaces()

getConvertNonBreakingSpaces

public boolean getConvertNonBreakingSpaces()
Deprecated. 
Get the non-breaking space replacing state.

Returns:
The replacing state.
See Also:
setConvertNonBreakingSpaces(boolean)