Package org.apache.ofbiz.base.util
Class UtilFormatOut
java.lang.Object
org.apache.ofbiz.base.util.UtilFormatOut
General output formatting functions - mainly for helping in JSPs
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
checkEmpty
(String string1, String string2) Returns the first passed String if not empty, otherwise the second if not empty, otherwise an empty but non-null String.static String
checkEmpty
(String string1, String string2, String string3) Returns the first passed String if not empty, otherwise the second if not empty, otherwise the third if not empty, otherwise an empty but non-null String.static String
Checks to see if the passed string is null, if it is returns an empty but non-null string.static String
Returns the first passed String if not null, otherwise the second if not null, otherwise an empty but non-null String.static String
Returns the first passed String if not null, otherwise the second if not null, otherwise the third if not null, otherwise an empty but non-null String.static String
Returns the first passed String if not null, otherwise the second if not null, otherwise the third if not null, otherwise the fourth if not null, otherwise an empty but non-null String.static String
decodeQueryValue
(String query) Decodes a single query value from an HTTP URL parameter, replacing %ASCII values with charactersstatic String
encodeQuery
(String query) Encodes an HTTP URL query String, replacing characters used for other things in HTTP URL query strings, but not touching the separator characters '?', '=', and '&'static String
encodeQueryValue
(String query) Encodes a single HTTP URL query value, replacing characters used for other things in HTTP URL query stringsstatic String
encodeXmlValue
(String inString) Encodes an XML string replacing the characters '<', '>', '"', ''', '&'static String
formatAmount
(double amount, Locale locale) Formats a double into a properly formatted string, with two decimals, based on Localestatic String
formatCurrency
(double price, String isoCode, Locale locale, int maximumFractionDigits) Formats a double into a properly formatted currency string based on isoCode and Localestatic String
formatCurrency
(BigDecimal price, String isoCode, Locale locale) Formats a BigDecimal into a properly formatted currency string based on isoCode and Localestatic String
formatCurrency
(BigDecimal price, String isoCode, Locale locale, int maximumFractionDigits) Formats a double into a properly formatted currency string based on isoCode and Localestatic String
formatDate
(Timestamp timestamp) Formats aTimestamp
into a date-timeString
using the default locale and time zone.static String
formatDate
(Date date, String dateTimeFormat, Locale locale, TimeZone timeZone) Formats aDate
into a date-onlyString
using the specified locale and time zone, or using the specified format.static String
formatDateTime
(Date date, String dateTimeFormat, Locale locale, TimeZone timeZone) Formats aDate
into a date-timeString
using the specified locale and time zone, or using the specified format.static String
formatDecimalNumber
(double number, String pattern, Locale locale) Format a decimal number to the pattern givenstatic String
formatNumber
(Double number, String formatType, Delegator delegator, Locale locale) Format a number with format type define by propertiesstatic String
formatNumber
(BigDecimal number, String formatType, Delegator delegator, Locale locale) static String
formatPaddedNumber
(long number, int numericPadding) static String
formatPaddingRemove
(String original) static String
formatPercentage
(Double percentage) Formats a Double representing a percentage into a stringstatic String
formatPercentage
(BigDecimal percentage) Formats a BigDecimal representing a percentage into a stringstatic String
formatPercentageRate
(BigDecimal percentage, boolean negate) Formats a BigDecimal value 1:1 into a percentage string (e.g.static String
formatPrice
(Double price) Deprecated.static String
formatPrice
(BigDecimal price) Deprecated.static String
formatPrintableCreditCard
(String original) static String
formatQuantity
(Double quantity) Formats an Double representing a quantity into a stringstatic String
formatQuantity
(Float quantity) Formats a Float representing a quantity into a stringstatic String
formatQuantity
(Integer quantity) Formats an Integer representing a quantity into a stringstatic String
formatQuantity
(Long quantity) Formats an Long representing a quantity into a stringstatic String
formatQuantity
(BigDecimal quantity) Formats an BigDecimal representing a quantity into a stringstatic String
formatSpelledOutAmount
(Double amount, Locale locale) Formats a Double into a properly spelled out number string based on Localestatic String
ifNotEmpty
(String base, String pre, String post) Returnspre + base + post
if base String is not null or empty, otherwise an empty but non-null String.static String
makeSqlSafe
(String unsafeString) static String
makeString
(Object obj1) Checks to see if the passed Object is null, if it is returns an empty but non-null string, otherwise calls toString() on the objectstatic String
static String
replaceString
(String mainString, String oldString, String newString) Replaces all occurrences of oldString in mainString with newString
-
Field Details
-
DEFAULT_FORMAT
- See Also:
-
AMOUNT_FORMAT
- See Also:
-
QUANTITY_FORMAT
- See Also:
-
PERCENTAGE_FORMAT
- See Also:
-
SPELLED_OUT_FORMAT
- See Also:
-
-
Method Details
-
formatNumber
public static String formatNumber(Double number, String formatType, Delegator delegator, Locale locale) Format a number with format type define by properties -
formatNumber
public static String formatNumber(BigDecimal number, String formatType, Delegator delegator, Locale locale) -
formatPrice
Deprecated.Formats a Double representing a price into a string- Parameters:
price
- The price Double to be formatted- Returns:
- A String with the formatted price
-
formatPrice
Deprecated.Formats a BigDecimal representing a price into a string- Parameters:
price
- The price BigDecimal to be formatted- Returns:
- A String with the formatted price
-
formatCurrency
public static String formatCurrency(double price, String isoCode, Locale locale, int maximumFractionDigits) Formats a double into a properly formatted currency string based on isoCode and Locale- Parameters:
price
- The price double to be formattedisoCode
- the currency ISO codelocale
- The Locale used to format the numbermaximumFractionDigits
- The maximum number of fraction digits used; if set to -1 than the default value for the locale- Returns:
- A String with the formatted price
-
formatCurrency
public static String formatCurrency(BigDecimal price, String isoCode, Locale locale, int maximumFractionDigits) Formats a double into a properly formatted currency string based on isoCode and Locale- Parameters:
price
- The price BigDecimal to be formattedisoCode
- the currency ISO codelocale
- The Locale used to format the numbermaximumFractionDigits
- The maximum number of fraction digits used; if set to -1 than the default value for the locale is used- Returns:
- A String with the formatted price
-
formatDecimalNumber
Format a decimal number to the pattern given- Parameters:
number
- The price double to be formattedpattern
- pattern apply to format numberlocale
- The Locale used to format the number- Returns:
- A String with the formatted price
-
formatCurrency
Formats a BigDecimal into a properly formatted currency string based on isoCode and Locale- Parameters:
price
- The price BigDecimal to be formattedisoCode
- the currency ISO codelocale
- The Locale used to format the number- Returns:
- A String with the formatted price
-
formatSpelledOutAmount
Formats a Double into a properly spelled out number string based on Locale- Parameters:
amount
- The amount Double to be formattedlocale
- The Locale used to format the number- Returns:
- A String with the formatted number
-
formatAmount
Formats a double into a properly formatted string, with two decimals, based on Locale- Parameters:
amount
- The amount double to be formattedlocale
- The Locale used to format the number- Returns:
- A String with the formatted amount
-
formatPercentage
Formats a Double representing a percentage into a string- Parameters:
percentage
- The percentage Double to be formatted- Returns:
- A String with the formatted percentage
-
formatPercentage
Formats a BigDecimal representing a percentage into a string- Parameters:
percentage
- The percentage Decimal to be formatted- Returns:
- A String with the formatted percentage
-
formatPercentageRate
Formats a BigDecimal value 1:1 into a percentage string (e.g. 10 to 10% instead of 0,1 to 10%)- Parameters:
percentage
- The percentage Decimal to be formatted- Returns:
- A String with the formatted percentage
-
formatQuantity
Formats an Long representing a quantity into a string- Parameters:
quantity
- The quantity Long to be formatted- Returns:
- A String with the formatted quantity
-
formatQuantity
Formats an Integer representing a quantity into a string- Parameters:
quantity
- The quantity Integer to be formatted- Returns:
- A String with the formatted quantity
-
formatQuantity
Formats a Float representing a quantity into a string- Parameters:
quantity
- The quantity Float to be formatted- Returns:
- A String with the formatted quantity
-
formatQuantity
Formats an Double representing a quantity into a string- Parameters:
quantity
- The quantity Double to be formatted- Returns:
- A String with the formatted quantity
-
formatQuantity
Formats an BigDecimal representing a quantity into a string- Parameters:
quantity
- The quantity BigDecimal to be formatted- Returns:
- A String with the formatted quantity
-
formatPaddedNumber
-
formatPaddingRemove
-
formatDate
Formats aTimestamp
into a date-timeString
using the default locale and time zone. Returns an emptyString
iftimestamp
isnull
.- Parameters:
timestamp
- TheTimestamp
to format- Returns:
- A
String
with the formatted date/time, or an emptyString
iftimestamp
isnull
-
formatDate
Formats aDate
into a date-onlyString
using the specified locale and time zone, or using the specified format.- Parameters:
date
- The date to formatdateTimeFormat
- Optional format stringlocale
- The format locale - can benull
ifdateFormat
is notnull
timeZone
- The format time zone- Returns:
date
formatted as a date-onlyString
- Throws:
NullPointerException
- if any required parameter isnull
-
formatDateTime
public static String formatDateTime(Date date, String dateTimeFormat, Locale locale, TimeZone timeZone) Formats aDate
into a date-timeString
using the specified locale and time zone, or using the specified format.- Parameters:
date
- The date to formatdateTimeFormat
- Optional format stringlocale
- The format locale - can benull
ifdateFormat
is notnull
timeZone
- The format time zone- Returns:
date
formatted as a date-timeString
- Throws:
NullPointerException
- if any required parameter isnull
-
makeString
Checks to see if the passed Object is null, if it is returns an empty but non-null string, otherwise calls toString() on the object- Parameters:
obj1
- The passed Object- Returns:
- The toString() of the passed Object if not null, otherwise an empty non-null String
-
checkNull
Checks to see if the passed string is null, if it is returns an empty but non-null string.- Parameters:
string1
- The passed String- Returns:
- The passed String if not null, otherwise an empty non-null String
-
checkNull
Returns the first passed String if not null, otherwise the second if not null, otherwise an empty but non-null String.- Parameters:
string1
- The first passed Stringstring2
- The second passed String- Returns:
- The first passed String if not null, otherwise the second if not null, otherwise an empty but non-null String
-
checkNull
Returns the first passed String if not null, otherwise the second if not null, otherwise the third if not null, otherwise an empty but non-null String.- Parameters:
string1
- The first passed Stringstring2
- The second passed Stringstring3
- The third passed String- Returns:
- The first passed String if not null, otherwise the second if not null, otherwise the third if not null, otherwise an empty but non-null String
-
checkNull
Returns the first passed String if not null, otherwise the second if not null, otherwise the third if not null, otherwise the fourth if not null, otherwise an empty but non-null String.- Parameters:
string1
- The first passed Stringstring2
- The second passed Stringstring3
- The third passed Stringstring4
- The fourth passed String- Returns:
- The first passed String if not null, otherwise the second if not null, otherwise the third if not null, otherwise the fourth if not null, otherwise an empty but non-null String
-
ifNotEmpty
Returnspre + base + post
if base String is not null or empty, otherwise an empty but non-null String.- Parameters:
base
- The base Stringpre
- The pre Stringpost
- The post String- Returns:
pre + base + post
if base String is not null or empty, otherwise an empty but non-null String.
-
checkEmpty
Returns the first passed String if not empty, otherwise the second if not empty, otherwise an empty but non-null String.- Parameters:
string1
- The first passed Stringstring2
- The second passed String- Returns:
- The first passed String if not empty, otherwise the second if not empty, otherwise an empty but non-null String
-
checkEmpty
Returns the first passed String if not empty, otherwise the second if not empty, otherwise the third if not empty, otherwise an empty but non-null String.- Parameters:
string1
- The first passed Stringstring2
- The second passed Stringstring3
- The third passed String- Returns:
- The first passed String if not empty, otherwise the second if not empty, otherwise the third if not empty, otherwise an empty but non-null String
-
encodeQuery
Encodes an HTTP URL query String, replacing characters used for other things in HTTP URL query strings, but not touching the separator characters '?', '=', and '&'- Parameters:
query
- The plain query String- Returns:
- The encoded String
-
encodeQueryValue
Encodes a single HTTP URL query value, replacing characters used for other things in HTTP URL query strings- Parameters:
query
- The plain query value String- Returns:
- The encoded String
-
replaceString
Replaces all occurrences of oldString in mainString with newString- Parameters:
mainString
- The original stringoldString
- The string to replacenewString
- The string to insert in place of the old- Returns:
- mainString with all occurrences of oldString replaced by newString
-
decodeQueryValue
Decodes a single query value from an HTTP URL parameter, replacing %ASCII values with characters- Parameters:
query
- The encoded query value String- Returns:
- The plain, decoded String
-
encodeXmlValue
Encodes an XML string replacing the characters '<', '>', '"', ''', '&'- Parameters:
inString
- The plain value String- Returns:
- The encoded String
-
padString
-
makeSqlSafe
-
formatPrintableCreditCard
-