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:org.apache.syncope.fit.core.reference.TestFileAuditAppender.java

@Override
public void initTargetAppender() {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    // get log file path from existing file appender
    RollingRandomAccessFileAppender mainFile = (RollingRandomAccessFileAppender) ctx.getConfiguration()
            .getAppender("mainFile");

    String pathPrefix = mainFile == null
            ? System.getProperty("user.dir") + StringUtils.replace("/target/log", "/", File.separator)
                    + File.separator
            : StringUtils.replace(mainFile.getFileName(), "core.log", StringUtils.EMPTY);

    targetAppender = FileAppender.newBuilder().withName(getTargetAppenderName()).withAppend(true)
            .withFileName(pathPrefix + getTargetAppenderName() + ".log").withLayout(PatternLayout.newBuilder()
                    .withPattern("%d{HH:mm:ss.SSS} %-5level %logger - %msg%n").build())
            .build();/*from ww w .  ja  v a  2s.c  o  m*/
}

From source file:org.apache.syncope.fit.core.reference.TestFileRewriteAuditAppender.java

@Override
public void initTargetAppender() {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);

    // get log file path from existing file appender
    RollingRandomAccessFileAppender mainFile = (RollingRandomAccessFileAppender) ctx.getConfiguration()
            .getAppender("mainFile");
    String pathPrefix = StringUtils.replace(mainFile.getFileName(), "core.log", StringUtils.EMPTY);

    targetAppender = FileAppender.newBuilder().withName(getTargetAppenderName()).withAppend(true)
            .withFileName(pathPrefix + getTargetAppenderName() + ".log").withLayout(PatternLayout.newBuilder()
                    .withPattern("%d{HH:mm:ss.SSS} %-5level %logger - %msg%n").build())
            .build();//  ww w .j ava 2  s  .  co m
}

From source file:org.apache.vxquery.index.IndexDocumentBuilder.java

private void buildIndexItem(String deweyId, String type, String[] result, String parentPath) {
    //Create an Index element
    IndexElement test = new IndexElement(deweyId, type, result[1]);

    String path = test.epath();/* w w w. j a va2  s.c om*/

    path = StringUtils.replace(path, parentPath, "");
    //Parser doesn't like / so paths are saved as name.name....
    String luceneParentPath = parentPath.replaceAll("/", ".");

    if (!type.equals("doc")) {
        path = path.replaceFirst("/", ":");
    } else {
        luceneParentPath = "";
    }
    //Parser doesn't like / so paths are saved as name.name....
    path = path.replaceAll("/", ".");
    //Add this element to the array (they will be added in reverse order.
    String fullItem = luceneParentPath + path + "." + test.type();

    results.add(new ComplexItem(new StringField("item", fullItem, Field.Store.YES), test.id()));
}

From source file:org.asqatasun.rules.domelement.DomElement.java

/**
 * /*from  w  w w .  j  a  v  a2  s.  c  om*/
 * @return the current element raw background color
 */
public String getBgColor() {
    String bgColor = getProperty(BG_COLOR_KEY);
    if (StringUtils.startsWith(bgColor, ALPHA_COLOR_KEY)) {
        float alpha = getAlpha(bgColor);
        if (alpha == 0f) {
            return "rgb(255; 255; 255)";
        } else if (alpha == 1f) {
            return StringUtils.replace(bgColor, ", 0)", ")");
        }
    }
    return bgColor;
}

From source file:org.asqatasun.rules.elementchecker.ElementCheckerImpl.java

/**
 * @param element/*from  ww w.j av a 2  s.  c o  m*/
 * @param attr
 * @return an evidenceElement 
 */
protected EvidenceElement getEvidenceElement(Element element, String attr) {
    EvidenceElement extraEe;
    String attrEE;
    // specific control with xml:lang attribute due to the ':' character
    if (StringUtils.equalsIgnoreCase(attr, AttributeStore.XML_LANG_ATTR)) {
        attrEE = StringUtils.replace(attr, ":", "-");
    } else {
        attrEE = attr;
    }
    if (isElementTextRequested(attr)) {
        extraEe = processRemarkService.getEvidenceElement(attrEE, StringUtils
                .substring(getTextElementBuilder().buildTextFromElement(element), 0, MAX_TEXT_EE_SIZE));
    } else if (isAttributeExternalResource(attr)) {
        extraEe = processRemarkService.getEvidenceElement(attrEE, buildAttributeContent(element, attr, true));
    } else {
        extraEe = processRemarkService.getEvidenceElement(attrEE, buildAttributeContent(element, attr, false));
    }
    return extraEe;
}

From source file:org.asqatasun.rules.elementchecker.ElementCheckerImpl.java

/**
 * @param evidenceKey/*  www . j  a  v a2  s.c o  m*/
 * @param evidenceValue
 * @return an evidenceElement 
 */
