Example usage for org.apache.commons.lang.text StrBuilder appendNewLine

List of usage examples for org.apache.commons.lang.text StrBuilder appendNewLine

Introduction

In this page you can find the example usage for org.apache.commons.lang.text StrBuilder appendNewLine.

Prototype

public StrBuilder appendNewLine() 

Source Link

Document

Appends the new line string to this string builder.

Usage

From source file:mitm.application.djigzo.DjigzoConfigurator.java

private static void logAllPackages() {
    List<Package> packages = Arrays.asList(Package.getPackages());

    Comparator<Package> packageComparator = new Comparator<Package>() {
        @Override//from w  ww  .j av a  2  s.c o m
        public int compare(Package package1, Package package2) {
            return package1.getName().compareTo(package2.getName());
        }
    };

    Collections.sort(packages, packageComparator);

    StrBuilder sb = new StrBuilder(1024);

    sb.appendNewLine();

    for (Package pack : packages) {
        sb.append("Package: ").append(pack.getName()).appendSeparator("; ");
        sb.append("Title: ").append(pack.getImplementationTitle()).appendSeparator("; ");
        sb.append("Version: ").append(pack.getImplementationVersion());
        sb.appendNewLine();
    }

    logger.info(sb.toString());
}

From source file:me.taylorkelly.mywarp.bukkit.util.FormattingUtils.java

/**
   * Creates a not numbered list from the given strings. Each string represents an independent entry on the list.
   * Strings that are longer than the given width will be split above several lines.
   *//from  w  w w .j av a2  s  . c o  m
   * @param listChar the character that will be displayed as bullet point before each entry
   * @param maxWidth the maximal width of each entry
   * @param entries  the list's entries
   * @return the list
   */
  public static String toList(char listChar, int maxWidth, List<String> entries) {
      StrBuilder ret = new StrBuilder();
      String listPrefix = listChar + " ";
      Splitter splitter = Splitter.on(' ').trimResults().omitEmptyStrings();

      for (String entry : entries) {

          if (!ret.isEmpty()) {
              ret.appendNewLine();
              // reset colors from the previous entry
              ret.append(ChatColor.RESET);
          }

          List<String> entryParts = new LinkedList<String>();
          entryParts.add(listPrefix);
          Iterables.addAll(entryParts, splitter.split(entry));

          ret.append(wrappedJoin(entryParts, "  ", maxWidth));
      }

      return ret.toString();
  }

From source file:mitm.common.postfix.SaslPasswordManager.java

protected static String createContent(List<SaslPassword> passwords) {
    StrBuilder content = new StrBuilder(256);

    if (passwords != null) {
        for (SaslPassword password : passwords) {
            if (!password.isMxLookup()) {
                content.append("[");
            }/*w w w. j a v  a2s  . c om*/

            content.append(password.getServer());

            if (!password.isMxLookup()) {
                content.append("]");
            }

            if (password.getPort() != null) {
                content.append(":").append(password.getPort());
            }

            content.append(" ").append(password.getUsername());
            content.append(":").append(password.getPassword());
            content.appendNewLine();
        }
    }

    return content.toString();
}

From source file:io.github.mywarp.mywarp.command.parametric.provider.exception.NoSuchWarpException.java

@Override
public String getLocalizedMessage() {
    StrBuilder builder = new StrBuilder();
    builder.append(msg.getString("exception.no-such-warp", getInput()));

    if (!matches.isEmpty()) {
        builder.appendNewLine();
        builder.append(msg.getString("exception.no-such-warp.suggestion", matches.get(1).getName()));
    }// w ww.  j a va2  s  . c  o  m
    return builder.toString();
}

From source file:com.collective.celos.ci.testing.fixtures.compare.RecursiveFsObjectComparer.java

