You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
2.9 KiB
Java
153 lines
2.9 KiB
Java
package info.bukova.isspst;
|
|
|
|
import java.util.List;
|
|
|
|
import org.zkoss.util.resource.Labels;
|
|
|
|
public class StringUtils
|
|
{
|
|
|
|
private static String nullStr(String str)
|
|
{
|
|
return str == null ? "" : str;
|
|
}
|
|
|
|
private static String not0ToStr(long i)
|
|
{
|
|
return i == 0 ? "" : String.valueOf(i);
|
|
}
|
|
|
|
public static String localizeDbErr(String sqlError)
|
|
{
|
|
String splitMessage[] = sqlError.split("'");
|
|
String message = "";
|
|
|
|
for (int i = 0; i < splitMessage.length; i++)
|
|
{
|
|
if (i % 2 == 0)
|
|
{
|
|
message += getLocalized(splitMessage[i]);
|
|
}
|
|
else
|
|
{
|
|
message += " '" + splitMessage[i] + "' ";
|
|
}
|
|
}
|
|
|
|
return message;
|
|
}
|
|
|
|
public static String localize(String key)
|
|
{
|
|
return Labels.getLabel(key) == null ? key : Labels.getLabel(key);
|
|
}
|
|
|
|
private static String getLocalized(String str)
|
|
{
|
|
String words[] = str.split(" ");
|
|
String key = "";
|
|
|
|
for (String word : words)
|
|
{
|
|
if (!word.isEmpty())
|
|
{
|
|
key += word.substring(0, 1).toUpperCase() + word.substring(1);
|
|
}
|
|
}
|
|
|
|
return Labels.getLabel("Db" + key);
|
|
}
|
|
|
|
public static boolean isEqualForFilter(String value, String search)
|
|
{
|
|
value = StringUtils.nullStr(value).toLowerCase();
|
|
search = StringUtils.nullStr(search).toLowerCase();
|
|
|
|
if (search.isEmpty())
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return value.startsWith(search);
|
|
}
|
|
|
|
public static boolean isIcEqualForFilter(long value, long search)
|
|
{
|
|
String compareValue = StringUtils.not0ToStr(value);
|
|
String searchValue = StringUtils.not0ToStr(search);
|
|
return compareValue.startsWith(searchValue);
|
|
}
|
|
|
|
public static String encodeSpecialChars(String value)
|
|
{
|
|
if (value != null)
|
|
{
|
|
value = value.replace("²", "[up]2[/up]");
|
|
value = value.replace("³", "[up]3[/up]");
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
public static String decodeSpecialChars(String value)
|
|
{
|
|
if (value != null)
|
|
{
|
|
value = value.replace("[up]2[/up]", "²");
|
|
value = value.replace("[up]3[/up]", "³");
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
public static String addSeparator(String value, String separator, boolean toTail)
|
|
{
|
|
if ((value != null) && (separator != null))
|
|
{
|
|
if (!value.isEmpty() && !separator.isEmpty())
|
|
{
|
|
value = (toTail ? value + separator : separator + value);
|
|
}
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
public static String addSeparator(String value, String separator)
|
|
{
|
|
return StringUtils.addSeparator(value, separator, true);
|
|
}
|
|
|
|
public static String join(List<String> list, String separator)
|
|
{
|
|
String result = "";
|
|
|
|
for (int i = 0; i < list.size(); i++)
|
|
{
|
|
String item = StringUtils.nullStr(list.get(i));
|
|
result = StringUtils.addSeparator(result, separator);
|
|
result += item;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static String joinNotEmpty(List<String> list, String separator)
|
|
{
|
|
String result = "";
|
|
|
|
for (int i = 0; i < list.size(); i++)
|
|
{
|
|
String item = StringUtils.nullStr(list.get(i));
|
|
|
|
if (!item.isEmpty())
|
|
{
|
|
result = StringUtils.addSeparator(result, separator);
|
|
result += item;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|