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

The following are Jave code examples for showing how to use replace() 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: alfresco-repository   File: ImporterComponent.java   View Source Code Vote up 6 votes
/**
 * Bind the specified value to the passed configuration values if it is a place holder
 * 
 * @param value  the value to bind
 * @param binding  the configuration properties to bind to
 * @return  the bound value
 */
private String bindPlaceHolder(String value, ImporterBinding binding)
{
    if (binding != null)
    {
        int iStartBinding = value.indexOf(START_BINDING_MARKER);
        while (iStartBinding != -1)
        {
            int iEndBinding = value.indexOf(END_BINDING_MARKER, iStartBinding + START_BINDING_MARKER.length());
            if (iEndBinding == -1)
            {
                throw new ImporterException("Cannot find end marker " + END_BINDING_MARKER + " within value " + value);
            }
            
            String key = value.substring(iStartBinding + START_BINDING_MARKER.length(), iEndBinding);
            String keyValue = binding.getValue(key);
            if (keyValue == null) {
                logger.warn("No binding value for placeholder (will default to empty string): " + value);
            }
            value = StringUtils.replace(value, START_BINDING_MARKER + key + END_BINDING_MARKER, keyValue == null ? "" : keyValue);
            iStartBinding = value.indexOf(START_BINDING_MARKER);
        }
    }
    return value;
}
 
Example 2
Project: lams   File: ShadowingClassLoader.java   View Source Code Vote up 6 votes
private Class<?> doLoadClass(String name) throws ClassNotFoundException {
	String internalName = StringUtils.replace(name, ".", "/") + ".class";
	InputStream is = this.enclosingClassLoader.getResourceAsStream(internalName);
	if (is == null) {
		throw new ClassNotFoundException(name);
	}
	try {
		byte[] bytes = FileCopyUtils.copyToByteArray(is);
		bytes = applyTransformers(name, bytes);
		Class<?> cls = defineClass(name, bytes, 0, bytes.length);
		// Additional check for defining the package, if not defined yet.
		if (cls.getPackage() == null) {
			int packageSeparator = name.lastIndexOf('.');
			if (packageSeparator != -1) {
				String packageName = name.substring(0, packageSeparator);
				definePackage(packageName, null, null, null, null, null, null, null);
			}
		}
		this.classCache.put(name, cls);
		return cls;
	}
	catch (IOException ex) {
		throw new ClassNotFoundException("Cannot load resource for class [" + name + "]", ex);
	}
}
 
Example 3
Project: alfresco-data-model   File: M2Label.java   View Source Code Vote up 6 votes
/**
 * Get label for data dictionary item given specified locale
 * 
 * @param locale Locale
 * @param model ModelDefinition
 * @param messageLookup MessageLookup
 * @param type String
 * @param item QName
 * @param label String
 * @return String
 */
public static String getLabel(Locale locale, ModelDefinition model, MessageLookup messageLookup, String type, QName item, String label)
{
    if (messageLookup == null)
    {
        return null;
    }
    String key = model.getName().toPrefixString();
    if (type != null)
    {
        key += "." + type;
    }
    if (item != null)
    {
        key += "." + item.toPrefixString();
    }
    key += "." + label;
    key = StringUtils.replace(key, ":", "_");
    return messageLookup.getMessage(key, locale);
}
 
Example 4
Project: spring-cloud-skipper   File: AboutController.java   View Source Code Vote up 5 votes
private String constructUrl(String url, String version) {
	final String VERSION_TAG = "{version}";
	final String REPOSITORY_TAG = "{repository}";
	if (url.contains(VERSION_TAG)) {
		url = StringUtils.replace(url, VERSION_TAG, version);
		url = StringUtils.replace(url, REPOSITORY_TAG, repoSelector(version));
	}
	return url;
}
 
Example 5
Project: buenojo   File: AngularCookieLocaleResolver.java   View Source Code Vote up 5 votes
private void parseLocaleCookieIfNecessary(HttpServletRequest request) {
    if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) {
        // Retrieve and parse cookie value.
        Cookie cookie = WebUtils.getCookie(request, getCookieName());
        Locale locale = null;
        TimeZone timeZone = null;
        if (cookie != null) {
            String value = cookie.getValue();

            // Remove the double quote
            value = StringUtils.replace(value, "%22", "");

            String localePart = value;
            String timeZonePart = null;
            int spaceIndex = localePart.indexOf(' ');
            if (spaceIndex != -1) {
                localePart = value.substring(0, spaceIndex);
                timeZonePart = value.substring(spaceIndex + 1);
            }
            locale = (!"-".equals(localePart) ? StringUtils.parseLocaleString(localePart.replace('-', '_')) : null);
            if (timeZonePart != null) {
                timeZone = StringUtils.parseTimeZoneString(timeZonePart);
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale +
                    "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
            }
        }
        request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
            (locale != null ? locale: determineDefaultLocale(request)));

        request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
            (timeZone != null ? timeZone : determineDefaultTimeZone(request)));
    }
}
 
