List of usage examples for org.apache.commons.lang3 StringUtils removeEnd
public static String removeEnd(final String str, final String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
A null source string will return null .
From source file:com.erudika.scoold.ScooldServer.java
/** * @return the host URL of this Scoold server *//* ww w. jav a2 s . c om*/ public static String getServerURL() { String defaultHost = "http://localhost:" + getServerPort(); String host = Config.IN_PRODUCTION ? Config.getConfigParam("host_url", defaultHost) : defaultHost; return StringUtils.removeEnd(host, "/"); }
From source file:com.amazonaws.service.apigateway.importer.impl.sdk.ApiGatewaySdkApiImporter.java
private String trimSlashes(String path) { return StringUtils.removeEnd(StringUtils.removeStart(path, "/"), "/"); }
From source file:com.khs.sherpa.SherpaSettings.java
public String serverUrl() { String value = properties.getProperty("server.url"); if (!StringUtils.isEmpty(value)) { // always remove the ending / if (StringUtils.endsWith(value, "/")) { value = StringUtils.removeEnd(value, "/"); }/*from w ww .ja v a 2s.c o m*/ return value; } return null; }
From source file:cn.calm.osgi.conter.FelixOsgiHost.java
/** * Return a list of directories under a directory whose name is a number *//* w ww .j a v a 2 s .co m*/ protected Map<String, String> getRunLevelDirs(String dir) { Map<String, String> dirs = new HashMap<String, String>(); try { URL url = resource.find("bundles"); if (url != null) { if ("file".equals(url.getProtocol())) { File bundlesDir = new File(url.toURI()); String[] runLevelDirs = bundlesDir.list(new FilenameFilter() { public boolean accept(File file, String name) { try { return file.isDirectory() && Integer.valueOf(name) > 0; } catch (NumberFormatException ex) { // the name is not a number return false; } } }); if (runLevelDirs != null && runLevelDirs.length > 0) { // add all the dirs to the list for (String runLevel : runLevelDirs) dirs.put(runLevel, StringUtils.removeEnd(dir, "/") + "/" + runLevel); } else if (LOG.isDebugEnabled()) { LOG.debug("No run level directories found under the [#0] directory", dir); } } else if (LOG.isWarnEnabled()) LOG.warn("Unable to read [#0] directory", dir); } else if (LOG.isWarnEnabled()) LOG.warn("The [#0] directory was not found", dir); } catch (Exception e) { if (LOG.isWarnEnabled()) LOG.warn("Unable load bundles from the [#0] directory", e, dir); } return dirs; }
From source file:de.crowdcode.kissmda.core.jdt.JdtHelper.java
/** * Get JDT ParameterizedType for the given type name. * // w w w . j a v a 2 s. c om * @param ast * JDT AST tree * @param typeName * input type name * @return JDT ParameterizedType */ @SuppressWarnings("unchecked") public ParameterizedType getAstParameterizedType(AST ast, String typeName) { // Get the component type and parameters <Type, Type, ...> String componentTypeName = StringUtils.substringBefore(typeName, "<"); Type componentType = getAstSimpleType(ast, componentTypeName); ParameterizedType parameterizedType = ast.newParameterizedType(componentType); String paramTypeNames = StringUtils.substringAfter(typeName, "<"); paramTypeNames = StringUtils.removeEnd(paramTypeNames, ">"); // Result: String, Integer, List<Boolean>, de.test.Company String[] parametersAsString = StringUtils.split(paramTypeNames, ","); for (int index = 0; index < parametersAsString.length; index++) { String paramTypeName = parametersAsString[index]; paramTypeName = StringUtils.remove(paramTypeName, ","); paramTypeName = StringUtils.trim(paramTypeName); Type paramType = getChosenType(ast, paramTypeName, paramTypeName, ""); // Add the type arguments parameterizedType.typeArguments().add(paramType); } return parameterizedType; }
From source file:info.magnolia.security.setup.migration.MoveAclPermissionsBetweenWorkspaces.java
/** * Iterate the subPaths list and try to found a valid one. * * @return the first valid path found or null otherwise. */// w w w . j a v a 2 s . c om private String getValidPathWithSubPath(Session targetSession, String originalPath) throws RepositoryException { for (String subPath : subPaths) { String migratedPath = PathUtil.createPath(StringUtils.removeEnd(subPath, "/"), StringUtils.removeStart(originalPath, "/")); log.debug("Check if the following migrated path exist {}", migratedPath); if (targetSession.itemExists(migratedPath)) { return migratedPath; } } return null; }
From source file:com.soolr.core.web.Servlets.java
public static String getBasePath(HttpServletRequest request) { String requestURL = request.getRequestURL().toString(); String requestURI = request.getRequestURI(); String host = StringUtils.substringBeforeLast(requestURL, requestURI); String contextPath = request.getContextPath(); return StringUtils.removeEnd(host + contextPath, "/"); }
From source file:com.qq.tars.service.monitor.TARSPropertyMonitorService.java
private MultiKeyMap call(List<String> groupBy, List<String> conditions) throws IOException { String template = "{\"groupby\":%s,\"method\":\"query\",\"dataid\":\"tars_property\"," + "\"filter\":%s,\"indexs\":[\"value\"]}"; ObjectMapper mapper = new ObjectMapper(); String request = String.format(template, mapper.writeValueAsString(groupBy), mapper.writeValueAsString(conditions)); List<Pair<String, Integer>> addrs = adminService.getEndpoints("tars.tarsqueryproperty.NoTarsObj"); if (addrs.isEmpty()) { throw new IOException("tars.tarsqueryproperty.NoTarsObj not found"); }//w ww . j av a 2 s .c o m Pair<String, Integer> addr = addrs.get(0); log.info("tars.tarsqueryproperty.NoTarsObj, use {}:{}", addr.getLeft(), addr.getRight()); TCPClient client = new TCPClient(addr.getLeft(), addr.getRight()); List<String> response = client.sendAndReceive(request.getBytes(), 60000); log.debug("request={}", request); log.debug("reponse={}", StringUtils.join(response, "\n")); String line1 = response.get(0); if (!line1.startsWith("Ret:")) { throw new IOException(String.format("line #1, doesn't start with \"Ret:\", line=%s", line1)); } int ret = Integer.parseInt(line1.substring(line1.lastIndexOf(':') + 1)); if (ret == -1) { throw new IOException(String.format("line #1, Ret=%s", ret)); } String line6 = response.get(5); if (!line6.startsWith("linecount:")) { throw new IOException(String.format("line #6, doesn't start with \"linecount:\", line=%s", line6)); } int count = Integer.parseInt(line6.substring(line6.lastIndexOf(':') + 1)); if (count + 7 != response.size()) { throw new IOException(String.format("line #6, size not match, %s vs %s", count + 7, response.size())); } String lastLine = response.get(response.size() - 1); if (!"endline".equals(lastLine)) { throw new IOException( String.format("line #%s, doesn't equal to \"endline\", line=%s", response.size(), lastLine)); } MultiKeyMap result = new MultiKeyMap(); for (int i = 6; i < response.size() - 1; i++) { String line = StringUtils.removeEnd(response.get(i), ","); String[] tokens = line.split(","); if (tokens.length != groupBy.size() + 1) { throw new IOException(String.format("line format error, line=%s", line)); } String[] key = new String[groupBy.size()]; int j = 0; for (; j < key.length; j++) { key[j] = tokens[j]; } double[] value = new double[] { Double.parseDouble(tokens[j]) }; result.put(new MultiKey(key), value); } return result; }
From source file:net.mach6.listeners.DependencyReportingListener.java
private void generatePngFromDotFiles() { if (!Option.OUTPUT.isSet("png", "all")) { return;//from www . j av a 2 s .c om } for (String dotFile : dotFiles) { dotFile = FilenameUtils.getFullPath(dotFile) + FilenameUtils.getName(dotFile); try { final String cmd = "/usr/local/bin/dot " + dotFile + " -Grankdir=LR -Tpng -o " + StringUtils.removeEnd(dotFile, ".dot").concat(".png"); Process p = Runtime.getRuntime().exec(cmd, null); p.waitFor(); } catch (IOException | InterruptedException e) { LOGGER.severe("Error generating png file due to " + e.getMessage()); throw new RuntimeException("Error generating png file", e); } finally { // Delete the dot file if it is not a requested output format if (!Option.OUTPUT.isSet("dot", "all")) { LOGGER.fine("deleting -> " + dotFile); FileUtils.deleteQuietly(new File(dotFile)); } } } }
From source file:com.wedian.site.common.utils.Setting.java
/** * ?//from ww w. j a va 2 s. c om * * @param siteUrl * ? */ public void setSiteUrl(String siteUrl) { this.siteUrl = StringUtils.removeEnd(siteUrl, "/"); }