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

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

Introduction

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

Prototype

public static String rightPad(String str, int size) 

Source Link

Document

Right pad a String with spaces (' ').

Usage

From source file:org.ejbca.ui.cli.service.ServiceListCommand.java

private void addClassPath(StringBuilder row, String classPath) {
    row.append(' ');
    final String className = classPath.replaceFirst("^.*\\.", "");
    row.append(StringUtils.rightPad(StringUtils.abbreviate(className, 16), 17));
}

From source file:org.endiansummer.tools.soaprunner.VariableStore.java

public void dump(File file) throws IOException {
    StringBuffer sb = new StringBuffer();
    for (Map.Entry<String, List<String>> entry : variables.entrySet()) {
        String key = entry.getKey();
        List<String> list = entry.getValue();
        StringBuffer vars = new StringBuffer();
        int len = list.size();
        for (String var : list) {
            if (vars.length() > 0) {
                vars.append("\n" + StringUtils.repeat(" ", 35));
            }/*from w  ww .ja v a2  s  .  c o  m*/
            vars.append(var);
            if (--len > 0) {
                vars.append(" ,\\");
            }
        }
        sb.append(StringUtils.rightPad(key, 32));
        sb.append(" = ");
        sb.append(vars.toString());
        sb.append("\n\n");
    }
    FileUtils.writeStringToFile(file, sb.toString(), "UTF-8");
}

From source file:org.ff4j.cli.FF4jCliDisplay.java

/**
 * Template for helps./*from  w w  w .  j  a  va 2s .  c  o  m*/
 *
 * @param opt
 *       options
 * @param message
 *       current messages
 */
private static void lineHelp(String opt, String message) {
    System.out.println("");
    cyan("  " + StringUtils.rightPad(opt, 43));
    white(message);
}

From source file:org.ff4j.cli.FF4jCliDisplay.java

/**
 * Display a table of available environments.
 *
 * @param envs/*from   w ww  .j  a v  a2s.co  m*/
 *       environnements in config file
 */
public static void displayEnvironments(Map<String, FF4j> envs) {
    yellow("+--------------------+----------+------------+-------+----------+\n");
    System.out.print("|");
    cyan(" Environments       ");
    yellow("|");
    cyan(" Features ");
    yellow("|");
    cyan(" Properties ");
    yellow("|");
    cyan(" Audit ");
    yellow("|");
    cyan(" Security ");
    yellow("|\n");
    System.out.println("+--------------------+----------+------------+-------+----------+");
    for (Map.Entry<String, FF4j> entries : envs.entrySet()) {
        FeatureStore fs = entries.getValue().getFeatureStore();
        PropertyStore ps = entries.getValue().getPropertiesStore();
        yellow("|  ");
        green(StringUtils.rightPad(entries.getKey(), 18));
        yellow("|  ");
        String featureStore = "---";
        if (fs != null) {
            featureStore = String.valueOf(fs.readAll().size());
        }
        white(StringUtils.rightPad(featureStore, 8));
        yellow("|  ");
        String propertyStore = "---";
        if (fs != null) {
            propertyStore = String.valueOf(ps.listPropertyNames().size());
        }
        white(StringUtils.rightPad(propertyStore, 10));
        yellow("|");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        if (entries.getValue().isEnableAudit()) {
            green("  ON   ");
        } else {
            red("  OFF  ");
        }
        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        yellow("|");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        if (entries.getValue().getAuthorizationsManager() != null) {
            green("  ON      ");
        } else {
            red("  OFF     ");
        }
        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        yellow("|\n");
    }
    System.out.println("+--------------------+----------+------------+-------+----------+");
    System.out.println("");
}

From source file:org.ff4j.cli.FF4jCliDisplay.java

/**
 * Command line uptime//from ww w . jav  a2 s. c  o  m
 */
