final int numPlurals = resourceUtils
.getNumPlurals(document, locale);
for (TextFlowTarget incomingTarget : batch) {
String resId = incomingTarget.getResId();
String sourceHash = incomingTarget.getSourceHash();
HTextFlow textFlow = resIdToTextFlowMap.get(resId);
if (textFlow == null) {
// return warning for unknown resId to caller
String warning =
"Could not find TextFlow for TextFlowTarget "
+ resId + " with contents: "
+ incomingTarget.getContents();
warnings.add(warning);
log.warn("skipping TextFlowTarget with unknown resId: {}",
resId);
} else if (sourceHash != null
&& !sourceHash.equals(textFlow.getContentHash())) {
String warning =
MessageFormat
.format("TextFlowTarget {0} may be obsolete; "
+ "associated source hash: {1}; "
+ "expected hash is {2} for source: {3}",
resId, sourceHash,
textFlow.getContentHash(),
textFlow.getContents());
warnings.add(warning);
log.warn(
"skipping TextFlowTarget {} with unknown sourceHash: {}",
resId, sourceHash);
} else {
String validationMessage =
validateTranslations(incomingTarget.getState(),
iteration,
incomingTarget.getResId(),
textFlow.getContents(),
incomingTarget.getContents());
if (!StringUtils.isEmpty(validationMessage)) {
warnings.add(validationMessage);
log.warn(validationMessage);
continue;
}
int nPlurals = textFlow.isPlural() ? numPlurals : 1;
// we have eagerly loaded all targets upfront
HTextFlowTarget hTarget = textFlow.getTargets().get(locale.getId());
ContentState currentState = ContentState.New;
if (hTarget != null) {
currentState = hTarget.getState();
}
if (mergeType == MergeType.IMPORT) {
removedTargets.remove(hTarget);
}
TranslationMergeServiceFactory.MergeContext mergeContext =
new TranslationMergeServiceFactory.MergeContext(
mergeType, textFlow, locale, hTarget,
nPlurals);
TranslationMergeService mergeService =
translationMergeServiceFactory
.getMergeService(mergeContext);
boolean targetChanged =
mergeService.merge(incomingTarget, hTarget,
extensions);
if (hTarget == null) {
// in case hTarget was null, we need to
// retrieve it after merge
hTarget = textFlow.getTargets().get(locale.getId());
}
targetChanged |=
adjustContentsAndState(hTarget, nPlurals, warnings);
// update translation information if applicable
if (targetChanged) {