Example usage for java.text DateFormatSymbols DateFormatSymbols

List of usage examples for java.text DateFormatSymbols DateFormatSymbols

Introduction

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

Prototype

private DateFormatSymbols(boolean flag) 

Source Link

Document

Constructs an uninitialized DateFormatSymbols.

Usage

From source file:com.marcohc.robotocalendar.RobotoCalendarView.java

@SuppressLint("DefaultLocale")
private void initializeTitleLayout() {

    String dateText = new DateFormatSymbols(locale).getMonths()[currentCalendar.get(Calendar.MONTH)];
    dateText = dateText.substring(0, 1).toUpperCase() + dateText.subSequence(1, dateText.length());
    Calendar calendar = Calendar.getInstance();
    //        if (currentCalendar.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)) {
    //            dateTitle.setText(dateText);
    //        } else {
    dateTitle.setText(String.format("%s %s", dateText, currentCalendar.get(Calendar.YEAR)));
    //        }//from   w  ww  .j  a  v  a 2s .c  o m
}

From source file:org.sqlite.date.FastDatePrinter.java

/**
 * <p>Returns a list of Rules given a pattern.</p>
 *
 * @return a {@code List} of Rule objects
 * @throws IllegalArgumentException if pattern is invalid
 *//*from   w  w w  .j  av a  2 s.c o m*/
protected List<Rule> parsePattern() {
    final DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
    final List<Rule> rules = new ArrayList<Rule>();

    final String[] ERAs = symbols.getEras();
    final String[] months = symbols.getMonths();
    final String[] shortMonths = symbols.getShortMonths();
    final String[] weekdays = symbols.getWeekdays();
    final String[] shortWeekdays = symbols.getShortWeekdays();
    final String[] AmPmStrings = symbols.getAmPmStrings();

    final int length = mPattern.length();
    final int[] indexRef = new int[1];

    for (int i = 0; i < length; i++) {
        indexRef[0] = i;
        final String token = parseToken(mPattern, indexRef);
        i = indexRef[0];

        final int tokenLen = token.length();
        if (tokenLen == 0) {
            break;
        }

        Rule rule;
        final char c = token.charAt(0);

        switch (c) {
        case 'G': // era designator (text)
            rule = new TextField(Calendar.ERA, ERAs);
            break;
        case 'y': // year (number)
            if (tokenLen == 2) {
                rule = TwoDigitYearField.INSTANCE;
            } else {
                rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen);
            }
            break;
        case 'M': // month in year (text and number)
            if (tokenLen >= 4) {
                rule = new TextField(Calendar.MONTH, months);
            } else if (tokenLen == 3) {
                rule = new TextField(Calendar.MONTH, shortMonths);
            } else if (tokenLen == 2) {
                rule = TwoDigitMonthField.INSTANCE;
            } else {
                rule = UnpaddedMonthField.INSTANCE;
            }
            break;
        case 'd': // day in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
            break;
        case 'h': // hour in am/pm (number, 1..12)
            rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
            break;
        case 'H': // hour in day (number, 0..23)
            rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
            break;
        case 'm': // minute in hour (number)
            rule = selectNumberRule(Calendar.MINUTE, tokenLen);
            break;
        case 's': // second in minute (number)
            rule = selectNumberRule(Calendar.SECOND, tokenLen);
            break;
        case 'S': // millisecond (number)
            rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
            break;
        case 'E': // day in week (text)
            rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
            break;
        case 'D': // day in year (number)
            rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
            break;
        case 'F': // day of week in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
            break;
        case 'w': // week in year (number)
            rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
            break;
        case 'W': // week in month (number)
            rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
            break;
        case 'a': // am/pm marker (text)
            rule = new TextField(Calendar.AM_PM, AmPmStrings);
            break;
        case 'k': // hour in day (1..24)
            rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
            break;
        case 'K': // hour in am/pm (0..11)
            rule = selectNumberRule(Calendar.HOUR, tokenLen);
            break;
        case 'X': // ISO 8601 
            rule = Iso8601_Rule.getRule(tokenLen);
            break;
        case 'z': // time zone (text)
            if (tokenLen >= 4) {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG);
            } else {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT);
            }
            break;
        case 'Z': // time zone (value)
            if (tokenLen == 1) {
                rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
            } else if (tokenLen == 2) {
                rule = TimeZoneNumberRule.INSTANCE_ISO_8601;
            } else {
                rule = TimeZoneNumberRule.INSTANCE_COLON;
            }
            break;
        case '\'': // literal text
            final String sub = token.substring(1);
            if (sub.length() == 1) {
                rule = new CharacterLiteral(sub.charAt(0));
            } else {
                rule = new StringLiteral(sub);
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal pattern component: " + token);
        }

        rules.add(rule);
    }

    return rules;
}

