Example usage for java.text DateFormatSymbols getInstance

List of usage examples for java.text DateFormatSymbols getInstance

Introduction

In this page you can find the example usage for java.text DateFormatSymbols getInstance.

Prototype

public static final DateFormatSymbols getInstance(Locale locale) 

Source Link

Document

Gets the DateFormatSymbols instance for the specified locale.

Usage

From source file:Main.java

public static String getFullNameOfMonth(final Locale locale, final int month) {
    return DateFormatSymbols.getInstance(locale).getMonths()[month];
}

From source file:Main.java

@TargetApi(9)
public static String getMonth(int month, Locale locale) {
    return DateFormatSymbols.getInstance(locale).getMonths()[month - 1];
}

From source file:org.shredzone.cilla.site.renderer.CalendarRenderStrategyImpl.java

/**
 * Writes the caption line. It consists of the month name, the year, and links to the
 * previous and next month.//from   w  ww .  j a v a2  s  .c o  m
 */
protected void writeCaption() throws IOException {
    Calendar cal = generator.getDisplayCalendar();

    DateFormatSymbols symbols = DateFormatSymbols.getInstance(generator.getLocale());
    String[] months = symbols.getMonths();

    out.append("<caption>");
    writePreviousLink();
    out.append(months[cal.get(Calendar.MONTH)]);
    out.append(' ');
    out.append(String.valueOf(cal.get(Calendar.YEAR)));
    writeNextLink();
    out.append("</caption>");
}

From source file:net.sf.logsaw.dialect.log4j.pattern.Log4JConversionPatternTranslator.java

@Override
public void applyLocale(Locale loc, List<ConversionRule> rules) {
    for (ConversionRule rule : rules) {
        if (rule.getPlaceholderName().equals("d")) { //$NON-NLS-1$
            SimpleDateFormat df = rule.getProperty(PROP_DATEFORMAT, SimpleDateFormat.class);
            Assert.isNotNull(df, "dateFormat"); //$NON-NLS-1$
            df.setDateFormatSymbols(DateFormatSymbols.getInstance(loc));
            return;
        }/*from  ww w .j  a va2  s . com*/
    }
}

From source file:org.shredzone.cilla.site.renderer.CalendarRenderStrategyImpl.java

/**
 * Writes the headline of the calendar table. It consists of the weekdays.
 *///from ww w.  j av a  2 s  .  c o m
protected void writeHeadline() throws IOException {
    Calendar calendar = Calendar.getInstance(generator.getLocale());
    int firstDay = calendar.getFirstDayOfWeek();

    DateFormatSymbols symbols = DateFormatSymbols.getInstance(generator.getLocale());
    String[] weekdays = symbols.getShortWeekdays();

    out.append("<tr>");
    for (int wd = firstDay; wd < firstDay + 7; wd++) {
        int weekdayIndex = (wd - 1) % 7;

        String wdname = weekdays[weekdayIndex + 1];
        if (wdname.length() > 2) {
            wdname = wdname.substring(0, 2);
        }

        out.append("<th>");
        out.append(HtmlUtils.htmlEscape(wdname));
        out.append("</th>");
    }
    out.append("</tr>");
}

From source file:com.redhat.rhn.common.util.RecurringEventPicker.java

/**
 * while we could just rely on the ordering and numbering of getWeekdays,
 *  I figured it would be best to not rely on the numbers being what we want.
 * @return List of day names in order from Sunday -> Saturday
 *///from ww  w. ja v a  2  s  . com
public String[] getDayNames() {
    String[] days = DateFormatSymbols.getInstance(Context.getCurrentContext().getLocale()).getWeekdays();
    String[] toReturn = new String[7];
    for (int i = 0; i < DAY_NUMBERS.length; i++) {
        toReturn[i] = days[DAY_NUMBERS[i]];
    }
    return toReturn;
}

From source file:it.tidalwave.northernwind.frontend.ui.component.calendar.DefaultCalendarViewController.java

/*******************************************************************************************************************
 *
 *
 *
 ******************************************************************************************************************/
