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.clustercontrol.jobmanagement.util.ParameterUtil.java

/**
 * #[RETURN:jobId:facilityId]??/*from w  w  w  . j  av  a 2  s .  c om*/
 * @param sessionId
 * @param jobunitId
 * @param jobId
 * @param source
 * @return
 */
public static String replaceReturnCodeParameter(String sessionId, String jobunitId, String source) {
    String regex = "#\\[RETURN:([^:]*):([^:]*)\\]";
    Pattern pattern = Pattern.compile(regex);
    String ret = source;
    for (int i = 0; i < 100; i++) { //??????????
        Matcher matcher = pattern.matcher(ret);
        if (matcher.find()) {
            String rJobId = matcher.group(1);
            String rFacilityId = matcher.group(2);
            try {
                JobSessionNodeEntity node = QueryUtil.getJobSessionNodePK(sessionId, jobunitId, rJobId,
                        rFacilityId);
                Integer endValue = node.getEndValue();
                if (endValue != null) {
                    ret = ret.replaceFirst(regex, endValue.toString());
                } else {
                    // ??????
                    ret = ret.replaceFirst(regex, "null");
                }
            } catch (JobInfoNotFound e) {
                m_log.warn("replaceReturnCodeParameter : jobId=" + rJobId + ", facilityId=" + rFacilityId);
                // ?ID????
                ret = ret.replaceFirst(regex, "null");
            }
            /*
             * for test
             * ?(??main?)??
             */
            // ret = ret.replaceFirst(regex, "12345");
        } else {
            break;
        }
    }
    return ret;
}

From source file:com.amalto.webapp.core.util.Util.java

public static String getFormatedFKInfo(String info, String conceptName) {
    info = info.substring(info.startsWith("/") ? 1 : 0); //$NON-NLS-1$
    String formatedInfo = info;/*from   w w  w. j a va2  s  .  c  om*/
    if (info.startsWith("./")) { //$NON-NLS-1$
        formatedInfo = info.replaceFirst("./", conceptName + "/"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    return formatedInfo;
}

From source file:com.liferay.jenkins.tools.TestJsonGetter.java

private String formatURL(String url) {
    url = url.replaceFirst("api/json.*", "");
    url = url.replaceFirst("/+$", "");

    return url;//from   w ww.  j av  a2  s.c o  m
}

From source file:org.apache.taverna.databundle.DataBundles.java

protected static String withExtensionFilename(String filename, String extension) {
    if (!extension.isEmpty() && !extension.startsWith("."))
        throw new IllegalArgumentException("Extension must be empty or start with .");
    if (!extension.isEmpty() && filename.toLowerCase().endsWith(extension.toLowerCase()))
        return filename;
    // Everything after the last . - or just the end
    return filename.replaceFirst("(\\.[^.]*)?$", extension);
}

From source file:Main.java

/**
 * Parses string ending with format ([FILE]:[LINE MODULE])
 * Assumes syntax is: "\(.*:[0-9]+(\s.+)?\)$"
 * @param line - String with the above criteria
 * @return a tuple of [String filename, Integer line]
 *///w  ww.j  ava2 s . c om
public static Object[] parseFilename(String line) {
    String filename = null;
    int lineNo = 0;

    int ix = line.lastIndexOf('(');
    if (ix >= 0) {
        String part = line.substring(ix, line.length());
        part = part.substring(1, part.length() - 1); // remove leading and trailing parentheses
        if ((ix = part.lastIndexOf(':')) >= 0) {
            String strLineNo = part.substring(ix + 1);
            if (isNumber(strLineNo)) {
                lineNo = Integer.parseInt(strLineNo);
                filename = part.substring(0, ix);
            } else {
                // handle format: (FILE:LINE MODULE)
                int ix1 = strLineNo.indexOf(' ');
                if (ix1 > 0) {
                    strLineNo = strLineNo.substring(0, ix1);
                    if (isNumber(strLineNo)) {
                        lineNo = Integer.parseInt(strLineNo);
                        filename = part.substring(0, ix);
                    }
                }
            }
        } else {
            // check for "in " token (lib, with symbol)
            part = part.replaceFirst("^in ", EMPTY_STRING); //$NON-NLS-1$
            // check for "within " token (lib, without symbol)
            part = part.replaceFirst("^within ", EMPTY_STRING); //$NON-NLS-1$
            filename = part; // library, no line number
        }
    }

    return new Object[] { filename, lineNo };
}

From source file:com.codyengel.simplenetworking.ui.details.UserDetailsRenderer.java

private void setPhone(String phone) {
    String formattedPhone = phone.replaceFirst("-", " ");
    getView().setPhone(formattedPhone);//w w  w  .j  a v  a2 s.c  o  m
}

From source file:com.netflix.spinnaker.halyard.config.config.v1.ResourceConfig.java

private String normalizePath(String path) {
    return path.replaceFirst("^~", System.getProperty("user.home"));
}

From source file:com.hcc.cms.util.PageUtils.java

public static String replacehtmlTags(String str) {
    if ((str != null) && !str.isEmpty()) {
        str = str.replace("<p>", "").replace("</p>", "");
        str = str.replace("<h2>", "").replace("</h2>", "");
        str = str.replace("<h3>", "").replace("</h3>", "");
        str = str.replace("<span", "<p").replace("</span>", "</p>");
        str = str.replaceFirst("<br>", "");
    }//from www  . ja  v  a  2  s  .  co  m
    return str;
}

From source file:com.thoughtworks.studios.shine.net.StubGoURLRepository.java

public void registerStubContent(String url, String content) {
    String baseFile = url.replaceFirst("http://localhost:3000/go", "");

    File file = new File(baseDir, baseFile);
    file.getParentFile().mkdirs();/*from  w ww  . ja  v  a 2  s  .c  o m*/

    try {
        FileUtils.writeStringToFile(file, content);
    } catch (IOException e) {
        throw new RuntimeException("Could not write to file", e);
    }
}

From source file:br.com.munif.ffjma.FreeFormApi.java

private String getCollection(HttpServletRequest req) {
    String uri = req.getRequestURI();
    return uri.replaceFirst(".*/api/", "").replaceFirst("/.*", "");
}