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

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

Introduction

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

Prototype

public static String replace(String text, String searchString, String replacement) 

Source Link

Document

Replaces all occurrences of a String within another String.

Usage

From source file:com.haulmont.cuba.gui.components.filter.condition.CustomCondition.java

public CustomCondition(AbstractConditionDescriptor descriptor, String where, String join, String entityAlias,
        boolean inExpr) {
    super(descriptor);
    this.entityAlias = entityAlias;
    this.join = join;
    this.text = where;
    this.inExpr = inExpr;
    //re-create param because at this moment we have a correct value of inExpr
    param = AppBeans.get(ConditionParamBuilder.class).createParam(this);
    if (param != null)
        text = StringUtils.replace(text, "?", ":" + param.getName());
}

From source file:com.marvelution.hudson.plugins.apiv2.listeners.JobActivityCacheItemListener.java

/**
 * {@inheritDoc}//from  w w w .  j  a v  a2s  . c  o  m
 */
@Override
public void onRenamed(Item item, String oldName, String newName) {
    String newFullName, oldFullName;
    if (item.getParent().getFullName().length() == 0) {
        newFullName = newName;
        oldFullName = oldName;
    } else {
        newFullName = item.getParent().getFullName() + "/" + newName;
        oldFullName = item.getParent().getFullName() + "/" + oldName;
    }
    Collection<ActivityCache> toBeRemoved = Lists.newArrayList();
    Collection<ActivityCache> toBeAdded = Lists.newArrayList();
    for (ActivityCache cache : APIv2Plugin.getActivitiesCache()) {
        ActivityCache newCache = null;
        if (oldFullName.equals(cache.getJob())) {
            newCache = getRenamedJobActivityCache(cache, newFullName);
        } else if (oldFullName.equals(cache.getParent())) {
            newCache = getRenamedJobActivityCache(cache,
                    StringUtils.replace(cache.getJob(), oldFullName, newFullName));
            newCache.setParent(newFullName);
        }
        if (newCache != null && !cache.equals(newCache)) {
            toBeRemoved.add(cache);
            toBeAdded.add(newCache);
        }
    }
    APIv2Plugin.getActivitiesCache().removeAll(toBeRemoved);
    APIv2Plugin.getActivitiesCache().addAll(toBeAdded);
}

From source file:de.thischwa.pmcms.tool.image.Dimension.java

/**
 * Grab the {@link Dimension} from the attributes of an img-tag. If height/width attribute doesn't exists, the style attribute will be
 * scanned./*from   w  w w  .j a  va2s .c o  m*/
 * 
 * @param attr {@link Map} of the attributes of the img-tag. The key is the name of the attribute.
 * @return {@link Dimension} grabbed from the attributes of an img-tag.
 * @throws IllegalArgumentException If the {@link Dimension} can't grab from the attributes. 
 */
public static Dimension getDimensionFromAttr(Map<String, String> attr) throws IllegalArgumentException {
    String heightStr = attr.get("height");
    String widthStr = attr.get("width");
    if (heightStr != null && widthStr != null)
        return new Dimension(Integer.parseInt(widthStr), Integer.parseInt(heightStr));

    if (StringUtils.isBlank(attr.get("style")))
        throw new IllegalArgumentException("Couldn't get the dimension from img-tag attributes!");
    String style = StringUtils.replace(attr.get("style"), " ", "");
    int height = -1;
    int width = -1;

    Matcher matcher = styleHeightPattern.matcher(style);
    if (matcher.matches())
        height = Integer.parseInt(matcher.group(1));

    matcher = styleWidthPattern.matcher(style);
    if (matcher.matches())
        width = Integer.parseInt(matcher.group(1));

    if (width == -1 || height == -1)
        throw new IllegalArgumentException("Couldn't get the dimension from style-attribute!");
    return new Dimension(width, height);
}

From source file:com.adguard.compiler.LocaleUtils.java

