*/
public class LocaleEncodingMappingListMergeHandler implements WebFragmentMergeHandler<WebFragment, WebApp> {
@Override
public void merge(WebFragment webFragment, WebApp webApp, MergeContext mergeContext) throws DeploymentException {
LocaleEncodingMappingList targetLocaleEncodingMappingList = webApp.getLocaleEncodingMappingList().isEmpty() ? null: webApp.getLocaleEncodingMappingList().get(0);
for (LocaleEncodingMappingList localeEncodingMappingList : webFragment.getLocaleEncodingMappingList()) {
for (LocaleEncodingMapping localeEncodingMapping : localeEncodingMappingList.getLocaleEncodingMapping()) {
String localeEncodingMappingKey = createLocaleEncodingMappingKey(localeEncodingMapping.getLocale());
MergeItem mergeItem = (MergeItem) mergeContext.getAttribute(localeEncodingMappingKey);
if (mergeItem != null && mergeItem.isFromWebFragment() && !mergeItem.getValue().equals(localeEncodingMapping.getEncoding())) {
throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateKeyValueMessage("locale-encoding-mapping", "locale", localeEncodingMapping.getLocale(), "encoding",
(String) mergeItem.getValue(), mergeItem.getBelongedURL(), localeEncodingMapping.getLocale(), mergeContext.getCurrentJarUrl()));
}
if (targetLocaleEncodingMappingList == null) {
targetLocaleEncodingMappingList = new LocaleEncodingMappingList();
webApp.getLocaleEncodingMappingList().add(targetLocaleEncodingMappingList);
}
targetLocaleEncodingMappingList.getLocaleEncodingMapping().add(localeEncodingMapping);
mergeContext.setAttribute(localeEncodingMappingKey, new MergeItem(localeEncodingMapping.getEncoding(), mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
}
}
}