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:it.eng.spagobi.meta.initializer.PhysicalModelInitializer.java

private String getEscapedMetadataPropertyValue(ResultSet rs, String propertyName) throws SQLException {
    String propertyValue;//  w w  w  . ja va2 s.  c  o m

    propertyValue = rs.getString(propertyName);
    if (propertyValue != null) {
        propertyValue = StringEscapeUtils.escapeXml(propertyValue);

        Pattern pattern = Pattern.compile("[\\000]*");
        Matcher matcher = pattern.matcher(propertyValue);
        if (matcher.find()) {
            propertyValue = matcher.replaceAll("");
        }
    }
    return propertyValue;
}

From source file:com.dvdprime.mobile.android.ui.DocumentViewActivity.java

@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    case android.R.id.home:
        EasyTracker.getTracker().sendEvent("DocView Menu", "Click", "Home", Long.valueOf(0L));
        finish();//from   ww w  .j  a v  a 2  s. co m
        return true;
    case R.id.menu_refresh:
        EasyTracker.getTracker().sendEvent("DocView Menu", "Click", "Refresh", Long.valueOf(0L));
        menuItem.setActionView(R.layout.indeterminate_progress_action);
        onRefreshStarted(null);
        return true;
    case R.id.menu_share:
        try {
            JsonObjectRequest jsonRequest = new JsonObjectRequest(Method.POST, Config.GOOGLE_SHORTENER_URL,
                    new JSONObject().put("longUrl", this.mUrl), createShortenerReqSuccessListener(),
                    createShortenerReqErrorListener());
            jsonRequest.setTag(TAG);
            DpApp.getRequestQueue().add(jsonRequest);
        } catch (JSONException e) {
        }
        return true;
    case R.id.menu_view_original:
        EasyTracker.getTracker().sendEvent("DocView Menu", "Click", "ViewOriginal", Long.valueOf(0L));
        AndroidUtil.clickedLinkAction(mActivity, mUrl);
        return true;
    case R.id.menu_copy_url:
        EasyTracker.getTracker().sendEvent("DocView Menu", "Click", "CopyURL", Long.valueOf(0L));
        SystemUtil.copyToClipboard(mActivity, mUrl);
        return true;
    case R.id.menu_recommend:
        if (this.rcmdMenu.isEnabled()) {
            EasyTracker.getTracker().sendEvent("DocView Menu", "Click", "Recommend", Long.valueOf(0L));
            new ViewRecommendTask(mActivity).execute(StringUtil.getParamValue(mUrl, "bbslist_id"));
        }
        return true;
    case R.id.menu_save_mydp:
        if (this.rcmdMenu.isEnabled()) {
            EasyTracker.getTracker().sendEvent("DocView Menu", "Click", "SaveMyDP", Long.valueOf(0L));
            new ViewSaveTask(mActivity).execute(StringUtil.getParamValue(mUrl, "bbslist_id"));
        }
        return true;
    case R.id.menu_modify:
        if (rcmdMenu.isEnabled()) {
            EasyTracker.getTracker().sendEvent("DocView Menu", "Click", "Modify", Long.valueOf(0L));
            String title = "";
            String content = "";
            String tag = "";
            String date = "";
            Source source = new Source(mContent);
            Element titleElement = source.getFirstElement("strong");
            if (titleElement != null) {
                title = StringUtil.substringAfter(titleElement.getTextExtractor().toString(), "] ");
            }
            Element contentElement = source.getFirstElement("id", "viewContent", false);
            if (contentElement != null) {
                content = contentElement.getContent().toString();
            }
            Element tagElement = source.getFirstElement("id", "viewTag", false);
            if (tagElement != null) {
                tag = tagElement.getTextExtractor().toString();
                if (StringUtil.equals(tag, getString(R.string.write_tag_empty))) {
                    tag = "";
                }
            }
            Element dateElement = source.getFirstElement("id", "viewDate", false);
            if (dateElement != null) {
                date = StringUtil.substringBefore(dateElement.getTextExtractor().toString(), " ");
            }
            Matcher matcher = Pattern.compile("<br?>", 2).matcher(content);
            Intent intent = new Intent(this, WriteDocumentActivity.class);
            intent.putExtra("id", StringUtil.getParamValue(mUrl, "major")
                    + StringUtil.getParamValue(mUrl, "minor") + StringUtil.getParamValue(mUrl, "master_id"));
            intent.putExtra("title", title);
            intent.putExtra("content", matcher.replaceAll("\n"));
            intent.putExtra("tag", tag);
            intent.putExtra("date", date);
            intent.putExtra("bbsId", StringUtil.getParamValue(mUrl, "bbslist_id"));
            startActivityForResult(intent, RequestCode.MODIFY_DOCUMENT);
        }
        return true;
    case R.id.menu_delete:
        EasyTracker.getTracker().sendEvent("DocView Menu", "Click", "Delete", Long.valueOf(0L));
        AndroidUtil.showConfim(mActivity, getString(R.string.alert_dialog_ok),
                getString(R.string.view_delete_message), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int paramInt) {
                        dialogInterface.dismiss();
                        new ViewDeleteTask(mActivity).execute(mUrl);
                    }
                });
        return true;
    case R.id.menu_setting:
        EasyTracker.getTracker().sendEvent("DocView Menu", "Click", "Setting", Long.valueOf(0L));
        startActivity(new Intent(this.mActivity, SettingActivity.class));
        return true;
    case R.id.menu_about:
        EasyTracker.getTracker().sendEvent("DocView Menu", "Click", "About", Long.valueOf(0L));
        startActivity(new Intent(this.mActivity, AboutActivity.class));
        return true;
    default:
        return super.onOptionsItemSelected(menuItem);
    }
}

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

