Example usage for java.text DateFormatSymbols getAmPmStrings

List of usage examples for java.text DateFormatSymbols getAmPmStrings

Introduction

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

Prototype

public String[] getAmPmStrings() 

Source Link

Document

Gets ampm strings.

Usage

From source file:com.application.utils.FastDateParser.java

private static String[] getDisplayNameArray(int field, boolean isLong, Locale locale) {
    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    switch (field) {
    case Calendar.AM_PM:
        return dfs.getAmPmStrings();
    case Calendar.DAY_OF_WEEK:
        return isLong ? dfs.getWeekdays() : dfs.getShortWeekdays();
    case Calendar.ERA:
        return dfs.getEras();
    case Calendar.MONTH:
        return isLong ? dfs.getMonths() : dfs.getShortMonths();
    }//from  ww  w.  j  a v a  2s .c  o m
    return null;
}

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

private void initializeLayout() {
    mContext = getContext();//from  ww w .  j  av  a 2  s. com
    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:com.application.utils.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 ww.  ja va2  s  . c  om
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 '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 {
                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: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 www  . ja v  a 2 s.com
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: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
 *//*ww  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<>();

    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:DateFormatUtils.java

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

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

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

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

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

        Rule rule;
        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 >= 4) {
                rule = selectNumberRule(Calendar.YEAR, tokenLen);
            } else {
                rule = TwoDigitYearField.INSTANCE;
            }
            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 'z': // time zone (text)
            if (tokenLen >= 4) {
                rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.LONG);
            } else {
                rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.SHORT);
            }
            break;
        case 'Z': // time zone (value)
            if (tokenLen == 1) {
                rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
            } else {
                rule = TimeZoneNumberRule.INSTANCE_COLON;
            }
            break;
        case '\'': // literal text
            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:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java

/**
 * Creates and returns a String which contains the initialisation data for
 * the popup calendar control as a sequence of javascript commands that
 * assign values to properties of a javascript object whose name is in
 * parameter popupCalendarVariable.//from w  w w  . j  av a  2 s .c o m
 * <p>
 * 
 * @param firstDayOfWeek
 *            is in java.util.Calendar form, ie Sun=1, Mon=2, Sat=7
 */
