|
|||||||||||
PREV NEXT | FRAMES NO FRAMES |
Deprecated Classes | |
org.htmlparser.nodeDecorators.AbstractNodeDecorator
Use direct subclasses or dynamic proxies instead. Use either direct subclasses of the appropriate node and set them on the
Here is an example of how to use dynamic proxies to accomplish the same effect as using decorators to wrap Text nodes: import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import org.htmlparser.Parser; import org.htmlparser.PrototypicalNodeFactory; import org.htmlparser.Text; import org.htmlparser.nodes.TextNode; import org.htmlparser.util.ParserException; public class TextProxy implements InvocationHandler { protected Object mObject; public static Object newInstance (Object object) { Class cls; cls = object.getClass (); return (Proxy.newProxyInstance ( cls.getClassLoader (), cls.getInterfaces (), new TextProxy (object))); } private TextProxy (Object object) { mObject = object; } public Object invoke (Object proxy, Method m, Object[] args) throws Throwable { Object result; String name; try { result = m.invoke (mObject, args); name = m.getName (); if (name.equals ("clone")) result = newInstance (result); // wrap the cloned object else if (name.equals ("doSemanticAction")) // or other methods System.out.println (mObject); // do the needful on the TextNode } catch (InvocationTargetException e) { throw e.getTargetException (); } catch (Exception e) { throw new RuntimeException ("unexpected invocation exception: " + e.getMessage()); } finally { } return (result); } public static void main (String[] args) throws ParserException { // create the wrapped text node and set it as the prototype Text text = (Text) TextProxy.newInstance (new TextNode (null, 0, 0)); PrototypicalNodeFactory factory = new PrototypicalNodeFactory (); factory.setTextPrototype (text); // perform the parse Parser parser = new Parser (args[0]); parser.setNodeFactory (factory); parser.parse (null); } } |
|
org.htmlparser.nodeDecorators.DecodingNode
Use direct subclasses or dynamic proxies instead. Use either direct subclasses of the appropriate node and set them on the
|
|
org.htmlparser.nodeDecorators.EscapeCharacterRemovingNode
Use direct subclasses or dynamic proxies instead. Use either direct subclasses of the appropriate node and set them on the
|
|
org.htmlparser.util.LinkProcessor
Use a Page object instead. |
|
org.htmlparser.nodeDecorators.NonBreakingSpaceConvertingNode
Use direct subclasses or dynamic proxies instead. Use either direct subclasses of the appropriate node and set them on the
|
|
org.htmlparser.StringNodeFactory
Use PrototypicalNodeFactory#setTextPrototype(Text) A more efficient implementation of affecting all string nodes, is to replace
the Text node prototype in the 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. |
|
|||||||||||
PREV NEXT | FRAMES NO FRAMES |