Example usage for org.apache.commons.lang3 StringUtils left

List of usage examples for org.apache.commons.lang3 StringUtils left

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils left.

Prototype

public static String left(final String str, final int len) 

Source Link

Document

Gets the leftmost len characters of a String.

If len characters are not available, or the String is null , the String will be returned without an exception.

Usage

From source file:org.javabeanstack.util.Strings.java

/**
 * Reemplazara con un caracter "replace" cualquier valor dentro de "var" 
 * que se encuentre comprendido entre caracteres "limit"
 * /*from w w  w  .  j  a  v a 2  s .  com*/
 * @param var 
 * @param limit lista de caracteres limitadores.
 * @param replace caracter con que se reemplazara las posiciones entre
 * los caracteres "limit"
 * @return cadena procesada.
 */
public static String varReplace(String var, String limit, String replace) {
    String result = var;
    // Si esta vacio la variable       
    if (Strings.isNullorEmpty(var) || Strings.isNullorEmpty(limit)) {
        return var;
    }
    String limit1, limit2;

    if (limit.length() == 2) {
        limit1 = StringUtils.left(limit, 1);
        limit2 = StringUtils.right(limit, 1);
    } else {
        limit1 = limit.substring(0, 1);
        limit2 = limit.substring(0, 1);
    }
    int c = 0, p1 = 0, p2 = 0, c2 = 0;
    while (true) {
        c = c + 1;
        p1 = findString(limit1, result, c);
        if (limit1.equals(limit2)) {
            c = c + 1;
        }
        p2 = findString(limit2, result, c);
        // Verificar que el caracter no sea un limitador interno
        if (!limit1.equals(limit2)) {
            c2 = c;
            while (p1 >= 0) {
                int innerLimit1 = occurs(limit1, result.substring(p1, p2));
                int innerLimit2 = occurs(limit2, result.substring(p1, p2 + 1));
                if (innerLimit2 == 0) {
                    break;
                }
                if (innerLimit1 - innerLimit2 != 0) {
                    c2 = c2 + innerLimit1 - innerLimit2;
                    p2 = findString(limit2, result, c2);
                } else {
                    break;
                }
            }
        }
        if (p1 == -1 || p2 == -1) {
            break;
        }
        result = StringUtils.left(result, p1 + 1) + StringUtils.repeat(replace, p2 - p1 - 1)
                + result.substring(p2);
    }
    return result;
}

From source file:org.javabeanstack.util.Strings.java

/**
 * Toma los n caracteres del lado izquierdo de un string
 * @param str variable string/*from   w  ww .  j av  a 2 s .  co  m*/
 * @param len cantidad de caracteres
 * @return cantidad de caracteres del lado izquierdo de una variable alfanumrica.
 */
public static String left(String str, int len) {
    return StringUtils.left(str, len);
}

From source file:org.jtalks.tests.jcommune.webdriver.action.PrivateMessages.java

private static void openDraft(PrivateMessage pm) {
    mainPage.openPrivateMessages();/*  w w  w.  ja v a  2s . c om*/
    pmPage.clickOpenDrafts();
    if (!openMessageOnCurrentPage(pm)) {
        throw new AssertionFailedError("The draft is not present in drafts folder. " + "Receiver: ["
                + pm.getReceiver() + "], " + "Subject: [" + StringUtils.left(pm.getMessageSubject(), 10) + "], "
                + "Content: [" + StringUtils.left(pm.getMessageContent(), 10) + "]");
    }
}

From source file:org.jtalks.tests.jcommune.webdriver.action.PrivateMessages.java

@Step
public static void assertPmExistsInRemoteInbox(User receiver, PrivateMessage pm) {
    Users.logout();//  w  w w.j a v a 2 s.c  o  m
    Users.signIn(receiver);
    info("Asserting that PM was received");
    mainPage.openPrivateMessages();
    if (!pmExists(pm)) {
        throw new AssertionFailedError("The PM is not present in inbox folder. " + "Receiver: ["
                + pm.getReceiver() + "], " + "Subject: [" + StringUtils.left(pm.getMessageSubject(), 10) + "], "
                + "Content: [" + StringUtils.left(pm.getMessageContent(), 10) + "]");
    }
    info("Success. PM exists in inbox folder.");
}

From source file:org.jtalks.tests.jcommune.webdriver.action.PrivateMessages.java