private void appendMessages(Collection<String> messages, StrBuilder strBuilder, String header) {
    if (messages.size() == 0) {
        return;/*ww  w .j  a v  a  2 s .c  o  m*/
    }
    if (!strBuilder.isEmpty()) {
        strBuilder.appendNewLine();
    }
    strBuilder.append(header);
    List<String> sortedMessages = Lists.newArrayList(messages);
    Collections.sort(sortedMessages);
    strBuilder.appendWithSeparators(sortedMessages, ", ");
}

From source file:me.taylorkelly.mywarp.bukkit.util.parametric.ExceptionConverter.java

/**
 * Converts a {@link NoSuchWarpException} to a human readable {@link CommandException}.
 *
 * @param ex the NoSuchWarpException/* w  ww. j  a v  a  2  s .  c om*/
 * @throws CommandException the wrapped exception
 */
@ExceptionMatch
public void convert(NoSuchWarpException ex) throws CommandException {
    Optional<Warp> match = ex.getMatches().getMatch(new Warp.PopularityComparator());

    StrBuilder builder = new StrBuilder();
    builder.append(MESSAGES.getString("exception.no-such-warp", ex.getQuery()));

    if (match.isPresent()) {
        builder.appendNewLine();
        builder.append(ChatColor.GRAY);
        builder.append(MESSAGES.getString("exception.no-such-warp.suggestion", match.get().getName()));
    }

    throw new CommandException(builder.toString(), ex);
}

From source file:mitm.application.djigzo.james.mock.MockMail.java

@Override
public String toString() {
    StrBuilder sb = new StrBuilder();

    sb.append("Recipients: ");
    sb.appendWithSeparators(recipients, ", ");
    sb.appendNewLine();
    sb.append("Remote address: ");
    sb.append(remoteAddr);//from w w w.j  av  a 2 s  .  c o  m
    sb.appendNewLine();
    sb.append("Sender: ");
    sb.append(sender);
    sb.appendNewLine();

    return sb.toString();
}

From source file:com.github.restdriver.serverdriver.http.response.DefaultResponse.java

private String createSummaryString(int truncateLength) {
    StrBuilder httpString = new StrBuilder();
    httpString.append(protocolVersion).append(" ").append(statusCode).append(" ").append(statusMessage);
    httpString.appendNewLine();

    httpString.appendWithSeparators(headers, SystemUtils.LINE_SEPARATOR);

    if (StringUtils.isNotEmpty(content)) {
        httpString.appendNewLine();//w w  w  .  j a  va2  s.c om
        httpString.appendNewLine();
        httpString.append(StringUtils.abbreviate(content, truncateLength));
    }

    return httpString.toString();
}

From source file:me.taylorkelly.mywarp.bukkit.commands.printer.InfoPrinter.java

/**
 * Gets information text./*  w w  w. j  a va  2 s .  c o  m*/
 *
 * @param receiver the Actor who will receive the text
 * @return the text
 */
