Ejemplo n.º 1
0
  /**
   * Formats the given text using the provided formatter.
   *
   * @param customFormatter The formatter details
   * @param text The text to be formatted
   * @return The formatted text
   */
  public static String formatText(final FormatterDetails customFormatter, final String text) {
    logger.trace("Formatting '" + text + "' with " + customFormatter.getName());
    String formattedText = text;

    for (final FormatterFunction function : customFormatter.getFunction()) {
      if (function.getSubstringReplace() != null) {
        formattedText = doSubstringReplacement(function.getSubstringReplace(), formattedText);
      } else if (function.getSubstringExtract() != null) {
        formattedText = doSubstringExtract(function.getSubstringExtract(), formattedText);
      } else if (function.getSubstringConversion() != null) {
        formattedText = doSubstringConversion(function.getSubstringConversion(), formattedText);
      } else if (function.getConversion() != null) {
        formattedText = convertText(function.getConversion().getFormat(), formattedText);
      } else if (function.getCharacterReplace() != null) {
        formattedText =
            replaceCharacters(
                function.getCharacterReplace().getFormat(),
                formattedText,
                function.getCharacterReplace().getCharacterRangeFrom(),
                function.getCharacterReplace().getCharacterRangeTo(),
                function.getCharacterReplace().getWrapCharacter());
      }

      logger.trace("After function transformation = '" + formattedText + "'");
    }

    return formattedText;
  }
Ejemplo n.º 2
0
  /**
   * Creates formatter details for the given parameters.
   *
   * @param id The ID of the formatter
   * @param name The name of the formatter
   * @param conversionMethod The conversion method
   * @return FormatterDetails object
   */
  public static FormatterDetails createBasicFormatter(
      final String id, final String name, final ConversionMethod conversionMethod) {
    final FormatterDetails formatter = new FormatterDetails();

    formatter.setID(id);
    formatter.setName(name);
    formatter.getFunction().add(createBasicFormatterFunction(conversionMethod));

    return formatter;
  }