Java Code Examples for org.springframework.util.StringUtils.delimitedListToStringArray()

The following are Jave code examples for showing how to use delimitedListToStringArray() of the org.springframework.util.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: profile-manager   File: ConversionUtility.java   View Source Code Vote up 6 votes
public static Class<?> getFieldType(Class<?> persistentClass, String name) throws NoSuchFieldException {
	String[] fields = StringUtils.delimitedListToStringArray(name, ".");
	Class<?> t;

	t = persistentClass.getDeclaredField(fields[0]).getType();

	if (Collection.class.isAssignableFrom(t)) {
		Field collectionField = persistentClass.getDeclaredField(fields[0]);
		ParameterizedType collectionType = (ParameterizedType) collectionField.getGenericType();
		t = (Class<?>) collectionType.getActualTypeArguments()[0];
	}
	if (fields.length == 1) {
		return t;
	} else {
		return getFieldType((Class<?>) t, name.substring(name.indexOf(".") + 1));
	}
}
 
Example 2
Project: spring-grow   File: ConversionUtility.java   View Source Code Vote up 6 votes
public static Class<?> getFieldType(Class<?> persistentClass, String name) throws NoSuchFieldException {
   String[] fields = StringUtils.delimitedListToStringArray(name, ".");
   Class<?> t;

   t = persistentClass.getDeclaredField(fields[0]).getType();

   if (Collection.class.isAssignableFrom(t)) {
      Field collectionField = persistentClass.getDeclaredField(fields[0]);
      ParameterizedType collectionType = (ParameterizedType) collectionField.getGenericType();
      t = (Class<?>) collectionType.getActualTypeArguments()[0];
   }
   if (fields.length == 1) {
      return t;
   } else {
      return getFieldType((Class<?>) t, name.substring(name.indexOf(".") + 1));
   }
}
 
Example 3
Project: alfresco-repository   File: ImporterComponent.java   View Source Code Vote up 5 votes
/**
 * Create a valid qname-based xpath
 * 
 * Note: 
 * - the localname will be truncated to 100 chars
 * - the localname should already be encoded for ISO 9075 (in case of MT bootstrap, the @ sign will be auto-encoded, see below)
 * 
 * Some examples:
 *      /
 *      sys:people/cm:admin
 *      /app:company_home/app:dictionary
 *      ../../cm:people_x0020_folder
 *      sys:people/cm:admin_x0040_test
 *      
 * @param path String
 * @return String
 */
private String createValidPath(String path)
{
    StringBuffer validPath = new StringBuffer(path.length());
    String[] segments = StringUtils.delimitedListToStringArray(path, "/");
    for (int i = 0; i < segments.length; i++)
    {
        if (segments[i] != null && segments[i].length() > 0)
        {
            int colonIndex = segments[i].indexOf(QName.NAMESPACE_PREFIX);
            if (colonIndex == -1)
            {
                // eg. ".."
                validPath.append(segments[i]);
            }
            else
            {
                String[] qnameComponents = QName.splitPrefixedQName(segments[i]);
                
                String localName = QName.createValidLocalName(qnameComponents[1]);
                
                // MT: bootstrap of "alfrescoUserStore.xml" requires 'sys:people/cm:[email protected]' to be encoded as 'sys:people/cm:admin_x0040_tenant' (for XPath)
                localName = localName.replace("@", "_x0040_");
                
                QName segmentQName = QName.createQName(qnameComponents[0], localName, namespaceService);
                validPath.append(segmentQName.toPrefixString());
            }
        }
        if (i < (segments.length -1))
        {
            validPath.append("/");
        }
    }
    return validPath.toString();
}
 
Example 4
Project: spring-cloud-release-tools   File: ProjectBuilder.java   View Source Code Vote up 5 votes
/**
 * We need to insert the system properties as a list of -Dkey=value entries
 * instead of just pasting the String that contains these values
 */
