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

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

Introduction

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

Prototype

public static String replaceChars(String str, String searchChars, String replaceChars) 

Source Link

Document

Replaces multiple characters in a String in one go.

Usage

From source file:org.jahia.services.search.jcr.JahiaJCRSearchProvider.java

private void addTermConstraints(SearchCriteria params, StringBuilder constraints, boolean xpath) {

    for (Term textSearch : params.getTerms()) {

        if (!textSearch.isEmpty()) {
            String searchExpression = getSearchExpressionForMatchType(textSearch.getTerm(),
                    textSearch.getMatch(), textSearch.isApplyFilter());

            SearchFields searchFields = textSearch.getFields();
            StringBuilder textSearchConstraints = new StringBuilder(256);
            if (searchFields.isSiteContent() || (!searchFields.isTags() && !searchFields.isFileContent()
                    && !searchFields.isDescription() && !searchFields.isTitle() && !searchFields.isKeywords()
                    && !searchFields.isFilename())) {
                addConstraint(textSearchConstraints, OR, xpath ? ("jcr:contains(., " + searchExpression + ")")
                        : ("contains(n, " + searchExpression + ")"));
            }//  w  w  w  . j a  v a  2s. com
            if (searchFields.isFileContent()) {
                if (xpath) {
                    addConstraint(textSearchConstraints, OR,
                            "jcr:contains(jcr:content," + searchExpression + ")");
                } else {
                    addConstraint(textSearchConstraints, OR,
                            getContainsExpr("jcr:content", searchExpression, xpath));
                }
            }
            if (searchFields.isDescription()) {
                addConstraint(textSearchConstraints, OR,
                        getContainsExpr(Constants.JCR_DESCRIPTION, searchExpression, xpath));
            }
            if (searchFields.isTitle()) {
                addConstraint(textSearchConstraints, OR,
                        getContainsExpr(Constants.JCR_TITLE, searchExpression, xpath));
            }
            if (searchFields.isKeywords()) {
                addConstraint(textSearchConstraints, OR,
                        getContainsExpr(Constants.KEYWORDS, searchExpression, xpath));
            }

            String[] terms = null;
            String constraint = "or";
            if (searchFields.isFilename() || searchFields.isTags()) {
                if (textSearch.getMatch() == MatchType.ANY_WORD || textSearch.getMatch() == MatchType.ALL_WORDS
                        || textSearch.getMatch() == MatchType.WITHOUT_WORDS) {
                    terms = Patterns.SPACE.split(cleanMultipleWhiteSpaces(textSearch.getTerm()));
                    if (textSearch.getMatch() == MatchType.ALL_WORDS
                            || textSearch.getMatch() == MatchType.WITHOUT_WORDS) {
                        constraint = AND;
                    }
                } else {
                    terms = new String[] { textSearch.getTerm() };
                }
            }
            if (searchFields.isFilename()) {
                StringBuilder nameSearchConstraints = new StringBuilder(256);
                for (String term : terms) {
                    final String likeTerm = term.contains("*")
                            ? stringToQueryLiteral(StringUtils.replaceChars(term, '*', '%'))
                            : stringToQueryLiteral("%" + term + "%");
                    String termConstraint = xpath ? ("jcr:like(fn:name(), " + likeTerm + ")")
                            : ("localname(n) like " + likeTerm);
                    if (textSearch.getMatch() == MatchType.WITHOUT_WORDS) {
                        termConstraint = "not(" + termConstraint + ")";
                    }
                    addConstraint(nameSearchConstraints, constraint, termConstraint);
                }
                addConstraint(textSearchConstraints, OR, nameSearchConstraints.toString());
            }
            if (searchFields.isTags() && getTaggingService() != null
                    && (params.getSites().getValue() != null || params.getOriginSiteKey() != null)
                    && !StringUtils.containsAny(textSearch.getTerm(), "?*")) {
                for (String term : terms) {
                    String tag = taggingService.getTagHandler().execute(term);
                    if (!StringUtils.isEmpty(tag)) {
                        addConstraint(textSearchConstraints, OR,
                                getPropertyName("j:tagList", xpath) + "=" + stringToJCRSearchExp(tag));
                    }
                }
                if (terms.length > 1) {
                    String tag = taggingService.getTagHandler().execute(textSearch.getTerm());
                    if (!StringUtils.isEmpty(tag)) {
                        addConstraint(textSearchConstraints, OR,
                                getPropertyName("j:tagList", xpath) + "=" + stringToJCRSearchExp(tag));
                    }
                }
            }
            if (textSearchConstraints.length() > 0) {
                addConstraint(constraints, AND, "(" + textSearchConstraints.toString() + ")");
            }
        }
    }
}

