1. Okapi Framework
  2. Okapi and localization
  3. XLIFF Toolkit
  4. Issues


Issue #10 resolved

Implement Visitor-like mechanism to the XLIFF document

Yves Savourel
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)

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. Martin Wunderlich

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

    Yves Savourel Chase 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. Log in to comment