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

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

Introduction

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

Prototype

public static String center(String str, int size, String padStr) 

Source Link

Document

Centers a String in a larger String of size size.

Usage

From source file:com.github.cereda.arara.rulechecker.RuleUtils.java

/**
 * Prints the report for every rule report.
 * @param rules The list of rule report.
 *///from w w  w.  j  a  v  a2s. c  o  m
public static void printReport(List<RuleReport> rules) {

    // print header
    System.out.println(StringUtils.center(" Task coverage report ", 60, "-").concat("\n"));

    // let's sort our list of reports according to
    // each rule coverage
    Collections.sort(rules, new Comparator<RuleReport>() {

        @Override
        public int compare(RuleReport t1, RuleReport t2) {

            // get values of each rule
            float a1 = t1.getCoverage();
            float a2 = t2.getCoverage();

            // they are equal, do nothing
            if (a1 == a2) {
                return 0;
            } else {

                // we want to sort in reverse order,
                // so return a negative value here
                if (a1 > a2) {
                    return -1;
                } else {

                    // return a positive value, since
                    // the first statement was false
                    return 1;
                }
            }
        }
    });

    // for each report, print
    // the corresponding entry
    for (RuleReport rule : rules) {

        // build the beginning of the line
        String line = String.format("- %s ", rule.getReference().getName());

        // build the coverage information
        String coverage = String.format(" %2.2f%%", rule.getCoverage());

        // generate the line by concatenating
        // the beginning and coverage
        line = line.concat(StringUtils.repeat(".", 60 - line.length() - coverage.length())).concat(coverage);

        // print the line
        System.out.println(line);
    }
}

From source file:com.github.cereda.arara.langchecker.LanguageUtils.java

/**
 * Prints the report for every language report.
 * @param languages The list of language reports.
 */// ww w .j a v  a  2 s  . c  om
public static void printReport(List<LanguageReport> languages) {

    // print header
    System.out.println(StringUtils.center(" Language coverage report ", 60, "-").concat("\n"));

    // let's sort our list of reports according to
    // each language coverage
    Collections.sort(languages, new Comparator<LanguageReport>() {

        @Override
        public int compare(LanguageReport t1, LanguageReport t2) {

            // get values of each language
            float a1 = t1.getCoverage();
            float a2 = t2.getCoverage();

            // they are equal, do nothing
            if (a1 == a2) {
                return 0;
            } else {

                // we want to sort in reverse order,
                // so return a negative value here
                if (a1 > a2) {
                    return -1;
                } else {

                    // return a positive value, since
                    // the first statement was false
                    return 1;
                }
            }
        }
    });

    // list of languages to be fixed
    List<LanguageReport> fix = new ArrayList<>();

    // for each report, print
    // the corresponding entry
    for (LanguageReport language : languages) {

        // if there are problematic lines,
        // add the current language report
        if (!language.getLines().isEmpty()) {
            fix.add(language);
        }

        // build the beginning of the line
        String line = String.format("- %s ", language.getReference().getName());

        // build the coverage information
        String coverage = String.format(" %2.2f%%", language.getCoverage());

        // generate the line by concatenating
        // the beginning and coverage
        line = line.concat(StringUtils.repeat(".", 60 - line.length() - coverage.length())).concat(coverage);

        // print the line
        System.out.println(line);
    }

    // we have some fixes to do
    if (!fix.isEmpty()) {

        // print header
        System.out.println();
        System.out.println(StringUtils.center(" Lines to fix ", 60, "-").concat("\n"));

        // print legend for a simple message
        System.out.println(StringUtils.center("S: Simple message, single quotes should not be doubled", 60));

        // print legend for a parametrized
        System.out.println(
                StringUtils.center("P: Parametrized message, single quotes must be doubled", 60).concat("\n"));

        // print a line separator
        System.out.println(StringUtils.repeat("-", 60));

        // print each language and its
        // corresponding lines
        for (LanguageReport report : fix) {

            // build the beginning of the line
            String line = String.format("- %s ", report.getReference().getName());

            // build the first batch
            String batch = pump(report.getLines(), 2);

            // generate the line by concatenating
            // the beginning and batch
            line = line.concat(StringUtils.repeat(" ", 60 - line.length() - batch.length())).concat(batch);

            // print the line
            System.out.println(line);

            // get the next batch, if any
            batch = pump(report.getLines(), 2);

            // repeat while there
            // are other batches
            while (!batch.isEmpty()) {

                // print current line
                System.out.println(StringUtils.leftPad(batch, 60));

                // get the next batch and let
                // the condition handle it
                batch = pump(report.getLines(), 2);
            }

            // print a line separator
            System.out.println(StringUtils.repeat("-", 60));
        }
    }

}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminVolume.java

