Implement Visitor-like mechanism to the XLIFF document
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)
-
-
reporter I’m afraid I do not Martin.
-
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.
-
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?
-
reporter In this specific case ‘master’.
Thanks,
-
ok, done. PR available here: https://bitbucket.org/okapiframework/xliff-toolkit/pull-requests/3/issue-10-create-xliffwalker-for-separating/diff
-
reporter -
assigned issue to
-
assigned issue to
-
reporter - changed status to resolved
-
Awesome, thanks Martin.
- Log in to comment
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.