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:org.languagetool.JLanguageTool.java

private Map<Integer, String> replaceSoftHyphens(List<String> tokens) {
    Pattern ignoredCharacterRegex = language.getIgnoredCharactersRegex();
    Map<Integer, String> ignoredCharsTokens = new HashMap<>();
    if (ignoredCharacterRegex == null) {
        return ignoredCharsTokens;
    }//www . j  a va2  s  .  c  om
    for (int i = 0; i < tokens.size(); i++) {
        Matcher matcher = ignoredCharacterRegex.matcher(tokens.get(i));
        if (matcher.find()) {
            ignoredCharsTokens.put(i, tokens.get(i));
            tokens.set(i, matcher.replaceAll(""));
        }
    }
    return ignoredCharsTokens;
}

From source file:net.longfalcon.newsj.FetchBinaries.java

@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
public long scan(NewsClient nntpClient, Group group, long firstArticle, long lastArticle, String type,
        boolean compressedHeaders) throws IOException {
    // this is a hack - tx is not working ATM
    TransactionStatus transaction = transactionManager
            .getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED));

    long startHeadersTime = System.currentTimeMillis();

    long maxNum = 0;
    Map<String, Message> messages = new LinkedHashMap<>(MESSAGE_BUFFER + 1);

    Iterable<NewsArticle> articlesIterable = null;
    try {/*w w w  .  j a  v  a  2  s  .c o m*/
        if (compressedHeaders) {
            _log.warn("Compressed Headers setting not currently functional");
            articlesIterable = nntpClient.iterateArticleInfo(firstArticle, lastArticle);
        } else {
            articlesIterable = nntpClient.iterateArticleInfo(firstArticle, lastArticle);
        }
    } catch (IOException e) {
        _log.error(e.toString());
        if (nntpClient.getReplyCode() == 400) {
            _log.info("NNTP connection timed out. Reconnecting...");
            nntpClient = nntpConnectionFactory.getNntpClient();
            nntpClient.selectNewsgroup(group.getName());
            articlesIterable = nntpClient.iterateArticleInfo(firstArticle, lastArticle);
        }
    }

    Period headersTime = new Period(startHeadersTime, System.currentTimeMillis());

    Set<Long> rangeRequested = ArrayUtil.rangeSet(firstArticle, lastArticle);
    Set<Long> messagesReceived = new HashSet<>();
    Set<Long> messagesBlacklisted = new HashSet<>();
    Set<Long> messagesIgnored = new HashSet<>();
    Set<Long> messagesInserted = new HashSet<>();
    Set<Long> messagesNotInserted = new HashSet<>();

    // check error codes?

    long startUpdateTime = System.currentTimeMillis();

    if (articlesIterable != null) {
        for (NewsArticle article : articlesIterable) {
            long articleNumber = article.getArticleNumberLong();

            if (articleNumber == 0) {
                continue;
            }

            messagesReceived.add(articleNumber);

            Pattern pattern = Defaults.PARTS_SUBJECT_REGEX;
            String subject = article.getSubject();
            Matcher matcher = pattern.matcher(subject);
            if (ValidatorUtil.isNull(subject) || !matcher.find()) {
                // not a binary post most likely.. continue
                messagesIgnored.add(articleNumber);
                if (_log.isDebugEnabled()) {
                    _log.debug(String.format("Skipping message no# %s : %s", articleNumber, subject));
                }
                continue;
            }

            //Filter binaries based on black/white list
            if (isBlacklisted(article, group)) {
                messagesBlacklisted.add(articleNumber);
                continue;
            }
            String group1 = matcher.group(1);
            String group2 = matcher.group(2);
            if (ValidatorUtil.isNumeric(group1) && ValidatorUtil.isNumeric(group2)) {
                int currentPart = Integer.parseInt(group1);
                int maxParts = Integer.parseInt(group2);
                subject = (matcher.replaceAll("")).trim();

                if (!messages.containsKey(subject)) {
                    messages.put(subject, new Message(article, currentPart, maxParts));
                } else if (currentPart > 0) {
                    Message message = messages.get(subject);
                    String articleId = article.getArticleId();
                    String messageId = articleId.substring(1, articleId.length() - 1);
                    int size = article.getSize();
                    message.addPart(currentPart, messageId, articleNumber, size);
                    messages.put(subject, message);
                }
            }
        }

        long count = 0;
        long updateCount = 0;
        long partCount = 0;
        maxNum = lastArticle;

        // add all the requested then remove the ones we did receive.
        Set<Long> rangeNotRecieved = new HashSet<>();
        rangeNotRecieved.addAll(rangeRequested);
        rangeNotRecieved.removeAll(messagesReceived);

        if (!type.equals("partrepair")) {
            _log.info(String.format("Received %d articles of %d requested, %d blacklisted, %d not binaries",
                    messagesReceived.size(), lastArticle - firstArticle + 1, messagesBlacklisted.size(),
                    messagesIgnored.size()));
        }

        if (rangeNotRecieved.size() > 0) {
            switch (type) {
            case "backfill":
                // don't add missing articles
                break;
            case "partrepair":
            case "update":
            default:
                addMissingParts(rangeNotRecieved, group);
                break;
            }
            _log.info("Server did not return article numbers " + ArrayUtil.stringify(rangeNotRecieved));
        }

        if (!messages.isEmpty()) {

            long dbUpdateTime = 0;
            maxNum = firstArticle;
            //insert binaries and parts into database. when binary already exists; only insert new parts
            for (Map.Entry<String, Message> entry : messages.entrySet()) {
                String subject = entry.getKey();
                Message message = entry.getValue();

                Map<Integer, MessagePart> partsMap = message.getPartsMap();
                if (!ValidatorUtil.isNull(subject) && !partsMap.isEmpty()) {
                    String binaryHash = EncodingUtil
                            .md5Hash(subject + message.getFrom() + String.valueOf(group.getId()));
                    Binary binary = binaryDAO.findByBinaryHash(binaryHash);
                    if (binary == null) {
                        long startDbUpdateTime = System.currentTimeMillis();
                        binary = new Binary();
                        binary.setName(subject);
                        binary.setFromName(message.getFrom());
                        binary.setDate(message.getDate().toDate());
                        binary.setXref(message.getxRef());
                        binary.setTotalParts(message.getMaxParts());
                        binary.setGroupId(group.getId());
                        binary.setBinaryHash(binaryHash);
                        binary.setDateAdded(new Date());
                        binaryDAO.updateBinary(binary);
                        dbUpdateTime += (System.currentTimeMillis() - startDbUpdateTime);
                        count++;
                        if (count % 500 == 0) {
                            _log.info(String.format("%s bin adds...", count));
                        }
                    } else {
                        updateCount++;
                        if (updateCount % 500 == 0) {
                            _log.info(String.format("%s bin updates...", updateCount));
                        }
                    }

                    long binaryId = binary.getId();
                    if (binaryId == 0) {
                        throw new RuntimeException("ID for binary wasnt set.");
                    }

                    for (MessagePart messagePart : message.getPartsMap().values()) {
                        long articleNumber = messagePart.getArticleNumber();
                        maxNum = (articleNumber > maxNum) ? articleNumber : maxNum;
                        partCount++;
                        // create part - its possible some bugs are happening here.
                        Part part = new Part();
                        part.setBinaryId(binaryId);
                        part.setMessageId(messagePart.getMessageId());
                        part.setNumber(messagePart.getArticleNumber());
                        part.setPartNumber(messagePart.getPartNumber());
                        part.setSize(messagePart.getSize());
                        part.setDateAdded(new Date());
                        try {
                            long startDbUpdateTime = System.currentTimeMillis();
                            partDAO.updatePart(part);
                            dbUpdateTime += (System.currentTimeMillis() - startDbUpdateTime);
                            messagesInserted.add(messagePart.getArticleNumber());
                        } catch (Exception e) {
                            _log.error(e.toString());
                            messagesNotInserted.add(messagePart.getArticleNumber());
                        }

                    }
                }
            }
            //TODO: determine whether to add to missing articles if insert failed
            if (messagesNotInserted.size() > 0) {
                _log.warn("WARNING: Parts failed to insert");
                addMissingParts(messagesNotInserted, group);
            }
            Period dbUpdatePeriod = new Period(dbUpdateTime);
            _log.info("Spent " + _periodFormatter.print(dbUpdatePeriod) + " updating the db");
        }
        Period updateTime = new Period(startUpdateTime, System.currentTimeMillis());

        if (!type.equals("partrepair")) {
            _log.info(count + " new, " + updateCount + " updated, " + partCount + " parts.");
            _log.info(" " + _periodFormatter.print(headersTime) + " headers, "
                    + _periodFormatter.print(updateTime) + " update.");
        }
        transactionManager.commit(transaction);
        return maxNum;
    } else {
        _log.error("Error: Can't get parts from server (msgs not array)\n Skipping group");
        return 0;
    }

}

