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

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

Introduction

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

Prototype

public static String stripEnd(String str, String stripChars) 

Source Link

Document

Strips any of a set of characters from the end of a String.

Usage

From source file:gov.nih.nci.caarray.plugins.affymetrix.AffymetrixTsvFileReader.java

private void parseHeaderLine() {
    String trimmedLine = currentLine.trim();
    int fileHeaderMarkerIndex = trimmedLine.indexOf(FILE_HEADER_MARKER);
    if (fileHeaderMarkerIndex < 0) {
        addColumnHeaders(currentLine, 0, dequoteData);
    } else {//from   w ww .  ja v  a 2  s .co  m
        int equalsIndex = trimmedLine.indexOf('=');
        if (equalsIndex > fileHeaderMarkerIndex && equalsIndex < trimmedLine.length() - 1) {
            String headerName = trimmedLine.substring(fileHeaderMarkerIndex + 2, equalsIndex).trim();
            String headerValue = StringUtils.stripEnd(trimmedLine.substring(equalsIndex + 1), null);
            if (headerName.startsWith(COLUMN_HEADER_PREFIX)) {
                int headerNum = Integer.valueOf(headerName.substring(6));
                addColumnHeaders(headerValue, headerNum, false);
            } else {
                List<String> values = fileHeaders.get(headerName);
                if (values == null) {
                    values = new ArrayList<String>();
                    fileHeaders.put(headerName, values);
                }
                values.add(headerValue.trim());
            }
        }
    }
}

From source file:com.contrastsecurity.ide.eclipse.ui.internal.preferences.ContrastPreferencesPage.java

private void verifyTeamServerUrl() {
    String tsUrl = teamServerText.getText();

    tsUrl = StringUtils.stripEnd(tsUrl, "/");
    if (tsUrl.endsWith(URL_SUFFIX)) {
        teamServerText.setText(tsUrl);//  w  w w.  j a v  a  2  s  .  c  o m
        return;
    }

    char lastChar = tsUrl.charAt(tsUrl.length() - 1);
    for (int i = URL_SUFFIX.length() - 1; i > -1; i--) {
        if (lastChar == URL_SUFFIX.charAt(i) && tsUrl.endsWith(URL_SUFFIX.substring(0, i + 1))) {
            teamServerText.setText(tsUrl + URL_SUFFIX.substring(i + 1));
            return;
        }
    }

    teamServerText.setText(tsUrl + URL_SUFFIX);
}

From source file:com.smartitengineering.util.bean.PropertiesLocator.java

protected void loadFromReader(Properties props, Reader reader) throws IOException {
    BufferedReader in = new BufferedReader(reader);
    while (true) {
        String line = in.readLine();
        if (line == null) {
            return;
        }/*from  w  ww  .  j  av  a  2s .c o m*/
        line = StringUtils.stripStart(line, null);
        if (line.length() > 0) {
            char firstChar = line.charAt(0);
            if (firstChar != '#' && firstChar != '!') {
                while (endsWithContinuationMarker(line)) {
                    String nextLine = in.readLine();
                    line = line.substring(0, line.length() - 1);
                    if (nextLine != null) {
                        line += StringUtils.stripStart(nextLine, null);
                    }
                }
                int separatorIndex = line.indexOf("=");
                if (separatorIndex == -1) {
                    separatorIndex = line.indexOf(":");
                }
                String key = (separatorIndex != -1 ? line.substring(0, separatorIndex) : line);
                String value = (separatorIndex != -1) ? line.substring(separatorIndex + 1) : "";
                key = StringUtils.stripEnd(key, null);
                value = StringUtils.stripStart(value, null);
                props.put(unescape(key), unescape(value));
            }
        }
    }
}

From source file:com.obomprogramador.tools.jqana.parsers.Lcom4Listener.java

private boolean checkForGetterSetter(Member m) {
    boolean isGetterSetter = false;
    for (Member n : this.membersTable) {
        if (n.type == MEMBER_TYPE.VARIABLE) {
            if (StringUtils.containsIgnoreCase(m.name, n.name)) {
                // StringUtils.strip("  abcyx", "xyz") = "  abc"
                String beginMethodName = StringUtils.stripEnd(m.name.toLowerCase(), n.name.toLowerCase());
                if (this.getterSetterPrefix.contains(beginMethodName)) {
                    isGetterSetter = true;
                    m.targetVariable = n;
                }//w ww.ja  va  2  s. co  m
                break;
            }
        }
    }
    return isGetterSetter;
}

From source file:com.yoncabt.ebr.executor.jasper.JasperReport.java

