Example usage for org.springframework.context.support MessageSourceAccessor MessageSourceAccessor

List of usage examples for org.springframework.context.support MessageSourceAccessor MessageSourceAccessor

Introduction

In this page you can find the example usage for org.springframework.context.support MessageSourceAccessor MessageSourceAccessor.

Prototype

public MessageSourceAccessor(MessageSource messageSource) 

Source Link

Document

Create a new MessageSourceAccessor, using LocaleContextHolder's locale as default locale.

Usage

From source file:org.jrecruiter.web.controller.BaseFormController.java

@Autowired
public void setMessages(MessageSource messageSource) {
    messages = new MessageSourceAccessor(messageSource);
}

From source file:nz.co.senanque.rules.decisiontable.PrototypeDecisionTableTest.java

/**
 * Test method for {@link nz.co.senanque.rules.decisiontable.PrototypeDecisionTable#evaluate(nz.co.senanque.rules.RuleSession, nz.co.senanque.validationengine.ValidationObject)}.
 *//*from w  w w. j  av a2s  . co  m*/
@Test
public void testEvaluate() throws Exception {
    SAXBuilder saxBuilder = new SAXBuilder();
    Document decisionTableDocument = saxBuilder.build(m_decisionTableResource.getInputStream());

    Element root = decisionTableDocument.getRootElement();
    List<Element> decisionTableElements = root.getChildren("DecisionTable");
    Element decisionTableElement = decisionTableElements.get(0);
    Rule decisionTable = new PrototypeDecisionTable(decisionTableElement, getDecisionTableFactoryMap());
    RuleSession ruleSession = new RuleSessionMock(root, new MessageSourceAccessor(m_messageSource));
    Pizza pizza = new Pizza();

    logger.debug("setting size {} topping {}", pizza.getSize(), pizza.getTopping());
    decisionTable.evaluate(ruleSession, pizza, null);
    pizza.setSize("Medium");
    logger.debug("setting size {} topping {}", pizza.getSize(), pizza.getTopping());
    decisionTable.evaluate(ruleSession, pizza, null);
    pizza.setTopping("Spanish");
    logger.debug("setting size {} topping {}", pizza.getSize(), pizza.getTopping());
    decisionTable.evaluate(ruleSession, pizza, null);
    pizza.setTopping(null);
    logger.debug("setting size {} topping {}", pizza.getSize(), pizza.getTopping());
    decisionTable.evaluate(ruleSession, pizza, null);
    pizza.setSize(null);
    logger.debug("setting size {} topping {}", pizza.getSize(), pizza.getTopping());
    decisionTable.evaluate(ruleSession, pizza, null);

}

From source file:nz.co.senanque.pizzabundle.AppFactoryImpl.java

public App createApp(Blackboard blackboard) {
    // Explicitly fetch this bean to ensure it is not instantiated until the session has started.
    m_maduraSessionManager = m_beanFactory.getBean("maduraSessionManager", MaduraSessionManager.class);
    App ret = new App();
    MaduraFieldGroup fieldGroup = getMaduraSessionManager().createMaduraFieldGroup();
    final Layout layout = new Layout(m_maduraSessionManager, fieldGroup);
    layout.setBlackboard(blackboard);/*  w  w  w . j av  a  2s  . c om*/
    ret.setComponentContainer(layout);
    Pizza pizza = new Pizza();

    m_maduraSessionManager.getValidationSession().bind(pizza);
    MenuBar menuBar = new MenuBar();
    final MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(m_messageSource);
    final MenuBar.MenuItem edit = menuBar.addItem(messageSourceAccessor.getMessage("menu.edit", "Edit"), null);

    CommandExt command = fieldGroup.createMenuItemCommand(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            Notification.show(messageSourceAccessor.getMessage("message.clicked.cancel"),
                    messageSourceAccessor.getMessage("message.noop"), Notification.Type.HUMANIZED_MESSAGE);

        }
    });
    MenuItem menuItemSave = edit.addItem("menu.cancel", command);
    fieldGroup.bind(menuItemSave);

    command = fieldGroup.createMenuItemCommandSubmit(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            Notification.show(messageSourceAccessor.getMessage("message.clicked.submit"),
                    messageSourceAccessor.getMessage("message.noop"), Notification.Type.HUMANIZED_MESSAGE);

        }
    });
    MenuItem menuItemCancel = edit.addItem("menu.save", command);
    fieldGroup.bind(menuItemCancel);

    ret.setMenuBar(menuBar);

    layout.load(pizza);

    return ret;
}

