Example usage for org.apache.commons.lang3 StringUtils substringAfter

List of usage examples for org.apache.commons.lang3 StringUtils substringAfter

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringAfter.

Prototype

public static String substringAfter(final String str, final String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:io.cloudslang.lang.compiler.modeller.ExecutableBuilder.java

private String resolveDoReferenceId(String rawReferenceId, Map<String, String> imports, String namespace) {

    int numberOfDelimiters = StringUtils.countMatches(rawReferenceId, NAMESPACE_DELIMITER);
    String resolvedReferenceId;/*from   w w  w  .  j  a v  a 2s.c  o m*/

    if (numberOfDelimiters == 0) {
        // implicit namespace
        resolvedReferenceId = namespace + NAMESPACE_DELIMITER + rawReferenceId;
    } else {
        String prefix = StringUtils.substringBefore(rawReferenceId, NAMESPACE_DELIMITER);
        String suffix = StringUtils.substringAfter(rawReferenceId, NAMESPACE_DELIMITER);
        if (MapUtils.isNotEmpty(imports) && imports.containsKey(prefix)) {
            // expand alias
            resolvedReferenceId = imports.get(prefix) + NAMESPACE_DELIMITER + suffix;
        } else {
            // full path without alias expanding
            resolvedReferenceId = rawReferenceId;
        }
    }

    return resolvedReferenceId;
}

From source file:edu.si.services.beans.edansidora.EdanAPITest.java

@Test
public void solrIDSTest() throws Exception {

    MockEndpoint mockResult = getMockEndpoint("mock:result");

    //Test IDS solr
    SOLR_PORT = 8089;//from  w w w.  j a  v  a2s .  c o m
    String uri = SOLR_SERVER + ":" + SOLR_PORT + "/solr/ids/select";
    String solrQuery = "archive:EMAMMAL AND uan:emammal_image_d33997s6i1";
    String httpQuery = "?q=" + URLEncoder.encode(solrQuery, "UTF-8") + "&wt=json&indent=true";

    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setHeader("CamelHttpMethod", "GET");
    exchange.getIn().setHeader("CamelHttpQuery", httpQuery);
    exchange.getIn().setHeader("uri", uri);

    assumeTrue("The Solr Server could not be found! Make sure you are connected to SI VPN!",
            hostAvailabilityCheck(SOLR_SERVER, SOLR_PORT));

    template.send("direct:solrTest", exchange);

    assertMockEndpointsSatisfied();

    JSONObject json = new JSONObject(mockResult.getExchanges().get(0).getIn().getBody(String.class));

    String expected_archive = StringUtils.substringBetween(solrQuery, "archive:", " ");
    String result_archive = json.getJSONObject("response").getJSONArray("docs").getJSONObject(0)
            .getString("archive");
    LOG.info("Expected archive = {}, Returned archive = {}", expected_archive, result_archive);
    assertEquals("The returned archive does not match", expected_archive, result_archive);

    String expected_uan = StringUtils.substringAfter(solrQuery, "uan:");
    String result_uan = json.getJSONObject("response").getJSONArray("docs").getJSONObject(0).getString("uan");
    LOG.info("Expected uan = {}, Returned uan = {}", expected_uan, result_uan);
    assertEquals("The returned uan does not match", expected_uan, result_uan);

}

From source file:io.wcm.handler.url.impl.UrlHandlerImplTest.java

/**
 * Simulate mapping:/*w w w.j a v  a2 s  .com*/
 * - /content/unittest/de_test/brand/de -> /de
 * - /content/* -> /*
 */
private static MockSlingHttpServletRequest applySimpleMapping(SlingHttpServletRequest request) {
    ResourceResolver spyResolver = spy(request.getResourceResolver());
    Answer<String> mappingAnswer = new Answer<String>() {
        @Override
        public String answer(InvocationOnMock invocation) {
            SlingHttpServletRequest mapRequest;
            String path;
            if (invocation.getArguments()[0] instanceof SlingHttpServletRequest) {
                mapRequest = (SlingHttpServletRequest) invocation.getArguments()[0];
                path = (String) invocation.getArguments()[1];
            } else {
                mapRequest = null;
                path = (String) invocation.getArguments()[0];
            }
            if (StringUtils.startsWith(path, "/content/unittest/de_test/brand/")) {
                path = "/" + StringUtils.substringAfter(path, "/content/unittest/de_test/brand/");
            }
            if (StringUtils.startsWith(path, "/content/")) {
                path = "/" + StringUtils.substringAfter(path, "/content/");
            }
            if (mapRequest != null) {
                path = StringUtils.defaultString(mapRequest.getContextPath()) + path;
            }
            path = Externalizer.mangleNamespaces(path);
            try {
                return URLEncoder.encode(path, CharEncoding.UTF_8);
            } catch (UnsupportedEncodingException ex) {
                throw new RuntimeException(ex);
            }
        }
    };
    when(spyResolver.map(anyString())).thenAnswer(mappingAnswer);
    when(spyResolver.map(any(SlingHttpServletRequest.class), anyString())).thenAnswer(mappingAnswer);
    MockSlingHttpServletRequest newRequest = new MockSlingHttpServletRequest(spyResolver);
    newRequest.setResource(request.getResource());
    newRequest.setContextPath(request.getContextPath());
    return newRequest;
}

From source file:cgeo.geocaching.connector.gc.GCParser.java

public static List<PocketQueryList> searchPocketQueryList() {

    final Parameters params = new Parameters();

    final String page = GCLogin.getInstance().getRequestLogged("http://www.geocaching.com/pocket/default.aspx",
            params);//from  w  w  w  .  j a  v a2  s .  c o  m

    if (StringUtils.isBlank(page)) {
        Log.e("GCParser.searchPocketQueryList: No data from server");
        return null;
    }

    String subPage = StringUtils.substringAfter(page, "class=\"PocketQueryListTable");
    if (StringUtils.isEmpty(subPage)) {
        Log.e("GCParser.searchPocketQueryList: class \"PocketQueryListTable\" not found on page");
        return Collections.emptyList();
    }

    List<PocketQueryList> list = new ArrayList<PocketQueryList>();

    final MatcherWrapper matcherPocket = new MatcherWrapper(GCConstants.PATTERN_LIST_PQ, subPage);

    while (matcherPocket.find()) {
        int maxCaches;
        try {
            maxCaches = Integer.parseInt(matcherPocket.group(1));
        } catch (NumberFormatException e) {
            maxCaches = 0;
            Log.e("GCParser.searchPocketQueryList: Unable to parse max caches", e);
        }
        final String guid = Html.fromHtml(matcherPocket.group(2)).toString();
        final String name = Html.fromHtml(matcherPocket.group(3)).toString();
        final PocketQueryList pqList = new PocketQueryList(guid, name, maxCaches);
        list.add(pqList);
    }

    // just in case, lets sort the resulting list
    Collections.sort(list, new Comparator<PocketQueryList>() {

        @Override
        public int compare(PocketQueryList left, PocketQueryList right) {
            return String.CASE_INSENSITIVE_ORDER.compare(left.getName(), right.getName());
        }
    });

    return list;
}

From source file:com.gargoylesoftware.htmlunit.WebClient.java

private WebResponse makeWebResponseForAboutUrl(final URL url) {
    final String urlWithoutQuery = StringUtils.substringBefore(url.toExternalForm(), "?");
    if (!"blank".equalsIgnoreCase(StringUtils.substringAfter(urlWithoutQuery, "about:"))) {
        throw new IllegalArgumentException(url + " is not supported, only about:blank is supported now.");
    }//from   www . j a  v a 2s.co  m
    return new StringWebResponse("", URL_ABOUT_BLANK);
}

From source file:me.ryanhamshire.griefprevention.DataStore.java

public Text parseMessage(Messages messageID, TextColor color, String... args) {
    String message = GriefPreventionPlugin.instance.dataStore.getMessage(messageID, args);
    Text textMessage = Text.of(color, message);
    List<String> urls = extractUrls(message);
    if (urls.isEmpty()) {
        return textMessage;
    }//ww w  .j  ava 2s.  c  o m

    Iterator<String> iterator = urls.iterator();
    while (iterator.hasNext()) {
        String url = iterator.next();
        String msgPart = StringUtils.substringBefore(message, url);

        if (msgPart != null && !msgPart.equals("")) {
            try {
                textMessage = Text.of(color, msgPart, TextColors.GREEN, TextActions.openUrl(new URL(url)), url);
            } catch (MalformedURLException e) {
                e.printStackTrace();
                return Text.of(message);
            }
        }

        iterator.remove();
        message = StringUtils.substringAfter(message, url);
    }

    if (message != null && !message.equals("")) {
        textMessage = Text.of(textMessage, " ", color, message);
    }

    return textMessage;
}

From source file:it.at.script.ConnectionScannerTest.java

public static String getRealPathOfResource(String resourceName) throws IOException {
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    final Enumeration<URL> resources = loader.getResources(resourceName);
    final String path = resources.nextElement().toString();
    final String replace = StringUtils.replace(path, "target/test-classes", "src/test/resources");
    return StringUtils.substringAfter(replace, "file:");
}

From source file:net.thirdy.blackmarket.util.BlackmarketConfig.java

private static Map<String, String> parseBlackmarketRawFile(File blackarketFile) {
    Map<String, String> map = new HashMap<>();
    String raw = readFileToString(blackarketFile);
    if (StringUtils.isNotBlank(raw)) {
        String[] lines = StringUtils.split(raw, BlackmarketUtil.lineSep());
        for (String line : lines) {
            if (isLineNotComment(line) && StringUtils.isNotBlank(line)) {
                // substringBefore/substringAfter is first occurance
                String key = StringUtils.substringBefore(line, "=");
                String value = StringUtils.substringAfter(line, "=");
                key = StringUtils.trim(key);
                value = StringUtils.trim(value);
                map.put(key, value);//from   w ww .  j  av  a 2 s .com
            }
        }
    }
    return map;
}

From source file:net.tirasa.olingooauth2.AzureADOAuth2HttpClientFactory.java

@Override
protected void init() throws OAuth2Exception {
    final DefaultHttpClient httpClient = wrapped.create(null, null);

    // 1. access the OAuth2 grant service (with authentication)
    String code = null;/*from w  ww  . j a  v  a 2s .  co m*/
    try {
        final URIBuilder builder = new URIBuilder(oauth2GrantServiceURI).addParameter("response_type", "code")
                .addParameter("client_id", clientId).addParameter("redirect_uri", redirectURI);

        HttpResponse response = httpClient.execute(new HttpGet(builder.build()));

        final String loginPage = EntityUtils.toString(response.getEntity());

        String postURL = StringUtils.substringBefore(
                StringUtils.substringAfter(loginPage, "<form id=\"credentials\" method=\"post\" action=\""),
                "\">");
        final String ppsx = StringUtils.substringBefore(StringUtils.substringAfter(loginPage,
                "<input type=\"hidden\" id=\"PPSX\" name=\"PPSX\" value=\""), "\"/>");
        final String ppft = StringUtils.substringBefore(StringUtils.substringAfter(loginPage,
                "<input type=\"hidden\" name=\"PPFT\" id=\"i0327\" value=\""), "\"/>");

        List<BasicNameValuePair> data = new ArrayList<BasicNameValuePair>();
        data.add(new BasicNameValuePair("login", creds.getUserName()));
        data.add(new BasicNameValuePair("passwd", creds.getPassword()));
        data.add(new BasicNameValuePair("PPSX", ppsx));
        data.add(new BasicNameValuePair("PPFT", ppft));

        HttpPost post = new HttpPost(postURL);
        post.setEntity(new UrlEncodedFormEntity(data, "UTF-8"));

        response = httpClient.execute(post);

        final String samlPage = EntityUtils.toString(response.getEntity());

        postURL = StringUtils.substringBefore(
                StringUtils.substringAfter(samlPage, "<form name=\"fmHF\" id=\"fmHF\" action=\""),
                "\" method=\"post\" target=\"_top\">");
        final String wctx = StringUtils.substringBefore(StringUtils.substringAfter(samlPage,
                "<input type=\"hidden\" name=\"wctx\" id=\"wctx\" value=\""), "\">");
        final String wresult = StringUtils.substringBefore(StringUtils.substringAfter(samlPage,
                "<input type=\"hidden\" name=\"wresult\" id=\"wresult\" value=\""), "\">");
        final String wa = StringUtils.substringBefore(
                StringUtils.substringAfter(samlPage, "<input type=\"hidden\" name=\"wa\" id=\"wa\" value=\""),
                "\">");

        data = new ArrayList<BasicNameValuePair>();
        data.add(new BasicNameValuePair("wctx", wctx));
        data.add(new BasicNameValuePair("wresult", wresult.replace("&quot;", "\"")));
        data.add(new BasicNameValuePair("wa", wa));

        post = new HttpPost(postURL);
        post.setEntity(new UrlEncodedFormEntity(data, "UTF-8"));

        response = httpClient.execute(post);

        final Header locationHeader = response.getFirstHeader("Location");
        if (response.getStatusLine().getStatusCode() != 302 || locationHeader == null) {
            throw new OAuth2Exception("Unexpected response from server");
        }

        final String[] oauth2Info = StringUtils
                .split(StringUtils.substringAfter(locationHeader.getValue(), "?"), '&');
        code = StringUtils.substringAfter(oauth2Info[0], "=");

        EntityUtils.consume(response.getEntity());
    } catch (Exception e) {
        throw new OAuth2Exception(e);
    }

    if (code == null) {
        throw new OAuth2Exception("No OAuth2 grant");
    }

    // 2. ask the OAuth2 token service
    final List<BasicNameValuePair> data = new ArrayList<BasicNameValuePair>();
    data.add(new BasicNameValuePair("grant_type", "authorization_code"));
    data.add(new BasicNameValuePair("code", code));
    data.add(new BasicNameValuePair("client_id", clientId));
    data.add(new BasicNameValuePair("redirect_uri", redirectURI));
    data.add(new BasicNameValuePair("resource", resourceURI));

    fetchAccessToken(httpClient, data);

    if (token == null) {
        throw new OAuth2Exception("No OAuth2 access token");
    }
}

From source file:nl.armatiek.xslweb.configuration.WebApp.java

public File getStaticFile(String path) {
    String relPath = (name.equals("ROOT")) ? path.substring(1)
            : StringUtils.substringAfter(path, this.name + "/");
    return new File(this.homeDir, "static" + "/" + relPath);
}