public static String getLocalizedLanguageScript(FacesContext facesContext, DateFormatSymbols symbols,
        int firstDayOfWeek, UIComponent uiComponent, String popupCalendarVariable) {

    // Convert day value to java.util.Date convention (Sun=0, Mon=1, Sat=6).
    // This is the convention that javascript Date objects use.
    int realFirstDayOfWeek = firstDayOfWeek - 1;

    String[] weekDays;

    if (realFirstDayOfWeek == 0) {
        // Sunday
        weekDays = mapShortWeekdaysStartingWithSunday(symbols);
    } else if (realFirstDayOfWeek == 1) {
        // Monday
        weekDays = mapShortWeekdays(symbols);
    } else if (realFirstDayOfWeek == 6) {
        // Saturday. Often used in Arabic countries
        weekDays = mapShortWeekdaysStartingWithSaturday(symbols);
    } else {
        throw new IllegalStateException("Week may only start with saturday, sunday or monday.");
    }

    StringBuffer script = new StringBuffer();
    AddResource ar = AddResourceFactory.getInstance(facesContext);

    if (uiComponent instanceof HtmlInputCalendar) {
        HtmlInputCalendar calendar = (HtmlInputCalendar) uiComponent;
        // Set the themePrefix variable
        String popupTheme = calendar.getPopupTheme();
        if (popupTheme == null) {
            popupTheme = "DB";
        }
        setStringVariable(script, popupCalendarVariable + ".initData.themePrefix", "jscalendar-" + popupTheme);

        // specify the URL for the directory in which all the .gif images
        // can be found
        String imageLocation = HtmlRendererUtils.getImageLocation(uiComponent);
        if (imageLocation == null) {
            String imageLibrary = (String) uiComponent.getAttributes()
                    .get(LibraryLocationAware.IMAGE_LIBRARY_ATTR);
            if (imageLibrary == null) {
                //String uri = ar.getResourceUri(facesContext, HtmlCalendarRenderer.class, popupTheme
                //        + "/");
                //setStringVariable(script, popupCalendarVariable + ".initData.imgDir",
                //        JavascriptUtils.encodeString(uri));
                Resource resource = facesContext.getApplication().getResourceHandler().createResource(";j",
                        "oam.custom.calendar"
                                + ((popupTheme != null && popupTheme.length() > 0) ? "." + popupTheme : ""));
                String path = resource.getRequestPath();
                int index = path.indexOf("/;j");
                String prefix = path.substring(0, index + 1);
                String suffix = path.substring(index + 3);
                setStringVariable(script, popupCalendarVariable + ".initData.imgDir", prefix);
                setStringVariable(script, popupCalendarVariable + ".initData.imgDirSuffix", suffix);
            } else {
                Resource resource = facesContext.getApplication().getResourceHandler().createResource(";j",
                        imageLibrary);
                String path = resource.getRequestPath();
                int index = path.indexOf("/;j");
                String prefix = path.substring(0, index + 1);
                String suffix = path.substring(index + 3);
                setStringVariable(script, popupCalendarVariable + ".initData.imgDir", prefix);
                setStringVariable(script, popupCalendarVariable + ".initData.imgDirSuffix", suffix);
            }
        } else {
            setStringVariable(script, popupCalendarVariable + ".initData.imgDir",
                    (JavascriptUtils.encodeString(AddResourceFactory.getInstance(facesContext)
                            .getResourceUri(facesContext, imageLocation + "/"))));
            setStringVariable(script, popupCalendarVariable + ".initData.imgDirSuffix", "");
        }
    } else {
        String imageLocation = HtmlRendererUtils.getImageLocation(uiComponent);
        if (imageLocation == null) {
            String imageLibrary = (String) uiComponent.getAttributes()
                    .get(LibraryLocationAware.IMAGE_LIBRARY_ATTR);
            if (imageLibrary == null) {
                //String uri = ar.getResourceUri(facesContext, HtmlCalendarRenderer.class, "images/");
                //setStringVariable(script, popupCalendarVariable + ".initData.imgDir",
                ///        JavascriptUtils.encodeString(uri));
                //setStringVariable(script, popupCalendarVariable + ".initData.imgDirSuffix","");
                Resource resource = facesContext.getApplication().getResourceHandler().createResource(";j",
                        "oam.custom.calendar.images");
                String path = resource.getRequestPath();
                int index = path.indexOf("/;j");
                String prefix = path.substring(0, index + 1);
                String suffix = path.substring(index + 3);
                setStringVariable(script, popupCalendarVariable + ".initData.imgDir", prefix);
                setStringVariable(script, popupCalendarVariable + ".initData.imgDirSuffix", suffix);
            } else {
                Resource resource = facesContext.getApplication().getResourceHandler().createResource(";j",
                        imageLibrary);
                String path = resource.getRequestPath();
                int index = path.indexOf("/;j");
                String prefix = path.substring(0, index + 1);
                String suffix = path.substring(index + 3);
                setStringVariable(script, popupCalendarVariable + ".initData.imgDir", prefix);
                setStringVariable(script, popupCalendarVariable + ".initData.imgDirSuffix", suffix);
            }
        } else {
            setStringVariable(script, popupCalendarVariable + ".initData.imgDir",
                    (JavascriptUtils.encodeString(AddResourceFactory.getInstance(facesContext)
                            .getResourceUri(facesContext, imageLocation + "/"))));
            setStringVariable(script, popupCalendarVariable + ".initData.imgDirSuffix", "");
        }
    }
    defineStringArray(script, popupCalendarVariable + ".initData.monthName", mapMonths(symbols));
    defineStringArray(script, popupCalendarVariable + ".initData.dayName", weekDays);
    setIntegerVariable(script, popupCalendarVariable + ".initData.startAt", realFirstDayOfWeek);

    defineStringArray(script, popupCalendarVariable + ".dateFormatSymbols.weekdays",
            mapWeekdaysStartingWithSunday(symbols));
    defineStringArray(script, popupCalendarVariable + ".dateFormatSymbols.shortWeekdays",
            mapShortWeekdaysStartingWithSunday(symbols));
    defineStringArray(script, popupCalendarVariable + ".dateFormatSymbols.shortMonths",
            mapShortMonths(symbols));
    defineStringArray(script, popupCalendarVariable + ".dateFormatSymbols.months", mapMonths(symbols));
    defineStringArray(script, popupCalendarVariable + ".dateFormatSymbols.eras", symbols.getEras());
    defineStringArray(script, popupCalendarVariable + ".dateFormatSymbols.ampms", symbols.getAmPmStrings());

    if (uiComponent instanceof HtmlInputCalendar) {

        HtmlInputCalendar inputCalendar = (HtmlInputCalendar) uiComponent;

        if (inputCalendar.getPopupGotoString() != null)
            setStringVariable(script, popupCalendarVariable + ".initData.gotoString",
                    inputCalendar.getPopupGotoString());
        if (inputCalendar.getPopupTodayString() != null)
            setStringVariable(script, popupCalendarVariable + ".initData.todayString",
                    inputCalendar.getPopupTodayString());
        if (inputCalendar.getPopupTodayDateFormat() != null)
            setStringVariable(script, popupCalendarVariable + ".initData.todayDateFormat",
                    inputCalendar.getPopupTodayDateFormat());
        else if (inputCalendar.getPopupDateFormat() != null)
            setStringVariable(script, popupCalendarVariable + ".initData.todayDateFormat",
                    inputCalendar.getPopupDateFormat());
        if (inputCalendar.getPopupWeekString() != null)
            setStringVariable(script, popupCalendarVariable + ".initData.weekString",
                    inputCalendar.getPopupWeekString());
        if (inputCalendar.getPopupScrollLeftMessage() != null)
            setStringVariable(script, popupCalendarVariable + ".initData.scrollLeftMessage",
                    inputCalendar.getPopupScrollLeftMessage());
        if (inputCalendar.getPopupScrollRightMessage() != null)
            setStringVariable(script, popupCalendarVariable + ".initData.scrollRightMessage",
                    inputCalendar.getPopupScrollRightMessage());
        if (inputCalendar.getPopupSelectMonthMessage() != null)
            setStringVariable(script, popupCalendarVariable + ".initData.selectMonthMessage",
                    inputCalendar.getPopupSelectMonthMessage());
        if (inputCalendar.getPopupSelectYearMessage() != null)
            setStringVariable(script, popupCalendarVariable + ".initData.selectYearMessage",
                    inputCalendar.getPopupSelectYearMessage());
        if (inputCalendar.getPopupSelectDateMessage() != null)
            setStringVariable(script, popupCalendarVariable + ".initData.selectDateMessage",
                    inputCalendar.getPopupSelectDateMessage());
        setBooleanVariable(script, popupCalendarVariable + ".initData.popupLeft", inputCalendar.isPopupLeft());

    }

    return script.toString();
}

