Example usage for java.util ResourceBundle getBundle

List of usage examples for java.util ResourceBundle getBundle

Introduction

In this page you can find the example usage for java.util ResourceBundle getBundle.

Prototype

@CallerSensitive
public static ResourceBundle getBundle(String baseName, Module module) 

Source Link

Document

Gets a resource bundle using the specified base name and the default locale on behalf of the specified module.

Usage

From source file:es.pode.administracion.presentacion.planificador.eliminarTarea.EliminarTareasControllerImpl.java

private ResourceBundle getFicheroRecursos(Locale locale) {
    ResourceBundle ficheroRecursos = null;
    ficheroRecursos = ResourceBundle.getBundle("application-resources", locale);
    return ficheroRecursos;
}

From source file:com.norconex.commons.lang.file.ContentFamily.java

private ResourceBundle getDisplayBundle(Locale locale) {
    ResourceBundle bundle = BUNDLE_DISPLAYNAMES.get(locale);
    if (bundle != null) {
        return bundle;
    }/*from w  w w  .  j  ava  2  s  .  c o m*/
    try {
        bundle = ResourceBundle.getBundle(ContentFamily.class.getSimpleName() + "-custom-names", locale);
    } catch (MissingResourceException e) {
        bundle = ResourceBundle.getBundle(ContentFamily.class.getName() + "-names", locale);
    }
    BUNDLE_DISPLAYNAMES.put(locale, bundle);
    return bundle;
}

From source file:com.salesmanager.core.util.LabelUtil.java

public String getText(Locale locale, String key) {

    Iterator bundleListIterator = bundleList.iterator();
    ResourceBundle myResources = null;
    String label = "";
    while (bundleListIterator.hasNext()) {
        String bundle = (String) bundleListIterator.next();
        try {//from   w ww  .  j  av  a  2 s. com
            myResources = ResourceBundle.getBundle(bundle, locale);
            if (myResources != null) {
                String l = myResources.getString(key);
                if (l != null) {
                    label = l;
                    break;
                }
            }

        } catch (Exception e) {
            // TODO: handle exception
        }

    }
    return label;
}

From source file:com.evolveum.midpoint.report.impl.ReportUtils.java

public static String getPropertyString(String key, String defaultValue) {
    String val = (defaultValue == null) ? key : defaultValue;
    ResourceBundle bundle;/*from w  ww  .j  ava  2  s  .c o  m*/
    try {
        bundle = ResourceBundle.getBundle("localization/Midpoint", new Locale("en", "US"));
    } catch (MissingResourceException e) {
        return (defaultValue != null) ? defaultValue : key; //workaround for Jasper Studio
    }
    if (bundle != null && bundle.containsKey(key)) {
        val = bundle.getString(key);
    }
    return val;
}

From source file:es.pode.modificador.presentacion.configurar.objetos.buscar.BuscarObjetoControllerImpl.java

