Example usage for org.apache.commons.lang StringUtils countMatches

List of usage examples for org.apache.commons.lang StringUtils countMatches

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils countMatches.

Prototype

public static int countMatches(String str, String sub) 

Source Link

Document

Counts how many times the substring appears in the larger String.

Usage

From source file:org.wso2.carbon.esb.passthru.transport.test.ESBJAVA4468ContentTypeCharsetInResponseTestCase.java

@Test(groups = { "wso2.esb" }, description = "Test for charset value in the Content-Type header "
        + "in response once message is built in out out sequence")
public void charsetTestWithInComingContentType() throws Exception {

    Map<String, String> headers = new HashMap<>();

    headers.put("Content-Type", "text/xml;charset=UTF-8");
    headers.put("SOAPAction", "urn:getQuote");

    HttpResponse response = HttpRequestUtil.doPost(new URL(getProxyServiceURLHttp("contentTypeCharsetProxy1")),
            messagePayload, headers);/*from w ww .  jav  a  2  s .c  o  m*/
    Assert.assertNotNull(response, "Response is null");
    Assert.assertTrue(response.getData().contains("WSO2 Company"), "Response not as expected " + response);

    String contentType = response.getHeaders().get("Content-Type");
    Assert.assertTrue(contentType.contains("text/xml"), "Content-Type mismatched " + contentType);
    Assert.assertEquals(StringUtils.countMatches(contentType, HTTPConstants.CHAR_SET_ENCODING), 1,
            "charset repeated in Content-Type header " + contentType);

}

From source file:org.wso2.carbon.esb.passthru.transport.test.ESBJAVA4468ContentTypeCharsetInResponseTestCase.java

@Test(groups = { "wso2.esb" }, description = "Test for charset value in the Content-Type header "
        + "in response once message is built in out out sequence " + "with messageType")
public void charsetTestByChangingContentType() throws Exception {

    Map<String, String> headers = new HashMap<>();

    headers.put("Content-Type", "text/xml;charset=UTF-8");
    headers.put("SOAPAction", "urn:getQuote");

    HttpResponse response = HttpRequestUtil.doPost(new URL(getProxyServiceURLHttp("contentTypeCharsetProxy2")),
            messagePayload, headers);/* ww w.  ja  v a 2s  .c o  m*/
    Assert.assertNotNull(response, "Response is null");
    Assert.assertTrue(response.getData().contains("WSO2 Company"), "Response not as expected " + response);

    String contentType = response.getHeaders().get("Content-Type");
    Assert.assertTrue(contentType.contains("application/xml"), "Content-Type is not changed " + contentType);
    Assert.assertEquals(StringUtils.countMatches(contentType, HTTPConstants.CHAR_SET_ENCODING), 1,
            "charset repeated in Content-Type header " + contentType);
}

From source file:org.wso2.carbon.esb.passthru.transport.test.ESBJAVA4468ContentTypeCharsetInResponseTestCase.java

@Test(groups = { "wso2.esb" }, description = "Test for charset value in the Content-Type header "
        + "in response once message is built in out out sequence " + "with messageType with charset")
public void charsetTestByChangingContentTypeWithCharset() throws Exception {

    Map<String, String> headers = new HashMap<>();

    headers.put("Content-Type", "text/xml;charset=UTF-8");
    headers.put("SOAPAction", "urn:getQuote");

    HttpResponse response = HttpRequestUtil.doPost(new URL(getProxyServiceURLHttp("contentTypeCharsetProxy3")),
            messagePayload, headers);//w w w  . j a v  a2s  .  com
    Assert.assertNotNull(response, "Response is null");
    Assert.assertTrue(response.getData().contains("WSO2 Company"), "Response not as expected " + response);

    String contentType = response.getHeaders().get("Content-Type");
    Assert.assertTrue(contentType.contains("application/xml"), "Content-Type is not changed " + contentType);
    Assert.assertEquals(StringUtils.countMatches(contentType, HTTPConstants.CHAR_SET_ENCODING), 1,
            "charset repeated in Content-Type header " + contentType);
}

From source file:org.wso2.carbon.integration.common.tests.DistributionValidationTest.java

@Test(groups = "wso2.all", description = "Recursive scan to identify SNAPSHOT keyword inside "
        + "the distribution", dependsOnMethods = "testValidateDuplicateJarEntriesInLicenceFile")