From source file:org.languagetool.tagging.uk.CompoundTagger.java

@Nullable
private List<AnalyzedToken> tagMatch(String word, List<AnalyzedToken> leftAnalyzedTokens,
        List<AnalyzedToken> rightAnalyzedTokens) {
    List<AnalyzedToken> newAnalyzedTokens = new ArrayList<>();
    List<AnalyzedToken> newAnalyzedTokensAnimInanim = new ArrayList<>();

    String animInanimNotTagged = null;

    for (AnalyzedToken leftAnalyzedToken : leftAnalyzedTokens) {
        String leftPosTag = leftAnalyzedToken.getPOSTag();

        if (leftPosTag == null || IPOSTag.contains(leftPosTag, IPOSTag.abbr.getText()))
            continue;

        // we don't want to have v_kly for -?
        // but we do for -
        if (leftPosTag.startsWith("noun:inanim") && leftPosTag.contains("v_kly"))
            continue;

        String leftPosTagExtra = "";
        boolean leftNv = false;

        if (leftPosTag.contains(PosTagHelper.NO_VIDMINOK_SUBSTR)) {
            leftNv = true;//from   w w  w  .  j av a 2  s.c o  m
            leftPosTag = leftPosTag.replace(PosTagHelper.NO_VIDMINOK_SUBSTR, "");
        }

        Matcher matcher = EXTRA_TAGS_DROP.matcher(leftPosTag);
        if (matcher.find()) {
            leftPosTag = matcher.replaceAll("");
        }

        matcher = EXTRA_TAGS.matcher(leftPosTag);
        if (matcher.find()) {
            leftPosTagExtra += matcher.group();
            leftPosTag = matcher.replaceAll("");
        }

        for (AnalyzedToken rightAnalyzedToken : rightAnalyzedTokens) {
            String rightPosTag = rightAnalyzedToken.getPOSTag();

            if (rightPosTag == null
                    //            || rightPosTag.contains("v_kly")
                    || rightPosTag.contains(IPOSTag.abbr.getText()))
                continue;

            if (rightPosTag.startsWith("noun:inanim") && rightPosTag.contains("v_kly"))
                continue;

            String extraNvTag = "";
            boolean rightNv = false;
            if (rightPosTag.contains(PosTagHelper.NO_VIDMINOK_SUBSTR)) {
                rightNv = true;

                if (leftNv) {
                    extraNvTag += PosTagHelper.NO_VIDMINOK_SUBSTR;
                }
            }

            Matcher matcherR = EXTRA_TAGS_DROP.matcher(rightPosTag);
            if (matcherR.find()) {
                rightPosTag = matcherR.replaceAll("");
            }

            matcherR = EXTRA_TAGS.matcher(rightPosTag);
            if (matcherR.find()) {
                rightPosTag = matcherR.replaceAll("");
            }

            if (stripPerfImperf(leftPosTag).equals(stripPerfImperf(rightPosTag)) && (IPOSTag
                    .startsWith(leftPosTag, IPOSTag.numr, IPOSTag.adv, IPOSTag.adj, IPOSTag.verb)
                    || (IPOSTag.startsWith(leftPosTag, IPOSTag.intj)
                            && leftAnalyzedToken.getLemma().equalsIgnoreCase(rightAnalyzedToken.getLemma())))) {
                String newPosTag = leftPosTag + extraNvTag + leftPosTagExtra;

                if ((leftPosTag.contains("adjp") && !rightPosTag.contains("adjp"))
                        || (!leftPosTag.contains("adjp") && rightPosTag.contains("adjp"))) {
                    newPosTag = newPosTag.replaceFirst(":&adjp:(actv|pasv):(im)?perf", "");
                }

                String newLemma = leftAnalyzedToken.getLemma() + "-" + rightAnalyzedToken.getLemma();
                newAnalyzedTokens.add(new AnalyzedToken(word, newPosTag, newLemma));
            }
            // noun-noun
            else if (leftPosTag.startsWith(IPOSTag.noun.getText())
                    && rightPosTag.startsWith(IPOSTag.noun.getText())) {

                // discard - as noun:anim
                if (leftAnalyzedToken.getToken().equalsIgnoreCase(rightAnalyzedToken.getToken())
                        && leftPosTag.contains(TAG_ANIM) && rightPosTag.contains(TAG_ANIM))
                    continue;

                String agreedPosTag = getAgreedPosTag(leftPosTag, rightPosTag, leftNv, word);

                if (agreedPosTag == null && rightPosTag.startsWith("noun:inanim:m:v_naz")
                        && isMinMax(rightAnalyzedToken.getToken())) {
                    agreedPosTag = leftPosTag;
                }

                if (agreedPosTag == null && !isSameAnimStatus(leftPosTag, rightPosTag)) {

                    agreedPosTag = tryAnimInanim(leftPosTag, rightPosTag, leftAnalyzedToken.getLemma(),
                            rightAnalyzedToken.getLemma(), leftNv, rightNv, word);

                    if (agreedPosTag == null) {
                        animInanimNotTagged = leftPosTag.contains(":anim") ? "anim-inanim" : "inanim-anim";
                    } else {
                        newAnalyzedTokensAnimInanim
                                .add(new AnalyzedToken(word, agreedPosTag + extraNvTag + leftPosTagExtra,
                                        leftAnalyzedToken.getLemma() + "-" + rightAnalyzedToken.getLemma()));
                        continue;
                    }
                }

                if (agreedPosTag != null) {
                    newAnalyzedTokens.add(new AnalyzedToken(word, agreedPosTag + extraNvTag + leftPosTagExtra,
                            leftAnalyzedToken.getLemma() + "-" + rightAnalyzedToken.getLemma()));
                }
            }
            // numr-numr: -
            else if (leftPosTag.startsWith(IPOSTag.numr.getText())
                    && rightPosTag.startsWith(IPOSTag.numr.getText())) {
                String agreedPosTag = getNumAgreedPosTag(leftPosTag, rightPosTag, leftNv);
                if (agreedPosTag != null) {
                    newAnalyzedTokens.add(new AnalyzedToken(word, agreedPosTag + extraNvTag + leftPosTagExtra,
                            leftAnalyzedToken.getLemma() + "-" + rightAnalyzedToken.getLemma()));
                }
            }
            // noun-numr match
            else if (IPOSTag.startsWith(leftPosTag, IPOSTag.noun)
                    && IPOSTag.startsWith(rightPosTag, IPOSTag.numr)) {
                // gender tags match
                String leftGenderConj = PosTagHelper.getGenderConj(leftPosTag);
                if (leftGenderConj != null && leftGenderConj.equals(PosTagHelper.getGenderConj(rightPosTag))) {
                    newAnalyzedTokens.add(new AnalyzedToken(word, leftPosTag + extraNvTag + leftPosTagExtra,
                            leftAnalyzedToken.getLemma() + "-" + rightAnalyzedToken.getLemma()));
                    // -   ?    :  -,  -
                    if (!leftPosTag.contains(":p:")) {
                        newAnalyzedTokens.add(new AnalyzedToken(word,
                                leftPosTag.replaceAll(":[mfn]:", ":p:") + extraNvTag + leftPosTagExtra,
                                leftAnalyzedToken.getLemma() + "-" + rightAnalyzedToken.getLemma()));
                    }
                } else {
                    // (with different gender tags): ? (:p:) -  (:f:)
                    String agreedPosTag = getNumAgreedPosTag(leftPosTag, rightPosTag, leftNv);
                    if (agreedPosTag != null) {
                        newAnalyzedTokens
                                .add(new AnalyzedToken(word, agreedPosTag + extraNvTag + leftPosTagExtra,
                                        leftAnalyzedToken.getLemma() + "-" + rightAnalyzedToken.getLemma()));
                        // -   ?    :  -,  -
                        if (!agreedPosTag.contains(":p:")) {
                            newAnalyzedTokens.add(new AnalyzedToken(word,
                                    agreedPosTag.replaceAll(":[mfn]:", ":p:") + extraNvTag + leftPosTagExtra,
                                    leftAnalyzedToken.getLemma() + "-" + rightAnalyzedToken.getLemma()));
                        }
                    }
                }
            }
            // noun-adj match: -, -
            //   -?   noun-adj    ?
            else if (leftPosTag.startsWith(IPOSTag.noun.getText())
                    && IPOSTag.startsWith(rightPosTag, IPOSTag.numr)
                    || (IPOSTag.startsWith(rightPosTag, IPOSTag.adj)
                            && isJuniorSenior(leftAnalyzedToken, rightAnalyzedToken))) {

                //          if( ! leftPosTag.contains(":prop")
                //              || isJuniorSenior(leftAnalyzedToken, rightAnalyzedToken) ) { 

                // discard - as noun:anim
                //             if( leftAnalyzedToken.getToken().equalsIgnoreCase(rightAnalyzedToken.getToken()) )
                //                continue;

                String leftGenderConj = PosTagHelper.getGenderConj(leftPosTag);
                if (leftGenderConj != null && leftGenderConj.equals(PosTagHelper.getGenderConj(rightPosTag))) {
                    newAnalyzedTokens.add(new AnalyzedToken(word, leftPosTag + extraNvTag + leftPosTagExtra,
                            leftAnalyzedToken.getLemma() + "-" + rightAnalyzedToken.getLemma()));
                }
                //        }
            }
        }
    }

    if (!newAnalyzedTokens.isEmpty() && !PosTagHelper.hasPosTagPart(newAnalyzedTokens, ":p:")) {
        if ((LemmaHelper.hasLemma(leftAnalyzedTokens, LemmaHelper.DAYS_OF_WEEK)
                && LemmaHelper.hasLemma(rightAnalyzedTokens, LemmaHelper.DAYS_OF_WEEK))
                || (LemmaHelper.hasLemma(leftAnalyzedTokens, LemmaHelper.MONTH_LEMMAS)
                        && LemmaHelper.hasLemma(rightAnalyzedTokens, LemmaHelper.MONTH_LEMMAS))) {
            newAnalyzedTokens.add(
                    new AnalyzedToken(word, newAnalyzedTokens.get(0).getPOSTag().replaceAll(":[mfn]:", ":p:"),
                            newAnalyzedTokens.get(0).getLemma()));
        }
    }

    // remove duplicates
    newAnalyzedTokens = new ArrayList<>(new LinkedHashSet<>(newAnalyzedTokens));

    if (newAnalyzedTokens.isEmpty()) {
        newAnalyzedTokens = newAnalyzedTokensAnimInanim;
    }

    if (animInanimNotTagged != null && newAnalyzedTokens.isEmpty()) {
        compoundDebugLogger.logUnknownCompound(word + " " + animInanimNotTagged);
    }

    return newAnalyzedTokens.isEmpty() ? null : newAnalyzedTokens;
}