/**
 * @see es.pode.modificador.presentacion.configurar.objetos.buscar.BuscarObjetoController#selectAction(org.apache.struts.action.ActionMapping, es.pode.modificador.presentacion.configurar.objetos.buscar.SelectActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///from ww  w .j av a 2  s.  co m
public final java.lang.String selectAction(ActionMapping mapping,
        es.pode.modificador.presentacion.configurar.objetos.buscar.SelectActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    java.util.Locale locale = (java.util.Locale) request.getSession()
            .getAttribute(ConstantesAgrega.DEFAULT_LOCALE);
    ResourceBundle i18n = ResourceBundle.getBundle("application-resources", locale);

    String volver = "Volver";
    String buscar = i18n.getString("buscarObjeto.Buscar");
    String action = form.getAction();
    if (action == null) {
        return volver;
    }
    if (action.equals(buscar)) {

        // Guarda datos bsqueda en sesin
        BusquedaSession sesion = getBusquedaSession(request);
        boolean alMenosUnParametro = false;
        boolean parteFecha = false;

        if (vacia(form.getIdioma())) {
            throw new ValidatorException("{buscarObjeto.msgErrorIdioma}");
        }
        if (!vacia(form.getAutor())) {

            alMenosUnParametro = true;
        }
        if (!vacia(form.getIdentificador())) {

            alMenosUnParametro = true;
        }
        if (!vacia(form.getTitulo())) {

            alMenosUnParametro = true;
        }
        if (fechaValida(
                form.getAnyoDesde())/*&&fechaValida(form.getDiaDesde())&&fechaValida(form.getMesDesde())*/) {

            alMenosUnParametro = true;
            parteFecha = true;
        }
        if (fechaValida(
                form.getAnyoHasta())/*&&fechaValida(form.getDiaHasta())&&fechaValida(form.getMesHasta())*/) {

            alMenosUnParametro = true;
            parteFecha = true;
        }
        if (fechaValida(form.getDiaDesde())) {

            alMenosUnParametro = true;
            parteFecha = true;
        }
        if (fechaValida(form.getDiaHasta())) {

            alMenosUnParametro = true;
            parteFecha = true;
        }
        if (fechaValida(form.getMesDesde())) {

            alMenosUnParametro = true;
            parteFecha = true;
        }
        if (fechaValida(form.getMesHasta())) {

            alMenosUnParametro = true;
            parteFecha = true;
        }

        //Si al menos uno de los campos de una fecha se ha introducido, se da error si falta otro

        if (parteFecha) {
            if (!fechaValida(form.getDiaDesde())) {
                throw new ValidatorException("{buscarObjeto.msgErrorDiaDesde}");
            } else if (!fechaValida(form.getMesDesde())) {
                throw new ValidatorException("{buscarObjeto.msgErrorMesDesde}");
            } else if (!fechaValida(form.getAnyoDesde())) {
                throw new ValidatorException("{buscarObjeto.msgErrorAnyoDesde}");
            } else if (!fechaValida(form.getDiaHasta())) {
                throw new ValidatorException("{buscarObjeto.msgErrorDiaHasta}");
            } else if (!fechaValida(form.getMesHasta())) {
                throw new ValidatorException("{buscarObjeto.msgErrorMesHasta}");
            } else if (!fechaValida(form.getAnyoHasta())) {
                throw new ValidatorException("{buscarObjeto.msgErrorAnyoHasta}");
            }
        }

        if (!alMenosUnParametro) {
            throw new ValidatorException("{buscarObjeto.exception}");
        }

        //Vuelco el form a la sesion
        sesion.setAutor(form.getAutor());
        sesion.setIdentificador(form.getIdentificador());
        sesion.setTitulo(form.getTitulo());
        sesion.setIdioma(form.getIdioma());

        if (fechaValida(form.getDiaDesde()) && fechaValida(form.getMesDesde())
                && fechaValida(form.getAnyoDesde()) && fechaValida(form.getDiaHasta())
                && fechaValida(form.getMesHasta()) && fechaValida(form.getAnyoHasta())) {
            //Comprobaciones de la fecha
            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
            format.setLenient(false);

            String guion = "-";
            int dayFrom, dayTo, yearFrom, yearTo, monthFrom, monthTo;
            try {
                dayFrom = Integer.valueOf(form.getDiaDesde()).intValue();
                dayTo = Integer.valueOf(form.getDiaHasta()).intValue();
                yearFrom = Integer.valueOf(form.getAnyoDesde()).intValue();
                yearTo = Integer.valueOf(form.getAnyoHasta()).intValue();
                monthFrom = Integer.valueOf(form.getMesDesde()).intValue();
                monthTo = Integer.valueOf(form.getMesHasta()).intValue();
            } catch (Exception e) {
                throw new ValidatorException("{buscarObjetos.msgErrorFormato}");
            }
            StringBuffer fechaFromStr = new StringBuffer();
            fechaFromStr.append(dayFrom).append(guion).append(monthFrom).append(guion).append(yearFrom);

            Date fechaFrom;
            Date fechaTo;

            try {
                fechaFrom = format.parse(fechaFromStr.toString());
                StringBuffer fechaToStr = new StringBuffer();
                fechaToStr.append(dayTo).append(guion).append(monthTo).append(guion).append(yearTo);

                fechaTo = format.parse(fechaToStr.toString());
                if (fechaTo.before(fechaFrom)) {
                    throw new ValidatorException("{buscarObjetos.msgErrorFormato}");
                }
            } catch (Exception e) {
                throw new ValidatorException("{buscarObjetos.msgErrorFormato}");
            }
            //Saco ahora campos de fecha a sesion
            String[] partes = format.format(fechaFrom).split("-");
            sesion.setDiaDesde(partes[0]);
            sesion.setMesDesde(partes[1]);
            sesion.setAnyoDesde(partes[2]);
            partes = format.format(fechaTo).split("-");
            sesion.setDiaHasta(partes[0]);
            sesion.setMesHasta(partes[1]);
            sesion.setAnyoHasta(partes[2]);
        } else {
            //Actualizamos los campos de fecha en sesion aunque no sean buenos
            sesion.setDiaDesde(form.getDiaDesde());
            sesion.setMesDesde(form.getMesDesde());
            sesion.setAnyoDesde(form.getAnyoDesde());
            sesion.setDiaHasta(form.getDiaHasta());
            sesion.setMesHasta(form.getMesHasta());
            sesion.setAnyoHasta(form.getAnyoHasta());
        }
        sesion.setResultados(null);
        return "Buscar";
    }

    return volver;
}