/**
 * This method loads the fields of this origin entry by parsing the passed in the string It is assumed that the String does not
 * contain the origin entry ID, but if it does, it will be ignored
 * /*from  ww w . j av a2s .  c o  m*/
 * @param line a string representing an origin entry
 * @param lineNumber used to render an error message by identifying this line
 * @throws LoadException
 */

public List<Message> setFromTextFileForBatch(String line, int lineNumber) throws LoadException {
    List<Message> returnList = new ArrayList<Message>();
    final Map<String, Integer> pMap = getOriginEntryFieldUtil().getFieldBeginningPositionMap();

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

    // Just in case
    line = org.apache.commons.lang.StringUtils.rightPad(line,
            GeneralLedgerConstants.getSpaceAllOriginEntryFields().length(), ' ');

    if (!GeneralLedgerConstants.getSpaceUniversityFiscalYear()
            .equals(line.substring(pMap.get(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                    pMap.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE)))) {
        try {
            setUniversityFiscalYear(
                    new Integer(getValue(line, pMap.get(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                            pMap.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE))));
        } catch (NumberFormatException e) {
            returnList.add(new Message("Fiscal year '"
                    + line.substring(pMap.get(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                            pMap.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE))
                    + "' contains an invalid value.", Message.TYPE_FATAL));
            setUniversityFiscalYear(null);
        }
    } else {
        setUniversityFiscalYear(null);
    }

    setChartOfAccountsCode(getValue(line, pMap.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE),
            pMap.get(OLEPropertyConstants.ACCOUNT_NUMBER)));
    setAccountNumber(getValue(line, pMap.get(OLEPropertyConstants.ACCOUNT_NUMBER),
            pMap.get(OLEPropertyConstants.SUB_ACCOUNT_NUMBER)));

    // if chart code is empty while accounts cannot cross charts, then derive chart code from account number
    AccountService acctserv = SpringContext.getBean(AccountService.class);
    if (StringUtils.isEmpty(getChartOfAccountsCode()) && StringUtils.isNotEmpty(getAccountNumber())
            && !acctserv.accountsCanCrossCharts()) {
        Account account = acctserv.getUniqueAccountForAccountNumber(getAccountNumber());
        if (account != null) {
            setChartOfAccountsCode(account.getChartOfAccountsCode());
        }
    }

    setSubAccountNumber(getValue(line, pMap.get(OLEPropertyConstants.SUB_ACCOUNT_NUMBER),
            pMap.get(OLEPropertyConstants.FINANCIAL_OBJECT_CODE)));
    setFinancialObjectCode(getValue(line, pMap.get(OLEPropertyConstants.FINANCIAL_OBJECT_CODE),
            pMap.get(OLEPropertyConstants.FINANCIAL_SUB_OBJECT_CODE)));
    setFinancialSubObjectCode(getValue(line, pMap.get(OLEPropertyConstants.FINANCIAL_SUB_OBJECT_CODE),
            pMap.get(OLEPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE)));
    setFinancialBalanceTypeCode(getValue(line, pMap.get(OLEPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE),
            pMap.get(OLEPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE)));
    setFinancialObjectTypeCode(getValue(line, pMap.get(OLEPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE),
            pMap.get(OLEPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE)));
    setUniversityFiscalPeriodCode(getValue(line, pMap.get(OLEPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE),
            pMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE)));
    setFinancialDocumentTypeCode(getValue(line, pMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE),
            pMap.get(OLEPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE)));
    setFinancialSystemOriginationCode(
            getValue(line, pMap.get(OLEPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE),
                    pMap.get(OLEPropertyConstants.DOCUMENT_NUMBER)));
    setDocumentNumber(getValue(line, pMap.get(OLEPropertyConstants.DOCUMENT_NUMBER),
            pMap.get(OLEPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER)));

    // don't trim sequenceNumber because SpaceTransactionEntrySequenceNumber is "     "
    if (!GeneralLedgerConstants.getSpaceTransactionEntrySequenceNumber()
            .equals(line.substring(pMap.get(OLEPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER),
                    pMap.get(OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC)))
            && !GeneralLedgerConstants.getZeroTransactionEntrySequenceNumber()
                    .equals(getValue(line, pMap.get(OLEPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER),
                            pMap.get(OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC)))) {
        try {
            setTransactionLedgerEntrySequenceNumber(
                    new Integer(getValue(line, pMap.get(OLEPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER),
                            pMap.get(OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC))));
        } catch (NumberFormatException e) {
            returnList.add(new Message("Transaction Sequence Number '"
                    + line.substring(pMap.get(OLEPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER),
                            pMap.get(OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC))
                    + "' contains an invalid value.", Message.TYPE_FATAL));
            setTransactionLedgerEntrySequenceNumber(null);
        }
    } else {
        setTransactionLedgerEntrySequenceNumber(null);
    }

    setTransactionLedgerEntryDescription(
            getValue(line, pMap.get(OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC),
                    pMap.get(OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT)));

    if (!getValue(line, pMap.get(OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT),
            pMap.get(OLEPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE))
                    .equals(GeneralLedgerConstants.EMPTY_CODE)) {
        try {
            setTransactionLedgerEntryAmount(new KualiDecimal(
                    getValue(line, pMap.get(OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT),
                            pMap.get(OLEPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE)).trim()));
        } catch (NumberFormatException e) {
            returnList.add(new Message("Transaction Amount '"
                    + line.substring(pMap.get(OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT),
                            pMap.get(OLEPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE))
                    + "' contains an invalid value.", Message.TYPE_FATAL));
            setTransactionLedgerEntryAmount(KualiDecimal.ZERO);
        }
    } else {
        returnList.add(new Message("Transaction Amount cannot be blank.", Message.TYPE_FATAL));
        setTransactionLedgerEntryAmount(KualiDecimal.ZERO);
    }

    setTransactionDebitCreditCode(line.substring(pMap.get(OLEPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE),
            pMap.get(OLEPropertyConstants.TRANSACTION_DATE)));

    if (!getValue(line, pMap.get(OLEPropertyConstants.TRANSACTION_DATE),
            pMap.get(OLEPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER))
                    .equals(GeneralLedgerConstants.EMPTY_CODE)) {
        // FSKD-193, KFSMI-5441
        try {
            setTransactionDate(parseDate(getValue(line, pMap.get(OLEPropertyConstants.TRANSACTION_DATE),
                    pMap.get(OLEPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER)), false));
        } catch (ParseException e) {
            setTransactionDate(SpringContext.getBean(DateTimeService.class).getCurrentSqlDate());
        }
    } else {
        setTransactionDate(null);
    }

    setOrganizationDocumentNumber(getValue(line, pMap.get(OLEPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER),
            pMap.get(OLEPropertyConstants.PROJECT_CODE)));
    setProjectCode(getValue(line, pMap.get(OLEPropertyConstants.PROJECT_CODE),
            pMap.get(OLEPropertyConstants.ORGANIZATION_REFERENCE_ID)));
    setOrganizationReferenceId(getValue(line, pMap.get(OLEPropertyConstants.ORGANIZATION_REFERENCE_ID),
            pMap.get(OLEPropertyConstants.REFERENCE_FIN_DOCUMENT_TYPE_CODE)));
    setReferenceFinancialDocumentTypeCode(
            getValue(line, pMap.get(OLEPropertyConstants.REFERENCE_FIN_DOCUMENT_TYPE_CODE),
                    pMap.get(OLEPropertyConstants.FIN_SYSTEM_REF_ORIGINATION_CODE)));
    setReferenceFinancialSystemOriginationCode(
            getValue(line, pMap.get(OLEPropertyConstants.FIN_SYSTEM_REF_ORIGINATION_CODE),
                    pMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_REFERENCE_NBR)));
    setReferenceFinancialDocumentNumber(
            getValue(line, pMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_REFERENCE_NBR),
                    pMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE)));

    if (!getValue(line, pMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE),
            pMap.get(OLEPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD))
                    .equals(GeneralLedgerConstants.EMPTY_CODE)) {
        try {
            setFinancialDocumentReversalDate(
                    parseDate(getValue(line, pMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE),
                            pMap.get(OLEPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD)), false));
        } catch (ParseException e) {
            setFinancialDocumentReversalDate(null);
            returnList.add(new Message("Reversal Date '"
                    + line.substring(pMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE),
                            pMap.get(OLEPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD))
                    + "' contains an invalid value.", Message.TYPE_FATAL));

        }
    } else {
        setFinancialDocumentReversalDate(null);
    }

    //set till end
    setTransactionEncumbranceUpdateCode(
            line.substring(pMap.get(OLEPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD),
                    GeneralLedgerConstants.getSpaceAllOriginEntryFields().length()));

    return returnList;
}

