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

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

Introduction

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

Prototype

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

Source Link

Document

Overlays part of a String with another String.

Usage

From source file:com.ewcms.content.resource.service.ResourceService.java

/**
 * Uri/*from  w  w  w  .  j  a v  a 2s . co m*/
 * 
 * @param uri ???
 * @return
 */
String getThumbUri(String uri) {
    int index = StringUtils.lastIndexOf(uri, '.');
    if (index == -1) {
        return uri + getThumbSuffix();
    } else {
        return StringUtils.overlay(uri, getThumbSuffix(), index, index);
    }
}

From source file:com.googlecode.l10nmavenplugin.validators.property.SpellCheckValidator.java

/**
 * WARN in case of spellcheck error using property locale.
 *///from   w w  w  .j a  v  a  2 s.  c  o  m
public int validate(Property property, List<L10nReportItem> reportItems) {
    Locale locale = property.getLocale();
    if (locale == null) {
        // Case of root bundle
        locale = Locale.ENGLISH;
    }
    SpellChecker spellChecker = spellCheckerLocaleRepository.getSpellChecker(locale);

    if (spellChecker != null) {
        ListSpellCheckErrorListener listener = new ListSpellCheckErrorListener(spellChecker);
        spellChecker.addSpellCheckListener(listener);

        String message = property.getMessage();
        spellChecker.checkSpelling(new StringWordTokenizer(message));

        Collection<SpellCheckError> errors = listener.getSpellCheckErrors();

        // The message with errors replaced by suggestions
        String correction = message;

        // Start from last errors, so that error position remains valid
        SpellCheckError[] errs = errors.toArray(new SpellCheckError[errors.size()]);
        for (int i = errs.length - 1; i >= 0; i--) {
            SpellCheckError error = errs[i];
            if (error.getSuggestion() != null) {
                int pos = error.getPosition();
                correction = StringUtils.overlay(correction, error.getSuggestion(), pos,
                        pos + error.getError().length());
            }
        }

        if (errors.size() > 0) {
            StringBuffer sb = new StringBuffer();
            sb.append("Spellcheck error on word(s): ").append(errors.toString()).append(" and locale <")
                    .append(locale).append(">.");
            if (correction != null) {
                sb.append(" Suggested correction: [").append(correction).append("]");
            }

            L10nReportItem reportItem = new L10nReportItem(Type.SPELLCHECK, sb.toString(), property, null);
            reportItems.add(reportItem);
            logger.log(reportItem);
        }

        spellChecker.removeSpellCheckListener(listener);
    }
    return 0;
}

From source file:org.mili.core.io.RevisionUtil.java

/**
 * Insert revision.//ww w.  ja v  a  2 s  . c o m
 *
 * @param filenameWithoutMinus the filename without minus
 * @param revisionNumber the revision number
 * @param usePattern the use pattern
 * @param revisionPrefix the revision prefix
 * @return filename with revision
 */
static String insertRevision(String filenameWithoutMinus, int revisionNumber, boolean usePattern,
        String revisionPrefix) {
    Validate.notEmpty(filenameWithoutMinus, "filename cannot be empty!");
    Validate.isTrue(revisionNumber > 0, "revision cannot be <= 0!");
    Validate.notNull(revisionPrefix, "revision prefix cannot be null!");
    String rev = String.valueOf(revisionNumber);
    if (usePattern) {
        rev = StringUtils.overlay(REV_PATTERN, rev, REV_PATTERN.length() - rev.length(), REV_PATTERN.length());
    }
    if (revisionPrefix.length() > 0) {
        rev = revisionPrefix + rev;
    }
    return filenameWithoutMinus.replaceAll("^(.*)\\.(.*)$", "$1-".concat(rev).concat(".$2"));
}

From source file:ummisco.gama.ui.views.GamaViewPart.java

@Override
public void changePartNameWithSimulation(final SimulationAgent agent) {
    final String old = getPartName();
    final int first = old.lastIndexOf('(');
    final int second = old.lastIndexOf(')');
    if (first == -1) {
        if (agent.getPopulation().size() > 1) {
            setPartName(old + " (" + agent.getName() + ")");
        }/*from ww w.j a v a  2 s. c om*/
    } else {

        setPartName(StringUtils.overlay(old, agent.getName(), first + 1, second));
    }
}