public static void displayProperties(Map<String, Property<?>> properties) {
    if (properties == null || properties.isEmpty()) {
        System.out.println(" There are no properties in the store");
    }
    yellow("+--------------------+--------------------+--------------------+--------------------------------+");
    System.out.print("\n|");
    cyan(" Property names     ");
    yellow("|");
    cyan(" Value              ");
    yellow("|");
    cyan(" Type               ");
    yellow("|");
    cyan(" FixedValues                    ");
    yellow("|");
    System.out.println(
            "\n+--------------------+--------------------+--------------------+--------------------------------+");
    for (Property<?> prop : properties.values()) {
        yellow("| ");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.GREEN);
        System.out.print(StringUtils.rightPad(prop.getName(), 19));
        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        yellow("| ");
        white(StringUtils.rightPad(prop.asString(), 19));
        yellow("| ");

        String pType = prop.getType();
        if (uxTypes.containsValue(prop.getType())) {
            pType = Util.getFirstKeyByValue(uxTypes, prop.getType());
        }
        white(StringUtils.rightPad(pType, 19));
        yellow("| ");
        String fixedValues = "---";
        if (prop.getFixedValues() != null && !prop.getFixedValues().isEmpty()) {
            fixedValues = prop.getFixedValues().toString();
            if (fixedValues.length() > 31) {
                fixedValues = fixedValues.substring(0, 28) + "...";
            }
        }
        white(StringUtils.rightPad(fixedValues, 31));
        yellow("|\n");
    }
    System.out.println(
            "+--------------------+--------------------+--------------------+--------------------------------+");
}

From source file:org.ff4j.cli.FF4jCliDisplay.java

/**
 * Command line uptime/*w ww . j a  v a 2 s .c  o m*/
 */
public static void displayFeatures(Map<String, Feature> features) {
    if (features == null || features.isEmpty()) {
        System.out.println(" There are no features in the store");
    }
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
    System.out.println("+--------------------+--------+---------------+--------------------------------+");
    System.out.print("|");
    AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.CYAN);
    System.out.print(" Feature names      ");
    AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
    System.out.print("|");
    AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.CYAN);
    System.out.print(" State  ");
    AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
    System.out.print("|");
    AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.CYAN);
    System.out.print(" Group         ");
    AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
    System.out.print("|");
    AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.CYAN);
    System.out.print(" Roles                          ");
    AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
    System.out.println("|");
    System.out.println("+--------------------+--------+---------------+--------------------------------+");
    for (Feature feat : features.values()) {
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
        System.out.print("| ");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.GREEN);
        System.out.print(StringUtils.rightPad(feat.getUid(), 19));

        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
        System.out.print("| ");
        if (feat.isEnable()) {
            AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
            AnsiTerminal.foreGroundColor(AnsiForegroundColor.GREEN);
            System.out.print(StringUtils.rightPad("ON", 7));
        } else {
            AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
            AnsiTerminal.foreGroundColor(AnsiForegroundColor.RED);
            System.out.print(StringUtils.rightPad("OFF", 7));
        }

        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
        System.out.print("| ");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.WHITE);
        String groupName = "---";
        if (!StringUtils.isEmpty(feat.getGroup())) {
            groupName = feat.getGroup();
        }
        System.out.print(StringUtils.rightPad(groupName, 14));

        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
        System.out.print("| ");
        AnsiTerminal.textAttribute(AnsiTextAttribute.BOLD);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.WHITE);
        String roles = feat.getPermissions().toString();
        roles = roles.substring(1, roles.length() - 1);
        if ("".equals(roles)) {
            roles = "---";
        }
        System.out.print(StringUtils.rightPad(roles, 31));

        AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
        AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
        System.out.println("| ");
    }
    AnsiTerminal.textAttribute(AnsiTextAttribute.CLEAR);
    AnsiTerminal.foreGroundColor(AnsiForegroundColor.YELLOW);
    System.out.println("+--------------------+--------+---------------+--------------------------------+");
}

From source file:org.gradle.internal.component.AmbiguousConfigurationSelectionException.java

