/** * Utility to apply a visitor to a node list. * Provides for a visitor to modify the contents of a page and get the * modified HTML as a string with code like this: * <pre> * Parser parser = new Parser ("http://whatever"); * NodeList list = parser.parse (null); // no filter * list.visitAllNodesWith (visitor); * System.out.println (list.toHtml ()); * </pre> */ public void visitAllNodesWith (NodeVisitor visitor) throws ParserException { Node node; visitor.beginParsing (); for (int i = 0; i < size; i++) nodeData[i].accept (visitor); visitor.finishedParsing (); } }
/** * Utility to apply a visitor to a node list. * Provides for a visitor to modify the contents of a page and get the * modified HTML as a string with code like this: * <pre> * Parser parser = new Parser ("http://whatever"); * NodeList list = parser.parse (null); // no filter * list.visitAllNodesWith (visitor); * System.out.println (list.toHtml ()); * </pre> */ public void visitAllNodesWith (NodeVisitor visitor) throws ParserException { Node node; visitor.beginParsing (); for (int i = 0; i < size; i++) nodeData[i].accept (visitor); visitor.finishedParsing (); } }
/** * @see org.htmlparser.Tag#accept(org.htmlparser.visitors.NodeVisitor) */ public void accept(NodeVisitor visitor) { // be invisible but show the children (if they like visits) NodeList children = m_decorated.getChildren(); if (children == null) { return; } SimpleNodeIterator itChildren = children.elements(); while (itChildren.hasMoreNodes()) { itChildren.nextNode().accept(visitor); } }
/** * @see org.htmlparser.nodes.TagNode#accept(org.htmlparser.visitors.NodeVisitor) */ public void accept(NodeVisitor visitor) { // be invisible but show the children (if they like visits) NodeList children = m_decorated.getChildren(); if (children == null) { return; } SimpleNodeIterator itChildren = children.elements(); while (itChildren.hasMoreNodes()) { itChildren.nextNode().accept(visitor); } }
/** * @see org.htmlparser.Tag#accept(org.htmlparser.visitors.NodeVisitor) */ public void accept(NodeVisitor visitor) { // be invisible but show the children (if they like visits) NodeList children = m_decorated.getChildren(); if (children == null) { return; } SimpleNodeIterator itChildren = children.elements(); while (itChildren.hasMoreNodes()) { itChildren.nextNode().accept(visitor); } }
/** * Apply the given visitor to the current page. * The visitor is passed to the <code>accept()</code> method of each node * in the page in a depth first traversal. The visitor * <code>beginParsing()</code> method is called prior to processing the * page and <code>finishedParsing()</code> is called after the processing. * @param visitor The visitor to visit all nodes with. * @throws ParserException If a parse error occurs while traversing * the page with the visitor. */ public void visitAllNodesWith (NodeVisitor visitor) throws ParserException { Node node; visitor.beginParsing(); for (NodeIterator e = elements(); e.hasMoreNodes(); ) { node = e.nextNode(); node.accept(visitor); } visitor.finishedParsing(); }
/** * Apply the given visitor to the current page. * The visitor is passed to the <code>accept()</code> method of each node * in the page in a depth first traversal. The visitor * <code>beginParsing()</code> method is called prior to processing the * page and <code>finishedParsing()</code> is called after the processing. * @param visitor The visitor to visit all nodes with. * @throws ParserException If a parse error occurs while traversing * the page with the visitor. */ public void visitAllNodesWith (NodeVisitor visitor) throws ParserException { Node node; visitor.beginParsing(); for (NodeIterator e = elements(); e.hasMoreNodes(); ) { node = e.nextNode(); node.accept(visitor); } visitor.finishedParsing(); }
/** * Convenience method to apply a {@link StringBean} to the filter results. * This may yield duplicate or multiple text elements if the node list * contains nodes from two or more levels in the same nested tag heirarchy, * but if the node list contains only one tag, it provides access to the * text within the node. * @return The textual contents of the nodes that pass through the filter set, * as collected by the StringBean. */ public String getText () { NodeList list; StringBean sb; String ret; list = getNodes (); if (0 != list.size ()) { sb = new StringBean (); for (int i = 0; i < list.size (); i++) list.elementAt (i).accept (sb); ret = sb.getStrings (); } else ret = ""; return (ret); }
/** * Convenience method to apply a {@link StringBean} to the filter results. * This may yield duplicate or multiple text elements if the node list * contains nodes from two or more levels in the same nested tag heirarchy, * but if the node list contains only one tag, it provides access to the * text within the node. * @return The textual contents of the nodes that pass through the filter set, * as collected by the StringBean. */ public String getText () { NodeList list; StringBean sb; String ret; list = getNodes (); if (0 != list.size ()) { sb = new StringBean (); for (int i = 0; i < list.size (); i++) list.elementAt (i).accept (sb); ret = sb.getStrings (); } else ret = ""; return (ret); }
@Override public CompiledTemplate compile(final String template, final ParserConfiguration parserConfiguration) { Source source = new StringSource(template); Page page = new Page(source); Lexer lexer = new Lexer(page); HTMLNodeVisitor visitor = new HTMLNodeVisitor(ehtAttributeprefix, expressionCompiler, inlineCompilers, parserConfiguration); visitor.beginParsing(); try { for (Node node = lexer.nextNode(); node != null; node = lexer.nextNode()) { node.accept(visitor); } } catch (ParserException e) { throw new RuntimeException(e); } visitor.finishedParsing(); return new CompiledTemplateImpl(visitor.getRootNode()); }
child.accept (visitor);
child.accept (visitor);