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.qtplaf.library.util.Calendar.java

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

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

From source file:org.pentaho.reporting.platform.plugin.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  www.ja va2 s .co  m*/

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

    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(LocaleHelper.getLocale()));
                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(LocaleHelper.getLocale()));
                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(Messages.getInstance()
                    .getString("ReportPlugin.unableToConvertParameter", parameter.getName(), valueAsString)); //$NON-NLS-1$
        }
    }
    return rawValue;
}

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

/**
 * Returns an array of localized names of months.
 *
 * @return An array of names.//from w  w w. java2 s. co m
 * @param locale The desired locale.
 * @param capitalized A boolean to capitalize the name.
 */
public static String[] getShortMonths(Locale locale, boolean capitalized) {

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

From source file:com.spacejake.jake.ultimatepurduediner.NavigationDrawerFragment.java

public void showDatePicker() {
    new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
        @Override/* w ww .ja va 2 s.com*/
        public void onDateSet(DatePicker datePicker, int year, int month, int day) {
            if (!dateSet) {
                Calendar cal = Calendar.getInstance();
                ((MainActivity) getActivity()).dateChange(year, month, day);
                if (datePicker.getDayOfMonth() == cal.get(Calendar.DAY_OF_MONTH)
                        && datePicker.getYear() == cal.get(Calendar.YEAR)) {
                    datePickerButton.setTitle("Today");
                } else {
                    DateFormatSymbols dfs = new DateFormatSymbols(new Locale("en"));
                    cal.set(year, month, day);
                    datePickerButton.setTitle(String.format("%s, %d/%d/%d",
                            dfs.getShortWeekdays()[cal.get(Calendar.DAY_OF_WEEK)], month + 1, day, year));
                }
                dateSet = true;
            } else {
                dateSet = false;
            }
        }
    }, year, month, day).show();
}

From source file:javadz.beanutils.locale.converters.DateLocaleConverter.java

/**
 * Convert a pattern from a localized format to the default format.
 *
 * @param locale   The locale//  w  w  w.  jav a2  s . c o  m
 * @param localizedPattern The pattern in 'local' symbol format
 * @return pattern in 'default' symbol format
 */
private String convertLocalizedPattern(String localizedPattern, Locale locale) {

    if (localizedPattern == null) {
        return null;
    }

    // Note that this is a little obtuse.
    // However, it is the best way that anyone can come up with 
    // that works with some 1.4 series JVM.

    // Get the symbols for the localized pattern
    DateFormatSymbols localizedSymbols = new DateFormatSymbols(locale);
    String localChars = localizedSymbols.getLocalPatternChars();

    if (DEFAULT_PATTERN_CHARS.equals(localChars)) {
        return localizedPattern;
    }

    // Convert the localized pattern to default
    String convertedPattern = null;
    try {
        convertedPattern = convertPattern(localizedPattern, localChars, DEFAULT_PATTERN_CHARS);
    } catch (Exception ex) {
        log.debug("Converting pattern '" + localizedPattern + "' for " + locale, ex);
    }
    return convertedPattern;
}

From source file:javadz.beanutils.locale.converters.DateLocaleConverter.java

/**
 * This method is called at class initialization time to define the
 * value for constant member DEFAULT_PATTERN_CHARS. All other methods needing
 * this data should just read that constant.
 *///from   w w w . ja  va  2 s  .c o m
