本文整理汇总了Java中org.springframework.util.StringUtils.replace方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.replace方法的具体用法?Java StringUtils.replace怎么用?Java StringUtils.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.StringUtils
的用法示例。
在下文中一共展示了StringUtils.replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bindPlaceHolder
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* 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;
}
示例2: doLoadClass
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
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);
}
}
示例3: getLabel
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* 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);
}
示例4: constructUrl
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
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;
}
示例5: parseLocaleCookieIfNecessary
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
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)));
}
}
示例6: parseLocaleCookieIfNecessary
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
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));
}
}
示例7: generateUsersComments
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
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);
}
}
示例8: applyTransformers
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
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);
}
}
示例9: replaceOrdinals
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* 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;
}
示例10: replaceBooleanOperators
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* If a type pattern has been specified in XML, the user cannot
* write {@code and} as "&&" (though && 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;
}
示例11: replaceBooleanOperators
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* If a pointcut expression has been specified in XML, the user cannot
* write {@code and} as "&&" (though && 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;
}
示例12: toURI
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
public static URI toURI(String location)
throws URISyntaxException {
return new URI(StringUtils.replace(location, " ", "%20"));
}
示例13: generateJson
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* 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();
}
示例14: getDisplayLabel
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* 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;
}
示例15: updatePrefixSuffix
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
private String updatePrefixSuffix(String base) {
String updatedPrefix = StringUtils.replace(base, "%PREFIX%", tablePrefix);
return StringUtils.replace(updatedPrefix, "%SUFFIX%", tableSuffix);
}