List of usage examples for org.apache.commons.lang StringUtils substringAfter
public static String substringAfter(String str, String separator)
Gets the substring after the first occurrence of a separator.
From source file:com.taobao.android.builder.tools.manifest.ManifestFileUtils.java
/** * Application?//w ww . j a va 2 s . co m * * @param element * @param replaceAttrs * @param removeAttrs */ private static void updateApplicationElement(Element element, Map<String, String> replaceAttrs, List<String> removeAttrs) { for (Map.Entry<String, String> entry : replaceAttrs.entrySet()) { String key = entry.getKey(); key = StringUtils.substringAfter(key, ":"); Attribute attribute = element.attribute(key); if (null != attribute) { element.remove(attribute); } } for (String key : removeAttrs) { key = StringUtils.substringAfter(key, ":"); Attribute attribute = element.attribute(key); if (null != attribute) { element.remove(attribute); } } }
From source file:edu.cornell.kfs.coa.document.validation.impl.AccountReversionGlobalRule.java
/** * Validates that the fund group code on the sub fund group on the cash and budget accounts is valid as defined by the * allowed values in SELECTION_1 system parameter. * /*from ww w. j a v a 2 s.c o m*/ * @param globalAcctRev * @return */ protected boolean validateAccountFundGroup(AccountReversionGlobal globalAcctRev) { boolean valid = true; String fundGroups = SpringContext.getBean(ParameterService.class).getParameterValueAsString(Reversion.class, CUKFSConstants.Reversion.SELECTION_1); String propertyName = StringUtils.substringBefore(fundGroups, "="); List<String> ruleValues = Arrays.asList(StringUtils.substringAfter(fundGroups, "=").split(";")); if (ObjectUtils.isNotNull(ruleValues) && ruleValues.size() > 0) { if (ObjectUtils.isNotNull(globalAcctRev.getBudgetReversionAccount()) && ObjectUtils.isNotNull(globalAcctRev.getBudgetReversionAccount().getSubFundGroup())) { String budgetAccountFundGroupCode = globalAcctRev.getBudgetReversionAccount().getSubFundGroup() .getFundGroupCode(); if (!ruleValues.contains(budgetAccountFundGroupCode)) { valid = false; GlobalVariables.getMessageMap().putError( MAINTAINABLE_ERROR_PREFIX + CUKFSPropertyConstants.ACCT_REVERSION_BUDGET_REVERSION_ACCT_NUMBER, RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_ALLOWED_VALUES_PARAMETER, new String[] { getDataDictionaryService().getAttributeLabel(FundGroup.class, KFSPropertyConstants.CODE), budgetAccountFundGroupCode, getParameterAsStringForMessage(CUKFSConstants.Reversion.SELECTION_1), getParameterValuesForMessage(ruleValues), getDataDictionaryService().getAttributeLabel(AccountReversion.class, CUKFSPropertyConstants.ACCT_REVERSION_BUDGET_REVERSION_ACCT_NUMBER) }); } } if (ObjectUtils.isNotNull(globalAcctRev.getCashReversionAccount()) && ObjectUtils.isNotNull(globalAcctRev.getCashReversionAccount().getSubFundGroup())) { String cashAccountFundGroupCode = globalAcctRev.getCashReversionAccount().getSubFundGroup() .getFundGroupCode(); if (!ruleValues.contains(cashAccountFundGroupCode)) { valid = false; GlobalVariables.getMessageMap().putError( MAINTAINABLE_ERROR_PREFIX + CUKFSPropertyConstants.ACCT_REVERSION_CASH_REVERSION_ACCT_NUMBER, RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_ALLOWED_VALUES_PARAMETER, new String[] { getDataDictionaryService().getAttributeLabel(FundGroup.class, KFSPropertyConstants.CODE), cashAccountFundGroupCode, getParameterAsStringForMessage(CUKFSConstants.Reversion.SELECTION_1), getParameterValuesForMessage(ruleValues), getDataDictionaryService().getAttributeLabel(AccountReversion.class, CUKFSPropertyConstants.ACCT_REVERSION_CASH_REVERSION_ACCT_NUMBER) }); } } } return valid; }
From source file:gov.nih.nci.cabig.caaers.rules.business.service.CaaersRulesEngineService.java
/** * Will return the organization Id (Sponsor/Institution) id * @param packageName//from w ww .j av a 2s.com * @return */ public String parseOrganizationId(String packageName) { String s = StringUtils.substringAfter(packageName, ".ORG_"); String orgId = StringUtils.substringBefore(s, "."); return orgId; }
From source file:gov.nih.nci.cabig.caaers.rules.business.service.CaaersRulesEngineService.java
/** * Will return the study Id/*from w w w . j av a2s . co m*/ * @param packageName * @return */ public String parseStudyId(String packageName) { String s = StringUtils.substringAfter(packageName, ".STU_"); String studyId = StringUtils.substringBefore(s, "."); return studyId; }
From source file:edu.cornell.kfs.coa.document.validation.impl.AccountReversionGlobalRule.java
/** * Validates that the sub fund group code on the cash and budget accounts is valid as defined by the allowed values in * SELECTION_4 system parameter.//from www . j a v a 2 s.c om * * @param globalAcctRev * @return */ protected boolean validateAccountSubFundGroup(AccountReversionGlobal globalAcctRev) { boolean valid = true; String subFundGroups = SpringContext.getBean(ParameterService.class) .getParameterValueAsString(Reversion.class, CUKFSConstants.Reversion.SELECTION_4); String propertyName = StringUtils.substringBefore(subFundGroups, "="); List<String> ruleValues = Arrays.asList(StringUtils.substringAfter(subFundGroups, "=").split(";")); if (ObjectUtils.isNotNull(ruleValues) && ruleValues.size() > 0) { if (ObjectUtils.isNotNull(globalAcctRev.getBudgetReversionAccount())) { String budgetAccountSubFundGroupCode = globalAcctRev.getBudgetReversionAccount() .getSubFundGroupCode(); if (ruleValues.contains(budgetAccountSubFundGroupCode)) { valid = false; GlobalVariables.getMessageMap().putError( MAINTAINABLE_ERROR_PREFIX + CUKFSPropertyConstants.ACCT_REVERSION_BUDGET_REVERSION_ACCT_NUMBER, RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_DENIED_VALUES_PARAMETER, new String[] { getDataDictionaryService().getAttributeLabel(SubFundGroup.class, KFSPropertyConstants.SUB_FUND_GROUP_CODE), budgetAccountSubFundGroupCode, getParameterAsStringForMessage(CUKFSConstants.Reversion.SELECTION_4), getParameterValuesForMessage(ruleValues), getDataDictionaryService().getAttributeLabel(AccountReversion.class, CUKFSPropertyConstants.ACCT_REVERSION_BUDGET_REVERSION_ACCT_NUMBER) }); } } if (ObjectUtils.isNotNull(globalAcctRev.getCashReversionAccount())) { String cashAccountSubFundGroupCode = globalAcctRev.getCashReversionAccount().getSubFundGroupCode(); if (ruleValues.contains(cashAccountSubFundGroupCode)) { valid = false; GlobalVariables.getMessageMap().putError( MAINTAINABLE_ERROR_PREFIX + CUKFSPropertyConstants.ACCT_REVERSION_CASH_REVERSION_ACCT_NUMBER, RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_DENIED_VALUES_PARAMETER, new String[] { getDataDictionaryService().getAttributeLabel(SubFundGroup.class, KFSPropertyConstants.SUB_FUND_GROUP_CODE), cashAccountSubFundGroupCode, getParameterAsStringForMessage(CUKFSConstants.Reversion.SELECTION_4), getParameterValuesForMessage(ruleValues), getDataDictionaryService().getAttributeLabel(AccountReversion.class, CUKFSPropertyConstants.ACCT_REVERSION_CASH_REVERSION_ACCT_NUMBER) }); } } } return valid; }
From source file:com.amalto.core.storage.StorageWrapper.java
protected String getXmlString(String clusterName, ComplexTypeMetadata type, Iterator<DataRecord> iterator, String uniqueID, String encoding, boolean isUserFormat) throws IOException { String xmlString = null;// w w w .j a v a2 s .co m if (iterator.hasNext()) { DataRecord result = iterator.next(); if (iterator.hasNext()) { iterateUnexceptedRecords(LOGGER, uniqueID, iterator); } ByteArrayOutputStream output = new ByteArrayOutputStream(1024); // Enforce root element name in case query returned instance of a subtype. DataRecordWriter dataRecordXmlWriter = isUserFormat ? new DataRecordXmlWriter(type) : new SystemDataRecordXmlWriter( (ClassRepository) getStorage(clusterName).getMetadataRepository(), type); if (isUserFormat) { dataRecordXmlWriter.setSecurityDelegator(SecuredStorage.getDelegator()); String key = uniqueID.startsWith(PROVISIONING_PREFIX_INFO) ? StringUtils.substringAfter(uniqueID, PROVISIONING_PREFIX_INFO) : uniqueID.split("\\.")[2]; //$NON-NLS-1$ long timestamp = result.getRecordMetadata().getLastModificationTime(); String taskId = result.getRecordMetadata().getTaskId(); String modelName = StringUtils.substringBeforeLast(clusterName, StorageAdmin.STAGING_SUFFIX); byte[] start = ("<ii><c>" + clusterName + "</c><dmn>" + modelName + "</dmn><dmr/><sp/><t>" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + timestamp + "</t><taskId>" + taskId + "</taskId><i>" + StringEscapeUtils.escapeXml(key) //$NON-NLS-1$//$NON-NLS-2$ + "</i><p>").getBytes(); //$NON-NLS-1$ output.write(start); } dataRecordXmlWriter.write(result, output); if (isUserFormat) { byte[] end = ("</p></ii>").getBytes(); //$NON-NLS-1$ output.write(end); } output.flush(); xmlString = new String(output.toByteArray(), encoding); } return xmlString; }
From source file:com.prowidesoftware.swift.model.field.Field.java
/** * Replaces the hash by empty and trims to null.<br> * * It also can remove meaningless component separators (If the resulting string only * contains the component separator "/", or starts with ":" or starts with "/" separators * all of them will also be removed).//w w w .j a v a 2s . c om * * @param hash hash string used by the get lines method * @param value current value to clean * @param removeSeparators if true, meaningless starting separators (: and /) are removed * @return proper final line value or null if the original field didn't contained content for such line */ private String clean(final String hash, final String value, boolean removeSeparators) { /* * try to replace /hash first just in case the component is optional * then replace the hash only if present */ String trimmed = StringUtils .trimToNull(StringUtils.replace(StringUtils.replace(value, "/" + hash, ""), hash, "")); if (trimmed != null && !onlySlashes(trimmed)) { /* * sebastian Oct 2015 * La logica para remover separadores debiera depender de si el offset * abarca la linea entera o si el componente del offset esta en al mitad * de una linea, y removerlo solo en este ultimo caso. * Esto es dificil de implementar porque no esta modelada la relacion * entre componentes y lineas. * Por lo tanto de momento se deja el parametro removeSeparators pero * con el codigo de aca abajo comentado. Y se coloca a cambio el patch * para el caso especifico de :// que es el que aparentemente no esta * contemplado segun los test. * if (removeSeparators) { for (int i = 0; i < trimmed.length(); i++) { char c = trimmed.charAt(i); if (c != ':' && c != '/') { return trimmed.substring(i); } } } else { return trimmed; } */ if (trimmed.startsWith("://")) { return StringUtils.substringAfter(trimmed, "://"); } else if (removeSeparators && (trimmed.startsWith(":") || trimmed.startsWith("/"))) { return StringUtils.trimToNull(StringUtils.substring(trimmed, 1)); } else { return trimmed; } } /* * otherwise return null */ return null; }
From source file:adalid.commons.util.StrUtils.java
/** * Replaces all occurrences of a String within another String that are found between another two Strings. * * @param text the String to search and replace in * @param search the String to search for * @param replacement the String to replace it with * @param preceding the String used as lower boundary of the search; if it is null or empty, the search begins at the beginning of text * @param following the String used as upper boundary of the search; if it is null or empty, the search ends at the end of text * @return the text with any replacements processed *//* w w w.j a v a 2 s. c om*/ public static String replaceBetween(String text, String search, String replacement, String preceding, String following) { final String turbofan = "\t\r\b\f\n"; if (text != null && search != null && replacement != null && text.length() > 0 && search.length() > 0 && text.contains(search)) { boolean preceded = preceding != null && preceding.length() > 0; if (preceded && !text.contains(preceding)) { return text; } boolean followed = following != null && following.length() > 0; if (followed && !text.contains(following)) { return text; } if (preceded || followed) { String searchless = text.replace(search, turbofan); String beforePreceding = preceded ? StringUtils.substringBefore(searchless, preceding) : ""; String afterPreceding = preceded ? StringUtils.substringAfter(searchless, preceding) : ""; String beforeFollowing = followed ? StringUtils.substringBefore(preceded ? afterPreceding : searchless, following) : ""; String afterFollowing = followed ? StringUtils.substringAfter(preceded ? afterPreceding : searchless, following) : ""; String inBetween = preceded && followed ? StringUtils.substringBetween(searchless, preceding, following) : ""; String substring = preceded && followed ? inBetween : preceded ? afterPreceding : beforeFollowing; if (StringUtils.contains(substring, turbofan)) { String string = substring.replace(turbofan, replacement); String concat = beforePreceding + (preceded ? preceding : "") + string + (followed ? following : "") + afterFollowing; String result = concat.replace(turbofan, search); return result; } } else { return text.replace(search, replacement); } } return text; }
From source file:eionet.web.action.VocabularyFolderActionBean.java
/** * Forwards to vocabulary concept page, if the url patter is: /vocabulary/folderIdentifier/conceptIdentifier. * * @return resolution// ww w .j av a2 s. c o m */ private Resolution getVocabularyConceptResolution() { HttpServletRequest httpRequest = getContext().getRequest(); String url = httpRequest.getRequestURL().toString(); // String query = httpRequest.getQueryString(); String[] parameters = StringUtils.split(StringUtils.substringAfter(url, "/vocabulary/"), "/"); if (parameters.length >= 3) { if (!RESERVED_VOCABULARY_EVENTS.contains(parameters[2])) { RedirectResolution resolution = new RedirectResolution(VocabularyConceptActionBean.class, "view"); resolution.addParameter("vocabularyFolder.folderName", parameters[0]); resolution.addParameter("vocabularyFolder.identifier", parameters[1]); resolution.addParameter("vocabularyConcept.identifier", parameters[2]); if (vocabularyFolder.isWorkingCopy()) { resolution.addParameter("vocabularyFolder.workingCopy", vocabularyFolder.isWorkingCopy()); } return resolution; } } return null; }
From source file:com.collabnet.ccf.pi.qc.v90.QCHandler.java
/** * @param newRs//from ww w .j a v a2 s .c o m * @param filterFieldName * @return */ private String getDeltaOfComment(IRecordSet newRs, String filterFieldName, IConnection qcc) { String deltaComment = ""; String newFieldValue = null; String emptyString = ""; int newRc = newRs.getRecordCount(); String qcMajorVersion = qcc.getMajorVersion(); for (int newCnt = 0; newCnt < newRc; newCnt++, newRs.next()) { String fieldName = newRs.getFieldValueAsString("AP_FIELD_NAME"); if (fieldName.equals(filterFieldName)) { String oldFieldValue = newRs.getFieldValueAsString("AP_OLD_LONG_VALUE"); newFieldValue = newRs.getFieldValueAsString("AP_NEW_LONG_VALUE"); if (!StringUtils.isEmpty(newFieldValue) && !StringUtils.isEmpty(oldFieldValue)) { String strippedOldValue = stripStartAndEndTags(oldFieldValue); String strippedNewValue = stripStartAndEndTags(newFieldValue); String delta = ""; if (QC_VERSION_12.equals(qcMajorVersion)) { //Extract text values from html tags String trimmedOldValue = JerichoUtils.htmlToText(strippedOldValue); String trimmedNewValue = JerichoUtils.htmlToText(strippedNewValue); //Get the new comment value from the extracted text String newComment = trimmedNewValue.substring(trimmedOldValue.length()); // All characters before first '\r' will be skipped. //This is to get the new comment values alone and omit // the extra characters carry forwarded when switching between clients. delta = StringUtils.substringAfter(newComment, QC12_LINE_BREAK); //Encode back html to entity references to preserve tags around the <fullname> in the QC comment format //which is validated during transformation deltaComment += com.collabnet.ccf.core.utils.StringUtils .encodeHTMLToEntityReferences(delta); } else { if (newFieldValue.length() > oldFieldValue.length()) { if (QC_VERSION_11.equals(qcMajorVersion)) { delta = strippedNewValue.substring(strippedOldValue.length()); /* * QC11 inserts line breaks into the comment * values, which causes the new value to be too * long after a comment was synched e.g. from * TF. Thus, the delta contains some characters * at the beginning which belong to the previous * comment. Here, we cut these off in order to * prevent the extraneous chars from being * synched back to the other system. XXX: this * will break if a very long comment or very * many comments are synched, so that the start * of the delta moves so far back that the * "extraneous chars" contain the entire * previous comment. */ final String commentPrefix = QC_COMMENT_PREFIX; final int offset = delta.indexOf(commentPrefix); if (offset > 0) { delta = delta.substring(offset); } } else { delta = strippedNewValue.substring(strippedOldValue.length()); } deltaComment += delta; } else if (newFieldValue.length() == oldFieldValue.length()) { log.warn("QC comments not changed"); } else { log.warn("New comment is smaller than old comment"); } } } else { if (!StringUtils.isEmpty(newFieldValue)) { deltaComment = stripStartAndEndTags(newFieldValue); } } } } if (StringUtils.isEmpty(newFieldValue)) return emptyString; else { return cleanUpComment(deltaComment, qcMajorVersion); } }