Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(142)

Issue 214044: Introduce DomWalker (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
15 years, 11 months ago by johnfargo
Modified:
15 years, 11 months ago
Reviewers:
henry.saputra, zhoresh, shindig.remailer
Base URL:
http://svn.apache.org/repos/asf/shindig/trunk/
Visibility:
Public.

Description

DomWalker is a helper class/framework for writing rewriters that take the very typical form of walking a DOM tree and manipulating nodes as you go. It supports multiple Visitors at the same time, reducing the need for multiple DOM walks depending on the semantics. As of this CL the framework isn't used -- it sets up several follow-up CLs to come.

Patch Set 1 #

Total comments: 23

Patch Set 2 : Accommodating current comments. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+554 lines, -0 lines) Patch
java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/DomWalker.java View 1 1 chunk +256 lines, -0 lines 0 comments Download
java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/DomWalkerTest.java View 1 1 chunk +298 lines, -0 lines 0 comments Download

Messages

Total messages: 7
johnfargo
15 years, 11 months ago (2010-02-18 17:32:37 UTC) #1
zhoresh
Looks promising. See some structural comments below. http://codereview.appspot.com/214044/diff/1/3 File java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/DomWalker.java (right): http://codereview.appspot.com/214044/diff/1/3#newcode53 java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/DomWalker.java:53: public interface ...
15 years, 11 months ago (2010-02-18 19:23:44 UTC) #2
johnfargo
Thanks for the review! Comments provided here. Patch coming in a moment. http://codereview.appspot.com/214044/diff/1/3 File java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/DomWalker.java ...
15 years, 11 months ago (2010-02-19 19:52:32 UTC) #3
henry.saputra
http://codereview.appspot.com/214044/diff/1/3 File java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/DomWalker.java (right): http://codereview.appspot.com/214044/diff/1/3#newcode53 java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/DomWalker.java:53: public interface Visitor { I think this is fine ...
15 years, 11 months ago (2010-02-19 19:55:06 UTC) #4
johnfargo
Accommodating current comments.
15 years, 11 months ago (2010-02-19 20:06:00 UTC) #5
zhoresh
http://codereview.appspot.com/214044/diff/1/3 File java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/DomWalker.java (right): http://codereview.appspot.com/214044/diff/1/3#newcode53 java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/DomWalker.java:53: public interface Visitor { On 2010/02/19 19:55:06, henry.saputra wrote: ...
15 years, 11 months ago (2010-02-19 23:26:39 UTC) #6
johnfargo
15 years, 11 months ago (2010-02-20 03:59:02 UTC) #7
On Fri, Feb 19, 2010 at 3:26 PM, <zhoresh@gmail.com> wrote:

>
> http://codereview.appspot.com/214044/diff/1/3
> File
>
> java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/DomWalker.java
> (right):
>
> http://codereview.appspot.com/214044/diff/1/3#newcode53
>
>
java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/DomWalker.java:53:
> public interface Visitor {
> On 2010/02/19 19:55:06, henry.saputra wrote:
>
>> I think this is fine since John is using Visitor pattern to manipulate
>>
> the DOM
>
>> elements. Maybe changing it to NodeVisitor would be better just in
>>
> case we need
>
>> other kind of Visitor.
>>
>
>  On 2010/02/18 19:23:44, zhoresh wrote:
>> > This is the actual rewriter. Maybe a better name: DomNodeRewriter
>>
>
>
>
> Fine by me.
>
>
> http://codereview.appspot.com/214044/diff/1/3#newcode145
>
>
java/gadgets/src/main/java/org/apache/shindig/gadgets/rewrite/DomWalker.java:145:
> Map<Visitor, List<Node>> reservations = Maps.newHashMap();
> On 2010/02/19 19:52:32, johnfargo wrote:
>
>> Hm, interesting. Doing that would ensure that revisiting order is the
>>
> same as
>
>> the first-reserved order, which seems a little arbitrary to me. I've
>>
> changed the
>
>> code to revisit in visitors-order, which seems more useful. Thoughts?
>>
>
>  On 2010/02/18 19:23:44, zhoresh wrote:
>> > Change to List< Pair<Node, Visitor>>
>> > this way you promise revisiting order to be same as scan order.
>> >
>>
>
> I guess my question here is why revisit is done on list of nodes and not
> just one like visit?
> I am not sure I see the advantage, and maybe do revisit on a node might
> simplify things.


The follow-up CLs would make this a lot more clear :)

To give an example, consider the concatenation operation. In this paradigm,
it's implemented by visit(...) reserving all nodes whose previous or next
sibling is a same-typed external reference. When revisit(...)ing, it's the
job of the Visitor to take *all* the reserved nodes at once and push them
together. If revisit(...) simply used a single node (which was the original
impl), then the Visitor would have to remember all the nodes it reserved and
only perform a modification action when it gets to the last one, and at that
it would have to maintain its own list of reserved nodes. Changing to
List<Node>, though somewhat odd, easily fixed that.


>
>
> http://codereview.appspot.com/214044/show
>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b