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

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

Introduction

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

Prototype

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

Source Link

Document

Replaces multiple characters in a String in one go.

Usage

From source file:com.haulmont.cuba.web.widgets.CubaDateField.java

@Override
protected Result<LocalDate> handleUnparsableDateString(String dateString) {
    if (Objects.equals(dateString, StringUtils.replaceChars(getState(false).dateMask, "#U", "__"))) {
        return Result.ok(null);
    }//from  w ww  . jav  a 2  s .  c om

    return Result.error(getParseErrorMessage());
}

From source file:com.sangupta.passcode.PassCode.java

/**
 * Update the set of allowed and required characters based on configuration
 * // w  ww  .  j a  v  a 2s. c  o m
 * @param charset
 *            the character set to be used
 * @param number
 *            the number of times it should be present in password
 * 
 */
private void updateAllowedAndRequired(final String charset, int number) {
    if (number < 0) {
        return;
    }

    if (number == 0) {
        this.allowed = StringUtils.replaceChars(this.allowed, charset, "");
    } else {
        while (number > 0) {
            this.required.add(charset);
            number--;
        }
    }
}

From source file:de.knightsoftnet.validators.rebind.BeanHelper.java

private String makeJavaSafe(final String in) {
    return StringUtils.replaceChars(in, '.', '_');
}

From source file:de.hasait.genesis.base.freemarker.FreemarkerModelWriter.java

public FreemarkerModelWriter() {
    super();/*from w w  w  .java 2  s.  com*/

    _configuration = new Configuration(Configuration.VERSION_2_3_23);
    _configuration.setDefaultEncoding("UTF-8");
    _configuration.setSharedVariable("delegate", new DelegateDirective());
    final String ftlPath = "/" + StringUtils.replaceChars(ModelWriter.class.getPackage().getName(), '.', '/')
            + "/ftl/";
    final ClassTemplateLoader templateLoader = new ClassTemplateLoader(getClass(), ftlPath);
    _configuration.setTemplateLoader(new HeaderFilterTemplateLoader(templateLoader));
}

From source file:com.nesscomputing.log4j.StructuredSyslogAppender.java

@Override
protected void append(final LoggingEvent event) {
    final SyslogIF syslog = getSyslog();
    final SyslogLevel level = SyslogLevel.forValue(event.getLevel().getSyslogEquivalent());

    final String messageId = UUID.randomUUID().toString().replace("-", "");

    final String[] messageLines = StringUtils
            .split((layout != null) ? layout.format(event) : event.getRenderedMessage(), "\n\r");

    for (int i = 0; i < messageLines.length; i++) {
        final Builder<String, String> b = ImmutableMap.builder();
        b.put("l", event.getLoggerName());
        b.put("c", Integer.toString(i));

        if (serviceId != null) {
            b.put("si", serviceId);
        }/*from  w w w .j  a v a 2s.  c  o m*/

        if (serviceConfiguration != null) {
            b.put("sc", serviceConfiguration);
        }

        Object trackToken = event.getMDC("track");
        if (trackToken != null) {
            b.put("t", trackToken.toString());
        }

        Map<String, String> payload = b.build();

        final String threadName = StringUtils.replaceChars(event.getThreadName(), " \t", "");
        final StructuredSyslogMessage structuredMessage = new StructuredSyslogMessage(messageId, threadName,
                ImmutableMap.of(ianaIdentifier, payload), messageLines[i]);
        syslog.log(level, structuredMessage);
    }
}

From source file:com.nridge.connector.common.con_com.crawl.CrawlFollow.java

/**
 * Determines if the name parameter matches the list of URIs
 * to follow. Prior to the lookup, the name will be normalized
 * (e.g. stripped of Window device names and Window backslashes
 * converted to forward slashes).//ww w  .j a  va  2  s . co  m
 *
 * @param aName File name (could be a URL).
 *
 * @return <i>true</i> if it matches, <i>false</i> otherwise.
 */
public boolean isMatchedNormalized(String aName) {
    String pathFileName;
    boolean isNameMatched;
    Logger appLogger = mAppMgr.getLogger(this, "isMatchedNormalized");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    if (StringUtils.isNotEmpty(aName)) {

        /* Prepare the file name for evaluation - strip any device name and replace
        backslashes with forward slashes. */

        if ((aName.length() > 2) && (aName.charAt(1) == StrUtl.CHAR_COLON))
            pathFileName = aName.substring(2);
        else
            pathFileName = aName;

        isNameMatched = isMatched(
                StringUtils.replaceChars(pathFileName, StrUtl.CHAR_BACKSLASH, StrUtl.CHAR_FORWARDSLASH));
    } else
        isNameMatched = false;

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);

    return isNameMatched;
}

From source file:net.eledge.android.europeana.search.model.enums.Country.java

public static Country safeValueOf(String string) {
    if (StringUtils.isNotBlank(string)) {
        string = StringUtils.replaceChars(string, " _", "");
        string = StringUtils.lowerCase(string);
        for (Country c : values()) {
            if (c.hardcoded.equals(string)) {
                return c;
            }//ww w.  j a v  a 2s . c o m
        }
    }
    return null;
}

From source file:com.xpn.xwiki.internal.skin.WikiSkinUtils.java

