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:eu.semlibproject.annotationserver.restapis.APIHelper.java

/**
 * Prepare a SPARQL query to be executed on the internal SPARQL end-point
 * //w  ww  . j  av  a2  s.co m
 * @param query             the SPARQL query
 * @param annotationsIDs    the list of all annotations ID in a Notebooks
 * @return                  the prepared query
 */
public String prepareQueryForNotebooksSPARQLEndPoint(String query, List<String> annotationsIDs) {

    String froms = "";
    String fromNameds = "";

    for (String annID : annotationsIDs) {
        String annotationGraph = Annotation.getGraphURIFromID(annID);
        String itemGraph = Annotation.getItemsGraphURIFormID(annID);
        froms += "FROM <" + annotationGraph + "> FROM <" + itemGraph + "> ";
        fromNameds += "FROM NAMED <" + annotationGraph + "> FROM NAMED <" + itemGraph + "> ";
    }

    String finalFroms = " " + froms + fromNameds;

    // Remove any existing FROM and FROM NAMED from the original query
    int startIndex = -1;
    Pattern regExPattern = Pattern.compile("(FROM <.+>\\s*|FROM NAMED <.+>\\s*)+", Pattern.CASE_INSENSITIVE);
    Matcher matcher = regExPattern.matcher(query);

    if (matcher.find()) {
        startIndex = matcher.start();
        String cleanQuery = matcher.replaceAll("");

        StringBuilder finalQuery = new StringBuilder(cleanQuery);
        finalQuery.insert(startIndex, finalFroms);

        return finalQuery.toString();
    } else {
        int indexOfWhere = query.toLowerCase().indexOf("where");
        StringBuilder strBuilder = new StringBuilder(query);
        strBuilder.insert(indexOfWhere, finalFroms);
        return strBuilder.toString();
    }
}

From source file:org.apache.hadoop.fs.azure.NativeAzureFileSystem.java

/**
 * Reverse the encoding done by encodeTrailingPeriod().
 *///w  w w  . j a  v a2 s .co m
private static String decodeTrailingPeriod(String toDecode) {
    Matcher matcher = TRAILING_PERIOD_PLACEHOLDER_PATTERN.matcher(toDecode);
    return matcher.replaceAll(".");
}

From source file:de.mpg.mpdl.inge.exportmanager.Export.java

