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

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

Introduction

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

Prototype

public static String substring(String str, int start, int end) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

From source file:org.jboss.windup.util.RecursiveZipMetaFactory.java

public RecursiveZipMetaFactory(File startLocation, Set<String> extensions) {
    UUID uuidKey = UUID.randomUUID();
    safeExtractKey = "_" + StringUtils.substring(StringUtils.remove(uuidKey.toString(), "-"), 0, 6);

    this.startLocation = new File(
            startLocation.getAbsolutePath() + File.separator + "jboss_windup" + safeExtractKey);
    this.kae = extensions;
}

From source file:org.jenkins.ci.plugins.jobimport.RemoteJob.java

protected static final String cleanRemoteString(final String string) {
    return StringUtils.substring(StringEscapeUtils.escapeHtml(string), 0, MAX_STRLEN);
}

From source file:org.jenkinsci.plugins.docker.traceability.test.FingerprintTestUtil.java

/**
 * Generates 64-symbol id with the specified prefix;
 * @param prefix Prefix to be retrieved/* w w w.  jav a  2  s.co  m*/
 * @return Generated ID (works for container and image).
 */
public static @Nonnull String generateDockerId(@Nonnull String prefix) {
    final String src = "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc";
    return prefix + StringUtils.substring(src, 0, 64 - prefix.length());
}

From source file:org.jspringbot.keyword.config.ConfigHelper.java

public void init() throws IOException {
    ResourceEditor editor = new ResourceEditor();
    editor.setAsText("classpath:config/");
    Resource configDirResource = (Resource) editor.getValue();

    boolean hasConfigDirectory = true;
    boolean hasConfigProperties = true;

    if (configDirResource != null) {
        try {/* w w  w . j a v a2  s .co m*/
            File configDir = configDirResource.getFile();

            if (configDir.isDirectory()) {
                File[] propertiesFiles = configDir.listFiles(new FileFilter() {
                    @Override
                    public boolean accept(File file) {
                        return StringUtils.endsWith(file.getName(), ".properties")
                                || StringUtils.endsWith(file.getName(), ".xml");
                    }
                });

                for (File propFile : propertiesFiles) {
                    String filename = propFile.getName();
                    String name = StringUtils.substring(filename, 0, StringUtils.indexOf(filename, "."));

                    addProperties(name, propFile);
                }
            }
        } catch (IOException e) {
            hasConfigDirectory = false;
        }
    }

    editor.setAsText("classpath:config.properties");
    Resource configPropertiesResource = (Resource) editor.getValue();

    if (configPropertiesResource != null) {
        try {
            File configPropertiesFile = configPropertiesResource.getFile();

            if (configPropertiesFile.isFile()) {
                Properties configs = new Properties();

                configs.load(new FileReader(configPropertiesFile));

                for (Map.Entry entry : configs.entrySet()) {
                    String name = (String) entry.getKey();
                    editor.setAsText(String.valueOf(entry.getValue()));

                    try {
                        Resource resource = (Resource) editor.getValue();
                        addProperties(name, resource.getFile());
                    } catch (Exception e) {
                        throw new IOException(String.format("Unable to load config '%s'.", name), e);
                    }
                }
            }
        } catch (IOException e) {
            hasConfigProperties = false;
        }
    }

    if (!hasConfigDirectory && !hasConfigProperties) {
        LOGGER.warn("No configuration found.");
    }
}

From source file:org.jspringbot.keyword.expression.ELUtils.java

public static String substring(String str, Integer... index) {
    if (index.length > 1) {
        return StringUtils.substring(str, index[0], index[1]);
    } else if (index.length == 1) {
        return StringUtils.substring(str, index[0]);
    }//  www  . j  av  a 2  s . c o  m

    throw new IllegalArgumentException("No startIndex provided.");
}

From source file:org.jspringbot.syntax.HighlighterUtils.java

