List of usage examples for org.apache.commons.lang3.text StrTokenizer StrTokenizer
public StrTokenizer(final char[] input, final StrMatcher delim)
From source file:com.mmone.gpdati.allotment.GpDatiDispoRecord.java
private void detokenizeValues(String value) { // '1|1|13|2016-10-27|2016-10-28' StrTokenizer tokenizer = new StrTokenizer(key, "|"); String[] ta = tokenizer.getTokenArray(); structureId = ta[0];// w w w. j a va 2s .co m roomId = ta[1]; allotment = ta[2]; dateFrom = ta[3]; dateTo = ta[4]; }
From source file:me.ineson.demo.service.utils.RestUtils.java
/** * @param where/*ww w .j a v a 2 s. c o m*/ * @param root * @param query * @param builder * @param translations * @return */ public static Predicate parseWhereClause(String where, Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder, Map<String, String> translations) { List<Predicate> predicates = new ArrayList<Predicate>(); for (String singleCriteria : new StrTokenizer(where, ",").getTokenList()) { if (StringUtils.isNotBlank(singleCriteria)) { int equalsIndex = singleCriteria.indexOf("="); if (equalsIndex > 0) { String fieldPath = singleCriteria.substring(0, equalsIndex); String value = singleCriteria.substring(equalsIndex + 1); if (translations != null && translations.containsKey(fieldPath)) { String newFieldPath = translations.get(fieldPath); log.debug("replacing field {} with {} ", fieldPath, newFieldPath); fieldPath = newFieldPath; } StrTokenizer tokenizer = new StrTokenizer(fieldPath, "."); javax.persistence.criteria.Path<?> expression = null; while (tokenizer.hasNext()) { String field = tokenizer.next(); if (tokenizer.hasNext()) { if (expression == null) { expression = root.join(field); } else { // expression = expression.join( field); throw new IllegalArgumentException( "Paths to joins of greater than a depth of 1 are not implemented yet"); } } else { if (expression == null) { log.info("expression0 {}", expression); expression = root.get(field); log.info("expression1 {}", expression); } else { expression = expression.get(field); } } } Object realValue = value; if ("bodyType".equals(fieldPath)) { me.ineson.demo.service.SolarBodyType solarBodyType = me.ineson.demo.service.SolarBodyType .valueOf(value); switch (solarBodyType) { case PLANET: realValue = SolarBodyType.Planet; break; case SUN: realValue = SolarBodyType.Sun; break; case DWARF_PLANET: realValue = SolarBodyType.DwarfPlanet; break; default: realValue = solarBodyType; } log.info("enum bodyType before {} after {}", value, realValue); } log.info("expression9 {}", expression); predicates.add(builder.equal(expression, realValue)); } } } log.debug("predictes "); if (predicates.size() == 0) { return null; } if (predicates.size() == 1) { return predicates.get(0); } return builder.and(predicates.toArray(new Predicate[predicates.size()])); }
From source file:com.stratelia.silverpeas.silverstatistics.control.SilverStatisticsService.java
/** * @param type/*from w w w . j a va2 s .c om*/ * @param data */ @Override public void putStats(StatType type, String data) { StrTokenizer stData = new StrTokenizer(data, SEPARATOR); List<String> dataArray = stData.getTokenList(); if (myStatsConfig.isGoodDatas(type, dataArray)) { Connection myCon = DBUtil.makeConnection(SILVERSTATISTICS_DATASOURCE); try { SilverStatisticsDAO.putDataStats(myCon, type, dataArray, myStatsConfig); if (!myCon.getAutoCommit()) { myCon.commit(); } } catch (SQLException e) { SilverTrace.error("silverstatistics", "SilverStatisticsEJB.putStats", "silverstatistics.MSG_ALIMENTATION_BD", "typeOfStats = " + type + ", dataArray = " + dataArray, e); } catch (StatisticsRuntimeException e) { SilverTrace.error("silverstatistics", "SilverStatisticsEJB.putStats", "MSG_CONNECTION_BD"); } finally { DBUtil.close(myCon); } } else { SilverTrace.error("silverstatistics", "SilverStatisticsEJB.putStats", "MSG_CONFIG_DATAS", "data en entree=" + data + " pour " + type); } }
From source file:com.hurence.logisland.repository.csv.CsvFileParser.java
/** * Parse the file given in parameters//from www . j a v a2s. c o m * * @param filePath * @return */ public List<T> parseFile(String filePath) { List<T> result = new ArrayList<>(); InputStreamReader isr = null; BufferedReader bsr = null; try { isr = new InputStreamReader(new FileInputStream(filePath), "UTF-8"); bsr = new BufferedReader(isr); logger.debug("start parsing csv file : " + filePath); int nblines = 0; String line; while ((line = bsr.readLine()) != null) { // don't parse the first line of csv if (nblines != 0) { StrTokenizer tokenizer = new StrTokenizer(line, separator); tokenizer.setIgnoreEmptyTokens(false); T o = createEntity(tokenizer); if (o != null) { result.add(o); } } else { nblines++; } } logger.debug("done parsing csv file : " + filePath); } catch (FileNotFoundException ex) { logger.error("file not found : " + filePath); } catch (IOException ex) { logger.error("unknown error while parsing : " + filePath); } finally { try { if (bsr != null) { bsr.close(); } } catch (IOException ex) { logger.error("unknown error while parsing : " + filePath); } } return result; }
From source file:de.vandermeer.skb.interfaces.transformers.String_To_ConditionalBreak.java
/** * Transforms a String to a String[] processing conditional line breaks. * Conditional line breaks are CR LF, CR, LF, <br>, and <br/>. * /*from ww w . ja va 2 s . c o m*/ * The method proceeds as follows: * * . replace all line breaks (CR LF, CR, LF) into HTML4 line break entity <br> * . replace all HTML4 line break entities to HTML5 entities (as in self-closing <br/> entity). * . use a `tokenizer` to process the resulting string (not ignoring empty tokens, since they mark required line breaks). * . return the array of the `tokenizer` * * As a result, a string containing 1 line break will be converted into an array length 2: * ---- * String: "paragraph 1\nparagraph 2" * Array: {paragraph 1,paragraph 2} * ---- * * A string containing 2 line breaks will be converted into a string array with 3 entries (first paragraph, additional line break, second paragraph): * ---- * String: "paragraph 1\n\nparagraph 2" * Array: {paragraph 1,,paragraph 2} * ---- * * @param s input string * @return array with conditional line breaks converted to empty entries, `null` if `s` was `null` */ @Override default String[] transform(String s) { IsTransformer.super.transform(s); if ("".equals(s)) { return new String[] { "" }; } String lfRep = StringUtils.replacePattern(s.toString(), "\\r\\n|\\r|\\n", "<br>"); lfRep = StringUtils.replace(lfRep, "<br>", "<br/>"); lfRep = StringUtils.replace(lfRep, "<br/>", "<br />"); StrTokenizer tok = new StrTokenizer(lfRep, "<br />").setIgnoreEmptyTokens(false); return tok.getTokenArray(); }
From source file:de.vandermeer.skb.interfaces.transformers.textformat.Text_To_WrappedFormat.java
@Override default Pair<ArrayList<String>, ArrayList<String>> transform(String input) { Validate.notBlank(input);//w ww . ja v a2 s . c o m Validate.isTrue(this.getWidth() > 0); ArrayList<String> topList = new ArrayList<>(); ArrayList<String> bottomList = new ArrayList<>(); //an emergency break, counting loops to avoid endless loops int count; String text = StringUtils.replacePattern(input, "\\r\\n|\\r|\\n", LINEBREAK); text = StringUtils.replace(text, "<br>", LINEBREAK); text = StringUtils.replace(text, "<br/>", LINEBREAK); StrBuilder sb = new StrBuilder(text); if (this.getTopSettings() != null) { //we have a top request, do that one first Validate.notNull(this.getTopSettings().getLeft()); Validate.notNull(this.getTopSettings().getRight()); Validate.isTrue(this.getTopSettings().getLeft() > 0); Validate.isTrue(this.getTopSettings().getRight() > 0); int topLines = this.getTopSettings().getLeft(); int topWidth = this.getTopSettings().getRight(); count = 0; while (sb.size() > 0 && topLines > 0 && count++ < 200) { if (sb.startsWith(LINEBREAK)) { sb.replaceFirst(LINEBREAK, ""); } String s = null; boolean wln = false; if (sb.indexOf(LINEBREAK) > 0) { s = sb.substring(0, sb.indexOf(LINEBREAK)); wln = true; //sb.replace(0, sb.indexOf(LINEBREAK) + LINEBREAK.length(), ""); } else { s = sb.toString(); //sb.clear(); } String wrap = WordUtils.wrap(s, topWidth, LINEBREAK, true); StrTokenizer tok = new StrTokenizer(wrap, LINEBREAK).setIgnoreEmptyTokens(false); String[] ar = tok.getTokenArray(); if (ar.length <= topLines) { //all lines done, cleanup for (String str : ar) { topList.add(str.trim()); } if (wln == true) { //if we had a conditional linebreak there might be more text, remove the line we processed sb.replace(0, sb.indexOf(LINEBREAK) + LINEBREAK.length(), ""); } else { //no conditional line break, clean builder sb.clear(); } topLines = 0; } else { //we have more lines than we need, so remove the text we have from the builder and copy processed lines StrBuilder replace = new StrBuilder(); for (int i = 0; i < topLines; i++) { topList.add(ar[i].trim()); replace.appendSeparator(' ').append(ar[i]); } if (wln == true) { replace.append(LINEBREAK); } sb.replaceFirst(replace.toString(), ""); topLines = 0; } } } //no top, simple wrapping with recognition of conditional line breaks count = 0; while (sb.size() > 0 && count++ < 200) { if (sb.startsWith(LINEBREAK)) { sb.replaceFirst(LINEBREAK, ""); } String s = null; if (sb.indexOf(LINEBREAK) > 0) { s = sb.substring(0, sb.indexOf(LINEBREAK)); sb.replace(0, sb.indexOf(LINEBREAK) + LINEBREAK.length(), ""); } else { s = sb.toString(); sb.clear(); } s = WordUtils.wrap(s, this.getWidth(), LINEBREAK, true); StrTokenizer tok = new StrTokenizer(s, LINEBREAK).setIgnoreEmptyTokens(false); for (String str : tok.getTokenArray()) { bottomList.add(str.trim()); } } return Pair.of(topList, bottomList); }
From source file:com.digitalgeneralists.assurance.model.entities.ApplicationConfiguration.java
private List<String> transformStringPropertyToListProperty(String property, boolean removeExtensionPatterns) { StrTokenizer tokenizer = new StrTokenizer(property, ','); List<String> tokenizedList = tokenizer.getTokenList(); // NOTE: May want to reconsider the toLowercase conversion. ListIterator<String> iterator = tokenizedList.listIterator(); while (iterator.hasNext()) { String extension = iterator.next(); // NOTE: This is probably a bit overly-aggressive and less-sophisticated than it could be, // but it should handle 99% of the input that will be entered. if (removeExtensionPatterns) { extension = StringUtils.replace(extension, "*.", ""); extension = StringUtils.replace(extension, "*", ""); extension = StringUtils.replace(extension, ".", ""); }//from w ww. j a v a 2s . c om iterator.set(extension.toLowerCase().trim()); } return tokenizedList; }
From source file:me.ineson.demo.service.utils.RestUtils.java
/** * @param orderBy//from w ww . j a va 2 s . com * @return */ public static Sort parseSortOrder(String orderBy) { Sort sort = null; if (StringUtils.isNotEmpty(orderBy)) { List<Order> orderByList = new ArrayList<>(); for (String singleOrderBy : new StrTokenizer(orderBy, ",").getTokenList()) { log.trace("singleOrderBy {}", singleOrderBy); if (StringUtils.isNotBlank(singleOrderBy)) { Direction direction = Direction.ASC; if (singleOrderBy.startsWith("+")) { singleOrderBy = singleOrderBy.substring(1); } else if (singleOrderBy.startsWith("-")) { direction = Direction.DESC; singleOrderBy = singleOrderBy.substring(1); } orderByList.add(new Order(direction, singleOrderBy)); } } if (!orderByList.isEmpty()) { sort = new Sort(orderByList); } } return sort; }
From source file:de.vandermeer.asciitable.commons.ArrayTransformations.java
/** * Takes an object (used as a string) and returns a string array with all processed lines. * The process is as follows://w w w .j ava 2 s . c om * (1) replace all line breaks (CR LF, CR, LF) into HTML4 line break entity (<br>). * (2) replace all HTML4 line break entities to HTML5 entities (as in self-closing <br/> entity). * (3) use a tokenizer to process the resulting string (not ignoring empty tokens, since they mark required line breaks). * (4) return the array of the tokenizer * * As a result, a string containing 1 line break will be converted into 2 paragraphs (array length 2): * <pre>{@code String: "paragraph 1\nparagraph 2" Array: {paragraph 1,paragraph 2} * }</pre> * A string containing 2 line breaks will be converted into 3 strings (first paragraph, additional line break, second paragraph): * <pre>{@code String: "paragraph 1\n\nparagraph 2" Array: {paragraph 1,,paragraph 2} * }</pre> * * @param content the content to process * @return null if content was null, empty array if content was an empty string, string array with lines otherwise */ public static final String[] PROCESS_CONTENT(Object content) { if (content == null || content.toString() == null) { return null; } if ("".equals(content)) { return new String[] { "" }; } String lfRep = StringUtils.replacePattern(content.toString(), "\\r\\n|\\r|\\n", "<br>"); lfRep = StringUtils.replace(lfRep, "<br>", "<br/>"); StrTokenizer tok = new StrTokenizer(lfRep, "<br/>").setIgnoreEmptyTokens(false); return tok.getTokenArray(); }
From source file:com.bekwam.resignator.commands.KeytoolCommand.java
public List<KeystoreEntry> parseKeystoreEntries(BufferedReader br) throws IOException { List<KeystoreEntry> entries = new ArrayList<>(); String line = ""; KeystoreListParseStateType parseState = KeystoreListParseStateType.HEADER; KeystoreEntry currEntry = null;/*w w w . j a v a 2 s . c om*/ while (parseState != KeystoreListParseStateType.END && parseState != KeystoreListParseStateType.ERROR_END) { switch (parseState) { case START: parseState = KeystoreListParseStateType.HEADER; break; case HEADER: line = br.readLine(); if (StringUtils.startsWith(line, "Your keystore")) { parseState = KeystoreListParseStateType.ENTRY; } else if (line == null) { parseState = KeystoreListParseStateType.ERROR_END; } break; case ENTRY: line = br.readLine(); if (StringUtils.startsWith(line, "Certificate fingerprint")) { parseState = KeystoreListParseStateType.FP; } else { if (line == null) { parseState = KeystoreListParseStateType.ERROR_END; } else if (StringUtils.isNotEmpty(line)) { String[] toks = StringUtils.split(line, ","); currEntry = new KeystoreEntry(StringUtils.trim(toks[0]), StringUtils.trim(toks[1] + toks[2]), StringUtils.trim(toks[3])); } } break; case FP: if (StringUtils.isNotEmpty(line)) { StrTokenizer st = new StrTokenizer(line, ": "); if (st != null) { String[] toks = st.getTokenArray(); currEntry = new KeystoreEntry(currEntry, toks[1]); entries.add(currEntry); } } parseState = KeystoreListParseStateType.ENTRY; break; case ERROR_END: case END: break; } } return entries; }