[Htmlparser-cvs] htmlparser/src/org/htmlparser/nodeDecorators AbstractNodeDecorator.java,1.22,1.23 D
Brought to you by:
derrickoswald
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodeDecorators In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30655/htmlparser/src/org/htmlparser/nodeDecorators Modified Files: AbstractNodeDecorator.java DecodingNode.java EscapeCharacterRemovingNode.java NonBreakingSpaceConvertingNode.java package.html Log Message: Documentation revamp part one. Deprecated node decorators. Added doSemanticAction for Text and Comment nodes. Added missing sitecapturer scripts. Fixed DOS batch files to work when called from any location. Index: NonBreakingSpaceConvertingNode.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodeDecorators/NonBreakingSpaceConvertingNode.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** NonBreakingSpaceConvertingNode.java 24 May 2004 16:18:18 -0000 1.14 --- NonBreakingSpaceConvertingNode.java 10 Apr 2005 23:20:43 -0000 1.15 *************** *** 29,32 **** --- 29,39 ---- import org.htmlparser.Text; + /** + * @deprecated Use direct subclasses or dynamic proxies instead. + * <p>Use either direct subclasses of the appropriate node and set them on the + * {@link org.htmlparser.PrototypicalNodeFactory PrototypicalNodeFactory}, + * or use a dynamic proxy implementing the required node type interface.</p> + * @see AbstractNodeDecorator + */ public class NonBreakingSpaceConvertingNode extends AbstractNodeDecorator { public NonBreakingSpaceConvertingNode(Text newDelegate) { Index: package.html =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodeDecorators/package.html,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** package.html 29 Feb 2004 15:09:57 -0000 1.1 --- package.html 10 Apr 2005 23:20:43 -0000 1.2 *************** *** 33,37 **** <BODY> The nodeDecorators package contains classes that use the Decorator pattern. ! The nodeDecorators package contains example decorators that alter node behaviour. For example, the DecodingNode class overrides the toPlainTextString() method of all nodes it wraps and applies the Translate class decode() method to the --- 33,41 ---- <BODY> The nodeDecorators package contains classes that use the Decorator pattern. ! <p><b>Deprecated.</b> <i>Use either prototypes or dynamic proxies instead.<br> ! Use either direct subclasses of the appropriate node and set them on the ! {@link org.htmlparser.PrototypicalNodeFactory PrototypicalNodeFactory}, ! or use a dynamic proxy implementing the required node type interface.</i></p> ! <p>The nodeDecorators package contains example decorators that alter node behaviour. For example, the DecodingNode class overrides the toPlainTextString() method of all nodes it wraps and applies the Translate class decode() method to the *************** *** 48,54 **** System.out.println (content.toString ()); </pre> ! Decorators are a powerful way of performing the same operation on every node. ! <pre> ! </pre> </BODY> </HTML> --- 52,58 ---- System.out.println (content.toString ()); </pre> ! Decorators are a powerful way of performing the same operation on every node.</p> ! @see org.htmlparser.StringNodeFactory ! @see org.htmlparser.nodeDecorators.AbstractNodeDecorator </BODY> </HTML> Index: DecodingNode.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodeDecorators/DecodingNode.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** DecodingNode.java 24 May 2004 16:18:18 -0000 1.16 --- DecodingNode.java 10 Apr 2005 23:20:43 -0000 1.17 *************** *** 30,33 **** --- 30,40 ---- import org.htmlparser.util.Translate; + /** + * @deprecated Use direct subclasses or dynamic proxies instead. + * <p>Use either direct subclasses of the appropriate node and set them on the + * {@link org.htmlparser.PrototypicalNodeFactory PrototypicalNodeFactory}, + * or use a dynamic proxy implementing the required node type interface.</p> + * @see AbstractNodeDecorator + */ public class DecodingNode extends AbstractNodeDecorator { public DecodingNode(Text node) { Index: AbstractNodeDecorator.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodeDecorators/AbstractNodeDecorator.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** AbstractNodeDecorator.java 2 Jul 2004 00:49:27 -0000 1.22 --- AbstractNodeDecorator.java 10 Apr 2005 23:20:43 -0000 1.23 *************** *** 35,38 **** --- 35,129 ---- import org.htmlparser.visitors.NodeVisitor; + /** + * Node wrapping base class. + * @deprecated Use direct subclasses or dynamic proxies instead. + * <p>Use either direct subclasses of the appropriate node and set them on the + * {@link org.htmlparser.PrototypicalNodeFactory PrototypicalNodeFactory}, + * or use a dynamic proxy implementing the required node type interface. + * In the former case this avoids the wrapping and delegation, while the latter + * case handles the wrapping and delegation without this class.</p> + * <p>Here is an example of how to use dynamic proxies to accomplish the same + * effect as using decorators to wrap Text nodes: + * <pre> + 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); + } + } + * </pre> + * </p> + */ public abstract class AbstractNodeDecorator implements Text { *************** *** 65,76 **** } - public int elementBegin() { - return delegate.elementBegin(); - } - - public int elementEnd() { - return delegate.elementEnd(); - } - /** * Gets the starting position of the node. --- 156,159 ---- Index: EscapeCharacterRemovingNode.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodeDecorators/EscapeCharacterRemovingNode.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** EscapeCharacterRemovingNode.java 24 May 2004 16:18:18 -0000 1.14 --- EscapeCharacterRemovingNode.java 10 Apr 2005 23:20:43 -0000 1.15 *************** *** 30,33 **** --- 30,40 ---- import org.htmlparser.util.ParserUtils; + /** + * @deprecated Use direct subclasses or dynamic proxies instead. + * <p>Use either direct subclasses of the appropriate node and set them on the + * {@link org.htmlparser.PrototypicalNodeFactory PrototypicalNodeFactory}, + * or use a dynamic proxy implementing the required node type interface.</p> + * @see AbstractNodeDecorator + */ public class EscapeCharacterRemovingNode extends AbstractNodeDecorator { public EscapeCharacterRemovingNode(Text newDelegate) { |