Example usage for org.apache.commons.lang StringUtils repeat

List of usage examples for org.apache.commons.lang StringUtils repeat

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils repeat.

Prototype

public static String repeat(String str, int repeat) 

Source Link

Document

Repeat a String repeat times to form a new String.

Usage

From source file:nl.strohalm.cyclos.entities.settings.LocalSettings.java

private DecimalFormat getDecimalFormat(final int precision) {
    String pattern = "#,##0";
    if (precision > 0) {
        pattern += "." + StringUtils.repeat("0", precision);
    }/*w ww. jav  a 2  s.c o m*/
    return new DecimalFormat(pattern, getDecimalSymbols());
}

From source file:nl.strohalm.cyclos.services.ads.AdCategoryServiceImpl.java

private void appendXml(final StringBuilder xml, final AdCategory adCategory) {
    final String indent = StringUtils.repeat("    ", adCategory.getLevel());
    xml.append(String.format("%s<%s %s=\"%s\"", indent, CATEGORY_ELEMENT, NAME_ATTRIBUTE,
            StringEscapeUtils.escapeXml(adCategory.getName())));
    final Collection<AdCategory> children = adCategory.getChildren();
    if (CollectionUtils.isEmpty(children)) {
        xml.append(" />\n");
    } else {//ww w .jav a 2 s.c om
        xml.append(">\n");
        for (final AdCategory child : children) {
            appendXml(xml, child);
        }
        xml.append(indent).append("</").append(CATEGORY_ELEMENT).append(">\n");
    }
}

From source file:nl.strohalm.cyclos.services.settings.SettingsServiceImpl.java

private void appendSetting(final StringBuilder xml, final Setting setting) {
    final String indent2Levels = StringUtils.repeat("    ", 2);
    final String indent3Levels = StringUtils.repeat("    ", 3);
    xml.append(indent2Levels).append(String.format("<setting name=\"%s\" >\n", setting.getName()));
    xml.append(indent3Levels).append(StringEscapeUtils.escapeXml(setting.getValue()));
    xml.append(indent2Levels).append("</setting>\n");
}

From source file:nl.strohalm.cyclos.services.settings.SettingsServiceImpl.java

private void appendSettingType(final StringBuilder xml, final Setting.Type type) {
    final String indent = StringUtils.repeat("    ", 1);
    xml.append(String.format("%s<settings type=\"%s\" >\n", indent, type.getValue()));
    final SettingsHandler<?, ?> handler = handlersMap.get(type);
    final List<Setting> settings = handler.listSettings();
    for (final Setting setting : settings) {
        // Setting in ignore list, don't export it
        if (type == Setting.Type.LOCAL && IGNORED_SETTINGS.contains(setting.getName())) {
            continue;
        }/* w w w .  j  a  v  a 2  s. c o m*/
        appendSetting(xml, setting);
    }
    xml.append(indent).append("</settings>\n");
}

From source file:nl.strohalm.cyclos.setup.Version.java

@Override
public String toString() {
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    final String header = String.format("Version %s", label);
    pw.println(header);/*  ww  w  .  j a va 2 s  .co m*/
    pw.println(StringUtils.repeat("-", header.length()));
    if (StringUtils.isNotEmpty(description)) {
        pw.println(description);
    }
    pw.println();
    appendList(pw, enhancements, "New / modified functions", " * ", null);
    appendList(pw, bugFixes, "Bug fixes", " * ", null);
    appendList(pw, newLibraries, "New library dependencies", " * ", null);
    appendList(pw, removedLibraries, "Removed library dependencies", " * ", null);
    appendList(pw, newHelps, "New help files", " * ", null);
    appendList(pw, removedHelps, "Removed help files", " * ", null);
    appendList(pw, newStaticFiles, "New static files", " * ", null);
    appendList(pw, removedStaticFiles, "Removed static files", " * ", null);
    appendList(pw, newCssClasses, "New CSS classes", " * ", null);
    appendList(pw, removedCssClasses, "Removed CSS classes", " * ", null);
    appendList(pw, newTranslationKeys, "New application translation keys", " * ", null);
    appendList(pw, removedTranslationKeys, "Removed application translation keys", " * ", null);
    appendList(pw, newSetupKeys, "New setup translation keys", " * ", null);
    appendList(pw, removedSetupKeys, "Removed setup translation keys", " * ", null);
    pw.close();
    return sw.toString();
}

From source file:nl.toolforge.karma.cli.cmd.HelpImpl.java