private String[] substituteSystemProps(String... commands) {
	boolean containsSystemProps = this.properties.getMaven().getSystemProperties().contains("-D");
	String[] splitSystemProps = StringUtils.delimitedListToStringArray(this.properties.getMaven()
			.getSystemProperties(), "-D");
	// first element might be empty even though the second one contains values
	if (splitSystemProps.length > 1) {
		splitSystemProps = StringUtils.isEmpty(splitSystemProps[0]) ?
				Arrays.copyOfRange(splitSystemProps, 1, splitSystemProps.length) :
				splitSystemProps;
	}
	String[] systemPropsWithPrefix = containsSystemProps ? Arrays.stream(splitSystemProps)
			.map(s -> "-D" + s.trim())
			.collect(Collectors.toList())
			.toArray(new String[splitSystemProps.length]) : splitSystemProps;
	final AtomicInteger index = new AtomicInteger(-1);
	for (int i = 0; i < commands.length; i++) {
		if (commands[i].contains(ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER)) {
			index.set(i);
			break;
		}
	}
	List<String> commandsList = new ArrayList<>(Arrays.asList(commands));
	List<String> systemPropsList = Arrays.asList(systemPropsWithPrefix);
	if (index.get() != -1) {
		commandsList.remove(index.get());
		if (index.get() >= commandsList.size()) {
			commandsList.addAll(systemPropsList);
		} else {
			// we need to reverse to set the objects in the same order as passed in the prop
			List<String> reversedSystemProps = new ArrayList<>(systemPropsList);
			Collections.reverse(reversedSystemProps);
			reversedSystemProps.forEach(s -> commandsList.add(index.get(), s));
		}
	}
	return commandsList.toArray(new String[commandsList.size()]);
}
 
Example 5
Project: profile-manager   File: DataTablesRequestGrid.java   View Source Code Vote up 5 votes
private List<SearchField> createSearchFieldList(String aSearchNames, String aSearchValues,
      List<SearchField> addedFilters) {
   String[] values, names;
   List<SearchField> res = new ArrayList<SearchField>();
   values = StringUtils.delimitedListToStringArray(aSearchValues, SEARCH_SEPARATOR);
   names = StringUtils.delimitedListToStringArray(aSearchNames, SEARCH_SEPARATOR);
   int i = 0;
   for (String name : names) {
      String val = values[i];
      if (name.startsWith("json_")) {
         String temp = name.substring(5);
         name = temp.replace("_", ".");
      }
      if (isRangeValue(val)) {
         SearchField sfFrom = new SearchField(name);
         SearchField sfTo = new SearchField(name);
         sfFrom.setValue(getRangeValue(val, 0));
         sfFrom.setRangeType(SearchField.RangeType.RANGE_FROM);
         sfFrom.setNullType(SearchField.NullType.NO_NULL);
         sfTo.setValue(getRangeValue(val, 1));
         sfTo.setRangeType(SearchField.RangeType.RANGE_TO);
         sfTo.setNullType(SearchField.NullType.NO_NULL);
         res.add(sfFrom);
         res.add(sfTo);
      } else {
         SearchField sf = new SearchField(name);
         sf.setRangeType(SearchField.RangeType.RANGE_NONE);
         sf.setValue(val);
         sf.setNullType(SearchField.NullType.NO_NULL);
         sf.setAddPercentPrefix(true);
         res.add(sf);
      }
      i++;
   }
   res.addAll(addedFilters);
   return res;
}
 
Example 6
Project: profile-manager   File: DataTablesRequestGrid.java   View Source Code Vote up 5 votes
public void addPrefixToProtocollo(String protocoloName) {
   String[] names = StringUtils.delimitedListToStringArray(this.getaSearchNames(),
         DataTablesRequestGrid.SEARCH_SEPARATOR);
   String[] values = StringUtils.delimitedListToStringArray(this.getaSearchValues(),
         DataTablesRequestGrid.SEARCH_SEPARATOR);
   StringBuilder newNames = new StringBuilder();
   StringBuilder newValues = new StringBuilder();
   String protocolloNormValue = null;
   for (int i = 0; i < names.length; i++) {
      String name = names[i];
      if (!protocoloName.equals(name)) {
         newNames.append(name);
         newValues.append(values[i]);
         if (i < (names.length - 1)) {
            newNames.append(DataTablesRequestGrid.SEARCH_SEPARATOR);
            newValues.append(DataTablesRequestGrid.SEARCH_SEPARATOR);
         }
      } else {
         protocolloNormValue = values[i];
      }
   }

   this.setaSearchNames(newNames.toString());
   this.setaSearchValues(newValues.toString());
   SearchField sf = new SearchField(protocoloName);
   sf.setNullType(SearchField.NullType.NO_NULL);
   sf.setValue(protocolloNormValue);
   sf.setRangeType(SearchField.RangeType.RANGE_NONE);
   if (isAddPercentPrefix()) {
      sf.setAddPercentPrefix(true);
   }
   this.addFilter(sf);

}
 
