List of usage examples for com.liferay.portal.kernel.util FastDateFormatFactoryUtil getSimpleDateFormat
public static Format getSimpleDateFormat(String pattern)
From source file:com.liferay.dynamic.data.mapping.internal.util.DDMIndexerImpl.java
License:Open Source License
@Override public String extractIndexableAttributes(DDMStructure ddmStructure, DDMFormValues ddmFormValues, Locale locale) {/* w ww . j a v a2 s .c o m*/ Format dateFormat = FastDateFormatFactoryUtil .getSimpleDateFormat(PropsUtil.get(PropsKeys.INDEX_DATE_FORMAT_PATTERN)); StringBundler sb = new StringBundler(); Fields fields = toFields(ddmStructure, ddmFormValues); for (Field field : fields) { try { String indexType = ddmStructure.getFieldProperty(field.getName(), "indexType"); if (Validator.isNull(indexType)) { continue; } Serializable value = field.getValue(locale); if (value instanceof Boolean || value instanceof Number) { sb.append(value); sb.append(StringPool.SPACE); } else if (value instanceof Date) { sb.append(dateFormat.format(value)); sb.append(StringPool.SPACE); } else if (value instanceof Date[]) { Date[] dates = (Date[]) value; for (Date date : dates) { sb.append(dateFormat.format(date)); sb.append(StringPool.SPACE); } } else if (value instanceof Object[]) { Object[] values = (Object[]) value; for (Object object : values) { sb.append(object); sb.append(StringPool.SPACE); } } else { String valueString = String.valueOf(value); String type = field.getType(); if (type.equals(DDMImpl.TYPE_SELECT)) { JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString); String[] stringArray = ArrayUtil.toStringArray(jsonArray); sb.append(stringArray); sb.append(StringPool.SPACE); } else { if (type.equals(DDMImpl.TYPE_DDM_TEXT_HTML)) { valueString = HtmlUtil.extractText(valueString); } sb.append(valueString); sb.append(StringPool.SPACE); } } } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn(e, e); } } } return sb.toString(); }
From source file:com.liferay.httpservice.internal.servlet.BundleServletContextTest.java
License:Open Source License
@Before public void setUp() { mockStatic(FastDateFormatFactoryUtil.class); when(FastDateFormatFactoryUtil.getSimpleDateFormat(Mockito.anyString())).thenReturn(new SimpleDateFormat()); mockStatic(PortalUtil.class); when(PortalUtil.getPathContext()).thenReturn("sample-test-module"); _bundleServletContext = new BundleServletContext(_bundle, "test", _servletContext); }