List of usage examples for org.springframework.context MessageSource getMessage
String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException;
From source file:com.nkapps.billing.webservices.AccountWebService.java
private GenericResult initResult(GenericArgument argument, GenericResult result) { try {//w w w . ja v a 2 s . c om String username = argument.getUsername(); String password = md5Encrypt(argument.getPassword()); WSDao wsDao = (WSDao) getBean("wsDao"); WsUser user = wsDao.findByUsernameAndPassword(username, password); if (user == null) { MessageSource messageSource = (MessageSource) getBean("messageSource"); // throw new Exception(messageSource.getMessage("auth.login_or_password_not_correct",null,new Locale("ru"))); Environment environment = (Environment) getBean("environment"); String a = environment.getProperty("ws.allow_user_add"); if ("true".equals(a)) { if (wsDao.createWsUser(username, password) == null) { throw new Exception(messageSource.getMessage("auth.login_or_password_not_correct", null, new Locale("ru"))); } } else { throw new Exception( messageSource.getMessage("auth.login_or_password_not_correct", null, new Locale("ru"))); } } result.setStatus(GenericResult.STATUS_INIT); } catch (Exception e) { logger.error(e.getMessage()); result.setStatus(GenericResult.STATUS_ERROR_AUTH); result.setReason(e.getMessage()); } return result; }
From source file:pl.chilldev.facelets.taglib.spring.web.MessageTag.java
/** * {@inheritDoc}/*from ww w. j ava 2 s . c o m*/ * * @since 0.0.1 */ @Override public void apply(FaceletContext context, UIComponent parent) { // get required components WebApplicationContext applicationContext = FacesContextUtils .getRequiredWebApplicationContext(context.getFacesContext()); MessageSource messageSource = applicationContext.getBean(MessageSource.class); String message = this.message.getValue(context); Locale locale = this.locale == null ? context.getLocale() : (Locale) this.locale.getObject(context, Locale.class); // if message source is not available simply stay with original message if (messageSource != null) { // note that we don't pass any arguments, we will handle interpolation on our as Spring's implementation // doesn't interpolate default message message = messageSource.getMessage(message, null, locale); } // interpolate parameters String separator = this.separator == null ? "," : this.separator.getValue(context); message = MessageFormat.format(message, this.args == null ? null : this.resolveArguments(this.args.getObject(context), separator)); // just output the text if (this.var == null) { UIOutput component = new UIOutput(); component.setValue(message); parent.getChildren().add(component); } else { // assign result to the variable context.setAttribute(this.var.getValue(context), message); } }
From source file:ch.ralscha.extdirectspring.bean.ExtDirectResponseBuilder.java
/** * Adds an "errors" property in the response if there are any errors in the * bindingResult. Sets the success flag to false if there are errors. * * @param locale// ww w. j a v a 2 s .c o m * @param messageSource * @param bindingResult * @return this instance */ public ExtDirectResponseBuilder addErrors(Locale locale, MessageSource messageSource, final BindingResult bindingResult) { if (bindingResult != null && bindingResult.hasFieldErrors()) { Map<String, List<String>> errorMap = new HashMap<String, List<String>>(); for (FieldError fieldError : bindingResult.getFieldErrors()) { String message = fieldError.getDefaultMessage(); if (messageSource != null) { Locale loc = locale != null ? locale : Locale.getDefault(); message = messageSource.getMessage(fieldError.getCode(), fieldError.getArguments(), loc); } List<String> fieldErrors = errorMap.get(fieldError.getField()); if (fieldErrors == null) { fieldErrors = new ArrayList<String>(); errorMap.put(fieldError.getField(), fieldErrors); } fieldErrors.add(message); } if (errorMap.isEmpty()) { addResultProperty("success", Boolean.TRUE); } else { addResultProperty("errors", errorMap); addResultProperty("success", Boolean.FALSE); } } return this; }
From source file:eu.eidas.node.auth.connector.tests.AUCONNECTORSAMLTestCase.java
/** * Test method for//from w w w.j av a 2 s . co m * {@link AUCONNECTORSAML#processAuthenticationResponse(byte[], EIDASAuthnRequest, EIDASAuthnRequest, String)} * . Testing with missing SAML engine data. Must throw a * {@link InternalErrorEIDASException}. */ @Test(expected = InternalErrorEIDASException.class) public void testProcessAuthenticationResponseSamlError() { final AUCONNECTORSAML auconnectorsaml = new AUCONNECTORSAML(); final AUCONNECTORUtil auconnectorutil = new AUCONNECTORUtil(); auconnectorutil.setConcurrentMapService(new ConcurrentMapServiceDefaultImpl()); auconnectorutil.setAntiReplayCache(auconnectorutil.getConcurrentMapService().getNewAntiReplayCache()); auconnectorutil.flushReplayCache(); auconnectorsaml.setConnectorUtil(auconnectorutil); auconnectorsaml.setSamlServiceInstance(TestingConstants.SAML_INSTANCE_CONS.toString()); auconnectorsaml.setSamlSpInstance(TestingConstants.SAML_INSTANCE_CONS.toString()); final EIDASAuthnRequest authData = new EIDASAuthnRequest(); authData.setSamlId(TestingConstants.SAML_ID_CONS.toString()); final EIDASAuthnRequest spAuthData = new EIDASAuthnRequest(); final IEIDASLogger mockLoggerBean = mock(IEIDASLogger.class); auconnectorsaml.setLoggerBean(mockLoggerBean); auconnectorsaml.setSamlEngineFactory(new EidasSamlEngineFactory()); final MessageSource mockMessages = mock(MessageSource.class); when(mockMessages.getMessage(anyString(), (Object[]) any(), (Locale) any())) .thenReturn("003002 - Authentication Failed."); auconnectorsaml.setMessageSource(mockMessages); auconnectorsaml.processAuthenticationResponse( generateSAMLResponse(TestingConstants.SAML_ID_CONS.toString(), true), authData, spAuthData, TestingConstants.USER_IP_CONS.toString()); }
From source file:se.softhouse.garden.orchid.spring.tags.OrchidMessageTag.java
/** * Resolve the specified message into a concrete message String. The * returned message String should be unescaped. *//*from w ww . j a v a2 s . c om*/ protected String resolveMessage() throws JspException, NoSuchMessageException { MessageSource messageSource = getMessageSource(); if (messageSource == null) { throw new JspTagException("No corresponding MessageSource found"); } try { String resolvedCode = ExpressionEvaluationUtils.evaluateString("code", this.code, this.pageContext); if (resolvedCode != null) { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); HttpServletResponse response = (HttpServletResponse) this.pageContext.getResponse(); this.arguments.arg(OrchidMessageFormatLinkFunction.LINK_FUNC, new OrchidMessageFormatLinkFunction(request, response)); // We have a code or default text that we need to resolve. Object[] argumentsArray = new Object[] { this.arguments }; String message = messageSource.getMessage(resolvedCode, argumentsArray, getRequestContext().getLocale()); String type = messageSource.getMessage("+.type." + resolvedCode, argumentsArray, null, getRequestContext().getLocale()); return formatMessage(message, type); } // All we have is a specified literal text. return this.code; } catch (Throwable e) { return this.defaultMessage; } }
From source file:org.gvnix.web.datatables.util.DatatablesUtils.java
public static boolean checkBooleanFilters(String expression, MessageSource messageSource) { // Getting all operations String trueOperation = "TRUE"; String falseOperation = "FALSE"; String isNullOperation = ISNULL_OPE; String isNotNullOperation = NOTNULL_OPE; if (messageSource != null) { trueOperation = messageSource.getMessage("global.filters.operations.boolean.true", null, LocaleContextHolder.getLocale()); falseOperation = messageSource.getMessage("global.filters.operations.boolean.false", null, LocaleContextHolder.getLocale()); isNullOperation = messageSource.getMessage(G_ISNULL_OPE, null, LocaleContextHolder.getLocale()); isNotNullOperation = messageSource.getMessage(G_NOTNULL_OPE, null, LocaleContextHolder.getLocale()); }/*from ww w. j a va2 s.c o m*/ // If written function is TRUE Pattern trueOperator = Pattern.compile(String.format("%s", trueOperation)); Matcher trueMatcher = trueOperator.matcher(expression); if (trueMatcher.matches()) { return true; } // If written function is FALSE Pattern falseOperator = Pattern.compile(String.format("%s", falseOperation)); Matcher falseMatcher = falseOperator.matcher(expression); if (falseMatcher.matches()) { return true; } // If written expression is ISNULL operation Pattern isNullOperator = Pattern.compile(String.format("%s", isNullOperation)); Matcher isNullMatcher = isNullOperator.matcher(expression); if (isNullMatcher.matches()) { return true; } // If written expression is ISNOTNULL operation Pattern isNotNullOperator = Pattern.compile(String.format("%s", isNotNullOperation)); Matcher isNotNullMatcher = isNotNullOperator.matcher(expression); if (isNotNullMatcher.matches()) { return true; } return false; }
From source file:org.gvnix.web.datatables.util.QuerydslUtils.java
/** * Return where clause expression for {@code Boolean} fields by transforming * the given {@code searchStr} to {@code Boolean} before check its value. * <p/>/*from w w w. j a va 2s .c om*/ * Expr: {@code entityPath.fieldName eq (TRUE | FALSE)} * * @param entityPath Full path to entity and associations. For example: * {@code Pet} , {@code Pet.owner} * @param fieldName Property name in the given entity path. For example: * {@code weight} in {@code Pet} entity, {@code age} in * {@code Pet.owner} entity. * @param searchStr the boolean value to find, may be null. Supported string * are: si, yes, true, on, no, false, off * @return BooleanExpression */ public static <T> BooleanExpression createBooleanExpressionWithOperators(PathBuilder<T> entityPath, String fieldName, String searchStr, ConversionService conversionService, MessageSource messageSource) { if (StringUtils.isBlank(searchStr)) { return null; } // Getting all operations String trueOperation = "TRUE"; String falseOperation = "FALSE"; String isNullOperation = OPERATOR_ISNULL; String isNotNullOperation = OPERATOR_NOTNULL; if (messageSource != null) { trueOperation = messageSource.getMessage("global.filters.operations.boolean.true", null, LocaleContextHolder.getLocale()); falseOperation = messageSource.getMessage("global.filters.operations.boolean.false", null, LocaleContextHolder.getLocale()); isNullOperation = messageSource.getMessage(G_FIL_OPE_ISNULL, null, LocaleContextHolder.getLocale()); isNotNullOperation = messageSource.getMessage(G_FIL_OPE_NOTNULL, null, LocaleContextHolder.getLocale()); } // If written function is TRUE Pattern trueOperator = Pattern.compile(String.format("%s", trueOperation)); Matcher trueMatcher = trueOperator.matcher(searchStr); if (trueMatcher.matches()) { return entityPath.getBoolean(fieldName).eq(Boolean.TRUE); } // If written function is FALSE Pattern falseOperator = Pattern.compile(String.format("%s", falseOperation)); Matcher falseMatcher = falseOperator.matcher(searchStr); if (falseMatcher.matches()) { return entityPath.getBoolean(fieldName).eq(Boolean.FALSE); } // If written expression is ISNULL operation Pattern isNullOperator = Pattern.compile(String.format("%s", isNullOperation)); Matcher isNullMatcher = isNullOperator.matcher(searchStr); if (isNullMatcher.matches()) { return entityPath.getBoolean(fieldName).isNull(); } // If written expression is ISNOTNULL operation Pattern isNotNullOperator = Pattern.compile(String.format("%s", isNotNullOperation)); Matcher isNotNullMatcher = isNotNullOperator.matcher(searchStr); if (isNotNullMatcher.matches()) { return entityPath.getBoolean(fieldName).isNotNull(); } return null; }
From source file:org.guanxi.sp.engine.service.shibboleth.AuthConsumerServiceThread.java
/** * This creates an AuthConsumerServiceThread that can be used * to retrieve the attributes from the AA URL and then pass them * to the Guard.//from w w w . j ava 2 s . com * * @param parent This is the AuthConsumerService object that has spawned this object. * @param guardSession This is the Guard Session string that has been passed to the Engine. * @param acsURL This is the URL of the Attribute Consumer Service on the Guard. * @param aaURL This is the URL of the Attribute Authority on the IdP. * @param podderURL This is the URL of the Podder Service on the Guard. * @param entityID This is the entityID of the Guard that will be used when talking to the IdP. * @param keystoreFile This is the location of the KeyStore which will be used to authenticate the client in secure communications. * @param keystorePassword This is the password for the KeyStore file. * @param truststoreFile This is the TrustStore file which will be used to authenticate the server in secure communications. * @param truststorePassword This is the password for the TrustStore file. * @param idpProviderId This is the providerId for the IdP that provides the Attributes. * @param idpNameIdentifier This is the name identifier that the IdP requires. * @param samlResponse This is the initial SAML response from the IdP that confirmed that the user had logged in. * @param messages This is the source of localised messages the thread must display * @param request This is the request this thread is associated with * @param manager This is the entity manager for the AA */ public AuthConsumerServiceThread(AuthConsumerService parent, String guardSession, String acsURL, String aaURL, String podderURL, String entityID, String keystoreFile, String keystorePassword, String truststoreFile, String truststorePassword, String idpProviderId, String idpNameIdentifier, ResponseType samlResponse, MessageSource messages, HttpServletRequest request, EntityManager manager) { this.parent = parent; this.guardSession = guardSession; this.acsURL = acsURL; this.aaURL = aaURL; this.podderURL = podderURL; this.entityID = entityID; this.keystoreFile = keystoreFile; this.keystorePassword = keystorePassword; this.truststoreFile = truststoreFile; this.truststorePassword = truststorePassword; this.idpProviderId = idpProviderId; this.idpNameIdentifier = idpNameIdentifier; this.samlResponse = samlResponse; this.messages = messages; this.manager = manager; preparingAARequest.addObject(progressTextKey, messages.getMessage("engine.acs.preparing.aa.request", null, request.getLocale())); readingAAResponse.addObject(progressTextKey, messages.getMessage("engine.acs.comm.with.aa", null, request.getLocale())); preparingGuardRequest.addObject(progressTextKey, messages.getMessage("engine.acs.preparing.guard.request", null, request.getLocale())); readingGuardResponse.addObject(progressTextKey, messages.getMessage("engine.acs.comm.with.guard", null, request.getLocale())); }
From source file:org.gvnix.web.datatables.util.DatatablesUtils.java
public static boolean checkStringFilters(String expression, MessageSource messageSource) { // All operations String endsOperation = "ENDS"; String startsOperation = "STARTS"; String containsOperation = "CONTAINS"; String isEmptyOperation = "ISEMPTY"; String isNotEmptyOperation = "ISNOTEMPTY"; String isNullOperation = ISNULL_OPE; String isNotNullOperation = NOTNULL_OPE; if (messageSource != null) { endsOperation = messageSource.getMessage("global.filters.operations.string.ends", null, LocaleContextHolder.getLocale()); startsOperation = messageSource.getMessage("global.filters.operations.string.starts", null, LocaleContextHolder.getLocale()); containsOperation = messageSource.getMessage("global.filters.operations.string.contains", null, LocaleContextHolder.getLocale()); isEmptyOperation = messageSource.getMessage("global.filters.operations.string.isempty", null, LocaleContextHolder.getLocale()); isNotEmptyOperation = messageSource.getMessage("global.filters.operations.string.isnotempty", null, LocaleContextHolder.getLocale()); isNullOperation = messageSource.getMessage(G_ISNULL_OPE, null, LocaleContextHolder.getLocale()); isNotNullOperation = messageSource.getMessage(G_NOTNULL_OPE, null, LocaleContextHolder.getLocale()); }//w ww . j ava 2s. c om // If written expression is ENDS operation Pattern endsOperator = Pattern.compile(String.format("%s[(]([a-zA-Z\\s\\d]*)[)]", endsOperation)); Matcher endsMatcher = endsOperator.matcher(expression); if (endsMatcher.matches()) { return true; } // If written expression is STARTS operation Pattern startsOperator = Pattern.compile(String.format("%s[(](.+)[)]$", startsOperation)); Matcher startsMatcher = startsOperator.matcher(expression); if (startsMatcher.matches()) { return true; } // If written expression is CONTAINS operation Pattern containsOperator = Pattern.compile(String.format("%s[(](.+)[)]$", containsOperation)); Matcher containsMatcher = containsOperator.matcher(expression); if (containsMatcher.matches()) { return true; } // If written expression is ISEMPTY operation Pattern isEmptyOperator = Pattern.compile(String.format("%s", isEmptyOperation)); Matcher isEmptyMatcher = isEmptyOperator.matcher(expression); if (isEmptyMatcher.matches()) { return true; } // If written expression is ISNOTEMPTY operation Pattern isNotEmptyOperator = Pattern.compile(String.format("%s", isNotEmptyOperation)); Matcher isNotEmptyMatcher = isNotEmptyOperator.matcher(expression); if (isNotEmptyMatcher.matches()) { return true; } // If written expression is ISNULL operation Pattern isNullOperator = Pattern.compile(String.format("%s", isNullOperation)); Matcher isNullMatcher = isNullOperator.matcher(expression); if (isNullMatcher.matches()) { return true; } // If written expression is ISNOTNULL operation Pattern isNotNullOperator = Pattern.compile(String.format("%s", isNotNullOperation)); Matcher isNotNullMatcher = isNotNullOperator.matcher(expression); if (isNotNullMatcher.matches()) { return true; } // If written expression is a symbol operation expression // Getting expressions with symbols Pattern symbolOperator = Pattern.compile("[=]?(.+)"); Matcher symbolMatcher = symbolOperator.matcher(expression); if (symbolMatcher.matches()) { return true; } return false; }