From source file:org.jahia.services.search.jcr.JahiaJCRSearchProvider.java

private String getMimeTypeConstraint(String mimeType, boolean xpath) {
    if (xpath) {//from ww  w  .j a v a 2 s  .c o m
        return mimeType.contains("*")
                ? "jcr:like(jcr:content/@jcr:mimeType,"
                        + stringToQueryLiteral(StringUtils.replaceChars(mimeType, '*', '%')) + ")"
                : "jcr:content/@jcr:mimeType=" + stringToQueryLiteral(mimeType);
    } else {
        return "n.[jcr:mimetype]=" + stringToQueryLiteral(mimeType);
    }

}

From source file:org.jahia.services.templates.JahiaTemplateManagerService.java

/**
 * Returns a set of all available template packages having templates for a module.
 *
 * @return a set of all available template packages
 *//*from w  ww .j a v a 2  s  .c  o m*/
public Set<JahiaTemplatesPackage> getModulesWithViewsForComponent(String componentName) {
    Set<JahiaTemplatesPackage> r = templatePackageRegistry.getModulesWithViewsPerComponents()
            .get(StringUtils.replaceChars(componentName, ':', '_'));
    return r != null ? r : Collections.<JahiaTemplatesPackage>emptySet();
}

From source file:org.jahia.tools.patches.GroovyPatcher.java

public void initAfterAllServicesAreStarted() throws JahiaInitializationException {
    if (!SettingsBean.getInstance().isProcessingServer()) {
        logger.info("Script watchdog is disabled on a non-processing Jahia server");
        return;//www.  jav a 2 s  .com
    }

    if (interval > 5000 && SettingsBean.getInstance().isDevelopmentMode()) {
        // in development mode reduce monitoring interval to 5 seconds
        interval = 5000;
    }

    if (interval <= 0) {
        logger.info("The interval for the Groovy patcher is <= 0. Skip starting file watcher.");
        return;
    }

    if (patchesLookup == null) {
        File patchesFolder = getPatchesFolder(servletContext);
        if (patchesFolder != null) {
            String absolutePath = patchesFolder.getAbsolutePath();
            absolutePath = StringUtils.replaceChars(absolutePath, '\\', '/');
            absolutePath = StringUtils.replace(absolutePath, " ", "%20");
            patchesLookup = "file://" + absolutePath + "/**/*.groovy";
        }
    }

    if (StringUtils.isEmpty(patchesLookup)) {
        logger.info("The patches lookup path is not set. Skip starting file watcher.");
        return;
    }

    try {
        if (getEngine() == null) {
            logger.error("The Groovy engine is not evailable. Skip starting file watcher.");
            return;
        }
    } catch (ScriptException e) {
        throw new JahiaInitializationException(e.getMessage(), e);
    }

    // execute scripts right now
    perform();

    // start watchdog for monitoring
    watchdog = new Timer(true);
    watchdog.schedule(new TimerTask() {
        @Override
        public void run() {
            perform();
        }
    }, 0, interval);
}

From source file:org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.java

