List of usage examples for org.apache.commons.lang StringUtils substringsBetween
public static String[] substringsBetween(String str, String open, String close)
Searches a String for substrings delimited by a start and end tag, returning all matching substrings in an array.
From source file:org.mule.modules.salesforce.automation.testcases.BatchResultStreamTestCases.java
@Category({ RegressionTests.class }) @Test// w w w.j a v a 2 s.co m public void testBatchResultStream() { BatchInfo batchInfo; String[] results; String id; String success; boolean isSuccess = true; List<String> sObjectsIds = new ArrayList<String>(); try { batchInfo = getBatchInfoByOperation(createBatchFlow); do { Thread.sleep(BATCH_PROCESSING_DELAY); testObjects.put("batchInfoRef", batchInfo); batchInfo = getBatchInfoByOperation(batchInfoFlow); } while (batchInfo.getState().equals(com.sforce.async.BatchStateEnum.InProgress) || batchInfo.getState().equals(com.sforce.async.BatchStateEnum.Queued)); assertTrue(batchInfo.getState().equals(com.sforce.async.BatchStateEnum.Completed)); MuleEvent response = (MuleEvent) batchResultStreamFlow.process(getTestEvent(testObjects)); String operationResponse = IOUtils.toString((InputStream) response.getMessage().getPayload()); results = StringUtils.substringsBetween(operationResponse, "<result>", "</result>"); for (int index = 0; index < results.length; index++) { id = StringUtils.substringBetween(results[index], "<id>", "</id>"); success = StringUtils.substringBetween(results[index], "<success>", "</success>"); if (success.equals("true")) { sObjectsIds.add(id); } else { isSuccess = false; } } testObjects.put("idsToDeleteFromMessage", sObjectsIds); assertTrue(isSuccess); } catch (Exception e) { e.printStackTrace(); fail(); } }
From source file:org.mule.modules.salesforce.automation.testcases.QueryResultStreamTestCases.java
@Category({ RegressionTests.class }) @Test// w ww .jav a2s . c o m public void testQueryResultStream() { BatchInfo batchInfo; String[] results; String id; String success; boolean isSuccess = true; List<String> sObjectsIds = new ArrayList<String>(); try { batchInfo = getBatchInfoByOperation(createBatchFlow); do { Thread.sleep(BATCH_PROCESSING_DELAY); testObjects.put("batchInfoRef", batchInfo); batchInfo = getBatchInfoByOperation(batchInfoFlow); } while (batchInfo.getState().equals(com.sforce.async.BatchStateEnum.InProgress) || batchInfo.getState().equals(com.sforce.async.BatchStateEnum.Queued)); assertTrue(batchInfo.getState().equals(com.sforce.async.BatchStateEnum.Completed)); MuleEvent response = (MuleEvent) batchQueryStreamFlow.process(getTestEvent(testObjects)); String operationResponse = IOUtils.toString((InputStream) response.getMessage().getPayload()); results = StringUtils.substringsBetween(operationResponse, "<result>", "</result>"); for (int index = 0; index < results.length; index++) { id = StringUtils.substringBetween(results[index], "<id>", "</id>"); success = StringUtils.substringBetween(results[index], "<success>", "</success>"); if (success.equals("true")) { sObjectsIds.add(id); } else { isSuccess = false; } } testObjects.put("idsToDeleteFromMessage", sObjectsIds); assertTrue(isSuccess); } catch (Exception e) { e.printStackTrace(); fail(); } }
From source file:org.sonar.api.test.ReviewContextTestUtils.java
public static ReviewContext createReviewContext(String properties) { Map<String, Map<String, String>> reviewContextMap = Maps.newLinkedHashMap(); for (String innerMap : StringUtils.split(properties, ';')) { if (StringUtils.isNotBlank(innerMap)) { String mapName = StringUtils.substringBefore(innerMap, "=").trim(); Map<String, String> currentMap = Maps.newLinkedHashMap(); for (String keyValuePairList : StringUtils.substringsBetween(innerMap, "{", "}")) { for (String keyValuePair : StringUtils.split(keyValuePairList, ',')) { currentMap.put(StringUtils.substringBefore(keyValuePair, "=").trim(), StringUtils.substringAfter(keyValuePair, "=").trim()); }//from ww w .j a v a2 s.c om } reviewContextMap.put(mapName, currentMap); } } return ReviewContext.createFromMap(reviewContextMap); }
From source file:org.sonar.plugins.flex.cpd.FlexCpdMavenSensor.java
String removeCDataNodes(String xml) { String result = xml;//from w ww.j av a 2 s. co m String startNode = "<codefragment>"; String endNode = "</codefragment>"; String[] subs = StringUtils.substringsBetween(xml, startNode, endNode); if (subs != null) { for (String sub : subs) { result = StringUtils.remove(result, startNode + sub + endNode); } } return result; }
From source file:org.sonar.plugins.gosu.codenarc.Rule.java
private Set<RuleParameter> extractParameters(AptResult results, String description) { Map<String, RuleParameter> extractedParameters = Maps.newHashMap(); addParameters(results, extractedParameters); String[] params1 = StringUtils.substringsBetween(description, "<em>", "</em> property"); if (params1 != null) { for (int i = 0; i < params1.length; i++) { String paramName = params1[i]; if (paramName.contains("<em>")) { params1[i] = paramName.substring(paramName.lastIndexOf("<em>") + 4); }/* w ww. jav a 2 s . c om*/ } addParameters(params1, ruleInstance, extractedParameters); } String[] params2 = StringUtils.substringsBetween(description, "configured in <em>", "</em>"); if (params2 != null) { addParameters(params2, ruleInstance, extractedParameters); } if (StringUtils.contains(description, "length property")) { addParameter("length", ruleInstance, extractedParameters); } if (StringUtils.contains(description, "sameLine property")) { addParameter("sameLine", ruleInstance, extractedParameters); } return Sets.newHashSet(extractedParameters.values()); }
From source file:org.sonar.plugins.gosu.codenarc.Rule.java
private String cleanDescription(String description) { String copy = description;/*from ww w . java 2s .co m*/ String[] refToParams = StringUtils.substringsBetween(description, " (${rule.", "})"); if (refToParams != null) { for (String ref : refToParams) { String paramRef = " (${rule." + ref + "})"; copy = copy.replace(paramRef, ""); } } return handleUrls(copy); }
From source file:org.sonar.plugins.groovy.codenarc.Converter.java
private void rule(Class<? extends AbstractRule> ruleClass, String since) throws Exception { if (duplications.contains(ruleClass)) { System.out.println("Duplicated rule " + ruleClass.getName()); } else {//from www . j a va 2s . c om duplications.add(ruleClass); } AbstractRule rule = ruleClass.newInstance(); String key = ruleClass.getCanonicalName(); String configKey = StringUtils.removeEnd(ruleClass.getSimpleName(), "Rule"); String name = StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(configKey), ' '); String priorityStr = priority(rule.getPriority()); String description = props.getProperty(configKey + ".description.html"); SortedSet<String> params = new TreeSet<String>(); // extract params String[] params1 = StringUtils.substringsBetween(description, "${", "}"); if (params1 != null) { for (String param : params1) { description = StringUtils.remove(description, " (${" + param + "})"); param = StringUtils.removeStart(param, "rule."); params.add(param); } } String[] params2 = StringUtils.substringsBetween(description, "<em>", "</em> property"); if (params2 != null) { params.addAll(Arrays.asList(params2)); } String[] params3 = StringUtils.substringsBetween(description, "configured in <em>", "</em>"); if (params3 != null) { params.addAll(Arrays.asList(params3)); } if (StringUtils.contains(description, "length property")) { params.add("length"); } if (StringUtils.contains(description, "sameLine property")) { params.add("sameLine"); } // output if (since != null) { out.println(" <!-- since " + since + " -->"); } out.println(" <rule key=\"" + key + "\"" + " priority=\"" + priorityStr + "\">"); out.println(" <name><![CDATA[" + name + "]]></name>"); out.println(" <configKey><![CDATA[" + configKey + "]]></configKey>"); out.println(" <description><![CDATA[" + description + "]]></description>"); if (params != null) { for (String param : params) { out.println(" <param key=\"" + param + "\"/>"); } } out.println(" </rule>"); out.println(); count++; }
From source file:org.sonar.plugins.ldap.LdapGroupMapping.java
/** * Constructs mapping from Sonar settings. *//*from www . j av a 2 s. c o m*/ public LdapGroupMapping(Settings settings, String settingsPrefix) { this.baseDn = settings.getString(settingsPrefix + ".group.baseDn"); this.idAttribute = StringUtils.defaultString(settings.getString(settingsPrefix + ".group.idAttribute"), DEFAULT_ID_ATTRIBUTE); String objectClass = settings.getString(settingsPrefix + ".group.objectClass"); String memberAttribute = settings.getString(settingsPrefix + ".group.memberAttribute"); String req; if (StringUtils.isNotBlank(objectClass) || StringUtils.isNotBlank(memberAttribute)) { // For backward compatibility with plugin versions 1.1 and 1.1.1 objectClass = StringUtils.defaultString(objectClass, DEFAULT_OBJECT_CLASS); memberAttribute = StringUtils.defaultString(memberAttribute, DEFAULT_MEMBER_ATTRIBUTE); req = "(&(objectClass=" + objectClass + ")(" + memberAttribute + "=" + "{dn}))"; LOG.warn("Properties '" + settingsPrefix + ".group.objectClass' and '" + settingsPrefix + ".group.memberAttribute' are deprecated" + " and should be replaced by single property '" + settingsPrefix + ".group.request' with value: " + req); } else { req = StringUtils.defaultString(settings.getString(settingsPrefix + ".group.request"), DEFAULT_REQUEST); } this.requiredUserAttributes = StringUtils.substringsBetween(req, "{", "}"); for (int i = 0; i < requiredUserAttributes.length; i++) { req = StringUtils.replace(req, "{" + requiredUserAttributes[i] + "}", "{" + i + "}"); } this.request = req; }
From source file:org.twinkql.context.TwinkqlContextFactory.java
/** * Replace markers.//from w w w. j a v a 2 s. c o m * * @param adder the adder * @param clazz the clazz * @param select the select * @param xmlStart the xml start * @param xmlEnd the xml end * @param marker the marker */ private void replaceMarkers(AddToSelectItem adder, Class<?> clazz, Select select, String xmlStart, String xmlEnd, String marker) { String content = select.getContent(); String[] newContents = StringUtils.substringsBetween(content, marker, marker); if (newContents != null) { for (String newContent : newContents) { String excapedContent = this.excapeInnerXml(newContent); String adjustedContent = xmlStart + excapedContent + xmlEnd; Object obj; try { obj = Unmarshaller.unmarshal(clazz, new StringReader(adjustedContent)); } catch (Exception e) { throw new RuntimeException(e); } SelectItem newSelectItem = new SelectItem(); adder.addToSelectItem(obj, newSelectItem); select.addSelectItem(newSelectItem); String uuid = "{" + UUID.randomUUID().toString() + "}"; content = StringUtils.replaceOnce(content, marker + newContent + marker, uuid); adder.setId(obj, uuid); } select.setContent(content); } }
From source file:org.wso2.identity.integration.test.openid.OpenIDSSOTestCase.java
private void assertAttributes(String results) { String str = results.substring(results.lastIndexOf("<table>")); String[] dataArray = StringUtils.substringsBetween(str, "<td>", "</td>"); Map<String, String> attributeMap = new HashMap<String, String>(); String key = null;/*w w w. j a v a2 s .c om*/ String value; for (int i = 0; i < dataArray.length; i++) { if ((i % 2) == 0) { key = dataArray[i]; } else { value = dataArray[i].trim(); attributeMap.put(key, value); } } OpenIDUtils.User user = config.getUser(); Assert.assertTrue(attributeMap.containsKey("email"), "Claim email is expected"); Assert.assertEquals(attributeMap.get("email"), user.getEmail(), "Expected claim value for email is " + user.getEmail()); Assert.assertTrue(attributeMap.containsKey("nickname"), "Claim nickname is expected"); Assert.assertEquals(attributeMap.get("nickname"), user.getUsername(), "Expected claim value for nickname is " + user.getUsername()); Assert.assertTrue(attributeMap.containsKey("lastname"), "Claim lastname is expected"); Assert.assertEquals(attributeMap.get("lastname"), user.getUsername(), "Expected claim value for lastname is " + user.getUsername()); }