/**
 *  ? ? ?     Console? /* ww w. j  a va2  s. c  o  m*/
 * 
 * @param volumeId  ?
 */
public void removeVolume(int volumeId) {
    try {
        if (dao.deleteVolume(volumeId)) { // success
            StringBuilder volumes = new StringBuilder(LINE_SEPERATOR);
            volumes.append("").append(StringUtils.rightPad("", 100, "-")).append("?")
                    .append(LINE_SEPERATOR);
            volumes.append("")
                    .append(StringUtils.center("removeVolume Successfully : " + volumeId, 100, " "))
                    .append("").append(LINE_SEPERATOR);
            volumes.append("").append(StringUtils.rightPad("", 100, "-")).append("")
                    .append(LINE_SEPERATOR);
            if (printlog) {
                log.info(volumes.toString());
            } else {
                out.print(volumes.toString());
            }
        } else {
            logger.log(LoggerIF.LOG_ERROR, "removeVolume() failed");
        }
    } catch (Exception e) {
        logger.log(LoggerIF.LOG_ERROR, e.getMessage());
    }
}

From source file:com.github.cereda.arara.rulechecker.RuleUtils.java

public static void updateRules(List<File> files) {

    // check if the provided list is empty
    if (files.isEmpty()) {

        // print error message
        System.err.println(WordUtils.wrap("Fatal exception: I could not find any rules in "
                + "the provided directory. I am afraid I won't be "
                + "be able to continue. Please make sure the "
                + "provided directory contains at least one rule to "
                + "be analyzed. The application will halt now.", 60));
    }/* w  ww .j  a v a 2  s  . c  om*/

    // print header
    System.out.println(StringUtils.center(" Update report ", 60, "-").concat("\n"));

    // read each file of the list and extract
    // each task found
    for (File file : files) {

        try {

            // read each file into a list
            // of strings
            List<String> lines = FileUtils.readLines(file, "UTF-8");

            // create the potential
            // output for the updated file
            List<String> output = new ArrayList<>();

            // iterate through each line
            for (String line : lines) {

                // only add lines not matching
                // the task pattern
                if (!match(line)) {
                    output.add(line);
                }

            }

            // result string
            String result;

            // if the sizes are the same,
            // nothing happened
            if (lines.size() == output.size()) {

                // update status
                result = " Unchanged";
            } else {

                // update the file reference
                FileUtils.writeLines(file, "UTF-8", output);

                // update status
                result = " Updated";
            }

            // build the beginning of the line
            String line = String.format("- %s ", file.getName());

            // generate the full entry
            line = line.concat(StringUtils.repeat(".", 60 - line.length() - result.length())).concat(result);

            // print entry
            System.out.println(line);

        } catch (IOException exception) {

            // print error message
            System.err.println(WordUtils.wrap("Fatal exception: an error was raised while "
                    + "trying to read one of the rules. Please make "
                    + "sure all rules in the provided directory have "
                    + "read permission. I won't be able to continue. " + "The application will halt now.", 60));
            System.exit(1);
        }
    }
}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminVolume.java

/**
 *    ?   Console ? /*from   ww  w. j a  v a  2s.  co m*/
 * 
 * @param id  ?
 * @param name  
 * @param accessAuth  
 * @param desc  
 */
