List of usage examples for org.apache.commons.lang3 StringUtils startsWith
public static boolean startsWith(final CharSequence str, final CharSequence prefix)
Check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:ch.cyberduck.core.MappingMimeTypeService.java
@Override public String getMime(final String filename) { if (StringUtils.startsWith(filename, "._")) { return DEFAULT_CONTENT_TYPE; }//from ww w. j a v a 2s . c om // Reads from mime.types in classpath return types.getMimetype(StringUtils.lowerCase(filename)); }
From source file:com.yqboots.security.access.RoleHierarchyImpl.java
/** * Retrieves the hierarchy roles.//from w w w.ja va 2 s. c om * * @param role the granted authority * @return the roles from hierarchy */ protected Collection<? extends GrantedAuthority> retrieveHierarchyRoles(GrantedAuthority role) { final Set<GrantedAuthority> results = new HashSet<>(); // /R001/R002/R003 ... String roleStr = role.getAuthority(); if (StringUtils.startsWith(roleStr, "ROLE_") && StringUtils.contains(roleStr, "/")) { roleStr = StringUtils.substringAfter(roleStr, "ROLE_"); } while (StringUtils.isNotBlank(roleStr)) { results.add(new SimpleGrantedAuthority(roleStr)); if (!StringUtils.contains(roleStr, "/")) { break; } roleStr = StringUtils.substringBeforeLast(roleStr, "/"); } return results; }
From source file:com.nesscomputing.httpserver.log.log4j.Log4jRequestLog.java
@Override public void log(Request request, Response response) { final String requestUri = request.getRequestURI(); for (String blackListEntry : blackList) { if (StringUtils.startsWith(requestUri, blackListEntry)) { return; }//from w w w .j a va 2s . c o m } final StringTemplate template = new StringTemplate(pattern); for (Entry<String, LogField> field : knownFields.entrySet()) { template.setAttribute(field.getKey(), ObjectUtils.toString(field.getValue().log(request, response, null))); } try { MDC.put("track", ObjectUtils.toString(response.getHeader("X-Trumpet-Track"))); log.info(template.toString()); } finally { MDC.remove("track"); } }
From source file:com.btmatthews.selenium.junit4.runner.ServerFactory.java
/** * Return a string to identify the browser by trimming the leading * from * the {@code browserStartCommand}./*from w w w . j a va2 s. com*/ * * @return The derived browser identification string. */ public String getBrowser() { String browser; if (StringUtils.startsWith(browserStartCommand, "*")) { browser = browserStartCommand.substring(1); } else { browser = StringUtils.EMPTY; } return browser; }
From source file:com.quatico.base.aem.test.api.setup.Resources.java
@Override public Resource aResource(Resource parent, String relativePath, Object... properties) throws Exception { if (relativePath == null) { relativePath = StringUtils.EMPTY; }/*from www. j a v a 2 s.c om*/ if (StringUtils.isNotEmpty(relativePath) && !StringUtils.startsWith(relativePath, "/")) { relativePath += "/"; } return aResource(parent.getPath() + relativePath, properties); }
From source file:com.omnigon.aem.handlebars.helpers.StartsWithHelper.java
/** * * @param context contains comparable string param. * @param options contains handlebar's content and * prefix param.//w w w. ja v a 2 s. c o m * @return returns handlebar's content if comparable * string param starts with otherwise null. * @throws IOException */ @Override public CharSequence apply(final Object context, final Options options) throws IOException { if (!isValidComparableStringParam(context) || !isValidPrefixParam(options)) { return StringUtils.EMPTY; } CharSequence comparableString = (CharSequence) context; CharSequence prefix = options.param(0); CharSequence content = StringUtils.EMPTY; if (StringUtils.startsWith(comparableString, prefix)) { content = options.fn(); } return content; }
From source file:io.wcm.devops.conga.generator.plugins.fileheader.UnixShellScriptFileHeaderTest.java
@Test public void testApply() throws Exception { File file = new File("target/generation-test/fileHeader.sh"); FileUtils.write(file, "#!/bin/bash\n" + "myscript"); List<String> lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); FileHeaderContext context = new FileHeaderContext().commentLines(lines); FileContext fileContext = new FileContext().file(file); assertTrue(underTest.accepts(fileContext, context)); underTest.apply(fileContext, context); String content = FileUtils.readFileToString(file); assertTrue(StringUtils.contains(content, "# Der Jodelkaiser\n# aus dem Oetztal\n# ist wieder daheim.\n")); assertTrue(StringUtils.endsWith(content, "\nmyscript")); assertTrue(StringUtils.startsWith(content, "#!/bin/bash\n")); FileHeaderContext extractContext = underTest.extract(fileContext); assertEquals(lines, extractContext.getCommentLines()); file.delete();/*from w w w .j av a2 s. com*/ }
From source file:com.neophob.sematrix.core.output.E1_31Device.java
/** * //from w ww . j a va2 s.c om * @param controller */ public E1_31Device(ApplicationConfigurationHelper ph, int nrOfScreens) { super(OutputDeviceEnum.E1_31, ph, 8, nrOfScreens); this.displayOptions = ph.getE131Device(); //Get dmx specific config this.pixelsPerUniverse = ph.getE131PixelsPerUniverse(); try { String ip = ph.getE131Ip(); String sendMode = "Unicast"; if (StringUtils.startsWith(ip, MULTICAST_START)) { this.sendMulticast = true; sendMode = "Multicast"; } this.targetAdress = InetAddress.getByName(ip); this.firstUniverseId = ph.getE131StartUniverseId(); calculateNrOfUniverse(); packet = new DatagramPacket(new byte[0], 0, targetAdress, E1_31DataPacket.E131_PORT); dsocket = new DatagramSocket(); this.initialized = true; LOG.log(Level.INFO, "E1.31 device initialized, send mode: " + sendMode + ", use " + this.displayOptions.size() + " panels"); } catch (Exception e) { LOG.log(Level.WARNING, "failed to initialize E1.31 device", e); } }
From source file:com.omnigon.aem.common.utils.url.DefaultSlingUrlBuilder.java
@Override public String build() { StringBuilder b = new StringBuilder(contentPath); for (String selector : selectors) { b.append("."); b.append(selector);//from w w w . j a va 2s. c o m } if (StringUtils.isNotBlank(extension)) { if (StringUtils.startsWith(extension, ".")) { b.append(extension); } else { b.append("."); b.append(extension); } } if (StringUtils.isNotBlank(suffix)) { if (StringUtils.startsWith(suffix, "/")) { b.append(suffix); } else { b.append("/"); b.append(suffix); } } return b.toString(); }
From source file:com.glaf.base.modules.sys.interceptor.AuthorizeInterceptor.java
/** * method - method being invoked args - arguments to the method target - * target of the method invocation. May be null. *//*w ww. j a v a 2s.co m*/ public void before(Method method, Object[] args, Object target) throws Throwable { boolean authorized = false; String objectName = target.getClass().getName(); String methodName = method.getName(); // logger.debug("object:" + objectName); // logger.debug("method:" + methodName); if (StringUtils.startsWith(methodName, "org.springframework.web.servlet.view")) { return; } if (StringUtils.startsWith(methodName, "login")) { return; } if (StringUtils.startsWith(methodName, "logout")) { return; } String ip = ""; String account = ""; for (int i = 0; i < args.length; i++) { // logger.debug("args:" + args[i]); if (args[i] instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) args[i]; if (request != null && request.getParameter("method") != null) { methodName = request.getParameter("method"); ip = request.getRemoteHost(); SysUser user = RequestUtil.getLoginUser(request); if (user != null) { //logger.debug(user.toJsonObject().toJSONString()); account = user.getAccount(); if (StringUtils.equals(user.getAdminFlag(), "1")) { authorized = true; } if (user.isSystemAdmin()) { authorized = true; logger.debug(account + " is admin"); } } // logger.debug("IP:" + ip + ", Account:" + account); } } } methodName = objectName + "." + methodName; // logger.debug("methodName:" + methodName); // if (findSysFunction(methodName)) { // if (findUserFunction(account, methodName)) { // logger.debug("method is in user functions"); authorized = true; } } else {// ? // logger.debug("method isn't in sys functions"); authorized = true; } // ? createLog(account, methodName, ip, authorized ? 1 : 0); if (!authorized) { throw new AuthorizeException("No Privileges."); } }