Package org.exist.xquery.util

Examples of org.exist.xquery.util.NumberFormatter


                }
            case 'Z':
                final Sequence tz = dt.getTimezone();
                if(tz != Sequence.EMPTY_SEQUENCE) {
                    final DayTimeDurationValue dtv = ((DayTimeDurationValue)tz);
                    final NumberFormatter formatter = NumberFormatter.getInstance(language);
                    sb.append(dtv.getPart(DurationValue.SIGN) >= 0 ? '+' : '-');
                    sb.append(formatter.formatNumber(dtv.getPart(DurationValue.HOUR), "01", 2, 2));
                    sb.append(':');
                    sb.append(formatter.formatNumber(dtv.getPart(DurationValue.MINUTE), "01", 2, 2));
                }
                break;

            default:
                throw new XPathException(this, ErrorCodes.FOFD1340, "Unrecognized date/time component: " + component);
View Full Code Here


        }
    }

    private void formatNumber(char specifier, String picture, String width, int num, String language,
                              StringBuilder sb) throws XPathException {
        final NumberFormatter formatter = NumberFormatter.getInstance(language);
        if ("N".equals(picture) || "n".equals(picture) || "Nn".equals(picture)) {
            String name;
            switch (specifier) {
                case 'M':
                    name = formatter.getMonth(num);
                    break;
                case 'F':
                    name = formatter.getDay(num);
                    break;
                case 'P':
                    name = formatter.getAmPm(num);
                    break;
                default:
                    name = "";
                    break;
            }
            if ("N".equals(picture))
                {name = name.toUpperCase();}
            if ("n".equals(picture))
                {name = name.toLowerCase();}
            sb.append(name);
            return;
        }

        // determine min and max width
        int min = NumberFormatter.getMinDigits(picture);
        int max = NumberFormatter.getMaxDigits(picture);
        if (max == 1)
            {max = Integer.MAX_VALUE;}
        // explicit width takes precedence
        final int widths[] = getWidths(width);
        if (widths != null) {
            if (widths[0] > 0) {min = widths[0];}
            if (widths[1] > 0) {max = widths[1];}
        }
        try {
            sb.append(formatter.formatNumber(num, picture, min, max));
        } catch (final XPathException e) {
            throw new XPathException(this, ErrorCodes.FOFD1350, e.getMessage());
        }
    }
View Full Code Here

TOP

Related Classes of org.exist.xquery.util.NumberFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.