/**
 *
 * @throws CommandException Occurs when a command load error occurred.
 */// w  w  w.java2s. c  o m
public void execute() throws CommandException {

    String commandName = getCommandLine().getOptionValue("c");

    try {
        String renderedStuff = null;
        SimpleMessage message = null;

        if (commandName != null) {
            renderedStuff = CommandRenderer.renderCommand(commandName);

            int usage = FRONTEND_MESSAGES.getString("message.COMMAND_HELP").length() + commandName.length();

            message = new SimpleMessage(
                    "\n" + FRONTEND_MESSAGES.getString("message.COMMAND_HELP") + "\n"
                            + StringUtils.repeat("-", usage) + "\n" + renderedStuff,
                    new Object[] { commandName });
        } else {
            renderedStuff = CommandRenderer.renderedCommands(CommandFactory.getInstance().getCommands());
            renderedStuff += "\n" + FRONTEND_MESSAGES.getString("message.HELP_DETAILS") + "\n";
            renderedStuff += CommandRenderer.renderCommand("help");
            message = new SimpleMessage(
                    "\n" + FRONTEND_MESSAGES.getString("message.VALID_COMMANDS") + "\n" + renderedStuff);
        }

        response.addEvent(new MessageEvent(message));

    } catch (CommandLoadException e) {
        throw new CommandException(e.getErrorCode(), e.getMessageArguments());
    }
}

From source file:nl.toolforge.karma.cli.cmd.ListManifestsImpl.java

public void execute() throws CommandException {

    super.execute();

    Set headers = getHeaders();/*  w w  w  . j a  v  a  2s  .c  om*/

    if (headers.size() == 0) {
        response.addEvent(
                new MessageEvent(this, new SimpleMessage("No manifests found for this working context.")));
        response.addEvent(new MessageEvent(this,
                new SimpleMessage("TIP : Try updating the manifest store with the `update-admin`-command.")));
    } else {

        Iterator manifestsIterator = headers.iterator();
        ManifestHeader header;

        Manifest currentManifest = getContext().getCurrentManifest();

        StringBuffer buffer = new StringBuffer();

        buffer.append("\nManifests for working context `" + getWorkingContext().getName() + "`:\n\n");

        String h1 = "Type";
        int MAX_TYPE_LENGTH = 13;

        String h2 = "Name";
        int MAX_NAME_LENGTH = 30;

        buffer.append(h1 + StringUtils.repeat(" ", 13 - h1.length()) + " | ");
        buffer.append(h2 + StringUtils.repeat(" ", 32 - h1.length()) + "\n");
        buffer.append(StringUtils.repeat("_", 71) + "\n");

        List manifestList = new ArrayList();

        while (manifestsIterator.hasNext()) {

            header = (ManifestHeader) manifestsIterator.next();

            String typeSpaces = StringUtils.repeat(" ", MAX_TYPE_LENGTH - header.getType().length());
            String nameSpaces = StringUtils.repeat(" ", MAX_NAME_LENGTH - header.getName().length());

            if ((currentManifest != null) && header.getName().equals(currentManifest.getName())) {
                manifestList.add(header.getType() + typeSpaces + " | " + header.getName() + nameSpaces
                        + " ** current manifest **\n");
            } else {
                manifestList.add(header.getType() + typeSpaces + " | " + header.getName() + nameSpaces + "\n");
            }
        }

        Collections.sort(manifestList);

        manifestsIterator = manifestList.iterator();
        while (manifestsIterator.hasNext()) {
            buffer.append((String) manifestsIterator.next());
        }
        response.addEvent(new MessageEvent(this, new SimpleMessage(buffer.toString())));
    }

}

From source file:nl.toolforge.karma.cli.cmd.ViewManifestImpl.java

/**
 * Shows the contents using simple rendering.
 *//*from   w  ww. j  av a2  s . c  o  m*/
