public String [ ] getReplacement ( String text ) { ConversionRule conversionRule ; Pattern pattern ; Matcher matcher ; Iterator < ConversionRule > conversionRuleIterator = ruleSet . iterator ( ) ; String additionalLine = null ; while ( conversionRuleIterator . hasNext ( ) ) { conversionRule = conversionRuleIterator . next ( ) ; pattern = conversionRule . getPattern ( ) ; matcher = pattern . matcher ( text ) ; if ( matcher . find ( ) ) { // System.out.println("matching " + text); atLeastOneMatchOccured = true ; String replacementText = conversionRule . replace ( matcher ) ; text = matcher . replaceAll ( replacementText ) ; if ( conversionRule . getAdditionalLine ( ) != null ) { additionalLine = conversionRule . getAdditionalLine ( ) ; } } } if ( additionalLine == null ) { return new String [ ] { text } ; } else { return new String [ ] { text , additionalLine } ; } }
Check if the specified text is matching some conversions rules . If a rule matches ask for line replacement .