From source file:com.icesoft.faces.component.selectinputdate.SelectInputDateRenderer.java

public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    validateParameters(facesContext, uiComponent, SelectInputDate.class);
    DOMContext domContext = DOMContext.attachDOMContext(facesContext, uiComponent);
    SelectInputDate selectInputDate = (SelectInputDate) uiComponent;

    Date value;/*from   www.  j  a v a  2s  .co m*/
    boolean actuallyHaveTime = false;
    if (selectInputDate.isNavEvent()) {
        if (log.isTraceEnabled()) {
            log.trace("Rendering Nav Event");
        }
        value = selectInputDate.getNavDate();
        //System.out.println("navDate: " + value);
    } else if (selectInputDate.isRenderAsPopup() && !selectInputDate.isEnterKeyPressed(facesContext)) {
        value = selectInputDate.getPopupDate();
        if (value != null) {
            actuallyHaveTime = true;
        }
    } else {
        if (log.isTraceEnabled()) {
            log.trace("Logging non nav event");
        }
        value = CustomComponentUtils.getDateValue(selectInputDate);
        if (value != null) {
            actuallyHaveTime = true;
        }
        //System.out.println("CustomComponentUtils.getDateValue: " + value);
    }

    DateTimeConverter converter = selectInputDate.resolveDateTimeConverter(facesContext);
    TimeZone tz = selectInputDate.resolveTimeZone(facesContext);
    Locale currentLocale = selectInputDate.resolveLocale(facesContext);
    DateFormatSymbols symbols = new DateFormatSymbols(currentLocale);

    //System.out.println("SIDR.encodeEnd()  timezone: " + tz);
    //System.out.println("SIDR.encodeEnd()  locale: " + currentLocale);

    Calendar timeKeeper = Calendar.getInstance(tz, currentLocale);
    timeKeeper.setTime(value != null ? value : new Date());

    // get the parentForm
    UIComponent parentForm = findForm(selectInputDate);
    // if there is no parent form - ERROR
    if (parentForm == null) {
        log.error("SelectInputDate::must be in a FORM");
        return;
    }
    String clientId;
    if (!domContext.isInitialized()) {
        Element root = domContext.createRootElement(HTML.DIV_ELEM);
        boolean popupState = selectInputDate.isShowPopup();

        clientId = uiComponent.getClientId(facesContext);
        if (uiComponent.getId() != null)
            root.setAttribute("id", clientId + ROOT_DIV);

        Element table = domContext.createElement(HTML.TABLE_ELEM);
        if (selectInputDate.isRenderAsPopup()) {
            if (log.isTraceEnabled()) {
                log.trace("Render as popup");
            }
            // ICE-2492
            root.setAttribute(HTML.CLASS_ATTR,
                    Util.getQualifiedStyleClass(uiComponent, CSS_DEFAULT.DEFAULT_CALENDARPOPUP_CLASS, false));
            Element dateText = domContext.createElement(HTML.INPUT_ELEM);
            //System.out.println("value: " + selectInputDate.getValue());

            dateText.setAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_TEXT); // ICE-2302
            dateText.setAttribute(HTML.VALUE_ATTR, selectInputDate.getTextToRender());
            dateText.setAttribute(HTML.ID_ATTR, clientId + SelectInputDate.CALENDAR_INPUTTEXT);
            dateText.setAttribute(HTML.NAME_ATTR, clientId + SelectInputDate.CALENDAR_INPUTTEXT);
            dateText.setAttribute(HTML.CLASS_ATTR, selectInputDate.getCalendarInputClass());
            dateText.setAttribute(HTML.ONFOCUS_ATTR, "setFocus('');");
            dateText.setAttribute("onkeypress", this.ICESUBMIT);
            boolean withinSingleSubmit = org.icefaces.impl.util.Util.withinSingleSubmit(selectInputDate);
            if (withinSingleSubmit) {
                JavascriptContext.addJavascriptCall(facesContext,
                        "ice.cancelSingleSubmit('" + clientId + ROOT_DIV + "');");
            }
            String singleSubmitCall = "ice.fullSubmit('@this', '@all', event, this, function(p) { p('ice.submit.type', 'ice.se'); p('ice.submit.serialization', 'form');});";
            String onblur = combinedPassThru("setFocus('');",
                    selectInputDate.getPartialSubmit() ? ICESUBMITPARTIAL
                            : withinSingleSubmit ? singleSubmitCall : null);
            dateText.setAttribute(HTML.ONBLUR_ATTR, onblur);
            if (selectInputDate.getTabindex() != null) {
                dateText.setAttribute(HTML.TABINDEX_ATTR, selectInputDate.getTabindex());
            }
            if (selectInputDate.getAutocomplete() != null
                    && "off".equalsIgnoreCase(selectInputDate.getAutocomplete())) {
                dateText.setAttribute(HTML.AUTOCOMPLETE_ATTR, "off");
            }
            String tooltip = null;
            tooltip = selectInputDate.getInputTitle();
            if (tooltip == null || tooltip.length() == 0) {
                // extract the popupdate format and use it as a tooltip
                tooltip = getMessageWithParamFromResource(facesContext, INPUT_TEXT_TITLE,
                        selectInputDate.getSpecifiedPopupDateFormat());
            }
            if (tooltip != null && tooltip.length() > 0) {
                dateText.setAttribute(HTML.TITLE_ATTR, tooltip);
            }
            if (selectInputDate.isDisabled()) {
                dateText.setAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR);
            }
            if (selectInputDate.isReadonly()) {
                dateText.setAttribute(HTML.READONLY_ATTR, HTML.READONLY_ATTR);
            }
            int maxlength = selectInputDate.getMaxlength();
            if (maxlength > 0) {
                dateText.setAttribute(HTML.MAXLENGTH_ATTR, String.valueOf(maxlength));
            }
            root.appendChild(dateText);
            Element calendarButton = domContext.createElement(HTML.INPUT_ELEM);
            calendarButton.setAttribute(HTML.ID_ATTR, clientId + CALENDAR_BUTTON);
            calendarButton.setAttribute(HTML.NAME_ATTR, clientId + CALENDAR_BUTTON);
            calendarButton.setAttribute(HTML.TYPE_ATTR, "image");
            calendarButton.setAttribute(HTML.ONFOCUS_ATTR, "setFocus('');");
            calendarButton.setAttribute(HTML.ONMOUSEDOWN_ATTR,
                    "if (Event.isLeftClick(event)) this.selfClick = true;");
            calendarButton.setAttribute(HTML.ONKEYDOWN_ATTR,
                    "if (event.keyCode == 13 || event.keyCode == 32) this.selfClick = true;");
            // render onclick to set value of hidden field to true
            String formClientId = parentForm.getClientId(facesContext);
            String hiddenValue1 = "document.forms['" + formClientId + "']['"
                    + this.getLinkId(facesContext, uiComponent) + "'].value='";
            String hiddenValue2 = "document.forms['" + formClientId + "']['"
                    + getHiddenFieldName(facesContext, uiComponent) + "'].value='";
            String onClick = "if (!this.selfClick) return false; this.selfClick = false; " + hiddenValue1
                    + clientId + CALENDAR_BUTTON + "';" + hiddenValue2 + "toggle';"
                    + "iceSubmitPartial( document.forms['" + formClientId + "'], this,event);" + hiddenValue1
                    + "';" + hiddenValue2 + "';" + "Ice.Calendar.addCloseListener('" + clientId + "','"
                    + formClientId + "','" + this.getLinkId(facesContext, uiComponent) + "','"
                    + getHiddenFieldName(facesContext, uiComponent) + "');" + "return false;";
            calendarButton.setAttribute(HTML.ONCLICK_ATTR, onClick);
            if (selectInputDate.getTabindex() != null) {
                try {
                    int tabIndex = Integer.valueOf(selectInputDate.getTabindex()).intValue();
                    tabIndex += 1;
                    calendarButton.setAttribute(HTML.TABINDEX_ATTR, String.valueOf(tabIndex));
                } catch (NumberFormatException e) {
                    if (log.isInfoEnabled()) {
                        log.info("NumberFormatException on tabindex");
                    }
                }
            }

            if (selectInputDate.isDisabled()) {
                calendarButton.setAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR);
            }
            if (selectInputDate.isReadonly()) {
                calendarButton.setAttribute(HTML.READONLY_ATTR, HTML.READONLY_ATTR);
            }
            root.appendChild(calendarButton);
            // render a hidden field to manage the popup state; visible || hidden
            FormRenderer.addHiddenField(facesContext, getHiddenFieldName(facesContext, uiComponent));
            String resolvedSrc;
            if (popupState) {
                JavascriptContext.addJavascriptCall(facesContext, "Ice.util.adjustMyPosition('" + clientId
                        + CALENDAR_TABLE + "', '" + clientId + ROOT_DIV + "');");
                if (selectInputDate.isImageDirSet()) {
                    resolvedSrc = CoreUtils.resolveResourceURL(facesContext,
                            selectInputDate.getImageDir() + selectInputDate.getClosePopupImage());
                } else {
                    // ICE-2127: allow override of button images via CSS
                    calendarButton.setAttribute(HTML.CLASS_ATTR, selectInputDate.getClosePopupClass());
                    // without this Firefox would display a default text on top of the image
                    resolvedSrc = CoreUtils.resolveResourceURL(facesContext,
                            selectInputDate.getImageDir() + "spacer.gif");
                }
                calendarButton.setAttribute(HTML.SRC_ATTR, resolvedSrc);
                addAttributeToElementFromResource(facesContext, CLOSE_POPUP_ALT, calendarButton, HTML.ALT_ATTR);
                addAttributeToElementFromResource(facesContext, CLOSE_POPUP_TITLE, calendarButton,
                        HTML.TITLE_ATTR);
            } else {
                if (selectInputDate.isImageDirSet()) {
                    resolvedSrc = CoreUtils.resolveResourceURL(facesContext,
                            selectInputDate.getImageDir() + selectInputDate.getOpenPopupImage());
                } else {
                    // ICE-2127: allow override of button images via CSS
                    calendarButton.setAttribute(HTML.CLASS_ATTR, selectInputDate.getOpenPopupClass());
                    // without this Firefox would display a default text on top of the image
                    resolvedSrc = CoreUtils.resolveResourceURL(facesContext,
                            selectInputDate.getImageDir() + "spacer.gif");
                }
                calendarButton.setAttribute(HTML.SRC_ATTR, resolvedSrc);
                addAttributeToElementFromResource(facesContext, OPEN_POPUP_ALT, calendarButton, HTML.ALT_ATTR);
                addAttributeToElementFromResource(facesContext, OPEN_POPUP_TITLE, calendarButton,
                        HTML.TITLE_ATTR);
                FormRenderer.addHiddenField(facesContext, formClientId
                        + UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance()) + "j_idcl");
                FormRenderer.addHiddenField(facesContext, clientId + CALENDAR_CLICK);
                PassThruAttributeRenderer.renderHtmlAttributes(facesContext, uiComponent,
                        passThruAttributesWithoutTabindex);
                domContext.stepOver();
                return;
            }

            Text br = domContext.createTextNodeUnescaped("<br/>");
            root.appendChild(br);

            Element calendarDiv = domContext.createElement(HTML.DIV_ELEM);
            calendarDiv.setAttribute(HTML.ID_ATTR, clientId + CALENDAR_POPUP);
            calendarDiv.setAttribute(HTML.NAME_ATTR, clientId + CALENDAR_POPUP);
            calendarDiv.setAttribute(HTML.STYLE_ELEM, "position:absolute;z-index:10;");
            addAttributeToElementFromResource(facesContext, POPUP_CALENDAR_TITLE, calendarDiv, HTML.TITLE_ATTR);
            table.setAttribute(HTML.ID_ATTR, clientId + CALENDAR_TABLE);
            table.setAttribute(HTML.NAME_ATTR, clientId + CALENDAR_TABLE);
            table.setAttribute(HTML.CLASS_ATTR, selectInputDate.getStyleClass());
            table.setAttribute(HTML.STYLE_ATTR, "position:absolute;");
            table.setAttribute(HTML.CELLPADDING_ATTR, "0");
            table.setAttribute(HTML.CELLSPACING_ATTR, "0");
            // set mouse events on table bug 372
            String mouseOver = selectInputDate.getOnmouseover();
            table.setAttribute(HTML.ONMOUSEOVER_ATTR, mouseOver);
            String mouseOut = selectInputDate.getOnmouseout();
            table.setAttribute(HTML.ONMOUSEOUT_ATTR, mouseOut);
            String mouseMove = selectInputDate.getOnmousemove();
            table.setAttribute(HTML.ONMOUSEMOVE_ATTR, mouseMove);

            addAttributeToElementFromResource(facesContext, POPUP_CALENDAR_SUMMARY, table, HTML.SUMMARY_ATTR);
            Element positionDiv = domContext.createElement(HTML.DIV_ELEM);
            positionDiv.appendChild(table);
            calendarDiv.appendChild(positionDiv);
            Text iframe = domContext.createTextNodeUnescaped("<!--[if lte IE" + " 6.5]><iframe src='"
                    + CoreUtils.resolveResourceURL(FacesContext.getCurrentInstance(), "/xmlhttp/blank")
                    + "' class=\"iceSelInpDateIFrameFix\"></iframe><![endif]-->");
            calendarDiv.appendChild(iframe);
            root.appendChild(calendarDiv);

        } else {
            if (log.isTraceEnabled()) {
                log.trace("Select input Date Normal");
            }
            table.setAttribute(HTML.ID_ATTR, clientId + CALENDAR_TABLE);
            table.setAttribute(HTML.NAME_ATTR, clientId + CALENDAR_TABLE);
            table.setAttribute(HTML.CLASS_ATTR, selectInputDate.getStyleClass());
            addAttributeToElementFromResource(facesContext, CALENDAR_TITLE, table, HTML.TITLE_ATTR);
            table.setAttribute(HTML.CELLPADDING_ATTR, "0");
            table.setAttribute(HTML.CELLSPACING_ATTR, "0");
            // set mouse events on table bug 372
            String mouseOver = selectInputDate.getOnmouseover();
            table.setAttribute(HTML.ONMOUSEOVER_ATTR, mouseOver);
            String mouseOut = selectInputDate.getOnmouseout();
            table.setAttribute(HTML.ONMOUSEOUT_ATTR, mouseOut);
            String mouseMove = selectInputDate.getOnmousemove();
            table.setAttribute(HTML.ONMOUSEMOVE_ATTR, mouseMove);
            addAttributeToElementFromResource(facesContext, CALENDAR_SUMMARY, table, HTML.SUMMARY_ATTR);
            root.appendChild(table);

            Element dateText = domContext.createElement(HTML.INPUT_ELEM);
            dateText.setAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN);
            dateText.setAttribute(HTML.VALUE_ATTR, selectInputDate.getTextToRender());
            dateText.setAttribute(HTML.ID_ATTR, clientId + SelectInputDate.CALENDAR_INPUTTEXT);
            dateText.setAttribute(HTML.NAME_ATTR, clientId + SelectInputDate.CALENDAR_INPUTTEXT);
            root.appendChild(dateText);
        }
    }
    clientId = uiComponent.getClientId(facesContext);

    String[] weekdays = mapWeekdays(symbols);
    String[] weekdaysLong = mapWeekdaysLong(symbols);
    String[] months = mapMonths(symbols);

    // use the currentDay to set focus - do not set
    int lastDayInMonth = timeKeeper.getActualMaximum(Calendar.DAY_OF_MONTH);
    int currentDay = timeKeeper.get(Calendar.DAY_OF_MONTH); // starts at 1

    if (currentDay > lastDayInMonth) {
        currentDay = lastDayInMonth;
    }

    timeKeeper.set(Calendar.DAY_OF_MONTH, 1);

    int weekDayOfFirstDayOfMonth = mapCalendarDayToCommonDay(timeKeeper.get(Calendar.DAY_OF_WEEK));

    int weekStartsAtDayIndex = mapCalendarDayToCommonDay(timeKeeper.getFirstDayOfWeek());

    // do not require a writer - clean out all methods that reference a writer
    ResponseWriter writer = facesContext.getResponseWriter();

    Element root = (Element) domContext.getRootNode();

    Element table = null;
    if (selectInputDate.isRenderAsPopup()) {
        if (log.isTraceEnabled()) {
            log.trace("SelectInputDate as Popup");
        }

        // assumption input text is first child
        Element dateText = (Element) root.getFirstChild();
        //System.out.println("dateText  currentValue: " + currentValue);
        dateText.setAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_TEXT); // ICE-2302
        dateText.setAttribute(HTML.VALUE_ATTR, selectInputDate.getTextToRender());
        int maxlength = selectInputDate.getMaxlength();
        if (maxlength > 0) {
            dateText.setAttribute(HTML.MAXLENGTH_ATTR, String.valueOf(maxlength));
        }

        // get tables , our table is the first and only one
        NodeList tables = root.getElementsByTagName(HTML.TABLE_ELEM);
        // assumption we want the first table in tables. there should only be one
        table = (Element) tables.item(0);

        PassThruAttributeRenderer.renderHtmlAttributes(facesContext, uiComponent,
                passThruAttributesWithoutTabindex);

        Element tr1 = domContext.createElement(HTML.TR_ELEM);

        table.appendChild(tr1);
        writeMonthYearHeader(domContext, facesContext, writer, selectInputDate, timeKeeper, currentDay, tr1,
                selectInputDate.getMonthYearRowClass(), currentLocale, months, weekdays, weekdaysLong,
                converter);

        Element tr2 = domContext.createElement(HTML.TR_ELEM);
        table.appendChild(tr2);

        writeWeekDayNameHeader(domContext, weekStartsAtDayIndex, weekdays, facesContext, writer,
                selectInputDate, tr2, selectInputDate.getWeekRowClass(), timeKeeper, months, weekdaysLong,
                converter);

        writeDays(domContext, facesContext, writer, selectInputDate, timeKeeper, currentDay,
                weekStartsAtDayIndex, weekDayOfFirstDayOfMonth, lastDayInMonth, table, months, weekdays,
                weekdaysLong, converter, (actuallyHaveTime ? value : null));
    } else {
        if (log.isTraceEnabled()) {
            log.trace("renderNormal::endcodeEnd");
        }
        // assume table is the first child
        table = (Element) root.getFirstChild();

        PassThruAttributeRenderer.renderHtmlAttributes(facesContext, uiComponent, passThruAttributes);

        Element tr1 = domContext.createElement(HTML.TR_ELEM);
        table.appendChild(tr1);

        writeMonthYearHeader(domContext, facesContext, writer, selectInputDate, timeKeeper, currentDay, tr1,
                selectInputDate.getMonthYearRowClass(), currentLocale, months, weekdays, weekdaysLong,
                converter);

        Element tr2 = domContext.createElement(HTML.TR_ELEM);

        writeWeekDayNameHeader(domContext, weekStartsAtDayIndex, weekdays, facesContext, writer,
                selectInputDate, tr2, selectInputDate.getWeekRowClass(), timeKeeper, months, weekdaysLong,
                converter);

        table.appendChild(tr2);

        writeDays(domContext, facesContext, writer, selectInputDate, timeKeeper, currentDay,
                weekStartsAtDayIndex, weekDayOfFirstDayOfMonth, lastDayInMonth, table, months, weekdays,
                weekdaysLong, converter, (actuallyHaveTime ? value : null));
    }

    //System.out.println("SIDR.encodeEnd()  isTime? " + SelectInputDate.isTime(converter));
    if (SelectInputDate.isTime(converter)) {
        Element tfoot = domContext.createElement(HTML.TFOOT_ELEM);
        Element tr = domContext.createElement(HTML.TR_ELEM);
        Element td = domContext.createElement(HTML.TD_ELEM);
        td.setAttribute(HTML.COLSPAN_ATTR, selectInputDate.isRenderWeekNumbers() ? "8" : "7");
        td.setAttribute(HTML.CLASS_ATTR, selectInputDate.getTimeClass());
        Element tbl = domContext.createElement(HTML.TABLE_ELEM);
        Element tr2 = domContext.createElement(HTML.TR_ELEM);
        Element tdHours = domContext.createElement(HTML.TD_ELEM);
        Element hours = domContext.createElement(HTML.SELECT_ELEM);
        hours.setAttribute(HTML.ID_ATTR, clientId + SELECT_HOUR);
        hours.setAttribute(HTML.NAME_ATTR, clientId + SELECT_HOUR);
        hours.setAttribute(HTML.CLASS_ATTR, selectInputDate.getTimeDropDownClass());
        hours.setAttribute(HTML.ONCHANGE_ATTR, DomBasicRenderer.ICESUBMITPARTIAL);

        // Convert from an hour to an index into the list of hours
        int hrs[] = selectInputDate.getHours(facesContext);
        //System.out.println("SIDR.encodeEnd()  hrs: " + hrs[0] + ", " + hrs[hrs.length-1]);
        int hourIndex;
        int min;
        int sec;
        int amPm;
        //System.out.println("SIDR.encodeEnd()  actuallyHaveTime: " + actuallyHaveTime);
        if (!actuallyHaveTime && selectInputDate.getHoursSubmittedValue() != null
                && selectInputDate.getMinutesSubmittedValue() != null) {
            //System.out.println("SIDR.encodeEnd()  Using submitted hours and minutes");
            hourIndex = selectInputDate.getHoursSubmittedValue().intValue();
            //System.out.println("SIDR.encodeEnd()  hour: " + hourIndex);
            min = selectInputDate.getMinutesSubmittedValue().intValue();
            //System.out.println("SIDR.encodeEnd()  min: " + min);
            String amPmStr = selectInputDate.getAmPmSubmittedValue();
            //System.out.println("SIDR.encodeEnd()  amPmStr: " + amPmStr);
            if (amPmStr != null) {
                amPm = amPmStr.equalsIgnoreCase("PM") ? 1 : 0;
            } else {
                amPm = (hourIndex >= 12) ? 1 : 0;
            }
            //System.out.println("SIDR.encodeEnd()  amPm: " + amPm);
            if (hrs[0] == 1) {
                hourIndex--;
                if (hourIndex < 0) {
                    hourIndex = hrs.length - 1;
                }
            }
            //System.out.println("SIDR.encodeEnd()  hourIndex: " + hourIndex);
        } else {
            if (hrs.length > 12) {
                hourIndex = timeKeeper.get(Calendar.HOUR_OF_DAY);
                //System.out.println("SIDR.encodeEnd()  hour 24: " + hourIndex);
            } else {
                hourIndex = timeKeeper.get(Calendar.HOUR);
                //System.out.println("SIDR.encodeEnd()  hour 12: " + hourIndex);
            }
            if (hrs[0] == 1) {
                hourIndex--;
                if (hourIndex < 0) {
                    hourIndex = hrs.length - 1;
                }
            }
            //System.out.println("SIDR.encodeEnd()  hourIndex: " + hourIndex);

            min = timeKeeper.get(Calendar.MINUTE);
            amPm = timeKeeper.get(Calendar.AM_PM);
            //System.out.println("SIDR.encodeEnd()  amPm: " + amPm);
        }
        if (!actuallyHaveTime && selectInputDate.getSecondsSubmittedValue() != null) {
            sec = selectInputDate.getSecondsSubmittedValue().intValue();
        } else {
            sec = timeKeeper.get(Calendar.SECOND);
        }
        for (int i = 0; i < hrs.length; i++) {
            Element hoursOption = domContext.createElement(HTML.OPTION_ELEM);
            hoursOption.setAttribute(HTML.VALUE_ATTR, String.valueOf(hrs[i]));
            Text hourText = domContext.createTextNode(String.valueOf(hrs[i]));
            hoursOption.appendChild(hourText);
            if (i == hourIndex) {
                hoursOption.setAttribute(HTML.SELECTED_ATTR, "true");
            }
            hours.appendChild(hoursOption);
        }
        Element tdColon = domContext.createElement(HTML.TD_ELEM);
        Element tdMinutes = domContext.createElement(HTML.TD_ELEM);
        Element minutes = domContext.createElement(HTML.SELECT_ELEM);
        minutes.setAttribute(HTML.ID_ATTR, clientId + SELECT_MIN);
        minutes.setAttribute(HTML.NAME_ATTR, clientId + SELECT_MIN);
        minutes.setAttribute(HTML.CLASS_ATTR, selectInputDate.getTimeDropDownClass());
        minutes.setAttribute(HTML.ONCHANGE_ATTR, DomBasicRenderer.ICESUBMITPARTIAL);
        for (int i = 0; i < 60; i++) {
            Element minutesOption = domContext.createElement(HTML.OPTION_ELEM);
            minutesOption.setAttribute(HTML.VALUE_ATTR, String.valueOf(i));
            String digits = String.valueOf(i);
            if (i < 10) {
                digits = "0" + digits;
            }
            Text minuteText = domContext.createTextNode(digits);
            minutesOption.appendChild(minuteText);
            if (i == min) {
                minutesOption.setAttribute(HTML.SELECTED_ATTR, "true");
            }
            minutes.appendChild(minutesOption);
        }

        Text colon = domContext.createTextNode(":");
        tfoot.appendChild(tr);
        tr.appendChild(td);
        td.appendChild(tbl);
        tbl.appendChild(tr2);
        tdHours.appendChild(hours);
        tr2.appendChild(tdHours);
        tdColon.appendChild(colon);
        tdMinutes.appendChild(minutes);
        tr2.appendChild(tdColon);
        tr2.appendChild(tdMinutes);

        if (selectInputDate.isSecond(facesContext)) {
            Element tdSeconds = domContext.createElement(HTML.TD_ELEM);
            Element tdSecColon = domContext.createElement(HTML.TD_ELEM);
            Element seconds = domContext.createElement(HTML.SELECT_ELEM);
            seconds.setAttribute(HTML.ID_ATTR, clientId + SELECT_SEC);
            seconds.setAttribute(HTML.NAME_ATTR, clientId + SELECT_SEC);
            seconds.setAttribute(HTML.CLASS_ATTR, selectInputDate.getTimeDropDownClass());
            seconds.setAttribute(HTML.ONCHANGE_ATTR, DomBasicRenderer.ICESUBMITPARTIAL);
            for (int i = 0; i < 60; i++) {
                Element secondsOption = domContext.createElement(HTML.OPTION_ELEM);
                secondsOption.setAttribute(HTML.VALUE_ATTR, String.valueOf(i));
                String digits = String.valueOf(i);
                if (i < 10) {
                    digits = "0" + digits;
                }
                Text secondText = domContext.createTextNode(digits);
                secondsOption.appendChild(secondText);
                if (i == sec) {
                    secondsOption.setAttribute(HTML.SELECTED_ATTR, "true");
                }
                seconds.appendChild(secondsOption);
            }
            Text secondColon = domContext.createTextNode(":");
            tdSecColon.appendChild(secondColon);
            tdSeconds.appendChild(seconds);
            tr2.appendChild(tdSecColon);
            tr2.appendChild(tdSeconds);
        }

        if (selectInputDate.isAmPm(facesContext)) {
            Element tdAamPm = domContext.createElement(HTML.TD_ELEM);
            Element amPmElement = domContext.createElement(HTML.SELECT_ELEM);
            amPmElement.setAttribute(HTML.ID_ATTR, clientId + SELECT_AM_PM);
            amPmElement.setAttribute(HTML.NAME_ATTR, clientId + SELECT_AM_PM);
            amPmElement.setAttribute(HTML.CLASS_ATTR, selectInputDate.getTimeDropDownClass());
            amPmElement.setAttribute(HTML.ONCHANGE_ATTR, DomBasicRenderer.ICESUBMITPARTIAL);
            String[] symbolsAmPm = symbols.getAmPmStrings();

            Element amPmElementOption = domContext.createElement(HTML.OPTION_ELEM);
            amPmElementOption.setAttribute(HTML.VALUE_ATTR, "AM");
            Text amPmElementText = domContext.createTextNode(symbolsAmPm[0]);
            amPmElementOption.appendChild(amPmElementText);

            Element amPmElementOption2 = domContext.createElement(HTML.OPTION_ELEM);
            amPmElementOption2.setAttribute(HTML.VALUE_ATTR, "PM");
            Text amPmElementText2 = domContext.createTextNode(symbolsAmPm[1]);
            amPmElementOption2.appendChild(amPmElementText2);
            if (amPm == 0) {
                amPmElementOption.setAttribute(HTML.SELECTED_ATTR, "true");
            } else {
                amPmElementOption2.setAttribute(HTML.SELECTED_ATTR, "true");
            }
            amPmElement.appendChild(amPmElementOption);
            amPmElement.appendChild(amPmElementOption2);
            tdAamPm.appendChild(amPmElement);
            tr2.appendChild(tdAamPm);
        }
        table.appendChild(tfoot);
    }
    // purge child components as they have been encoded no need to keep them around
    selectInputDate.getChildren().clear();

    // steps to the position where the next sibling should be rendered
    domContext.stepOver();
}