Example 7
Project: profile-manager   File: ConversionUtility.java   View Source Code Vote up 5 votes
public static boolean isCollectionFieldType(Class<?> persistentClass, String name) throws NoSuchFieldException {
	String[] fields = StringUtils.delimitedListToStringArray(name, ".");
	Class<?> t;

	t = persistentClass.getDeclaredField(fields[0]).getType();
	return Collection.class.isAssignableFrom(t);
}
 
Example 8
Project: gemini.blueprint   File: ConfigUtils.java   View Source Code Vote up 5 votes
/**
 * Return the directive value as a String. If the directive does not exist
 * or is invalid (wrong format) a null string will be returned.
 * 
 * @param header
 * @param directive
 * @return
 */
public static String getDirectiveValue(String header, String directive) {
	Assert.notNull(header, "not-null header required");
	Assert.notNull(directive, "not-null directive required");
	String[] directives = StringUtils.tokenizeToStringArray(header, DIRECTIVE_SEPARATOR);

	for (int i = 0; i < directives.length; i++) {
		String[] splittedDirective = StringUtils.delimitedListToStringArray(directives[i].trim(), EQUALS);
		if (splittedDirective.length == 2 && splittedDirective[0].equals(directive))
			return splittedDirective[1];
	}

	return null;
}
 
Example 9
Project: lams   File: CronSequenceGenerator.java   View Source Code Vote up 5 votes
private int[] getRange(String field, int min, int max) {
	int[] result = new int[2];
	if (field.contains("*")) {
		result[0] = min;
		result[1] = max - 1;
		return result;
	}
	if (!field.contains("-")) {
		result[0] = result[1] = Integer.valueOf(field);
	}
	else {
		String[] split = StringUtils.delimitedListToStringArray(field, "-");
		if (split.length > 2) {
			throw new IllegalArgumentException("Range has more than two fields: '" +
					field + "' in expression \"" + this.expression + "\"");
		}
		result[0] = Integer.valueOf(split[0]);
		result[1] = Integer.valueOf(split[1]);
	}
	if (result[0] >= max || result[1] >= max) {
		throw new IllegalArgumentException("Range exceeds maximum (" + max + "): '" +
				field + "' in expression \"" + this.expression + "\"");
	}
	if (result[0] < min || result[1] < min) {
		throw new IllegalArgumentException("Range less than minimum (" + min + "): '" +
				field + "' in expression \"" + this.expression + "\"");
	}
	return result;
}
 
Example 10
Project: lams   File: StringArrayPropertyEditor.java   View Source Code Vote up 5 votes
@Override
public void setAsText(String text) throws IllegalArgumentException {
	String[] array = StringUtils.delimitedListToStringArray(text, this.separator, this.charsToDelete);
	if (trimValues) {
		array = StringUtils.trimArrayElements(array);
	}
	if (this.emptyArrayAsNull && array.length == 0) {
		setValue(null);
	}
	else {
		setValue(array);
	}
}
 