public String explainFormatsXML() throws ExportManagerException {

    // TODO: Revision with ValueObjects

    String citStyles;//w  ww .  j a  v a  2 s  .co m
    try {
        citStyles = getCitationStyleHandler().explainStyles();
    } catch (Exception e) {
        throw new ExportManagerException("Cannot get citation styles explain", e);
    }

    String structured;
    try {
        structured = getStructuredExportHandler().explainFormats();
    } catch (Exception e) {
        throw new ExportManagerException("Cannot get structured exports explain", e);
    }

    String result;
    // get export-format elements
    String regexp = "<export-formats.*?>(.*?)</export-formats>";
    Matcher m = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(citStyles);
    m.find();
    result = m.group(1);
    m = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(structured);
    m.find();
    result += m.group(1);

    m = Pattern.compile("<export-format\\s+.*</export-format>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL)
            .matcher(structured);
    m.find();
    result = m.replaceAll(result);

    // replace comments
    // m = Pattern
    // .compile(
    // "<!--.*?-->"
    // , Pattern.CASE_INSENSITIVE | Pattern.DOTALL
    // )
    // .matcher(result);
    // m.find();
    // result = m.replaceAll("");

    return result;
}

From source file:org.fenixedu.academic.domain.Lesson.java

public List<EventBean> getAllLessonsEvents() {
    HashMap<DateTime, LessonInstance> hashmap = new HashMap<DateTime, LessonInstance>();
    ArrayList<EventBean> result = new ArrayList<EventBean>();
    LocalDate lessonEndDay = null;
    if (getLessonEndDay() != null) {
        getLessonEndDay().toLocalDate();
    }/*from ww w. j  av a2s .c  o m*/
    for (LessonInstance lessonInstance : getAllLessonInstancesUntil(lessonEndDay)) {
        hashmap.put(lessonInstance.getBeginDateTime(), lessonInstance);
    }

    for (YearMonthDay aDay : getAllLessonDates()) {
        DateTime beginDate = new DateTime(aDay.getYear(), aDay.getMonthOfYear(), aDay.getDayOfMonth(),
                getBeginHourMinuteSecond().getHour(), getBeginHourMinuteSecond().getMinuteOfHour(),
                getBeginHourMinuteSecond().getSecondOfMinute(), 0);

        LessonInstance lessonInstance = hashmap.get(beginDate);
        EventBean bean;
        Set<Space> location = new HashSet<>();

        String url = getExecutionCourse().getSiteUrl();

        if (lessonInstance != null) {

            if (lessonInstance.getLessonInstanceSpaceOccupation() != null) {
                location.add(lessonInstance.getLessonInstanceSpaceOccupation().getRoom());
            }
            String summary = null;
            if (lessonInstance.getSummary() != null) {
                summary = lessonInstance.getSummary().getSummaryText().toString();
                Pattern p = Pattern.compile("<[a-zA-Z0-9\\/]*[^>]*>");
                Matcher matcher = p.matcher(summary);
                summary = matcher.replaceAll("");

                p = Pattern.compile("\\s(\\s)*");
                matcher = p.matcher(summary);
                summary = matcher.replaceAll(" ");
            }

            bean = new ClassEventBean(lessonInstance.getBeginDateTime(), lessonInstance.getEndDateTime(), false,
                    location, url + "/sumarios", summary, getShift());
        } else {
            if (getLessonSpaceOccupation() != null) {
                location.add(getLessonSpaceOccupation().getRoom());
            }
            DateTime endDate = new DateTime(aDay.getYear(), aDay.getMonthOfYear(), aDay.getDayOfMonth(),
                    getEndHourMinuteSecond().getHour(), getEndHourMinuteSecond().getMinuteOfHour(),
                    getEndHourMinuteSecond().getSecondOfMinute(), 0);

            bean = new ClassEventBean(beginDate, endDate, false, location, url, null, getShift());
        }

        result.add(bean);
    }

    return result;
}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

public List<EventBean> getAllLessonsEvents() {
    HashMap<DateTime, LessonInstance> hashmap = new HashMap<DateTime, LessonInstance>();
    ArrayList<EventBean> result = new ArrayList<EventBean>();
    LocalDate lessonEndDay = null;
    if (getLessonEndDay() != null) {
        getLessonEndDay().toLocalDate();
    }//from ww w .ja  v  a2  s .co  m
    for (LessonInstance lessonInstance : getAllLessonInstancesUntil(lessonEndDay)) {
        hashmap.put(lessonInstance.getBeginDateTime(), lessonInstance);
    }

    for (YearMonthDay aDay : getAllLessonDates()) {
        DateTime beginDate = new DateTime(aDay.getYear(), aDay.getMonthOfYear(), aDay.getDayOfMonth(),
                getBeginHourMinuteSecond().getHour(), getBeginHourMinuteSecond().getMinuteOfHour(),
                getBeginHourMinuteSecond().getSecondOfMinute(), 0);

        LessonInstance lessonInstance = hashmap.get(beginDate);
        EventBean bean;
        Set<Space> location = new HashSet<>();

        String url = CoreConfiguration.getConfiguration().applicationUrl()
                + getExecutionCourse().getSite().getReversePath();

        if (lessonInstance != null) {

            if (lessonInstance.getLessonInstanceSpaceOccupation() != null) {
                location.add(lessonInstance.getLessonInstanceSpaceOccupation().getRoom());
            }
            String summary = null;
            if (lessonInstance.getSummary() != null) {
                summary = lessonInstance.getSummary().getSummaryText().toString();
                Pattern p = Pattern.compile("<[a-zA-Z0-9\\/]*[^>]*>");
                Matcher matcher = p.matcher(summary);
                summary = matcher.replaceAll("");

                p = Pattern.compile("\\s(\\s)*");
                matcher = p.matcher(summary);
                summary = matcher.replaceAll(" ");
            }

            bean = new ClassEventBean(lessonInstance.getBeginDateTime(), lessonInstance.getEndDateTime(), false,
                    location, url + "/sumarios", summary, getShift());
        } else {
            if (getLessonSpaceOccupation() != null) {
                location.add(getLessonSpaceOccupation().getRoom());
            }
            DateTime endDate = new DateTime(aDay.getYear(), aDay.getMonthOfYear(), aDay.getDayOfMonth(),
                    getEndHourMinuteSecond().getHour(), getEndHourMinuteSecond().getMinuteOfHour(),
                    getEndHourMinuteSecond().getSecondOfMinute(), 0);

            bean = new ClassEventBean(beginDate, endDate, false, location, url, null, getShift());
        }

        result.add(bean);
    }

    return result;
}

From source file:de.mpg.escidoc.services.exportmanager.Export.java

public String explainFormatsXML() throws ExportManagerException {

    //TODO: Revision with ValueObjects

    String citStyles;//from www  . j a  va  2 s  .com
    try {
        citStyles = getCitationStyleHandler().explainStyles();
    } catch (Exception e) {
        throw new ExportManagerException("Cannot get citation styles explain", e);
    }

    String structured;
    try {
        structured = getStructuredExportHandler().explainFormats();
    } catch (Exception e) {
        throw new ExportManagerException("Cannot get structured exports explain", e);
    }

    String result;
    // get export-format elements
    String regexp = "<export-formats.*?>(.*?)</export-formats>";
    Matcher m = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(citStyles);
    m.find();
    result = m.group(1);
    m = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE | Pattern.DOTALL).matcher(structured);
    m.find();
    result += m.group(1);

    m = Pattern.compile("<export-format\\s+.*</export-format>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL)
            .matcher(structured);
    m.find();
    result = m.replaceAll(result);

    // replace comments
    // m = Pattern
    // .compile(
    // "<!--.*?-->"
    // , Pattern.CASE_INSENSITIVE | Pattern.DOTALL
    // )
    // .matcher(result);
    // m.find();
    // result = m.replaceAll("");

    return result;
}

From source file:org.kuali.ole.gl.businessobject.OriginEntryFull.java

@Override
public String getLine() {
    StringBuffer sb = new StringBuffer();
    Map<String, Integer> fieldLengthMap = getOriginEntryFieldUtil().getFieldLengthMap();

    if (universityFiscalYear == null) {
        sb.append(GeneralLedgerConstants.getSpaceUniversityFiscalYear());
    } else {//from   w w w.  j  a va2s .c  o  m
        sb.append(universityFiscalYear);
    }

    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE), chartOfAccountsCode));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.ACCOUNT_NUMBER), accountNumber));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.SUB_ACCOUNT_NUMBER), subAccountNumber));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.FINANCIAL_OBJECT_CODE), financialObjectCode));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.FINANCIAL_SUB_OBJECT_CODE),
            financialSubObjectCode));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE),
            financialBalanceTypeCode));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE),
            financialObjectTypeCode));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE),
            universityFiscalPeriodCode));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE),
            financialDocumentTypeCode));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE),
            financialSystemOriginationCode));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.DOCUMENT_NUMBER), documentNumber));

    // This is the cobol code for transaction sequence numbers.
    // 3025 019280 IF TRN-ENTR-SEQ-NBR OF GLEN-RECORD NOT NUMERIC
    // 3026 019290 MOVE ZEROES TO TRN-ENTR-SEQ-NBR OF GLEN-RECORD
    // 3027 019300 END-IF
    // 3028 019310 IF TRN-ENTR-SEQ-NBR OF GLEN-RECORD = SPACES
    // 3029 019320 MOVE ZEROES
    // 3030 019330 TO TRN-ENTR-SEQ-NBR OF ALT-GLEN-RECORD
    // 3031 019340 ELSE
    // 3032 019350 MOVE TRN-ENTR-SEQ-NBR OF GLEN-RECORD
    // 3033 019360 TO TRN-ENTR-SEQ-NBR OF ALT-GLEN-RECORD
    // 3034 019370 END-IF
    String seqNum = "";
    if (transactionLedgerEntrySequenceNumber != null) {
        seqNum = transactionLedgerEntrySequenceNumber.toString();
    }
    // Format to a length of 5
    sb.append(StringUtils.leftPad(seqNum.trim(),
            fieldLengthMap.get(OLEPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER), "0"));

    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC),
            transactionLedgerEntryDescription));
    if (transactionLedgerEntryAmount == null) {
        sb.append(GeneralLedgerConstants.getZeroTransactionLedgerEntryAmount());
    } else {
        String a = transactionLedgerEntryAmount.abs().toString();
        if (transactionLedgerEntryAmount.isNegative()) {
            sb.append("-");
        } else {
            sb.append("+");
        }
        sb.append(GeneralLedgerConstants.getZeroTransactionLedgerEntryAmount().substring(1,
                fieldLengthMap.get(OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT) - a.length()));
        sb.append(a);
    }
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE),
            transactionDebitCreditCode));
    sb.append(formatDate(transactionDate));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER),
            organizationDocumentNumber));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.PROJECT_CODE), projectCode));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.ORGANIZATION_REFERENCE_ID),
            organizationReferenceId));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.REFERENCE_FIN_DOCUMENT_TYPE_CODE),
            referenceFinancialDocumentTypeCode));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.FIN_SYSTEM_REF_ORIGINATION_CODE),
            referenceFinancialSystemOriginationCode));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_REFERENCE_NBR),
            referenceFinancialDocumentNumber));
    sb.append(formatDate(financialDocumentReversalDate));
    sb.append(getField(fieldLengthMap.get(OLEPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD),
            transactionEncumbranceUpdateCode));
    // pad to full length 
    while (GeneralLedgerConstants.getSpaceAllOriginEntryFields().length() > sb.toString().length()) {
        sb.append(' ');
    }

    // KFSMI-5958: Don't want any control characters in output files. They potentially disrupt further processing
    Matcher controlCharacterMatcher = MATCH_CONTROL_CHARACTERS.matcher(sb);
    String returnString = controlCharacterMatcher.replaceAll(REPLACE_MATCHED_CONTROL_CHARACTERS);

    return returnString;
}

