List of usage examples for org.apache.commons.lang StringUtils splitPreserveAllTokens
public static String[] splitPreserveAllTokens(String str, String separatorChars)
Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.
From source file:com.dcsquare.hivemq.spi.topic.PermissionTopicMatcher.java
private static boolean matchesWildcards(final String topicSubscription, final String actualTopic) { if (topicSubscription.contains("#")) { if (!StringUtils.endsWith(topicSubscription, "/#") && topicSubscription.length() > 1) { return false; }/*ww w. j av a 2 s.c o m*/ } final String[] subscription = StringUtils.splitPreserveAllTokens(topicSubscription, "/"); final String[] topic = StringUtils.splitPreserveAllTokens(actualTopic, "/"); final int smallest = min(subscription.length, topic.length); for (int i = 0; i < smallest; i++) { final String sub = subscription[i]; final String t = topic[i]; if (!sub.equals(t)) { if (sub.equals("#")) { return true; } else if (sub.equals("+")) { //Matches Topic Level wildcard, so we can just ignore } else { //Does not match a wildcard and is not equal to the topic token return false; } } } //If the length is equal or the subscription token with the number x+1 (where x is the topic length) is a wildcard, //everything is alright. return subscription.length == topic.length || (subscription.length - topic.length == 1 && (subscription[subscription.length - 1].equals("#"))); }
From source file:kr.ac.korea.dbserver.parser.SQLErrorListener.java
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { CommonTokenStream tokens = (CommonTokenStream) recognizer.getInputStream(); String input = tokens.getTokenSource().getInputStream().toString(); Token token = (Token) offendingSymbol; String[] lines = StringUtils.splitPreserveAllTokens(input, '\n'); String errorLine = lines[line - 1]; throw new SQLParseError(token, line, charPositionInLine, msg, errorLine); }
From source file:ch.astina.hesperid.web.services.springsecurity.RequestInvocationDefinition.java
public RequestInvocationDefinition(String key, String roles) { this.requestKey = new RequestKey(key); String[] allAttrs = StringUtils.stripAll(StringUtils.splitPreserveAllTokens(roles, ',')); this.configAttributes = new ArrayList<ConfigAttribute>(); for (String attr : allAttrs) { this.configAttributes.add(new SecurityConfig(attr)); }//from w ww . j a v a 2 s. com }
From source file:ch.ksfx.web.services.springsecurity.RequestInvocationDefinition.java
public RequestInvocationDefinition(String key, String roles) { this.requestKey = new RequestKey(key); String[] allAttrs = StringUtils.stripAll(StringUtils.splitPreserveAllTokens(roles, ',')); this.configAttributes = new ArrayList<ConfigAttribute>(); for (String attr : allAttrs) { this.configAttributes.add(new SecurityConfig(attr)); }//www.j a va 2s . c o m }
From source file:com.pureinfo.srm.xls2srm.CSVObjectsImpl.java
public CSVObjectsImpl(String _sFileName) throws PureException { m_datas = new ArrayList(); BufferedReader br = null;/*from w ww .j a va 2 s . c o m*/ try { br = new BufferedReader(new InputStreamReader(new FileInputStream(_sFileName))); String sLine = null; while ((sLine = br.readLine()) != null) { String[] fields = StringUtils.splitPreserveAllTokens(sLine, ','); DolphinObject obj = new DolphinObject(); for (int i = 0; i < fields.length; i++) { obj.setProperty(String.valueOf(i), fields[i]); } m_datas.add(obj); } } catch (Exception ex) { throw new PureException(PureException.UNKNOWN, "", ex); } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.edm.utils.View.java
/** * cron.//from ww w . java2 s .c o m */ public String cron(String cron) { String cronStr = null; if (StringUtils.isNotBlank(cron)) { String[] crons = StringUtils.splitPreserveAllTokens(cron, " "); if (Asserts.empty(crons) || crons.length < 5) { return null; } String minute = crons[0]; String hour = crons[1]; String day = crons[2]; String week = crons[3]; String month = crons[4]; // month if (!day.equals("*")) { cronStr = "?"; if (day.equals("-1")) cronStr += "?"; else cronStr += day + ""; } // week if (!week.equals("*")) { cronStr = "?"; if (week.equals("1,2,3,4,5")) cronStr += ""; else if (week.equals("6,7")) cronStr += "?"; else if (StringUtils.splitPreserveAllTokens(week, ",").length == 1) cronStr += "" + WeekMap.week(week); } // day if (month.equals("*") && week.equals("*") && day.equals("*")) { cronStr = "?"; } if (StringUtils.isNotBlank(cronStr)) { if (hour.length() == 1) hour = "0" + hour; if (minute.length() == 1) minute = "0" + minute; cronStr += hour + ":" + minute; } } return cronStr; }
From source file:bazaar4idea.command.BzrShowConfigCommand.java
public Map<String, String> execute(VirtualFile repo) { if (repo == null) { return Collections.emptyMap(); }// w w w . java 2 s . c om BzrStandardResult result = ShellCommandService.getInstance(project).execute2(repo, "showconfig", null); Map<String, String> options = new HashMap<String, String>(); for (String line : result.getStdOutAsLines()) { String[] option = StringUtils.splitPreserveAllTokens(line, '='); if (option.length == 2) { options.put(option[0].trim(), option[1].trim()); } } return options; }
From source file:architecture.ee.web.struts.action.common.SqlClientAction.java
private String[] stringToArray(String parametersString) { return StringUtils.splitPreserveAllTokens(parametersString, ","); }
From source file:gov.nih.nci.cacisweb.user.CacisUserService.java
@Override public UserDetails loadUserByUsername(String arg0) throws UsernameNotFoundException { try {//from w w w . j av a 2 s . co m log.debug("Loading User.."); String userProperty = CaCISUtil.getProperty(arg0); if (userProperty == null) { log.error("User Not Found"); throw new UsernameNotFoundException("User Not Found"); } String[] userDetails = StringUtils.splitPreserveAllTokens(userProperty, ','); if (userDetails.length > 0 && userDetails.length < 5) { log.error("User Not Configured Properly"); throw new UsernameNotFoundException("User Not Configured Properly"); } Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); int i = 4; while (i < userDetails.length) { authorities.add(new SimpleGrantedAuthority(userDetails[i])); i++; } SimpleDateFormat sDateFormat = new SimpleDateFormat(CaCISWebConstants.COM_DATE_FORMAT); if (!StringUtils.isBlank(userDetails[3])) { Calendar lockOutTimeCalendar = Calendar.getInstance(); lockOutTimeCalendar.setTime(sDateFormat.parse(userDetails[3])); long lockoutTimeMillis = lockOutTimeCalendar.getTimeInMillis(); long currentTimeMillis = Calendar.getInstance().getTimeInMillis(); long diffMinutes = (currentTimeMillis - lockoutTimeMillis) / (1000 * 60); if (diffMinutes > 60) { log.debug("Lockout Time greater than restricted time. Hence unlocking"); return new CacisUser(arg0, userDetails[0], true, new Short("0").shortValue(), "", authorities); } } return new CacisUser(arg0, userDetails[0], new Boolean(userDetails[1]).booleanValue(), new Short(userDetails[2]).shortValue(), userDetails[3], authorities); } catch (CaCISWebException e) { log.error("User Not Found... " + e.getMessage()); throw new UsernameNotFoundException("User Not Found. " + e.getMessage()); } catch (ParseException e) { log.error("Lockout time not configured properly. " + e.getMessage()); throw new UsernameNotFoundException("Lockout time not configured properly. " + e.getMessage()); } }
From source file:com.spotify.hdfs2cass.misc.ClusterInfoTest.java
@Test public void testSetConf() throws Exception { final ClusterInfo clusterInfo = createClusterInfo(); clusterInfo.init("foo"); final JobConf conf = new JobConf(); clusterInfo.setConf(conf);// ww w. j a va 2 s . com final String result = conf.get(ClusterInfo.SPOTIFY_CASSANDRA_TOKENS_PARAM); assertEquals(4, StringUtils.splitPreserveAllTokens(result, ",").length); }