List of usage examples for java.lang StringBuilder replace
@Override public StringBuilder replace(int start, int end, String str)
From source file:org.springframework.util.PropertyPlaceholderHelper.java
protected String parseStringValue(String value, PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders) { StringBuilder result = new StringBuilder(value); int startIndex = value.indexOf(this.placeholderPrefix); while (startIndex != -1) { int endIndex = findPlaceholderEndIndex(result, startIndex); if (endIndex != -1) { String placeholder = result.substring(startIndex + this.placeholderPrefix.length(), endIndex); String originalPlaceholder = placeholder; if (!visitedPlaceholders.add(originalPlaceholder)) { throw new IllegalArgumentException( "Circular placeholder reference '" + originalPlaceholder + "' in property definitions"); }/*from w w w . j av a2 s . c o m*/ // Recursive invocation, parsing placeholders contained in the placeholder key. placeholder = parseStringValue(placeholder, placeholderResolver, visitedPlaceholders); // Now obtain the value for the fully resolved key... String propVal = placeholderResolver.resolvePlaceholder(placeholder); if (propVal == null && this.valueSeparator != null) { int separatorIndex = placeholder.indexOf(this.valueSeparator); if (separatorIndex != -1) { String actualPlaceholder = placeholder.substring(0, separatorIndex); String defaultValue = placeholder.substring(separatorIndex + this.valueSeparator.length()); propVal = placeholderResolver.resolvePlaceholder(actualPlaceholder); if (propVal == null) { propVal = defaultValue; } } } if (propVal != null) { // Recursive invocation, parsing placeholders contained in the // previously resolved placeholder value. propVal = parseStringValue(propVal, placeholderResolver, visitedPlaceholders); result.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal); if (logger.isTraceEnabled()) { logger.trace("Resolved placeholder '" + placeholder + "'"); } startIndex = result.indexOf(this.placeholderPrefix, startIndex + propVal.length()); } else if (this.ignoreUnresolvablePlaceholders) { // Proceed with unprocessed value. startIndex = result.indexOf(this.placeholderPrefix, endIndex + this.placeholderSuffix.length()); } else { throw new IllegalArgumentException( "Could not resolve placeholder '" + placeholder + "'" + " in value \"" + value + "\""); } visitedPlaceholders.remove(originalPlaceholder); } else { startIndex = -1; } } return result.toString(); }
From source file:costumetrade.common.util.PropertyPlaceholderHelper.java
protected String parseStringValue(String strVal, PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders) { StringBuilder result = new StringBuilder(strVal); int startIndex = strVal.indexOf(this.placeholderPrefix); while (startIndex != -1) { int endIndex = findPlaceholderEndIndex(result, startIndex); if (endIndex != -1) { String placeholder = result.substring(startIndex + this.placeholderPrefix.length(), endIndex); String originalPlaceholder = placeholder; if (!visitedPlaceholders.add(originalPlaceholder)) { throw new IllegalArgumentException( "Circular placeholder reference '" + originalPlaceholder + "' in property definitions"); }/*from w ww.j a v a2s. co m*/ // Recursive invocation, parsing placeholders contained in the placeholder key. placeholder = parseStringValue(placeholder, placeholderResolver, visitedPlaceholders); // Now obtain the value for the fully resolved key... String propVal = placeholderResolver.resolvePlaceholder(placeholder); if (propVal == null && this.valueSeparator != null) { int separatorIndex = placeholder.indexOf(this.valueSeparator); if (separatorIndex != -1) { String actualPlaceholder = placeholder.substring(0, separatorIndex); String defaultValue = placeholder.substring(separatorIndex + this.valueSeparator.length()); propVal = placeholderResolver.resolvePlaceholder(actualPlaceholder); if (propVal == null) { propVal = defaultValue; } } } if (propVal != null) { // Recursive invocation, parsing placeholders contained in the // previously resolved placeholder value. propVal = parseStringValue(propVal, placeholderResolver, visitedPlaceholders); result.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal); if (logger.isTraceEnabled()) { logger.trace("Resolved placeholder '" + placeholder + "'"); } startIndex = result.indexOf(this.placeholderPrefix, startIndex + propVal.length()); } else if (this.ignoreUnresolvablePlaceholders) { // Proceed with unprocessed value. startIndex = result.indexOf(this.placeholderPrefix, endIndex + this.placeholderSuffix.length()); } else { throw new IllegalArgumentException("Could not resolve placeholder '" + placeholder + "'" + " in string value \"" + strVal + "\""); } visitedPlaceholders.remove(originalPlaceholder); } else { startIndex = -1; } } return result.toString(); }
From source file:oscar.eform.data.EForm.java
public void setSignatureCode(String contextPath, String userAgent, String demographicNo, String providerId) { String signatureRequestId = DigitalSignatureUtils.generateSignatureRequestId(providerId); String imageUrl = contextPath + "/imageRenderingServlet?source=" + ImageRenderingServlet.Source.signature_preview.name() + "&" + DigitalSignatureUtils.SIGNATURE_REQUEST_ID_KEY + "=" + signatureRequestId; String storedImgUrl = contextPath + "/imageRenderingServlet?source=" + ImageRenderingServlet.Source.signature_stored.name() + "&digitalSignatureId="; StringBuilder html = new StringBuilder(this.formHtml); int signatureLoc = StringBuilderUtils.indexOfIgnoreCase(html, signatureMarker, 0); if (signatureLoc > -1) { String browserType = ""; if (userAgent != null) { if (userAgent.toLowerCase().indexOf("ipad") > -1) { browserType = "IPAD"; } else { browserType = "ALL"; }//from w ww .j av a2s . c om } String signatureCode = "<script type='text/javascript' src='${oscar_javascript_path}../jquery/jquery-1.4.2.js'></script>" + "<script type='text/javascript' src='${oscar_javascript_path}signature.js'></script>" + "<script type='text/javascript'>\n" + "var _signatureRequestId = '" + signatureRequestId + "';\n" + "var _imageUrl = '" + imageUrl + "';\n" + "var _storedImgUrl = '" + storedImgUrl + "';\n" + "var _contextPath = '" + contextPath + "';\n" + "var _digitalSignatureRequestIdKey = '" + DigitalSignatureUtils.SIGNATURE_REQUEST_ID_KEY + "';\n" + "var _browserType = '" + browserType + "';\n" + "var _demographicNo = '" + demographicNo + "';\n" + "</script>"; html.replace(signatureLoc, signatureLoc + signatureMarker.length(), signatureCode); this.formHtml = html.toString(); } }
From source file:org.jahia.services.importexport.LegacyImportHandler.java
private boolean setPropertyField(ExtendedNodeType baseType, String localName, JCRNodeWrapper node, String propertyName, String value, Map<String, String> creationMetadata) throws RepositoryException { JCRNodeWrapper parent = node;/*from w ww . ja v a 2 s . c om*/ String mixinType = null; if (propertyName.contains("|")) { mixinType = StringUtils.substringBefore(propertyName, "|"); propertyName = StringUtils.substringAfter(propertyName, "|"); } if (StringUtils.contains(propertyName, "/")) { String parentPath = StringUtils.substringBeforeLast(propertyName, "/"); if (parent.hasNode(parentPath)) { parent = parent.getNode(parentPath); } propertyName = StringUtils.substringAfterLast(propertyName, "/"); } parent = checkoutNode(parent); if (!StringUtils.isEmpty(mixinType) && !parent.isNodeType(mixinType)) { parent.addMixin(mixinType); } ExtendedPropertyDefinition propertyDefinition; propertyDefinition = parent.getApplicablePropertyDefinition(propertyName); if (propertyDefinition == null) { return false; } if (propertyDefinition.isProtected()) { return false; } if (StringUtils.isNotBlank(value) && !value.equals("<empty>")) { Node n = parent; if (propertyDefinition.isInternationalized()) { n = getOrCreateI18N(parent, locale, creationMetadata); } if (!n.isCheckedOut()) { session.checkout(n); } switch (propertyDefinition.getRequiredType()) { case PropertyType.DATE: GregorianCalendar cal = new GregorianCalendar(); try { DateFormat df = new SimpleDateFormat(ImportExportService.DATE_FORMAT); Date d = df.parse(value); cal.setTime(d); n.setProperty(propertyName, cal); } catch (java.text.ParseException e) { logger.error(e.getMessage(), e); } break; case PropertyType.REFERENCE: case PropertyType.WEAKREFERENCE: if (propertyDefinition.isMultiple()) { String[] strings = Patterns.TRIPPLE_DOLLAR.split(value); for (String s : strings) { createReferenceValue(s, propertyDefinition.getSelector(), n, propertyName); } } else { createReferenceValue(value, propertyDefinition.getSelector(), n, propertyName); } break; default: switch (propertyDefinition.getSelector()) { case SelectorType.RICHTEXT: { if (value.contains("=\"###")) { int count = 1; StringBuilder buf = new StringBuilder(value); while (buf.indexOf("=\"###") > -1) { int from = buf.indexOf("=\"###") + 2; int to = buf.indexOf("\"", from); String ref = buf.substring(from, to); if (ref.startsWith("###/webdav")) { ref = StringUtils.substringAfter(ref, "###/webdav"); buf.replace(from, to, "##doc-context##/{workspace}/##ref:link" + count + "##"); } else if (ref.startsWith("###file:")) { ref = StringUtils.substringAfter(ref, "###file:"); final int qmPos = ref.indexOf('?'); boolean isUuid = false; if (qmPos != -1) { if (StringUtils.substring(ref, qmPos + 1).startsWith("uuid=default:")) { ref = StringUtils.substring(ref, qmPos + 14); isUuid = true; } else ref = StringUtils.substringBefore(ref, "?"); } if (!isUuid) ref = correctFilename(ref); buf.replace(from, to, "##doc-context##/{workspace}/##ref:link" + count + "##"); } else { ref = StringUtils.substringAfterLast(ref, "/"); // we keep the URL parameters if any String params = ""; int pos = ref.indexOf('?'); if (pos == -1) { pos = ref.indexOf('#'); } if (pos != -1) { params = ref.substring(pos); ref = ref.substring(0, pos); } buf.replace(from, to, "##cms-context##/{mode}/{lang}/##ref:link" + count + "##.html" + params); } try { ref = URLDecoder.decode(ref, "UTF-8"); } catch (UnsupportedEncodingException e) { } if (!references.containsKey(ref)) { references.put(ref, new ArrayList<String>()); } references.get(ref) .add(n.getIdentifier() + "/[" + count + "]" + propertyDefinition.getName()); count++; } value = buf.toString(); } n.setProperty(propertyName, value); if (logger.isDebugEnabled()) logger.debug("Setting on node " + n.getPath() + " property " + propertyName + " with value=" + value); break; } default: { String[] vcs = propertyDefinition.getValueConstraints(); List<String> constraints = Arrays.asList(vcs); if (!propertyDefinition.isMultiple()) { if (value.startsWith("<jahia-resource")) { value = ResourceBundleMarker.parseMarkerValue(value).getResourceKey(); if (value.startsWith(propertyDefinition.getResourceBundleKey())) { value = value.substring(propertyDefinition.getResourceBundleKey().length() + 1); } } else if ("jcr:description".equals(propertyName)) { value = removeHtmlTags(value); } value = baseType != null ? mapping.getMappedPropertyValue(baseType, localName, value) : value; if (valueMatchesContraints(value, constraints)) { try { n.setProperty(propertyName, value); if (logger.isDebugEnabled()) logger.debug("Setting on node " + n.getPath() + " property " + propertyName + " with value=" + value); } catch (Exception e) { logger.error("Impossible to set property " + propertyName + " due to exception", e); } } else { logger.error( "Impossible to set property " + propertyName + " due to some constraint error"); logger.error(" - value = " + value); logger.error(" - constraints = " + constraints.toString()); } } else { String[] strings = Patterns.TRIPPLE_DOLLAR.split(value); List<Value> values = new ArrayList<Value>(); for (String string : strings) { if (string.startsWith("<jahia-resource")) { string = ResourceBundleMarker.parseMarkerValue(string).getResourceKey(); if (string.startsWith(propertyDefinition.getResourceBundleKey())) { string = string .substring(propertyDefinition.getResourceBundleKey().length() + 1); } } value = baseType != null ? mapping.getMappedPropertyValue(baseType, localName, value) : value; if (constraints.isEmpty() || constraints.contains(value)) { values.add(new ValueImpl(string, propertyDefinition.getRequiredType())); } } n.setProperty(propertyName, values.toArray(new Value[values.size()])); if (logger.isDebugEnabled()) logger.debug("Setting on node " + n.getPath() + " property " + propertyName + " with value=" + values); } break; } } } } else { return false; } return true; }
From source file:de.tudarmstadt.ukp.clarin.webanno.tsv.WebannoTsv2Reader.java
/** * Iterate through lines and create span annotations accordingly. For * multiple span annotation, based on the position of the annotation in the * line, update only the end position of the annotation *///from w ww. ja v a 2 s.c o m private void setAnnotations(JCas aJcas, InputStream aIs, String aEncoding, StringBuilder text) throws IOException { // getting header information LineIterator lineIterator = IOUtils.lineIterator(aIs, aEncoding); int columns = 1;// token number + token columns (minimum required) int tokenStart = 0, sentenceStart = 0; Map<Type, Set<Feature>> spanLayers = new LinkedHashMap<Type, Set<Feature>>(); Map<Type, Type> relationayers = new LinkedHashMap<Type, Type>(); // an annotation for every feature in a layer Map<Type, Map<Integer, AnnotationFS>> annotations = new LinkedHashMap<Type, Map<Integer, AnnotationFS>>(); // store if this is a Begin/Intermediate/End of an annotation Map<Type, Map<Integer, String>> beginEndAnno = new LinkedHashMap<Type, Map<Integer, String>>(); // Store annotations of tokens so that it can be used later for relation // annotations Map<Type, Map<String, List<AnnotationFS>>> tokenAnnotations = new LinkedHashMap<Type, Map<String, List<AnnotationFS>>>(); // store target token ids used for a relation Map<Type, Map<String, List<String>>> relationTargets = new LinkedHashMap<Type, Map<String, List<String>>>(); // store tokens indexing with the concat of itsbegin-end so that lemma // and pos annotation // can be attached, if exists, later indexedTokens = new HashMap<String, Token>(); while (lineIterator.hasNext()) { String line = lineIterator.next().trim(); if (line.trim().equals("") && sentenceStart == tokenStart) { continue; } if (line.trim().equals("")) { text.replace(tokenStart - 1, tokenStart, ""); tokenStart = tokenStart - 1; Sentence sentence = new Sentence(aJcas, sentenceStart, tokenStart); sentence.addToIndexes(); tokenStart++; sentenceStart = tokenStart; text.append("\n"); continue; } // sentence if (line.startsWith("#text=")) { continue; } if (line.startsWith("#id=")) { continue;// it is a comment line } if (line.startsWith("#")) { columns = getLayerAndFeature(aJcas, columns, spanLayers, relationayers, line); continue; } // some times, the sentence in #text= might have a new line which // break this reader, // so skip such lines if (!Character.isDigit(line.split(" ")[0].charAt(0))) { continue; } // If we are still unlucky, the line starts with a number from the // sentence but not // a token number, check if it didn't in the format NUM-NUM if (!Character.isDigit(line.split("-")[1].charAt(0))) { continue; } int count = StringUtils.countMatches(line, "\t"); if (columns != count) { throw new IOException(fileName + " This is not a valid TSV File. check this line: " + line); } // adding tokens and sentence StringTokenizer lineTk = new StringTokenizer(line, "\t"); String tokenNumberColumn = lineTk.nextToken(); String tokenColumn = lineTk.nextToken(); Token token = new Token(aJcas, tokenStart, tokenStart + tokenColumn.length()); token.addToIndexes(); Type posType = JCasUtil.getType(aJcas, POS.class); Type lemmaType = JCasUtil.getType(aJcas, Lemma.class); if (spanLayers.containsKey(posType) || spanLayers.containsKey(lemmaType)) { indexedTokens.put(tokenStart + "-" + tokenStart + tokenColumn.length(), token); } // adding the annotations createSpanAnnotation(aJcas, tokenStart, spanLayers, relationayers, annotations, beginEndAnno, tokenAnnotations, relationTargets, lineTk, tokenColumn, tokenNumberColumn); tokenStart = tokenStart + tokenColumn.length() + 1; text.append(tokenColumn + " "); } if (tokenStart > sentenceStart) { Sentence sentence = new Sentence(aJcas, sentenceStart, tokenStart); sentence.addToIndexes(); text.append("\n"); } createRelationLayer(aJcas, relationayers, tokenAnnotations, relationTargets); }
From source file:com.servioticy.dispatcher.jsonprocessors.JsonPathReplacer.java
public String replace(Map<String, String> jsons) throws InvalidPathException { if (this.str == null) { this.str = ""; }/*from w ww. ja v a 2 s . co m*/ String result = this.str; int indexOffset = 0; StringBuilder sb = new StringBuilder(result); for (Map.Entry<Integer, LinkedList<Map.Entry<String, JsonPath>>> jpsReplacement : this.jsonPaths .entrySet()) { int index = jpsReplacement.getKey() + indexOffset; LinkedList<Map.Entry<String, JsonPath>> jps = jpsReplacement.getValue(); // String startStr = (index == 0) ? "" : result.substring(0, index); // String endStr = (index == result.length()) ? "" : result.substring(index, result.length()); String partial = ""; for (Map.Entry<String, JsonPath> jp : jps) { // if(jp.isPathDefinite()){ String json; String key = jp.getKey(); try { // If the path does not exist in the input json, throws InvalidPathException json = jsons.get(key); Object content = jp.getValue().read(json); if (content instanceof String) { partial += "'" + content + "'"; } else { partial += this.mapper.writeValueAsString(content); } } catch (java.lang.IllegalArgumentException e) { // The input is not a json // TODO This should be done *only* on queries. In navigations of implicit queries or selfdocument, it should be an error // and the document shouldn't be processed. e.printStackTrace(); partial += "null"; } catch (Exception e) { // Not a correct input json // TODO log this e.printStackTrace(); partial += "null"; } // } } if (index > sb.toString().length()) { sb.append(partial); } else { sb.replace(index, index, partial); } // result = startStr + partial + endStr; indexOffset += partial.length(); } result = sb.toString(); return result; }
From source file:fr.landel.utils.scripts.ScriptsReplacer.java
private void replaceConditions(final StringBuilder sb, final Map<String, String> replacements) { Pair<Integer, Integer> bounds; String condition;// w ww .j av a 2 s.c om int indexValid; int indexDefault; String expression; String value; String defaultValue; final int stopLen = this.template.getExpressionClose().length(); final int operatorLen = this.template.getOperatorThen().length(); final int elseLen = this.template.getOperatorElse().length(); for (bounds = this.findDeepestCondition(sb, this.template.getExpressionOpen(), this.template.getExpressionClose()); bounds != null; bounds = this.findDeepestCondition(sb, this.template.getExpressionOpen(), this.template.getExpressionClose())) { condition = sb.substring(bounds.getLeft(), bounds.getRight()); indexValid = condition.indexOf(this.template.getOperatorThen()); indexDefault = condition.indexOf(this.template.getOperatorElse(), indexValid); expression = null; value = null; defaultValue = null; if (indexValid > -1) { expression = condition.substring(0, indexValid); if (indexDefault > -1) { value = condition.substring(indexValid + operatorLen, indexDefault); defaultValue = condition.substring(indexDefault + elseLen); } else { value = condition.substring(indexValid + operatorLen); } } else if (indexDefault > -1) { expression = condition.substring(0, indexDefault); defaultValue = condition.substring(indexDefault + elseLen); } if (expression != null) { sb.replace(bounds.getLeft() - 1, bounds.getRight() + stopLen, this.replaceCondition(replacements, expression, value, defaultValue)); } else { sb.replace(bounds.getLeft() - 1, bounds.getRight() + stopLen, ""); } } }
From source file:com.ocean.common.asserts.PropertyPlaceholderHelper.java
protected String parseStringValue(String value, PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders) { StringBuilder result = new StringBuilder(value); int startIndex = value.indexOf(this.placeholderPrefix); while (startIndex != -1) { int endIndex = findPlaceholderEndIndex(result, startIndex); if (endIndex != -1) { String placeholder = result.substring(startIndex + this.placeholderPrefix.length(), endIndex); String originalPlaceholder = placeholder; if (!visitedPlaceholders.add(originalPlaceholder)) { throw new IllegalArgumentException( "Circular placeholder reference '" + originalPlaceholder + "' in property definitions"); }//from w w w. j a v a 2 s . c o m // Recursive invocation, parsing placeholders contained in the // placeholder key. placeholder = parseStringValue(placeholder, placeholderResolver, visitedPlaceholders); // Now obtain the value for the fully resolved key... String propVal = placeholderResolver.resolvePlaceholder(placeholder); if (propVal == null && this.valueSeparator != null) { int separatorIndex = placeholder.indexOf(this.valueSeparator); if (separatorIndex != -1) { String actualPlaceholder = placeholder.substring(0, separatorIndex); String defaultValue = placeholder.substring(separatorIndex + this.valueSeparator.length()); propVal = placeholderResolver.resolvePlaceholder(actualPlaceholder); if (propVal == null) { propVal = defaultValue; } } } if (propVal != null) { // Recursive invocation, parsing placeholders contained in // the // previously resolved placeholder value. propVal = parseStringValue(propVal, placeholderResolver, visitedPlaceholders); result.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal); if (logger.isTraceEnabled()) { logger.trace("Resolved placeholder '" + placeholder + "'"); } startIndex = result.indexOf(this.placeholderPrefix, startIndex + propVal.length()); } else if (this.ignoreUnresolvablePlaceholders) { // Proceed with unprocessed value. startIndex = result.indexOf(this.placeholderPrefix, endIndex + this.placeholderSuffix.length()); } else { throw new IllegalArgumentException( "Could not resolve placeholder '" + placeholder + "'" + " in value \"" + value + "\""); } visitedPlaceholders.remove(originalPlaceholder); } else { startIndex = -1; } } return result.toString(); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.pdf.Pdf2CasConverter.java
private StringBuilder sanitize(final StringBuilder aContent) { int i = 0;//from w w w. ja v a 2 s.c o m int lastBreak = 0; while (i < aContent.length()) { // Check valid unicode char if (!isValidXMLChar(aContent.codePointAt(i))) { aContent.setCharAt(i, ' '); i++; continue; } // Set up how many characters we want to skip int seek = i + 1; // Do we maybe have an entity? if (aContent.charAt(i) == '&') { // REC 2006-10-21 Some PDFs seem to have entities and others // don't // so we may encounter &'s that do not introduce an entity and // just ignore them. final int end = aContent.indexOf(";", i); if (end != -1) { final String cand = aContent.substring(i, end + 1); String r = null; try { if (cand.startsWith("&#x")) { final int cp = Integer.parseInt(cand.substring(2, cand.length() - 1), 16); r = isValidXMLChar(cp) ? String.valueOf(Character.toChars(cp)) : " "; } else if (cand.startsWith("&#")) { final int cp = Integer.parseInt(cand.substring(2, cand.length() - 1)); r = isValidXMLChar(cp) ? String.valueOf(Character.toChars(cp)) : " "; } else { // RE 2006-10-22 The chance that there is a & and a // ; // together in a string is quite big. Let's be // tolerant. } } catch (final NumberFormatException e) { log.warn("Invalid numeric entity in fragment [" + cand + "] - Dropping it."); } // Expand the entity and set proper skip (if found) if (r != null) { aContent.replace(i, i + cand.length(), r); seek = i + r.length(); } } } // Match against the Trie after numeric entity expansion is over if (substitutionTable != null) { final Trie<String>.Node match = substitutionTable.getNode(aContent, i); if (match != null) { aContent.replace(i, i + match.level, match.value); seek = i + match.value.length(); } } // Check line breaks while (i < seek) { if (aContent.charAt(i) == '\n') { lastBreak = i; } else if (Character.isWhitespace(aContent.codePointAt(i)) && (i > (lastBreak + 79))) { lastBreak = i; aContent.replace(i, i + 1, "\n"); } i++; } } return aContent; }
From source file:org.kuali.kfs.fp.document.DisbursementVoucherDocument.java
/** * build document title based on the properties of current document * * @param the default document title/*from ww w .j a v a 2 s .co m*/ * @return the combine information of the given title and additional payment indicators */ protected String buildDocumentTitle(String title) { DisbursementVoucherPayeeDetail payee = getDvPayeeDetail(); if (payee == null) { return title; } Boolean addPaymentReasonToTitle = getParameterService().getParameterValueAsBoolean(this.getClass(), DisbursementVoucherConstants.ADD_PAYMENT_REASON_TO_DV_TITLE_PARM_NM, Boolean.TRUE); Boolean addPayeeTaxRevToTitle = getParameterService().getParameterValueAsBoolean(this.getClass(), DisbursementVoucherConstants.ADD_PAYEE_TAX_REV_TO_DV_TITLE_PARM_NM, Boolean.TRUE); Boolean addPaymentReasonTaxRevToTitle = getParameterService().getParameterValueAsBoolean(this.getClass(), DisbursementVoucherConstants.ADD_PAYMENT_REASON_TAX_REV_TO_DV_TITLE_PARM_NM, Boolean.TRUE); DisbursementVoucherPaymentReasonService paymentReasonService = SpringContext .getBean(DisbursementVoucherPaymentReasonService.class); if (title != null && title.contains(DisbursementVoucherConstants.DV_DOC_NAME) && addPaymentReasonToTitle) { String paymentCodeAndDescription = StringUtils.EMPTY; if (StringUtils.isNotBlank(payee.getDisbVchrPaymentReasonCode())) { PaymentReasonCode paymentReasonCode = paymentReasonService .getPaymentReasonByPrimaryId(payee.getDisbVchrPaymentReasonCode()); paymentCodeAndDescription = ObjectUtils.isNotNull(paymentReasonCode) ? paymentReasonCode.getCodeAndDescription() : paymentCodeAndDescription; } String replaceTitle = DisbursementVoucherConstants.DV_DOC_NAME + " " + paymentCodeAndDescription; title = title.replace(DisbursementVoucherConstants.DV_DOC_NAME, replaceTitle); } List<String> indicatorsArr = new ArrayList<String>(); indicatorsArr.add(payee.isEmployee() ? AdHocPaymentIndicator.EMPLOYEE_PAYEE : AdHocPaymentIndicator.OTHER); indicatorsArr.add(payee.isDisbVchrAlienPaymentCode() ? AdHocPaymentIndicator.ALIEN_PAYEE : AdHocPaymentIndicator.OTHER); if (addPayeeTaxRevToTitle) { String taxControlCode = this.getDisbVchrPayeeTaxControlCode(); if (StringUtils.equals(taxControlCode, DisbursementVoucherDocument.TAX_CONTROL_BACKUP_HOLDING) || StringUtils.equals(taxControlCode, DisbursementVoucherDocument.TAX_CONTROL_HOLD_PAYMENTS)) { indicatorsArr.add(AdHocPaymentIndicator.TAX_CONTROL_REQUIRING_TAX_REVIEW); } else { indicatorsArr.add(AdHocPaymentIndicator.OTHER); } } if (addPaymentReasonTaxRevToTitle) { boolean isTaxReviewRequired = paymentReasonService .isTaxReviewRequired(payee.getDisbVchrPaymentReasonCode()); indicatorsArr.add(isTaxReviewRequired ? AdHocPaymentIndicator.PAYMENT_REASON_REQUIRING_TAX_REVIEW : AdHocPaymentIndicator.OTHER); } boolean needIndicators = false; StringBuilder titleWithIndicators = new StringBuilder(); titleWithIndicators.append(title); titleWithIndicators.append(" ["); for (String indicator : indicatorsArr) { titleWithIndicators.append(String.format("%s:", indicator)); if (!AdHocPaymentIndicator.OTHER.equals(indicator)) { needIndicators = true; } } if (needIndicators) { titleWithIndicators.replace(titleWithIndicators.length() - 1, titleWithIndicators.length(), "]"); return titleWithIndicators.toString(); } return title; }