From source file:it.cnr.icar.eric.client.ui.swing.metal.MetalThemeMenu.java

/**
 * Listens to property changes in the bound property
 * RegistryBrowser.PROPERTY_LOCALE.//w  ww. j  ava  2  s.c om
 */
public void propertyChange(PropertyChangeEvent ev) {
    if (ev.getPropertyName().equals(RegistryBrowser.PROPERTY_LOCALE)) {
        themeNames = ResourceBundle.getBundle(BASE_NAME, (Locale) ev.getNewValue());

        setLocale((Locale) ev.getNewValue());
        updateText();
    }
}

From source file:es.pode.empaquetador.presentacion.avanzado.recursos.exportar.ExportarRecursosControllerImpl.java

public String selectAction(ActionMapping mapping, SelectActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String result = null;/*from   ww  w .  j a  v  a  2  s .c o m*/
    String actionSubmit = form.getAction();
    java.util.Locale locale = (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE);
    ResourceBundle i18n = ResourceBundle.getBundle("application-resources", locale);

    if (form.getAction() == (null)) {
        throw new ValidatorException("{portal_empaquetado.exception}");
    }

    else if (actionSubmit.equals(i18n.getString("presentacion.avanzado.recursos.exportar.cancelar"))) {
        result = "Cancelar";
    } else if (actionSubmit.equals(i18n.getString("presentacion.avanzado.recursos.exportar.aceptar"))) {
        result = "Aceptar";
    } else {

        Logger.getLogger(this.getClass())
                .debug("El valor del submit no es correcto (actionSubmit = " + actionSubmit + ";");
    }
    return result;
}

From source file:edu.ku.brc.specify.utilapps.CreateTextSchema.java

/**
 * @param args/* ww w .  j a  v a2 s.  co  m*/
 */
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        @SuppressWarnings("synthetic-access") //$NON-NLS-1$
        public void run() {
            try {
                UIHelper.OSTYPE osType = UIHelper.getOSType();
                if (osType == UIHelper.OSTYPE.Windows) {
                    UIManager.setLookAndFeel(new PlasticLookAndFeel());
                    PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());

                } else if (osType == UIHelper.OSTYPE.Linux) {
                    UIManager.setLookAndFeel(new PlasticLookAndFeel());
                }
            } catch (Exception e) {
            }

            String schemaVersion = JOptionPane.showInputDialog("Enter Schema Version:");

            Locale.setDefault(currLang);

            try {
                ResourceBundle.getBundle("resources", Locale.getDefault()); //$NON-NLS-1$

            } catch (MissingResourceException ex) {
                Locale.setDefault(Locale.ENGLISH);
                UIRegistry.setResourceLocale(Locale.ENGLISH);
            }

            CreateTextSchema cts = new CreateTextSchema();
            cts.process(schemaVersion);

            //File file = XMLHelper.getConfigDir(specifyDescFileName);
            //file.delete();

            JOptionPane.showMessageDialog(null, "Done");
        }
    });
}