public void execute() throws CommandException {

    SimpleMessage message = new SimpleMessage("Checking manifest status, please wait ...");
    commandResponse.addEvent(new MessageEvent(this, message));

    super.execute(); // Ignore the response from the superclass

    List renderedData = getData();

    // -- formatting manifest data

    StringBuffer buffer = new StringBuffer();
    buffer.append("\n");

    try {
        if (getContext().getCurrentManifest() instanceof ReleaseManifest) {
            buffer.append("RELEASE MANIFEST\n\n");

            String h1 = "MODULE-NAME";
            String h2 = "TYPE";
            String h3 = "LOCAL";
            String h4 = "REMOTE";
            String h5 = "STATIC";
            String h6 = "PATCHLINE";
            String h7 = "STATE";
            String h8 = "LOCATION";

            buffer.append(h1 + StringUtils.repeat(" ", 45 - h1.length()) + "| ");
            buffer.append(h2 + StringUtils.repeat(" ", 8 - h2.length()) + "| ");
            buffer.append(h3 + StringUtils.repeat(" ", 7 - h3.length()) + "| ");
            buffer.append(h4 + StringUtils.repeat(" ", 9 - h4.length()) + "| ");
            buffer.append(h5 + StringUtils.repeat(" ", 7 - h5.length()) + "| ");
            buffer.append(h6 + StringUtils.repeat(" ", 15 - h6.length()) + "| ");
            buffer.append(h7 + StringUtils.repeat(" ", 10 - h7.length()) + "| ");
            buffer.append(h8 + "\n");
            buffer.append(StringUtils.repeat("_", 155));
            buffer.append("\n");

            for (Iterator i = renderedData.iterator(); i.hasNext();) {

                String[] data = (String[]) i.next();

                buffer.append(data[0] + StringUtils.repeat(" ", 45 - data[0].length()) + "| ");
                buffer.append(data[1] + StringUtils.repeat(" ", 8 - data[1].length()) + "| ");
                buffer.append(data[2] + StringUtils.repeat(" ", 7 - data[2].length()) + "| ");
                buffer.append(data[3] + StringUtils.repeat(" ", 9 - data[3].length()) + "| ");
                buffer.append(data[4] + StringUtils.repeat(" ", 7 - data[4].length()) + "| ");
                buffer.append(data[5] + StringUtils.repeat(" ", 15 - data[5].length()) + "| ");
                buffer.append(data[6] + StringUtils.repeat(" ", 10 - data[6].length()) + "| ");
                buffer.append(data[7] + "\n");
            }

        } else {

            buffer.append("DEVELOPMENT MANIFEST\n\n");

            String h1 = "MODULE-NAME";
            String h2 = "TYPE";
            String h3 = "LOCAL";
            String h4 = "REMOTE";
            String h5 = "STATIC";
            String h6 = "STATE";
            String h7 = "LOCATION";

            buffer.append(h1 + StringUtils.repeat(" ", 45 - h1.length()) + "| ");
            buffer.append(h2 + StringUtils.repeat(" ", 8 - h2.length()) + "| ");
            buffer.append(h3 + StringUtils.repeat(" ", 7 - h3.length()) + "| ");
            buffer.append(h4 + StringUtils.repeat(" ", 9 - h4.length()) + "| ");
            buffer.append(h5 + StringUtils.repeat(" ", 7 - h5.length()) + "| ");
            buffer.append(h6 + StringUtils.repeat(" ", 35 - h6.length()) + "| ");
            buffer.append(h7 + "\n");
            buffer.append(StringUtils.repeat("_", 155));
            buffer.append("\n");

            for (Iterator i = renderedData.iterator(); i.hasNext();) {

                String[] data = (String[]) i.next();
                buffer.append(data[0] + StringUtils.repeat(" ", 45 - data[0].length()) + "| ");
                buffer.append(data[1] + StringUtils.repeat(" ", 8 - data[1].length()) + "| ");
                buffer.append(data[2] + StringUtils.repeat(" ", 7 - data[2].length()) + "| ");
                buffer.append(data[3] + StringUtils.repeat(" ", 9 - data[3].length()) + "| ");
                buffer.append(data[4] + StringUtils.repeat(" ", 7 - data[4].length()) + "| ");
                // No fifth column
                buffer.append(data[6] + StringUtils.repeat(" ", 35 - data[6].length()) + "| ");
                buffer.append(data[7] + "\n");
            }
        }
    } catch (NegativeArraySizeException n) {
        logger.error(n);
        buffer = new StringBuffer().append("Pfff, some data item is bigger than Karma can handle.");
    }

    // -- end of formatting

    message = new SimpleMessage(buffer.toString());
    commandResponse.addEvent(new MessageEvent(message));
}

From source file:nl.toolforge.karma.cli.cmd.ViewModuleHistory.java