From source file:gate.creole.orthomatcher.OrthoMatcher.java

/** creates the lookup tables */
protected void createAnnotList(String nameFile, String nameList) throws IOException {
    // create the relative URL
    URL fileURL = new URL(definitionFileURL, nameFile);
    BufferedReader bufferedReader = null;
    try {/*  w  ww  .j a  v a2  s .  com*/
        bufferedReader = new BomStrippingInputStreamReader(fileURL.openStream(), encoding);

        String lineRead = null;
        while ((lineRead = bufferedReader.readLine()) != null) {
            if (nameList.compareTo(CDGLISTNAME) == 0) {
                Matcher matcher = punctPat.matcher(lineRead.toLowerCase().trim());
                lineRead = matcher.replaceAll(" ").trim();
                if (caseSensitive)
                    cdg.add(lineRead);
                else
                    cdg.add(lineRead.toLowerCase());
            } // if
            else {
                int index = lineRead.indexOf("");
                if (index != -1) {
                    String expr = lineRead.substring(0, index);
                    // if not case-sensitive, we need to downcase all strings
                    if (!caseSensitive)
                        expr = expr.toLowerCase();
                    String code = lineRead.substring(index + 1, lineRead.length());
                    if (nameList.equals(ALIASLISTNAME)) {
                        alias.put(expr, code);
                    } else if (nameList.equals(ARTLISTNAME)) {
                        def_art.put(expr, code);
                    } else if (nameList.equals(PREPLISTNAME)) {
                        prepos.put(expr, code);
                    } else if (nameList.equals(CONNECTORLISTNAME)) {
                        connector.put(expr, code);
                    } else if (nameList.equals(SPURLISTNAME)) {
                        spur_match.put(expr, code);
                    }
                } // if
            } // else

        } // while
    } finally {
        IOUtils.closeQuietly(bufferedReader);
    }
}

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