From source file:com.ibm.bi.dml.test.utils.TestUtils.java

/**
 * <p>//from   w w  w  . j a  v  a 2 s  . c  o m
 * Replaces variables in a DML or R script with the specified values. A
 * variable of format ##name## will be replaced where the name is used to
 * identify the variable in the hashmap containing the belonging value.
 * </p>
 * 
 * @param strScriptDirectory
 *            directory which contains the DML script
 * @param strScriptFile
 *            filename of the DML script
 * @param variables
 *            hashmap containing all the variables and their replacements
 * @deprecated Use ParameterBuilder.setVariablesInScript instead
 */
public static void setVariablesInScript(String strScriptDirectory, String strScriptFile,
        HashMap<String, String> variables) {
    try {
        String strScript = strScriptDirectory + strScriptFile;
        String strTmpScript = strScript + "t";

        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(strScript)));
        FileOutputStream out = new FileOutputStream(strTmpScript);
        PrintWriter pw = new PrintWriter(out);
        String content;
        Pattern unresolvedVars = Pattern.compile(_RS + ".*" + _RS);
        /**
         * sothat variables, which were not assigned, are replaced by an
         * empty string
         */
        while ((content = in.readLine()) != null) {
            for (String variable : variables.keySet()) {
                Pattern pattern = Pattern.compile(_RS + variable + _RS);
                Matcher matcher = pattern.matcher(content);
                while (matcher.find()) {
                    content = content.replaceFirst(matcher.group().replace("$", "\\$"),
                            variables.get(variable));
                }
            }
            Matcher matcher = unresolvedVars.matcher(content);
            content = matcher.replaceAll("");
            pw.println(content);
        }
        pw.close();
        out.close();
        in.close();

        /*
         * // remove checksum files if created Path crcFile = new
         * Path(dmlScriptDirectory + "." + dmlScriptFile + ".crc"); if
         * (fs.exists(crcFile)) fs.delete(crcFile, false); crcFile = new
         * Path(dmlScriptDirectory + "." + dmlScriptFile + "t.crc"); if
         * (fs.exists(crcFile)) fs.delete(crcFile, false);
         */
    } catch (IOException e) {
        e.printStackTrace();
        fail("unable to set variables in dml script: " + e.getMessage());
    }
}

