*/
public class LocaleEncodingMappingListMergeHandler implements WebFragmentMergeHandler<WebFragmentType, WebAppType> {
@Override
public void merge(WebFragmentType webFragment, WebAppType webApp, MergeContext mergeContext) throws DeploymentException {
LocaleEncodingMappingListType targetLocaleEncodingMappingList = null;
for (LocaleEncodingMappingListType localeEncodingMappingList : webFragment.getLocaleEncodingMappingListArray()) {
for (LocaleEncodingMappingType localeEncodingMapping : localeEncodingMappingList.getLocaleEncodingMappingArray()) {
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 = webApp.getLocaleEncodingMappingListArray().length > 0 ? webApp.getLocaleEncodingMappingListArray(0) : webApp.addNewLocaleEncodingMappingList();
}
targetLocaleEncodingMappingList.addNewLocaleEncodingMapping().set(localeEncodingMapping);
mergeContext.setAttribute(localeEncodingMappingKey, new MergeItem(localeEncodingMapping.getEncoding(), mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
}
}
}