private String getString(String code, String type) {
    if (!enable) {
        return "\n" + StringEscapeUtils.escapeHtml(code);
    }/* w  ww. ja va2 s.  c om*/

    SyntaxHighlighterParser parser = parserMap.get(type);
    if (parser == null) {
        return "\n" + StringEscapeUtils.escapeHtml(code);
    }

    int i = 0;
    StringBuilder buf = new StringBuilder("<pre style=\"padding:3px;");

    if (theme.getBackground() != null) {
        cssColor(buf, "background-color", theme.getBackground());
    }
    if (theme.getFont() != null) {
        buf.append("font-family:")
                .append("Menlo, 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', Monaco, Consolas, monospace");
    }
    buf.append("font-size:").append(fontSize).append(";");
    buf.append(
            "white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word;");
    buf.append("\">");

    for (ParseResult result : parser.parse(code)) {
        if (i > result.getOffset())
            continue;

        String before = StringUtils.substring(code, i, result.getOffset());
        if (!StringUtils.isEmpty(before)) {
            style(buf, "plain", before);
        }

        String token = StringUtils.substring(code, result.getOffset(), result.getOffset() + result.getLength());
        String keys = result.getStyleKeysString();

        if (StringUtils.equals(type, "json") && StringUtils.equals(keys, "string")
                && isLastStringJsonKeyword(code, result.getOffset())) {
            style(buf, "keyword", token);
        } else {
            style(buf, result.getStyleKeys(), token);
        }

        i = result.getOffset() + result.getLength();
    }

    String before = StringUtils.substring(code, i, i + code.length());
    if (!StringUtils.isEmpty(before)) {
        style(buf, "plain", before);
    }

    return buf.append("</pre>").toString();
}

From source file:org.jtalks.jcommune.service.nontransactional.MentionedUsers.java

/**
 * Extract names of users that were mentioned in passed text.
 *
 * @param canContainMentionedUsers can contain users mentioning
 * @param mentionedUserPattern     pattern to extract mentioned user in given text
 * @return extracted users' names//  w  ww  .j  av a  2 s.  c  om
 */
private Set<String> extractMentionedUsers(String canContainMentionedUsers, Pattern mentionedUserPattern) {
    if (!StringUtils.isEmpty(canContainMentionedUsers)) {
        Matcher matcher = mentionedUserPattern.matcher(canContainMentionedUsers);
        Set<String> mentionedUsernames = new HashSet<>();
        while (matcher.find()) {
            String userBBCode = matcher.group();
            String mentionedUser;
            if (userBBCode.contains("[user notified=true]")) {
                mentionedUser = StringUtils.substring(userBBCode, 20, userBBCode.length() - 7);
            } else {
                mentionedUser = StringUtils.substring(userBBCode, 6, userBBCode.length() - 7);
            }
            mentionedUsernames.add(replacePlaceholdersWithChars(mentionedUser));
        }
        return mentionedUsernames;
    }
    return Collections.emptySet();
}

From source file:org.jumpmind.metl.core.runtime.component.ModelAttributeScriptHelper.java

public String substr(int start, int end) {
    String text = value != null ? value.toString() : "";
    return StringUtils.substring(text, start, end);
}

From source file:org.kuali.kfs.fp.document.web.struts.CashManagementAction.java

/**
 * Overrides the default document-creation code to auto-save new documents upon creation: since creating a CMDoc changes the
 * CashDrawer's state as a side-effect, we need all CMDocs to be docsearchable so that someone can relocate and use or cancel
 * whatever the current CMDoc is.// ww w .j  a v a2s .  co m
 * 
 * @param kualiDocumentFormBase
 * @throws WorkflowException
 */
@Override
protected void createDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
    Person user = GlobalVariables.getUserSession().getPerson();
    String campusCode = SpringContext.getBean(CashReceiptService.class)
            .getCashReceiptVerificationUnitForUser(user);

    String defaultDescription = SpringContext.getBean(ConfigurationService.class)
            .getPropertyValueAsString(CashManagement.DEFAULT_DOCUMENT_DESCRIPTION);
    defaultDescription = StringUtils.replace(defaultDescription, "{0}", campusCode);
    defaultDescription = StringUtils.substring(defaultDescription, 0, 39);

    // create doc
    CashManagementDocument cmDoc = SpringContext.getBean(CashManagementService.class)
            .createCashManagementDocument(campusCode, defaultDescription, null);

    // update form
    kualiDocumentFormBase.setDocument(cmDoc);
    kualiDocumentFormBase.setDocTypeName(cmDoc.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
}

From source file:org.kuali.kfs.gl.batch.CollectorBatch.java

protected String getValue(String headerLine, int s, int e) {
    return org.springframework.util.StringUtils.trimTrailingWhitespace(StringUtils.substring(headerLine, s, e));
}