From source file:org.kuali.kfs.module.ld.businessobject.LaborOriginEntry.java

/**
 * Get lines from string//from   w w w.j a v  a 2 s .  com
 */
@Override
public String getLine() {
    StringBuilder sb = new StringBuilder();
    Map<String, Integer> lMap = getLaborOriginEntryFieldUtil().getFieldLengthMap();
    Map<String, Integer> pMap = getLaborOriginEntryFieldUtil().getFieldBeginningPositionMap();
    int entryLength = pMap.get(LaborPropertyConstants.SET_ID) + lMap.get(LaborPropertyConstants.SET_ID);

    if (universityFiscalYear == null) {
        sb.append(GeneralLedgerConstants.getSpaceUniversityFiscalYear());
    } else {
        sb.append(universityFiscalYear);
    }

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

    String seqNum = "";
    if (transactionLedgerEntrySequenceNumber != null) {
        seqNum = transactionLedgerEntrySequenceNumber.toString();
    }
    // Format to a length of 5
    sb.append(StringUtils.leftPad(seqNum.trim(),
            lMap.get(KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER), "0"));

    // Labor Specified fields
    sb.append(getField(lMap.get(KFSPropertyConstants.POSITION_NUMBER), positionNumber));
    sb.append(getField(lMap.get(KFSPropertyConstants.PROJECT_CODE), projectCode));
    sb.append(getField(lMap.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,
                lMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT) - a.length()));
        sb.append(a);
    }

    sb.append(
            getField(lMap.get(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE), transactionDebitCreditCode));
    sb.append(formatDate(transactionDate));
    sb.append(
            getField(lMap.get(KFSPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER), organizationDocumentNumber));
    sb.append(getField(lMap.get(KFSPropertyConstants.ORGANIZATION_REFERENCE_ID), organizationReferenceId));
    sb.append(getField(lMap.get(KFSPropertyConstants.REFERENCE_FIN_DOCUMENT_TYPE_CODE),
            referenceFinancialDocumentTypeCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.FIN_SYSTEM_REF_ORIGINATION_CODE),
            referenceFinancialSystemOriginationCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_REFERENCE_NBR),
            referenceFinancialDocumentNumber));
    sb.append(formatDate(financialDocumentReversalDate));
    sb.append(getField(lMap.get(KFSPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD),
            transactionEncumbranceUpdateCode));
    sb.append(formatDate(transactionPostingDate));
    sb.append(formatDate(payPeriodEndDate));

    if (transactionTotalHours == null) {
        sb.append(StringUtils.rightPad("", lMap.get(KFSPropertyConstants.TRANSACTION_TOTAL_HOURS), " "));
    } else {
        String totalhour = getField(lMap.get(KFSPropertyConstants.TRANSACTION_TOTAL_HOURS),
                transactionTotalHours.toString());
        sb.append(StringUtils.leftPad(totalhour.trim(), lMap.get(KFSPropertyConstants.TRANSACTION_TOTAL_HOURS),
                " "));
    }

    if (payrollEndDateFiscalYear == null) {
        sb.append(StringUtils.rightPad("", lMap.get(KFSPropertyConstants.PAYROLL_END_DATE_FISCAL_YEAR), " "));
    } else {
        sb.append(getField(lMap.get(KFSPropertyConstants.PAYROLL_END_DATE_FISCAL_YEAR),
                payrollEndDateFiscalYear.toString()));
    }

    sb.append(getField(lMap.get(LaborPropertyConstants.PAYROLL_END_DATE_FISCAL_PERIOD_CODE),
            payrollEndDateFiscalPeriodCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.EMPLID), emplid));

    if (employeeRecord == null) {
        sb.append(StringUtils.rightPad("", lMap.get(KFSPropertyConstants.EMPLOYEE_RECORD), " "));
    } else {
        String empRecord = getField(lMap.get(KFSPropertyConstants.EMPLOYEE_RECORD), employeeRecord.toString());
        sb.append(StringUtils.leftPad(empRecord.trim(), lMap.get(KFSPropertyConstants.EMPLOYEE_RECORD), " "));
    }

    sb.append(getField(lMap.get(KFSPropertyConstants.EARN_CODE), earnCode));
    sb.append(getField(lMap.get(KFSPropertyConstants.PAY_GROUP), payGroup));
    sb.append(getField(lMap.get(LaborPropertyConstants.SALARY_ADMINISTRATION_PLAN), salaryAdministrationPlan));
    sb.append(getField(lMap.get(LaborPropertyConstants.GRADE), grade));
    sb.append(getField(lMap.get(LaborPropertyConstants.RUN_IDENTIFIER), runIdentifier));
    sb.append(getField(lMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_CHART_OF_ACCOUNTS_CODE),
            laborLedgerOriginalChartOfAccountsCode));
    sb.append(getField(lMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_ACCOUNT_NUMBER),
            laborLedgerOriginalAccountNumber));
    sb.append(getField(lMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_SUB_ACCOUNT_NUMBER),
            laborLedgerOriginalSubAccountNumber));
    sb.append(getField(lMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_FINANCIAL_OBJECT_CODE),
            laborLedgerOriginalFinancialObjectCode));
    sb.append(getField(lMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_FINANCIAL_SUB_OBJECT_CODE),
            laborLedgerOriginalFinancialSubObjectCode));
    sb.append(getField(lMap.get(LaborPropertyConstants.HRMS_COMPANY), hrmsCompany));
    sb.append(getField(lMap.get(LaborPropertyConstants.SET_ID), setid));

    // pad to full length of 295 chars.
    while (entryLength > 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.module.ld.businessobject.LaborOriginEntry.java

/**
 * Sets the entries from text file.//from  w w  w .j  a  v  a  2s.  c  o m
 */

@Override
public List<Message> setFromTextFileForBatch(String line, int lineNumber) {
    List<Message> returnList = new ArrayList();
    Map<String, Integer> pMap = getLaborOriginEntryFieldUtil().getFieldBeginningPositionMap();
    Map<String, Integer> lMap = getLaborOriginEntryFieldUtil().getFieldLengthMap();
    int entryLength = pMap.get(LaborPropertyConstants.SET_ID) + lMap.get(LaborPropertyConstants.SET_ID);

    // 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, entryLength, ' ');
    String fiscalYearString = line.substring(pMap.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR),
            pMap.get(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE));
    if (!GeneralLedgerConstants.getSpaceUniversityFiscalYear().equals(fiscalYearString)) {
        try {
            setUniversityFiscalYear(new Integer(fiscalYearString));
        } catch (NumberFormatException e) {
            returnList.add(new Message("Fiscal year '" + fiscalYearString + "' 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)));

    String sequenceNumberString = line.substring(
            pMap.get(KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER),
            pMap.get(KFSPropertyConstants.POSITION_NUMBER));
    if (!GeneralLedgerConstants.getSpaceTransactionEntrySequenceNumber().equals(sequenceNumberString)
            && !GeneralLedgerConstants.getZeroTransactionEntrySequenceNumber().equals(sequenceNumberString)) {
        try {
            setTransactionLedgerEntrySequenceNumber(new Integer(sequenceNumberString.trim()));
        } catch (NumberFormatException e) {
            returnList.add(new Message(
                    "Transaction Sequence Number '" + sequenceNumberString + "' contains an invalid value.",
                    Message.TYPE_FATAL));
            setTransactionLedgerEntrySequenceNumber(null);
        }
    } else {
        setTransactionLedgerEntrySequenceNumber(null);
    }

    setPositionNumber(getValue(line, pMap.get(KFSPropertyConstants.POSITION_NUMBER),
            pMap.get(KFSPropertyConstants.PROJECT_CODE)));
    setProjectCode(getValue(line, pMap.get(KFSPropertyConstants.PROJECT_CODE),
            pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC)));
    setTransactionLedgerEntryDescription(
            getValue(line, pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC),
                    pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT)));

    String amountString = line.substring(pMap.get(KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT),
            pMap.get(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE));
    if (!amountString.trim().equals(GeneralLedgerConstants.EMPTY_CODE)) {
        try {
            setTransactionLedgerEntryAmount(new KualiDecimal(amountString.trim()));
        } catch (NumberFormatException e) {
            returnList.add(new Message("Transaction Amount '" + amountString + "' 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)));

    String transactionDateString = line.substring(pMap.get(KFSPropertyConstants.TRANSACTION_DATE),
            pMap.get(KFSPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER));
    if (!transactionDateString.trim().equals(GeneralLedgerConstants.EMPTY_CODE)) {
        try {
            setTransactionDate(parseDate(
                    org.springframework.util.StringUtils.trimTrailingWhitespace(transactionDateString), false));
        } catch (ParseException e) {
            setTransactionDate(null);
            returnList.add(
                    new Message("Transaction Date '" + transactionDateString + "' contains an invalid value.",
                            Message.TYPE_FATAL));
        }
    } else {
        setTransactionDate(null);
    }

    setOrganizationDocumentNumber(getValue(line, pMap.get(KFSPropertyConstants.ORGANIZATION_DOCUMENT_NUMBER),
            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)));

    String revDateStr = line.substring(pMap.get(KFSPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE),
            pMap.get(KFSPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD));
    if (!revDateStr.trim().equals(GeneralLedgerConstants.EMPTY_CODE)) {
        try {
            setFinancialDocumentReversalDate(
                    parseDate(org.springframework.util.StringUtils.trimTrailingWhitespace(revDateStr), false));
        } catch (ParseException e) {
            setFinancialDocumentReversalDate(null);
            returnList.add(new Message("Reversal Date '" + revDateStr + "' contains an invalid value.",
                    Message.TYPE_FATAL));
        }
    } else {
        setFinancialDocumentReversalDate(null);
    }

    setTransactionEncumbranceUpdateCode(
            line.substring(pMap.get(KFSPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD),
                    pMap.get(KFSPropertyConstants.TRANSACTION_POSTING_DATE)));

    String postDateStr = line.substring(pMap.get(KFSPropertyConstants.TRANSACTION_POSTING_DATE),
            pMap.get(KFSPropertyConstants.PAY_PERIOD_END_DATE));
    if (!postDateStr.trim().equals(GeneralLedgerConstants.EMPTY_CODE)) {
        try {
            setTransactionPostingDate(
                    parseDate(org.springframework.util.StringUtils.trimTrailingWhitespace(postDateStr), false));
        } catch (ParseException e) {
            setTransactionPostingDate(null);
            returnList.add(
                    new Message("Transaction Posting Date '" + postDateStr + "' contains an invalid value.",
                            Message.TYPE_FATAL));
        }
    } else {
        setTransactionPostingDate(null);
    }

    String payPeriodDateStr = line.substring(pMap.get(KFSPropertyConstants.PAY_PERIOD_END_DATE),
            pMap.get(KFSPropertyConstants.TRANSACTION_TOTAL_HOURS));
    if (!payPeriodDateStr.trim().equals(GeneralLedgerConstants.EMPTY_CODE)) {
        try {
            setPayPeriodEndDate(parseDate(
                    org.springframework.util.StringUtils.trimTrailingWhitespace(payPeriodDateStr), false));
        } catch (ParseException e) {
            setPayPeriodEndDate(null);
            returnList.add(
                    new Message("Pay Period End Date '" + payPeriodDateStr + "' contains an invalid value.",
                            Message.TYPE_FATAL));
        }
    } else {
        setPayPeriodEndDate(null);
    }

    String transTotHrsStr = line.substring(pMap.get(KFSPropertyConstants.TRANSACTION_TOTAL_HOURS),
            pMap.get(KFSPropertyConstants.PAYROLL_END_DATE_FISCAL_YEAR));
    if (!transTotHrsStr.trim().equals(GeneralLedgerConstants.EMPTY_CODE)) {
        try {
            setTransactionTotalHours(new BigDecimal(transTotHrsStr.trim()));
        } catch (NumberFormatException e) {
            setTransactionTotalHours(null);
            returnList.add(new Message(
                    "Transaction Total Hours '" + transTotHrsStr.trim() + "' contains an invalid value.",
                    Message.TYPE_FATAL));
        }
    } else {
        setTransactionTotalHours(null);
    }
    String payEndFisYrStr = line.substring(pMap.get(KFSPropertyConstants.PAYROLL_END_DATE_FISCAL_YEAR),
            pMap.get(LaborPropertyConstants.PAYROLL_END_DATE_FISCAL_PERIOD_CODE));
    if (!GeneralLedgerConstants.getSpaceUniversityFiscalYear().equals(payEndFisYrStr)) {
        try {
            setPayrollEndDateFiscalYear(
                    new Integer(org.springframework.util.StringUtils.trimTrailingWhitespace(payEndFisYrStr)));
        } catch (NumberFormatException e) {
            returnList.add(new Message(
                    "Payroll End Date Fiscal Year '" + payEndFisYrStr + "' contains an invalid value.",
                    Message.TYPE_FATAL));
            setPayrollEndDateFiscalYear(null);
        }
    } else {
        setPayrollEndDateFiscalYear(null);
    }

    setPayrollEndDateFiscalPeriodCode(
            getValue(line, pMap.get(LaborPropertyConstants.PAYROLL_END_DATE_FISCAL_PERIOD_CODE),
                    pMap.get(KFSPropertyConstants.EMPLID)));
    setEmplid(getValue(line, pMap.get(KFSPropertyConstants.EMPLID),
            pMap.get(KFSPropertyConstants.EMPLOYEE_RECORD)));

    String empRecordStr = line.substring(pMap.get(KFSPropertyConstants.EMPLOYEE_RECORD),
            pMap.get(KFSPropertyConstants.EARN_CODE));
    if (!empRecordStr.trim().equals(GeneralLedgerConstants.EMPTY_CODE)) {
        try {
            setEmployeeRecord(new Integer(empRecordStr.trim()));
        } catch (NumberFormatException e) {
            returnList
                    .add(new Message("Employee Record '" + empRecordStr.trim() + "' contains an invalid value.",
                            Message.TYPE_FATAL));
            setEmployeeRecord(null);
        }
    } else {
        setEmployeeRecord(null);
    }

    setEarnCode(
            getValue(line, pMap.get(KFSPropertyConstants.EARN_CODE), pMap.get(KFSPropertyConstants.PAY_GROUP)));
    setPayGroup(getValue(line, pMap.get(KFSPropertyConstants.PAY_GROUP),
            pMap.get(LaborPropertyConstants.SALARY_ADMINISTRATION_PLAN)));
    setSalaryAdministrationPlan(getValue(line, pMap.get(LaborPropertyConstants.SALARY_ADMINISTRATION_PLAN),
            pMap.get(LaborPropertyConstants.GRADE)));
    setGrade(getValue(line, pMap.get(LaborPropertyConstants.GRADE),
            pMap.get(LaborPropertyConstants.RUN_IDENTIFIER)));
    setRunIdentifier(getValue(line, pMap.get(LaborPropertyConstants.RUN_IDENTIFIER),
            pMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_CHART_OF_ACCOUNTS_CODE)));
    setLaborLedgerOriginalChartOfAccountsCode(
            getValue(line, pMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_CHART_OF_ACCOUNTS_CODE),
                    pMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_ACCOUNT_NUMBER)));
    setLaborLedgerOriginalAccountNumber(
            getValue(line, pMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_ACCOUNT_NUMBER),
                    pMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_SUB_ACCOUNT_NUMBER)));
    setLaborLedgerOriginalSubAccountNumber(
            getValue(line, pMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_SUB_ACCOUNT_NUMBER),
                    pMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_FINANCIAL_OBJECT_CODE)));
    setLaborLedgerOriginalFinancialObjectCode(
            getValue(line, pMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_FINANCIAL_OBJECT_CODE),
                    pMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_FINANCIAL_SUB_OBJECT_CODE)));
    setLaborLedgerOriginalFinancialSubObjectCode(
            getValue(line, pMap.get(LaborPropertyConstants.LABORLEDGER_ORIGINAL_FINANCIAL_SUB_OBJECT_CODE),
                    pMap.get(LaborPropertyConstants.HRMS_COMPANY)));
    setHrmsCompany(getValue(line, pMap.get(LaborPropertyConstants.HRMS_COMPANY),
            pMap.get(LaborPropertyConstants.SET_ID)));
    setSetid(getValue(line, pMap.get(LaborPropertyConstants.SET_ID), entryLength));

    return returnList;
}