static void formatConfiguration(StringBuilder sb, AttributeContainer fromConfigurationAttributes,
        AttributesSchema consumerSchema, List<ConfigurationMetadata> matches, Set<String> requestedAttributes,
        int maxConfLength, final String conf) {
    Optional<ConfigurationMetadata> match = Iterables.tryFind(matches, new Predicate<ConfigurationMetadata>() {
        @Override//from   www  .ja v a 2s .co  m
        public boolean apply(ConfigurationMetadata input) {
            return conf.equals(input.getName());
        }
    });
    if (match.isPresent()) {
        AttributeContainer producerAttributes = match.get().getAttributes();
        Set<Attribute<?>> targetAttributes = producerAttributes.keySet();
        Set<String> targetAttributeNames = Sets
                .newTreeSet(Iterables.transform(targetAttributes, ATTRIBUTE_NAME));
        Set<Attribute<?>> allAttributes = Sets.union(fromConfigurationAttributes.keySet(),
                producerAttributes.keySet());
        Set<String> commonAttributes = Sets.intersection(requestedAttributes, targetAttributeNames);
        Set<String> consumerOnlyAttributes = Sets.difference(requestedAttributes, targetAttributeNames);
        sb.append("   ").append("- Configuration '").append(StringUtils.rightPad(conf + "'", maxConfLength + 1))
                .append(" :");
        List<Attribute<?>> sortedAttributes = Ordering.usingToString().sortedCopy(allAttributes);
        List<String> values = new ArrayList<String>(sortedAttributes.size());
        formatAttributes(sb, fromConfigurationAttributes, consumerSchema, producerAttributes, commonAttributes,
                consumerOnlyAttributes, sortedAttributes, values);
    }
}

From source file:org.jumpmind.symmetric.io.AbstractWriterTest.java

protected String translateExpectedCharString(String value, int size, boolean isRequired) {
    if (isRequired && value == null) {
        if (!platform.getDatabaseInfo().isRequiredCharColumnEmptyStringSameAsNull()
                || platform.getDatabaseInfo().isEmptyStringNulled()) {
            value = AbstractDatabasePlatform.REQUIRED_FIELD_NULL_SUBSTITUTE;
        }/* w w w.  j a v a2 s .  com*/
    }
    if (value != null
            && ((StringUtils.isBlank(value) && platform.getDatabaseInfo().isBlankCharColumnSpacePadded())
                    || (StringUtils.isNotBlank(value)
                            && platform.getDatabaseInfo().isNonBlankCharColumnSpacePadded()))) {
        return StringUtils.rightPad(value, size);
    } else if (value != null && platform.getDatabaseInfo().isCharColumnSpaceTrimmed()) {
        return value.replaceFirst(" *$", "");
    }
    return value;
}

From source file:org.jumpmind.symmetric.service.impl.AbstractDataLoaderServiceTest.java

protected String translateExpectedCharString(String value, int size, boolean isRequired) {
    if (isRequired && value == null) {
        value = AbstractDatabasePlatform.REQUIRED_FIELD_NULL_SUBSTITUTE;
    }//from w  w  w.j  ava  2 s.com
    if (value != null && ((StringUtils.isBlank(value)
            && getDbDialect().getPlatform().getDatabaseInfo().isBlankCharColumnSpacePadded())
            || (StringUtils.isNotBlank(value)
                    && getDbDialect().getPlatform().getDatabaseInfo().isNonBlankCharColumnSpacePadded()))) {
        return StringUtils.rightPad(value, size);
    } else if (value != null && getDbDialect().getPlatform().getDatabaseInfo().isCharColumnSpaceTrimmed()) {
        return value.replaceFirst(" *$", "");
    }
    return value;
}

From source file:org.jumpmind.symmetric.util.SnapshotUtil.java