From source file:com.qtplaf.library.util.Calendar.java

/**
 * Returns an array of localized names of week days.
 *
 * @return An array of names./*from ww  w  .j  a v  a2 s  .  c o m*/
 * @param locale The desired locale.
 * @param capitalized A boolean to capitalize the name.
 */
public static String[] getLongDays(Locale locale, boolean capitalized) {

    DateFormatSymbols sysd = new DateFormatSymbols(locale);
    String[] dsc = sysd.getWeekdays();
    if (capitalized) {
        for (int i = 0; i < dsc.length; i++) {
            dsc[i] = StringUtils.capitalize(dsc[i]);
        }
    }
    return dsc;
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDatePrinter.java

/**
 * <p>Returns a list of Rules given a pattern.</p>
 *
 * @return a {@code List} of Rule objects
 * @throws IllegalArgumentException if pattern is invalid
 *//*from   www  . j a  v  a2s .co m*/
protected List<Rule> parsePattern() {
    final DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
    final List<Rule> rules = new ArrayList<>();

    final String[] ERAs = symbols.getEras();
    final String[] months = symbols.getMonths();
    final String[] shortMonths = symbols.getShortMonths();
    final String[] weekdays = symbols.getWeekdays();
    final String[] shortWeekdays = symbols.getShortWeekdays();
    final String[] AmPmStrings = symbols.getAmPmStrings();

    final int length = mPattern.length();
    final int[] indexRef = new int[1];

    for (int i = 0; i < length; i++) {
        indexRef[0] = i;
        final String token = parseToken(mPattern, indexRef);
        i = indexRef[0];

        final int tokenLen = token.length();
        if (tokenLen == 0) {
            break;
        }

        Rule rule;
        final char c = token.charAt(0);

        switch (c) {
        case 'G': // era designator (text)
            rule = new TextField(Calendar.ERA, ERAs);
            break;
        case 'y': // year (number)
        case 'Y': // week year
            if (tokenLen == 2) {
                rule = TwoDigitYearField.INSTANCE;
            } else {
                rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen);
            }
            if (c == 'Y') {
                rule = new WeekYear((NumberRule) rule);
            }
            break;
        case 'M': // month in year (text and number)
            if (tokenLen >= 4) {
                rule = new TextField(Calendar.MONTH, months);
            } else if (tokenLen == 3) {
                rule = new TextField(Calendar.MONTH, shortMonths);
            } else if (tokenLen == 2) {
                rule = TwoDigitMonthField.INSTANCE;
            } else {
                rule = UnpaddedMonthField.INSTANCE;
            }
            break;
        case 'd': // day in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
            break;
        case 'h': // hour in am/pm (number, 1..12)
            rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
            break;
        case 'H': // hour in day (number, 0..23)
            rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
            break;
        case 'm': // minute in hour (number)
            rule = selectNumberRule(Calendar.MINUTE, tokenLen);
            break;
        case 's': // second in minute (number)
            rule = selectNumberRule(Calendar.SECOND, tokenLen);
            break;
        case 'S': // millisecond (number)
            rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
            break;
        case 'E': // day in week (text)
            rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
            break;
        case 'u': // day in week (number)
            rule = new DayInWeekField(selectNumberRule(Calendar.DAY_OF_WEEK, tokenLen));
            break;
        case 'D': // day in year (number)
            rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
            break;
        case 'F': // day of week in month (number)
            rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
            break;
        case 'w': // week in year (number)
            rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
            break;
        case 'W': // week in month (number)
            rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
            break;
        case 'a': // am/pm marker (text)
            rule = new TextField(Calendar.AM_PM, AmPmStrings);
            break;
        case 'k': // hour in day (1..24)
            rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
            break;
        case 'K': // hour in am/pm (0..11)
            rule = selectNumberRule(Calendar.HOUR, tokenLen);
            break;
        case 'X': // ISO 8601 
            rule = Iso8601_Rule.getRule(tokenLen);
            break;
        case 'z': // time zone (text)
            if (tokenLen >= 4) {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG);
            } else {
                rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT);
            }
            break;
        case 'Z': // time zone (value)
            if (tokenLen == 1) {
                rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
            } else if (tokenLen == 2) {
                rule = Iso8601_Rule.ISO8601_HOURS_COLON_MINUTES;
            } else {
                rule = TimeZoneNumberRule.INSTANCE_COLON;
            }
            break;
        case '\'': // literal text
            final String sub = token.substring(1);
            if (sub.length() == 1) {
                rule = new CharacterLiteral(sub.charAt(0));
            } else {
                rule = new StringLiteral(sub);
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal pattern component: " + token);
        }

        rules.add(rule);
    }

    return rules;
}