public void changeVolume(int id, String name, String accessAuth, String desc) {
    try {
        Volume volume = new Volume();
        volume.setId(id);
        volume.setName(name);
        volume.setAccessable(accessAuth);
        volume.setDesc(desc);
        if (dao.updateVolume(volume)) {
            StringBuilder volumes = new StringBuilder(LINE_SEPERATOR);
            volumes.append("").append(StringUtils.rightPad("", 100, "-")).append("?")
                    .append(LINE_SEPERATOR);
            volumes.append("").append(StringUtils.center("changeVolume Successfully : " + id, 100, " "))
                    .append("").append(LINE_SEPERATOR);
            volumes.append("").append(StringUtils.rightPad("", 100, "-")).append("")
                    .append(LINE_SEPERATOR);
            if (printlog) {
                log.info(volumes.toString());
            } else {
                out.print(volumes.toString());
            }
        } else {
            logger.log(LoggerIF.LOG_ERROR, "changeVolume() failed..");
        }
    } catch (Exception ex) {
        logger.log(LoggerIF.LOG_ERROR, ex.getMessage());
    }
}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminFile.java

/**
 * ?? ? ?  Console? //from  www  .  j a va2  s .com
 * 
 * @param host HOST 
 * @param port PORT 
 * @param regFilePath ? ?(?  )
 * @param regVolId ?  ?
 * @param regStatType ? ? 
 */
public void regFile(String host, int port, String regFilePath, int regVolId, String regStatType) {
    NFile[] nFile = null;
    try {
        int numOfFiles = 1;
        nFile = new NFile[numOfFiles];
        nFile[0] = new NFile();
        nFile[0].setName(regFilePath);
        nFile[0].setVolumeId(regVolId);
        nFile[0].setStatType(regStatType);

        xnapi.XNDisc_Connect(host, port);
        String[] arrRet = xnapi.XNDISC_FileReg(nFile);
        if (null == arrRet) {
            logger.log(LoggerIF.LOG_ERROR, "XNDISC_FileReg() return null");
        } else {
            StringBuilder files = new StringBuilder(LINE_SEPERATOR);
            files.append("").append(StringUtils.rightPad("", 100, "-")).append("?").append(LINE_SEPERATOR);
            files.append("").append(StringUtils.center("Registered File ID : " + arrRet[0], 100, " "))
                    .append("").append(LINE_SEPERATOR);
            files.append("").append(StringUtils.rightPad("", 100, "-") + "").append(LINE_SEPERATOR);
            if (printlog) {
                log.info(files.toString());
            } else {
                out.print(files.toString());
            }
        }
    } catch (FileException e) {
        logger.log(LoggerIF.LOG_ERROR, e.getMessage());
    } catch (NetworkException e) {
        logger.log(LoggerIF.LOG_ERROR, e.getMessage());
    } catch (NDiscException e) {
        logger.log(LoggerIF.LOG_ERROR, e.getMessage());
    } finally {
        try {
            xnapi.XNDisc_Disconnect();
        } catch (NetworkException ne) {
            logger.log(LoggerIF.LOG_ERROR, ne.getMessage());
        } catch (IOException e) {
            logger.log(LoggerIF.LOG_ERROR, e.getMessage());
        }
    }
}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminFile.java

/**
 * ? ? ? ??    Console? /*ww w . j a  v  a 2  s  .  c o  m*/
 * 
 * @param host HOST 
 * @param port PORT 
 * @param fileId ? ?
 * @param destFilePath  ? (?)
 */
