コード例 #1
0
ファイル: FormattingUtils.java プロジェクト: 0x7678/mqtt-spy
  /**
   * Creates a basic formatter function from the supplied conversion method.
   *
   * @param conversionMethod The conversion method to be used
   * @return Created formmater function
   */
  private static FormatterFunction createBasicFormatterFunction(
      final ConversionMethod conversionMethod) {
    final FormatterFunction function = new FormatterFunction();

    final ConversionFormatterDetails conversionFormatterDetails = new ConversionFormatterDetails();
    conversionFormatterDetails.setFormat(conversionMethod);

    function.setConversion(conversionFormatterDetails);

    return function;
  }
コード例 #2
0
ファイル: FormattingUtils.java プロジェクト: 0x7678/mqtt-spy
  /**
   * 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;
  }