Example usage for java.lang String replaceFirst

List of usage examples for java.lang String replaceFirst

Introduction

In this page you can find the example usage for java.lang String replaceFirst.

Prototype

public String replaceFirst(String regex, String replacement) 

Source Link

Document

Replaces the first substring of this string that matches the given regular expression with the given replacement.

Usage

From source file:com.splunk.shuttl.archiver.LocalFileSystemPaths.java

private String removeEventualFileSchema(String path) {
    if (path.startsWith("file:/"))
        return path.replaceFirst("file:/", "");
    return path;//w ww.  j a v a2  s  .c o  m
}

From source file:edu.umass.cs.gigapaxos.PaxosConfig.java

/**
 * @return A map of names and socket addresses corresponding to servers
 *         hosting paxos replicas./*  w  w  w .  j a  v a2 s.c om*/
 */
public static Map<String, InetSocketAddress> getActives() {
    Map<String, InetSocketAddress> map = new HashMap<String, InetSocketAddress>();
    Properties config = getAsProperties();

    Set<String> keys = config.stringPropertyNames();
    for (String key : keys) {
        if (key.trim().startsWith(DEFAULT_SERVER_PREFIX)) {
            map.put(key.replaceFirst(DEFAULT_SERVER_PREFIX, ""),
                    Util.getInetSocketAddressFromString(config.getProperty(key)));
        }
    }
    return map;
}

From source file:com.hp.autonomy.frontend.find.core.web.ControllerUtilsImpl.java

private String getBaseUrl(final HttpServletRequest request) {
    final String originalUri = (String) request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
    final String requestUri = originalUri != null ? originalUri : request.getRequestURI();
    final String path = requestUri.replaceFirst(request.getContextPath(), "");
    final int depth = StringUtils.countMatches(path, "/") - 1;

    return depth <= 0 ? "." : StringUtils.repeat("../", depth);
}

From source file:net.rptools.maptool.util.PersistenceUtil.java

/**
 * Determines whether the incoming map name is unique. If it is, it's
 * returned as-is. If it's not unique, a newly generated name is returned.
 *
 * @param n// w ww. j  a v  a  2  s.  c o m
 *            name from imported map
 * @return new name to use for the map
 */
private static String fixupZoneName(String n) {
    List<Zone> zones = MapTool.getCampaign().getZones();
    for (Zone zone : zones) {
        if (zone.getName().equals(n)) {
            String count = n.replaceFirst("Import (\\d+) of.*", "$1"); //$NON-NLS-1$
            Integer next = 1;
            try {
                next = StringUtil.parseInteger(count) + 1;
                n = n.replaceFirst("Import \\d+ of", "Import " + next + " of"); //$NON-NLS-1$
            } catch (ParseException e) {
                n = "Import " + next + " of " + n; //$NON-NLS-1$
            }
        }
    }
    return n;
}

From source file:eu.ggnet.dwoss.util.HtmlDialog.java

public HtmlDialog setText(String text) {
    documentTextPane.setText(text.replaceFirst("\\<\\?.*\\?\\>", "")); // Solution for XHTML
    documentTextPane.setCaretPosition(0);
    return this;
}

From source file:com.asual.summer.core.view.AbstractResponseView.java

protected String getFilename(HttpServletRequest request) {
    String requestUri = urlPathHelper.getLookupPathForRequest(request);
    String filename = WebUtils.extractFullFilenameFromUrlPath(requestUri);
    String extension = StringUtils.getFilenameExtension(filename);
    return filename.replaceFirst("\\." + extension + "$", "") + "." + getExtension();
}

From source file:com.boundary.sdk.event.notification.WebhookRouteBuilderTest.java