Example 11
Project: spring-grow   File: DataTablesRequest.java   View Source Code Vote up 5 votes
private List<SearchField> createSearchFieldList(String aSearchNames, String aSearchValues,
      List<SearchField> addedFilters) {
   String[] values, names;
   List<SearchField> res = new ArrayList<SearchField>();
   values = StringUtils.delimitedListToStringArray(aSearchValues, SEARCH_SEPARATOR);
   names = StringUtils.delimitedListToStringArray(aSearchNames, SEARCH_SEPARATOR);
   int i = 0;
   for (String name : names) {
      String val = values[i];
      if (name.startsWith("json_")) {
         String temp = name.substring(5);
         name = temp.replace("_", ".");
      }
      if (isRangeValue(val)) {
         SearchField sfFrom = new SearchField(name);
         SearchField sfTo = new SearchField(name);
         sfFrom.setValue(getRangeValue(val, 0));
         sfFrom.setRangeType(SearchField.RangeType.RANGE_FROM);
         sfFrom.setNullType(SearchField.NullType.NO_NULL);
         sfTo.setValue(getRangeValue(val, 1));
         sfTo.setRangeType(SearchField.RangeType.RANGE_TO);
         sfTo.setNullType(SearchField.NullType.NO_NULL);
         res.add(sfFrom);
         res.add(sfTo);
      } else {
         SearchField sf = new SearchField(name);
         sf.setRangeType(SearchField.RangeType.RANGE_NONE);
         sf.setValue(val);
         sf.setNullType(SearchField.NullType.NO_NULL);
         sf.setAddPercentPrefix(true);
         res.add(sf);
      }
      i++;
   }
   res.addAll(addedFilters);
   return res;
}
 
Example 12
Project: spring-grow   File: DataTablesRequest.java   View Source Code Vote up 5 votes
public void addPrefixToProtocollo(String protocoloName) {
   String[] names = StringUtils.delimitedListToStringArray(this.getaSearchNames(),
         DataTablesRequest.SEARCH_SEPARATOR);
   String[] values = StringUtils.delimitedListToStringArray(this.getaSearchValues(),
         DataTablesRequest.SEARCH_SEPARATOR);
   StringBuilder newNames = new StringBuilder();
   StringBuilder newValues = new StringBuilder();
   String protocolloNormValue = null;
   for (int i = 0; i < names.length; i++) {
      String name = names[i];
      if (!protocoloName.equals(name)) {
         newNames.append(name);
         newValues.append(values[i]);
         if (i < (names.length - 1)) {
            newNames.append(DataTablesRequest.SEARCH_SEPARATOR);
            newValues.append(DataTablesRequest.SEARCH_SEPARATOR);
         }
      } else {
         protocolloNormValue = values[i];
      }
   }

   this.setaSearchNames(newNames.toString());
   this.setaSearchValues(newValues.toString());
   SearchField sf = new SearchField(protocoloName);
   sf.setNullType(SearchField.NullType.NO_NULL);
   sf.setValue(protocolloNormValue);
   sf.setRangeType(SearchField.RangeType.RANGE_NONE);
   if (isAddPercentPrefix()) {
      sf.setAddPercentPrefix(true);
   }
   this.addFilter(sf);

}
 
Example 13
Project: spring-grow   File: ConversionUtility.java   View Source Code Vote up 5 votes
public static boolean isCollectionFieldType(Class<?> persistentClass, String name) throws NoSuchFieldException {
   String[] fields = StringUtils.delimitedListToStringArray(name, ".");
   Class<?> t;

   t = persistentClass.getDeclaredField(fields[0]).getType();
   return Collection.class.isAssignableFrom(t);
}
 
Example 14
Project: profile-manager   File: SearchField.java   View Source Code Vote up 4 votes
public String getAlias() {        
    String[] temp = StringUtils.delimitedListToStringArray(name, ".");
    return ALIAS_PREFIX.concat(temp[0]);        
}
 
Example 15
Project: profile-manager   File: SearchField.java   View Source Code Vote up 4 votes
public String getNameRoot() {
    return  StringUtils.delimitedListToStringArray(name, ".")[0];        
}
 
Example 16
Project: spring-grow   File: SearchField.java   View Source Code Vote up 4 votes
public String getAlias() {        
    String[] temp = StringUtils.delimitedListToStringArray(name, ".");
    return ALIAS_PREFIX.concat(temp[0]);        
}
 
Example 17
Project: spring-grow   File: SearchField.java   View Source Code Vote up 4 votes
public String getNameRoot() {
    return  StringUtils.delimitedListToStringArray(name, ".")[0];        
}