Traversing document entities
The visitor pattern enables a class implementer to traverse all child objects in an object hierarchy without needing to know how the hierarchy is implemented or changes to the implementation.
Implementing IMarkupDataVisitor
Your class must derive from the IMarkupDataVisitor interface and explicitly implement all its methods. To use the visitor pattern effectively, write a private method that calls accept visitor for all markup data child items of the given parent.
Use this method to initiate traversal of all items in a paragraph-unit and write them to the translated target document. Implement this in the ProcessParagraphUnit method. Pass the Source and Target paragraphs from the IParagraphUnit object to AppendItems(). The IMarkupDataVisitor interface methods process the various types of text and markup objects in the paragraph data hierarchies.
VisitTagPair()
The VisitTagPair method executes when visiting a tag pair object of type ITagPair. Typically, process this object by writing the tag pair start tag to the target document, processing all child nodes, and writing the tag pair end tag. Some bilingual writers may prefer to cache this information first. Call the AppendItems() helper method with the tag object as a parameter to process all child nodes of a tag pair.
VisitPlaceholderTag()
The VisitPlaceholderTag method executes when visiting a placeholder tag object of type IPlaceholderTag. Typically, write the placeholder tag to the target document. Some bilingual writers may prefer to cache this information first.
VisitText()
The VisitText method executes when visiting a text object of type IText. Write the content to the target document. When processing text items, consider the ContentRestriction value. The content restriction type indicates whether to write the source or target text. For translatable paragraph-units, call AppendItems() for the source paragraph when the restriction requires source text. Subsequent VisitText calls will then process the source text.
VisitSegment()
The VisitSegment method executes when visiting a segment object of type ISegment. Write any required information from the ISegmentPairProperties, such as MatchPercent or TranslationOrigin.
VisitLocationMarker()
The VisitLocationMarker method executes when visiting a location marker object of type ILocationMarker. Location markers identify positions within a translated document, such as the scroll position when previewing a document in a framework-based editor.
VisitOtherMarker()
The VisitOtherMarker method executes when visiting an alternate location marker object of type IOtherMarker.
VisitRevisionMarker()
The VisitRevisionMarker method executes when visiting a track change location marker object of type IRevisionMarker.
VisitLockedContent()
The VisitLockedContent method executes when visiting a locked content container object of type ILockedContent. Check the LockType value in its Properties property. The lock type indicates how to treat the container contents when writing them to the translated target document. Call AppendItems() for the Content collection of child objects.