@Override public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) { String msg = localizationService.translate(code, args, locale); if (msg == null) { return defaultMessage; } return msg; }
/** * Fills-in message and localizedMessage based on userFriendlyMessage, if needed. */ <T extends CommonException> T translate(T e); }
private String resolve(String key) { if (key != null) { return localizationService.translate(key, null, Locale.getDefault(), key); } else { return null; } }
@Override public String translate(LocalizableMessage message) { return localizationService.translate(message, Locale.getDefault()); }
@NotNull private String getString(String key, Object... parameters) { return localizationService.translate(key, parameters, Locale.getDefault(), key); }
@Override public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException { String msg = localizationService.translate(code, args, locale); if (msg == null) { throw new NoSuchMessageException("Message code '" + code + "' was not found"); } return msg; }
@Override public String translate(LocalizableMessageType message) { return localizationService.translate(LocalizationUtil.toLocalizableMessage(message), Locale.getDefault()); }
@NotNull private String getMajorMidPointVersion() { String version = localizationService .translate(LocalizableMessageBuilder.buildKey("midPointVersion"), Locale.getDefault()); String noSnapshot = removeSuffix(version); int firstDot = noSnapshot.indexOf('.'); if (firstDot < 0) { throw new SystemException("Couldn't determine midPoint version from '" + version + "'"); } int secondDot = noSnapshot.indexOf('.', firstDot+1); if (secondDot < 0) { return noSnapshot; } else { return noSnapshot.substring(0, secondDot); } }
private String getTranslatedMessage(Throwable t) { return localizationService.translate(t.getMessage(), new Object[0], Locale.getDefault()); }
private BuildInformationType getBuildInformation() { BuildInformationType info = new BuildInformationType(); LocalizationService localizationService = taskManager.getLocalizationService(); info.setVersion(localizationService.translate(LocalizableMessageBuilder.buildKey("midPointVersion"), Locale.getDefault())); info.setRevision(localizationService.translate(LocalizableMessageBuilder.buildKey("midPointRevision"), Locale.getDefault())); return info; }
protected String getTranslatedMessage(CommonException e) { if (e.getUserFriendlyMessage() != null) { return localizationService.translate(e.getUserFriendlyMessage(), Locale.US); } else { return e.getMessage(); } }
private void executeRegular(EvaluationContext evalCtx) throws PolicyViolationException { if (!evalCtx.messages.isEmpty()) { LocalizableMessage message = new LocalizableMessageListBuilder() .messages(evalCtx.messages) .separator(LocalizableMessageList.SEMICOLON) .buildOptimized(); throw localizationService.translate(new PolicyViolationException(message)); } }
@Override public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException { Validate.notNull(resolvable, "Message source resolvable must not be null"); for (String code : resolvable.getCodes()) { String msg = localizationService.translate(code, resolvable.getArguments(), locale); if (msg != null) { return msg; } } if (resolvable.getDefaultMessage() != null) { return resolvable.getDefaultMessage(); } throw new NoSuchMessageException("Can't resolve message: " + resolvable); } }
} else if (object instanceof OperationResult) { Function<LocalizableMessage, String> resolveKeys = msg -> localizationService.translate(msg, Locale.US); OperationResultType operationResultType = ((OperationResult) object).createOperationResultType(resolveKeys); xml = serializer.serializeAnyData(operationResultType, fakeQName);
private void assertTranslation(LocalizationService service, String key, String defaultValue, String expectedValue) { Locale locale = new Locale("sk"); String real = service.translate(key, null, locale, defaultValue); AssertJUnit.assertEquals("Expected translation for key '" + key + "' was '" + expectedValue + "', real '" + real + "'", expectedValue, real); LocalizableMessage msg = new LocalizableMessageBuilder().key(key).fallbackMessage(defaultValue).build(); real = service.translate(msg, locale); AssertJUnit.assertEquals("Expected translation for localization message key '" + key + "' was '" + expectedValue + "', real '" + real + "'", expectedValue, real); } }
private <T extends ObjectType> void prepareObjectRelatedTaskInstructions( List<PcpChildWfTaskCreationInstruction<?>> instructions, ApprovalSchemaBuilder.Result builderResult, List<ObjectDelta<T>> deltasToApprove, PrismObject<UserType> requester, ModelInvocationContext<T> ctx, OperationResult result) throws SchemaException { ModelContext<T> modelContext = ctx.modelContext; for (ObjectDelta<T> deltaToApprove : deltasToApprove) { LocalizableMessage processName = main.createProcessName(builderResult, null, ctx, result); if (main.useDefaultProcessName(processName)) { processName = createDefaultProcessName(modelContext, deltaToApprove); } String processNameInDefaultLocale = localizationService.translate(processName, Locale.getDefault()); PcpChildWfTaskCreationInstruction<ItemApprovalSpecificContent> instruction = PcpChildWfTaskCreationInstruction.createItemApprovalInstruction(main.getChangeProcessor(), processNameInDefaultLocale, builderResult.schemaType, builderResult.attachedRules); instruction.prepareCommonAttributes(main, modelContext, requester); instruction.setDeltasToProcess(deltaToApprove); instruction.setObjectRef(modelContext, result); String taskNameInDefaultLocale = localizationService.translate( new LocalizableMessageBuilder() .key(instruction.isExecuteApprovedChangeImmediately() ? "ApprovalAndExecutionOf" : "ApprovalOf") .arg(processNameInDefaultLocale) .build(), Locale.getDefault()); instruction.setTaskName(taskNameInDefaultLocale); instruction.setProcessInstanceName(processNameInDefaultLocale); itemApprovalProcessInterface.prepareStartInstruction(instruction); instructions.add(instruction); } }
private void processValidationResult(OperationResult validationResult) throws PolicyViolationException { result.addSubresult(validationResult); if (!validationResult.isAcceptable()) { SingleLocalizableMessage message = new LocalizableMessageBuilder() .key("PolicyViolationException.message.credentials." + getCredentialHumanReadableKey()) .arg(validationResult.getUserFriendlyMessage()) .build(); throw localizationService.translate(new PolicyViolationException(message)); } }
processName = createDefaultProcessName(modelContext, assignmentMode, target); String processNameInDefaultLocale = localizationService.translate(processName, Locale.getDefault()); instruction.setTargetRef(createObjectRef(target, prismContext), result); String taskNameInDefaultLocale = localizationService.translate( new LocalizableMessageBuilder() .key(instruction.isExecuteApprovedChangeImmediately() ? "ApprovalAndExecutionOf" : "ApprovalOf")
public static void triggerConstraintLegacy(EvaluatedPolicyRuleTrigger trigger, Collection<String> policySituations, LocalizationService localizationService) throws PolicyViolationException { LOGGER.debug("Legacy policy rule triggered: {}", trigger); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Legacy Policy rule triggered:\n{}", trigger.debugDump(1)); } if (trigger.getConstraint().getEnforcement() == null || trigger.getConstraint().getEnforcement() == PolicyConstraintEnforcementType.ENFORCE) { throw localizationService.translate(new PolicyViolationException(trigger.getMessage())); } }
/** * Creates a root job creation instruction. * * @param changeProcessor reference to the change processor responsible for the whole operation * @param modelContext model context in which the original model operation is carried out * @param taskFromModel task in which the original model operation is carried out * @param contextForRoot model context that should be put into the root task (might be different from the modelContext) * @return the job creation instruction * @throws SchemaException */ public WfTaskCreationInstruction createInstructionForRoot(ChangeProcessor changeProcessor, ModelContext modelContext, Task taskFromModel, ModelContext contextForRoot, OperationResult result) throws SchemaException { WfTaskCreationInstruction<?, ?> instruction; if (contextForRoot != null) { instruction = WfTaskCreationInstruction.createModelOnly(changeProcessor, contextForRoot); } else { instruction = WfTaskCreationInstruction.createEmpty(changeProcessor); } LocalizableMessage rootTaskName = determineRootTaskName(modelContext); String rootTaskNameInDefaultLocale = localizationService.translate(rootTaskName, Locale.getDefault()); instruction.setLocalizableTaskName(rootTaskName); instruction.setTaskName(rootTaskNameInDefaultLocale); instruction.setTaskObject(determineRootTaskObject(modelContext)); instruction.setTaskOwner(taskFromModel.getOwner()); instruction.setCreateTaskAsWaiting(); instruction.setObjectRef(modelContext, result); instruction.setRequesterRef(getRequester(taskFromModel, result)); return instruction; }