Example usage for java.util.regex Matcher replaceAll

List of usage examples for java.util.regex Matcher replaceAll

Introduction

In this page you can find the example usage for java.util.regex Matcher replaceAll.

Prototype

public String replaceAll(Function<MatchResult, String> replacer) 

Source Link

Document

Replaces every subsequence of the input sequence that matches the pattern with the result of applying the given replacer function to the match result of this matcher corresponding to that subsequence.

Usage

From source file:com.photon.phresco.framework.rest.api.QualityService.java

private String getLoadOrPerformanceTestResultPath(String rootModulePath, String subModuleName,
        String testAgainst, String resultFileName, String action) throws PhrescoException {
    try {/*  w  w w . ja  v a 2 s. c o  m*/
        ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
        File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModuleName);

        StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
        String reportDir = "";
        if (Constants.PHASE_PERFORMANCE_TEST.equals(action)) {
            reportDir = FrameworkServiceUtil.getPerformanceTestReportDir(rootModulePath, subModuleName);
        } else {
            reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
        }
        //To change the dir_type based on the selected type
        Pattern p = Pattern.compile(TEST_DIRECTORY);
        Matcher matcher = p.matcher(reportDir);
        if (StringUtils.isNotEmpty(reportDir) && StringUtils.isNotEmpty(testAgainst) && matcher.find()) {
            reportDir = matcher.replaceAll(testAgainst);
        }
        sb.append(reportDir);
        sb.append(File.separator);
        sb.append(resultFileName);

        return sb.toString();
    } catch (Exception e) {
        throw new PhrescoException(e);
    }
}

From source file:com.photon.phresco.framework.rest.api.QualityService.java

private String getUnitTestResultPath(String rootModulePath, String subModuleName, String testAgainst,
        String resultFileName, String action) throws PhrescoException {
    try {// w w  w . j  a va  2  s . c o  m
        ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName);
        File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModuleName);

        StringBuilder sb = new StringBuilder(testFolderLocation.getPath());
        String reportDir = "";
        if (Constants.PHASE_UNIT_TEST.equals(action)) {
            reportDir = FrameworkServiceUtil.getUnitTestRptDir(rootModulePath, subModuleName);
        } /*else {
           reportDir = FrameworkServiceUtil.getLoadTestReportDir(rootModulePath, subModuleName);
          }*/
        //To change the dir_type based on the selected type
        Pattern p = Pattern.compile(TEST_DIRECTORY);
        Matcher matcher = p.matcher(reportDir);
        if (StringUtils.isNotEmpty(reportDir) && StringUtils.isNotEmpty(testAgainst) && matcher.find()) {
            reportDir = matcher.replaceAll(testAgainst);
        }
        sb.append(reportDir);
        sb.append(File.separator);
        sb.append(resultFileName);

        return sb.toString();

    } catch (Exception e) {
        throw new PhrescoException(e);
    }
}

From source file:mondrian.rolap.RolapSchemaLoader.java

private static boolean isRelative(String path) {
    final Matcher matcher = PROTOCOL_PATTERN.matcher(path);
    if (matcher.matches()) {
        path = matcher.replaceAll("");
    }//from w  w w .j a v  a 2s  . c  o m
    return !path.startsWith("/");
}

From source file:com.ichi2.anki2.Reviewer.java

private void displayCardAnswer() {
    Log.i(AnkiDroidApp.TAG, "displayCardAnswer");

    // prevent answering (by e.g. gestures) before card is loaded
    if (mCurrentCard == null) {
        return;/*from  w  ww . j ava 2  s  . co  m*/
    }

    sDisplayAnswer = true;
    setFlipCardAnimation();

    String answer = mCurrentCard.getAnswer(mCurrentSimpleInterface);
    answer = typeAnsAnswerFilter(answer);

    String displayString = "";

    if (mCurrentSimpleInterface) {
        mCardContent = convertToSimple(answer);
        if (mCardContent.length() == 0) {
            SpannableString hint = new SpannableString(
                    getResources().getString(R.string.simple_interface_hint, R.string.card_details_answer));
            hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            mCardContent = hint;
        }
    } else {
        Sound.stopSounds();
        Recorder.stopRecording();

        if (mPrefFixArabic) {
            // reshape
            answer = ArabicUtilities.reshapeSentence(answer, true);
        }

        // If the user wrote an answer
        if (typeAnswer()) {
            mAnswerField.setVisibility(View.GONE);
            if (mCurrentCard != null) {
                if (mPrefFixArabic) {
                    // reshape
                    mTypeCorrect = ArabicUtilities.reshapeSentence(mTypeCorrect, true);
                }
                // Obtain the user answer and the correct answer
                String userAnswer = mAnswerField.getText().toString();
                Matcher matcher = sSpanPattern.matcher(Utils.stripHTMLMedia(mTypeCorrect));
                String correctAnswer = matcher.replaceAll("");
                matcher = sBrPattern.matcher(correctAnswer);
                correctAnswer = matcher.replaceAll("\n");
                matcher = Sound.sSoundPattern.matcher(correctAnswer);
                correctAnswer = matcher.replaceAll("");
                Log.i(AnkiDroidApp.TAG, "correct answer = " + correctAnswer);

                // Obtain the diff and send it to updateCard
                DiffEngine diff = new DiffEngine();

                StringBuffer span = new StringBuffer();
                span.append("<span style=\"font-family: '").append(mTypeFont).append("'; font-size: ")
                        .append(mTypeSize).append("px\">");
                span.append(diff.diff_prettyHtml(diff.diff_main(userAnswer, correctAnswer), mNightMode));
                span.append("</span>");
                span.append("<br/>").append(answer);
                displayString = enrichWithQADiv(span.toString(), true);
            }

            // Hide soft keyboard
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(mAnswerField.getWindowToken(), 0);
        } else {
            displayString = enrichWithQADiv(answer, true);
        }
    }

    mIsSelecting = false;
    updateCard(displayString);
    showEaseButtons();

    // If the user want to show next question automatically
    if (mPrefUseTimer) {
        mTimeoutHandler.removeCallbacks(mShowQuestionTask);
        mTimeoutHandler.postDelayed(mShowQuestionTask, mWaitQuestionSecond * 1000);
    }
}

