In this documentation we assume you are familiar with Batch Task plugin structure and with Visitor Pattern. More information about Visitor Pattern can be found here. Like in previous documentation we'll also use Project Anonymizer plugin for code example. Full source code of the project can be found here . SegmentVisitor.cs class contains the algorithm which recursive searches for words inside a segment. And does all the logic for replacing the data.
What we want to achieve
Search in a segment for a particular text and transform that text in a placeholder. In our source code we use regular expressions find matches in segment text.
Dependencies
If you don't have referenced Sdl.FileTypeSupport.Framework.BilingualApi.dll and Sdl.FileTypeSupport.Framework.NativeApi.dll please add a reference to them.
From Sdl.FileTypeSupport.Framework.BilingualApi.dll we'll use IDocumentItemFactory interface.
From Sdl.FileTypeSupport.Framework.NativeApi.dll we'll use IPropertiesFactory interface. This two interfaces will allow is to create a placeholder object.
Brief API's concepts explications
Each segment you see in Studio editor programmatically is in fact List<IAbstractMarkupData> . For example if in one segment you have plain text and placeholder tag. The list will have one IText object and an IPlaceholderTag both interfaces inherits IAbstractMarkupData.
Because the objects you see above are interfaces we don't have access to them out of the box. Because of that we need to use Visitor Pattern which will loop through all the elements and if the element is a placeholder, the method VisitPlaceholderTag() will be called automatically. If the element is a text VisitText() method will be called automatically.
Bellow you can see how you have access to text property for am IText object.
For example if we want to transform "December" which currently is IText object we need to implement Visitor Pattern