List of usage examples for java.lang String replaceFirst
public String replaceFirst(String regex, String replacement)
From source file:org.alfresco.selenium.FetchUtil.java
/** * Updates the HTML with the new locations of assets. * @param html//from w w w. j a v a 2 s . c o m * @param files * @return update html source */ public static String parseHtml(String html, List<String> files) { if (html == null || html.isEmpty()) { throw new IllegalArgumentException("Html source code is required"); } String value = html.substring(0); value = stripBaseTag(value); value = stripMetaTag(value); //Add the only meta tag we need that remove strange characters from page. value = value.replaceFirst("<head>", "<head>\n" + UTF8_HTML); if (files != null) { for (String file : files) { //Get the name of the asset. int index = file.lastIndexOf(URL_PATH_SEPARATOR); String name = file.substring(index + 1); if (name.startsWith("?")) { try { //Java Regex cant handle ?[a-z]= String t[] = file.split("\\?"); String prefix = t[0]; String rest = t[1]; //Remove ? from new filename. String updatedName = name.replaceFirst("\\?", ""); value = value.replaceFirst(prefix + "\\?" + rest, "./" + ASSET_FOLDER + updatedName); } catch (Exception e) { logger.error("Unable to parse new url", e); } } else { value = value.replaceFirst(file, "./" + ASSET_FOLDER + name); } } } return value; }
From source file:com.ibm.sbt.service.basic.ProxyEndpointService.java
public static String getProxyUrlForEndpoint(Context context, String proxyName, String endpointName, String url) { StringBuilder b = new StringBuilder(); RuntimeConstants.get().appendBaseProxyUrl(b, context); b.append("/"); b.append(proxyName);/*ww w. java2s . c o m*/ b.append("/"); b.append(endpointName); if (StringUtil.isNotEmpty(url)) { b.append("/"); String newUrl = url.replaceFirst("://", "\\/"); b.append(newUrl); } String proxyUrl = b.toString(); return proxyUrl; }
From source file:com.autentia.tnt.manager.report.ReportManager.java
public static String normalize(String path) { String pathCleaned = null; final int reportIndex = path.indexOf("Informe"); if (reportIndex >= 0) { pathCleaned = path.substring(reportIndex); pathCleaned = pathCleaned.replaceFirst(".jrxml", ""); }/*from w w w . ja v a 2 s .c o m*/ return pathCleaned; }
From source file:com.qmetry.qaf.automation.util.StringUtil.java
public static Boolean handleRegex(String prefix, String expectedPattern, String actual, int flags) { if (expectedPattern.startsWith(prefix)) { String expectedRegEx = expectedPattern.replaceFirst(prefix, "");// + // ".*";//w w w .j a v a 2s . co m Pattern p = Pattern.compile(expectedRegEx, flags); if (!p.matcher(actual).matches()) { System.out.println("expected " + actual + " to match regexp " + expectedPattern); return Boolean.FALSE; } return Boolean.TRUE; } return null; }
From source file:com.dell.asm.asmcore.asmmanager.util.deployment.HostnameUtil.java
public static String replaceNumPattern(String hostnameTemplate, Set<String> allHostnames) { // we might already have the same hostname with auto-generated numbers. There is no way // to keep the counter updated, thus we have to check for dup every time we replace // ${num} with next gen number. String hostnameWithNumPattern = hostnameTemplate; int hostNameCounter = 0; while (hostnameWithNumPattern != null && hostNameCounter <= allHostnames.size()) { while (hostnameWithNumPattern.contains(NUM_PATTERN)) { hostNameCounter++;//from w w w . ja v a2 s. c o m hostnameWithNumPattern = hostnameWithNumPattern.replaceFirst(Pattern.quote(NUM_PATTERN), String.valueOf(hostNameCounter)); } if (!allHostnames.contains(hostnameWithNumPattern)) { hostnameTemplate = hostnameWithNumPattern; break; } else { // number pattern was already used, try again with next gen, reset the original name to get pattern back hostnameWithNumPattern = hostnameTemplate; } } return hostnameTemplate; }
From source file:Utils.java
public static String addDefaultPortIfMissing(String urlString, String defaultPort) { URL url = null;/*from w w w . ja v a 2s. co m*/ try { url = new URL(urlString); } catch (MalformedURLException e) { return urlString; } if (url.getPort() != -1) { return urlString; } String regex = "http://([^/]+)"; String found = getFirstFound(urlString, regex); String replacer = "http://" + found + ":" + defaultPort; if (!isEmpty(found)) { urlString = urlString.replaceFirst(regex, replacer); } return urlString; }
From source file:io.fabric8.jenkins.openshiftsync.BuildConfigToJobMapper.java
/** * Updates the {@link BuildConfig} if the Jenkins {@link WorkflowJob} changes * * @param job the job thats been updated via Jenkins * @param buildConfig the OpenShift BuildConfig to update * @return true if the BuildConfig was changed *///from ww w. j a v a 2s .c o m public static boolean updateBuildConfigFromJob(WorkflowJob job, BuildConfig buildConfig) { NamespaceName namespaceName = NamespaceName.create(buildConfig); JenkinsPipelineBuildStrategy jenkinsPipelineStrategy = null; BuildConfigSpec spec = buildConfig.getSpec(); if (spec != null) { BuildStrategy strategy = spec.getStrategy(); if (strategy != null) { jenkinsPipelineStrategy = strategy.getJenkinsPipelineStrategy(); } } if (jenkinsPipelineStrategy == null) { LOGGER.warning("No jenkinsPipelineStrategy available in the BuildConfig " + namespaceName); return false; } FlowDefinition definition = job.getDefinition(); if (definition instanceof CpsScmFlowDefinition) { CpsScmFlowDefinition cpsScmFlowDefinition = (CpsScmFlowDefinition) definition; String scriptPath = cpsScmFlowDefinition.getScriptPath(); if (scriptPath != null && scriptPath.trim().length() > 0) { String bcContextDir = buildConfig.getSpec().getSource().getContextDir(); if (StringUtils.isNotBlank(bcContextDir) && scriptPath.startsWith(bcContextDir)) { scriptPath = scriptPath.replaceFirst("^" + bcContextDir + "/?", ""); } jenkinsPipelineStrategy.setJenkinsfilePath(scriptPath); SCM scm = cpsScmFlowDefinition.getScm(); if (scm instanceof GitSCM) { GitSCM gitSCM = (GitSCM) scm; List<RemoteConfig> repositories = gitSCM.getRepositories(); if (repositories != null && repositories.size() > 0) { RemoteConfig remoteConfig = repositories.get(0); List<URIish> urIs = remoteConfig.getURIs(); if (urIs != null && urIs.size() > 0) { URIish urIish = urIs.get(0); String gitUrl = urIish.toString(); if (gitUrl != null && gitUrl.length() > 0) { String ref = null; List<BranchSpec> branches = gitSCM.getBranches(); if (branches != null && branches.size() > 0) { BranchSpec branchSpec = branches.get(0); String branch = branchSpec.getName(); while (branch.startsWith("*") || branch.startsWith("/")) { branch = branch.substring(1); } if (!branch.isEmpty()) { ref = branch; } } OpenShiftUtils.updateGitSourceUrl(buildConfig, gitUrl, ref); } } } } return true; } return false; } if (definition instanceof CpsFlowDefinition) { CpsFlowDefinition cpsFlowDefinition = (CpsFlowDefinition) definition; String jenkinsfile = cpsFlowDefinition.getScript(); if (jenkinsfile != null && jenkinsfile.trim().length() > 0) { jenkinsPipelineStrategy.setJenkinsfile(jenkinsfile); return true; } return false; } LOGGER.warning("Cannot update BuildConfig " + namespaceName + " as the definition is of class " + (definition == null ? "null" : definition.getClass().getName())); return false; }
From source file:gov.nih.nci.cananolab.util.StringUtils.java
/** * Convert a string with multiple words separated by space to one word, with * first letter as upper case./*w w w . j a va2 s . co m*/ * * @param words * @return */ public static String getOneWordUpperCaseFirstLetter(String words) { // remove space in words and make the first letter lower case. String firstLetter = words.substring(0, 1); String oneWord = words.replaceFirst(firstLetter, firstLetter.toUpperCase()).replace(" ", ""); return oneWord; }
From source file:Commander.Main.java
private static void doCommand() { String input = txtCommand.getText(); String[] commands = input.split(","); //Execute one command at a time for (String s : commands) { int readingIndex = 0; String name;/*from w ww . ja v a 2 s . co m*/ File target; List<String> options = new ArrayList<>(); //Remove whitespaces if (s.startsWith(" ")) { s = s.replaceFirst(" ", ""); } //Options while (s.startsWith("/")) { int nextIndex = s.indexOf(" "); String option = s.substring(readingIndex, nextIndex); options.add(option); s = s.substring(nextIndex, s.length()).replaceFirst(" ", ""); } } }
From source file:azkaban.webapp.servlet.ExternalAnalyzerUtils.java
private static String buildExternalAnalyzerURL(HttpServletRequest req, String url, String pattern) { StringBuilder builder = new StringBuilder(); builder.append(req.getRequestURL()); builder.append("?"); builder.append(req.getQueryString()); String flowExecutionURL = builder.toString(); String encodedFlowExecUrl = ""; try {//from w ww . j a va 2 s . c o m encodedFlowExecUrl = URLEncoder.encode(flowExecutionURL, "UTF-8"); } catch (UnsupportedEncodingException e) { LOGGER.error("Specified encoding is not supported", e); } return url.replaceFirst(pattern, encodedFlowExecUrl); }