@PostConstruct/* w ww. ja v a  2  s.  c  om*/
/* package */ void initialize() throws NotFoundException, IOException, ParserConfigurationException,
        SAXException, XPathExpressionException, HttpStatusException {
    final String pathParams = requestHolder.get().getPathParams(siteNode);
    final int currentYear = getCurrentYear(pathParams);

    final ResourceProperties siteNodeProperties = siteNode.getProperties();
    final ResourceProperties viewProperties = siteNode.getPropertyGroup(view.getId());

    //        try
    //          {
    //            siteNodeProperties.getProperty(PROPERTY_ENTRIES);
    //          }
    //        catch (NotFoundException e)
    //          {
    //            throw new HttpStatusException(404);
    //          }

    final String entries = siteNodeProperties.getProperty(PROPERTY_ENTRIES);
    final StringBuilder builder = new StringBuilder();
    final int selectedYear = viewProperties.getIntProperty(PROPERTY_SELECTED_YEAR, currentYear);
    final int firstYear = viewProperties.getIntProperty(PROPERTY_FIRST_YEAR,
            Math.min(selectedYear, currentYear));
    final int lastYear = viewProperties.getIntProperty(PROPERTY_LAST_YEAR, Math.max(selectedYear, currentYear));
    final int columns = 4;

    builder.append("<div class='nw-calendar'>\n");
    appendTitle(builder, siteNodeProperties);

    builder.append("<table class='nw-calendar-table'>\n").append("<tbody>\n");

    builder.append(String.format("<tr>%n<th colspan='%d' class='nw-calendar-title'>%d</th>%n</tr>%n", columns,
            selectedYear));

    final String[] monthNames = DateFormatSymbols.getInstance(requestLocaleManager.getLocales().get(0))
            .getMonths();
    final String[] shortMonthNames = DateFormatSymbols.getInstance(Locale.ENGLISH).getShortMonths();

    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    final DocumentBuilder db = dbf.newDocumentBuilder();
    final Document document = db.parse(new InputSource(new StringReader(entries)));
    final XPathFactory xPathFactory = XPathFactory.newInstance();
    final XPath xPath = xPathFactory.newXPath();

    for (int month = 1; month <= 12; month++) {
        if ((month - 1) % columns == 0) {
            builder.append("<tr>\n");

            for (int column = 0; column < columns; column++) {
                builder.append(String.format("<th width='%d%%'>%s</th>", 100 / columns,
                        monthNames[month + column - 1]));
            }

            builder.append("</tr>\n<tr>\n");
        }

        builder.append("<td>\n<ul>\n");
        final String pathTemplate = "/calendar/year[@id='%d']/month[@id='%s']/item";
        final String jq1 = String.format(pathTemplate, selectedYear, shortMonthNames[month - 1].toLowerCase());
        final XPathExpression jx1 = xPath.compile(jq1);
        final NodeList nodes = (NodeList) jx1.evaluate(document, XPathConstants.NODESET);

        for (int i = 0; i < nodes.getLength(); i++) {
            // FIXME: verbose XML code below
            final Node node = nodes.item(i);
            final String link = site
                    .createLink(new ResourcePath(node.getAttributes().getNamedItem("link").getNodeValue()));

            String linkClass = "";
            Node typeNode = node.getAttributes().getNamedItem("type");

            if (typeNode != null) {
                linkClass = String.format(" class='nw-calendar-table-link-%s'", typeNode.getNodeValue());
            }

            final String name = node.getAttributes().getNamedItem("name").getNodeValue();
            builder.append(String.format("<li><a href='%s'%s>%s</a></li>%n", link, linkClass, name));
        }

        builder.append("</ul>\n</td>\n");

        if ((month - 1) % columns == (columns - 1)) {
            builder.append("</tr>\n");
        }
    }

    builder.append("</tbody>\n</table>\n");

    appendYearSelector(builder, firstYear, lastYear, selectedYear);
    builder.append("</div>\n");
    view.setContent(builder.toString());
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.SublimeTimePicker.java

private void initializeLayout() {
    mContext = getContext();/*ww  w .j  ava2s .c  o m*/
    setCurrentLocale(Locale.getDefault());

    // process style attributes
    final TypedArray a = mContext.obtainStyledAttributes(R.styleable.SublimeTimePicker);
    final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final Resources res = mContext.getResources();

    mSelectHours = res.getString(R.string.select_hours);
    mSelectMinutes = res.getString(R.string.select_minutes);

    DateFormatSymbols dfs = DateFormatSymbols.getInstance(mCurrentLocale);
    String[] amPmStrings = dfs.getAmPmStrings();/*{"AM", "PM"}*/

    if (amPmStrings.length == 2 && !TextUtils.isEmpty(amPmStrings[0]) && !TextUtils.isEmpty(amPmStrings[1])) {
        mAmText = amPmStrings[0].length() > 2 ? amPmStrings[0].substring(0, 2) : amPmStrings[0];
        mPmText = amPmStrings[1].length() > 2 ? amPmStrings[1].substring(0, 2) : amPmStrings[1];
    } else {
        // Defaults
        mAmText = "AM";
        mPmText = "PM";
    }

    final int layoutResourceId = R.layout.time_picker_layout;
    final View mainView = inflater.inflate(layoutResourceId, this);

    mHeaderView = mainView.findViewById(R.id.time_header);

    // Set up hour/minute labels.
    mHourView = (TextView) mainView.findViewById(R.id.hours);
    mHourView.setOnClickListener(mClickListener);

    ViewCompat.setAccessibilityDelegate(mHourView, new ClickActionDelegate(mContext, R.string.select_hours));

    mSeparatorView = (TextView) mainView.findViewById(R.id.separator);

    mMinuteView = (TextView) mainView.findViewById(R.id.minutes);
    mMinuteView.setOnClickListener(mClickListener);

    ViewCompat.setAccessibilityDelegate(mMinuteView,
            new ClickActionDelegate(mContext, R.string.select_minutes));

    // Now that we have text appearances out of the way, make sure the hour
    // and minute views are correctly sized.
    mHourView.setMinWidth(computeStableWidth(mHourView, 24));
    mMinuteView.setMinWidth(computeStableWidth(mMinuteView, 60));

    // Set up AM/PM labels.
    mAmPmLayout = mainView.findViewById(R.id.ampm_layout);
    mAmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.am_label);
    mAmLabel.setText(obtainVerbatim(amPmStrings[0]));
    mAmLabel.setOnClickListener(mClickListener);
    mPmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.pm_label);
    mPmLabel.setText(obtainVerbatim(amPmStrings[1]));
    mPmLabel.setOnClickListener(mClickListener);

    ColorStateList headerTextColor = a.getColorStateList(R.styleable.SublimeTimePicker_spHeaderTextColor);

    if (headerTextColor != null) {
        mHourView.setTextColor(headerTextColor);
        mSeparatorView.setTextColor(headerTextColor);
        mMinuteView.setTextColor(headerTextColor);
        mAmLabel.setTextColor(headerTextColor);
        mPmLabel.setTextColor(headerTextColor);
    }

    // Set up header background, if available.
    if (SUtils.isApi_22_OrHigher()) {
        if (a.hasValueOrEmpty(R.styleable.SublimeTimePicker_spHeaderBackground)) {
            SUtils.setViewBackground(mHeaderView,
                    a.getDrawable(R.styleable.SublimeTimePicker_spHeaderBackground));
        }
    } else {
        if (a.hasValue(R.styleable.SublimeTimePicker_spHeaderBackground)) {
            SUtils.setViewBackground(mHeaderView,
                    a.getDrawable(R.styleable.SublimeTimePicker_spHeaderBackground));
        }
    }

    a.recycle();

    mRadialTimePickerView = (RadialTimePickerView) mainView.findViewById(R.id.radial_picker);

    setupListeners();

    mAllowAutoAdvance = true;

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();

    // Initialize with current time
    final Calendar calendar = Calendar.getInstance(mCurrentLocale);
    final int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
    final int currentMinute = calendar.get(Calendar.MINUTE);
    initialize(currentHour, currentMinute, false /* 12h */, HOUR_INDEX);
}