Example 6
Project: sentry   File: AngularCookieLocaleResolver.java   View Source Code Vote up 5 votes
private void parseLocaleCookieIfNecessary(HttpServletRequest request) {
    if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) {
        // Retrieve and parse cookie value.
        Cookie cookie = WebUtils.getCookie(request, getCookieName());
        Locale locale = null;
        TimeZone timeZone = null;
        if (cookie != null) {
            String value = cookie.getValue();

            // Remove the double quote
            value = StringUtils.replace(value, "%22", "");

            String localePart = value;
            String timeZonePart = null;
            int spaceIndex = localePart.indexOf(' ');
            if (spaceIndex != -1) {
                localePart = value.substring(0, spaceIndex);
                timeZonePart = value.substring(spaceIndex + 1);
            }
            locale = !"-".equals(localePart) ? StringUtils.parseLocaleString(localePart.replace('-', '_')) : null;
            if (timeZonePart != null) {
                timeZone = StringUtils.parseTimeZoneString(timeZonePart);
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale +
                    "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
            }
        }
        request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
            locale != null ? locale: determineDefaultLocale(request));

        request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
            timeZone != null ? timeZone : determineDefaultTimeZone(request));
    }
}
 
Example 7
Project: lams   File: SpreadsheetBuilder.java   View Source Code Vote up 5 votes
private void generateUsersComments(PeerreviewSession session, List<ExcelCell[]> rowList,
    Map<Long, String> userNames, RatingCriteria criteria, PeerreviewUser user, boolean showForName) {

List<ExcelCell[]> commentRowList = new LinkedList<ExcelCell[]>();
List<Object[]> comments = peerreviewUserDao.getDetailedRatingsComments(session.getPeerreview().getContentId(),
	session.getSessionId(), criteria.getRatingCriteriaId(), user.getUserId());
for (Object[] comment : comments) {
    if (comment[1] != null) {
	ExcelCell[] commentRow = new ExcelCell[2];
	commentRow[0] = new ExcelCell(userNames.get(((BigInteger) comment[0]).longValue()), false);
	commentRow[1] = new ExcelCell(StringUtils.replace((String) comment[1], "<BR>", "\n"), false);
	commentRowList.add(commentRow);
    }
}

if (commentRowList.size() > 0) {

    rowList.add(EMPTY_ROW);

    if (showForName) {
	ExcelCell[] userRow = new ExcelCell[1];
	userRow[0] = new ExcelCell(service.getLocalisedMessage("label.for.user",
		new Object[] { userNames.get(user.getUserId()) }), false);
	rowList.add(userRow);
    }

    rowList.addAll(commentRowList);
}

   }
 
Example 8
Project: lams   File: ShadowingClassLoader.java   View Source Code Vote up 5 votes
private byte[] applyTransformers(String name, byte[] bytes) {
	String internalName = StringUtils.replace(name, ".", "/");
	try {
		for (ClassFileTransformer transformer : this.classFileTransformers) {
			byte[] transformed = transformer.transform(this, internalName, null, null, bytes);
			bytes = (transformed != null ? transformed : bytes);
		}
		return bytes;
	}
	catch (IllegalClassFormatException ex) {
		throw new IllegalStateException(ex);
	}
}
 
Example 9
Project: lams   File: CronSequenceGenerator.java   View Source Code Vote up 5 votes
/**
 * Replace the values in the commaSeparatedList (case insensitive) with
 * their index in the list.
 * @return a new string with the values from the list replaced
 */
private String replaceOrdinals(String value, String commaSeparatedList) {
	String[] list = StringUtils.commaDelimitedListToStringArray(commaSeparatedList);
	for (int i = 0; i < list.length; i++) {
		String item = list[i].toUpperCase();
		value = StringUtils.replace(value.toUpperCase(), item, "" + i);
	}
	return value;
}
 
Example 10
Project: lams   File: TypePatternClassFilter.java   View Source Code Vote up 5 votes
/**
 * If a type pattern has been specified in XML, the user cannot
 * write {@code and} as "&&" (though &amp;&amp; will work).
 * We also allow {@code and} between two sub-expressions.
 * <p>This method converts back to {@code &&} for the AspectJ pointcut parser.
 */