/**
 * This method loads the fields of this origin entry by parsing the passed in the string It is assumed that the String does not
 * contain the origin entry ID, but if it does, it will be ignored
 *
 * @param line a string representing an origin entry
 * @param lineNumber used to render an error message by identifying this line
 * @throws LoadException/*from   w ww  .j av a 2 s. co  m*/
 */

public List<Message> setFromTextFileForBatch(String line, int lineNumber) throws LoadException {
    List<Message> returnList = new ArrayList<Message>();
    final Map<String, Integer> pMap = getOriginEntryFieldUtil().getFieldBeginningPositionMap();

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

    // Just in case
    line = org.apache.commons.lang.StringUtils.rightPad(line,
            GeneralLedgerConstants.getSpaceAllOriginEntryFields().length(), ' ');

    if (!GeneralLedgerConstants.getSpaceUniversityFiscalYear()
            .equals(line.substring(pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                    pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE)))) {
        try {
            setUniversityFiscalYear(
                    new Integer(getValue(line, pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                            pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE))));
        } catch (NumberFormatException e) {
            returnList.add(new Message("Fiscal year '"
                    + line.substring(pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR),
                            pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE))
                    + "' contains an invalid value.", Message.TYPE_FATAL));
            setUniversityFiscalYear(null);
        }
    } else {
        setUniversityFiscalYear(null);
    }

    setChartOfAccountsCode(getValue(line, pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE),
            pMap.get(KFSPropertyConstants.ACCOUNT_NUMBER)));
    setAccountNumber(getValue(line, pMap.get(KFSPropertyConstants.ACCOUNT_NUMBER),
            pMap.get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER)));

    // if chart code is empty while accounts cannot cross charts, then derive chart code from account number
    AccountService acctserv = SpringContext.getBean(AccountService.class);
    if (StringUtils.isEmpty(getChartOfAccountsCode()) && StringUtils.isNotEmpty(getAccountNumber())
            && !acctserv.accountsCanCrossCharts()) {
        Account account = acctserv.getUniqueAccountForAccountNumber(getAccountNumber());
        if (account != null) {
            setChartOfAccountsCode(account.getChartOfAccountsCode());
        }
    }

    setSubAccountNumber(getValue(line, pMap.get(KFSPropertyConstants.SUB_ACCOUNT_NUMBER),
            pMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE)));
    setFinancialObjectCode(getValue(line, pMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_CODE),
            pMap.get(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE)));
    setFinancialSubObjectCode(getValue(line, pMap.get(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE),
            pMap.get(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE)));
    setFinancialBalanceTypeCode(getValue(line, pMap.get(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE),
            pMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE)));
    setFinancialObjectTypeCode(getValue(line, pMap.get(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE),
            pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE)));
    setUniversityFiscalPeriodCode(getValue(line, pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE),
            pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE)));
    setFinancialDocumentTypeCode(getValue(line, pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE),
            pMap.get(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE)));
    setFinancialSystemOriginationCode(
            getValue(line, pMap.get(KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE),
                    pMap.get(KFSPropertyConstants.DOCUMENT_NUMBER)));
    setDocumentNumber(getValue(line, pMap.get(KFSPropertyConstants.DOCUMENT_NUMBER),
            pMap.get(KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER)));

    // don't trim sequenceNumber because SpaceTransactionEntrySequenceNumber is "     "
    if (!GeneralLedgerConstants.getSpaceTransactionEntrySequenceNumber()
            .equals(line.substring(pMap.get(KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER),
                    pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC)))
            && !GeneralLedgerConstants.getZeroTransactionEntrySequenceNumber()
                    .equals(getValue(line, pMap.get(KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER),
                            pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC)))) {
        try {
            setTransactionLedgerEntrySequenceNumber(new Integer(StringUtils
                    .trim(getValue(line, pMap.get(KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER),
                            pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC)))));
        } catch (NumberFormatException e) {
            returnList.add(new Message("Transaction Sequence Number '"
                    + line.substring(pMap.get(KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER),
                            pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC))
                    + "' contains an invalid value.", Message.TYPE_FATAL));
            setTransactionLedgerEntrySequenceNumber(null);
        }
    } else {
        setTransactionLedgerEntrySequenceNumber(null);
    }

    setTransactionLedgerEntryDescription(
            getValue(line, pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC),
                    pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT)));

    if (!getValue(line, pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT),
            pMap.get(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE))
                    .equals(GeneralLedgerConstants.EMPTY_CODE)) {
        try {
            setTransactionLedgerEntryAmount(new KualiDecimal(
                    getValue(line, pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT),
                            pMap.get(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE)).trim()));
        } catch (NumberFormatException e) {
            returnList.add(new Message("Transaction Amount '"
                    + line.substring(pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT),
                            pMap.get(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE))
                    + "' contains an invalid value.", Message.TYPE_FATAL));
            setTransactionLedgerEntryAmount(KualiDecimal.ZERO);
        }
    } else {
        returnList.add(new Message("Transaction Amount cannot be blank.", Message.TYPE_FATAL));
        setTransactionLedgerEntryAmount(KualiDecimal.ZERO);
    }

    setTransactionDebitCreditCode(line.substring(pMap.get(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE),
            pMap.get(KFSPropertyConstants.TRANSACTION_DATE)));

    if (!getValue(line, pMap.get(KFSPropertyConstants.TRANSACTION_DATE),
            pMap.get(KFSPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER))
                    .equals(GeneralLedgerConstants.EMPTY_CODE)) {
        // FSKD-193, KFSMI-5441
        try {
            setTransactionDate(parseDate(getValue(line, pMap.get(KFSPropertyConstants.TRANSACTION_DATE),
                    pMap.get(KFSPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER)), false));
        } catch (ParseException e) {
            setTransactionDate(SpringContext.getBean(DateTimeService.class).getCurrentSqlDate());
        }
    } else {
        setTransactionDate(null);
    }

    setOrganizationDocumentNumber(getValue(line, pMap.get(KFSPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER),
            pMap.get(KFSPropertyConstants.PROJECT_CODE)));
    setProjectCode(getValue(line, pMap.get(KFSPropertyConstants.PROJECT_CODE),
            pMap.get(KFSPropertyConstants.ORGANIZATION_REFERENCE_ID)));
    setOrganizationReferenceId(getValue(line, pMap.get(KFSPropertyConstants.ORGANIZATION_REFERENCE_ID),
            pMap.get(KFSPropertyConstants.REFERENCE_FIN_DOCUMENT_TYPE_CODE)));
    setReferenceFinancialDocumentTypeCode(
            getValue(line, pMap.get(KFSPropertyConstants.REFERENCE_FIN_DOCUMENT_TYPE_CODE),
                    pMap.get(KFSPropertyConstants.FIN_SYSTEM_REF_ORIGINATION_CODE)));
    setReferenceFinancialSystemOriginationCode(
            getValue(line, pMap.get(KFSPropertyConstants.FIN_SYSTEM_REF_ORIGINATION_CODE),
                    pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_REFERENCE_NBR)));
    setReferenceFinancialDocumentNumber(
            getValue(line, pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_REFERENCE_NBR),
                    pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE)));

    if (!getValue(line, pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE),
            pMap.get(KFSPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD))
                    .equals(GeneralLedgerConstants.EMPTY_CODE)) {
        try {
            setFinancialDocumentReversalDate(
                    parseDate(getValue(line, pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE),
                            pMap.get(KFSPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD)), false));
        } catch (ParseException e) {
            setFinancialDocumentReversalDate(null);
            returnList.add(new Message("Reversal Date '"
                    + line.substring(pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE),
                            pMap.get(KFSPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD))
                    + "' contains an invalid value.", Message.TYPE_FATAL));

        }
    } else {
        setFinancialDocumentReversalDate(null);
    }

    //set till end
    setTransactionEncumbranceUpdateCode(
            line.substring(pMap.get(KFSPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD),
                    GeneralLedgerConstants.getSpaceAllOriginEntryFields().length()));

    return returnList;
}

