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

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

Introduction

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

Prototype

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

Source Link

Document

Replaces all occurrences of a String within another String.

A null reference passed to this method is a no-op.

 StringUtils.replace(null, *, *)        = null StringUtils.replace("", *, *)          = "" StringUtils.replace("any", null, *)    = "any" StringUtils.replace("any", *, null)    = "any" StringUtils.replace("any", "", *)      = "any" StringUtils.replace("aba", "a", null)  = "aba" StringUtils.replace("aba", "a", "")    = "b" StringUtils.replace("aba", "a", "z")   = "zbz" 

Usage

From source file:at.bitfire.davdroid.log.PlainTextFormatter.java

private String shortClassName(String className) {
    String s = StringUtils.replace(className, "at.bitfire.davdroid.", "");
    return StringUtils.replace(s, "at.bitfire.", "");
}

From source file:com.sonicle.webtop.core.util.IdentifierUtils.java

/**
 * @deprecated use com.sonicle.commons.IdentifierUtils.getUUID instead
 * @return /*  ww  w  .  j  a  va  2s  .  c  o  m*/
 */
@Deprecated
public static synchronized String getUUID(boolean noDashes) {
    String uuid = UUID.randomUUID().toString();
    return (noDashes) ? StringUtils.replace(uuid, "-", "") : uuid;
}

From source file:com.xpn.xwiki.user.impl.xwiki.GroovyAuthServiceImpl.java

protected String getParam(String name, XWikiContext context) {
    String param = "";
    try {//from w w w  . j  a v  a  2 s  . com
        param = context.getWiki().getXWikiPreference(name, context);
    } catch (Exception e) {
    }
    if (param == null || "".equals(param)) {
        try {
            param = context.getWiki()
                    .Param("xwiki.authentication." + StringUtils.replace(name, "groovy_", "groovy."));
        } catch (Exception e) {
        }
    }
    if (param == null)
        param = "";
    return param;
}

From source file:com.hubspot.jinjava.lib.filter.CutFilter.java

@Override
public Object filter(Object object, JinjavaInterpreter interpreter, String... arg) {
    if (arg.length != 1) {
        throw new InterpretException("filter cut expects 1 arg >>> " + arg.length);
    }/* w  ww .j  ava2s .com*/
    String cutee = arg[0];
    String origin = Objects.toString(object, "");
    return StringUtils.replace(origin, cutee, "");
}

From source file:com.school.exam.rest.StudentRestController.java

@RequestMapping(value = "answer", method = RequestMethod.POST, produces = MediaTypes.JSON_UTF_8)
public String answer(@RequestParam(defaultValue = "PM2.5?") String course,
        @RequestParam String title, @RequestParam long userId, @RequestParam(required = false) String answer) {

    Answer answerObj = new Answer();

    if (null != course) {
        course = StringUtils.replace(course, "<br/>", "");
        course = StringUtils.replace(course, " ", "");
    }//from  w w w .j av  a 2 s.  co m
    answerObj.setTitle(title);
    answerObj.setCourse(course);
    answerObj.setAnswer(answer);

    User user = new User();
    user.setId(userId);

    answerObj.setUser(user);

    answerService.save(answerObj);

    return "true";
}

From source file:net.ontopia.topicmaps.nav2.servlets.AutoSuggestServlet.java

private String escape(String s) {
    return StringUtils.replace(StringUtils.replace(s, "\"", "\\\""), "\n", " ");
}

From source file:com.yahoo.maven.visitor.VisitorGenerator.java