From source file:com.threerings.getdown.data.Application.java

/**
 * If appbase_domain property is set, replace the domain on the provided string.
 *//*  w  w w .  j  ava 2 s.c  o  m*/
protected String replaceDomain(String appbase) {
    String appbaseDomain = SysProps.appbaseDomain();
    if (appbaseDomain != null) {
        Matcher m = Pattern.compile("(http://[^/]+)(.*)").matcher(appbase);
        appbase = m.replaceAll(appbaseDomain + "$2");
    }
    return appbase;
}

From source file:com.juick.android.MessagesFragment.java

private ArrayList<JuickMessage> filterMessages(ArrayList<JuickMessage> messages) {
    log("filterMessages start");
    SharedPreferences sp = PreferenceManager
            .getDefaultSharedPreferences(JuickAdvancedApplication.instance.getApplicationContext());
    boolean filterNonRussian = sp.getBoolean("filterNonRussian", false);
    Set<String> filteredOutUsers1 = JuickMessagesAdapter.getFilteredOutUsers(parent);
    log("filterMessages got filtered out users");
    for (Iterator<JuickMessage> iterator = messages.iterator(); iterator.hasNext();) {
        JuickMessage message = iterator.next();
        if (filteredOutUsers1.contains(message.User.UName)) {
            iterator.remove();//from  w w  w .j  a  va 2 s .  com
            continue;
        }
        if (message.getRID() == 0) {
            // don't check comments
            if (XMPPService.getAnyJuboMessageFilter() != null) {
                if (!XMPPService.getAnyJuboMessageFilter().allowMessage(message)) {
                    iterator.remove();
                    continue;
                }
            }
            if (XMPPService.getAnyJuickBlacklist() != null) {
                if (!XMPPService.getAnyJuickBlacklist().allowMessage(message)) {
                    iterator.remove();
                    continue;
                }
            }
        }
        if (filterNonRussian) {
            String text = message.Text;
            int nRussian = 0;
            while (true) {
                boolean replaced = false;
                Matcher matcher = httpURL.matcher(text);
                if (matcher.find()) {
                    try {
                        text = matcher.replaceAll("");
                        replaced = true;
                    } catch (Exception e) {
                        //
                    }
                }
                if (!replaced)
                    break;
            }
            final int limit = text.length();
            for (int i = 0; i < limit; i++) {
                int charCode = (int) text.charAt(i);
                if (russians.get(charCode)) {
                    nRussian++;
                    break;
                }
            }
            if (!text.contains("No description")) {
                if (nRussian == 0 && limit > 30) {
                    iterator.remove();
                    continue;
                }
            }
        }
    }
    log("filterMessages end");
    return messages;
}