From source file:org.kuali.kfs.gl.businessobject.OriginEntryFull.java

@Override
public String getLine() {
    StringBuffer sb = new StringBuffer();
    Map<String, Integer> fieldLengthMap = getOriginEntryFieldUtil().getFieldLengthMap();

    if (universityFiscalYear == null) {
        sb.append(GeneralLedgerConstants.getSpaceUniversityFiscalYear());
    } else {/*from w w w .  j a v a2 s. c  o  m*/
        sb.append(universityFiscalYear);
    }

    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE), chartOfAccountsCode));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.ACCOUNT_NUMBER), accountNumber));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER), subAccountNumber));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE), financialObjectCode));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE),
            financialSubObjectCode));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE),
            financialBalanceTypeCode));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE),
            financialObjectTypeCode));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE),
            universityFiscalPeriodCode));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE),
            financialDocumentTypeCode));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE),
            financialSystemOriginationCode));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.DOCUMENT_NUMBER), documentNumber));

    // This is the cobol code for transaction sequence numbers.
    // 3025 019280 IF TRN-ENTR-SEQ-NBR OF GLEN-RECORD NOT NUMERIC
    // 3026 019290 MOVE ZEROES TO TRN-ENTR-SEQ-NBR OF GLEN-RECORD
    // 3027 019300 END-IF
    // 3028 019310 IF TRN-ENTR-SEQ-NBR OF GLEN-RECORD = SPACES
    // 3029 019320 MOVE ZEROES
    // 3030 019330 TO TRN-ENTR-SEQ-NBR OF ALT-GLEN-RECORD
    // 3031 019340 ELSE
    // 3032 019350 MOVE TRN-ENTR-SEQ-NBR OF GLEN-RECORD
    // 3033 019360 TO TRN-ENTR-SEQ-NBR OF ALT-GLEN-RECORD
    // 3034 019370 END-IF
    String seqNum = "";
    if (transactionLedgerEntrySequenceNumber != null) {
        seqNum = transactionLedgerEntrySequenceNumber.toString();
    }
    // Format to a length of 5
    sb.append(StringUtils.leftPad(seqNum.trim(),
            fieldLengthMap.get(KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER), "0"));

    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC),
            transactionLedgerEntryDescription));
    if (transactionLedgerEntryAmount == null) {
        sb.append(GeneralLedgerConstants.getZeroTransactionLedgerEntryAmount());
    } else {
        String a = transactionLedgerEntryAmount.abs().toString();
        if (transactionLedgerEntryAmount.isNegative()) {
            sb.append("-");
        } else {
            sb.append("+");
        }
        sb.append(GeneralLedgerConstants.getZeroTransactionLedgerEntryAmount().substring(1,
                fieldLengthMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT) - a.length()));
        sb.append(a);
    }
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE),
            transactionDebitCreditCode));
    sb.append(formatDate(transactionDate));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER),
            organizationDocumentNumber));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.PROJECT_CODE), projectCode));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.ORGANIZATION_REFERENCE_ID),
            organizationReferenceId));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.REFERENCE_FIN_DOCUMENT_TYPE_CODE),
            referenceFinancialDocumentTypeCode));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FIN_SYSTEM_REF_ORIGINATION_CODE),
            referenceFinancialSystemOriginationCode));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_REFERENCE_NBR),
            referenceFinancialDocumentNumber));
    sb.append(formatDate(financialDocumentReversalDate));
    sb.append(getField(fieldLengthMap.get(KFSPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD),
            transactionEncumbranceUpdateCode));
    // pad to full length
    while (GeneralLedgerConstants.getSpaceAllOriginEntryFields().length() > sb.toString().length()) {
        sb.append(' ');
    }

    // KFSMI-5958: Don't want any control characters in output files. They potentially disrupt further processing
    Matcher controlCharacterMatcher = MATCH_CONTROL_CHARACTERS.matcher(sb);
    String returnString = controlCharacterMatcher.replaceAll(REPLACE_MATCHED_CONTROL_CHARACTERS);

    return returnString;
}