public void generate() throws IOException {
    for (Visitor visitor : getVisitors()) {
        String name = visitor.getVisitedName();
        int packageTail = name.lastIndexOf(".");
        String aPackage = packageTail == -1 ? null : name.substring(0, packageTail);
        String disjunctName = packageTail == -1 ? name : name.substring(packageTail + 1, name.length());
        String className = capitalizer.capitalize(disjunctName);
        String dir = aPackage == null ? ""
                : StringUtils.replace(aPackage, ".", FileSystems.getDefault().getSeparator());
        List<TypeParameterContext> typeParameterContexts = new ArrayList<>();
        Set<String> typeParameterNames = new LinkedHashSet<>();
        if (visitor.getTypeParameters() != null) {
            typeParameterContexts.addAll(Arrays.asList(visitor.getTypeParameters()));
            for (TypeParameter typeParameter : visitor.getTypeParameters()) {
                typeParameterNames.add(typeParameter.getName());
            }//from w  w  w  . j  a  va 2s .co m
        }
        List<DisjunctContext> disjuncts = new ArrayList<>();
        for (Disjunction disjunction : visitor.getDisjunctions()) {
            List<ParameterContext> parameterContexts = new ArrayList<>();
            if (disjunction.parameters != null) {
                for (Parameter parameter : disjunction.parameters) {
                    parameterContexts.add(new ParameterContext() {
                        @Override
                        public String getType() {
                            return parameter.type;
                        }

                        @Override
                        public String getName() {
                            return parameter.name;
                        }

                        @Override
                        public String getHashExpression() {
                            switch (getType()) {
                            case "boolean":
                                return "(" + getName() + " ? 1 : 0)";
                            case "char":
                            case "byte":
                            case "short":
                                return "(int) " + getName();
                            case "int":
                                return getName();
                            case "long":
                                return "(int) (" + getName() + " ^ (" + getName() + " >>> 32))";
                            case "float":
                                return "(" + getName() + " != +0.0f ? Float.floatToIntBits(" + getName()
                                        + ") : 0)";
                            case "double":
                                return "(int) (Double.doubleToLongBits(" + getName()
                                        + ") ^ (Double.doubleToLongBits(" + getName() + ") >>> 32))";
                            default:
                                return "(" + getName() + " != null ? " + getName() + ".hashCode() : 0)";
                            }
                        }
                    });
                }
            }
            disjuncts.add(new DisjunctContext() {
                @Override
                public String getMethodName() {
                    return disjunction.name;
                }

                @Override
                public List<ParameterContext> getParameters() {
                    return parameterContexts.isEmpty() ? null : parameterContexts;
                }

                @Override
                public boolean hasAsMethod() {
                    return parameterContexts.size() == 1
                            && !primitives.contains(parameterContexts.get(0).getType());
                }
            });
        }
        class AbstractBaseContext implements BaseContext {
            @Override
            public String getPackage() {
                return aPackage;
            }

            @Override
            public String getVisitedClassName() {
                return className;
            }

            @Override
            public List<TypeParameterContext> getTypeParameters() {
                return typeParameterContexts.isEmpty() ? null : typeParameterContexts;
            }

            @Override
            public List<DisjunctContext> getDisjuncts() {
                return disjuncts.isEmpty() ? null : disjuncts;
            }
        }
        Path outputFolder = getOutputDirectory().resolve(dir);
        File outputFolderAsFile = outputFolder.toFile();
        if (!outputFolderAsFile.mkdirs() && !outputFolderAsFile.exists()) {
            throw new IOException("Unable to make directory: " + outputFolderAsFile.getAbsolutePath());
        }
        try (Writer visitedWriter = Files.newBufferedWriter(outputFolder.resolve(className + ".java"))) {
            class ThisVisitedContext extends AbstractBaseContext implements VisitedContext {
            }
            visitedTemplate.merge(visitedWriter, new ThisVisitedContext());
        }
        try (Writer visitorWriter = Files.newBufferedWriter(outputFolder.resolve(className + "Visitor.java"))) {
            class ThisVisitorContext extends AbstractBaseContext implements VisitorContext {
            }
            visitorTemplate.merge(visitorWriter, new ThisVisitorContext());
        }
        try (Writer visitorWriter = Files
                .newBufferedWriter(outputFolder.resolve("Defaulting" + className + "Visitor.java"))) {
            class ThisDefaultingVisitorContext extends AbstractBaseContext implements DefaultingVisitorContext {
            }
            defaultingVisitorTemplate.merge(visitorWriter, new ThisDefaultingVisitorContext());
        }
        try (Writer visitorWriter = Files
                .newBufferedWriter(outputFolder.resolve("Identity" + className + "Visitor.java"))) {
            class ThisIdentityVisitorContext extends AbstractBaseContext implements IdentityVisitorContext {
            }
            identityVisitorTemplate.merge(visitorWriter, new ThisIdentityVisitorContext());
        }
        try (Writer visitorWriter = Files
                .newBufferedWriter(outputFolder.resolve("DefaultingIdentity" + className + "Visitor.java"))) {
            class ThisIdentityVisitorContext extends AbstractBaseContext
                    implements IdentityVisitorContext, DefaultingVisitorContext {
            }
            defaultingIdentityVisitorTemplate.merge(visitorWriter, new ThisIdentityVisitorContext());
        }
    }
}

From source file:de.micromata.mgc.javafx.FXGuiUtils.java

/**
 * Creates a "safe" CSS Selector from a String. That means replacing all empty spaces with a unqiue value, because
 * spaces in CSS Selectors are interpreted as the beginning of a new selector.
 * /* w w  w. j  a  va 2 s .  com*/
 * @param value value to convert.
 * @return a safe CSS Selector.
 */
public static String cssSafeSelectorId(final String value) {
    return StringUtils.replace(value, " ", "$BLANK$");
}

From source file:com.norconex.commons.wicket.markup.html.chart.jqplot.Point.java

private String convert(Object obj) {
    if (obj == null) {
        return "''";
    }//from  w ww  .j av  a 2  s  . c  o m
    if (Integer.class.isAssignableFrom(obj.getClass())) {
        return Integer.toString((Integer) obj);
    }
    if (Float.class.isAssignableFrom(obj.getClass())) {
        return Float.toString((Float) obj);
    }
    if (Long.class.isAssignableFrom(obj.getClass())) {
        return Long.toString((Long) obj);
    }
    if (Double.class.isAssignableFrom(obj.getClass())) {
        return Double.toString((Double) obj);
    }
    return "'" + StringUtils.replace(obj.toString(), "'", "\\'") + "'";
}

From source file:com.impetus.ankush.common.scripting.impl.ReplaceText.java

public ReplaceText(String targetText, String replacementText, String filePath, boolean createBackUpFile) {
    this.targetText = StringUtils.replace(targetText, "/", "\\/");
    this.replacementText = StringUtils.replace(replacementText, "/", "\\/");
    this.filePath = filePath;
    this.createBackUpFile = createBackUpFile;
    this.password = null;
    this.addSudoOption = false;
}