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, String padStr) 

Source Link

Document

Right pad a String with a specified String.

Usage

From source file:com.pureinfo.studio.db.cmd2srm.ref.impl.GeneratePrjCardId.java

/**
 * @see com.pureinfo.importer.ref.IImportorRef#convert(com.pureinfo.dolphin.model.DolphinObject,
 *      com.pureinfo.dolphin.model.DolphinObject, java.lang.String,
 *      java.lang.String, com.pureinfo.dolphin.persister.ISession,
 *      com.pureinfo.dolphin.persister.ISession,
 *      com.pureinfo.dolphin.mapping.EntityMetadata, java.lang.String,
 *      java.lang.String)//from   w  w  w .  ja v a  2  s .com
 */
public Object convert(DolphinObject _old, DolphinObject _new, String _sFromProperty, String _sToProperty,
        ISession _fromSession, ISession _toSession, EntityMetadata _metadata, String _sKey, String _sToTable)
        throws PureException {
    String sCampus = null;
    String sOrgCode = null;
    String sPrjSort = null;
    String sAS = null;
    Project project = (Project) _new;
    sCampus = project.getCampus();// 

    sAS = project.getStrProperty("administerSection");// 
    Organization org = project.getDepartment();
    if (org == null) {
        logger.error("error occur when generate prjCardId. project has no department.");
        return null;
    }
    sOrgCode = org.getCode();
    sOrgCode = StringUtils.rightPad(sOrgCode, 5, '0');
    sPrjSort = project.getPrjSortId();//.getRequiredParameter("prjSortId", "");
    logger.debug("to generate prjCardId of:");
    logger.debug("" + sCampus);
    logger.debug("" + sAS);
    logger.debug("" + sPrjSort);
    logger.debug("" + sOrgCode);
    CardIdGenerator cg = CardIdGenerator.instance(sCampus, sOrgCode, sPrjSort, sAS);
    String nextValue = cg.getNextId();
    cg.advance();
    return nextValue;
}

From source file:net.jofm.format.Format.java

public final String format(Object value) {
    if (value == null) {
        return StringUtils.repeat(String.valueOf(padWith), length);
    }/*  w  w w .  j  a  v a 2s .  c  om*/
    String formattedValue = doFormat(value);

    if (formattedValue.length() < length) {
        if (pad == Pad.LEFT) {
            return StringUtils.leftPad(formattedValue, length, padWith);
        } else if (pad == Pad.RIGHT) {
            return StringUtils.rightPad(formattedValue, length, padWith);
        }
    } else if (formattedValue.length() > length) {
        if (logger.isWarnEnabled()) {
            logger.warn("The length of formatted value '" + formattedValue + "' is greater than the length("
                    + length + ") of the field. It is trimmed to match the length.");
        }
        return formattedValue.substring(0, length);
    }

    return formattedValue;
}

From source file:net.sourceforge.fenixedu.util.FenixStringTools.java

public static String multipleLineRightPad(String field, int LINE_LENGTH, char fillPaddingWith) {
    if (!StringUtils.isEmpty(field) && !field.endsWith(" ")) {
        field += " ";
    }//w w  w.  j  a v  a2  s .  c  o m

    if (field.length() < LINE_LENGTH) {
        return StringUtils.rightPad(field, LINE_LENGTH, fillPaddingWith);
    } else {
        final List<String> words = Arrays.asList(field.split(" "));
        int currentLineLength = 0;
        String result = "";

        for (final String word : words) {
            final String toAdd = word + " ";

            if (currentLineLength + toAdd.length() > LINE_LENGTH) {
                result = StringUtils.rightPad(result, LINE_LENGTH, fillPaddingWith) + '\n';
                currentLineLength = toAdd.length();
            } else {
                currentLineLength += toAdd.length();
            }

            result += toAdd;
        }

        if (currentLineLength < LINE_LENGTH) {
            return StringUtils.rightPad(result, result.length() + (LINE_LENGTH - currentLineLength),
                    fillPaddingWith);
        }

        return result;
    }
}

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

/**
 *  ? ?   Console? /*from  www  . j  a va 2  s .  c om*/
 * 
 * @param host HOST 
 * @param port PORT 
 * @param name  
 * @param type  
 * @param path  
 * @param desc  
 * @param maxSize   ?
 * @param volumeId   ?
 */