From source file:org.kuali.coeus.org.kuali.rice.krad.uif.container.KcLightTable.java

/**
 * Special handling of the InputField in the row, replaces necessary content with row specific content
 *
 * @param item the item being processed//from  w w  w  .j ava  2 s . co  m
 * @param obj the row's object model
 * @param row the row in html
 * @param index the current row index
 * @param originalId the original id of the component item
 * @return the updated row
 */
protected String handleInputFieldInRow(Component item, Object obj, String row, int index, String originalId) {
    if (!(item instanceof InputField) || ((InputField) item).getControl() == null) {
        return row;
    }

    Control control = ((InputField) item).getControl();

    //updates the name path to the current path for any instance this item's propertyName with
    //a collection binding prefix
    row = row.replace("name=\"" + ((InputField) item).getBindingInfo().getBindingPath() + "\"",
            "name=\"" + this.getBindingInfo().getBindingPath() + "[" + index + "]."
                    + ((InputField) item).getPropertyName() + "\"");

    Object value = ObjectPropertyUtils.getPropertyValue(obj, ((InputField) item).getPropertyName());
    String stringValue = "";

    if (value == null) {
        stringValue = "";
    } else if (value.getClass().isAssignableFrom(boolean.class)) {
        stringValue = "" + value;
    } else if (!(value instanceof Collection)) {
        stringValue = ObjectPropertyUtils.getPropertyValueAsText(obj, ((InputField) item).getPropertyName());
    }

    String controlId = originalId + "_line" + index + UifConstants.IdSuffixes.CONTROL;

    if (control instanceof CheckboxControl && stringValue.equalsIgnoreCase("true")) {
        //CheckboxControl handling - only replace if true with a checked attribute appended
        row = row.replaceAll("(id(\\s)*?=(\\s)*?\"" + controlId + "\")", "$1 checked=\"checked\" ");
    } else if (control instanceof TextControl) {
        //TextControl handling - replace with
        row = row.replaceAll("(id(\\s)*?=(\\s)*?\"" + controlId + "\"(.|\\s)*?value=\")(.|\\s)*?\"",
                "$1" + stringValue + "\"");
    } else if (control instanceof SelectControl && !((SelectControl) control).isMultiple()) {
        //SelectControl handling (single item only)
        Pattern pattern = Pattern
                .compile("<select(\\s)*?id(\\s)*?=(\\s)*?\"" + controlId + "\"(.|\\s)*?</select>");
        Matcher matcher = pattern.matcher(row);
        String replacement = "";

        if (matcher.find()) {
            //remove selected from select options
            String selected = "selected=\"selected\"";
            replacement = matcher.group().replace(selected, "");

            //put selected on only the selected option
            String selectedValue = "value=\"" + stringValue + "\"";
            replacement = replacement.replace(selectedValue, selectedValue + " " + selected);
        }

        //replace the old select tag with the old one
        if (StringUtils.isNotBlank(replacement)) {
            row = matcher.replaceAll(replacement);
        }
    }

    currentColumnValue = stringValue;

    return row;
}

