List of usage examples for org.apache.commons.lang3 StringUtils indexOfAny
public static int indexOfAny(final CharSequence str, final CharSequence... searchStrs)
Find the first index of any of a set of potential substrings.
A null CharSequence will return -1 .
From source file:com.mirth.connect.plugins.datatypes.hl7v2.HL7v2ResponseValidator.java
@Override public Response validate(Response response, ConnectorMessage connectorMessage) { HL7v2ResponseValidationProperties responseValidationProperties = getReplacedResponseValidationProperties( connectorMessage);// w ww . j av a 2 s. co m String[] successfulACKCodes = StringUtils.split(responseValidationProperties.getSuccessfulACKCode(), ','); String[] errorACKCodes = StringUtils.split(responseValidationProperties.getErrorACKCode(), ','); String[] rejectedACKCodes = StringUtils.split(responseValidationProperties.getRejectedACKCode(), ','); boolean validateMessageControlId = responseValidationProperties.isValidateMessageControlId(); String responseData = response.getMessage(); if (StringUtils.isNotBlank(responseData)) { try { if (responseData.trim().startsWith("<")) { // XML response received Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new InputSource(new CharArrayReader(responseData.toCharArray()))); String ackCode = XPathFactory.newInstance().newXPath().compile("//MSA.1/text()").evaluate(doc) .trim(); boolean rejected = Arrays.asList(rejectedACKCodes).contains(ackCode); boolean error = rejected || Arrays.asList(errorACKCodes).contains(ackCode); if (error || rejected) { String msa3 = StringUtils.trim( XPathFactory.newInstance().newXPath().compile("//MSA.3/text()").evaluate(doc)); String err1 = StringUtils.trim( XPathFactory.newInstance().newXPath().compile("//ERR.1/text()").evaluate(doc)); handleNACK(response, rejected, msa3, err1); } else if (Arrays.asList(successfulACKCodes).contains(ackCode)) { if (validateMessageControlId) { String msa2 = StringUtils.trim( XPathFactory.newInstance().newXPath().compile("//MSA.2/text()").evaluate(doc)); String originalControlID = getOriginalControlId(connectorMessage); if (!StringUtils.equals(msa2, originalControlID)) { handleInvalidControlId(response, originalControlID, msa2); } else { response.setStatus(Status.SENT); } } else { response.setStatus(Status.SENT); } } } else { // ER7 response received if (serializationProperties.isConvertLineBreaks()) { responseData = StringUtil.convertLineBreaks(responseData, serializationSegmentDelimiter); } int index = -1; boolean valid = true; // Attempt to find the MSA segment using the segment delimiters in the serialization properties if ((index = responseData.indexOf(serializationSegmentDelimiter + "MSA")) >= 0) { // MSA found; add the length of the segment delimiter, MSA, and field separator to get to the index of MSA.1 index += serializationSegmentDelimiter.length() + 4; if (index < responseData.length()) { boolean rejected = startsWithAny(responseData, rejectedACKCodes, index); boolean error = rejected || startsWithAny(responseData, errorACKCodes, index); char fieldSeparator = responseData.charAt(index - 1); if (error || rejected) { String msa3 = null; String err1 = null; // Index of MSA.2 index = responseData.indexOf(fieldSeparator, index); if (index >= 0) { // Index of MSA.3 index = responseData.indexOf(fieldSeparator, index + 1); if (index >= 0) { // Find the next index of either the field separator or segment delimiter, and then the resulting substring String tempSegment = StringUtils.substring(responseData, index + 1); index = StringUtils.indexOfAny(tempSegment, fieldSeparator + serializationSegmentDelimiter); if (index >= 0) { msa3 = StringUtils.substring(tempSegment, 0, index); } else { msa3 = StringUtils.substring(tempSegment, 0); } } } if ((index = responseData.indexOf(serializationSegmentDelimiter + "ERR")) >= 0) { // ERR found; add the length of the segment delimiter, ERR, and field separator to get to the index of ERR.1 index += serializationSegmentDelimiter.length() + 4; // Find the next index of either the field separator or segment delimiter, and then the resulting substring String tempSegment = StringUtils.substring(responseData, index); index = StringUtils.indexOfAny(tempSegment, fieldSeparator + serializationSegmentDelimiter); if (index >= 0) { err1 = StringUtils.substring(tempSegment, 0, index); } else { err1 = StringUtils.substring(tempSegment, 0); } } handleNACK(response, rejected, msa3, err1); } else if (startsWithAny(responseData, successfulACKCodes, index)) { if (validateMessageControlId) { String msa2 = ""; index = responseData.indexOf(fieldSeparator, index); if (index >= 0) { String tempSegment = StringUtils.substring(responseData, index + 1); index = StringUtils.indexOfAny(tempSegment, fieldSeparator + serializationSegmentDelimiter); if (index >= 0) { msa2 = StringUtils.substring(tempSegment, 0, index); } else { msa2 = StringUtils.substring(tempSegment, 0); } } String originalControlID = getOriginalControlId(connectorMessage); if (!StringUtils.equals(msa2, originalControlID)) { handleInvalidControlId(response, originalControlID, msa2); } else { response.setStatus(Status.SENT); } } else { response.setStatus(Status.SENT); } } else { valid = false; } } else { valid = false; } } else { valid = false; } if (!valid) { response.setStatus(Status.QUEUED); response.setStatusMessage("Invalid HL7 v2.x acknowledgement received."); response.setError(response.getStatusMessage()); } } } catch (Exception e) { response.setStatus(Status.QUEUED); response.setStatusMessage("Error validating response: " + e.getMessage()); response.setError(ErrorMessageBuilder.buildErrorMessage(this.getClass().getSimpleName(), response.getStatusMessage(), e)); } } else { response.setStatus(Status.QUEUED); response.setStatusMessage("Empty or blank response received."); response.setError(response.getStatusMessage()); } return response; }
From source file:de.micromata.genome.util.text.TextSplitterUtils.java
/** * Escape.//from w w w .ja v a 2s .com * * @param text the text * @param escapeChar the escape char * @param toEscaped the to escaped * @return the string */ public static String escape(String text, char escapeChar, char... toEscaped) { if (StringUtils.indexOfAny(text, toEscaped) == -1) { return text; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < text.length(); ++i) { char c = text.charAt(i); if (ArrayUtils.contains(toEscaped, c) == true) { sb.append(escapeChar); } sb.append(c); } return sb.toString(); }
From source file:com.mirth.connect.plugins.datatypes.hl7v2.HL7v2ResponseValidator.java
private String getOriginalControlId(ConnectorMessage connectorMessage) throws Exception { String controlId = ""; String originalMessage = ""; if (responseValidationProperties.getOriginalMessageControlId() .equals(OriginalMessageControlId.Destination_Encoded)) { originalMessage = connectorMessage.getEncoded().getContent(); } else if (responseValidationProperties.getOriginalMessageControlId() .equals(OriginalMessageControlId.Map_Variable)) { String originalIdMapVariable = responseValidationProperties.getOriginalIdMapVariable(); if (StringUtils.isEmpty(originalIdMapVariable)) { throw new Exception("Map variable for original control Id not set."); }//w w w . j a v a2s . c o m Object value = null; if (connectorMessage.getConnectorMap().containsKey(originalIdMapVariable)) { value = connectorMessage.getConnectorMap().get(originalIdMapVariable); } else { value = connectorMessage.getChannelMap().get(originalIdMapVariable); } if (value == null) { throw new Exception("Map variable for original control Id not set."); } controlId = value.toString(); return controlId; } if (originalMessage.startsWith("<")) { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new InputSource(new CharArrayReader(originalMessage.toCharArray()))); controlId = XPathFactory.newInstance().newXPath().compile("//MSH.10.1/text()").evaluate(doc).trim(); } else { int index; if ((index = originalMessage.indexOf("MSH")) >= 0) { index += 4; char fieldSeparator = originalMessage.charAt(index - 1); int iteration = 2; int segmentDelimeterIndex = originalMessage.indexOf(serializationSegmentDelimiter, index); while (iteration < MESSAGE_CONTROL_ID_FIELD) { index = originalMessage.indexOf(fieldSeparator, index + 1); if ((segmentDelimeterIndex >= 0 && segmentDelimeterIndex < index) || index == -1) { return ""; } iteration++; } String tempSegment = StringUtils.substring(originalMessage, index + 1); index = StringUtils.indexOfAny(tempSegment, fieldSeparator + serializationSegmentDelimiter); if (index >= 0) { controlId = StringUtils.substring(tempSegment, 0, index); } else { controlId = StringUtils.substring(tempSegment, 0); } } } return controlId; }
From source file:jp.terasoluna.fw.beans.JXPathIndexedBeanWrapperImpl.java
/** * ???????// www . ja v a 2 s. c o m * @param propertyName ?? * @return ??????Map?? */ @Override public Map<String, Object> getIndexedPropertyValues(String propertyName) { // ???Null if (StringUtils.isEmpty(propertyName)) { String message = "PropertyName is empty!"; log.error(message); throw new IllegalArgumentException(message); } // ????? if (StringUtils.indexOfAny(propertyName, new char[] { '/', '"', '\'' }) != -1) { String message = "Invalid character has found within property name." + " '" + propertyName + "' " + "Cannot use [ / \" ' ]"; log.error(message); throw new IllegalArgumentException(message); } // ??[]?[]???? String stringIndex = extractIndex(propertyName); if (stringIndex.length() > 0) { try { Integer.parseInt(stringIndex); } catch (NumberFormatException e) { String message = "Invalid character has found within property name." + " '" + propertyName + "' " + "Cannot use [ [] ]"; log.error(message); throw new IllegalArgumentException(message); } } Map<String, Object> result = new LinkedHashMap<String, Object>(); String requestXpath = toXPath(propertyName); // JXPath?? Iterator<?> ite = null; try { ite = context.iteratePointers(requestXpath); } catch (JXPathException e) { // ???? String message = "Invalid property name. " + "PropertyName: '" + propertyName + "'" + "XPath: '" + requestXpath + "'"; log.error(message, e); throw new IllegalArgumentException(message, e); } // XPath Java property while (ite.hasNext()) { Pointer p = (Pointer) ite.next(); result.put(this.toPropertyName(p.asPath()), p.getValue()); } return result; }
From source file:gtu._work.ui.DirectoryCompareUI.java
/** * TODO/*from ww w. j av a 2 s .c o m*/ */ private void totalScanFiles(EventObject event) { try { // ? final Map<String, Object> searchTextMap = new HashMap<String, Object>(); if (event != null && event.getSource() == searchText && // StringUtils.isNotBlank(searchText.getText()) && ((KeyEvent) event).getKeyCode() != 10)// { return; } else { String text = searchText.getText(); Matcher matcher = SEARCHTEXTPATTERN.matcher(text); if (matcher.matches()) { final String left = StringUtils.trim(matcher.group(1)); String operator = StringUtils.trim(matcher.group(2)); String condition = StringUtils.trim(matcher.group(3)); System.out.println("left = " + left); System.out.println("operator = " + operator); System.out.println("condition = " + condition); SearchTextEnum currentSearchType = null; for (SearchTextEnum e : SearchTextEnum.values()) { if (StringUtils.equals(e.name(), left)) { currentSearchType = e; break; } } Validate.notNull(currentSearchType, "??? : " + left); searchTextMap.put("currentSearchType", currentSearchType); searchTextMap.put("operator", operator); searchTextMap.put("condition", condition); } else if (event != null && event instanceof KeyEvent && ((KeyEvent) event).getKeyCode() == 10) { JCommonUtil._jOptionPane_showMessageDialog_error( "?:" + SEARCHTEXTPATTERN.pattern()); } } // ? final List<DiffMergeStatus> chkList = new ArrayList<DiffMergeStatus>(); A: for (DiffMergeStatus diff2 : DiffMergeStatus.values()) { for (int ii = 0; ii < diffMergeChkBox.length; ii++) { if (StringUtils.equals(diffMergeChkBox[ii].getText(), diff2.toString()) && diffMergeChkBox[ii].isSelected()) { chkList.add(diff2); continue A; } } } // ??? String extensionName = (String) extensionNameComboBox.getSelectedItem(); SingletonMap extensionNameMessageMap = new SingletonMap(); final SingletonMap extensionNameMap = new SingletonMap(); if (StringUtils.equals(EXTENSION_CUSTOM, extensionName)) { String result = JCommonUtil._jOptionPane_showInputDialog("???", EXTENSION_ALL); if (StringUtils.isNotBlank(result)) { String[] arry = result.split(",", -1); extensionNameMap.setValue(arry); extensionNameMessageMap.setValue(Arrays.toString(arry)); } else { extensionNameMap.setValue(new String[] { EXTENSION_ALL }); extensionNameMessageMap.setValue(EXTENSION_ALL); } } else { extensionNameMap.setValue(new String[] { extensionName }); extensionNameMessageMap.setValue(extensionName); } if (extensionNameCache == null) { extensionNameCache = new ExtensionNameCache(); extensionNameCache.extensionNameMap = extensionNameMap; extensionNameCache.extensionNameMessageMap = extensionNameMessageMap; } if (event != null && event.getSource() != extensionNameComboBox) { extensionNameMap.setValue(extensionNameCache.extensionNameMap.getValue()); extensionNameMessageMap.setValue(extensionNameCache.extensionNameMessageMap.getValue()); } FileSearch search = new FileSearch(DirectoryCompareUI.this) { @Override boolean isMatch(InfoObj infoObj) { boolean searchTextResult = true; if (searchTextMap.containsKey("currentSearchType") && searchTextMap.containsKey("operator") && searchTextMap.containsKey("condition")) { SearchTextEnum currentSearchType = (SearchTextEnum) searchTextMap.get("currentSearchType"); String operator = (String) searchTextMap.get("operator"); String condition = (String) searchTextMap.get("condition"); searchTextResult = currentSearchType.isMatch(infoObj, operator, condition); } boolean extensionNameResult = true; if (extensionNameMap.getValue() != null) { String[] extensionNameArray = (String[]) extensionNameMap.getValue(); if (StringUtils.indexOfAny(EXTENSION_ALL, extensionNameArray) == -1) { boolean findOk = false; for (String extension : extensionNameArray) { if ((infoObj.mainFile.isFile() && infoObj.mainFile.getName().toLowerCase().endsWith(extension)) || (infoObj.compareToFile.isFile() && infoObj.compareToFile.getName() .toLowerCase().endsWith(extension))) { findOk = true; break; } } if (!findOk) { extensionNameResult = false; } } } boolean chkListResult = chkList.contains(infoObj.status2); return chkListResult && extensionNameResult && searchTextResult; } }; search.execute(DirectoryCompareUI.this, // "?[?:" + StringUtils.defaultString(searchText.getText()) + "][??:" + extensionNameMessageMap.getValue() + "][:" + chkList + "]"); } catch (Exception ex) { JCommonUtil.handleException(ex, false); } }
From source file:org.dbgl.model.conf.Autoexec.java
void parseLines(final List<String> orgLines) { char driveletter = '\0'; String remainder = StringUtils.EMPTY; String executable = StringUtils.EMPTY; String image1 = StringUtils.EMPTY; String image2 = StringUtils.EMPTY; String image3 = StringUtils.EMPTY; int exeIndex = -1; String customEchos = StringUtils.EMPTY; List<String> leftOvers = new ArrayList<String>(); int customSection = -1; line: for (String orgLine : orgLines) { orgLine = orgLine.trim();//from w ww . j av a 2s .c o m for (int i = 0; i < SECTIONS; i++) { if (orgLine.startsWith(CUSTOM_SECTION_MARKERS[i * 2])) { customSection = i; continue line; } } if (customSection > -1) { if (orgLine.startsWith(CUSTOM_SECTION_MARKERS[customSection * 2 + 1])) customSection = -1; else customSections[customSection] += orgLine + PlatformUtils.EOLN; continue; } orgLine = StringUtils.stripStart(orgLine, "@").trim(); Matcher loadhighMatcher = LOADHIGH_PATRN.matcher(orgLine); Matcher loadfixMatcher = LOADFIX_PATRN.matcher(orgLine); Matcher bootMatcher = BOOT_PATRN.matcher(orgLine); if (loadhighMatcher.matches()) { loadhigh = true; orgLine = loadhighMatcher.group(1).trim(); } if (loadfixMatcher.matches()) { if (!loadfix) { loadfixValue = 64; loadfix = true; } if (loadfixMatcher.group(1) != null) // -f continue; if (loadfixMatcher.group(2) != null) { try { loadfixValue = Integer.parseInt(loadfixMatcher.group(2).trim().substring(1)); } catch (NumberFormatException e) { // use default value of 64 } } if (loadfixMatcher.group(3) == null) continue; orgLine = loadfixMatcher.group(3).trim(); } String line = orgLine.toLowerCase(); if (StringUtils.isEmpty(line)) { continue; } else if (line.startsWith("mount ") || line.startsWith("imgmount ")) { addMount(orgLine); } else if ((line.endsWith(":") && line.length() == 2) || (line.endsWith(":\\") && line.length() == 3)) { driveletter = Character.toUpperCase(line.charAt(0)); remainder = StringUtils.EMPTY; } else if (line.startsWith("cd\\")) { if (driveletter != '\0') { String add = PlatformUtils.toNativePath(orgLine).substring(2); if (add.startsWith("\\")) remainder = add; else remainder = new File(remainder, add).getPath(); } } else if (line.startsWith("cd ")) { if (driveletter != '\0') { String add = PlatformUtils.toNativePath(orgLine).substring(3); if (add.startsWith("\\")) remainder = add; else remainder = new File(remainder, add).getPath(); } } else if (line.startsWith("keyb ") || line.startsWith("keyb.com ")) { keyb = orgLine.substring(line.indexOf(' ') + 1); } else if (line.startsWith("mixer ") || line.startsWith("mixer.com ")) { mixer = orgLine.substring(line.indexOf(' ') + 1); } else if (line.startsWith("ipxnet ") || line.startsWith("ipxnet.com ")) { ipxnet = orgLine.substring(line.indexOf(' ') + 1); } else if (line.equals("pause")) { pause = true; } else if (line.startsWith("z:\\config.com")) { // just ignore } else if ((exeIndex = StringUtils.indexOfAny(line, FileUtils.EXECUTABLES)) != -1) { executable = orgLine; // If there is a space BEFORE executable name, strip everything before it int spaceBeforeIndex = executable.lastIndexOf(' ', exeIndex); if (spaceBeforeIndex != -1) { executable = executable.substring(spaceBeforeIndex + 1); } // If there is a space AFTER executable name, define it as being parameters int spaceAfterIndex = executable.indexOf(' '); if (spaceAfterIndex != -1) { params = orgLine.substring(spaceBeforeIndex + spaceAfterIndex + 2); executable = executable.substring(0, spaceAfterIndex); } } else if (bootMatcher.matches()) { Matcher bootImgsMatcher = BOOTIMGS_PATRN.matcher(bootMatcher.group(1).trim()); if (bootImgsMatcher.matches()) { if (bootImgsMatcher.group(1) != null) image1 = StringUtils.strip(bootImgsMatcher.group(1), "\""); if (bootImgsMatcher.group(2) != null) image2 = StringUtils.strip(bootImgsMatcher.group(2), "\""); if (bootImgsMatcher.group(3) != null) image3 = StringUtils.strip(bootImgsMatcher.group(3), "\""); } if (bootMatcher.group(2) != null) imgDriveletter = bootMatcher.group(2).trim().toUpperCase(); if (StringUtils.isEmpty(image1) && StringUtils.isNotEmpty(imgDriveletter)) { char driveNumber = (char) ((int) imgDriveletter.charAt(0) - 17); String matchingImageMount = findImageMatchByDrive(driveNumber, imgDriveletter.charAt(0)); if (matchingImageMount != null) image1 = matchingImageMount; } if ("\\file".equals(image1)) { img1 = "file"; // for template if . was unavailable } } else if (line.equals("exit") || line.startsWith("exit ")) { exit = true; } else if (line.equals("echo off")) { // just ignore } else if (line.equals("echo") || line.startsWith("echo ") || line.startsWith("echo.")) { customEchos += orgLine + PlatformUtils.EOLN; } else if (line.startsWith(":") || line.equals("cd") || line.equals("cls") || line.startsWith("cls ") || line.startsWith("cls\\") || line.equals("rem") || line.startsWith("rem ") || line.startsWith("goto ") || line.startsWith("if errorlevel ")) { // just ignore } else { leftOvers.add(orgLine); } } if (StringUtils.isNotEmpty(customEchos) && !customEchos.equalsIgnoreCase("echo." + PlatformUtils.EOLN)) { customSections[1] += "@echo off" + PlatformUtils.EOLN + customEchos; // add echo commands to pre-launch custom section customSections[1] += "pause" + PlatformUtils.EOLN; // add pause statement to make it all readable } if (executable.equals(StringUtils.EMPTY) && !leftOvers.isEmpty()) { for (int i = 0; i < leftOvers.size(); i++) { executable = leftOvers.get(i).trim(); if (i == (leftOvers.size() - 1)) { // the last executable should be the main game boolean isCalledBatch = executable.toLowerCase().startsWith("call "); if (isCalledBatch) executable = executable.substring(5); int spaceAfterIndex = executable.indexOf(' '); if (spaceAfterIndex != -1) { params = executable.substring(spaceAfterIndex + 1); executable = executable.substring(0, spaceAfterIndex); } executable += isCalledBatch ? FileUtils.EXECUTABLES[2] : FileUtils.EXECUTABLES[0]; } else { customSections[1] += executable + PlatformUtils.EOLN; // add other statements to pre-launch custom section } } } for (Mount mount : mountingpoints) { char mount_drive = mount.getDriveletter(); String mountPath = mount.getHostPathAsString(); if (driveMatches(executable, mount_drive, driveletter)) main = splitInThree(executable, mountPath, remainder); else { if (mount.matchesImageMountPath(image1)) img1 = image1; else if (driveMatches(image1, mount_drive, driveletter)) img1 = splitInThree(image1, mountPath, remainder); if (mount.matchesImageMountPath(image2)) img2 = image2; else if (driveMatches(image2, mount_drive, driveletter)) img2 = splitInThree(image2, mountPath, remainder); if (mount.matchesImageMountPath(image3)) img3 = image1; else if (driveMatches(image3, mount_drive, driveletter)) img3 = splitInThree(image3, mountPath, remainder); } } if (exit == null) exit = false; }
From source file:org.opensilk.video.util.Utils.java
public static int extractSeasonNumber(CharSequence title) { int num = -1; if (!StringUtils.isEmpty(title)) { Matcher m = TV_REGEX.matcher(title); if (m.matches()) { String episodes = m.group(2); if (!StringUtils.isEmpty(episodes)) { if (StringUtils.isNumeric(episodes)) { //101 style num = Character.getNumericValue(episodes.charAt(0)); } else { //s01e01 style int eidx = StringUtils.indexOfAny(episodes, "Ee"); num = Integer.valueOf(episodes.substring(1, eidx)); }/*from w w w . ja v a2 s . co m*/ } } } return num; }
From source file:org.opensilk.video.util.Utils.java
public static int extractEpisodeNumber(CharSequence title) { int num = -1; if (!StringUtils.isEmpty(title)) { Matcher m = TV_REGEX.matcher(title); if (m.matches()) { String episodes = m.group(2); if (!StringUtils.isEmpty(episodes)) { if (StringUtils.isNumeric(episodes)) { //101 style num = Integer.valueOf(episodes.substring(1)); } else { //s01e01 style int eidx = StringUtils.indexOfAny(episodes, "Ee"); num = Integer.valueOf(episodes.substring(eidx + 1)); }/*from w w w . ja v a2s .c o m*/ } } } return num; }
From source file:org.wikipedia.language.TranslationTests.java
private <T> void testTranslation(String lang, Map.Entry<String, String> entry, CharSequence[] expectedAny, @NonNull T... input) {//w ww . j av a 2 s .c o m String subject = String.format(new Locale(lang), entry.getValue(), input); String msg = lang + ":" + entry.getKey() + " = \"" + subject + "\""; if (StringUtils.indexOfAny(subject, (CharSequence[]) expectedAny) < 0) { msg += " is missing any of \"" + Arrays.toString(expectedAny) + "\""; L.e(msg); mismatches.append(msg).append("\n"); } }