From source file:com.twinsoft.convertigo.engine.servlets.ReverseProxyServlet.java

private byte[] handleStringReplacements(String baseUrl, String contentType, String charset,
        ProxyHttpConnector proxyHttpConnector, byte[] data) throws IOException {

    Engine.logEngine.debug("(ReverseProxyServlet) String replacements for content-type: " + contentType);

    if (contentType == null) {
        Engine.logEngine.warn("(ReverseProxyServlet) Aborting string replacements because of null mimetype!");
    } else {//from ww  w.jav  a 2  s. co  m
        Replacements replacements = proxyHttpConnector.getReplacementsForMimeType(contentType);

        if (!replacements.isEmpty()) {
            String sData = new String(data, charset);

            Engine.logEngine.trace("(ReverseProxyServlet) Data before string replacements:\n" + sData);

            Engine.logEngine.debug("(ReverseProxyServlet) Replacements in progress");

            String strSearched, strReplacing;
            for (int i = 0; i < replacements.strReplacing.length; i++) {
                strSearched = replacements.strSearched[i];
                Engine.logEngine.debug("(ReverseProxyServlet) Replacing: " + strSearched);

                strReplacing = replacements.strReplacing[i];

                Matcher m_connector = reg_connector.matcher(strReplacing);
                if (m_connector.find() && m_connector.groupCount() >= 1) {
                    String newConnector = m_connector.group(1);
                    Engine.logEngine.trace("(ReverseProxyServlet) find connector : " + newConnector);

                    // Bugfix for #1798 regression about #1718
                    String newBaseUrl = switchConnector(baseUrl, newConnector) + '/';
                    Engine.logEngine.trace("(ReverseProxyServlet) new baseUrl : " + newBaseUrl);
                    strReplacing = m_connector.replaceAll(newBaseUrl);
                } else {
                    strReplacing = reg_base.matcher(replacements.strReplacing[i]).replaceAll(baseUrl);
                }

                Engine.logEngine.debug("(ReverseProxyServlet) By: " + strReplacing);

                sData = sData.replaceAll(strSearched, strReplacing);
            }

            Engine.logEngine.debug("(ReverseProxyServlet) Replacements done!");

            Engine.logEngine.trace("(ReverseProxyServlet) Data after string replacements:\n" + sData);

            data = sData.getBytes(charset);
        }
    }
    return data;
}