private static String computeUniqueInstanceId(Configuration config) {
    final String suffix;

    if (config.has(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID_SUFFIX)) {
        suffix = LongEncoding.encode(config.get(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID_SUFFIX));
    } else {/* www .  ja v a2 s .  co  m*/
        suffix = ManagementFactory.getRuntimeMXBean().getName()
                + LongEncoding.encode(INSTANCE_COUNTER.incrementAndGet());
    }

    byte[] addrBytes;
    try {
        addrBytes = Inet4Address.getLocalHost().getAddress();
    } catch (UnknownHostException e) {
        throw new JanusGraphConfigurationException("Cannot determine local host", e);
    }
    String uid = new String(Hex.encodeHex(addrBytes)) + suffix;
    for (char c : ConfigElement.ILLEGAL_CHARS) {
        uid = StringUtils.replaceChars(uid, c, '-');
    }
    return uid;
}

From source file:org.janusgraph.graphdb.idmanagement.UniqueInstanceIdRetriever.java

private String computeUniqueInstanceId(Configuration config) {
    final String suffix = getSuffix(config);
    final String uid = getUid(config);
    String instanceId = uid + suffix;
    for (char c : ConfigElement.ILLEGAL_CHARS) {
        instanceId = StringUtils.replaceChars(instanceId, c, '-');
    }/*from w w w  .ja v  a 2 s  .  co  m*/
    return instanceId;
}

From source file:org.jlibrary.core.search.extraction.html.HTMLRipper.java

private String cleanString(String source) {

    source = StringUtils.replaceChars(source, '?', '_');
    source = StringUtils.replaceChars(source, '&', '_');

    return source;
}

From source file:org.jrimum.utilix.text.Field.java

/**
 * <p>/* ww w .j a v a 2s  . co m*/
 * Escreve o campo no formato e tamanho especificado.
 * </p>
 * 
 * @see TextStream#write()
 * 
 * @return campo escrito
 * @since 0.2
 */
public String write() {

    String str = null;

    if (value instanceof TextStream) {

        TextStream its = (TextStream) value;

        str = its.write();

    } else if (value instanceof Date) {

        Date campoDate = (Date) value;

        if (Dates.equalsInvalidDate(campoDate)) {

            str = StringUtils.EMPTY;

        } else {
            str = format.format(value);
        }

    } else if (value instanceof BigDecimal) {
        str = StringUtils.replaceChars(value.toString(), ".", StringUtils.EMPTY);

    } else {
        str = value.toString();
    }

    str = fill(str);

    if (str.length() != length) {
        throw new IllegalArgumentException(
                "O tamaho do campo [ " + str + " ]  incompatvel com o especificado [" + length + "]!");
    }

    return Strings.eliminateAccent(str).toUpperCase();
}

From source file:org.jrimum.vallia.digitoverificador.BoletoLinhaDigitavelDV.java

/**
 * @see org.jrimum.vallia.digitoverificador.AbstractDigitoVerificador#calcule(java.lang.String)
 * @since 0.2//w  w w .  j av a2  s .  co  m
 */
@Override
public int calcule(String numero) throws IllegalArgumentException {

    int dv = 0;
    int resto = 0;

    if (StringUtils.isNotBlank(numero) && Pattern.matches(REGEX_CAMPO, numero)) {

        numero = StringUtils.replaceChars(numero, ".", "");

        resto = modulo10.calcule(numero);

        if (resto != 0) {
            dv = modulo10.valor() - resto;
        }
    } else {
        throw new IllegalArgumentException(
                "O campo [" + numero + "] da linha digitvel deve conter apenas nmeros com 9 ou 10 dgitos "
                        + "ou nos formatos [#####.####, #####.#####]");
    }

    return dv;
}

From source file:org.jrimum.vallia.digitoverificador.CNPJDV.java

/**
 * Mtodo null-safe que remove a formatao da String, com a inteno de deixar
 * apenas nmeros.//from   w w  w .  j a  va 2 s .c  o  m
 * 
 * @param numero - CNPJ que pode estar formatado.
 * @return Nmero CNPJ sem formatao.
 */
private String removaFormatacao(String numero) {

    numero = StringUtils.replaceChars(numero, ".", "");
    numero = StringUtils.replaceChars(numero, "/", "");

    return numero;
}