From source file:org.apache.hadoop.hive.ql.QOutProcessor.java

public LineProcessingResult processLine(String line, String tname) {
    LineProcessingResult result = new LineProcessingResult(line);

    Matcher matcher = null;

    if (fsType == FsType.encrypted_hdfs) {
        for (Pattern pattern : partialReservedPlanMask) {
            matcher = pattern.matcher(result.line);
            if (matcher.find()) {
                result.line = PARTIAL_MASK_PATTERN + " " + matcher.group(0);
                result.partialMaskWasMatched = true;
                break;
            }/*from  ww w.j  a  v  a  2  s.  c  o m*/
        }
    } else {
        for (PatternReplacementPair prp : partialPlanMask) {
            matcher = prp.pattern.matcher(result.line);
            if (matcher.find()) {
                result.line = result.line.replaceAll(prp.pattern.pattern(), prp.replacement);
                result.partialMaskWasMatched = true;
            }
        }
    }

    if (!result.partialMaskWasMatched) {
        for (Pair<Pattern, String> pair : patternsWithMaskComments) {
            Pattern pattern = pair.getLeft();
            String maskComment = pair.getRight();

            matcher = pattern.matcher(result.line);
            if (matcher.find()) {
                result.line = matcher.replaceAll(maskComment);
                result.partialMaskWasMatched = true;
                break;
            }
        }

        if (!result.partialMaskWasMatched && qMaskStatsQuerySet.contains(tname)) {
            matcher = MASK_STATS.pattern.matcher(result.line);
            if (matcher.find()) {
                result.line = result.line.replaceAll(MASK_STATS.pattern.pattern(), MASK_STATS.replacement);
                result.partialMaskWasMatched = true;
            }
        }

        if (!result.partialMaskWasMatched && qMaskDataSizeQuerySet.contains(tname)) {
            matcher = MASK_DATA_SIZE.pattern.matcher(result.line);
            if (matcher.find()) {
                result.line = result.line.replaceAll(MASK_DATA_SIZE.pattern.pattern(),
                        MASK_DATA_SIZE.replacement);
                result.partialMaskWasMatched = true;
            }
        }

        if (!result.partialMaskWasMatched && qMaskLineageQuerySet.contains(tname)) {
            matcher = MASK_LINEAGE.pattern.matcher(result.line);
            if (matcher.find()) {
                result.line = result.line.replaceAll(MASK_LINEAGE.pattern.pattern(), MASK_LINEAGE.replacement);
                result.partialMaskWasMatched = true;
            }
        }

        for (Pattern pattern : planMask) {
            result.line = pattern.matcher(result.line).replaceAll(MASK_PATTERN);
        }
    }

    return result;
}