private static String initDefaultChars() {
    DateFormatSymbols defaultSymbols = new DateFormatSymbols(Locale.US);
    return defaultSymbols.getLocalPatternChars();
}

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   w w w  .  j a va 2  s.c  om
    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();
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaLineChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final XYPlot plot = chart.getXYPlot();

    if (isSharedRangeAxis() == false) {
        final ValueAxis linesAxis = plot.getRangeAxis(1);
        if (linesAxis instanceof NumberAxis) {
            final NumberAxis numberAxis = (NumberAxis) linesAxis;
            numberAxis.setAutoRangeIncludesZero(isLineAxisIncludesZero());
            numberAxis.setAutoRangeStickyZero(isLineAxisStickyZero());

            if (getLinePeriodCount() > 0) {
                if (getLineTicksLabelFormat() != null) {
                    final FastDecimalFormat formatter = new FastDecimalFormat(getLineTicksLabelFormat(),
                            getResourceBundleFactory().getLocale());
                    numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount(), formatter));
                } else {
                    numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount()));
                }//w  w  w . j ava2  s.c o  m
            } else {
                if (getLineTicksLabelFormat() != null) {
                    final DecimalFormat formatter = new DecimalFormat(getLineTicksLabelFormat(),
                            new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
                    numberAxis.setNumberFormatOverride(formatter);
                }
            }
        } else if (linesAxis instanceof DateAxis) {
            final DateAxis numberAxis = (DateAxis) linesAxis;

            if (getLinePeriodCount() > 0 && getLineTimePeriod() != null) {
                if (getLineTicksLabelFormat() != null) {
                    final SimpleDateFormat formatter = new SimpleDateFormat(getLineTicksLabelFormat(),
                            new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                    numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()),
                            (int) getLinePeriodCount(), formatter));
                } else {
                    numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()),
                            (int) getLinePeriodCount()));
                }
            } else if (getRangeTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setDateFormatOverride(formatter);
            }
        }

        if (linesAxis != null) {
            final Font labelFont = Font.decode(getLabelFont());
            linesAxis.setLabelFont(labelFont);
            linesAxis.setTickLabelFont(labelFont);

            if (getLineTitleFont() != null) {
                linesAxis.setLabelFont(getLineTitleFont());
            }
            if (getLineTickFont() != null) {
                linesAxis.setTickLabelFont(getLineTickFont());
            }
            final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
            if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) {
                final double lineRangeMinimumVal = lineRangeMinimum == null ? 0 : lineRangeMinimum;
                final double lineRangeMaximumVal = lineRangeMaximum == null ? 0 : lineRangeMaximum;
                if (lineRangeMinimum != null) {
                    linesAxis.setLowerBound(getLineRangeMinimum());
                }
                if (lineRangeMaximum != null) {
                    linesAxis.setUpperBound(getRangeMaximum());
                }
                if (lineRangeMinimumVal == 0 && lineRangeMaximumVal == 1) {
                    linesAxis.setLowerBound(0);
                    linesAxis.setUpperBound(1);
                    linesAxis.setAutoRange(true);
                }
            } else {
                if (lineRangeMinimum != null) {
                    linesAxis.setLowerBound(lineRangeMinimum);
                }
                if (lineRangeMaximum != null) {
                    linesAxis.setUpperBound(lineRangeMaximum);
                }
                linesAxis.setAutoRange(isLineAxisAutoRange());
            }
        }
    }

    final XYLineAndShapeRenderer linesRenderer = (XYLineAndShapeRenderer) plot.getRenderer(1);
    if (linesRenderer != null) {
        //set stroke with line width
        linesRenderer.setStroke(translateLineStyle(getLineWidth(), getLineStyle()));
        //hide shapes on line
        linesRenderer.setShapesVisible(isMarkersVisible());
        linesRenderer.setBaseShapesFilled(isMarkersVisible());

        //set colors for each line
        for (int i = 0; i < lineSeriesColor.size(); i++) {
            final String s = (String) lineSeriesColor.get(i);
            linesRenderer.setSeriesPaint(i, parseColorFromString(s));
        }
    }
}

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 . jav a  2  s . co m*/
    return null;
}

From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java