public void getFile(String host, int port, String fileId, String destFilePath) {
    try {
        int numOfFiles = 1;
        NFile[] nFile = new NFile[numOfFiles];
        nFile[0] = new NFile();
        nFile[0].setId(fileId);
        nFile[0].setName(destFilePath);
        nFile[0].setStatType(XNDiscAdminConfig.STAT_AUTO); // AUTO

        xnapi.XNDisc_Connect(host, port);
        boolean reg = xnapi.XNDISC_FileGet(nFile);
        if (reg) {
            StringBuilder files = new StringBuilder(LINE_SEPERATOR);
            files.append("").append(StringUtils.rightPad("", 100, "-")).append("?").append(LINE_SEPERATOR);
            files.append("").append(StringUtils.center("getFile : " + getName(destFilePath, 100), 100, " "))
                    .append("").append(LINE_SEPERATOR);
            files.append("").append(StringUtils.rightPad("", 100, "-")).append("").append(LINE_SEPERATOR);
            if (printlog) {
                log.info(files.toString());
            } else {
                out.print(files.toString());
            }
        } else {
            logger.log(LoggerIF.LOG_ERROR, "getFile() failed.");
        }
    } catch (Exception ex) {
        logger.log(LoggerIF.LOG_ERROR, ex.getMessage());
        ex.printStackTrace();
    } finally {
        try {
            xnapi.XNDisc_Disconnect();
        } catch (NetworkException ne) {
            logger.log(LoggerIF.LOG_ERROR, ne.getMessage());
        } catch (IOException e) {
            logger.log(LoggerIF.LOG_ERROR, e.getMessage());
        }
    }
}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminMedia.java

/**
 *      Console? /*from  w  w  w  . ja v  a 2  s . c om*/
 * 
 * @param id  ?
 * @param name  
 * @param type  
 * @param path  
 * @param desc  
 * @param maxSize   ?
 * @param volumeId   ?
 */
public void changeMedia(int id, String name, int type, String path, String desc, int maxSize, int volumeId) {
    try {
        Media media = new Media();
        media.setId(id);
        media.setName(name);
        media.setType(type);
        media.setPath(path);
        media.setDesc(desc);
        media.setMaxSize(maxSize);
        media.setVolumeId(volumeId);
        dao.updateMedia(media);
        StringBuilder medias = new StringBuilder(LINE_SEPERATOR);
        medias.append("").append(StringUtils.rightPad("", 100, "-")).append("?").append(LINE_SEPERATOR);
        medias.append("").append(StringUtils.center("changeMedia Successfully", 100, " ")).append("")
                .append(LINE_SEPERATOR);
        medias.append("").append(StringUtils.rightPad("", 100, "-")).append("").append(LINE_SEPERATOR);
        if (printlog) {
            log.info(medias.toString());
        } else {
            out.print(medias.toString());
        }
    } catch (Exception ex) {
        logger.log(LoggerIF.LOG_ERROR, ex.getMessage());
    }
}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminMedia.java

/**
 *     //from w  w w .ja va2 s.  com
 * 
 * @param id  ?
 */
public void removeMedia(int id) {
    try {
        dao.deleteMedia(id);
        StringBuilder medias = new StringBuilder(LINE_SEPERATOR);
        medias.append("").append(StringUtils.rightPad("", 100, "-")).append("?").append(LINE_SEPERATOR);
        medias.append("").append(StringUtils.center("removeMedia Successfully", 100, " ")).append("")
                .append(LINE_SEPERATOR);
        medias.append("").append(StringUtils.rightPad("", 100, "-")).append("").append(LINE_SEPERATOR);
        if (printlog) {
            log.info(medias.toString());
        } else {
            out.print(medias.toString());
        }
    } catch (Exception ex) {
        logger.log(LoggerIF.LOG_ERROR, ex.getMessage());
    }
}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminFile.java

/**
 * ? ? ? ?    Console? /*from   w  w w  . j  av  a2 s  . co  m*/
 * 
 * @param fileId ? ?
 */
public void getFilePathByFileId(String fileId) {
    NFile[] nFile = null;
    try {
        nFile = new NFile[1];
        nFile[0] = new NFile();
        nFile[0].setId(fileId);
        nFile = storage.aquireStorageInfo(nFile, NDCommon.STORAGE_PATH_ACCESS);
        String ret = nFile[0].getStoragePath();
        if (!StringUtils.isEmpty(ret)) {
            StringBuilder files = new StringBuilder(LINE_SEPERATOR);
            files.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("?")
                    .append(LINE_SEPERATOR);
            files.append("").append(StringUtils.center("getFilePath : " + ret, PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
            files.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("")
                    .append(LINE_SEPERATOR);
            if (printlog) {
                log.info(files.toString());
            } else {
                out.print(files.toString());
            }
        }
    } catch (Exception e) {
        logger.log(LoggerIF.LOG_ERROR, e.getMessage());
    }
}