From source file:nz.co.senanque.vaadinsupport.formatting.FormattingTable.java

/**
 * Does the same as the normal setContainerDataSource but accepts the column list (subset) and the headings for each column.
 * The headings are translated to the current locale.
 * Column names for numeric values should be prefixed with '-' which will make the right justify.
 * Numbers (Double, Float, Long, Integer, BigDecimal) will be formatted for the current locale.
 * @param indexed// w  ww .j  a v a 2  s.c o m
 * @param allColumns
 * @param headings
 */
public void setContainerDataSource(Container indexed, String[] allColumns, String[] headings,
        MessageSource messageSource) {
    super.setContainerDataSource(indexed);
    Collection<?> propertyIds = indexed.getContainerPropertyIds();
    Object[] visiblePropertyIds = new String[allColumns.length];
    String[] headings_ = new String[allColumns.length];
    int i = 0;
    MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(messageSource);
    for (int j = 0; j < allColumns.length; j++) {
        for (Object propertyId : propertyIds) {
            String thisColumn = allColumns[j];
            if (thisColumn.startsWith("-")) {
                thisColumn = thisColumn.substring(1);
                setColumnAlignment(thisColumn, Table.ALIGN_RIGHT);
            }
            if (propertyId.toString().equals(thisColumn)) {
                visiblePropertyIds[i] = propertyId;
                headings_[i] = messageSourceAccessor.getMessage(headings[j]);
                i++;
                break;
            }
        }
    }
    /*      
    super.setVisibleColumns(allColumns);
    */
    super.setVisibleColumns(visiblePropertyIds);
    super.setColumnHeaders(headings_);
}

From source file:org.openmrs.module.rwandaprimarycare.EnterSimpleEncounterController.java

@RequestMapping(method = RequestMethod.GET, params = "form=vitals")
public String setupVitalsForm(@RequestParam("patientId") Integer patientId,
        @RequestParam(required = false, value = "visitDate") Long visitDate, ModelMap model)
        throws PrimaryCareException {
    //LK: Need to ensure that all primary care methods only throw a PrimaryCareException
    //So that errors will be directed to a touch screen error page
    try {/*  ww  w.j av  a  2  s  .c om*/

        Patient patient = getPatient(patientId);
        model.addAttribute(patient);
        model.addAttribute("encounterType", PrimaryCareConstants.ENCOUNTER_TYPE_VITALS);
        List<Question> questions = new ArrayList<Question>();
        MessageSourceAccessor msa = new MessageSourceAccessor(
                Context.getMessageSourceService().getActiveMessageSource());
        questions.add(new Question(msa.getMessage("rwandaprimarycare.temperature"),
                PrimaryCareBusinessLogic.getTemperatureConcept(), false));
        questions.add(new Question(msa.getMessage("rwandaprimarycare.weight"),
                PrimaryCareBusinessLogic.getWeightConcept(), true));

        StringBuilder heightMsg = new StringBuilder(msa.getMessage("rwandaprimarycare.height"));
        //LK: if the BMI automatic calculation functionality is turned on we want to display
        //the last entered height and approximate age so the clerk can determine if remeasuring the patient is required
        Boolean calculateBMI = new Boolean(
                Context.getAdministrationService().getGlobalProperty("registration.calculateBMI"));
        if (calculateBMI) {
            Obs mostRecentHeightOb = PrimaryCareUtil.getMostRecentHeightObservation(patient);
            if (mostRecentHeightOb != null) {
                heightMsg = heightMsg.append(". ")
                        .append(msa.getMessage("rwandaprimarycare.lastRecordedHeight")).append(": ")
                        .append(mostRecentHeightOb.getValueAsString(Context.getLocale()));
                heightMsg = heightMsg.append(" ")
                        .append(msa.getMessage("rwandaprimarycare.lastRecordedHeightAge")).append(": ")
                        .append(PrimaryCareUtil.getAgeAtObservation(patient, mostRecentHeightOb));
            }
        }
        questions.add(new Question(heightMsg.toString(), PrimaryCareBusinessLogic.getHeightConcept(), false));
        model.addAttribute("questions", questions);

        if (visitDate != null) {
            model.addAttribute("visitDate", visitDate);
        }

    } catch (Exception e) {
        throw new PrimaryCareException(e);
    }
    return "/module/rwandaprimarycare/enterSimpleEncounter";
}