public void testRecursiveScanForSnapshotKeyword() throws IOException {

    String[] extensions = new String[] { "txt", "xsd", "js" };

    // getting the textual file list
    List<File> distributionTextualFileList = DistributionValidationTestUtils
            .recursiveScanToRetrieveTextualFiles(productPath, extensions);

    ArrayList<String> textualFileNameWithSnapshotKeyword = new ArrayList<String>();

    for (File textualFile : distributionTextualFileList) {

        int count;

        //checking for file names which contains the keyword
        if (textualFile.getName().contains(KEYWORD)) {
            textualFileNameWithSnapshotKeyword.add(textualFile.toString());
        }/*from  w w w. jav  a2s.  c om*/

        // checking for the specific keyword inside textual file contents
        String contents = FileUtils.readFileToString(textualFile);
        count = StringUtils.countMatches(contents, KEYWORD);

        if (count > 0) {
            snapshotKeywordMap.put(textualFile, count);
        }
    }

    Iterator<File> it = jarFileListInDistribution.iterator();
    ArrayList<String> jarFileNameWithSnapshotKeyword = new ArrayList<String>();

    while (it.hasNext()) {
        String fileName = (it.next()).getName();
        if (fileName.contains(KEYWORD)) {
            jarFileNameWithSnapshotKeyword.add(fileName);
        }
    }

    DistributionValidationTestUtils.reportGeneratorList(textualFileNameWithSnapshotKeyword,
            "Following are the" + " textual file names which contain " + KEYWORD + " keyword", reportFile);

    DistributionValidationTestUtils.reportGeneratorMap(snapshotKeywordMap,
            "List of textual file names together" + " with number of occurrences of " + KEYWORD + " keyword",
            reportFile);

    DistributionValidationTestUtils.reportGeneratorList(jarFileNameWithSnapshotKeyword,
            "List of jar file " + "names which contain " + KEYWORD + " keyword", reportFile);

    assertFalse("Textual file names with " + KEYWORD + " exists inside the product distribution",
            textualFileNameWithSnapshotKeyword.size() > 0);

    assertFalse("Occurrence of the keyword" + KEYWORD + " inside a textual file/s contents " + "detected",
            snapshotKeywordMap.size() > 0);

    assertFalse("Jar file names with " + KEYWORD + " exists inside the product distribution",
            jarFileNameWithSnapshotKeyword.size() > 0);
}

From source file:org.wso2.javaagent.JDBCAgentPublisher.java

/**
 * Count the number of parameters to be filled and create a array list to store actual values
 * Pass the obtained query to originalQuery
 * @param query original query obtained/*  w  ww  .  ja va 2  s . c o m*/
 */
public static void setObtainedQuery(String query) {
    originalQuery = query;
    variableCount = StringUtils.countMatches(query, "?");
    if (variableCount > 0) {
        arrayList = new ArrayList();
    }
}

From source file:org.wso2.javaagent.JDBCClassTransformer.java

/**
 * Check the signature of executeUpdate method and instrument methods without any argument
 * and method with single argument. Call reimplementQuery, for methods which don not
 * contain any parameters//from ww  w. j av a  2  s .  c o m
 * 
 * @param method currently processing method as a ctMethod object
 * @throws NotFoundException
 */
private void testExecuteUpdateSignature(CtMethod method) throws NotFoundException {
    String methodSignature = method.getSignature();
    if ((methodSignature.substring(methodSignature.indexOf('('), methodSignature.indexOf(')') + 1)).equals("()")
            || StringUtils.countMatches(methodSignature, "(Ljava/lang/String;)") == 1) {
        if (StringUtils.countMatches(methodSignature, "(Ljava/lang/String;)") == 1) {
            try {
                method.insertAt(1, true,
                        "org.wso2.javaagent.JDBCAgentPublisher.publishEvents("
                                + "org.wso2.javaagent.JDBCAgentPublisher.getDataPublisher(), "
                                + "org.wso2.javaagent.JDBCAgentPublisher.getStreamId(), "
                                + "org.wso2.javaagent.JDBCAgentPublisher.getConnectionURL(), " + "$1);");
            } catch (CannotCompileException e) {
                e.printStackTrace();
            }
        } else {
            this.reimplementQuery(method);
        }
    }
}

