List of usage examples for org.springframework.context.support MessageSourceAccessor MessageSourceAccessor
public MessageSourceAccessor(MessageSource messageSource)
From source file:nz.co.senanque.validationengine.Binder.java
public Map<ValidationObject, ProxyObject> bind(final ValidationObject object, final ValidationSession session, final ProxyField parent, final Integer index, ValidationObject owner) { MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor( m_validationEngine.getMessageSource()); final Map<ValidationObject, ProxyObject> ret = new IdentityHashMap<ValidationObject, ProxyObject>(); if (object == null) { return ret; }//from ww w .j av a 2s . co m Class<?> clazz = object.getClass(); final ClassMetadata classMetadata = m_validationEngine.getClassMetadata(clazz); if (classMetadata == null) { throw m_validationEngine.getLocaleAwareExceptionFactory().getRuntimeException( "nz.co.senanque.validationengine.class.not.recognised", new Object[] { clazz.getName() }); } object.setValidationSession(session); final ProxyObject proxyObject = new ProxyObject(object, parent, index, session); ret.put(object, proxyObject); final ObjectMetadata objectMetadata = (ObjectMetadata) object.getMetadata(); objectMetadata.setClassMetadata(proxyObject, classMetadata); Map<String, Property> propertyMap = ValidationUtils.getProperties(object.getClass()); for (Property property : propertyMap.values()) { String fieldName = property.getFieldName(); final PropertyMetadataImpl propertyMetadata = (PropertyMetadataImpl) classMetadata.getField(fieldName); if (propertyMetadata == null) { continue; } final ProxyFieldImpl proxyField = new ProxyFieldImpl(fieldName, proxyObject, parent, propertyMetadata, messageSourceAccessor); proxyObject.put(fieldName, proxyField); Method method = property.getGetter(); if (property.getGetter().getReturnType().isAssignableFrom(List.class)) { try { @SuppressWarnings("unchecked") final List<ValidationObject> validationObjects = (List<ValidationObject>) method.invoke(object, new Object[] {}); final ListeningArray<Object> array = new ListeningArray<Object>(); array.addAll(validationObjects); array.setValidationSession(session); array.setProxyField(proxyField); final Method setterMethod = property.getSetter(); setterMethod.invoke(object, array); int index1 = 0; for (ValidationObject child : validationObjects) { ret.putAll(bind(child, session, proxyField, index1++, owner)); } } catch (Exception e) { throw new RuntimeException(e); } continue; } if (m_validationEngine.getClassMetadata(method.getReturnType()) != null) { try { final ValidationObject child = (ValidationObject) method.invoke(object, new Object[] {}); ret.putAll(bind(child, session, proxyField, null, owner)); } catch (Exception e) { throw new RuntimeException(e); } continue; } try { Method getter = ValidationUtils.figureGetter(fieldName, clazz); if (getter.isAnnotationPresent(Ignore.class)) { continue; } java.lang.reflect.Field propertyField = getField(clazz, fieldName); Object value = ConvertUtils.convertToObject(propertyField.getType()); proxyField.setInitialValue(value); } catch (Exception e) { throw new RuntimeException(e); } } return ret; }
From source file:nz.co.senanque.vaadinsupport.ButtonProperty.java
public String getCaption() { MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(m_messageSource); String ret = messageSourceAccessor.getMessage(m_rawCaption, new Object[] {}, m_rawCaption); return ret;//from w ww. ja va 2 s . com }
From source file:org.fornax.cartridges.sculptor.framework.richclient.errorhandling.ExceptionAware.java
/** * It is convenient to use the// w ww . j a v a 2 s . c o m * {@link org.springframework.context.support.MessageSourceAccessor} to * fetch messages. Note that it uses the locale held by * {@link org.springframework.context.i18nLocaleContextHolder}. */ protected MessageSourceAccessor getMessagesAccessor() { return new MessageSourceAccessor(getMessages()); }
From source file:net.mojodna.sprout.support.SpringHttpServlet.java
/** * Initialize the WebApplicationContext for this Action. * Invokes onInit after successful initialization of the context. * @see #initWebApplicationContext//from w w w. j av a 2 s . c o m * @see #onInit */ public void init(final ServletConfig cfg) throws ServletException { super.init(cfg); if (null != cfg) { this.webApplicationContext = initWebApplicationContext(cfg.getServletContext()); this.messageSourceAccessor = new MessageSourceAccessor(this.webApplicationContext); onInit(); } }
From source file:videoshop.controller.CatalogController.java
@Autowired public CatalogController(VideoCatalog videoCatalog, Inventory<InventoryItem> inventory, BusinessTime businessTime, MessageSource messageSource) { this.videoCatalog = videoCatalog; this.inventory = inventory; this.businessTime = businessTime; this.messageSourceAccessor = new MessageSourceAccessor(messageSource); }
From source file:grails.plugin.springsecurity.web.authentication.preauth.x509.ClosureX509PrincipalExtractor.java
/** * Dependency injection for the message source. * @param messageSource the message source *//*from w w w . ja v a 2 s .c om*/ public void setMessageSource(MessageSource messageSource) { messages = new MessageSourceAccessor(messageSource); }
From source file:nz.co.senanque.perspectiveslibrary.SubApplicationimpl.java
public String getDescription() { MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(m_messageSource); return (m_description == null) ? null : messageSourceAccessor.getMessage("project.description", null, m_description); }
From source file:net.mojodna.sprout.support.SpringBodyTagSupport.java
/** * Initialize the WebApplicationContext for this Action. * Invokes onInit after successful initialization of the context. * @see #initWebApplicationContext// w w w. j a v a 2 s. c om * @see #onInit */ public void setPageContext(final PageContext pageContext) { super.setPageContext(pageContext); if (null != pageContext) { this.webApplicationContext = initWebApplicationContext(pageContext); this.messageSourceAccessor = new MessageSourceAccessor(this.webApplicationContext); onInit(); } else { log.warn("Setting a NULL PageContext."); } }
From source file:nz.co.senanque.vaadinsupport.viewmanager.TouchLoginForm.java
public void afterPropertiesSet() throws Exception { MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(m_messageSource); usernameCaption = messageSourceAccessor.getMessage("username"); passwordCaption = messageSourceAccessor.getMessage("password"); submitCaption = messageSourceAccessor.getMessage("login.button"); welcomeCaption = messageSourceAccessor.getMessage("welcome"); final TextField userName = new TextField(usernameCaption); userName.setImmediate(true);// w w w.j a va 2 s . c o m addField("userName", userName); final PasswordField password = new PasswordField(passwordCaption); password.setImmediate(true); addField("password", password); Button submit = new Button(submitCaption); addField("submit", submit); submit.addListener(new ClickListener() { private static final long serialVersionUID = 5201900702970450254L; public void buttonClick(ClickEvent event) { Map<String, String> map = new HashMap<String, String>(); map.put("user", String.valueOf(userName.getValue())); map.put("password", String.valueOf(password.getValue())); if (getLoginListener() != null) { try { getLoginListener().onLogin(map); } catch (Exception e) { Throwable cause = e.getCause(); if (cause == null || !(cause instanceof LoginException)) { logger.error(e.getMessage(), e); } MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(m_messageSource); String message = messageSourceAccessor.getMessage("Bad.Login", "Bad Login"); TouchKitApplication.get().getMainWindow().showNotification(message, Notification.TYPE_ERROR_MESSAGE); return; } } TouchKitApplication.get().setUser(userName.getValue()); } }); }
From source file:com.gnoht.tlrl.config.ApplicationConfig.java
/** * Returns a {@link MessageSourceAccessor} instance, that's pre-configured to * use a {@link LocaleContextHolder} for locale lookups. Note: Working with * MessageSourceAccessor is more convenient then working directly with {@link MessageSource}. * /*from w ww . j av a 2 s .c o m*/ * @param messageSource being wrapped * @return instance of {@link MessageSourceAccessor} */ @Autowired @Bean public MessageSourceAccessor messageSourceAccessor(MessageSource messageSource) { return new MessageSourceAccessor(messageSource); }