From source file:nz.co.senanque.sandbox.PropertyMetadataMock.java

@Override
public MessageSourceAccessor getMessageSourceAccessor() {
    return new MessageSourceAccessor(m_messageSource);
}

From source file:nz.co.senanque.vaadinsupport.tableeditor.EditorWindowImpl.java

public EditorWindowImpl(MaduraSessionManager maduraSessionManager, ViewManager viewManager, String caption,
        MessageSource messageSource) {/*w w  w. j a v a2  s  .c  o  m*/
    m_maduraSessionManager = maduraSessionManager;
    m_viewManager = viewManager;
    m_form = new MaduraForm(maduraSessionManager);
    setCaption(new MessageSourceAccessor(messageSource).getMessage(caption));
}

From source file:nz.co.senanque.workflowui.AttachmentsPopup.java

@Override
public void setMessageSource(MessageSource messageSource) {
    m_messageSource = messageSource;
    m_messageSourceAccessor = new MessageSourceAccessor(m_messageSource);
}

From source file:org.openmrs.module.rwandaprimarycare.CreateNewPatientController.java

@RequestMapping(method = RequestMethod.GET)
public String confirmIdNumber(
        @RequestParam(required = false, value = "addNationalIdentifier") String addNationalIdentifier,
        @RequestParam("givenName") String givenName, @RequestParam("familyName") String familyName,
        @RequestParam("gender") String gender, @RequestParam("age") Integer age,
        @RequestParam(required = false, value = "birthdateDay") Integer birthdateDay,
        @RequestParam(required = false, value = "birthdateMonth") Integer birthdateMonth,
        @RequestParam(required = false, value = "birthdateYear") Integer birthdateYear,
        @RequestParam("country") String country, @RequestParam("province") String province,
        @RequestParam("district") String district, @RequestParam("sector") String sector,
        @RequestParam("cell") String cell, @RequestParam("address1") String address1,
        @RequestParam("mothersName") String mothersName, @RequestParam("fathersName") String fathersName,
        HttpSession session, ModelMap map) throws PrimaryCareException {

    //LK: Need to ensure that all primary care methods only throw a PrimaryCareException
    //So that errors will be directed to a touch screen error page
    try {/*from   w  w  w .j ava2  s.  co  m*/
        IdentifierSource is = PrimaryCareUtil.getPrimaryIdentifierTypeSource();
        if (is == null) {
            map.addAttribute("addIdentifier", "");
        } else {
            MessageSourceAccessor msa = new MessageSourceAccessor(
                    Context.getMessageSourceService().getActiveMessageSource());
            map.addAttribute("addIdentifier", msa.getMessage("rwandaprimarycare.automaticallyassigned"));
            map.addAttribute("idSource", is.getId());
        }

        map.addAttribute("nationalIdIdentifierType", PrimaryCareUtil.getNationalIdIdentifierType());
    } catch (Exception e) {
        throw new PrimaryCareException(e);
    }
    return "/module/rwandaprimarycare/createNewPatient";
}

From source file:com.evolveum.midpoint.model.impl.security.AuthenticationEvaluatorImpl.java

@Override
public void setMessageSource(MessageSource messageSource) {
    this.messages = new MessageSourceAccessor(messageSource);
}