private String replaceBooleanOperators(String pcExpr) {
	pcExpr = StringUtils.replace(pcExpr," and "," && ");
	pcExpr = StringUtils.replace(pcExpr, " or ", " || ");
	pcExpr = StringUtils.replace(pcExpr, " not ", " ! ");
	return pcExpr;
}
 
Example 11
Project: lams   File: AspectJExpressionPointcut.java   View Source Code Vote up 5 votes
/**
 * If a pointcut expression has been specified in XML, the user cannot
 * write {@code and} as "&&" (though &amp;&amp; will work).
 * We also allow {@code and} between two pointcut sub-expressions.
 * <p>This method converts back to {@code &&} for the AspectJ pointcut parser.
 */
private String replaceBooleanOperators(String pcExpr) {
	String result = StringUtils.replace(pcExpr, " and ", " && ");
	result = StringUtils.replace(result, " or ", " || ");
	result = StringUtils.replace(result, " not ", " ! ");
	return result;
}
 
Example 12
Project: shoucang   File: AngularCookieLocaleResolver.java   View Source Code Vote up 5 votes
private void parseLocaleCookieIfNecessary(HttpServletRequest request) {
    if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) {
        // Retrieve and parse cookie value.
        Cookie cookie = WebUtils.getCookie(request, getCookieName());
        Locale locale = null;
        TimeZone timeZone = null;
        if (cookie != null) {
            String value = cookie.getValue();

            // Remove the double quote
            value = StringUtils.replace(value, "%22", "");

            String localePart = value;
            String timeZonePart = null;
            int spaceIndex = localePart.indexOf(' ');
            if (spaceIndex != -1) {
                localePart = value.substring(0, spaceIndex);
                timeZonePart = value.substring(spaceIndex + 1);
            }
            locale = (!"-".equals(localePart) ? StringUtils.parseLocaleString(localePart.replace('-', '_')) : null);
            if (timeZonePart != null) {
                timeZone = StringUtils.parseTimeZoneString(timeZonePart);
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale +
                    "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
            }
        }
        request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
            (locale != null ? locale: determineDefaultLocale(request)));

        request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
            (timeZone != null ? timeZone : determineDefaultTimeZone(request)));
    }
}
 
Example 13
Project: klask-io   File: AngularCookieLocaleResolver.java   View Source Code Vote up 5 votes
private void parseLocaleCookieIfNecessary(HttpServletRequest request) {
    if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) {
        // Retrieve and parse cookie value.
        Cookie cookie = WebUtils.getCookie(request, getCookieName());
        Locale locale = null;
        TimeZone timeZone = null;
        if (cookie != null) {
            String value = cookie.getValue();

            // Remove the double quote
            value = StringUtils.replace(value, "%22", "");

            String localePart = value;
            String timeZonePart = null;
            int spaceIndex = localePart.indexOf(' ');
            if (spaceIndex != -1) {
                localePart = value.substring(0, spaceIndex);
                timeZonePart = value.substring(spaceIndex + 1);
            }
            locale = (!"-".equals(localePart) ? StringUtils.parseLocaleString(localePart.replace('-', '_')) : null);
            if (timeZonePart != null) {
                timeZone = StringUtils.parseTimeZoneString(timeZonePart);
            }
            if (logger.isTraceEnabled()) {
                logger.trace("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale +
                    "'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
            }
        }
        request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
            (locale != null ? locale: determineDefaultLocale(request)));

        request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
            (timeZone != null ? timeZone : determineDefaultTimeZone(request)));
    }
}
 
Example 14
Project: tasfe-framework   File: ResourcesUtil.java   View Source Code Vote up 4 votes
public static URI toURI(String location)
        throws URISyntaxException {
    return new URI(StringUtils.replace(location, " ", "%20"));
}
 
Example 15
Project: lams   File: LiveBeansView.java   View Source Code Vote up 4 votes
/**
 * Actually generate a JSON snapshot of the beans in the given ApplicationContexts.
 * <p>This implementation doesn't use any JSON parsing libraries in order to avoid
 * third-party library dependencies. It produces an array of context description
 * objects, each containing a context and parent attribute as well as a beans
 * attribute with nested bean description objects. Each bean object contains a
 * bean, scope, type and resource attribute, as well as a dependencies attribute
 * with a nested array of bean names that the present bean depends on.
 * @param contexts the set of ApplicationContexts
 * @return the JSON document
 */
