List of usage examples for java.text MessageFormat toPattern
public String toPattern()
From source file:net.mlw.vlh.web.util.JspUtils.java
public static String format(Object value, String format, Locale loc) { if (value == null) { return ""; } else {//w w w . ja v a 2 s. co m if (value instanceof Number) { if (format == null || format.length() == 0) { return value.toString(); } MessageFormat mf = new MessageFormat("{0,number," + format + "}"); if (loc != null) { mf.setLocale(loc); mf.applyPattern(mf.toPattern()); } return mf.format(new Object[] { value }); } else if (value instanceof java.util.Date) { if (format == null || format.length() == 0) { //TODO: get the default date format in here somehow. format = // SystemProperties.getProperty("default.dateFormat", "EEE, MMM // d, ''yy"); format = "EEE, MMM d, ''yy"; } MessageFormat mf = new MessageFormat("{0,date," + format + "}"); if (loc != null) { mf.setLocale(loc); mf.applyPattern(mf.toPattern()); } return mf.format(new Object[] { value }); } else if (value instanceof Calendar) { Calendar calendar = (Calendar) value; if (format == null || format.length() == 0) { //TODO: get the default date format in here somehow. format = // SystemProperties.getProperty("default.dateFormat", "EEE, MMM // d, ''yy"); format = "EEE, MMM d, ''yy"; } MessageFormat mf = new MessageFormat("{0,date," + format + "}"); if (loc != null) { mf.setLocale(loc); mf.applyPattern(mf.toPattern()); } return mf.format(new Object[] { value }); } else { return value.toString(); } } }
From source file:org.opentravel.schemacompiler.security.impl.JNDIAuthenticationProvider.java
/** * Returns the colon-separated list of LDAP filter expressions to use when searching for a * user's directory entry, with <code>{0}</code> marking where the actual username should be * inserted.// w w w . ja va 2s. co m * * @return String */ public String getUserSearchPatterns() { String searchPatterns; if (userSearchPatterns != null) { StringBuilder sp = new StringBuilder(); for (MessageFormat pattern : userSearchPatterns) { if (sp.length() > 0) sp.append(":"); sp.append(pattern.toPattern()); } searchPatterns = sp.toString(); } else { searchPatterns = null; } return searchPatterns; }