private Resource<?> getSkinResourceFromDocumentSkin(String resource, XWikiDocument skinDocument, Skin skin) {
    if (skinDocument != null) {
        // Try to find a XWikiSkinFileOverrideClass object
        BaseObject obj = skinDocument.getXObject(
                XWikiSkinFileOverrideClassDocumentInitializer.DOCUMENT_REFERENCE,
                XWikiSkinFileOverrideClassDocumentInitializer.PROPERTY_PATH, resource, false);
        if (obj != null) {
            ObjectPropertyReference reference = new ObjectPropertyReference(
                    XWikiSkinFileOverrideClassDocumentInitializer.PROPERTY_CONTENT, obj.getReference());
            return new ObjectPropertyWikiResource(getPath(reference), skin, reference,
                    skinDocument.getAuthorReference(), this.xcontextProvider,
                    obj.getLargeStringValue(XWikiSkinFileOverrideClassDocumentInitializer.PROPERTY_CONTENT));
        }/*from   www  . j  av a 2  s. co  m*/

        // Try parsing the object property
        BaseProperty<ObjectPropertyReference> property = getSkinResourceProperty(resource, skinDocument);
        if (property != null) {
            ObjectPropertyReference reference = property.getReference();
            return new ObjectPropertyWikiResource(getPath(reference), skin, reference,
                    skinDocument.getAuthorReference(), this.xcontextProvider, (String) property.getValue());
        }

        // Try parsing a document attachment
        // Convert "/" into "." in order to support wiki skin attachments to override some resources located in
        // subdirectories.
        String normalizedResourceName = StringUtils.replaceChars(resource, '/', '.');
        XWikiAttachment attachment = skinDocument.getAttachment(normalizedResourceName);
        if (attachment != null) {
            AttachmentReference reference = attachment.getReference();
            return new AttachmentWikiResource(getPath(reference), skin, reference,
                    attachment.getAuthorReference(), this.xcontextProvider);
        }
    }

    return null;
}

From source file:com.nesscomputing.httpserver.log.syslog.SyslogRequestLog.java

@Override
public void log(final Request request, final Response response) {
    if (syslog == null) {
        return;/*  ww w  .j a  v a  2s.c om*/
    }

    final String requestUri = request.getRequestURI();

    for (String blackListEntry : blackList) {
        if (StringUtils.startsWith(requestUri, blackListEntry)) {
            return;
        }
    }

    final String messageId = UUID.randomUUID().toString().replace("-", "");

    final Map<String, Builder<String, String>> builderMap = Maps.newHashMap();

    final Builder<String, String> logBuilder = ImmutableMap.builder();
    builderMap.put("l@" + ianaIdentifier, logBuilder);

    if (galaxyConfig != null) {
        if (galaxyConfig.getEnv().getAgentId() != null) {
            logBuilder.put("si", galaxyConfig.getEnv().getAgentId());
        }
        if (galaxyConfig.getDeploy().getConfig() != null) {
            logBuilder.put("sc", galaxyConfig.getDeploy().getConfig());
        }
    }

    for (Iterator<String> it = logFields.iterator(); it.hasNext();) {
        // Parse out fields that have parameters e.g. header:X-Trumpet-Track, and print
        final String[] chunks = StringUtils.split(it.next(), ":");

        final LogField field = knownFields.get(chunks[0]);
        if (chunks.length == 1) {
            final Object result = field.log(request, response, null);
            if (result != null) {
                logBuilder.put(field.getShortName(), result.toString());
            }
        } else if (chunks.length == 2) {
            final String fieldName = field.getShortName() + "@" + ianaIdentifier;
            Builder<String, String> subBuilder = builderMap.get(fieldName);
            if (subBuilder == null) {
                subBuilder = new Builder<String, String>();
                builderMap.put(fieldName, subBuilder);
            }
            final String fieldKey = chunks[1].toLowerCase(Locale.ENGLISH).replace("=", "_");
            final Object result = field.log(request, response, chunks[1]);
            if (result != null) {
                subBuilder.put(fieldKey, result.toString());
            }
        }
    }

    final String threadName = StringUtils.replaceChars(Thread.currentThread().getName(), " \t", "");

    final StructuredSyslogMessage structuredMessage = new StructuredSyslogMessage(messageId, threadName,
            Maps.transformValues(builderMap, new Function<Builder<String, String>, Map<String, String>>() {
                @Override
                public Map<String, String> apply(final Builder<String, String> builder) {
                    return builder.build();
                }
            }), null);
    syslog.info(structuredMessage);
}

From source file:de.teamgrit.grit.checking.testing.JavaProjectTester.java

/**
 * Creates the fully qualified name of a class based on its location
 * relative to a base directory./*from   w ww.j  a  v a  2  s. c o m*/
 *
 * @param basePath
 *            the base path
 * @param subPath
 *            the path to the classfile, must be a located bellow basepath
 *            in the directory tree
 * @return the fully name of the class
 */
private String getQuallifiedName(Path basePath, Path subPath) {
    // relative resolution
    String quallifiedName = StringUtils.difference(basePath.toString(), subPath.toString());
    quallifiedName = quallifiedName.substring(1);
    quallifiedName = FilenameUtils.removeExtension(quallifiedName);
    quallifiedName = StringUtils.replaceChars(quallifiedName, '/', '.');

    return quallifiedName;
}