List of usage examples for org.apache.commons.lang3 StringUtils split
public static String[] split(final String str, final String separatorChars)
Splits the provided text into an array, separators specified.
From source file:com.nesscomputing.log4j.StructuredSyslogAppender.java
@Override protected void append(final LoggingEvent event) { final SyslogIF syslog = getSyslog(); final SyslogLevel level = SyslogLevel.forValue(event.getLevel().getSyslogEquivalent()); final String messageId = UUID.randomUUID().toString().replace("-", ""); final String[] messageLines = StringUtils .split((layout != null) ? layout.format(event) : event.getRenderedMessage(), "\n\r"); for (int i = 0; i < messageLines.length; i++) { final Builder<String, String> b = ImmutableMap.builder(); b.put("l", event.getLoggerName()); b.put("c", Integer.toString(i)); if (serviceId != null) { b.put("si", serviceId); }/*ww w. j a v a 2 s . c o m*/ if (serviceConfiguration != null) { b.put("sc", serviceConfiguration); } Object trackToken = event.getMDC("track"); if (trackToken != null) { b.put("t", trackToken.toString()); } Map<String, String> payload = b.build(); final String threadName = StringUtils.replaceChars(event.getThreadName(), " \t", ""); final StructuredSyslogMessage structuredMessage = new StructuredSyslogMessage(messageId, threadName, ImmutableMap.of(ianaIdentifier, payload), messageLines[i]); syslog.log(level, structuredMessage); } }
From source file:com.zhumeng.dream.orm.PropertyFilter.java
/** * @param filterName ,???. eg.//from w w w . j a v a2s. c o m * LIKES_NAME_OR_LOGIN_NAME * @param value . */ public PropertyFilter(final String filterName, final String value) { String propertyNameStr = StringUtils.substringAfter(filterName, "_"); init(filterName, value, propertyNameStr); if (propertyClass == Enum.class) { for (Class<?> clazz : enumObjects) { if (propertyNameStr.equalsIgnoreCase(clazz.getSimpleName())) { Class<Enum> enumObjet = (Class<Enum>) clazz; // add by wucong String[] values = StringUtils.split(value, "_"); if (!StringUtils.contains(value, "_")) this.matchValue = Enum.valueOf(enumObjet, value); else this.matchValue = Enum.valueOf(enumObjet, values[0]);// ? if (values != null) { matchValues = new Object[values.length]; for (int i = 0; i < values.length; i++) { matchValues[i] = Enum.valueOf(enumObjet, values[i]); } if (values.length == 0) { matchValues = new Object[1]; matchValues[0] = this.matchValue; } } break; } } } else { /* * if(!StringUtils.contains(value, "_")) this.matchValue = * ConvertUtils.convertStringToObject(value, propertyClass); */ // add by wucong String[] values = null; //???"_" if (filterName.lastIndexOf("unionId") > 0 || filterName.lastIndexOf("openId") > 0 || (!StringUtils.contains(value, "_")))//???"_" values = new String[] { value }; else values = StringUtils.split(value, "_"); if ((!StringUtils.contains(value, "_") || filterName.lastIndexOf("unionId") > 0) || (!StringUtils.contains(value, "_") && filterName.lastIndexOf("openId") > 0))//???"_" this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass); else this.matchValue = ConvertUtils.convertStringToObject(values[0], propertyClass);// ? if (values != null) { matchValues = new Object[values.length]; for (int i = 0; i < values.length; i++) { matchValues[i] = ConvertUtils.convertStringToObject(values[i], propertyClass); } if (values.length == 0) { matchValues = new Object[1]; matchValues[0] = this.matchValue; } } } }
From source file:de.micromata.genome.gwiki.auth.GWikiAuthorizationBase.java
protected GWikiSimpleUser findUserByAuthenticationToken(GWikiContext ctx) { String tk = ctx.getCookie(COOKIE_STAY_LOGIN_TOKEN, null); if (StringUtils.isBlank(tk) == true) { return null; }//from w ww. j a v a2 s .c om String[] tks = StringUtils.split(tk, ':'); if (tks.length < 2) { return null; } String userName = tks[0]; GWikiSimpleUser user = findUser(ctx, userName); if (user == null) { return null; } String st = user.getProps().get(COOKIE_STAY_LOGIN_TOKEN); if (StringUtils.equals(tks[1], st) == true) { GLog.note(GWikiLogCategory.Wiki, "User autologin from cookie: " + userName, new LogAttribute(GenomeAttributeType.AdminUserName, userName)); return user; } return null; }
From source file:com.devicehive.resource.impl.DeviceCommandResourceImpl.java
private void poll(final long timeout, final String deviceGuidsCsv, final String namesCsv, final String timestamp, final AsyncResponse asyncResponse) throws InterruptedException { final HivePrincipal principal = (HivePrincipal) SecurityContextHolder.getContext().getAuthentication() .getPrincipal();/* ww w . j a va 2 s . co m*/ final Date ts = TimestampQueryParamParser .parse(timestamp == null ? timestampService.getDateAsString() : timestamp); final Response response = ResponseFactory.response(Response.Status.OK, Collections.emptyList(), JsonPolicyDef.Policy.COMMAND_LISTED); asyncResponse.setTimeoutHandler(asyncRes -> asyncRes.resume(response)); Set<String> availableDevices; if (deviceGuidsCsv == null) { availableDevices = deviceService.findByGuidWithPermissionsCheck(Collections.emptyList(), principal) .stream().map(DeviceVO::getGuid).collect(Collectors.toSet()); } else { availableDevices = Optional.ofNullable(StringUtils.split(deviceGuidsCsv, ',')).map(Arrays::asList) .map(list -> deviceService.findByGuidWithPermissionsCheck(list, principal)) .map(list -> list.stream().map(DeviceVO::getGuid).collect(Collectors.toSet())) .orElse(Collections.emptySet()); } Set<String> names = Optional.ofNullable(StringUtils.split(namesCsv, ',')).map(Arrays::asList) .map(list -> list.stream().collect(Collectors.toSet())).orElse(Collections.emptySet()); BiConsumer<DeviceCommand, String> callback = (command, subscriptionId) -> { if (!asyncResponse.isDone()) { asyncResponse.resume(ResponseFactory.response(Response.Status.OK, Collections.singleton(command), Policy.COMMAND_LISTED)); } }; if (!availableDevices.isEmpty()) { Pair<String, CompletableFuture<List<DeviceCommand>>> pair = commandService .sendSubscribeRequest(availableDevices, names, ts, callback); pair.getRight().thenAccept(collection -> { if (!collection.isEmpty() && !asyncResponse.isDone()) { asyncResponse.resume( ResponseFactory.response(Response.Status.OK, collection, Policy.COMMAND_LISTED)); } if (timeout == 0) { asyncResponse.setTimeout(1, TimeUnit.MILLISECONDS); // setting timeout to 0 would cause // the thread to suspend indefinitely, see AsyncResponse docs } else { asyncResponse.setTimeout(timeout, TimeUnit.SECONDS); } }); asyncResponse.register(new CompletionCallback() { @Override public void onComplete(Throwable throwable) { commandService.sendUnsubscribeRequest(pair.getLeft(), null); } }); } else { if (!asyncResponse.isDone()) { asyncResponse.resume(response); } } }
From source file:net.ontopia.utils.ontojsp.FakeServletContext.java
public String getRealFilePath(String path) { File current = new File(rootpath); String[] components = StringUtils.split(path, "/"); for (String component : components) { logger.debug(" - comp: " + component); logger.debug(" - current " + current); if ("".equals(component) || ".".equals(component)) { } else if ("..".equals(component)) { current = current.getParentFile(); } else {/*from w ww . j ava2s. c o m*/ current = new File(current, component); } } return current.toString(); }
From source file:com.mirth.connect.server.util.ServerSMTPConnection.java
public void send(String toList, String ccList, String from, String subject, String body, String charset) throws EmailException { Email email = new SimpleEmail(); // Set the charset if it was specified. Otherwise use the system's default. if (StringUtils.isNotBlank(charset)) { email.setCharset(charset);/* w w w . j a va 2s .c o m*/ } email.setHostName(host); email.setSmtpPort(Integer.parseInt(port)); email.setSocketConnectionTimeout(socketTimeout); email.setDebug(true); if (useAuthentication) { email.setAuthentication(username, password); } if (StringUtils.equalsIgnoreCase(secure, "TLS")) { email.setStartTLSEnabled(true); } else if (StringUtils.equalsIgnoreCase(secure, "SSL")) { email.setSSLOnConnect(true); email.setSslSmtpPort(port); } // These have to be set after the authenticator, so that a new mail session isn't created ConfigurationController configurationController = ControllerFactory.getFactory() .createConfigurationController(); email.getMailSession().getProperties().setProperty("mail.smtp.ssl.protocols", StringUtils.join( MirthSSLUtil.getEnabledHttpsProtocols(configurationController.getHttpsClientProtocols()), ' ')); email.getMailSession().getProperties().setProperty("mail.smtp.ssl.ciphersuites", StringUtils.join( MirthSSLUtil.getEnabledHttpsCipherSuites(configurationController.getHttpsCipherSuites()), ' ')); for (String to : StringUtils.split(toList, ",")) { email.addTo(to); } if (StringUtils.isNotEmpty(ccList)) { for (String cc : StringUtils.split(ccList, ",")) { email.addCc(cc); } } email.setFrom(from); email.setSubject(subject); email.setMsg(body); email.send(); }
From source file:com.nesscomputing.migratory.mojo.database.DatabaseUpgradeMojo.java
protected Map<String, String> extractDatabases(final String migrations) throws MojoExecutionException { String[] migrationNames = StringUtils.stripAll(StringUtils.split(migrations, ",")); final List<String> availableDatabases = getAvailableDatabases(); if (migrationNames == null) { return Collections.<String, String>emptyMap(); }/*www .ja v a 2s .c o m*/ final Map<String, String> databases = Maps.newHashMap(); if (migrationNames.length == 1 && migrationNames[0].equalsIgnoreCase("all")) { migrationNames = availableDatabases.toArray(new String[availableDatabases.size()]); } for (String migration : migrationNames) { final String[] migrationFields = StringUtils.stripAll(StringUtils.split(migration, "=")); if (migrationFields == null || migrationFields.length < 1 || migrationFields.length > 2) { throw new MojoExecutionException("Migration " + migration + " is invalid."); } if (!availableDatabases.contains(migrationFields[0])) { throw new MojoExecutionException("Database " + migrationFields[0] + " is unknown!"); } databases.put(migrationFields[0], (migrationFields.length == 1 ? null : migrationFields[1])); } return databases; }
From source file:com.paladin.mvc.URLMappingFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { // ? ?/*from w ww . j ava2 s. c o m*/ HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; RequestContext rc = RequestContext.begin(this.context, request, response); String req_uri = rc.uri(); try { // URL ? for (String ignoreURI : ignoreURIs) { if (req_uri.startsWith(ignoreURI)) { chain.doFilter(rc.request(), rc.response()); return; } } // URL ? for (String ignoreExt : ignoreExts) { if (req_uri.endsWith(ignoreExt)) { chain.doFilter(rc.request(), rc.response()); return; } } rc.request().setAttribute(REQUEST_URI, req_uri); String[] paths = StringUtils.split(req_uri, '/'); String vm = _GetTemplate(rc.request(), paths, paths.length); rc.forward(vm); } catch (SecurityException e) { String login_page = e.getMessage() + "?goto_page=" + URLEncoder.encode(req_uri, "utf-8"); rc.redirect(login_page); } finally { if (rc != null) rc.end(); } }
From source file:com.frank.search.solr.server.support.HttpSolrClientFactoryBean.java
private void createLoadBalancedHttpSolrClient() { try {//from w ww .j ava 2s. c o m LBHttpSolrClient lbHttpSolrClient = new LBHttpSolrClient( StringUtils.split(this.url, SERVER_URL_SEPARATOR)); if (timeout != null) { lbHttpSolrClient.setConnectionTimeout(timeout.intValue()); } this.setSolrClient(lbHttpSolrClient); } catch (MalformedURLException e) { throw new IllegalArgumentException("Unable to create Load Balanced Http Solr Server", e); } }
From source file:hip.util.CliCommonOpts.java
public static String[] extractFilesFromOpts(Cli cli) { return StringUtils.split(cli.getArgValueAsString(CliCommonOpts.FileOption.FILE), ","); }