From source file:com.marcohc.robotocalendar.RobotoCalendarView.java

@SuppressLint("DefaultLocale")
private void initializeWeekDaysLayout() {

    TextView dayOfWeek;//  ww w. ja va  2 s.  com
    String dayOfTheWeekString;
    String[] weekDaysArray = new DateFormatSymbols(locale).getShortWeekdays();
    for (int i = 1; i < weekDaysArray.length; i++) {
        dayOfWeek = (TextView) view.findViewWithTag(DAY_OF_WEEK + getWeekIndex(i, currentCalendar));
        dayOfTheWeekString = weekDaysArray[i];
        dayOfTheWeekString = checkSpecificLocales(dayOfTheWeekString, i);
        dayOfWeek.setText(dayOfTheWeekString);
    }
}

From source file:CalendarUtils.java

/**
 * Parses strings the way that CVS supports it... very human readable
 *///www.j ava 2s . com
public static Calendar parse(String original, Locale locale) {
    //Get the symbol names
    DateFormatSymbols symbols = new DateFormatSymbols(locale);

    //Prep the string to parse
    String value = original.toLowerCase().trim();

    //Get the current date/time
    Calendar now = Calendar.getInstance();
    if (value.endsWith(" ago")) {
        //If this was a date that was "ago" the current time...
        //Strip out the ' ago' part
        value = value.substring(0, value.length() - 4);

        //Split the value and unit
        int start = value.indexOf(" ");
        if (start < 0) {
            throw new RuntimeException("Could not find space in between value and unit");
        }
        String unit = value.substring(start + 1);
        value = value.substring(0, start);
        //We support "a week", so we need to parse the value as "a"
        int val = 0;
        if (value.equals("a") || value.equals("an")) {
            val = 1;
        } else {
            val = Integer.parseInt(value);
        }

        //Determine the unit
        if (unit.equals("milliseconds") || unit.equals("millisecond")) {
            now.add(Calendar.MILLISECOND, -val);
        } else if (unit.equals("seconds") || unit.equals("second")) {
            now.add(Calendar.SECOND, -val);
        } else if (unit.equals("minutes") || unit.equals("minute")) {
            now.add(Calendar.MINUTE, -val);
        } else if (unit.equals("hours") || unit.equals("hour")) {
            now.add(Calendar.HOUR, -val);
        } else if (unit.equals("days") || unit.equals("day")) {
            now.add(Calendar.DATE, -val);
        } else if (unit.equals("weeks") || unit.equals("week")) {
            now.add(Calendar.DATE, -val * 7);
        } else if (unit.equals("fortnights") || unit.equals("fortnight")) {
            now.add(Calendar.DATE, -val * 14);
        } else if (unit.equals("months") || unit.equals("month")) {
            now.add(Calendar.MONTH, -val);
        } else if (unit.equals("years") || unit.equals("year")) {
            now.add(Calendar.YEAR, -val);
        } else {
            throw new RuntimeException("We do not understand that many units ago");
        }
        return now;
    } else if (value.startsWith("last ")) {
        //If this was the last time a certain field was met
        //Strip out the 'last ' part
        value = value.substring(5);
        //Get the current date/time
        String[] strings = symbols.getWeekdays();
        for (int i = 0; i < strings.length; i++) {
            if (value.equalsIgnoreCase(strings[i])) {
                //How many days after Sunday
                int daysAgo = now.get(Calendar.DAY_OF_WEEK) - i;
                if (daysAgo <= 0) {
                    daysAgo += 7;
                }
                now.add(Calendar.DATE, -daysAgo);
                return now;
            }
        }
        strings = symbols.getMonths();
        for (int i = 0; i < strings.length; i++) {
            if (value.equalsIgnoreCase(strings[i])) {
                //How many days after January
                int monthsAgo = now.get(Calendar.MONTH) - i;
                if (monthsAgo <= 0) {
                    monthsAgo += 12;
                }
                now.add(Calendar.MONTH, -monthsAgo);
                return now;
            }
        }
        if (value.equals("week")) {
            now.add(Calendar.DATE, -7);
            return now;
        }
    } else if (value.equals("yesterday")) {
        now.add(Calendar.DATE, -1);
        return now;
    } else if (value.equals("tomorrow")) {
        now.add(Calendar.DATE, 1);
        return now;
    }
    //Try to parse the date a number of different ways
    for (int i = 0; i < dateFormats.length; i++) {
        try {
            Date datetime = dateFormats[i].parse(original);
            Calendar cal = Calendar.getInstance();
            cal.setTime(datetime);
            return cal;
        } catch (ParseException pe) {
            //we ignore this and just keep trying
        }
    }

    throw new RuntimeException("Unable to parse '" + original + "'.");
}

