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

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

Introduction

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

Prototype

public static String left(String str, int len) 

Source Link

Document

Gets the leftmost len characters of a String.

Usage

From source file:org.apache.roller.weblogger.pojos.WeblogEntry.java

/**
 * Return the Title of this post, or the first 255 characters of the
 * entry's text./*from ww w.  ja  v  a2s. c o  m*/
 *
 * @roller.wrapPojoMethod type="simple"
 * @return String
 */
public String getDisplayTitle() {
    if (getTitle() == null || getTitle().trim().equals("")) {
        return StringUtils.left(Utilities.removeHTML(text), 255);
    }
    return Utilities.removeHTML(getTitle());
}

From source file:org.apache.roller.weblogger.ui.rendering.model.UtilitiesModel.java

public String left(String str, int length) {
    return StringUtils.left(str, length);
}

From source file:org.apache.roller.weblogger.ui.tags.LeftTag.java

public String changeString(String text) throws JspException {
    return StringUtils.left(text, NumberUtils.stringToInt(count));
}

From source file:org.apache.roller.weblogger.util.Trackback.java

/**
 * Sends trackback from entry to remote URL.
 * See Trackback spec for details: http://www.sixapart.com/pronet/docs/trackback_spec
 *//*from www  . j  av a  2  s.  c  om*/
public RollerMessages send() throws WebloggerException {

    RollerMessages messages = new RollerMessages();

    log.debug("Sending trackback to url - " + trackbackURL);

    // Construct data
    String title = entry.getTitle();
    String excerpt = StringUtils.left(Utilities.removeHTML(entry.getDisplayContent()), 255);
    String url = entry.getPermalink();
    String blog_name = entry.getWebsite().getName();

    // build trackback post parameters as query string
    Map params = new HashMap();
    params.put("title", URLUtilities.encode(title));
    params.put("excerpt", URLUtilities.encode(excerpt));
    params.put("url", URLUtilities.encode(url));
    params.put("blog_name", URLUtilities.encode(blog_name));
    String queryString = URLUtilities.getQueryString(params);

    log.debug("query string - " + queryString);

    // prepare http request
    HttpClient client = new HttpClient();
    client.setConnectionTimeout(45 * 1000);
    HttpMethod method = new PostMethod(trackbackURL);
    method.setQueryString(queryString);

    try {
        // execute trackback
        int statusCode = client.executeMethod(method);

        // read response
        byte[] response = method.getResponseBody();
        String responseString = Utilities.escapeHTML(new String(response, "UTF-8"));

        log.debug("result = " + statusCode + " " + method.getStatusText());
        log.debug("response:\n" + responseString);

        if (statusCode == HttpStatus.SC_OK) {
            // trackback request succeeded, message will give details
            try {
                messages = parseTrackbackResponse(new String(response, "UTF-8"), messages);
            } catch (Exception e) {
                // Cannot parse response, indicates failure
                messages.addError("weblogEdit.trackbackErrorParsing", responseString);
            }
        } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
            // 404, invalid trackback url
            messages.addError("weblogEdit.trackbackError404");
        } else {
            // some other kind of error with url, like 500, 403, etc
            // just provide a generic error message and give the http response text
            messages.addError("weblogEdit.trackbackErrorResponse",
                    new String[] { "" + statusCode, method.getStatusText() });
        }

    } catch (IOException e) {
        // some kind of transport error sending trackback post
        log.debug("Error sending trackback", e);
        messages.addError("weblogEdit.trackbackErrorTransport");
    } finally {
        // release used connection
        method.releaseConnection();
    }

    return messages;
}

From source file:org.apereo.portal.events.PortalEventFactoryImpl.java

