List of usage examples for org.apache.commons.lang StringUtils splitByWholeSeparator
public static String[] splitByWholeSeparator(String str, String separator)
Splits the provided text into an array, separator string specified.
From source file:com.fiveamsolutions.nci.commons.web.struts2.validator.HibernateValidator.java
private void convertMultipleCriteriaMessages(String fieldName, String combinedMessage) { String[] messages = StringUtils.splitByWholeSeparator(combinedMessage, MultipleCriteriaMessageInterpolator.MESSAGE_SEPARATOR); //start from 1, because the message at index 0 is actually the header for (int i = 1; i < messages.length; i++) { if (StringUtils.isNotBlank(messages[i])) { String[] messageParts = StringUtils.splitByWholeSeparator(messages[i], MultipleCriteriaMessageInterpolator.FIELD_SEPARATOR); InvalidValue iv = new InvalidValue(messageParts[1], null, messageParts[0], null, null); addFieldError(fieldName, iv); }/*from w w w . j a va 2 s . co m*/ } }
From source file:info.magnolia.cms.util.QueryUtil.java
/** * Creates a simple SQL2 query statement. * /*from w w w . j a v a 2s. c o m*/ * @param statement * @param startPath */ public static String buildQuery(String statement, String startPath) { Set<String> arguments = new HashSet<String>( Arrays.asList(StringUtils.splitByWholeSeparator(statement, ","))); Iterator<String> argIt = arguments.iterator(); String queryString = "select * from [nt:base] as t where ISDESCENDANTNODE([" + startPath + "])"; while (argIt.hasNext()) { queryString = queryString + " AND contains(t.*, '" + argIt.next() + "')"; } log.debug("query string: " + queryString); return queryString; }
From source file:adalid.commons.velocity.VelocityAid.java
/** * split a text into a list of lines./*from w w w. ja va2 s . c o m*/ * * @param string the text to split. * @param max the maximum line length. * @param separator the paragraph separator string. * @param separatorLine if true, the paragraph separator is added as a line between paragraphs. * @param prefix the new line prefix * @return the list of split. */ public static List<String> split(String string, int max, String separator, boolean separatorLine, String prefix) { List<String> strings = new ArrayList<>(); String str = StringUtils.trimToNull(string); if (str != null) { int maxLineLength, lineLength, wordLength, lastParagraph; String line, paragraph; String[] words, paragraphs; String sep = StringUtils.trimToNull(separator); String nlp = prefix == null ? "" : prefix; boolean sl = sep != null && separatorLine; paragraphs = sep == null ? new String[] { str } : StringUtils.splitByWholeSeparator(str, separator); lastParagraph = paragraphs.length - 1; for (int i = 0; i < paragraphs.length; i++) { // paragraph = paragraphs[i].trim(); paragraph = paragraphs[i].replaceAll(" +$", ""); // remove spaces at the end of the paragraph if (max > 0) { maxLineLength = max; if (paragraph.length() > maxLineLength) { line = ""; words = StringUtils.split(paragraph); for (String word : words) { lineLength = line.length(); wordLength = word.length() + 1; if (lineLength == 0) { line = word; } else if (lineLength + wordLength > maxLineLength) { strings.add(line); maxLineLength = max - nlp.length(); line = nlp + word; } else { line += " " + word; } } strings.add(line); } else { strings.add(paragraph); } } else { strings.add(paragraph); } if (sl && i < lastParagraph) { strings.add(sep); } } } return strings; }
From source file:com.dianping.cache.service.impl.CacheConfigurationServiceImpl.java
@SuppressWarnings("unchecked") public void clearByKey(String cacheType, String key, boolean clearDistributed) { CacheConfiguration configuration = find(cacheType); if (configuration != null) { String clientClazz = configuration.getClientClazz(); try {//from w w w . j a v a2 s . c o m if ("com.dianping.cache.memcached.MemcachedClientImpl".equals(clientClazz)) { if (clearDistributed) { MemcachedClientConfig config = new MemcachedClientConfig(); config.setServerList(configuration.getServerList()); Class<?> transcoderClazz = Class.forName(configuration.getTranscoderClazz()); config.setTranscoderClass(transcoderClazz); StoreClient cacheClient = StoreClientBuilder.buildStoreClient(cacheType, config); String[] keyList = StringUtils.splitByWholeSeparator(key, CACHE_FINAL_KEY_SEP); if (keyList != null) { for (String singleKey : keyList) { cacheClient.delete(singleKey); } } } } else { final SingleCacheRemoveDTO message = new SingleCacheRemoveDTO(); message.setAddTime(System.currentTimeMillis()); message.setCacheType(cacheType); message.setCacheKey(key); cacheMessageProducer.sendMessageToTopic(message); } logCacheItemClear(cacheType, key, true); } catch (Exception e) { logCacheItemClear(cacheType, key, false); throw new RuntimeException("Clear cache with key[" + key + "] failed.", e); } } else { logger.error("Clear cache by key failed, cacheType[" + cacheType + "] not found."); } }
From source file:com.baidu.rigel.biplatform.ac.util.DataModelUtils.java
/** * UniqueName??value//from w w w .jav a 2 s . c o m * * @param nodeUniqueName * @return */ public static String[] parseNodeUniqueNameToNodeValueArray(String nodeUniqueName) { if (StringUtils.isBlank(nodeUniqueName)) { throw new IllegalArgumentException("node unique is illegal:" + nodeUniqueName); } String preSplitUniqueName = nodeUniqueName; if (preSplitUniqueName.startsWith("{")) { preSplitUniqueName = preSplitUniqueName.substring(1); } if (preSplitUniqueName.endsWith("}")) { preSplitUniqueName = preSplitUniqueName.substring(0, preSplitUniqueName.length() - 1); } // ].[?? return StringUtils.splitByWholeSeparator(preSplitUniqueName, "}.{"); }
From source file:gov.nih.nci.cabig.caaers.domain.report.Report.java
@Transient public String[] getCorrelationIds() { return StringUtils.splitByWholeSeparator(getMetaDataAsMap().get("correlationId"), ","); }
From source file:gov.nih.nci.cabig.caaers.domain.report.Report.java
@Transient public LinkedHashMap<String, String> getMetaDataAsMap() { LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(); String[] kvs = StringUtils.splitByWholeSeparator(getMetaData(), "|$"); if (kvs != null) { for (String kv : kvs) { int i = kv.indexOf(":~"); map.put(kv.substring(0, i), kv.substring(i + 2)); }/*w ww .ja v a 2s. c om*/ } return map; }
From source file:com.cloudera.impala.service.ZooKeeperSession.java
/** * Parse comma separated list of ACL entries to secure generated nodes, e.g. * <code>sasl:recordservice/host1@MY.DOMAIN:cdrwa,</code> */// w w w .ja v a 2 s. co m private static List<ACL> parseACLs(String aclString) { String[] aclComps = StringUtils.splitByWholeSeparator(aclString, ","); List<ACL> acl = new ArrayList<ACL>(aclComps.length); for (String a : aclComps) { if (StringUtils.isBlank(a)) { continue; } a = a.trim(); // from ZooKeeperMain private method int firstColon = a.indexOf(':'); int lastColon = a.lastIndexOf(':'); if (firstColon == -1 || lastColon == -1 || firstColon == lastColon) { LOGGER.error(a + " does not have the form scheme:id:perm"); continue; } ACL newAcl = new ACL(); newAcl.setId(new Id(a.substring(0, firstColon), a.substring(firstColon + 1, lastColon))); newAcl.setPerms(getPermFromString(a.substring(lastColon + 1))); acl.add(newAcl); } return acl; }
From source file:net.sourceforge.seqware.webservice.resources.tables.WorkflowRunIDResource.java
/** * <p>updateWorkflowRun.</p> * * @param newWR a {@link net.sourceforge.seqware.common.model.WorkflowRun} object. * @return a {@link net.sourceforge.seqware.common.model.WorkflowRun} object. * @throws org.restlet.resource.ResourceException if any. * @throws java.sql.SQLException if any. *//* w w w.j a v a 2s . c o m*/ public WorkflowRun updateWorkflowRun(WorkflowRun newWR) throws ResourceException, SQLException { authenticate(); WorkflowRunService wrs = BeanFactory.getWorkflowRunServiceBean(); WorkflowRun wr = (WorkflowRun) testIfNull(wrs.findBySWAccession(newWR.getSwAccession())); wr.givesPermission(registration); //ius_workflow_runs if (newWR.getIus() != null) { SortedSet<IUS> iuses = newWR.getIus(); if (iuses != null) { SortedSet<IUS> set = new TreeSet<>(); for (IUS ius : iuses) { IUSService is = BeanFactory.getIUSServiceBean(); IUS newI = is.findBySWAccession(ius.getSwAccession()); newI.givesPermission(registration); set.add(newI); } wr.setIus(set); } else { Log.info("Could not be found: iuses"); } } //lane_workflow_runs if (newWR.getLanes() != null) { SortedSet<Lane> lanes = newWR.getLanes(); if (lanes != null) { SortedSet<Lane> set = new TreeSet<>(); for (Lane lane : lanes) { LaneService ls = BeanFactory.getLaneServiceBean(); Lane newL = ls.findBySWAccession(lane.getSwAccession()); newL.givesPermission(registration); set.add(newL); } wr.setLanes(set); } else { Log.info("Could not be found: lanes"); } } wr.setCommand(newWR.getCommand()); wr.setCurrentWorkingDir(newWR.getCurrentWorkingDir()); wr.setDax(newWR.getDax()); wr.setHost(newWR.getHost()); wr.setIniFile(newWR.getIniFile()); wr.setName(newWR.getName()); wr.setStatus(newWR.getStatus()); wr.setStatusCmd(newWR.getStatusCmd()); wr.setTemplate(newWR.getTemplate()); wr.setSeqwareRevision(newWR.getSeqwareRevision()); wr.setUserName(newWR.getUserName()); wr.setUpdateTimestamp(new Date()); wr.setStdErr(newWR.getStdErr()); wr.setStdOut(newWR.getStdOut()); wr.setWorkflowEngine(newWR.getWorkflowEngine()); if (newWR.getInputFileAccessions() != null) { Log.debug("Saving " + wr.getInputFileAccessions().size() + " input files"); wr.getInputFileAccessions().addAll(newWR.getInputFileAccessions()); } if (newWR.getWorkflow() != null) { WorkflowService ws = BeanFactory.getWorkflowServiceBean(); Workflow w = ws.findByID(newWR.getWorkflow().getWorkflowId()); if (w != null) { wr.setWorkflow(w); } else { Log.info("Could not be found: workflow " + newWR.getWorkflow()); } } if (newWR.getOwner() != null) { Registration reg = BeanFactory.getRegistrationServiceBean() .findByEmailAddress(newWR.getOwner().getEmailAddress()); if (reg != null) { wr.setOwner(reg); } else { Log.info("Could not be found: " + newWR.getOwner()); } } else if (wr.getOwner() == null) { wr.setOwner(registration); } if (newWR.getWorkflowRunAttributes() != null) { this.mergeAttributes(wr.getWorkflowRunAttributes(), newWR.getWorkflowRunAttributes(), wr); } // SEQWARE-1778 - try to properly create parameters in the workflow_run_param table as well //convert ini file parameters into expected format HashMap<String, String> map = new HashMap<>(); if (wr.getIniFile() != null && !wr.getIniFile().isEmpty()) { // just skip if previous ini file params detected if (wr.getWorkflowRunParams().size() > 0) { Log.debug("Skipping since params: " + wr.getWorkflowRunParams().size()); } else { String[] splitByWholeSeparator = StringUtils.splitByWholeSeparator(wr.getIniFile(), "\n"); for (String line : splitByWholeSeparator) { String[] lineSplit = StringUtils.splitByWholeSeparator(line, "="); if (lineSplit.length == 0) { continue; } map.put(lineSplit[0], lineSplit.length > 1 ? lineSplit[1] : ""); } SortedSet<WorkflowRunParam> createWorkflowRunParameters = WorkflowManager .createWorkflowRunParameters(map); // looks like the WorkflowManager code does not set workflow run for (WorkflowRunParam p : createWorkflowRunParameters) { p.setWorkflowRun(wr); } Log.debug("Setting params: " + createWorkflowRunParameters.size()); wr.getWorkflowRunParams().addAll(createWorkflowRunParameters); } } wrs.update(registration, wr); //direct DB calls if (newWR.getIus() != null) { addNewIUSes(newWR, wr); } if (newWR.getLanes() != null) { addNewLanes(newWR, wr); } return wr; }
From source file:nl.strohalm.cyclos.services.application.ApplicationServiceImpl.java
private static String extract(final String cvsTagName) { if (cvsTagName == null) { return ""; }// w w w .j a va 2 s . c o m String result = cvsTagName; result = result.replaceAll("\\$Name:", ""); result = result.replaceAll("\\$", ""); result = result.replaceAll(" ", ""); if (StringUtils.isBlank(result) || !result.contains(MINOR_VERSION_TAG)) { return ""; } else { String[] tmp = StringUtils.splitByWholeSeparator(result, MINOR_VERSION_TAG); return tmp[tmp.length - 1]; } }