protected EvidenceElement getEvidenceElement(String evidenceKey, String evidenceValue) {
    if (StringUtils.equalsIgnoreCase(evidenceKey, AttributeStore.XML_LANG_ATTR)) {
        evidenceKey = StringUtils.replace(evidenceKey, COLON_CHAR, MINUS_CHAR);
    }
    return processRemarkService.getEvidenceElement(evidenceKey, evidenceValue);
}

From source file:org.asqatasun.rules.test.AbstractRuleImplementationTestCase.java

@Override
public String getName() {
    int lastPointIndex = StringUtils.lastIndexOf(ruleImplementationClassName, ".") + 1;
    String className = StringUtils.substring(ruleImplementationClassName, lastPointIndex);
    return StringUtils.replace(className, "Rule", "-");
}

From source file:org.asqatasun.rules.test.PreProcessResultDataServiceMock.java

@Override
public String getPreProcessResultByKeyAndWebResource(String key, WebResource webresource) {
    String path = StringUtils.replace(webresource.getURL(), "html", "json");
    path = StringUtils.replace(path, "file:", "");
    try {//from   ww  w .  j a va2 s.c  o m
        String json = FileUtils.readFileToString(new File(path));
        LOGGER.debug(json);
        return json;
    } catch (IOException ex) {
        LOGGER.warn(ex);
        throw new NoResultException();
    }
}

From source file:org.asqatasun.webapp.orchestrator.AsqatasunOrchestratorImpl.java

/**
 * /* ww  w.  j  a v  a  2  s  .co m*/
 * @param act
 * @param locale
 * @param exception 
 */
private void sendKrashAuditEmail(Act act, Locale locale, Exception exception) {
    ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale);
    String emailFrom = bundle.getString(RECIPIENT_KEY);
    String projectName = getProjectNameFromAct(act);

    if (isAllowedToSendKrashReport && CollectionUtils.isNotEmpty(krashReportMailList)) {
        Set<String> emailToSet = new HashSet<>();
        emailToSet.addAll(krashReportMailList);
        String host = "";
        try {
            host = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException uhe) {
        }

        String msgSubject = bundle.getString(KRASH_ADMIN_SUBJECT_KEY);
        msgSubject = StringUtils.replace(msgSubject, PROJECT_NAME_TO_REPLACE, projectName);
        msgSubject = StringUtils.replace(msgSubject, HOST_TO_REPLACE, host);

        String msgContent = bundle.getString(KRASH_ADMIN_MSG_CONTENT_KEY);
        msgContent = StringUtils.replace(msgContent, PROJECT_NAME_TO_REPLACE, projectName);
        msgContent = StringUtils.replace(msgContent, USER_EMAIL_TO_REPLACE,
                act.getContract().getUser().getEmail1());
        msgContent = StringUtils.replace(msgContent, HOST_TO_REPLACE, host);
        msgContent = StringUtils.replace(msgContent, EXCEPTION_TO_REPLACE,
                ExceptionUtils.getStackTrace(exception));
        if (act.getAudit().getSubject() != null) {
            msgContent = StringUtils.replace(msgContent, AUDIT_URL_TO_REPLACE,
                    act.getAudit().getSubject().getURL());
        }
        LOGGER.info("krash email sent to " + krashReportMailList + " on audit n " + act.getAudit().getId());
        sendEmail(emailFrom, emailToSet, msgSubject, msgContent);
    }

    String emailTo = act.getContract().getUser().getEmail1();
    if (this.emailSentToUserExclusionList.contains(emailTo)) {
        LOGGER.info("Email not set cause user " + emailTo + " belongs to " + "exlusion list");
        return;
    }
    Set<String> emailToSet = new HashSet<>();
    emailToSet.add(emailTo);
    String msgSubject = bundle.getString(KRASH_SUBJECT_KEY);
    msgSubject = StringUtils.replace(msgSubject, PROJECT_NAME_TO_REPLACE, projectName);
    String msgContent = bundle.getString(KRASH_MSG_CONTENT_KEY);
    msgContent = StringUtils.replace(msgContent, PROJECT_NAME_TO_REPLACE, projectName);
    msgContent = StringUtils.replace(msgContent, PROJECT_URL_TO_REPLACE, buildContractUrl(act.getContract()));
    LOGGER.info("krash email sent to [" + emailTo + "]" + " on audit n " + act.getAudit().getId());
    sendEmail(emailFrom, emailToSet, msgSubject, msgContent);
}

From source file:org.asqatasun.webapp.report.expression.ProcessRemarkCsvExtractorExpression.java

private String escapeCsvSeparator(String strToEscape, String elementToEscape) {
    return StringUtils.replace(strToEscape, elementToEscape, BACKSLASH_KEY + elementToEscape);
}