From source file:org.apache.hadoop.hive.service.HSSessionItem.java

public String removen(String in) {
    if (in == null) {
        return "";
    }/*from   w w w . ja v  a  2s  . com*/
    l4j.info("input:  " + in);
    Pattern p = Pattern.compile("\\n");
    Matcher m = p.matcher(in);
    String ttt = m.replaceAll("");
    l4j.debug("output:  " + ttt);
    return ttt;
}

From source file:org.apache.tika.eval.AbstractProfiler.java

void getExceptionStrings(Metadata metadata, Map<Cols, String> data) {

    String fullTrace = metadata.get(TikaCoreProperties.TIKA_META_EXCEPTION_PREFIX + "runtime");

    if (fullTrace == null) {
        fullTrace = metadata.get(RecursiveParserWrapper.EMBEDDED_EXCEPTION);
    }//from  w w w .j a v a  2 s.  c  om

    if (fullTrace != null) {
        //check for "expected" exceptions...exceptions
        //that can't be fixed.
        //Do not store trace for "expected" exceptions

        Matcher matcher = ACCESS_PERMISSION_EXCEPTION.matcher(fullTrace);
        if (matcher.find()) {
            data.put(Cols.PARSE_EXCEPTION_ID, Integer.toString(EXCEPTION_TYPE.ACCESS_PERMISSION.ordinal()));
            return;
        }
        matcher = ENCRYPTION_EXCEPTION.matcher(fullTrace);
        if (matcher.find()) {
            data.put(Cols.PARSE_EXCEPTION_ID, Integer.toString(EXCEPTION_TYPE.ENCRYPTION.ordinal()));
            return;
        }

        data.put(Cols.PARSE_EXCEPTION_ID, Integer.toString(EXCEPTION_TYPE.RUNTIME.ordinal()));

        data.put(Cols.ORIG_STACK_TRACE, fullTrace);
        //TikaExceptions can have object ids, as in the "@2b1ea6ee" in:
        //org.apache.tika.exception.TikaException: TIKA-198: Illegal
        //IOException from org.apache.tika.parser.microsoft.OfficeParser@2b1ea6ee
        //For reporting purposes, let's snip off the object id so that we can more
        //easily count exceptions.
        String sortTrace = ExceptionUtils.trimMessage(fullTrace);

        matcher = CAUSED_BY_SNIPPER.matcher(sortTrace);
        sortTrace = matcher.replaceAll("$1");
        sortTrace = sortTrace.replaceAll("org.apache.tika.", "o.a.t.");
        data.put(Cols.SORT_STACK_TRACE, sortTrace);
    }
}