public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
    RendererUtils.checkParamValidity(facesContext, component, HtmlInputCalendar.class);

    HtmlInputCalendar inputCalendar = (HtmlInputCalendar) component;

    Locale currentLocale = facesContext.getViewRoot().getLocale();
    Map<String, List<ClientBehavior>> behaviors = inputCalendar.getClientBehaviors();
    if (!behaviors.isEmpty()) {
        ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, facesContext.getResponseWriter());
    }// ww w . ja  v  a2  s.co m

    log.debug("current locale:" + currentLocale.toString());

    String textValue;

    Converter converter = inputCalendar.getConverter();
    Object submittedValue = inputCalendar.getSubmittedValue();

    Date value;

    if (submittedValue != null) {
        //Don't need to convert anything, the textValue is the same as the submittedValue
        textValue = (String) submittedValue;

        if (textValue == null || textValue.trim().length() == 0
                || textValue.equals(getHelperString(inputCalendar))) {
            value = null;
        } else {
            try {
                String formatStr = CalendarDateTimeConverter.createJSPopupFormat(facesContext,
                        inputCalendar.getPopupDateFormat());
                Calendar timeKeeper = Calendar.getInstance(currentLocale);
                int firstDayOfWeek = timeKeeper.getFirstDayOfWeek() - 1;
                org.apache.myfaces.dateformat.DateFormatSymbols symbols = new org.apache.myfaces.dateformat.DateFormatSymbols(
                        currentLocale);

                SimpleDateFormatter dateFormat = new SimpleDateFormatter(formatStr, symbols, firstDayOfWeek);
                value = dateFormat.parse(textValue);
            } catch (IllegalArgumentException illegalArgumentException) {
                value = null;
            }
        }
    } else {
        if (converter == null) {
            CalendarDateTimeConverter defaultConverter = new CalendarDateTimeConverter();

            value = (Date) getDateBusinessConverter(inputCalendar).getDateValue(facesContext, component,
                    inputCalendar.getValue());

            textValue = defaultConverter.getAsString(facesContext, inputCalendar, value);
        } else {
            Object componentValue = null;
            boolean usedComponentValue = false;
            //Use converter to retrieve the value.
            if (converter instanceof DateConverter) {
                value = ((DateConverter) converter).getAsDate(facesContext, inputCalendar);
            } else {
                componentValue = inputCalendar.getValue();
                if (componentValue instanceof Date) {
                    value = (Date) componentValue;
                } else {
                    usedComponentValue = true;
                    value = null;
                }
            }
            textValue = converter.getAsString(facesContext, inputCalendar,
                    usedComponentValue ? componentValue : value);
        }
    }
    /*        
    try
    {
    // value = RendererUtils.getDateValue(inputCalendar);
            
    Converter converter = getConverter(inputCalendar);
    if (converter instanceof DateConverter)
    {
        value = ((DateConverter) converter).getAsDate(facesContext, component);
    }
    else
    {
        //value = RendererUtils.getDateValue(inputCalendar);
        Object objectValue = RendererUtils.getObjectValue(component);
        if (objectValue == null || objectValue instanceof Date)
        {
            value = (Date) objectValue;
        }
        else
        {
            //Use Converter.getAsString and convert to date using 
            String stringValue = converter.getAsString(facesContext, component, objectValue);
            
            if(stringValue ==null || stringValue.trim().length()==0 ||stringValue.equals(getHelperString(inputCalendar)))
            {
                value = null;
            }
            else
            {
                String formatStr = CalendarDateTimeConverter.createJSPopupFormat(facesContext, inputCalendar.getPopupDateFormat());
                Calendar timeKeeper = Calendar.getInstance(currentLocale);
                int firstDayOfWeek = timeKeeper.getFirstDayOfWeek() - 1;
                org.apache.myfaces.dateformat.DateFormatSymbols symbols = new org.apache.myfaces.dateformat.DateFormatSymbols(currentLocale);
            
                SimpleDateFormatter dateFormat = new SimpleDateFormatter(formatStr, symbols, firstDayOfWeek);
                value = dateFormat.parse(stringValue);
            }
        }
    }
    }
    catch (IllegalArgumentException illegalArgumentException)
    {
    value = null;
    }
    */

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

    DateFormatSymbols symbols = new DateFormatSymbols(currentLocale);

    if (inputCalendar.isRenderAsPopup()) {
        renderPopup(facesContext, inputCalendar, textValue, timeKeeper, symbols);
    } else {
        renderInline(facesContext, inputCalendar, timeKeeper, symbols);
    }

    component.getChildren().removeAll(component.getChildren());
}