protected final Map<String, List<String>> pruneParameters(Map<String, List<String>> parameters) {
    final Builder<String, List<String>> builder = ImmutableMap.builder();

    int paramCount = 0;
    for (final Map.Entry<String, List<String>> parameterEntry : parameters.entrySet()) {
        if (paramCount == this.maxParameters) {
            break;
        }/*from w w  w. j av  a2 s.co  m*/
        paramCount++;

        final String name = StringUtils.left(parameterEntry.getKey(), this.maxParameterLength);
        List<String> values = parameterEntry.getValue();
        if (values == null) {
            values = Collections.emptyList();
        }

        final com.google.common.collect.ImmutableList.Builder<String> valuesBuilder = ImmutableList.builder();

        int valueCount = 0;
        for (final String value : values) {
            if (valueCount == this.maxParameters) {
                break;
            }
            valueCount++;

            valuesBuilder.add(StringUtils.left(value, this.maxParameterLength));
        }

        builder.put(name, valuesBuilder.build());
    }

    return builder.build();
}

From source file:org.archfirst.bfexch.domain.trading.order.ClOrdIDParser.java

public static String getBrokerId(String clientOrderId) {
    return StringUtils.left(clientOrderId, 4);
}

From source file:org.batoo.jpa.parser.impl.acl.ClassloaderAnnotatedClassLocator.java

private Set<Class<?>> findClasses(ClassLoader cl, Set<Class<?>> classes, String root, String path) {
    final File file = new File(path);

    if (file.isDirectory()) {
        ClassloaderAnnotatedClassLocator.LOG.debug("Processing directory {0}", path);

        for (final String child : file.list()) {
            this.findClasses(cl, classes, root, path + "/" + child);
        }/* ww  w  .j a va  2  s .c  om*/
    } else {
        if (FilenameUtils.isExtension(path, "class")) {
            final String normalizedPath = FilenameUtils.separatorsToUnix(FilenameUtils.normalize(path));

            final int rootLength = FilenameUtils.normalizeNoEndSeparator(root).length();
            String className = normalizedPath.substring(rootLength + 1).replaceAll("/", ".");
            className = StringUtils.left(className, className.length() - 6);

            final Class<?> clazz = this.isPersistentClass(cl, className);
            if (clazz != null) {
                ClassloaderAnnotatedClassLocator.LOG.debug("Found persistent class {0}", className);
                classes.add(clazz);
            }
        }
    }

    return classes;
}

From source file:org.beer30.jdefault.JDefaultBusinessTest.java

@Test
public void testGenerateCreditCard() {
    String visa = JDefaultBusiness.creditCardNumber(JDefaultCreditCardType.VISA);
    System.out.println(visa);/*from  w  w  w .  j a va 2s . com*/
    Assert.assertEquals(16, visa.length());
    Assert.assertEquals("4", StringUtils.left(visa, 1));

    String masterCard = JDefaultBusiness.creditCardNumber(JDefaultCreditCardType.MASTERCARD);
    System.out.println(masterCard);
    Assert.assertEquals(16, masterCard.length());
    Assert.assertEquals("5", StringUtils.left(masterCard, 1));

    String amex = JDefaultBusiness.creditCardNumber(JDefaultCreditCardType.AMEX);
    System.out.println(amex);
    Assert.assertEquals(15, amex.length());
    Assert.assertEquals("3", StringUtils.left(amex, 1));

    String discover = JDefaultBusiness.creditCardNumber(JDefaultCreditCardType.DISCOVER);
    System.out.println(discover);
    Assert.assertEquals(16, discover.length());
    Assert.assertEquals("6011", StringUtils.left(discover, 4));
}

From source file:org.beer30.jdefault.JDefaultInternet.java

/**
 * generates a random username in the format of Firstname intial + lastname + random 2 digit
 * ie tjones67//  w w  w.j a va  2  s.com
 *
 * @return
 */
public static String userName() {
    return fixNonWord(StringUtils.left(JDefaultName.firstName(), 1).toLowerCase()
            + JDefaultName.lastName().toLowerCase() + JDefaultNumber.randomNumberString(2));
}

From source file:org.codehaus.mojo.versions.branch.BranchMojo.java

static String truncateBranch(String branch) {
    return BranchHelper.find(branch, JIRA_ID_PATTERN).orElse(StringUtils.left(branch, 10));
}