public static File createSnapshot(ISymmetricEngine engine) {

    String dirName = engine.getEngineName().replaceAll(" ", "-") + "-"
            + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());

    IParameterService parameterService = engine.getParameterService();
    File tmpDir = new File(parameterService.getTempDirectory(), dirName);
    tmpDir.mkdirs();/*from   w  ww  .ja va2  s.  c  om*/

    File logDir = null;

    String parameterizedLogDir = parameterService.getString("server.log.dir");
    if (isNotBlank(parameterizedLogDir)) {
        logDir = new File(parameterizedLogDir);
    }

    if (logDir != null && logDir.exists()) {
        log.info("Using server.log.dir setting as the location of the log files");
    } else {
        logDir = new File("logs");

        if (!logDir.exists()) {
            File file = findSymmetricLogFile();
            if (file != null) {
                logDir = file.getParentFile();
            }
        }

        if (!logDir.exists()) {
            logDir = new File("../logs");
        }

        if (!logDir.exists()) {
            logDir = new File("target");
        }

        if (logDir.exists()) {
            File[] files = logDir.listFiles();
            if (files != null) {
                for (File file : files) {
                    if (file.getName().toLowerCase().endsWith(".log")) {
                        try {
                            FileUtils.copyFileToDirectory(file, tmpDir);
                        } catch (IOException e) {
                            log.warn("Failed to copy " + file.getName() + " to the snapshot directory", e);
                        }
                    }
                }
            }
        }

    }

    ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
    List<TriggerHistory> triggerHistories = triggerRouterService.getActiveTriggerHistories();
    TreeSet<Table> tables = new TreeSet<Table>();
    for (TriggerHistory triggerHistory : triggerHistories) {
        Table table = engine.getDatabasePlatform().getTableFromCache(triggerHistory.getSourceCatalogName(),
                triggerHistory.getSourceSchemaName(), triggerHistory.getSourceTableName(), false);
        if (table != null && !table.getName().toUpperCase()
                .startsWith(engine.getSymmetricDialect().getTablePrefix().toUpperCase())) {
            tables.add(table);
        }
    }

    List<Trigger> triggers = triggerRouterService.getTriggers(true);
    for (Trigger trigger : triggers) {
        Table table = engine.getDatabasePlatform().getTableFromCache(trigger.getSourceCatalogName(),
                trigger.getSourceSchemaName(), trigger.getSourceTableName(), false);
        if (table != null) {
            tables.add(table);
        }
    }

    FileWriter fwriter = null;
    try {
        fwriter = new FileWriter(new File(tmpDir, "config-export.csv"));
        engine.getDataExtractorService().extractConfigurationStandalone(engine.getNodeService().findIdentity(),
                fwriter, TableConstants.SYM_NODE, TableConstants.SYM_NODE_SECURITY,
                TableConstants.SYM_NODE_IDENTITY, TableConstants.SYM_NODE_HOST,
                TableConstants.SYM_NODE_CHANNEL_CTL, TableConstants.SYM_CONSOLE_USER);
    } catch (IOException e) {
        log.warn("Failed to export symmetric configuration", e);
    } finally {
        IOUtils.closeQuietly(fwriter);
    }

    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(new File(tmpDir, "table-definitions.xml"));
        DbExport export = new DbExport(engine.getDatabasePlatform());
        export.setFormat(Format.XML);
        export.setNoData(true);
        export.exportTables(fos, tables.toArray(new Table[tables.size()]));
    } catch (IOException e) {
        log.warn("Failed to export table definitions", e);
    } finally {
        IOUtils.closeQuietly(fos);
    }

    String tablePrefix = engine.getTablePrefix();

    DbExport export = new DbExport(engine.getDatabasePlatform());
    export.setFormat(Format.CSV);
    export.setNoCreateInfo(true);

    extract(export, new File(tmpDir, "identity.csv"),
            TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_IDENTITY));

    extract(export, new File(tmpDir, "node.csv"),
            TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE));

    extract(export, new File(tmpDir, "nodesecurity.csv"),
            TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_SECURITY));

    extract(export, new File(tmpDir, "nodehost.csv"),
            TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_HOST));

    extract(export, new File(tmpDir, "triggerhist.csv"),
            TableConstants.getTableName(tablePrefix, TableConstants.SYM_TRIGGER_HIST));

    extract(export, new File(tmpDir, "lock.csv"),
            TableConstants.getTableName(tablePrefix, TableConstants.SYM_LOCK));

    extract(export, new File(tmpDir, "nodecommunication.csv"),
            TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_COMMUNICATION));

    extract(export, 5000, new File(tmpDir, "outgoingbatch.csv"),
            TableConstants.getTableName(tablePrefix, TableConstants.SYM_OUTGOING_BATCH));

    extract(export, 5000, new File(tmpDir, "incomingbatch.csv"),
            TableConstants.getTableName(tablePrefix, TableConstants.SYM_INCOMING_BATCH));

    final int THREAD_INDENT_SPACE = 50;
    fwriter = null;
    try {
        fwriter = new FileWriter(new File(tmpDir, "threads.txt"));
        ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
        long[] threadIds = threadBean.getAllThreadIds();
        for (long l : threadIds) {
            ThreadInfo info = threadBean.getThreadInfo(l, 100);
            if (info != null) {
                String threadName = info.getThreadName();
                fwriter.append(StringUtils.rightPad(threadName, THREAD_INDENT_SPACE));
                StackTraceElement[] trace = info.getStackTrace();
                boolean first = true;
                for (StackTraceElement stackTraceElement : trace) {
                    if (!first) {
                        fwriter.append(StringUtils.rightPad("", THREAD_INDENT_SPACE));
                    } else {
                        first = false;
                    }
                    fwriter.append(stackTraceElement.getClassName());
                    fwriter.append(".");
                    fwriter.append(stackTraceElement.getMethodName());
                    fwriter.append("()");
                    int lineNumber = stackTraceElement.getLineNumber();
                    if (lineNumber > 0) {
                        fwriter.append(": ");
                        fwriter.append(Integer.toString(stackTraceElement.getLineNumber()));
                    }
                    fwriter.append("\n");
                }
                fwriter.append("\n");
            }
        }
    } catch (IOException e) {
        log.warn("Failed to export thread information", e);
    } finally {
        IOUtils.closeQuietly(fwriter);
    }

    fos = null;
    try {
        fos = new FileOutputStream(new File(tmpDir, "parameters.properties"));
        Properties effectiveParameters = engine.getParameterService().getAllParameters();
        SortedProperties parameters = new SortedProperties();
        parameters.putAll(effectiveParameters);
        parameters.remove("db.password");
        parameters.store(fos, "parameters.properties");
    } catch (IOException e) {
        log.warn("Failed to export parameter information", e);
    } finally {
        IOUtils.closeQuietly(fos);
    }

    fos = null;
    try {
        fos = new FileOutputStream(new File(tmpDir, "parameters-changed.properties"));
        Properties defaultParameters = new Properties();
        InputStream in = SnapshotUtil.class.getResourceAsStream("/symmetric-default.properties");
        defaultParameters.load(in);
        IOUtils.closeQuietly(in);
        in = SnapshotUtil.class.getResourceAsStream("/symmetric-console-default.properties");
        if (in != null) {
            defaultParameters.load(in);
            IOUtils.closeQuietly(in);
        }
        Properties effectiveParameters = engine.getParameterService().getAllParameters();
        Properties changedParameters = new SortedProperties();
        Map<String, ParameterMetaData> parameters = ParameterConstants.getParameterMetaData();
        for (String key : parameters.keySet()) {
            String defaultValue = defaultParameters.getProperty((String) key);
            String currentValue = effectiveParameters.getProperty((String) key);
            if (defaultValue == null && currentValue != null
                    || (defaultValue != null && !defaultValue.equals(currentValue))) {
                changedParameters.put(key, currentValue == null ? "" : currentValue);
            }
        }
        changedParameters.remove("db.password");
        changedParameters.store(fos, "parameters-changed.properties");
    } catch (IOException e) {
        log.warn("Failed to export parameters-changed information", e);
    } finally {
        IOUtils.closeQuietly(fos);
    }

    writeRuntimeStats(engine, tmpDir);
    writeJobsStats(engine, tmpDir);

    if ("true".equals(System.getProperty(SystemConstants.SYSPROP_STANDALONE_WEB))) {
        writeDirectoryListing(engine, tmpDir);
    }

    fos = null;
    try {
        fos = new FileOutputStream(new File(tmpDir, "system.properties"));
        SortedProperties props = new SortedProperties();
        props.putAll(System.getProperties());
        props.store(fos, "system.properties");
    } catch (IOException e) {
        log.warn("Failed to export thread information", e);
    } finally {
        IOUtils.closeQuietly(fos);
    }

    try {
        File jarFile = new File(getSnapshotDirectory(engine), tmpDir.getName() + ".zip");
        JarBuilder builder = new JarBuilder(tmpDir, jarFile, new File[] { tmpDir }, Version.version());
        builder.build();
        FileUtils.deleteDirectory(tmpDir);
        return jarFile;
    } catch (IOException e) {
        throw new IoException("Failed to package snapshot files into archive", e);
    }
}