public void execute() throws CommandException {

    if (!getContext().isManifestLoaded()) {
        throw new CommandException(ManifestException.NO_ACTIVE_MANIFEST);
    }/*from   w  ww .j av  a 2 s  .c  o  m*/

    String moduleName = getCommandLine().getOptionValue("m");
    Module module = null;
    try {
        module = getContext().getCurrentManifest().getModule(moduleName);
    } catch (ManifestException e) {
        throw new CommandException(e.getErrorCode(), e.getMessageArguments());
    }

    if (!getContext().getCurrentManifest().isLocal(module)) {
        throw new CommandException(CommandException.MODULE_NOT_LOCAL, new Object[] { module.getName() });
    }

    ModuleHistoryFactory factory = ModuleHistoryFactory
            .getInstance(getContext().getCurrentManifest().getBaseDirectory());

    ModuleHistory history = null;
    try {
        history = factory.getModuleHistory(module);
    } catch (ModuleHistoryException e) {
        logger.error(e.getMessage());
        throw new CommandException(e.getErrorCode(), e.getMessageArguments());
    }

    StringBuffer buffer = new StringBuffer();
    buffer.append("\n");

    String header = "Module history for module : " + module.getName();
    buffer.append(header + "\n\n\n");

    String h1 = "Type";
    String h2 = "Author";
    String h3 = "Version";
    String h4 = "Timestamp";
    String h5 = "Comment";

    final int MAX_DATETIME = 20;
    final int MAX_COMMENT = 60;

    buffer.append(h1 + StringUtils.repeat(" ", 18 - h1.length()) + "| ");
    buffer.append(h2 + StringUtils.repeat(" ", 15 - h2.length()) + "| ");
    buffer.append(h3 + StringUtils.repeat(" ", 8 - h3.length()) + "| ");
    buffer.append(h4 + StringUtils.repeat(" ", MAX_DATETIME - h4.length()) + "| ");
    buffer.append(h5);
    buffer.append("\n");
    buffer.append(StringUtils.repeat("_", 100));
    buffer.append("\n\n");

    List events = history.getEvents();

    for (Iterator i = events.iterator(); i.hasNext();) {

        ModuleHistoryEvent event = (ModuleHistoryEvent) i.next();

        buffer.append(event.getType() + StringUtils.repeat(" ", 18 - event.getType().length()) + "| ");
        buffer.append(event.getAuthor() + StringUtils.repeat(" ", 15 - event.getAuthor().length()) + "| ");
        buffer.append(event.getVersion().getVersionNumber()
                + StringUtils.repeat(" ", 8 - event.getVersion().getVersionNumber().length()) + "| ");

        String date = new SimpleDateFormat("dd-MMM-yyyy HH:mm").format(event.getDatetime());

        buffer.append(date + StringUtils.repeat(" ", MAX_DATETIME - date.length()) + "| ");

        String comment = null;
        if (event.getComment().length() > MAX_COMMENT) {
            comment = event.getComment().substring(0, MAX_COMMENT);
        } else {
            comment = event.getComment();
        }
        buffer.append(comment + "\n");
    }

    commandResponse.addEvent(new MessageEvent(new SimpleMessage(buffer.toString())));
}

From source file:nl.toolforge.karma.console.CommandRenderer.java

private static StringBuffer printCommand(CommandDescriptor descriptor, Option[] options, boolean showOptions,
        boolean showHelp) {

    StringBuffer buffer = new StringBuffer();
    String commandNameAlias = descriptor.getName() + " (" + descriptor.getAlias() + ")";

    buffer.append(commandNameAlias).append(StringUtils.repeat(" ", COMMAND_FILL - commandNameAlias.length()));
    if (!showOptions) {
        buffer.append(descriptor.getDescription());
    }/*from w w w  .j  a  va  2  s  .  co m*/
    buffer.append("\n");

    if (showOptions) {
        for (int j = 0; j < options.length; j++) {

            Option o = options[j];

            String leftPadding = "   ";

            buffer.append(leftPadding).append("-" + o.getOpt()).append(", --" + o.getLongOpt());

            String args = "";
            if (o.hasArg()) {
                args = " <".concat(o.getArgName()).concat(">");
            }

            // todo when the commands are described with too much of text, then FILL will run out of count ...
            //
            buffer.append(args.concat(StringUtils.repeat(" ", OPTION_FILL - (o.getLongOpt() + args).length())));
            buffer.append(leftPadding);
            if (!o.isRequired()) {
                buffer.append("(Optional) ");
            }
            buffer.append(o.getDescription());
            buffer.append("\n");
        }
    }

    if (showHelp) {
        buffer.append("\n");

        String trimmed = NiftyStringUtils.deleteWhiteSpaceExceptOne(descriptor.getHelp());
        String[] split = NiftyStringUtils.split(trimmed, " ", 120);
        String joined = StringUtils.join(split, "\n");

        buffer.append(joined);
        buffer.append("\n");
    }

    return buffer;
}