List of usage examples for org.apache.commons.lang StringUtils splitByWholeSeparatorPreserveAllTokens
public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator)
Splits the provided text into an array, separator string specified.
From source file:org.eclipse.wb.internal.core.utils.ast.AstEditor.java
/** * Re-indents source at place.// w w w. j a va2 s . co m */ private void reindentSource(int sourceStart, int sourceLength, String indent, String eol) throws Exception { // prepare lines String[] lines; { String source = getSource(sourceStart, sourceLength); lines = StringUtils.splitByWholeSeparatorPreserveAllTokens(source, eol); } // change indentation for lines int position = sourceStart; String oldIndent = null; for (String line : lines) { // prepare line indentation String lineIndent = ""; { int endOfIndent = StringUtils.indexOfAnyBut(line, "\t "); if (endOfIndent != -1) { lineIndent = line.substring(0, endOfIndent); } else { lineIndent = line; } } // use indentation of first line as base if (oldIndent == null) { oldIndent = lineIndent; } // replace indentation if (lineIndent.startsWith(oldIndent)) { replaceSubstring(position, oldIndent.length(), indent); position += indent.length() - oldIndent.length(); } // move position to next line position += line.length() + eol.length(); } }
From source file:org.fornax.utilities.xtendtools.lib.StringsExtension.java
/** * Delegate for StringUtils.splitByWholeSeparatorPreserveAllTokens. * /* w w w. j av a 2 s . co m*/ * @see StringUtils#splitByWholeSeparatorPreserveAllTokens(String, String) */ public static List<String> splitByWholeSeparatorPreserveAllTokens(final String str, final String separator) { return Arrays.asList(StringUtils.splitByWholeSeparatorPreserveAllTokens(str, separator)); }
From source file:org.kuali.maven.wagon.MimeTypeParser.java
/** * @param args/* w ww . ja v a2 s . co m*/ */ public static void main(final String[] args) { try { String filename = "C:/Program Files/Apache Software Foundation/Tomcat 6.0/conf/web.xml"; String contents = IOUtils.toString(new FileInputStream(filename)); String tomcatMimetypes = StringUtils.substringBetween(contents, "<!-- deployment descriptor. -->", "<!-- ==================== Default Welcome File List ===================== -->"); String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(tomcatMimetypes, "<mime-mapping>"); System.out.println(tokens.length); List<Mapping> mappings = new ArrayList<Mapping>(); int count = 0; for (String token : tokens) { count++; if (count == 1) { continue; } Mapping m = new Mapping(); String extension = StringUtils.substringBetween(token, "<extension>", "</extension>"); String type = StringUtils.substringBetween(token, "<mime-type>", "</mime-type>"); m.setExtension(extension); m.setType(type); // System.out.println("'" + token + "'" + " " + type + " " + extension); mappings.add(m); } Map<String, String> mimeTypes = new TreeMap<String, String>(); for (Mapping mapping : mappings) { String extension = mimeTypes.get(mapping.getType()); if (extension == null) { extension = mapping.getExtension(); } else { extension += " " + mapping.getExtension(); } mimeTypes.put(mapping.getType(), extension); } System.out.println(mappings.size() + " " + mimeTypes.size()); System.out.println(getString(mimeTypes)); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.kuali.rice.kew.docsearch.SearchableAttributeNumericBase.java
/** * Tests that (if the given binaryOperator is present in the valueEntered) the operands are valid. * * <p>The operand test is done by calling isPassesDefaultValidation. If the binaryOperator is not present, * true is returned.</p>//from w w w . j a v a2 s . c o m * * @param valueEntered the string being validated * @param binaryOperator the operator to test * @return whether the operands are valid for the given binaryOperator */ private boolean isOperandsValid(String valueEntered, SearchOperator binaryOperator) { if (StringUtils.contains(valueEntered, binaryOperator.op())) { // using this split method to make sure we test both sides of the operator. Using String.split would // throw away empty strings, so e.g. "&&100".split("&&") would return an array with one element, ["100"]. String[] l = StringUtils.splitByWholeSeparatorPreserveAllTokens(valueEntered, binaryOperator.op()); for (String value : l) { if (!isPassesDefaultValidation(value)) { return false; } } } return true; }
From source file:org.kuali.rice.krad.uif.service.impl.ViewHelperServiceImpl.java
/** * {@inheritDoc}/* w ww .j a v a 2 s . com*/ */ @SuppressWarnings("unchecked") public void processMultipleValueLookupResults(ViewModel model, String collectionId, String collectionPath, String multiValueReturnFields, String lookupResultValues) { // if no line values returned, no population is needed if (StringUtils.isBlank(lookupResultValues) || !(model instanceof ViewModel)) { return; } ViewModel viewModel = (ViewModel) model; if (StringUtils.isBlank(collectionId)) { throw new RuntimeException( "Id is not set for this collection lookup: " + collectionId + ", " + "path: " + collectionPath); } // retrieve the collection group so we can get the collection class and collection lookup Class<?> collectionObjectClass = (Class<?>) viewModel.getViewPostMetadata() .getComponentPostData(collectionId, UifConstants.PostMetadata.COLL_OBJECT_CLASS); Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(model, collectionPath); if (collection == null) { Class<?> collectionClass = ObjectPropertyUtils.getPropertyType(model, collectionPath); collection = (Collection<Object>) KRADUtils.createNewObjectFromClass(collectionClass); ObjectPropertyUtils.setPropertyValue(model, collectionPath, collection); } // get the field conversions Map<String, String> fieldConversions = (Map<String, String>) viewModel.getViewPostMetadata() .getComponentPostData(collectionId, UifConstants.PostMetadata.COLL_LOOKUP_FIELD_CONVERSIONS); // filter the field conversions by what was returned from the multi value lookup return fields Map<String, String> returnedFieldConversions = filterByReturnedFieldConversions(multiValueReturnFields, fieldConversions); List<String> toFieldNamesColl = new ArrayList<String>(returnedFieldConversions.values()); Collections.sort(toFieldNamesColl); String[] toFieldNames = new String[toFieldNamesColl.size()]; toFieldNamesColl.toArray(toFieldNames); // first split to get the line value sets String[] lineValues = StringUtils.split(lookupResultValues, ","); List<Object> lineDataObjects = new ArrayList<Object>(); // for each returned set create a new instance of collection class and populate with returned line values for (String lineValue : lineValues) { Object lineDataObject = null; // TODO: need to put this in data object service so logic can be reused ModuleService moduleService = KRADServiceLocatorWeb.getKualiModuleService() .getResponsibleModuleService(collectionObjectClass); if (moduleService != null && moduleService.isExternalizable(collectionObjectClass)) { lineDataObject = moduleService.createNewObjectFromExternalizableClass(collectionObjectClass .asSubclass(org.kuali.rice.krad.bo.ExternalizableBusinessObject.class)); } else { lineDataObject = KRADUtils.createNewObjectFromClass(collectionObjectClass); } String[] fieldValues = StringUtils.splitByWholeSeparatorPreserveAllTokens(lineValue, ":"); if (fieldValues.length != toFieldNames.length) { throw new RuntimeException( "Value count passed back from multi-value lookup does not match field conversion count"); } // set each field value on the line for (int i = 0; i < fieldValues.length; i++) { String fieldName = toFieldNames[i]; ObjectPropertyUtils.setPropertyValue(lineDataObject, fieldName, fieldValues[i]); } lineDataObjects.add(lineDataObject); processAndAddLineObject(viewModel, lineDataObject, collectionId, collectionPath); } viewModel.getViewPostMetadata().getAddedCollectionObjects().put(collectionId, lineDataObjects); }
From source file:org.localmatters.serializer.resolver.ComplexPropertyResolver.java
/** * @see org.localmatters.serializer.resolver.PropertyResolver#resolve(java.lang.Object, java.lang.String) *//* ww w .ja va 2 s. c o m*/ public Object resolve(Object bean, String property) throws PropertyResolverException { if (StringUtils.isBlank(property)) { throw new InvalidPropertyException(property, bean.getClass().getName()); } Object value = bean; String[] simpleProperties = StringUtils.splitByWholeSeparatorPreserveAllTokens(property, getToken()); for (String simpleProperty : simpleProperties) { if (StringUtils.isBlank(simpleProperty)) { throw new InvalidPropertyException(property, bean.getClass().getName()); } value = getDelegate().resolve(value, simpleProperty); if (value == null) { return null; } } return value; }
From source file:org.openhab.binding.homematic.internal.communicator.parser.CcuVariablesAndScriptsParser.java
/** * {@inheritDoc}//w w w .j av a 2s . c o m */ @Override public Void parse(TclScriptDataList resultList) throws IOException { if (resultList.getEntries() != null) { for (TclScriptDataEntry entry : resultList.getEntries()) { HmDatapoint dp = new HmDatapoint(); dp.setName(entry.name); dp.setInfo(entry.name); dp.setDescription(entry.description); dp.setValue(convertToType(entry.value)); dp.setMinValue((Number) convertToType(entry.minValue)); dp.setMaxValue((Number) convertToType(entry.maxValue)); dp.setReadOnly(entry.readOnly); dp.setUnit(entry.unit); String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(entry.options, ";"); dp.setOptions(result == null || result.length == 0 ? null : result); if (dp.getOptions() != null) { dp.setMinValue(0); dp.setMaxValue(dp.getOptions().length - 1); } dp.setType(HmValueType.parse(entry.valueType)); dp.setParamsetType(HmParamsetType.VALUES); channel.addDatapoint(dp); } } return null; }
From source file:org.openhab.binding.homematic.internal.model.adapter.ValueListAdapter.java
/** * {@inheritDoc}// w w w.j ava 2 s .com */ @Override public String[] unmarshal(String value) throws Exception { String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(value, ";"); return (result.length == 0 ? null : result); }
From source file:org.openhab.binding.weather.internal.model.common.adapter.ValueListAdapter.java
/** * {@inheritDoc}//from ww w .jav a2 s . com */ @Override public String[] unmarshal(String value) throws Exception { String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(value, ","); return (result.length == 0 ? null : result); }
From source file:org.openmrs.module.emrmonitor.UptimeLog.java
/** * @return a current line in the log file into a String[]. Returns null if the line is blank *//* w ww . ja va 2 s . c o m*/ public static String[] parseLine(String line) { if (StringUtils.isNotBlank(line)) { return StringUtils.splitByWholeSeparatorPreserveAllTokens(line, LOG_ENTRY_SEPARATOR); } return null; }