diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java index ce0effd41..4ea21e664 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java @@ -36,12 +36,15 @@ public class CLDRHelper { @MetadataProvider(LikelySubtagsMetadataGenerator.class) private static native ResourceMap getLikelySubtagsMap(); - public static String[] resolveEras(String localeCode) { + public static String[] resolveEras(String language, String country) { ResourceMap> map = getErasMap(); - ResourceArray arrayRes = map.has(localeCode) ? map.get(localeCode) : map.get("root"); + String localeCode = getCode(language, country); + ResourceArray arrayRes = map.has(localeCode) ? map.get(localeCode) : + map.has(language) ? map.get(language) : map.get("root"); return new String[] { arrayRes.get(0).getValue(), arrayRes.get(1).getValue() }; } + @MetadataProvider(DateSymbolsMetadataGenerator.class) private static native ResourceMap> getErasMap(); @MetadataProvider(LanguageMetadataGenerator.class) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/DateSymbolsMetadataGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/DateSymbolsMetadataGenerator.java new file mode 100644 index 000000000..52ede4d19 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/DateSymbolsMetadataGenerator.java @@ -0,0 +1,51 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.impl.unicode; + +import java.util.Map; +import org.teavm.model.MethodReference; +import org.teavm.platform.metadata.*; + +/** + * + * @author Alexey Andreev + */ +public class DateSymbolsMetadataGenerator implements MetadataGenerator { + @Override + public Resource generateMetadata(MetadataGeneratorContext context, MethodReference method) { + switch (method.getName()) { + case "getErasMap": + return generateEras(context); + default: + throw new AssertionError("Unsupported method: " + method); + } + } + + private Resource generateEras(MetadataGeneratorContext context) { + CLDRReader reader = context.getService(CLDRReader.class); + ResourceMap> result = context.createResourceMap(); + for (Map.Entry localeEntry : reader.getKnownLocales().entrySet()) { + ResourceArray erasRes = context.createResourceArray(); + result.put(localeEntry.getKey(), erasRes); + for (String era : localeEntry.getValue().getEras()) { + StringResource eraRes = context.createResource(StringResource.class); + eraRes.setValue(era); + erasRes.add(eraRes); + } + } + return result; + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/Annotation.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAnnotation.java similarity index 93% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/text/Annotation.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAnnotation.java index 98013ad47..a7b28b68a 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/Annotation.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAnnotation.java @@ -17,10 +17,10 @@ package org.teavm.classlib.java.text; -public class Annotation { +public class TAnnotation { private Object value; - public Annotation(Object attribute) { + public TAnnotation(Object attribute) { value = attribute; } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/AttributedCharacterIterator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedCharacterIterator.java similarity index 98% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/text/AttributedCharacterIterator.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedCharacterIterator.java index 6c6096e9c..f3baf6960 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/AttributedCharacterIterator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedCharacterIterator.java @@ -21,7 +21,7 @@ import org.teavm.classlib.java.io.TSerializable; import org.teavm.classlib.java.util.TMap; import org.teavm.classlib.java.util.TSet; -public interface AttributedCharacterIterator extends CharacterIterator { +public interface TAttributedCharacterIterator extends TCharacterIterator { public static class Attribute implements TSerializable { public static final Attribute INPUT_METHOD_SEGMENT = new Attribute( diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/AttributedString.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedString.java similarity index 86% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/text/AttributedString.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedString.java index 3b9e6f7a4..d59073f56 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/AttributedString.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedString.java @@ -17,14 +17,14 @@ package org.teavm.classlib.java.text; -import org.teavm.classlib.java.text.AttributedCharacterIterator.Attribute; +import org.teavm.classlib.java.text.TAttributedCharacterIterator.Attribute; import org.teavm.classlib.java.util.*; -public class AttributedString { +public class TAttributedString { String text; - TMap> attributeMap; + TMap> attributeMap; static class Range { int start; @@ -40,22 +40,22 @@ public class AttributedString { } } - static class AttributedIterator implements AttributedCharacterIterator { + static class AttributedIterator implements TAttributedCharacterIterator { private int begin, end, offset; - private AttributedString attrString; + private TAttributedString attrString; private THashSet attributesAllowed; - AttributedIterator(AttributedString attrString) { + AttributedIterator(TAttributedString attrString) { this.attrString = attrString; begin = 0; end = attrString.text.length(); offset = 0; } - AttributedIterator(AttributedString attrString, AttributedCharacterIterator.Attribute[] attributes, int begin, + AttributedIterator(TAttributedString attrString, TAttributedCharacterIterator.Attribute[] attributes, int begin, int end) { if (begin < 0 || end > attrString.text.length() || begin > end) { throw new IllegalArgumentException(); @@ -120,7 +120,7 @@ public class AttributedString { } private boolean inRange(Range range) { - if (!(range.value instanceof Annotation)) { + if (!(range.value instanceof TAnnotation)) { return true; } return range.start >= begin && range.start < end && range.end > begin && range.end <= end; @@ -131,9 +131,9 @@ public class AttributedString { while (it.hasNext()) { Range range = it.next(); if (range.start >= begin && range.start < end) { - return !(range.value instanceof Annotation) || (range.end > begin && range.end <= end); + return !(range.value instanceof TAnnotation) || (range.end > begin && range.end <= end); } else if (range.end > begin && range.end <= end) { - return !(range.value instanceof Annotation) || (range.start >= begin && range.start < end); + return !(range.value instanceof TAnnotation) || (range.start >= begin && range.start < end); } } return false; @@ -171,7 +171,7 @@ public class AttributedString { } @Override - public Object getAttribute(AttributedCharacterIterator.Attribute attribute) { + public Object getAttribute(TAttributedCharacterIterator.Attribute attribute) { if (attributesAllowed != null && !attributesAllowed.contains(attribute)) { return null; } @@ -222,7 +222,7 @@ public class AttributedString { } @Override - public int getRunLimit(AttributedCharacterIterator.Attribute attribute) { + public int getRunLimit(TAttributedCharacterIterator.Attribute attribute) { if (attributesAllowed != null && !attributesAllowed.contains(attribute)) { return end; } @@ -238,7 +238,7 @@ public class AttributedString { int limit = end; TIterator it = attributes.iterator(); while (it.hasNext()) { - AttributedCharacterIterator.Attribute attribute = it.next(); + TAttributedCharacterIterator.Attribute attribute = it.next(); int newLimit = getRunLimit(attribute); if (newLimit < limit) { limit = newLimit; @@ -271,7 +271,7 @@ public class AttributedString { } @Override - public int getRunStart(AttributedCharacterIterator.Attribute attribute) { + public int getRunStart(TAttributedCharacterIterator.Attribute attribute) { if (attributesAllowed != null && !attributesAllowed.contains(attribute)) { return begin; } @@ -287,7 +287,7 @@ public class AttributedString { int start = begin; TIterator it = attributes.iterator(); while (it.hasNext()) { - AttributedCharacterIterator.Attribute attribute = it.next(); + TAttributedCharacterIterator.Attribute attribute = it.next(); int newStart = getRunStart(attribute); if (newStart > start) { start = newStart; @@ -335,7 +335,7 @@ public class AttributedString { } } - public AttributedString(AttributedCharacterIterator iterator) { + public TAttributedString(TAttributedCharacterIterator iterator) { if (iterator.getBeginIndex() > iterator.getEndIndex()) { throw new IllegalArgumentException("Invalid substring range"); } @@ -345,7 +345,7 @@ public class AttributedString { iterator.next(); } text = buffer.toString(); - TSet attributes = iterator.getAllAttributeKeys(); + TSet attributes = iterator.getAllAttributeKeys(); if (attributes == null) { return; } @@ -353,9 +353,9 @@ public class AttributedString { TIterator it = attributes.iterator(); while (it.hasNext()) { - AttributedCharacterIterator.Attribute attribute = it.next(); + TAttributedCharacterIterator.Attribute attribute = it.next(); iterator.setIndex(0); - while (iterator.current() != CharacterIterator.DONE) { + while (iterator.current() != TCharacterIterator.DONE) { int start = iterator.getRunStart(attribute); int limit = iterator.getRunLimit(attribute); Object value = iterator.getAttribute(attribute); @@ -367,7 +367,7 @@ public class AttributedString { } } - private AttributedString(AttributedCharacterIterator iterator, int start, int end, TSet attributes) { + private TAttributedString(TAttributedCharacterIterator iterator, int start, int end, TSet attributes) { if (start < iterator.getBeginIndex() || end > iterator.getEndIndex() || start > end) { throw new IllegalArgumentException(); } @@ -387,14 +387,14 @@ public class AttributedString { TIterator it = attributes.iterator(); while (it.hasNext()) { - AttributedCharacterIterator.Attribute attribute = it.next(); + TAttributedCharacterIterator.Attribute attribute = it.next(); iterator.setIndex(start); while (iterator.getIndex() < end) { Object value = iterator.getAttribute(attribute); int runStart = iterator.getRunStart(attribute); int limit = iterator.getRunLimit(attribute); - if ((value instanceof Annotation && runStart >= start && limit <= end) || - (value != null && !(value instanceof Annotation))) { + if ((value instanceof TAnnotation && runStart >= start && limit <= end) || + (value != null && !(value instanceof TAnnotation))) { addAttribute(attribute, value, (runStart < start ? start : runStart) - start, (limit > end ? end : limit) - start); } @@ -403,16 +403,16 @@ public class AttributedString { } } - public AttributedString(AttributedCharacterIterator iterator, int start, int end) { + public TAttributedString(TAttributedCharacterIterator iterator, int start, int end) { this(iterator, start, end, iterator.getAllAttributeKeys()); } - public AttributedString(AttributedCharacterIterator iterator, int start, int end, - AttributedCharacterIterator.Attribute[] attributes) { + public TAttributedString(TAttributedCharacterIterator iterator, int start, int end, + TAttributedCharacterIterator.Attribute[] attributes) { this(iterator, start, end, new THashSet<>(TArrays.asList(attributes))); } - public AttributedString(String value) { + public TAttributedString(String value) { if (value == null) { throw new NullPointerException(); } @@ -420,7 +420,7 @@ public class AttributedString { attributeMap = new THashMap<>(11); } - public AttributedString(String value, TMap attributes) { + public TAttributedString(String value, TMap attributes) { if (value == null) { throw new NullPointerException(); } @@ -434,7 +434,7 @@ public class AttributedString { TMap.Entry entry = (TMap.Entry) it.next(); TArrayList ranges = new TArrayList<>(1); ranges.add(new Range(0, text.length(), entry.getValue())); - attributeMap.put((AttributedCharacterIterator.Attribute) entry.getKey(), ranges); + attributeMap.put((TAttributedCharacterIterator.Attribute) entry.getKey(), ranges); } } @@ -451,7 +451,7 @@ public class AttributedString { * @throws NullPointerException * if {@code attribute} is {@code null}. */ - public void addAttribute(AttributedCharacterIterator.Attribute attribute, Object value) { + public void addAttribute(TAttributedCharacterIterator.Attribute attribute, Object value) { if (null == attribute) { throw new NullPointerException(); } @@ -487,7 +487,7 @@ public class AttributedString { * @throws NullPointerException * if {@code attribute} is {@code null}. */ - public void addAttribute(AttributedCharacterIterator.Attribute attribute, Object value, int start, int end) { + public void addAttribute(TAttributedCharacterIterator.Attribute attribute, Object value, int start, int end) { if (null == attribute) { throw new NullPointerException(); } @@ -575,11 +575,11 @@ public class AttributedString { * if {@code start < 0}, {@code end} is greater than the length * of this string, or if {@code start >= end}. */ - public void addAttributes(TMap attributes, int start, int end) { + public void addAttributes(TMap attributes, int start, int end) { TIterator it = attributes.entrySet().iterator(); while (it.hasNext()) { TMap.Entry entry = (TMap.Entry) it.next(); - addAttribute((AttributedCharacterIterator.Attribute) entry.getKey(), entry.getValue(), start, end); + addAttribute((TAttributedCharacterIterator.Attribute) entry.getKey(), entry.getValue(), start, end); } } @@ -589,7 +589,7 @@ public class AttributedString { * * @return the newly created {@code AttributedCharacterIterator}. */ - public AttributedCharacterIterator getIterator() { + public TAttributedCharacterIterator getIterator() { return new AttributedIterator(this); } @@ -604,7 +604,7 @@ public class AttributedString { * iterator if they are defined for this text. * @return the newly created {@code AttributedCharacterIterator}. */ - public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes) { + public TAttributedCharacterIterator getIterator(TAttributedCharacterIterator.Attribute[] attributes) { return new AttributedIterator(this, attributes, 0, text.length()); } @@ -623,7 +623,7 @@ public class AttributedString { * the end index of the iterator on the underlying text. * @return the newly created {@code AttributedCharacterIterator}. */ - public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes, int start, + public TAttributedCharacterIterator getIterator(TAttributedCharacterIterator.Attribute[] attributes, int start, int end) { return new AttributedIterator(this, attributes, start, end); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/CharacterIterator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TCharacterIterator.java similarity index 95% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/text/CharacterIterator.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/text/TCharacterIterator.java index c3f0e6434..82491583e 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/CharacterIterator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TCharacterIterator.java @@ -17,7 +17,7 @@ package org.teavm.classlib.java.text; -public interface CharacterIterator extends Cloneable { +public interface TCharacterIterator extends Cloneable { public static final char DONE = '\uffff'; public Object clone(); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/DateFormat.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormat.java similarity index 87% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/text/DateFormat.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormat.java index ed9bb38fd..f663eff15 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/DateFormat.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormat.java @@ -19,7 +19,7 @@ package org.teavm.classlib.java.text; import org.teavm.classlib.java.util.*; -public abstract class DateFormat extends Format { +public abstract class TDateFormat extends TFormat { protected TCalendar calendar; //protected NumberFormat numberFormat; public final static int DEFAULT = 2; @@ -46,12 +46,12 @@ public abstract class DateFormat extends Format { public final static int HOUR0_FIELD = 16; public final static int TIMEZONE_FIELD = 17; - protected DateFormat() { + protected TDateFormat() { } @Override public Object clone() { - DateFormat clone = (DateFormat) super.clone(); + TDateFormat clone = (TDateFormat) super.clone(); clone.calendar = (TCalendar) calendar.clone(); // TODO: implement //clone.numberFormat = (NumberFormat) numberFormat.clone(); @@ -76,7 +76,7 @@ public abstract class DateFormat extends Format { } @Override - public final StringBuffer format(Object object, StringBuffer buffer, FieldPosition field) { + public final StringBuffer format(Object object, StringBuffer buffer, TFieldPosition field) { if (object instanceof TDate) { return format((TDate) object, buffer, field); } @@ -87,10 +87,10 @@ public abstract class DateFormat extends Format { } public final String format(TDate date) { - return format(date, new StringBuffer(), new FieldPosition(0)).toString(); + return format(date, new StringBuffer(), new TFieldPosition(0)).toString(); } - public abstract StringBuffer format(TDate date, StringBuffer buffer, FieldPosition field); + public abstract StringBuffer format(TDate date, StringBuffer buffer, TFieldPosition field); public static TLocale[] getAvailableLocales() { return TLocale.getAvailableLocales(); @@ -100,16 +100,16 @@ public abstract class DateFormat extends Format { return calendar; } - public final static DateFormat getDateInstance() { + public final static TDateFormat getDateInstance() { return getDateInstance(DEFAULT); } - public final static DateFormat getDateInstance(int style) { + public final static TDateFormat getDateInstance(int style) { checkDateStyle(style); return getDateInstance(style, TLocale.getDefault()); } - public final static DateFormat getDateInstance(int style, TLocale locale) { + public final static TDateFormat getDateInstance(int style, TLocale locale) { /*checkDateStyle(style); com.ibm.icu.text.DateFormat icuFormat = com.ibm.icu.text.DateFormat.getDateInstance(style, locale); return new SimpleDateFormat(locale, (com.ibm.icu.text.SimpleDateFormat) icuFormat);*/ @@ -117,17 +117,17 @@ public abstract class DateFormat extends Format { return null; } - public final static DateFormat getDateTimeInstance() { + public final static TDateFormat getDateTimeInstance() { return getDateTimeInstance(DEFAULT, DEFAULT); } - public final static DateFormat getDateTimeInstance(int dateStyle, int timeStyle) { + public final static TDateFormat getDateTimeInstance(int dateStyle, int timeStyle) { checkTimeStyle(timeStyle); checkDateStyle(dateStyle); return getDateTimeInstance(dateStyle, timeStyle, TLocale.getDefault()); } - public final static DateFormat getDateTimeInstance(int dateStyle, int timeStyle, TLocale locale) { + public final static TDateFormat getDateTimeInstance(int dateStyle, int timeStyle, TLocale locale) { /*checkTimeStyle(timeStyle); checkDateStyle(dateStyle); com.ibm.icu.text.DateFormat icuFormat = com.ibm.icu.text.DateFormat.getDateTimeInstance(dateStyle, timeStyle, @@ -137,7 +137,7 @@ public abstract class DateFormat extends Format { return null; } - public final static DateFormat getInstance() { + public final static TDateFormat getInstance() { return getDateTimeInstance(SHORT, SHORT); } @@ -166,16 +166,16 @@ public abstract class DateFormat extends Format { return styleName; } - public final static DateFormat getTimeInstance() { + public final static TDateFormat getTimeInstance() { return getTimeInstance(DEFAULT); } - public final static DateFormat getTimeInstance(int style) { + public final static TDateFormat getTimeInstance(int style) { checkTimeStyle(style); return getTimeInstance(style, TLocale.getDefault()); } - public final static DateFormat getTimeInstance(int style, TLocale locale) { + public final static TDateFormat getTimeInstance(int style, TLocale locale) { /*checkTimeStyle(style); com.ibm.icu.text.DateFormat icuFormat = com.ibm.icu.text.DateFormat.getTimeInstance(style, locale); return new SimpleDateFormat(locale, (com.ibm.icu.text.SimpleDateFormat) icuFormat);*/ @@ -196,19 +196,19 @@ public abstract class DateFormat extends Format { return calendar.isLenient(); } - public TDate parse(String string) throws ParseException { - ParsePosition position = new ParsePosition(0); + public TDate parse(String string) throws TParseException { + TParsePosition position = new TParsePosition(0); TDate date = parse(string, position); if (position.getIndex() == 0) { - throw new ParseException("Unparseable date" + string, position.getErrorIndex()); + throw new TParseException("Unparseable date" + string, position.getErrorIndex()); } return date; } - public abstract TDate parse(String string, ParsePosition position); + public abstract TDate parse(String string, TParsePosition position); @Override - public Object parseObject(String string, ParsePosition position) { + public Object parseObject(String string, TParsePosition position) { return parse(string, position); } @@ -224,7 +224,7 @@ public abstract class DateFormat extends Format { numberFormat = format; }*/ - public static class Field extends Format.Field { + public static class Field extends TFormat.Field { private static THashMap table = new THashMap<>(); public final static Field ERA = new Field("era", TCalendar.ERA); public final static Field YEAR = new Field("year", TCalendar.YEAR); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/DateFormatSymbols.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java similarity index 93% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/text/DateFormatSymbols.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java index 95cbfe583..a1eb98f2b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/DateFormatSymbols.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java @@ -23,24 +23,24 @@ import org.teavm.classlib.java.io.TSerializable; import org.teavm.classlib.java.lang.TCloneable; import org.teavm.classlib.java.util.TLocale; -public class DateFormatSymbols implements TSerializable, TCloneable { +public class TDateFormatSymbols implements TSerializable, TCloneable { private TLocale locale; private String localPatternChars; String[] ampms, eras, months, shortMonths, shortWeekdays, weekdays; String[][] zoneStrings; - public DateFormatSymbols() { + public TDateFormatSymbols() { this(TLocale.getDefault()); } - public DateFormatSymbols(TLocale locale) { + public TDateFormatSymbols(TLocale locale) { this.locale = locale; } @Override public Object clone() { - DateFormatSymbols symbols = new DateFormatSymbols(locale); + TDateFormatSymbols symbols = new TDateFormatSymbols(locale); if (ampms != null) { symbols.ampms = Arrays.copyOf(ampms, ampms.length); } @@ -73,11 +73,11 @@ public class DateFormatSymbols implements TSerializable, TCloneable { if (this == object) { return true; } - if (!(object instanceof DateFormatSymbols)) { + if (!(object instanceof TDateFormatSymbols)) { return false; } - DateFormatSymbols obj = (DateFormatSymbols) object; + TDateFormatSymbols obj = (TDateFormatSymbols) object; if (!locale.equals(obj.locale)) { return false; } @@ -124,7 +124,7 @@ public class DateFormatSymbols implements TSerializable, TCloneable { public String[] getEras() { if (eras == null) { - eras = CLDRHelper.resolveEras(CLDRHelper.getCode(locale.getLanguage(), locale.getCountry())); + eras = CLDRHelper.resolveEras(locale.getLanguage(), locale.getCountry()); } return eras.clone(); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/FieldPosition.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFieldPosition.java similarity index 85% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/text/FieldPosition.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFieldPosition.java index de14cc1ba..72e06628e 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/FieldPosition.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFieldPosition.java @@ -17,20 +17,20 @@ package org.teavm.classlib.java.text; -public class FieldPosition { +public class TFieldPosition { private int myField, beginIndex, endIndex; - private Format.Field myAttribute; + private TFormat.Field myAttribute; - public FieldPosition(int field) { + public TFieldPosition(int field) { myField = field; } - public FieldPosition(Format.Field attribute) { + public TFieldPosition(TFormat.Field attribute) { myAttribute = attribute; myField = -1; } - public FieldPosition(Format.Field attribute, int field) { + public TFieldPosition(TFormat.Field attribute, int field) { myAttribute = attribute; myField = field; } @@ -41,10 +41,10 @@ public class FieldPosition { @Override public boolean equals(Object object) { - if (!(object instanceof FieldPosition)) { + if (!(object instanceof TFieldPosition)) { return false; } - FieldPosition pos = (FieldPosition) object; + TFieldPosition pos = (TFieldPosition) object; return myField == pos.myField && myAttribute == pos.myAttribute && beginIndex == pos.beginIndex && endIndex == pos.endIndex; } @@ -61,7 +61,7 @@ public class FieldPosition { return myField; } - public Format.Field getFieldAttribute() { + public TFormat.Field getFieldAttribute() { return myAttribute; } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/Format.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFormat.java similarity index 80% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/text/Format.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFormat.java index 9d9f3f093..6ece84c18 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/Format.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFormat.java @@ -20,8 +20,8 @@ package org.teavm.classlib.java.text; import org.teavm.classlib.java.io.TSerializable; import org.teavm.classlib.java.lang.TCloneable; -public abstract class Format implements TSerializable, TCloneable { - public Format() { +public abstract class TFormat implements TSerializable, TCloneable { + public TFormat() { } @Override @@ -61,27 +61,27 @@ public abstract class Format implements TSerializable, TCloneable { } public final String format(Object object) { - return format(object, new StringBuffer(), new FieldPosition(0)).toString(); + return format(object, new StringBuffer(), new TFieldPosition(0)).toString(); } - public abstract StringBuffer format(Object object, StringBuffer buffer, FieldPosition field); + public abstract StringBuffer format(Object object, StringBuffer buffer, TFieldPosition field); - public AttributedCharacterIterator formatToCharacterIterator(Object object) { - return new AttributedString(format(object)).getIterator(); + public TAttributedCharacterIterator formatToCharacterIterator(Object object) { + return new TAttributedString(format(object)).getIterator(); } - public Object parseObject(String string) throws ParseException { - ParsePosition position = new ParsePosition(0); + public Object parseObject(String string) throws TParseException { + TParsePosition position = new TParsePosition(0); Object result = parseObject(string, position); if (position.getIndex() == 0) { - throw new ParseException("Format.parseObject(String) parse failure", position.getErrorIndex()); + throw new TParseException("Format.parseObject(String) parse failure", position.getErrorIndex()); } return result; } - public abstract Object parseObject(String string, ParsePosition position); + public abstract Object parseObject(String string, TParsePosition position); - static boolean upTo(String string, ParsePosition position, StringBuffer buffer, char stop) { + static boolean upTo(String string, TParsePosition position, StringBuffer buffer, char stop) { int index = position.getIndex(), length = string.length(); boolean lastQuote = false, quote = false; while (index < length) { @@ -104,7 +104,7 @@ public abstract class Format implements TSerializable, TCloneable { return false; } - static boolean upToWithQuotes(String string, ParsePosition position, StringBuffer buffer, char stop, char start) { + static boolean upToWithQuotes(String string, TParsePosition position, StringBuffer buffer, char stop, char start) { int index = position.getIndex(), length = string.length(), count = 1; boolean quote = false; while (index < length) { @@ -129,7 +129,7 @@ public abstract class Format implements TSerializable, TCloneable { throw new IllegalArgumentException("Unmatched braces in the pattern"); } - public static class Field extends AttributedCharacterIterator.Attribute { + public static class Field extends TAttributedCharacterIterator.Attribute { protected Field(String fieldName) { super(fieldName); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/ParseException.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParseException.java similarity index 93% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/text/ParseException.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParseException.java index fa1c7af84..3d7478d34 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/ParseException.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParseException.java @@ -20,7 +20,7 @@ package org.teavm.classlib.java.text; /** * Thrown when the string being parsed is not in the correct form. */ -public class ParseException extends Exception { +public class TParseException extends Exception { private static final long serialVersionUID = 2703218443322787634L; @@ -35,7 +35,7 @@ public class ParseException extends Exception { * @param location * the index at which the parse exception occurred. */ - public ParseException(String detailMessage, int location) { + public TParseException(String detailMessage, int location) { super(detailMessage); errorOffset = location; } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/ParsePosition.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParsePosition.java similarity index 90% rename from teavm-classlib/src/main/java/org/teavm/classlib/java/text/ParsePosition.java rename to teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParsePosition.java index 2c5adb00c..e20c31e94 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/ParsePosition.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParsePosition.java @@ -17,20 +17,20 @@ package org.teavm.classlib.java.text; -public class ParsePosition { +public class TParsePosition { private int currentPosition, errorIndex = -1; - public ParsePosition(int index) { + public TParsePosition(int index) { currentPosition = index; } @Override public boolean equals(Object object) { - if (!(object instanceof ParsePosition)) { + if (!(object instanceof TParsePosition)) { return false; } - ParsePosition pos = (ParsePosition) object; + TParsePosition pos = (TParsePosition) object; return currentPosition == pos.currentPosition && errorIndex == pos.errorIndex; } diff --git a/teavm-samples/src/main/java/org/teavm/samples/DateTime.java b/teavm-samples/src/main/java/org/teavm/samples/DateTime.java index 4e33d9c5a..75c751e7a 100644 --- a/teavm-samples/src/main/java/org/teavm/samples/DateTime.java +++ b/teavm-samples/src/main/java/org/teavm/samples/DateTime.java @@ -15,6 +15,7 @@ */ package org.teavm.samples; +import java.text.DateFormatSymbols; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; @@ -156,6 +157,20 @@ public class DateTime { HTMLInputElement fieldValueElem = (HTMLInputElement)document.getElementById("field-value"); Calendar calendar = new GregorianCalendar(currentLocale); calendar.setTime(currentDate); - fieldValueElem.setValue(String.valueOf(calendar.get(currentField))); + int value = calendar.get(currentField); + fieldValueElem.setValue(String.valueOf(value)); + + DateFormatSymbols symbols = new DateFormatSymbols(currentLocale); + String text; + switch (currentField) { + case Calendar.ERA: + text = symbols.getEras()[value]; + break; + default: + text = ""; + break; + } + HTMLInputElement fieldTextElem = (HTMLInputElement)document.getElementById("field-value-text"); + fieldTextElem.setValue(text); } } diff --git a/teavm-samples/src/main/resources/datetime.html b/teavm-samples/src/main/resources/datetime.html index 3598c8f3c..37edb01a7 100644 --- a/teavm-samples/src/main/resources/datetime.html +++ b/teavm-samples/src/main/resources/datetime.html @@ -43,6 +43,7 @@
+
\ No newline at end of file