@Override
public ReportDefinition loadDefinition(File file) throws IOException, ReportException {
    setFile(file);//w  w w.ja va 2  s  . c  om
    String jsonFileName = file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf(".jrxml"))
            + ".ebr.json";
    File jsonFile;
    jsonFile = new File(jsonFileName);
    final ReportDefinition ret = super.loadDefinition(file, jsonFile);
    ret.setReportType(ReportType.JASPER);

    net.sf.jasperreports.engine.JasperReport jasperReport;
    try {
        jasperReport = (net.sf.jasperreports.engine.JasperReport) JRLoader.loadObject(compileIfRequired(file));
    } catch (JRException ex) {
        throw new ReportException(ex);
    }
    for (JRParameter param : jasperReport.getParameters()) {
        if (!param.isForPrompting() || param.isSystemDefined()) {
            continue;
        }
        ReportParam rp = new ReportParam(param.getValueClass());
        rp.setName(param.getName());
        if (param.getDefaultValueExpression() != null
                && StringUtils.isNotBlank(param.getDefaultValueExpression().getText())) {
            // FIXME alttaki deer script olabilir altrlmas gerekebilir
            String raw = StringUtils.strip(param.getDefaultValueExpression().getText(), "\"");
            if (param.getValueClass().equals(Long.class))
                raw = StringUtils.stripEnd(raw, "Ll");
            rp.setDefaultValue(Convert.to(raw, param.getValueClass()));
        }
        rp.setLabel(param.getName());
        ret.getReportParams().add(rp);
    }

    return ret;
}

From source file:au.org.ands.vocabs.toolkit.utils.ToolkitFileUtils.java

/** Apply slug conventions. In practice, this means
 * (a) replacing punctuation with hyphens,
 * (b) replacing whitespace with hyphen,
 * (c) converting to lowercase,//from  w ww  .ja  v a2 s . c om
 * (d) encoding as a URL,
 * (e) replacing percents with hyphens,
 * (f) coalescing multiple consecutive hyphens into one,
 * (g) removing any leading and trailing hyphens,
 * (h) trimming the result to a maximum length of
 *     MAX_SLUG_COMPONENT_LENGTH,
 * (i) removing any remaining trailing hyphen.
 * @param aString The string that is to be converted.
 * @return The value of aString with slug conventions applied.
 */
public static String makeSlug(final String aString) {
    String slug = StringUtils.strip(
            UriComponent.encode(aString.replaceAll("\\p{Punct}", "-").replaceAll("\\s", "-").toLowerCase(),
                    UriComponent.Type.PATH_SEGMENT).replaceAll("%", "-").replaceAll("-+", "-"),
            "-");

    return StringUtils.stripEnd(slug.substring(0, Math.min(MAX_SLUG_COMPONENT_LENGTH, slug.length())), "-");
}

From source file:eu.esdihumboldt.hale.io.geoserver.rest.AbstractResourceManager.java

private String normalizeUrlPart(String urlPart) {
    // remove slashes at the beginning and end of the URL part
    // and return null if it empty or contains only whitespace
    urlPart = StringUtils.stripStart(urlPart, "/");
    urlPart = StringUtils.stripEnd(urlPart, "/");
    return StringUtils.defaultIfBlank(urlPart, null);
}

From source file:com.funambol.common.pim.common.Property.java

/**
 * Sets the property value. Blank spaces and tabs will be stripped from its
 * end if it is a string./*  ww w . j  a  v  a2 s  .c o m*/
 *
 * @param propertyValue the property value to set
 */
public void setPropertyValue(Object propertyValue) {

    if (propertyValue instanceof String) {
        this.propertyValue = StringUtils.stripEnd((String) propertyValue, " \t");
    } else {
        this.propertyValue = propertyValue;
    }
}

From source file:eu.carrade.amaury.BallsOfSteel.game.BoSGameManager.java

/**
 * Used to broadcast the amount of diamonds lost (if any).
 */// w w  w  .j  av a  2  s  .c  o  m
@EventHandler
public void onPlayerDeath(final PlayerDeathEvent ev) {
    if (ev.getKeepInventory())
        return;

    int diamondsCount = 0;
    for (final ItemStack item : ev.getEntity().getInventory()) {
        if (item == null)
            continue;

        switch (item.getType()) {
        case DIAMOND:
        case DIAMOND_ORE:
            diamondsCount += item.getAmount();
            break;

        case DIAMOND_BLOCK:
            diamondsCount += 9 * item.getAmount();
            break;
        }
    }

    if (diamondsCount > 0) {
        ev.setDeathMessage(StringUtils.stripEnd(ev.getDeathMessage(), null)
                + (ev.getDeathMessage().endsWith(".") ? "" : ".") + " "
                + I.tn("{gray}{0} diamond lost.", "{gray}{0} diamonds lost.", diamondsCount));
    }
}

From source file:com.adobe.acs.tools.tag_maker.impl.TagMakerServlet.java

private InputStream stripLineEnds(InputStream is, String charset, char chartoStrip) throws IOException {
    log.debug("Stripping [ {} ] from the end of lines.", chartoStrip);

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final PrintStream printStream = new PrintStream(baos);

    final LineIterator lineIterator = IOUtils.lineIterator(is, charset);

    while (lineIterator.hasNext()) {
        String line = StringUtils.stripToNull(lineIterator.next());
        if (line != null) {
            line = StringUtils.stripEnd(line, String.valueOf(chartoStrip));
            printStream.println(line);/*  w w  w  .j  a v a2s.  c  o m*/
        }
    }

    return new ByteArrayInputStream(baos.toByteArray());
}