From source file:org.yes.cart.service.image.impl.AbstractImageNameStrategyImpl.java

/**
 * {@inheritDoc}//from   w ww .j av  a2 s  .  c  o m
 */
@Cacheable(value = "imageNameStrategy-resolveObjectCode")
public String resolveObjectCode(final String url) {

    if (StringUtils.isNotBlank(url)) {

        final int extPos = url.lastIndexOf('.');
        if (extPos > -1) {

            final String urlNoExt = url.substring(0, extPos);

            if (urlNoExt.indexOf('_') > -1) {

                final String locale = resolveLocale(url);
                final String urlNoLocale;
                if (locale != null) {
                    urlNoLocale = urlNoExt.substring(0, urlNoExt.length() - locale.length() - 1);
                } else {
                    urlNoLocale = urlNoExt;
                }

                if (urlNoLocale.indexOf('_') > -1 && StringUtils.countMatches(urlNoLocale, "_") > 1) {
                    final String[] nameParts = urlNoLocale.split("_");
                    final String candidate = nameParts[nameParts.length - 2];
                    if (nameParts[nameParts.length - 1].length() == 1) {
                        final char csuf = nameParts[nameParts.length - 1].charAt(0);
                        if (csuf >= 'a' && csuf <= 'g') {
                            return candidate;
                        }
                    }
                }

            }
        }

        final String code = resolveObjectCodeInternal(url);
        if (code != null) {
            return code;
        }

    }

    return Constants.NO_IMAGE;
}

From source file:org.yes.cart.service.image.impl.AbstractImageNameStrategyImpl.java

/**
 * {@inheritDoc}//from www.  j  a va2 s. c  om
 */
@Cacheable(value = "imageNameStrategy-resolveSuffix")
public String resolveSuffix(final String url) {

    if (StringUtils.isNotBlank(url)) {

        final int extPos = url.lastIndexOf('.');
        if (extPos > -1) {

            final String urlNoExt = url.substring(0, extPos);

            if (urlNoExt.indexOf('_') > -1) {

                final String locale = resolveLocale(url);
                final String urlNoLocale;
                if (locale != null) {
                    urlNoLocale = urlNoExt.substring(0, urlNoExt.length() - locale.length() - 1);
                } else {
                    urlNoLocale = urlNoExt;
                }

                if (urlNoLocale.indexOf('_') > -1 && StringUtils.countMatches(urlNoLocale, "_") > 1) {
                    final String[] nameParts = urlNoLocale.split("_");
                    if (nameParts[nameParts.length - 1].length() == 1) {
                        final char csuf = nameParts[nameParts.length - 1].charAt(0);
                        if (csuf >= 'a' && csuf <= 'g') {
                            return String.valueOf(0 + csuf - 'a');
                        }
                    }
                }

            }
        }

    }

    return "0";
}

From source file:org.yes.cart.service.image.impl.ProductImageNameStrategyImpl.java

/**
 * {@inheritDoc}//from ww  w  .  java2s .  co m
 */
@Cacheable(value = "productImageNameStrategyService-productCode")
public String getCode(final String url) {

    if (StringUtils.isNotBlank(url)) {

        if (url.indexOf('_') > -1 && StringUtils.countMatches(url, "_") > 1) {
            final String[] nameParts = url.split("_");
            final String candidate = nameParts[nameParts.length - 2];
            if (nameParts[nameParts.length - 1].indexOf('.') == 1) {
                final char csuf = nameParts[nameParts.length - 1].charAt(0);
                if (csuf >= 'a' && csuf <= 'g') {
                    return candidate;
                }
            }
        }

        final String val = getFileNameWithoutPrefix(url);

        final String productCode = attrValueEntityProductDao
                .findSingleByNamedQuery("PRODUCT.CODE.BY.IMAGE.NAME", val);
        if (productCode != null) {
            return productCode;
        }

        final String skuCode = attrValueEntityProductSkuDao.findSingleByNamedQuery("SKU.CODE.BY.IMAGE.NAME",
                val);
        if (skuCode != null) {
            return skuCode;
        }

    }

    return Constants.NO_IMAGE;
}

From source file:pl.otros.logview.gui.message.pattern.PropertyPatternMessageColorizer.java

protected int countGroups(Pattern pattern) {
    int count = StringUtils.countMatches(pattern.pattern().replace("\\(", ""), "(");
    return count;
}