From source file:com.qtplaf.library.util.Calendar.java

/**
 * Returns an array of localized names of months.
 *
 * @return An array of names.//ww  w  .  jav  a2s.  c  o  m
 * @param locale The desired locale.
 * @param capitalized A boolean to capitalize the name.
 */
public static String[] getLongMonths(Locale locale, boolean capitalized) {

    DateFormatSymbols sysd = new DateFormatSymbols(locale);
    String[] dsc = sysd.getMonths();
    if (capitalized) {
        for (int i = 0; i < dsc.length; i++) {
            dsc[i] = StringUtils.capitalize(dsc[i]);
        }
    }
    return dsc;
}

From source file:org.glimpse.server.news.sax.ChannelHandler.java

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (Type.ATOM.equals(type)) {
        String path = getCurrentPath();
        if (path.equals("/feed/title")) {
            title = buffer.toString();//  www  .ja  v  a2  s .co m
        } else if (path.equals("/feed/entry")) {
            String content = currentContent;
            if (StringUtils.isBlank(content)) {
                content = currentSummary == null ? "" : currentSummary;
                content += "<p><a href=\"" + currentEntry.getUrl()
                        + "\" target=\"_blank\">Lire la suite</a></p>";
            }
            currentEntry.setContent(content);

            if (StringUtils.isNotBlank(currentEntry.getId()) && StringUtils.isNotBlank(currentEntry.getTitle())
                    && StringUtils.isNotBlank(currentEntry.getUrl())) {
                entries.add(currentEntry);
            }

            currentEntry = null;
            currentContent = null;
            currentSummary = null;
        } else if (path.equals("/feed/entry/id")) {
            currentEntry.setId(buffer.toString());
        } else if (path.equals("/feed/entry/title")) {
            currentEntry.setTitle(buffer.toString());
        } else if (path.equals("/feed/entry/updated")) {
            String updated = buffer.toString();
            if (StringUtils.length(updated) > 19) {
                try {
                    Date date = null;
                    if (updated.endsWith("Z")) {
                        // No timezone
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                        formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
                        date = formatter.parse(updated.substring(0, 19));
                    } else {
                        String timezone = updated.substring(updated.length() - 6);
                        timezone = timezone.substring(0, 3) + timezone.substring(4);
                        updated = updated.substring(0, 19) + timezone;
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
                        formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
                        date = formatter.parse(updated);
                    }
                    if (date != null) {
                        currentEntry.setDate(date);
                    }
                } catch (Exception e) {
                    // unparsable date
                    logger.warn("Unable to parse date <" + updated + ">", e);
                }
            }
        } else if (path.equals("/feed/entry/content")) {
            currentContent = buffer.toString();
        } else if (path.equals("/feed/entry/summary")) {
            currentSummary = buffer.toString();
        }
    } else if (Type.RSS_2_0.equals(type)) {
        String path = getCurrentPath();
        if (path.equals("/rss/channel/title")) {
            title = buffer.toString();
        } else if (path.equals("/rss/channel/link")) {
            url = buffer.toString();
        } else if (path.equals("/rss/channel/item")) {
            String content = currentSummary == null ? "" : currentSummary;
            content += "<p><a href=\"" + currentEntry.getUrl() + "\" target=\"_blank\">Lire la suite</a></p>";
            currentEntry.setContent(content);

            if (StringUtils.isBlank(currentEntry.getId()) && currentEntry.getDate() != null) {
                currentEntry.setId(currentEntry.getDate().toString());
            }

            if (StringUtils.isBlank(currentEntry.getUrl())) {
                currentEntry.setUrl(url);
            }

            if (StringUtils.isNotBlank(currentEntry.getId()) && StringUtils.isNotBlank(currentEntry.getTitle())
                    && StringUtils.isNotBlank(currentEntry.getUrl())) {
                entries.add(currentEntry);
            }

            currentEntry = null;
            currentContent = null;
            currentSummary = null;
        } else if (path.equals("/rss/channel/item/link")) {
            currentEntry.setId(buffer.toString());
            currentEntry.setUrl(buffer.toString());
        } else if (path.equals("/rss/channel/item/title")) {
            currentEntry.setTitle(buffer.toString());
        } else if (path.equals("/rss/channel/item/pubDate")) {
            String pubDate = buffer.toString();
            if (StringUtils.isNotBlank(pubDate)) {
                SimpleDateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
                formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
                formatter.setDateFormatSymbols(new DateFormatSymbols(Locale.ENGLISH));
                try {
                    Date date = formatter.parse(pubDate);
                    currentEntry.setDate(date);
                } catch (Exception e) {
                    // unparsable date
                    logger.debug("Unable to parse date <" + pubDate + ">", e);
                }
            }
        } else if (path.equals("/rss/channel/item/description")) {
            currentSummary = buffer.toString();
        } else if (path.equals("/rss/channel/item/enclosure/url")) {
            currentEnclosure.setUrl(buffer.toString());
        } else if (path.equals("/rss/channel/item/enclosure/type")) {
            currentEnclosure.setType(buffer.toString());
        }
    } else if (Type.RSS_1_0.equals(type)) {
        String path = getCurrentPath();
        if (path.equals("/rdf:RDF/channel/title")) {
            title = buffer.toString();
        } else if (path.equals("/rdf:RDF/channel/link")) {
            url = buffer.toString();
        } else if (path.equals("/rdf:RDF/item")) {
            String content = currentSummary == null ? "" : currentSummary;
            content += "<p><a href=\"" + currentEntry.getUrl() + "\" target=\"_blank\">Lire la suite</a></p>";
            currentEntry.setContent(content);

            if (StringUtils.isBlank(currentEntry.getUrl())) {
                currentEntry.setUrl(url);
            }

            if (StringUtils.isNotBlank(currentEntry.getId()) && StringUtils.isNotBlank(currentEntry.getTitle())
                    && StringUtils.isNotBlank(currentEntry.getUrl())) {
                entries.add(currentEntry);
            }

            currentEntry = null;
            currentContent = null;
            currentSummary = null;
        } else if (path.equals("/rdf:RDF/item/title")) {
            currentEntry.setTitle(buffer.toString());
        } else if (path.equals("/rdf:RDF/item/link")) {
            currentEntry.setId(buffer.toString());
            currentEntry.setUrl(buffer.toString());
        } else if (path.equals("/rdf:RDF/item/description")) {
            currentSummary = buffer.toString();
        } else if (path.equals("/rdf:RDF/item/dc:date")) {
            String updated = buffer.toString();
            if (StringUtils.length(updated) > 19) {
                try {
                    Date date = null;
                    if (updated.endsWith("Z")) {
                        // No timezone
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                        formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
                        date = formatter.parse(updated.substring(0, 19));
                    } else {
                        String timezone = updated.substring(updated.length() - 6);
                        timezone = timezone.substring(0, 3) + timezone.substring(4);
                        updated = updated.substring(0, 19) + timezone;
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
                        formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
                        date = formatter.parse(updated);
                    }
                    if (date != null) {
                        currentEntry.setDate(date);
                    }
                } catch (Exception e) {
                    // unparsable date
                    logger.warn("Unable to parse date <" + updated + ">", e);
                }
            }
        }
    }

    String s = elementsStack.remove(elementsStack.size() - 1);
    assert s.equals(qName);
}