From source file:com.hichinaschool.flashcards.anki.Reviewer.java

private void displayCardAnswer() {
    // Log.i(AnkiDroidApp.TAG, "displayCardAnswer");

    // prevent answering (by e.g. gestures) before card is loaded
    if (mCurrentCard == null) {
        return;/*ww w  .  java  2s  . c  om*/
    }

    sDisplayAnswer = true;
    setFlipCardAnimation();

    String answer = mCurrentCard.getAnswer(mCurrentSimpleInterface);
    answer = typeAnsAnswerFilter(answer);

    String displayString = "";

    if (mCurrentSimpleInterface) {
        mCardContent = convertToSimple(answer);
        if (mCardContent.length() == 0) {
            SpannableString hint = new SpannableString(
                    getResources().getString(R.string.simple_interface_hint, R.string.card_details_answer));
            hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            mCardContent = hint;
        }
    } else {
        Sound.stopSounds();

        if (mPrefFixArabic) {
            // reshape
            answer = ArabicUtilities.reshapeSentence(answer, true);
        }

        // If the user wrote an answer
        if (typeAnswer()) {
            mAnswerField.setVisibility(View.GONE);
            if (mCurrentCard != null) {
                if (mPrefFixArabic) {
                    // reshape
                    mTypeCorrect = ArabicUtilities.reshapeSentence(mTypeCorrect, true);
                }
                // Obtain the user answer and the correct answer
                String userAnswer = mAnswerField.getText().toString();
                Matcher matcher = sSpanPattern.matcher(Utils.stripHTMLMedia(mTypeCorrect));
                String correctAnswer = matcher.replaceAll("");
                matcher = sBrPattern.matcher(correctAnswer);
                correctAnswer = matcher.replaceAll("\n");
                matcher = Sound.sSoundPattern.matcher(correctAnswer);
                correctAnswer = matcher.replaceAll("");
                // Log.i(AnkiDroidApp.TAG, "correct answer = " + correctAnswer);

                // Obtain the diff and send it to updateCard
                DiffEngine diff = new DiffEngine();

                StringBuffer span = new StringBuffer();
                span.append("<span style=\"font-family: '").append(mTypeFont).append("'; font-size: ")
                        .append(mTypeSize).append("px\">");
                span.append(diff.diff_prettyHtml(diff.diff_main(userAnswer, correctAnswer), mNightMode));
                span.append("</span>");
                span.append("<br/>").append(answer);
                displayString = enrichWithQADiv(span.toString(), true);
            }

            // Hide soft keyboard
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(mAnswerField.getWindowToken(), 0);
        } else {
            displayString = enrichWithQADiv(answer, true);
        }
    }

    mIsSelecting = false;
    updateCard(displayString);
    showEaseButtons();

    // If the user want to show next question automatically
    if (mPrefUseTimer) {
        mTimeoutHandler.removeCallbacks(mShowQuestionTask);
        mTimeoutHandler.postDelayed(mShowQuestionTask, mWaitQuestionSecond * 1000);
    }
}

From source file:com.zimbra.cs.zclient.ZMailboxUtil.java

