List of usage examples for org.apache.commons.lang StringUtils removeEnd
public static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
From source file:com.adguard.compiler.LocaleUtils.java
public static void updateExtensionNameForChromeLocales(File dest, String extensionNamePostfix) throws IOException { if (StringUtils.isEmpty(extensionNamePostfix)) { return;// w w w . ja v a2 s. c o m } File chromeLocalesDir = new File(dest, "_locales"); for (File file : chromeLocalesDir.listFiles()) { File chromeLocaleFile = new File(file, "messages.json"); StringBuilder sb = new StringBuilder(); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(chromeLocaleFile)); String line; while ((line = reader.readLine()) != null) { sb.append(line).append("\r\n"); if (line.trim().startsWith("\"name\":") || line.trim().startsWith("\"short_name\":")) { line = reader.readLine(); String[] parts = StringUtils.split(line, ":"); String message = StringUtils.removeEnd(parts[1].trim(), "\"") + extensionNamePostfix + "\""; sb.append("\t\"message\": ").append(message).append("\r\n"); } } } finally { IOUtils.closeQuietly(reader); } FileUtils.writeStringToFile(chromeLocaleFile, sb.toString()); } }
From source file:com.tlabs.eve.api.EveRequest.java
protected final void putParam(String p, String[] values) { if (null == values) { this.params.put(p, null); return;//from w w w .j a v a 2s .com } String s = ""; for (Object v : values) { s = s + v + ","; } this.params.put(p, StringUtils.removeEnd(s, ",")); }
From source file:com.liferay.portal.search.elasticsearch.internal.SearchHitDocumentTranslatorImpl.java
protected String removeSuffixes(String fieldName, String... suffixes) { for (String suffix : suffixes) { fieldName = StringUtils.removeEnd(fieldName, suffix); }//from w w w .j a v a2 s. com return fieldName; }
From source file:com.aqnote.shared.cryptology.cert.loader.CaCertLoader.java
public synchronized static String getB64RootCaCert() throws IOException { if (StringUtils.isBlank(b64RootCaCert)) { ClassLoader classLoader = ClassLoaderUtil.getClassLoader(); InputStream is = classLoader.getResourceAsStream(CA_Cert_FILE); b64RootCaCert = StreamUtil.stream2Bytes(is, StandardCharsets.UTF_8); b64RootCaCert = StringUtils.removeStart(b64RootCaCert, BEGIN_CERT); b64RootCaCert = StringUtils.removeEnd(b64RootCaCert, END_CERT); }/*from w w w . ja v a 2 s . c o m*/ return b64RootCaCert; }
From source file:co.marcin.novaguilds.command.admin.config.CommandAdminConfigGet.java
@Override public void execute(CommandSender sender, String[] args) throws Exception { if (args.length == 0) { command.getUsageMessage().send(sender); return;/*from w w w.j av a 2 s . c o m*/ } String path = args[0]; String value = ""; Map<VarKey, String> vars = new HashMap<>(); FileConfiguration config = plugin.getConfigManager().getConfig(); if (!config.contains(path)) { Message.CHAT_INVALIDPARAM.send(sender); return; } if (config.isConfigurationSection(path)) { int depth = 1; String lastSection = null; vars.put(VarKey.DEPTH, ""); vars.put(VarKey.KEY, path); Message.CHAT_ADMIN_CONFIG_GET_LIST_SECTION.vars(vars).send(sender); for (String string : config.getConfigurationSection(path).getKeys(true)) { String[] prefixSplit = StringUtils.split(string, "."); String prefix = StringUtils.contains(string, ".") ? StringUtils.removeEnd(string, "." + prefixSplit[prefixSplit.length - 1]) : string; if (lastSection != null && !prefix.startsWith(lastSection)) { depth--; lastSection = null; } String space = ""; for (int i = 0; i < depth; i++) { space += " "; } vars.put(VarKey.DEPTH, space); if (config.isConfigurationSection(path + "." + string)) { depth++; lastSection = string; vars.put(VarKey.KEY, prefixSplit[prefixSplit.length - 1]); Message.CHAT_ADMIN_CONFIG_GET_LIST_SECTION.vars(vars).send(sender); } else { //key vars.put(VarKey.KEY, StringUtils.removeStart(string, prefix + ".")); Message.CHAT_ADMIN_CONFIG_GET_LIST_KEY.vars(vars).send(sender); } } } else { if (config.isList(path)) { value = StringUtils.join(config.getStringList(path), " "); } else { value = config.getString(path); } } vars.put(VarKey.KEY, path); vars.put(VarKey.VALUE, value); if (!value.isEmpty()) { Message.CHAT_ADMIN_CONFIG_GET_SINGLE.vars(vars).send(sender); } }
From source file:com.temenos.interaction.core.web.RequestContextFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest servletRequest = (HttpServletRequest) request; String requestURI = servletRequest.getRequestURI(); requestURI = StringUtils.removeStart(requestURI, servletRequest.getContextPath() + servletRequest.getServletPath()); String baseURL = StringUtils.removeEnd(servletRequest.getRequestURL().toString(), requestURI); Map<String, List<String>> headersMap = new HashMap<>(); Enumeration<String> headerNames = servletRequest.getHeaderNames(); if (headerNames != null) { while (headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); List<String> valuesList = Collections.list(servletRequest.getHeaders(headerName)); headersMap.put(headerName, valuesList); }/*from ww w. j ava2 s . c om*/ } RequestContext ctx; Principal userPrincipal = servletRequest.getUserPrincipal(); if (userPrincipal != null) { ctx = new RequestContext(baseURL, servletRequest.getRequestURI(), servletRequest.getHeader(RequestContext.HATEOAS_OPTIONS_HEADER), userPrincipal, headersMap); } else { ctx = new RequestContext(baseURL, servletRequest.getRequestURI(), servletRequest.getHeader(RequestContext.HATEOAS_OPTIONS_HEADER), headersMap); } RequestContext.setRequestContext(ctx); try { chain.doFilter(request, response); } finally { RequestContext.clearRequestContext(); } }
From source file:info.magnolia.content2bean.impl.PropertiesBasedTypeMapping.java
public PropertiesBasedTypeMapping() { Properties properties = SystemProperty.getProperties(); for (Iterator<Object> iterator = properties.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); if (key.endsWith(".transformer")) { String className = StringUtils.removeEnd(key, ".transformer"); String transformerClassName = properties.getProperty(key); try { final ClassFactory cl = Classes.getClassFactory(); final Class<?> beanClass = cl.forName(className); final Class<Content2BeanTransformer> transformerClass = cl.forName(transformerClassName); // TODO - we can't instantiate the bastards here, unless we fetch them from IoC. final Content2BeanTransformer transformer = cl.newInstance(transformerClass); getTypeDescriptor(beanClass).setTransformer(transformer); log.debug("Registered custom transformer [{}] for [{}]", className, transformerClassName); } catch (Exception e) { log.error("Can't register custom transformer for [" + className + "]", e); }/*from w ww . j a va 2 s .co m*/ } } }
From source file:com.yhd.spark.oozie.OozieAuditLogParser.java
private static Pattern constructPattern() { List<String> patterns = new ArrayList<String>(11); patterns.add(IP);//from w ww . j a v a 2 s. c o m patterns.add(USER); patterns.add(GROUP); patterns.add(APP); patterns.add(JOBID); patterns.add(OPERATION); patterns.add(PARAMETER); patterns.add(STATUS); patterns.add(HTTPCODE); patterns.add(ERRORCODE); patterns.add(ERRORMESSAGE); StringBuilder sb = new StringBuilder(); sb.append(PREFIX_REGEX + OOZIEAUDIT_FLAG); sb.append(MESSAGE_SPLIT_FLAG); for (int i = 0; i < patterns.size(); i++) { sb.append("("); sb.append(patterns.get(i) + COMMON_REGEX); sb.append(")"); sb.append(ALLOW_ALL_REGEX); } String rs = StringUtils.removeEnd(sb.toString(), ALLOW_ALL_REGEX); return Pattern.compile(rs); }
From source file:com.github.woonsanko.katharsis.examples.hippo.katharsis.filter.HstEnabledKatharsisFilter.java
/** * Returns the currently resolved domain by HST host/site mapping. * @return/*from w w w.ja v a2s . co m*/ */ @Override public String getResourceDefaultDomain() { final HstRequestContext requestContext = RequestContextProvider.get(); if (requestContext == null) { // only for debugging purpose... log.warn("HST RequestContext is not available."); return "http://localhost:8080"; } HstLinkCreator linkCreator = HstServices.getComponentManager().getComponent(HstLinkCreator.class.getName()); HstLink link = linkCreator.create("/", requestContext.getResolvedMount().getMount()); URI uri = URI.create(link.toUrlForm(requestContext, true)); return StringUtils.removeEnd(uri.toString(), "/"); }
From source file:com.cognifide.actions.msg.replication.reception.MessagePageListener.java
/** * Converts the JCR tree change event (creating new cq:Page node) to the the OSGI event with topic * com/cognifide/actions/defaultActionsTopic and sends it the queue. * /*from w w w.j ava 2 s. c om*/ * @param event * @throws RepositoryException */ @Override public void handleEvent(Event event) { if (!(isAuthor() && EventUtil.isLocal(event))) { return; } final String path = (String) event.getProperty("path"); if (!StringUtils.startsWith(path, config.getActionRoot())) { return; } final Map<String, Object> payload = new HashMap<String, Object>(); payload.put(SlingConstants.PROPERTY_PATH, StringUtils.removeEnd(path, JCR_CONTENT_SUFFIX)); jobManager.addJob(HandleMessageJob.TOPIC, null, payload); }