Implement Visitor-like mechanism to the XLIFF document

Issue #10 resolved
YvesS created an issue

From Martin: (original email: https://groups.google.com/forum/#!topic/okapi-devel/gPXTy6J8Zgw)

When manipulating an XLIFF2 document, I find myself iterating over the segments quite often, using this here pattern:

    for (String fileNodeID : xlf.getFileNodeIds()) {
        FileNode fileNode = xlf.getFileNode(fileNodeID);

        for (UnitNode unitNode : fileNode.getUnitNodes()) {
            Unit unit = unitNode.get();
            int segmentIndex = 0;

            for (Segment segment : unit.getSegments()) {
              // Do interesting stuff with the segment here.
              // (and its context)
              ...
              segmentIndex++
            }

It would be nice to separate the actual traversal of the XLIFF structure from the stuff that is done with the segment. So, I thought it might be possible to apply something like the visitor pattern to provide better abstraction and a clear separation of traversal and data manipulation. Each visitor class would have to have access to the context consisting of File, Unit, Segment and Segment Index. So, the pure visitor pattern might not be applicable as this context would be lost.

Comments (9)

  1. Martn Wunderl

    I have created a branch for this and merge my changes there: https://bitbucket.org/okapiframework/xliff-toolkit/branch/Issue_10_XLIFFwalker_by_Martin

    @ysavourel @tingley This is ready for code review. I don't want to pollute the main dev branch with the individual commits from the feature branch. Do you know how to create a pull request on Bitbucket and doing a squash commit for the whole branch at the same time? If not, I'll suqsh commit to my fork first and create the PR from there.

  2. Chase Tingley

    GitHub just added the ability to squash PRs on merge a couple months ago, but AFAIK bitbucket doesn't have it. So you would need to squash manually, as you suggest.

  3. Martn Wunderl

    OK, cool. I'll squash the commits first in my fork and then create the PR. Which branch should I create the PR from, dev or master?

  4. Log in to comment