public void makeMedia(String host, int port, String name, int type, String path, String desc, int maxSize,
        int volumeId) {
    try {
        Media media = new Media();
        media.setName(name);
        media.setType(type);
        media.setPath(path);
        media.setDesc(desc);
        media.setMaxSize(maxSize);
        media.setVolumeId(volumeId);
        media.setCreatedDate(getCreateDate());

        xnapi.XNDisc_Connect(host, port);
        boolean rtn = xnapi.XNDISC_MakeMedia(media);
        if (rtn) {
            StringBuilder medias = new StringBuilder(LINE_SEPERATOR);
            medias.append("").append(StringUtils.rightPad("", 100, "-")).append("?")
                    .append(LINE_SEPERATOR);
            medias.append("").append(StringUtils.center("makeMedia 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());
            }
        } else {
            logger.log(LoggerIF.LOG_ERROR, "mkmedia() failed !!!!");
        }
    } catch (Exception ex) {
        logger.log(LoggerIF.LOG_ERROR, ex.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.athena.peacock.common.core.util.XMLGregorialCalendarUtil.java

/**
 * <pre>/*from ww w . j a v  a 2 s . c o m*/
 * YYYYMMDDHH24MISS? ?? ??   XMLGregorialCalendar ? GMT(GMT+09:00) ? .
 * </pre>
 * @param dateString
 * @return
 */
public static String convertFormattedStringToXmlGregorianCalendarStr(String dateString) {
    Assert.notNull(dateString, "dateString must not be null.");

    if (dateString.length() < 14) {
        dateString = StringUtils.rightPad(dateString, 14, '0');
    }

    Assert.isTrue(dateString.length() == 14, "dateString's length must be 14.");

    GregorianCalendar cal = null;
    XMLGregorianCalendar calender = null;
    try {
        cal = convertTimezone(getDate(dateString), TimeZone.getTimeZone("ROK"));
        calender = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);

        return calender.toString();
    } catch (Exception e) {
        throw new IllegalArgumentException(
                "    . : [Date : " + dateString + " ]");
    }
}

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

/**
 * XNDisc Admin  /*from   w  ww. jav  a2s. com*/
 * 
 * @param mainop ? operation
 * @param processop  operation
 */
private static void printAdminUsage(String mainop, String processop) {

    clearConsoleOutput();

    List<String> ops = new ArrayList<String>();
    if (StringUtils.isEmpty(mainop)) {
        ops.add("file");
        ops.add("media");
        ops.add("vol");
        ops.add("id");
    } else {
        ops.add(mainop);
    }
    if (StringUtils.isEmpty(processop)) {
        ops.add("ls");
        ops.add("mk");
        ops.add("rm");
        ops.add("wh");
        ops.add("ch");
        ops.add("reg");
        ops.add("get");
        ops.add("enc");
        ops.add("dec");
    } else {
        ops.add(processop);
    }

    StringBuilder usage = new StringBuilder(LINE_SEPERATOR);
    usage.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("?")
            .append(LINE_SEPERATOR);
    usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
            .append(LINE_SEPERATOR);
    usage.append("").append(StringUtils.center(XNDISC_ADMIN_UTIL_VERSION, PRINT_COLUMN_SIZE, " "))
            .append("").append(LINE_SEPERATOR);
    usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
            .append(LINE_SEPERATOR);
    usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, "-")).append("")
            .append(LINE_SEPERATOR);
    usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
            .append(LINE_SEPERATOR);

    if (ops.contains("vol")) {
        usage.append("").append(StringUtils.rightPad("      VOLUME Usage", PRINT_COLUMN_SIZE, " "))
                .append("").append(LINE_SEPERATOR);
        usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
                .append(LINE_SEPERATOR);
        if (ops.contains("mk")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.MKVOL.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
            usage.append("").append(StringUtils.rightPad("  - " + XNDiscAdminUsage.ACCESSTYPE.getUsage(),
                    PRINT_COLUMN_SIZE, " ")).append("").append(LINE_SEPERATOR);
        }
        if (ops.contains("ls")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.LSVOL.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
        }
        if (ops.contains("rm")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.RMVOL.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
        }
        if (ops.contains("ch")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.CHVOL.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
            usage.append("").append(StringUtils.rightPad("  - " + XNDiscAdminUsage.ACCESSTYPE.getUsage(),
                    PRINT_COLUMN_SIZE, " ")).append("").append(LINE_SEPERATOR);
        }
        usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
                .append(LINE_SEPERATOR);
        usage.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("")
                .append(LINE_SEPERATOR);
    }
    if (ops.contains("media")) {
        usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
                .append(LINE_SEPERATOR);
        usage.append("").append(StringUtils.rightPad("      MEDIA Usage", PRINT_COLUMN_SIZE, " "))
                .append("").append(LINE_SEPERATOR);
        usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
                .append(LINE_SEPERATOR);
        if (ops.contains("mk")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.MKMEDIA.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
            usage.append("").append(StringUtils.rightPad("  - " + XNDiscAdminUsage.MEDIATYPE.getUsage(),
                    PRINT_COLUMN_SIZE, " ")).append("").append(LINE_SEPERATOR);
        }
        if (ops.contains("ls")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.LSMEDIA.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
        }
        if (ops.contains("rm")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.RMMEDIA.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
        }
        if (ops.contains("ch")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.CHMEDIA.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
            usage.append("").append(StringUtils.rightPad("  - " + XNDiscAdminUsage.MEDIATYPE.getUsage(),
                    PRINT_COLUMN_SIZE, " ")).append("").append(LINE_SEPERATOR);
        }
        usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
                .append(LINE_SEPERATOR);
        usage.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("")
                .append(LINE_SEPERATOR);
    }
    if (ops.contains("file")) {
        usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
                .append(LINE_SEPERATOR);
        usage.append("").append(StringUtils.rightPad("      FILE Usage", PRINT_COLUMN_SIZE, " "))
                .append("").append(LINE_SEPERATOR);
        usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
                .append(LINE_SEPERATOR);
        if (ops.contains("ls")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.LSFILE.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
        }
        if (ops.contains("reg")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.REGFILE.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
        }
        if (ops.contains("get")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.GETFILE.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
        }
        if (ops.contains("wh")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.WHFILE.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
        }
        if (ops.contains("rm")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.RMFILE.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
        }
        usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
                .append(LINE_SEPERATOR);
        usage.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("")
                .append(LINE_SEPERATOR);
    }
    if (ops.contains("id")) {
        usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
                .append(LINE_SEPERATOR);
        usage.append("").append(StringUtils.rightPad("      ID Usage", PRINT_COLUMN_SIZE, " ")).append("")
                .append(LINE_SEPERATOR);
        usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
                .append(LINE_SEPERATOR);
        if (ops.contains("enc")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.IDENC.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
        }
        if (ops.contains("dec")) {
            usage.append("")
                    .append(StringUtils.rightPad(XNDiscAdminUsage.IDDEC.getUsage(), PRINT_COLUMN_SIZE, " "))
                    .append("").append(LINE_SEPERATOR);
        }
        usage.append("").append(StringUtils.center("", PRINT_COLUMN_SIZE, " ")).append("")
                .append(LINE_SEPERATOR);
    }
    usage.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("")
            .append(LINE_SEPERATOR);
    usage.append(LINE_SEPERATOR);
    if (printlog) {
        logger.info(usage.toString());
    } else {
        out.print(usage.toString());
    }
}

From source file:com.enonic.cms.business.core.content.mail.ImportedContentAssignmentMailTemplate.java

private void appendContentListHeading(String languageCode, StringBuffer body) {
    String contentListHeading = getTranslation("%contentAssignmentImportedContentHeading%", languageCode);
    int contentListMsgLength = contentListHeading.length();

    body.append(contentListHeading);/*from   w  w  w .ja  v  a 2 s .c  o  m*/
    addNewLine(body);
    body.append(StringUtils.rightPad("", contentListMsgLength, '-'));
}

From source file:com.redhat.rhn.frontend.servlets.test.CreateRedirectURITest.java

public final void testExecuteWhenRedirectURIExceedsMaxLength() throws Exception {
    String url = StringUtils.rightPad("/YourRhn.do", (int) CreateRedirectURI.MAX_URL_LENGTH + 1, "x");

    mockRequest.stubs().method("getRequestURI").will(returnValue(url));

    CreateRedirectURI command = new CreateRedirectURI();
    String redirectUrl = command.execute(getMockRequest());

    assertEquals(LoginAction.DEFAULT_URL_BOUNCE, redirectUrl);
}

From source file:com.migratebird.launch.commandline.HelpMessageStream.java

/**
 * Prints out a help message that explains the usage of this class
 *//*  ww  w .  ja va2  s.  c  o  m*/
public void print() {
    stream.println("");
    stream.println("Usage:");
    stream.println(
            " java -jar migratebird.jar <operation> [extra operation arguments] [--config propertiesFile]");
    stream.println("");
    stream.println("");

    stream.println(" --config                     Optional. Provides custom properties file. If omitted,");
    stream.println("                              the file " + ConfigrationLoader.MIGRATEBIRD_PROPS_FILE_NAME
            + " is expected ");
    stream.println("                              to be available in the execution directory.");
    stream.println(" --help                       Prints this help message");
    stream.println(" --version                    Prints this version information");
    stream.println("");
    stream.println("Available operations are:");
    stream.println();

    stream.println(StringUtils.rightPad(CREATE_SCRIPT_ARCHIVE.getName(), 30, ' ')
            + "Creates an archive file containing all");
    stream.println(
            "                              configured script locations. Expects file name as second argument.");
    stream.println(
            "                              Optionally, a third argument may be added indicating the scripts archive file or root folder.");
    stream.println("                              This argument overrides the value of the property "
            + MigratebirdProperties.PROPERTY_SCRIPT_LOCATIONS + ".");
    stream.println("");
    stream.println(StringUtils.rightPad(UPDATE_DATABASE.getName(), 30, ' ')
            + "Updates the database to the latest version.");
    stream.println(
            "                              Optionally, an extra argument may be added indicating the scripts archive file or root folder.");
    stream.println("                              This argument overrides the value of the property "
            + MigratebirdProperties.PROPERTY_SCRIPT_LOCATIONS + ".");
    stream.println("");
    stream.println(StringUtils.rightPad(MARK_ERROR_SCRIPT_PERFORMED.getName(), 30, ' ')
            + "Task that indicates that the failed script was manually performed.");
    stream.println("                              The script will NOT be run again in the next update.");
    stream.println("                              No scripts will be executed by this task.");
    stream.println();
    stream.println(StringUtils.rightPad(MARK_ERROR_SCRIPT_REVERTED.getName(), 30, ' ')
            + "Task that indicates that the failed script was manually reverted.");
    stream.println("                              The script will be run again in the next update.");
    stream.println("                              No scripts will be executed by this task.");
    stream.println();
    stream.println(StringUtils.rightPad(MARK_DATABASE_AS_UPTODATE.getName(), 30, ' ')
            + "Marks the database as up-to-date, without executing any script.");
    stream.println(
            "                              You can use this operation to prepare an existing database to be managed by MigrateBird, ");
    stream.println("                              or after fixing a problem manually.");
    stream.println(
            "                              Optionally, an extra argument may be added indicating the scripts archive file or root folder.");
    stream.println("                              This argument overrides the value of the property "
            + MigratebirdProperties.PROPERTY_SCRIPT_LOCATIONS + ".");
    stream.println();
    stream.println(StringUtils.rightPad(CHECK_SCRIPT_UPDATES.getName(), 30, ' ')
            + "Checks if there are any script updates and prints them out, without executing any script.");
    stream.println();
    stream.println(StringUtils.rightPad(CLEAR_DATABASE.getName(), 30, ' ')
            + "Removes all database items, and empties the  table.");
    stream.println();
    stream.println(StringUtils.rightPad(CLEAN_DATABASE.getName(), 30, ' ')
            + "Removes the data of all database tables, except for the MIGRATEBIRD_SCRIPTS table.");
    stream.println();
    stream.println(StringUtils.rightPad(DISABLE_CONSTRAINTS.getName(), 30, ' ')
            + "Disables or drops all foreign key and not null constraints.");
    stream.println();
    stream.println(StringUtils.rightPad(UPDATE_SEQUENCES.getName(), 30, ' ')
            + "Updates all sequences and identity columns to a minimal value.");
}

From source file:blog.javaclue.jcexchanger.StringElement.java

public byte[] getFormattedBytes() {
    if (value == null) {
        if (isNullable) {
            if (AppProperties.useNullIndicator()) {
                return ("Y" + getBlanks(length - 1)).getBytes();
            } else {
                return getLowValues(length);
            }//from  www  .j a v a  2s .c  o  m
        } else {
            return getBlanks(length).getBytes();
        }
    } else {
        String rtn_str = toString();
        if (isNullable && AppProperties.useNullIndicator()) {
            rtn_str = "N" + rtn_str;
        }
        return StringUtils.rightPad(StringUtils.left(rtn_str, length), length, ' ').getBytes();
    }
}