@Step
public static void assertPmExistsInOutbox(PrivateMessage pm) {
    info("Asserting that sent PM was saved in outbox");
    mainPage.openPrivateMessages();//from ww w .  j  a  v  a  2 s . c  o m
    pmPage.clickOpenOutboxMessages();
    if (!pmExists(pm)) {
        throw new AssertionFailedError("The PM is not present in outbox folder. " + "Receiver: ["
                + pm.getReceiver() + "], " + "Subject: [" + StringUtils.left(pm.getMessageSubject(), 10) + "], "
                + "Content: [" + StringUtils.left(pm.getMessageContent(), 10) + "]");
    }
    info("Success. PM exists in outbox folder.");
}

From source file:org.jtalks.tests.jcommune.webdriver.action.PrivateMessages.java

@Step
public static void assertPmExistsInDraft(PrivateMessage pm) {
    info("Asserting that draft was really saved");
    mainPage.openPrivateMessages();/*from   w ww .  ja  v  a2  s  . co  m*/
    pmPage.clickOpenDrafts();
    if (!pmExists(pm)) {
        throw new AssertionFailedError("The draft is not present in drafts folder. " + "Receiver: ["
                + pm.getReceiver() + "], " + "Subject: [" + StringUtils.left(pm.getMessageSubject(), 10) + "], "
                + "Content: [" + StringUtils.left(pm.getMessageContent(), 10) + "]");
    }
    info("Success. PM exists in drafts folder.");
}

From source file:org.jtalks.tests.jcommune.webdriver.action.PrivateMessages.java

@Step
public static void assertPmNotExistInInbox(PrivateMessage pm) {
    info("Asserting that PM doesn't exist in inbox folder");
    mainPage.openPrivateMessages();//from  ww w .  ja  va2s  .  c  om
    if (pmExists(pm)) {
        throw new AssertionFailedError("The PM is present in inbox folder. " + "Receiver: [" + pm.getReceiver()
                + "], " + "Subject: [" + StringUtils.left(pm.getMessageSubject(), 10) + "], " + "Content: ["
                + StringUtils.left(pm.getMessageContent(), 10) + "]");
    }
    info("Success. PM doesn't exist in inbox folder.");
}

From source file:org.jtalks.tests.jcommune.webdriver.action.PrivateMessages.java

@Step
public static void assertPmNotExistInOutbox(PrivateMessage pm) {
    info("Asserting that PM doesn't exist in outbox folder");
    mainPage.openPrivateMessages();//w  ww .j  av  a2 s .co m
    pmPage.clickOpenOutboxMessages();
    if (pmExists(pm)) {
        throw new AssertionFailedError("The PM is present in outbox folder. " + "Receiver: [" + pm.getReceiver()
                + "], " + "Subject: [" + StringUtils.left(pm.getMessageSubject(), 10) + "], " + "Content: ["
                + StringUtils.left(pm.getMessageContent(), 10) + "]");
    }
    info("Success. PM doesn't exist in outbox folder.");
}

From source file:org.jtalks.tests.jcommune.webdriver.action.PrivateMessages.java

@Step
public static void assertPmNotExistInDrafts(PrivateMessage pm) {
    info("Asserting that PM doesn't exist in drafts folder");
    mainPage.openPrivateMessages();//from w w  w.  j  a v a 2 s .c o  m
    pmPage.clickOpenDrafts();
    if (pmExists(pm)) {
        throw new AssertionFailedError("The PM is present in drafts folder. " + "Receiver: [" + pm.getReceiver()
                + "], " + "Subject: [" + StringUtils.left(pm.getMessageSubject(), 10) + "], " + "Content: ["
                + StringUtils.left(pm.getMessageContent(), 10) + "]");
    }
    info("Success. PM doesn't exist in drafts folder.");
}

From source file:org.kalypso.commons.runtime.LogAnalyzer.java

/**
 * The ErrorDialog cannot show a message which is too long: the dialog's height would be bigger than the user's
 * monitor. That's why we truncate the summary string here. If the user wants to see more, he can have a look at the
 * log file using the 'details' button in the ErrorDialog
 *//* ww  w.  j  a va  2  s .c o  m*/
public static String shortenMessage(final String message) {
    /* Do not shorten if we are already short enough */
    if (message.length() < 512)
        return message;

    final String truncatedSummary = StringUtils.left(message, 512);
    // '\r' verschwinden lassen, da sonst der Status-Dialog zuviele Umbrche generiert
    final String msg = truncatedSummary.replace('\r', '\t');
    return msg + "..."; //$NON-NLS-1$
}