public static void convertFromChromeToFirefoxLocales(File chromeLocalesDir) throws IOException {

    for (File file : chromeLocalesDir.listFiles()) {

        File chromeLocaleFile = new File(file, "messages.json");
        if (!SupportedLocales.supported(file.getName())) {
            FileUtils.deleteQuietly(file);
            continue;
        }//from   www.  j a  v a  2s .c  o  m

        String firefoxLocale = StringUtils.replace(file.getName(), "_", "-");
        File appLocaleFile = new File(chromeLocalesDir, firefoxLocale + ".properties");

        byte[] content = FileUtils.readFileToByteArray(chromeLocaleFile);
        Map map = objectMapper.readValue(content, Map.class);
        StringBuilder sb = new StringBuilder();
        for (Object key : map.keySet()) {
            String message = (String) ((Map) map.get(key)).get("message");
            message = message.replaceAll("\n", "\\\\n");
            sb.append(key).append("=").append(message);
            sb.append(System.lineSeparator());
        }
        FileUtils.writeStringToFile(appLocaleFile, sb.toString(), "utf-8");
        FileUtils.deleteQuietly(file);
    }
}

From source file:gov.nih.nci.protexpress.ui.validators.HibernateValidator.java

@SuppressWarnings("unchecked")
private void validateObject(String fieldName, Object o) {
    if (o == null) {
        LOG.warn("The visited object is null, VisitorValidator will not be able to handle validation properly. "
                + "Please make sure the visited object is not null for VisitorValidator to function properly");
        return;//  w w  w .java2  s  .co  m
    }

    ContextualClassValidator classValidator = CLASS_VALIDATOR_MAP.get(o.getClass());
    if (classValidator == null) {
        classValidator = new ContextualClassValidator(o.getClass());
        CLASS_VALIDATOR_MAP.put(o.getClass(), classValidator);
    }
    InvalidValue[] validationMessages = classValidator.getInvalidValues(o);

    if (validationMessages.length > 0) {
        for (InvalidValue message : validationMessages) {
            String errorField = fieldName;
            String msg = message.getMessage();
            if (StringUtils.isNotBlank(message.getPropertyPath())) {
                errorField = fieldName + "." + message.getPropertyPath();
                msg = StringUtils.replace(msg, "fieldName", "\"" + errorField + "\"");
            }
            ValueStack stack = ActionContext.getContext().getValueStack();
            msg = TextParseUtil.translateVariables(msg, stack);
            getValidatorContext().addFieldError(errorField, msg);
        }
    }
}

From source file:com.echosource.ada.core.AdaFile.java

/**
 * Returns a AdaFile if the given file is a php file and can be found in the given directories. This instance will be initialized with
 * inferred attribute values/* w ww  .j av  a 2s .c o  m*/
 * 
 * @param file
 *          the file to load
 * @param isUnitTest
 *          if <code>true</code> the given resource will be marked as a unit test, otherwise it will be marked has a class
 * @param dirs
 *          the dirs
 * @return the php file
 */
public static AdaFile fromIOFile(File file, List<File> dirs, boolean isUnitTest) {
    // If the file has a valid suffix
    if (file == null || !Ada.INSTANCE.hasValidSuffixes(file.getName())) {
        return null;
    }
    String relativePath = DefaultProjectFileSystem.getRelativePath(file, dirs);
    // and can be found in the given directories
    if (relativePath != null) {
        String packageName = null;
        String className = relativePath;

        if (relativePath.indexOf('/') >= 0) {
            packageName = StringUtils.substringBeforeLast(relativePath, PATH_SEPARATOR);
            packageName = StringUtils.replace(packageName, PATH_SEPARATOR, PACKAGE_SEPARATOR);
            className = StringUtils.substringAfterLast(relativePath, PATH_SEPARATOR);
        }
        String extension = PACKAGE_SEPARATOR + StringUtils.substringAfterLast(className, PACKAGE_SEPARATOR);
        // className = StringUtils.substringBeforeLast(className, PACKAGE_SEPARATOR);
        return new AdaFile(packageName, className, extension, isUnitTest);
    }
    return null;
}