@Test
public void testNotification() throws InterruptedException, IOException {
    String body = readFile(NOTIFICATION_JSON, Charset.defaultCharset());

    out.setExpectedMessageCount(1);// w w w  . ja v a  2  s  .c  om

    // Get the url from the sprint DSL file by
    // 1) Getting the context
    // 2) Getting the registry
    // 3) Lookup the bean
    // 4) Call method to get url
    // 5) Strip out component name, "jetty:"
    CamelContext context = out.getCamelContext();
    Registry registry = context.getRegistry();
    WebHookRouteBuilder builder = (WebHookRouteBuilder) registry.lookupByName("webhook-route-builder");
    assertNotNull("builder is null", builder);
    String url = null;
    url = builder.getFromUri();
    url = url.replaceFirst("jetty:", "");
    LOG.debug("url {}", url);

    // Send an HTTP request with the JSON paylod that is sent
    // from a Boundary Event Notification
    HttpClient httpclient = new HttpClient();
    PostMethod httppost = new PostMethod(url);
    Header contentHeader = new Header("Content-Type", "application/json");
    httppost.setRequestHeader(contentHeader);
    StringRequestEntity reqEntity = new StringRequestEntity(body, null, null);
    httppost.setRequestEntity(reqEntity);

    // Check our reponse status
    int status = httpclient.executeMethod(httppost);
    assertEquals("Received wrong response status", 200, status);

    // Assert the mock end point
    out.assertIsSatisfied();

    // Get
    List<Exchange> exchanges = out.getExchanges();
    LOG.debug("EXCHANGE COUNT: " + exchanges.size());
    for (Exchange exchange : exchanges) {
        Message message = exchange.getIn();
        Object o = message.getBody();
        LOG.debug("class: " + o.getClass().toString());
        Notification notif = message.getBody(Notification.class);
        validateNotification(notif);
    }
}

From source file:com.norconex.collector.http.delay.impl.SiteDelay.java

public void delay(long expectedDelayNanos, String url) {
    if (expectedDelayNanos <= 0) {
        return;/*w  ww .  j a  v  a  2s .  com*/
    }
    String site = StringUtils.lowerCase(url.replaceFirst("(.*?//.*?)(/.*)|$]", "$1"));
    SleepState sleepState = null;
    try {
        synchronized (siteLastHitNanos) {
            sleepState = siteLastHitNanos.get(site);
            if (sleepState == null) {
                siteLastHitNanos.put(site, new SleepState());
                return;
            }
            while (sleepState.sleeping) {
                Sleeper.sleepNanos(Math.min(TINY_SLEEP_MS, expectedDelayNanos));
            }
            sleepState.sleeping = true;
        }
        delay(expectedDelayNanos, sleepState.lastHitEpochNanos);
        sleepState.lastHitEpochNanos = System.nanoTime();
    } finally {
        if (sleepState != null) {
            sleepState.sleeping = false;
        }
    }
}

From source file:br.com.munif.personalsecurity.aplicacao.autorizacao.Autorizador.java

protected String[] getUrlParameters(HttpServletRequest request) {
    url = this.getServletContext().getContextPath()
            + this.getClass().getAnnotation(WebServlet.class).urlPatterns()[0].replace("/*", "").trim();
    String paramters = request.getRequestURI().replaceFirst(url, "");
    paramters = paramters.replaceFirst("/", "");
    if (paramters.isEmpty()) {
        return new String[0];
    }/*  w  w  w. ja  v a 2s .c  o m*/
    return paramters.split("/");
}

From source file:ddf.catalog.transformer.output.rtf.model.ExportCategory.java

private String attributeKeyFrom(String key) {
    if (key.startsWith(EXTENDED_ATTRIBUTE_PREFIX)) {
        key = key.replaceFirst(EXTENDED_ATTRIBUTE_PREFIX, "");
    }/*from ww  w.j a v a  2  s. c o  m*/

    String formattedAttribute = Stream.of(key.split("\\.")).map(part -> part.replaceAll("-", " "))
            .collect(Collectors.joining(" "));

    return WordUtils.capitalize(formattedAttribute);
}