From source file:gate.pr.automate.AutomateCiriRating.java

private String getSubSectionExists(String sentString) {

    String separator_1 = "Country Reports on Human Rights";
    String separator_2 = "Bureau of Democracy, Human Rights and Labor";

    ArrayList<String> headerList = new ArrayList<String>();

    headerList.add(ReportConstants.KILL_SUBSECTION);
    headerList.add(ReportConstants.DISAP_SUBSECTION);
    headerList.add(ReportConstants.TORT_SUBSECTION);
    headerList.add(ReportConstants.POLPRIS_SUBSECTION);

    for (String subSection : headerList) {

        if (sentString.contains(subSection)) {
            int subSectionIndex = sentString.indexOf(subSection);

            String replaceSection = sentString.substring(0, subSectionIndex + subSection.length());
            sentString = sentString.replace(replaceSection, "");
        }//from   w w  w.java 2 s  .  c om

        if (sentString.contains(separator_1) && sentString.contains(separator_2)) {

            int subString_1 = sentString.indexOf(separator_1);
            int subString_2 = sentString.indexOf(separator_2);
            int subLength_2 = separator_2.length();

            String replaceSub = sentString.substring(subString_1, subString_2 + subLength_2);

            sentString = sentString.replace(replaceSub, "");
        }

        String regex = "\\b[A-Z]+[\\s]+[0-9]+\\b";
        Pattern pattern = Pattern.compile(regex);

        Matcher matches = pattern.matcher(sentString);

        if (matches.find()) {

            sentString = matches.replaceAll("");
        }

    }

    return sentString.trim();

}

From source file:com.clustercontrol.jobmanagement.factory.JobSessionNodeImpl.java

/**
 * ?????// www . j  a  v  a  2  s  .com
 * @param sessionNode
 * @param newMsg
 */
public void setMessage(JobSessionNodeEntity sessionNode, String newMsg) {
    String msg;
    Date date = HinemosTime.getDateInstance();
    SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    df.setTimeZone(HinemosTime.getTimeZone());
    String dateStr = df.format(date);
    String header = "[" + dateStr + "] ";
    String oldMsg = sessionNode.getMessage();

    //??????????
    Pattern pattern = Pattern.compile("\r\n$");
    Matcher m = pattern.matcher(newMsg);
    if (m.find() == false) {
        pattern = Pattern.compile("\n$");
        m = pattern.matcher(newMsg);
    }
    newMsg = m.replaceAll("");

    if (oldMsg == null || oldMsg.equals("")) {
        msg = header + newMsg;
    } else {
        //??????
        msg = header + newMsg + "\r\n" + oldMsg;
    }

    //???
    int msgMaxLen = HinemosPropertyUtil.getHinemosPropertyNum("job.message.max.length", Long.valueOf(2048))
            .intValue();
    if (msg.length() > msgMaxLen) {
        msg = msg.substring(0, msgMaxLen);
    }
    sessionNode.setMessage(msg);
}