From source file:com.marvelution.jira.plugins.hudson.utils.ChangelogAnnotator.java

/**
 * Annotate the Changelog given/*from  ww  w.ja  v a2  s  .  co  m*/
 * 
 * @param jiraBaseUrl the JIRA base URL
 * @param changelog the changelog to annotate
 * @return the annotated changelog
 */
public String annotate(String jiraBaseUrl, String changelog) {
    Pattern pattern = Pattern
            .compile("\\b((" + getProperty(APKeys.JIRA_PROJECTKEY_PATTERN) + ")-([1-9][0-9]*))\\b");
    Matcher matcher = pattern.matcher(changelog);
    while (matcher.find()) {
        String issueKey = matcher.group();
        if (issueManager.getIssueObject(issueKey) != null) {
            changelog = StringUtils.replace(changelog, issueKey,
                    String.format("<a href=\"%1$s/browse/%2$s\">%2$s</a>", jiraBaseUrl, issueKey));
        }
    }
    return changelog;
}

From source file:com.sk89q.craftbook.util.ICUtil.java

public static void parseSignFlags(LocalPlayer player, ChangedSign sign) {

    for (int i = 2; i < 4; i++) {

        if (sign.getLine(i).contains("[off]")) {

            if (CraftBookPlugin.plugins.getWorldEdit() == null) {
                sign.setLine(i, StringUtils.replace(sign.getLine(i), "[off]", ""));
                player.printError("worldedit.ic.notfound");
            } else {
                if (CraftBookPlugin.plugins.getWorldEdit()
                        .getSelection(((BukkitPlayer) player).getPlayer()) != null
                        && CraftBookPlugin.plugins.getWorldEdit()
                                .getSelection(((BukkitPlayer) player).getPlayer())
                                .getRegionSelector() != null) {

                    RegionSelector selector = CraftBookPlugin.plugins.getWorldEdit()
                            .getSelection(((BukkitPlayer) player).getPlayer()).getRegionSelector();

                    try {
                        if (selector instanceof CuboidRegionSelector) {

                            Vector centre = selector.getRegion().getMaximumPoint()
                                    .add(selector.getRegion().getMinimumPoint());

                            centre = centre.divide(2);

                            Vector offset = centre.subtract(sign.getBlockVector());

                            String x, y, z;

                            x = Double.toString(offset.getX());
                            if (x.endsWith(".0"))
                                x = StringUtils.replace(x, ".0", "");

                            y = Double.toString(offset.getY());
                            if (y.endsWith(".0"))
                                y = StringUtils.replace(y, ".0", "");

                            z = Double.toString(offset.getZ());
                            if (z.endsWith(".0"))
                                z = StringUtils.replace(z, ".0", "");

                            sign.setLine(i,
                                    StringUtils.replace(sign.getLine(i), "[off]", "&" + x + ":" + y + ":" + z));
                        } else if (selector instanceof SphereRegionSelector) {

                            Vector centre = ((SphereRegionSelector) selector).getRegion().getCenter();

                            Vector offset = centre.subtract(sign.getBlockVector());

                            String x, y, z;

                            x = Double.toString(offset.getX());
                            if (x.endsWith(".0"))
                                x = StringUtils.replace(x, ".0", "");

                            y = Double.toString(offset.getY());
                            if (y.endsWith(".0"))
                                y = StringUtils.replace(y, ".0", "");

                            z = Double.toString(offset.getZ());
                            if (z.endsWith(".0"))
                                z = StringUtils.replace(z, ".0", "");

                            sign.setLine(i,
                                    StringUtils.replace(sign.getLine(i), "[off]", "&" + x + ":" + y + ":" + z));
                        } else { // Unsupported.
                            sign.setLine(i, StringUtils.replace(sign.getLine(i), "[off]", ""));
                            player.printError("worldedit.ic.unsupported");
                        }//from ww  w  . j av a  2  s .  com
                    } catch (IncompleteRegionException e) {
                        player.printError("worldedit.ic.noselection");
                    }
                } else {
                    player.printError("worldedit.ic.noselection");
                }
            }
        }

        if (sign.getLine(i).contains("[rad]")) {

            if (CraftBookPlugin.plugins.getWorldEdit() == null) {
                sign.setLine(i, StringUtils.replace(sign.getLine(i), "[rad]", ""));
                player.printError("worldedit.ic.notfound");
            } else {

                if (CraftBookPlugin.plugins.getWorldEdit()
                        .getSelection(((BukkitPlayer) player).getPlayer()) != null
                        && CraftBookPlugin.plugins.getWorldEdit()
                                .getSelection(((BukkitPlayer) player).getPlayer())
                                .getRegionSelector() != null) {

                    RegionSelector selector = CraftBookPlugin.plugins.getWorldEdit()
                            .getSelection(((BukkitPlayer) player).getPlayer()).getRegionSelector();

                    try {
                        if (selector instanceof CuboidRegionSelector) {

                            String x, y, z;

                            x = Double.toString(Math.abs(selector.getRegion().getMaximumPoint().getX()
                                    - selector.getRegion().getMinimumPoint().getX()) / 2);
                            if (x.endsWith(".0"))
                                x = StringUtils.replace(x, ".0", "");

                            y = Double.toString(Math.abs(selector.getRegion().getMaximumPoint().getY()
                                    - selector.getRegion().getMinimumPoint().getY()) / 2);
                            if (y.endsWith(".0"))
                                y = StringUtils.replace(y, ".0", "");

                            z = Double.toString(Math.abs(selector.getRegion().getMaximumPoint().getZ()
                                    - selector.getRegion().getMinimumPoint().getZ()) / 2);
                            if (z.endsWith(".0"))
                                z = StringUtils.replace(z, ".0", "");

                            sign.setLine(i,
                                    StringUtils.replace(sign.getLine(i), "[rad]", x + "," + y + "," + z));
                        } else if (selector instanceof SphereRegionSelector) {

                            String x;

                            double amounts = ((EllipsoidRegion) selector.getRegion()).getRadius().getX();

                            x = Double.toString(amounts);
                            if (x.endsWith(".0"))
                                x = StringUtils.replace(x, ".0", "");

                            sign.setLine(i, StringUtils.replace(sign.getLine(i), "[rad]", x));
                        } else { // Unsupported.
                            sign.setLine(i, StringUtils.replace(sign.getLine(i), "[rad]", ""));
                            player.printError("worldedit.ic.unsupported");
                        }
                    } catch (IncompleteRegionException e) {
                        player.printError("worldedit.ic.noselection");
                    }
                } else {
                    player.printError("worldedit.ic.noselection");
                }
            }
        }
    }

    sign.update(false);
}

From source file:adalid.commons.util.FilUtils.java

public static String fixPath(String path) {
    if (StringUtils.isBlank(path)) {
        return null;
    }/*w w  w .  j  a v a 2 s .c o m*/
    String string = StringUtils.replace(path.trim(), "/", FILE_SEP);
    String replacement = workspace_folder_path.replace("\\", "\\\\");
    for (String workspace_folder_key : workspace_folder_keys) {
        string = string.replaceAll(workspace_folder_key, replacement);
    }
    return string;
}

From source file:com.github.dbourdette.glass.log.joblog.JobLog.java

public String getFormattedStackTrace() {
    String html = StringEscapeUtils.escapeHtml(stackTrace);

    html = StringUtils.replace(html, "\n", "<br/>");
    html = StringUtils.replace(html, "\t", "&nbsp;&nbsp;&nbsp;");

    return html;//from  w w  w.  ja  va2  s  .c om
}