protected String generateJson(Set<ConfigurableApplicationContext> contexts) {
	StringBuilder result = new StringBuilder("[\n");
	for (Iterator<ConfigurableApplicationContext> it = contexts.iterator(); it.hasNext();) {
		ConfigurableApplicationContext context = it.next();
		result.append("{\n\"context\": \"").append(context.getId()).append("\",\n");
		if (context.getParent() != null) {
			result.append("\"parent\": \"").append(context.getParent().getId()).append("\",\n");
		}
		else {
			result.append("\"parent\": null,\n");
		}
		result.append("\"beans\": [\n");
		ConfigurableListableBeanFactory bf = context.getBeanFactory();
		String[] beanNames = bf.getBeanDefinitionNames();
		boolean elementAppended = false;
		for (String beanName : beanNames) {
			BeanDefinition bd = bf.getBeanDefinition(beanName);
			if (isBeanEligible(beanName, bd, bf)) {
				if (elementAppended) {
					result.append(",\n");
				}
				result.append("{\n\"bean\": \"").append(beanName).append("\",\n");
				String scope = bd.getScope();
				if (!StringUtils.hasText(scope)) {
					scope = BeanDefinition.SCOPE_SINGLETON;
				}
				result.append("\"scope\": \"").append(scope).append("\",\n");
				Class<?> beanType = bf.getType(beanName);
				if (beanType != null) {
					result.append("\"type\": \"").append(beanType.getName()).append("\",\n");
				}
				else {
					result.append("\"type\": null,\n");
				}
				String resource = StringUtils.replace(bd.getResourceDescription(), "\\", "/");
				result.append("\"resource\": \"").append(resource).append("\",\n");
				result.append("\"dependencies\": [");
				String[] dependencies = bf.getDependenciesForBean(beanName);
				if (dependencies.length > 0) {
					result.append("\"");
				}
				result.append(StringUtils.arrayToDelimitedString(dependencies, "\", \""));
				if (dependencies.length > 0) {
					result.append("\"");
				}
				result.append("]\n}");
				elementAppended = true;
			}
		}
		result.append("]\n");
		result.append("}");
		if (it.hasNext()) {
			result.append(",\n");
		}
	}
	result.append("]");
	return result.toString();
}
 
Example 16
Project: alfresco-data-model   File: ListOfValuesConstraint.java   View Source Code Vote up 4 votes
/**
 * Get the display label for the specified allowable value in this constraint.
 * A key is constructed as follows:
 * <pre>
 *   "listconstraint." + constraintName + "." + constraintAllowableValue.
 *   e.g. listconstraint.test_listConstraintOne.VALUE_ONE.
 * </pre>
 * This key is then used to look up a properties bundle for the localised display label.
 * Spaces are allowed in the keys, but they should be escaped in the properties file as follows:
 * <pre>
 * listconstraint.test_listConstraintOne.VALUE\ WITH\ SPACES=Display label
 * </pre>
 * 
 * @param constraintAllowableValue String
 * @param messageLookup MessageLookup
 * @return the localised display label for the specified constraint value in the current locale.
 *         If no localisation is defined, it will return the allowed value itself.
 *         If the specified allowable value is not in the model, returns <code>null</code>.
 * @since 4.0
 * @see I18NUtil#getLocale()
 */
public String getDisplayLabel(String constraintAllowableValue, MessageLookup messageLookup)
{
    if (!allowedValues.contains(constraintAllowableValue))
    {
        return null;
    }
    
    String key = LOV_CONSTRAINT_VALUE;
    key += "." + this.getShortName();
    key += "." + constraintAllowableValue;
    key = StringUtils.replace(key, ":", "_");
    
    String message = messageLookup.getMessage(key, I18NUtil.getLocale());
    return message == null ? constraintAllowableValue : message;
}
 
Example 17
Project: spring-cloud-dashboard   File: AbstractRdbmsKeyValueRepository.java   View Source Code Vote up 4 votes
private String updatePrefixSuffix(String base) {
	String updatedPrefix = StringUtils.replace(base, "%PREFIX%", tablePrefix);
	return StringUtils.replace(updatedPrefix, "%SUFFIX%", tableSuffix);
}
 
Example 18
Project: profile-manager   File: SearchField.java   View Source Code Vote up 2 votes
public String getNameAlias() {        
    return StringUtils.replace(name, StringUtils.delimitedListToStringArray(name, ".")[0], getAlias());
    
}
 
Example 19
Project: spring-grow   File: SearchField.java   View Source Code Vote up 2 votes
public String getNameAlias() {        
    return StringUtils.replace(name, StringUtils.delimitedListToStringArray(name, ".")[0], getAlias());
    
}