From source file:com.untangle.app.branding_manager.BrandingManagerApp.java

/**
 * Using the non-branded version from uvm as a template base, modify
 * images and text to reflect branding.//ww  w . j a v  a 2 s . c  o m
 */
private void createRootCaInstaller() {
    /*
     * Use the non-branded version as a template base.  Copy over.
     */
    UvmContextFactory.context().execManager().exec("rm -rf " + ROOT_CA_INSTALLER_DIRECTORY_NAME + "; cp -fa "
            + CertificateManager.ROOT_CA_INSTALLER_DIRECTORY_NAME + " " + ROOT_CA_INSTALLER_DIRECTORY_NAME);

    /*
     * Convert images to .bmp format
     */
    UvmContextFactory.context().execManager().exec("anytopnm " + BRANDING_LOGO + " | ppmtobmp > "
            + ROOT_CA_INSTALLER_DIRECTORY_NAME + "/images/modern-header.bmp");
    UvmContextFactory.context().execManager().exec("anytopnm " + BRANDING_LOGO + " | pnmrotate 90 | ppmtobmp > "
            + ROOT_CA_INSTALLER_DIRECTORY_NAME + "/images/modern-wizard.bmp");

    /*
     * Parse files replacing Untangle defaults
     */
    String companyName = settings.getCompanyName();
    String companyUrl = settings.getCompanyUrl();
    for (Map.Entry<FILE_PARSE_TYPE, String> filenameSet : ROOT_CA_INSTALLER_PARSE_FILE_NAMES.entrySet()) {
        String filename = filenameSet.getValue();
        File file = new File(filename);
        String name = file.getName();
        HashMap<REGEX_TYPE, Pattern> regexes = new HashMap<>();
        String quotedString = "";
        int flags = 0;
        if (filenameSet.getKey() == FILE_PARSE_TYPE.QUOTED) {
            quotedString = "\"";
        } else {
            flags = Pattern.CASE_INSENSITIVE;
        }

        /*
         * Build up regexes to find the first occurance of our current name.
         */
        regexes.put(REGEX_TYPE.COMPANY_NAME, Pattern.compile(
                "(" + quotedString + ".*?)" + DEFAULT_UNTANGLE_COMPANY_NAME + "(.*" + quotedString + ")",
                flags));
        regexes.put(REGEX_TYPE.COMPANY_URL, Pattern.compile(
                "(" + quotedString + ".*?)" + "http://.*.untangle.com(.*" + quotedString + ")", flags));

        StringBuilder parsed = new StringBuilder();
        Matcher match = null;
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(filename));
            for (String line = reader.readLine(); null != line; line = reader.readLine()) {
                /*
                 * When parsing the nsi file we only want to replace strings within quotes and
                 * for other files, everything.
                 */
                for (Map.Entry<REGEX_TYPE, Pattern> regex : regexes.entrySet()) {
                    match = regex.getValue().matcher(line);
                    int startPos = 0;
                    while (match.find(startPos)) {
                        switch (regex.getKey()) {
                        case COMPANY_NAME:
                            startPos = match.start() + match.group(1).length() + companyName.length();
                            line = match.replaceAll("$1" + companyName + "$2");
                            break;
                        case COMPANY_URL:
                            startPos = match.start() + match.group(1).length() + companyUrl.length();
                            line = match.replaceAll("$1" + companyUrl + "$2");
                            break;

                        default:
                            /* Shouldn'e be here...but if we are, make sure we exit the loop. */
                            startPos = line.length();
                        }
                        if (startPos >= line.length()) {
                            break;
                        }
                        match = regex.getValue().matcher(line);
                    }
                }
                parsed.append(line).append(EOL);
            }
        } catch (Exception x) {
            logger.warn("Unable to open installer configuration file: " + filename);
            return;
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (Exception x) {
                    logger.warn("Unable to close installer configuration file: " + filename);
                }
            }
        }

        FileOutputStream fos = null;
        File tmp = null;
        try {
            tmp = File.createTempFile(file.getName(), ".tmp");
            fos = new FileOutputStream(tmp);
            fos.write(parsed.toString().getBytes());
            fos.flush();
            fos.close();
            IOUtil.copyFile(tmp, new File(filename));
            tmp.delete();
        } catch (Exception ex) {
            IOUtil.close(fos);
            tmp.delete();
            logger.error("Unable to create installer file:" + filename + ":", ex);
        }
    }

    /*
     * Regenerate
     */
    UvmContextFactory.context().execManager().exec(CertificateManager.ROOT_CA_INSTALLER_SCRIPT);
}