From source file:dk.teachus.backend.bean.impl.VelocityNotificationBean.java

public synchronized void sendTeacherNotificationMail() {
    log.info("Start sending notification mails to the teachers");

    List<Teacher> teachers = personDAO.getPersons(Teacher.class);

    for (Teacher teacher : teachers) {
        List<PupilBooking> pupilBookings = bookingDAO.getTeacherNotificationBookings(teacher);

        if (pupilBookings.isEmpty() == false) {
            if (log.isDebugEnabled()) {
                log.debug("Sending mails with booking count: " + pupilBookings.size() + " for teacher: "
                        + teacher.getName());
            }//  www  . j  a v a 2  s .  c om

            // Create message to the teacher
            MailMessage message = new MailMessage();

            // Sender and recipient
            message.setSender(teacher);
            message.setRecipient(teacher);

            // The locale
            Locale locale = teacher.getLocale();

            // Build up bookingslist and format date
            List<FormattedPupilBooking> pupilBookingList = new ArrayList<FormattedPupilBooking>();
            for (PupilBooking pupilBooking : pupilBookings) {
                FormattedPupilBooking formattedPupilBooking = new FormattedPupilBooking();
                formattedPupilBooking.setPupilBooking(pupilBooking);
                DateTimeFormatter dateFormat = DATE_TIME_FORMAT.withLocale(locale);
                formattedPupilBooking.setFormattedDate(dateFormat.print(pupilBooking.getDate()));
                pupilBookingList.add(formattedPupilBooking);
            }

            // Load properties
            ResourceBundle bundle = ResourceBundle.getBundle(
                    ClassUtils.getAsResourceBundlePath(VelocityNotificationBean.class, "NewBookingsMail"),
                    locale);

            // Subject
            message.setSubject(bundle.getString("subject"));

            // Parse the template
            Map<String, Object> model = new HashMap<String, Object>();
            model.put("followingPupilsHasBookings", bundle.getString("followingPupilsHasBookings"));
            model.put("pupilHeader", bundle.getString("pupilHeader"));
            model.put("dateHeader", bundle.getString("dateHeader"));
            model.put("pupilBookingList", pupilBookingList);
            String template = "";
            try {
                template = velocityBean.mergeTemplate(
                        ClassUtils.getAsResourcePath(VelocityNotificationBean.class, "NewBookingsMail.vm"),
                        model);
            } catch (VelocityException e) {
                throw new RuntimeException(e);
            }

            // Text
            message.setBody(template);
            message.setType(Type.HTML);
            message.setState(MessageState.FINAL);

            messageDAO.save(message);
        }

        // Send mails
        bookingDAO.teacherNotificationMailSent(pupilBookings);
    }
}

From source file:com.autentia.tnt.bean.billing.BillBean.java

public List<SelectItem> getYears() {
    ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
    FacesContext context = FacesContext.getCurrentInstance();
    Locale locale = context.getViewRoot().getLocale();
    ResourceBundle bundle = ResourceBundle.getBundle("com.autentia.tnt.resources.messages", locale);

    Date fecha = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(fecha);/*from w ww .j a  va2 s  . com*/
    int actual = cal.get(Calendar.YEAR);
    ret.add(new SelectItem(Integer.valueOf(actual), bundle.getString("bill.fiscalYear.now")));
    ret.add(new SelectItem(Integer.valueOf(ALL_YEARS), bundle.getString("bill.fiscalYear.all")));

    for (int i = 1; i < getMaximumYears(); i++) {
        ret.add(new SelectItem(Integer.valueOf(actual - i), "" + (actual - i)));
    }

    return ret;
}