From source file:com.cisco.dvbu.ps.deploytool.services.RegressionManagerUtils.java

/**
 * constructKey - take in strings and replace any "/" with "."
 * Example:  s1=TEST,  s2=CAT.SCHEMA.TABLE, s3=null, s4=null                --> TEST.CAT.SCHEMA.TABLE
 * Example:  s1=TestWebService, s2=/soap11/TestWebService, s3=null, s4=null --> TestWebService.soap11.TestWebService
 * @param s1 - any string//from   ww w  . j a v a2  s  .  c  om
 * @param s2 - any string
 * @param s3 - any string
 * @param s4 - any string
 * @return result - a URL with the format of S1.S2.S3.S4
 */
public static String constructKey(String s1, String s2, String s3, String s4) {
    String result = "";
    int regexSize = 102400;
    Pattern p = null;
    Matcher m = null;

    ArrayList<String> ss = new ArrayList<String>();
    if (s1 != null)
        ss.add(s1);
    if (s2 != null)
        ss.add(s2);
    if (s3 != null)
        ss.add(s3);
    if (s4 != null)
        ss.add(s4);

    for (int i = 0; i < ss.size(); i++) {
        // Replace all "/" with "." in the string
        String s = ss.get(i).replaceAll("/", ".");

        // Create a pattern to match a period within double quotes
        p = Pattern.compile("\\." + "(?=[^\"]{0," + regexSize + "}\"(?:[^\"\r\n]{0," + regexSize + "}\"[^\"]{0,"
                + regexSize + "}\"){0," + regexSize + "}[^\"\r\n]{0," + regexSize + "}$)");
        // Create a matcher with an input string
        m = p.matcher(s);
        // Encode all periods within double quotes "" with _002e
        s = m.replaceAll("_002e");

        // Remove the leading "." in the string
        if (s.indexOf(".") == 0)
            s = s.substring(1);
        // Add this string to the result with a "." separator
        if (i > 0)
            result = result + ".";
        result = result + s;
    }
    if (result.length() == 0)
        result = null;

    if (result != null) {
        // Double quote any reserved words or paths containing special characters like spaces or periods
        result = CommonUtils.applyReservedListToPath(result, ".");

        // Decode all encoded periods "_002e" with an actual period "."
        result = result.replaceAll("_002e", "\\.");
    }
    return result;
}