# User-specific Extensions

## BreakIterator

The `FlowUtilities` class uses the native BreakIterator class to determine the boundaries between words. Clients may contribute their own implementation by contributing a custom BreakIteratorProvider via SPI. If multiple services are contributed, the first one is chosen.

### Example: How to supply a custom BreakIterator

> Users may want to use the break rules from e.g. ICU instead of the JDK rules. Because those classes don’t share a common interface, the user has to extend the abstract BreakIterator class and call the corresponding ICU method for abstract method that is overwritten.

### Solution:

> SPI uses the context-classloader to instantiate the custom implementation. In order to use this mechanism in OSGi with minimal complications, it is recommended to create this class within a Draw2D fragment. Also note that this class needs to be registered via META-INF/services/java.text.spi.BreakIteratorProvider

>     public class CustomBreakIteratorProvider extends BreakIteratorProvider {
>     	@Override
>     	public BreakIterator getWordInstance(Locale locale) {
>     		...
>     	}

>     	@Override
>     	public BreakIterator getLineInstance(Locale locale) {
>     		...
>     	}

>     	@Override
>     	public BreakIterator getCharacterInstance(Locale locale) {
>     		...
>     	}

>     	@Override
>     	public BreakIterator getSentenceInstance(Locale locale) {
>     		...
>     	}

>     	@Override
>     	public Locale[] getAvailableLocales() {
>     		...
>     	}
>     }

## Bidi

Similarly to the BreakIterator, the BidiProcessor class uses the native Bidi class to determine whether a text requires a Bidi analysis. Clients may contribute their own implementation by contributing a custom BidiProvider via SPI. If multiple services are contributed, the first one is chosen.

### Example: Custom BidiProvider Service

> The Bidi algorithm provided by the JDK might not be sufficient to determine, whether a given text requires further analysis.

### Solution:

> SPI uses the context-classloader to instantiate the custom implementation. In order to use this mechanism in OSGi with minimal complications, it is recommended to create this class within a Draw2D fragment. Also note that this class needs to be registered via META-INF/services/org.eclipse.draw2d.text.BidiProvider.

>     public class CustomBidiProvider implements BidiProvider {
>     	@Override
>     	public boolean requiresBidi(char[] text, int start, int limit) {
>     		...
>     	}
>     }