public String getText(Actor receiver) {
    StrBuilder info = new StrBuilder();
    // heading
    info.append(ChatColor.GOLD);
    info.append(MESSAGES.getString("info.heading",
            ChatColor.getByChar(warp.getType().getColorCharacter()) + warp.getName() + ChatColor.GOLD));
    info.appendNewLine();

    // creator
    info.append(ChatColor.GRAY);

    info.append(MESSAGES.getString("info.created-by"));
    info.append(" ");
    info.append(ChatColor.WHITE);
    Profile creator = warp.getCreator();
    info.append(creator.getName().or(creator.getUniqueId().toString()));
    if (receiver instanceof LocalPlayer && warp.isCreator((LocalPlayer) receiver)) {
        info.append(" ");
        info.append(MESSAGES.getString("info.created-by-you"));
    }
    info.appendNewLine();

    // location
    info.append(ChatColor.GRAY);
    info.append(MESSAGES.getString("info.location"));
    info.append(" ");
    info.append(ChatColor.WHITE);
    info.append(MESSAGES.getString("info.location.position", warp.getPosition().getFloorX(),
            warp.getPosition().getFloorY(), warp.getPosition().getFloorZ(), warp.getWorld().getName()));

    info.appendNewLine();

    // if the warp is modifiable, show information about invitations
    if (warp.isModifiable(receiver)) {

        // invited players
        info.append(ChatColor.GRAY);
        info.append(MESSAGES.getString("info.invited-players"));
        info.append(" ");
        info.append(ChatColor.WHITE);

        Set<Profile> invitedPlayers = warp.getInvitedPlayers();
        if (invitedPlayers.isEmpty()) {
            info.append("-");
        } else {
            List<String> invitedPlayerNames = new ArrayList<String>();
            for (Profile profile : invitedPlayers) {
                invitedPlayerNames.add(profile.getName().or(profile.getUniqueId().toString()));
            }
            Collections.sort(invitedPlayerNames);
            info.appendWithSeparators(invitedPlayerNames, ", ");
        }
        info.appendNewLine();

        // invited groups
        info.append(ChatColor.GRAY);
        info.append(MESSAGES.getString("info.invited-groups"));
        info.append(" ");
        info.append(ChatColor.WHITE);

        List<String> invitedGroups = Ordering.natural().sortedCopy(warp.getInvitedGroups());
        if (invitedGroups.isEmpty()) {
            info.append("-");
        } else {
            info.appendWithSeparators(invitedGroups, ", ");
        }
        info.appendNewLine();
    }

    // creation date
    info.append(ChatColor.GRAY);
    info.append(MESSAGES.getString("info.creation-date", warp.getCreationDate()));
    info.append(" ");
    info.append(ChatColor.WHITE);
    info.append(DateFormat.getDateInstance(DateFormat.DEFAULT, LocaleManager.getLocale())
            .format(warp.getCreationDate()));

    info.appendNewLine();

    // visits
    info.append(ChatColor.GRAY);
    info.append(MESSAGES.getString("info.visits"));
    info.append(" ");
    info.append(ChatColor.WHITE);
    info.append(MESSAGES.getString("info.visits.per-day", warp.getVisits(), warp.getVisitsPerDay()));
    return info.toString();
}

From source file:me.taylorkelly.mywarp.bukkit.MyWarpPlugin.java

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    // create the CommandLocals
    CommandLocals locals = new CommandLocals();
    Actor actor = wrap(sender);/*from   w  w  w  .j  a v a2s  .c  om*/
    locals.put(Actor.class, actor);

    // set the locale for this command session
    LocaleManager.setLocale(actor.getLocale());

    // No parent commands
    String[] parentCommands = new String[0];

    // create the command string
    StrBuilder builder = new StrBuilder();
    builder.append(label);
    for (String argument : args) {
        builder.appendSeparator(' ');
        builder.append(argument);
    }

    // call the command
    try {
        return dispatcher.call(builder.toString(), locals, parentCommands);
    } catch (IllegalStateException e) {
        log.error(String.format(
                "The command '%s' could not be executed as the underling method could not be called.",
                cmd.toString()), e);
        actor.sendError(MESSAGES.getString("exception.unknown"));
    } catch (InvocationCommandException e) {
        // An InvocationCommandException can only be thrown if a thrown
        // Exception is not covered by our ExceptionConverter and is
        // therefore unintended behavior.
        actor.sendError(MESSAGES.getString("exception.unknown"));
        log.error(String.format("The command '%s' could not be executed.", cmd), e);
    } catch (InvalidUsageException e) {
        StrBuilder error = new StrBuilder();
        error.append(e.getSimpleUsageString("/"));
        if (e.getMessage() != null) {
            error.appendNewLine();
            error.append(e.getMessage());
        }
        if (e.isFullHelpSuggested()) {
            error.appendNewLine();
            error.append(e.getCommand().getDescription().getHelp());
        }
        actor.sendError(error.toString());
    } catch (CommandException e) {
        actor.sendError(e.getMessage());
    } catch (AuthorizationException e) {
        actor.sendError(MESSAGES.getString("exception.insufficient-permission"));
    }
    return true;
}