List of usage examples for org.apache.commons.lang StringUtils removeStart
public static String removeStart(String str, String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string.
From source file:at.bitfire.davdroid.mirakel.resource.LocalAddressBook.java
protected static String xNameToLabel(String xname) { // "X-MY_PROPERTY" // 1. ensure lower case -> "x-my_property" // 2. remove x- from beginning -> "my_property" // 3. replace "_" by " " -> "my property" // 4. capitalize -> "My Property" String lowerCase = StringUtils.lowerCase(xname, Locale.US), withoutPrefix = StringUtils.removeStart(lowerCase, "x-"), withSpaces = StringUtils.replace(withoutPrefix, "_", " "); return WordUtils.capitalize(withSpaces); }
From source file:adalid.commons.util.StrUtils.java
public static String removeWholeWord(String string, String remove, char affixType, String separator) { if (separator == null) { separator = " "; }//from w w w .ja va 2 s .co m return string == null || remove == null ? string : affixType == 'p' ? StringUtils.removeStart(string, remove + separator) : affixType == 's' ? StringUtils.removeEnd(string, separator + remove) : StringUtils.replace(string, separator + remove + separator, separator); }
From source file:com.gemstone.gemfire.management.internal.cli.GfshParser.java
private List<CommandTarget> locateTargets(String userInput, boolean matchIncomplete) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { List<CommandTarget> commandTargets = new ArrayList<CommandTarget>(); Map<String, CommandTarget> commands = commandManager.getCommands(); // Now we need to locate the CommandTargets from the entries in the map for (String commandName : commands.keySet()) { if (userInput.startsWith(commandName)) { // This means that the user has entered the command CommandTarget commandTarget = commands.get(commandName); if (isAvailable(commandTarget, commandName)) { String remainingBuffer = StringUtils.removeStart(userInput, commandName); if (remainingBuffer.length() == 0 || remainingBuffer.startsWith(" ") || remainingBuffer.startsWith(GfshParser.LINE_SEPARATOR)) { // We need to duplicate with a new MethodTarget as this // parser will be used in a concurrent execution environment if (!commandTargets.contains(commandTarget)) { // This test is necessary as the command may have similar // synonyms or which are prefix for the command commandTargets.add(commandTarget.duplicate(commandName, remainingBuffer)); }// w ww. jav a 2 s. c o m } } } else if (matchIncomplete && commandName.startsWith(userInput)) { // This means that the user is yet to enter the command properly CommandTarget commandTarget = commands.get(commandName); if (isAvailable(commandTarget, commandName)) { // We need to duplicate with a new MethodTarget as this // parser will be used in a concurrent execution environment if (!commandTargets.contains(commandTarget)) { // This test is necessary as the command may have similar // synonyms or which are prefix for the command commandTargets.add(commandTarget.duplicate(commandName)); } } } } return commandTargets; }
From source file:com.gemstone.gemfire.management.internal.cli.GfshParser.java
private CommandTarget locateExactMatchingTarget(final String userInput)//exact matching throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { CommandTarget commandTarget = null;/*from ww w. ja va 2s. c o m*/ Map<String, CommandTarget> commandTargetsMap = commandManager.getCommands(); // Reverse sort the command names because we should start from longer names // E.g. Consider commands "A", "A B" & user input as "A B --opt1=val1" // In this case, "A B" is the most probable match & should be matched first // which can be achieved by reversing natural order of sorting. Set<String> commandNamesReverseSorted = new TreeSet<String>(Collections.reverseOrder()); commandNamesReverseSorted.addAll(commandTargetsMap.keySet()); // Now we need to locate the CommandTargets from the entries in the map for (final String commandName : commandNamesReverseSorted) { if (userInput.startsWith(commandName) && commandWordsMatch(userInput, commandName)) { // This means that the user has entered the command & name matches exactly commandTarget = commandTargetsMap.get(commandName); if (commandTarget != null) { String remainingBuffer = StringUtils.removeStart(userInput, commandName); commandTarget = commandTarget.duplicate(commandName, remainingBuffer); break; } } } return commandTarget; }
From source file:adalid.core.programmers.AbstractSqlProgrammer.java
protected String join(String op1, String op2, String... strings) { String op1$ = StringUtils.equals(op1, op2) ? EMPTY : StringUtils.trimToEmpty(op1); String op2$ = SPC$ + StringUtils.trimToEmpty(op2) + SPC$; String expresion;// w w w. j a v a 2 s.c om String expresiones = EMPTY; boolean b = op1$.equals(getCast()) || op1$.equals(getCoalesce()); int n = 0; for (String string : strings) { if (StringUtils.isNotBlank(string)) { expresion = b ? StringUtils.trimToEmpty(string) : caseSingleQuotedOrInParentheses(string); expresiones += op2$ + expresion; n++; } } if (n > 0) { expresiones = StringUtils.removeStart(expresiones, op2$); if (StringUtils.isNotBlank(op1$)) { return op1$ + inParentheses(expresiones); } } return inParentheses(expresiones); }
From source file:net.ymate.platform.core.util.RuntimeUtils.java
/** * @param safe WEB??WEB-INF//w ww .j av a 2 s. c om * @return */ public static String getRootPath(boolean safe) { // String _rootPath = null; // URL _rootURL = RuntimeUtils.class.getClassLoader().getResource("/"); if (_rootURL == null) { _rootURL = RuntimeUtils.class.getClassLoader().getResource(""); if (_rootURL != null) { _rootPath = _rootURL.getPath(); } } else { _rootPath = StringUtils.removeEnd( StringUtils.substringBefore(_rootURL.getPath(), safe ? "classes/" : "WEB-INF/"), "/"); } // if (_rootPath != null) { _rootPath = StringUtils.replace(_rootPath, "%20", " "); if (isWindows()) { _rootPath = StringUtils.removeStart(_rootPath, "/"); } } return StringUtils.trimToEmpty(_rootPath); }
From source file:ninja.AssetsControllerHelper.java
/** * If we get - for whatever reason - a relative URL like * assets/../conf/application.conf we expand that to the "real" path. In the * above case conf/application.conf.//from w w w .j a va 2s. c om * * You should then add the assets prefix. * * Otherwise someone can create an attack and read all resources of our app. * If we expand and normalize the incoming path this is no longer possible. * * @param fileName A potential "fileName" * @param enforceUnixSeparator If true it will force the usage of the unix separator '/' * If false it will use the separator of the underlying system. * usually '/' in case of unix and '\' in case of windows. * @return A normalized fileName. */ public String normalizePathWithoutLeadingSlash(String fileName, boolean enforceUnixSeparator) { String fileNameNormalized = enforceUnixSeparator ? FilenameUtils.normalize(fileName, true) : FilenameUtils.normalize(fileName); return StringUtils.removeStart(fileNameNormalized, "/"); }
From source file:nl.tue.iot.reservation.ReservationServlet.java
/** * {@inheritDoc}/* w w w . jav a2 s .c om*/ */ @Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String[] path = StringUtils.split(req.getPathInfo(), '/'); String clientEndpoint = path[0]; // at least /endpoint/objectId/instanceId if (path.length < 3) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid path"); return; } try { String target = StringUtils.removeStart(req.getPathInfo(), "/" + clientEndpoint); Client client = server.getClientRegistry().get(clientEndpoint); if (client != null) { WriteResponse cResponse = this.writeRequest(client, target, req, resp); processDeviceResponse(req, resp, cResponse); } else { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); resp.getWriter().format("No registered client with id '%s'", clientEndpoint).flush(); } } catch (IllegalArgumentException e) { LOG.warn("Invalid request", e); resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); resp.getWriter().append(e.getMessage()).flush(); } catch (ResourceAccessException | RequestFailedException e) { LOG.warn(String.format("Error accessing resource %s%s.", req.getServletPath(), req.getPathInfo()), e); resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); resp.getWriter().append(e.getMessage()).flush(); } }
From source file:no.magott.training.ex2.ExchangeRateFieldSetMapper.java
@Override public void handleLine(String line) { if (line.startsWith(",EXR")) { String removeStart = StringUtils.removeStart(line, ","); String[] tokens = StringUtils.split(removeStart, "."); fromCurrency = tokens[2];/* w ww. j a v a 2s. c om*/ toCurrency = tokens[3]; } }
From source file:orca.ip_assignment.ndl.RequestSaver.java
/** * Do a reverse lookip on domain (NDL -> short name) * @param dom/*from www .j a va 2 s .c om*/ * @return */ public static String reverseLookupDomain(Resource dom) { if (dom == null) return null; // strip off name space and "/Domain" String domainName = StringUtils.removeStart(dom.getURI(), NdlCommons.ORCA_NS); domainName = StringUtils.removeEnd(domainName, "/Domain"); for (Iterator<Map.Entry<String, String>> domName = domainMap.entrySet().iterator(); domName.hasNext();) { Map.Entry<String, String> e = domName.next(); if (domainName.equals(e.getValue())) return e.getKey(); } return null; }