From source file:de.undercouch.citeproc.bibtex.DateParser.java

/**
 * Retrieves and caches a list of month names for a given locale
 * @param locale the locale//from w w  w.ja va  2s .  c o  m
 * @return the list of month names (short and long). All names are
 * converted to upper case
 */
private static Map<String, Integer> getMonthNames(Locale locale) {
    Map<String, Integer> r = MONTH_NAMES_CACHE.get(locale);
    if (r == null) {
        DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale);
        r = new HashMap<String, Integer>(24);

        //insert long month names
        String[] months = symbols.getMonths();
        for (int i = 0; i < months.length; ++i) {
            String m = months[i];
            if (!m.isEmpty()) {
                r.put(m.toUpperCase(), i + 1);
            }
        }

        //insert short month names
        String[] shortMonths = symbols.getShortMonths();
        for (int i = 0; i < shortMonths.length; ++i) {
            String m = shortMonths[i];
            if (!m.isEmpty()) {
                r.put(m.toUpperCase(), i + 1);
            }
        }
        MONTH_NAMES_CACHE.put(locale, r);
    }

    return r;
}

From source file:net.sf.logsaw.dialect.websphere.WebsphereDialect.java

private DateFormat getDateFormat(Locale loc) throws CoreException {
    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, loc);
    if (!(df instanceof SimpleDateFormat)) {
        return null;
    }//  w ww .  j av a2 s.c  om
    try {
        // Always use US locale for date format symbols
        return new SimpleDateFormat(((SimpleDateFormat) df).toPattern() + " " + TIME_FORMAT, //$NON-NLS-1$
                DateFormatSymbols.getInstance(Locale.US));
    } catch (RuntimeException e) {
        // Could also be ClassCastException
        throw new CoreException(new Status(IStatus.ERROR, WebsphereDialectPlugin.PLUGIN_ID,
                NLS.bind(Messages.WebsphereDialect_error_dateFormatNotSupported, loc.toString())));
    }
}