List of usage examples for org.apache.commons.lang StringUtils endsWith
public static boolean endsWith(String str, String suffix)
Check if a String ends with a specified suffix.
From source file:mitm.test.TestUtils.java
public static int getTempFileCount(final String prefix, final String postfix) { String[] files = SystemUtils.getJavaIoTmpDir().list(new FilenameFilter() { @Override// w w w .j a v a 2 s . c om public boolean accept(File file, String s) { return StringUtils.startsWith(s, prefix) && StringUtils.endsWith(s, postfix); } }); return files != null ? files.length : 0; }
From source file:de.hybris.platform.secureportaladdon.controllers.DefaultB2BRegistrationControllerIntegrationTest.java
@Test public void testShowRegistrationPageNotEnableRegistration() throws Exception { final CMSSiteModel currentSite = getCmsSiteService().getCurrentSite(); currentSite.setEnableRegistration(false); LOG.info("currentSite=" + currentSite.getName()); getModelService().save(currentSite); final MvcResult result = getMockMvc().perform(get(MOCK_SERVLET_PATH + "/register")).andReturn(); final String redirectedUrl = result.getResponse().getRedirectedUrl(); Assert.assertTrue(StringUtils.endsWith(redirectedUrl, ROOT)); }
From source file:com.taobao.tdhs.jdbc.sqlparser.ParseSQL.java
public ParseSQL(@NotNull String sql) { this.oriSql = sql; sql = sql.trim();//from w w w.j a va 2s.com if (StringUtils.endsWith(sql, ";")) { sql = sql.substring(0, sql.length() - 1); } this.sql = sql; this.errmsg = ""; this.tip = ""; this.tablename = ""; this.groupbycolumn = ""; this.orderbycolumn = ""; this.limitStart = 0; this.limit = 0; // ?0:?;1: this.tag = 0; this.columns = new ArrayList<Entry<String, String>>(); listOperationStructs = new LinkedList<OperationStruct>(); this.updateEntries = new ArrayList<Entry<String, String>>(); }
From source file:edu.cornell.med.icb.goby.alignments.AbstractAlignmentReader.java
/** * Return the basename corresponding to the input alignment filename. Note * that if the filename does have the extension known to be a compact alignment * the returned value is the original filename * * @param filename The name of the file to get the basename for * @return basename for the alignment file *///from ww w .j a v a 2s. c o m public static String getBasename(final String filename) { for (final String ext : FileExtensionHelper.COMPACT_ALIGNMENT_FILE_EXTS) { if (StringUtils.endsWith(filename, ext)) { return StringUtils.removeEnd(filename, ext); } } // perhaps the input was a basename already. return filename; }
From source file:com.tesora.dve.common.PEStringUtils.java
public static String normalizePrefix(String prefix) { String newPrefix = StringUtils.defaultString(prefix); if (newPrefix.length() > 0 && !StringUtils.endsWith(newPrefix, ".")) { newPrefix = newPrefix + "."; }// w w w.java2 s . c o m return newPrefix; }
From source file:com.cognifide.cq.cqsm.foundation.actions.allow.Allow.java
private ActionResult process(final Context context, boolean simulate) { ActionResult actionResult = new ActionResult(); try {/*from w w w . ja va2 s.co m*/ Authorizable authorizable = context.getCurrentAuthorizable(); actionResult.setAuthorizable(authorizable.getID()); context.getSession().getNode(path); final PermissionActionHelper permissionActionHelper = new PermissionActionHelper( context.getValueFactory(), path, glob, permissions); LOGGER.info(String.format("Adding permissions %s for authorizable with id = %s for path = %s %s", permissions.toString(), context.getCurrentAuthorizable().getID(), path, StringUtils.isEmpty(glob) ? "" : ("glob = " + glob))); if (simulate) { permissionActionHelper.checkPermissions(context.getAccessControlManager()); } else { permissionActionHelper.applyPermissions(context.getAccessControlManager(), authorizable.getPrincipal(), true); } actionResult.logMessage("Added allow privilege for " + authorizable.getID() + " on " + path); if (permissions.contains("MODIFY")) { String preparedGlob = ""; if (!StringUtils.isBlank(glob)) { preparedGlob = glob; if (StringUtils.endsWith(glob, "*")) { preparedGlob = StringUtils.substring(glob, 0, StringUtils.lastIndexOf(glob, '*')); } } new Allow(path, preparedGlob + "*/jcr:content*", ignoreInexistingPaths, Collections.singletonList("MODIFY_PAGE")).process(context, simulate); } } catch (final PathNotFoundException e) { if (ignoreInexistingPaths) { actionResult.logWarning("Path " + path + " not found"); } else { actionResult.logError("Path " + path + " not found"); return actionResult; } } catch (RepositoryException | PermissionException | ActionExecutionException e) { actionResult.logError(MessagingUtils.createMessage(e)); } return actionResult; }
From source file:com.inktomi.wxmetar.MetarParser.java
static boolean parseWinds(String token, final Metar metar) { boolean rval = Boolean.FALSE; // Winds will be the only element that ends in knots if (StringUtils.endsWith(token, "KT")) { // At this point, we know we should handle this token rval = Boolean.TRUE;//from w w w . jav a2 s . c o m // Remove the KT token = StringUtils.remove(token, "KT"); // Is it variable? if (StringUtils.startsWith(token, "VRB")) { metar.winds.variable = Boolean.TRUE; // Trim of the VRB token = StringUtils.remove(token, "VRB"); metar.winds.windSpeed = Float.parseFloat(token); // Stop processing this token return rval; } // At this point, we know the first 3 chars are wind direction metar.winds.windDirection = Integer.parseInt(StringUtils.substring(token, 0, 3)); // Is it gusting? 17012G24 int postionOfG = StringUtils.indexOf(token, "G"); if (postionOfG > -1) { metar.winds.windGusts = Float .parseFloat(StringUtils.substring(token, postionOfG + 1, token.length())); metar.winds.windSpeed = Float.parseFloat(StringUtils.substring(token, 3, postionOfG)); } // Is it just a normal wind measurement? // 26006 if (postionOfG == -1 && !metar.winds.variable) { metar.winds.windSpeed = Float.parseFloat(StringUtils.substring(token, 2, token.length())); } } return rval; }
From source file:com.cognifide.cq.cqsm.foundation.actions.deny.Deny.java
private ActionResult process(final Context context, boolean simulate) { ActionResult actionResult = new ActionResult(); try {// w ww .jav a2 s. c o m Authorizable authorizable = context.getCurrentAuthorizable(); actionResult.setAuthorizable(authorizable.getID()); context.getSession().getNode(path); final PermissionActionHelper permissionActionHelper = new PermissionActionHelper( context.getValueFactory(), path, glob, permissions); LOGGER.info(String.format("Denying permissions %s for authorizable with id = %s for path = %s %s", permissions.toString(), context.getCurrentAuthorizable().getID(), path, StringUtils.isEmpty(glob) ? "" : ("glob = " + glob))); if (simulate) { permissionActionHelper.checkPermissions(context.getAccessControlManager()); } else { permissionActionHelper.applyPermissions(context.getAccessControlManager(), authorizable.getPrincipal(), false); } actionResult.logMessage("Added deny privilege for " + authorizable.getID() + " on " + path); if (permissions.contains("MODIFY")) { List<String> globModifyPermission = new ArrayList<>(); globModifyPermission.add("MODIFY_PAGE"); String preparedGlob = ""; if (!StringUtils.isBlank(glob)) { preparedGlob = glob; if (StringUtils.endsWith(glob, "*")) { preparedGlob = StringUtils.substring(glob, 0, StringUtils.lastIndexOf(glob, '*')); } } new Deny(path, preparedGlob + "*/jcr:content*", ignoreUnexistingPaths, globModifyPermission) .process(context, simulate); } } catch (final PathNotFoundException e) { if (ignoreUnexistingPaths) { actionResult.logWarning("Path " + path + " not found"); } else { actionResult.logError("Path " + path + " not found"); } } catch (final RepositoryException | PermissionException | ActionExecutionException e) { actionResult.logError(MessagingUtils.createMessage(e)); } return actionResult; }
From source file:com.taobao.tdhs.jdbc.util.StringUtil.java
public static String[] escapeIn(String value) { value = StringUtils.trim(value);/*w w w . ja v a 2 s . c o m*/ if (!StringUtils.startsWith(value, "(") || !StringUtils.endsWith(value, ")")) { return null; } value = value.substring(1, value.length() - 1); String[] split = StringUtils.split(value, ","); String[] result = new String[split.length]; int i = 0; for (String s : split) { String str = escapeValue(s); if (StringUtils.isBlank(str)) { return null; } result[i++] = str; } return result; }
From source file:com.ewcms.web.filter.PreviewFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse rep, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String uri = request.getRequestURI(); if (!StringUtils.endsWith(uri, PREVIEW_PATH)) { logger.debug("Uri is not preview address"); chain.doFilter(req, rep);/* w ww . j a v a 2 s .c o m*/ return; } HttpServletResponse response = (HttpServletResponse) rep; try { Integer channelId = getChannelId(request); Integer templateId = getTemplateId(request); Long articleId = getArticleId(request); if (templateId == null && (channelId == null || articleId == null)) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } String redirectUri = getRedirectUri(request, articleId, templateId); if (redirectUri == null) { logger.debug("Redirect's address is null"); response.sendError(HttpServletResponse.SC_BAD_REQUEST); } else { logger.debug("Redirect's address is {}", redirectUri); response.sendRedirect(redirectUri); } } catch (Exception e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.toString()); } }