From source file:com.jarklee.materialdatetimepicker.time.TimePickerDialog.java

private void updateLocale() {
    String[] amPmTexts = new DateFormatSymbols(getLocale()).getAmPmStrings();
    mAmText = amPmTexts[0];/*from w w w  .  j  av  a2  s  .  com*/
    mPmText = amPmTexts[1];
    if (mTimePicker != null) {
        mTimePicker.updateLocale();
    }
    if (!isVisible()) {
        return;
    }
    Context context = getContext();
    if (context != null) {
        if (mOkButton != null) {
            if (mOkString != null) {
                mOkButton.setText(mOkString);
            } else {
                mOkButton.setText(Utils.getStringFromLocale(getContext(), mOkResid, getLocale()));
            }
        }
        if (mCancelButton != null) {
            if (mCancelString != null) {
                mCancelButton.setText(mCancelString);
            } else {
                mCancelButton.setText(Utils.getStringFromLocale(getContext(), mCancelResid, getLocale()));
            }
        }
    }
    updateDisplay(false);
}

From source file:org.saiku.reporting.backend.component.ReportContentUtil.java

private static Object convert(final ParameterContext context, final ParameterDefinitionEntry parameter,
        final Class targetType, final Object rawValue) throws ReportProcessingException {
    if (targetType == null) {
        throw new NullPointerException();
    }//from   ww w.  j  a  v  a2 s.  c  om

    if (rawValue == null) {
        return null;
    }
    if (targetType.isInstance(rawValue)) {
        return rawValue;
    }

    //TODO:    
    //    if (targetType.isAssignableFrom(TableModel.class) && IPentahoResultSet.class.isAssignableFrom(rawValue.getClass()))
    //    {
    //      // wrap IPentahoResultSet to simulate TableModel
    //      return new PentahoTableModel((IPentahoResultSet) rawValue);
    //    }

    final String valueAsString = String.valueOf(rawValue);
    if (StringUtils.isEmpty(valueAsString)) {
        // none of the converters accept empty strings as valid input. So we can return null instead.
        return null;
    }

    if (targetType.equals(Timestamp.class)) {
        try {
            final Date date = parseDate(parameter, context, valueAsString);
            return new Timestamp(date.getTime());
        } catch (ParseException pe) {
            // ignore, we try to parse it as real date now ..
        }
    } else if (targetType.equals(Time.class)) {
        try {
            final Date date = parseDate(parameter, context, valueAsString);
            return new Time(date.getTime());
        } catch (ParseException pe) {
            // ignore, we try to parse it as real date now ..
        }
    } else if (targetType.equals(java.sql.Date.class)) {
        try {
            final Date date = parseDate(parameter, context, valueAsString);
            return new java.sql.Date(date.getTime());
        } catch (ParseException pe) {
            // ignore, we try to parse it as real date now ..
        }
    } else if (targetType.equals(Date.class)) {
        try {
            final Date date = parseDate(parameter, context, valueAsString);
            return new Date(date.getTime());
        } catch (ParseException pe) {
            // ignore, we try to parse it as real date now ..
        }
    }

    final String dataFormat = parameter.getParameterAttribute(ParameterAttributeNames.Core.NAMESPACE,
            ParameterAttributeNames.Core.DATA_FORMAT, context);
    if (dataFormat != null) {
        try {
            if (Number.class.isAssignableFrom(targetType)) {
                final DecimalFormat format = new DecimalFormat(dataFormat,
                        new DecimalFormatSymbols(Locale.getDefault()));
                format.setParseBigDecimal(true);
                final Number number = format.parse(valueAsString);
                final String asText = ConverterRegistry.toAttributeValue(number);
                return ConverterRegistry.toPropertyValue(asText, targetType);
            } else if (Date.class.isAssignableFrom(targetType)) {
                final SimpleDateFormat format = new SimpleDateFormat(dataFormat,
                        new DateFormatSymbols(Locale.getDefault()));
                format.setLenient(false);
                final Date number = format.parse(valueAsString);
                final String asText = ConverterRegistry.toAttributeValue(number);
                return ConverterRegistry.toPropertyValue(asText, targetType);
            }
        } catch (Exception e) {
            // again, ignore it .
        }
    }

    final ValueConverter valueConverter = ConverterRegistry.getInstance().getValueConverter(targetType);
    if (valueConverter != null) {
        try {
            return valueConverter.toPropertyValue(valueAsString);
        } catch (BeanException e) {
            throw new ReportProcessingException(
                    "ReportPlugin.unableToConvertParameter " + parameter.getName() + " " + valueAsString); //$NON-NLS-1$
        }
    }
    return rawValue;
}