com.opensymphony.xwork2.util.logging.LoggerUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xwork Show documentation
Show all versions of xwork Show documentation
XWork is an command-pattern framework that is used to power WebWork
as well as other applications. XWork provides an Inversion of Control
container, a powerful expression language, data type conversion,
validation, and pluggable configuration.
/*
* Copyright (c) 2002-2006 by OpenSymphony
* All rights reserved.
*/
package com.opensymphony.xwork2.util.logging;
/**
* Logging utility methods
*/
public class LoggerUtils {
/**
* Formats messages using parameters. For example, the call:
*
*
* format("foo #1", "bob");
*
*
* will return:
*
* foo bob
*
*
* @param msg The message
* @param args A list of arguments. A maximum of 10 are supported.
* @return The formatted string
*/
public static String format(String msg, String... args) {
if (msg != null && msg.length() > 0 && msg.indexOf('#') > -1) {
StringBuilder sb = new StringBuilder();
boolean isArg = false;
for (int x = 0; x < msg.length(); x++) {
char c = msg.charAt(x);
if (isArg) {
isArg = false;
if (Character.isDigit(c)) {
int val = Character.getNumericValue(c);
if (val >= 0 && val < args.length) {
sb.append(args[val]);
continue;
}
}
sb.append('#');
}
if (c == '#') {
isArg = true;
continue;
}
sb.append(c);
}
if (isArg) {
sb.append('#');
}
return sb.toString();
}
return msg;
}
}