private String id(String indexOrId) throws ServiceException {
    Matcher m = sTargetConstraint.matcher(indexOrId);
    if (m.find()) {
        indexOrId = m.replaceAll("");
    }//from   w w w . j av a 2  s .co  m

    StringBuilder ids = new StringBuilder();
    for (String t : indexOrId.split(",")) {
        if (t.length() > 1 && t.charAt(0) == '#') {
            t = t.substring(1);
            //stdout.println(t);
            int i = t.indexOf('-');
            if (i != -1) {
                int start = Integer.parseInt(t.substring(0, i));
                int end = Integer.parseInt(t.substring(i + 1, t.length()));
                for (int j = start; j <= end; j++) {
                    String id = mIndexToId.get(j);
                    if (id == null) {
                        throw ZClientException.CLIENT_ERROR("unknown index: " + t, null);
                    }
                    if (ids.length() > 0) {
                        ids.append(",");
                    }
                    ids.append(id);
                }
            } else {
                String id = mIndexToId.get(Integer.parseInt(t));
                if (id == null) {
                    throw ZClientException.CLIENT_ERROR("unknown index: " + t, null);
                }
                if (ids.length() > 0) {
                    ids.append(",");
                }
                ids.append(id);
            }
        } else {
            if (ids.length() > 0) {
                ids.append(",");
            }
            ids.append(t);
        }
    }
    return ids.toString();
}

From source file:de.escidoc.core.test.EscidocTestBase.java

/**
 * Modifies the namespace prefixes of the provided xml data by adding a prefix to the namespac.
 * //from  w  w  w .ja  va  2  s  .c  om
 * @param xml
 *            The xml data to change the namespace prefixes in.
 * @return Returns the modified xml data.
 */
public static String modifyNamespacePrefixes(final String xml) {

    Matcher matcher = PATTERN_MODIFY_NAMESPACE_PREFIXES_REPLACE_PREFIXES.matcher(xml);
    String ret = matcher.replaceAll("$1prefix-$2");
    matcher = PATTERN_MODIFY_NAMESPACE_PREFIXES_FIX_NAMESPACE_DECLARATIONS.matcher(ret);
    ret = matcher.replaceAll("xmlns:prefix-$1");
    matcher = PATTERN_MODIFY_NAMESPACE_PREFIXES_FIX_PREFIX_XML.matcher(ret);
    ret = matcher.replaceAll("xml");
    return ret;
}

From source file:cgeo.geocaching.cgBase.java

public static String stripTags(String text) {
    if (StringUtils.isBlank(text)) {
        return "";
    }/*w ww  .  j  a  v  a 2  s . c om*/

    final Pattern patternP = Pattern.compile("(<[^>]+>)", Pattern.CASE_INSENSITIVE);
    final Matcher matcherP = patternP.matcher(text);

    matcherP.replaceAll(" ");

    return text.trim();
}

From source file:com.ichi2.anki.AbstractFlashcardViewer.java

/**
 * Format question field when it contains typeAnswer or clozes. If there was an error during type text extraction, a
 * warning is displayed//  w  w  w.j  a v a2 s  . c  o  m
 *
 * @param buf The question text
 * @return The formatted question text
 */
private String typeAnsQuestionFilter(String buf) {
    Matcher m = sTypeAnsPat.matcher(buf);
    if (mTypeWarning != null) {
        return m.replaceFirst(mTypeWarning);
    }
    StringBuilder sb = new StringBuilder();
    if (mUseInputTag) {
        // These functions are definde in the JavaScript file assets/scripts/card.js. We get the text back in
        // shouldOverrideUrlLoading() in createWebView() in this file.
        sb.append("<center>\n<input type=text name=typed id=typeans onfocus=\"taFocus();\" "
                + "onblur=\"taBlur(this);\" onKeyPress=\"return taKey(this, event)\" autocomplete=\"off\" ");
        // We have to watch out. For the preview we dont know the font or font size. Skip those there. (Anki
        // desktop just doesnt show the input tag there. Do it with standard values here instead.)
        if (mTypeFont != null && !TextUtils.isEmpty(mTypeFont) && mTypeSize > 0) {
            sb.append("style=\"font-family: '" + mTypeFont + "'; font-size: " + Integer.toString(mTypeSize)
                    + "px;\" ");
        }
        sb.append(">\n</center>\n");
    } else {
        sb.append("<span id=typeans class=\"typePrompt");
        if (!mShowTypeAnswerField) {
            sb.append(" typeOff");
        }
        sb.append("\">........</span>");
    }
    return m.replaceAll(sb.toString());
}

From source file:cgeo.geocaching.cgBase.java

public static String stripParagraphs(String text) {
    if (StringUtils.isBlank(text)) {
        return "";
    }//from  w  w w .  java2s . com

    final Pattern patternP = Pattern.compile("(<p>|</p>|<br \\/>|<br>)", Pattern.CASE_INSENSITIVE);
    final Pattern patternP2 = Pattern.compile("([ ]+)", Pattern.CASE_INSENSITIVE);
    final Matcher matcherP = patternP.matcher(text);
    final Matcher matcherP2 = patternP2.matcher(text);

    matcherP.replaceAll(" ");
    matcherP2.replaceAll(" ");

    return text.trim();
}