From: Peter Bernard West Date: Sun, 30 May 2004 06:30:36 +0000 (+0000) Subject: Added getLocale() X-Git-Tag: Defoe_export~111 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=92744826d617ae847b473609c12ab3858c57b470;p=xmlgraphics-fop.git Added getLocale() git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@197667 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 6297e20d3..bb794b837 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -22,6 +22,7 @@ import java.awt.geom.Rectangle2D; import java.util.BitSet; import java.util.HashMap; import java.util.Iterator; +import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; @@ -31,7 +32,9 @@ import org.apache.fop.area.AreaListener; import org.apache.fop.datastructs.ROBitSet; import org.apache.fop.datastructs.SyncedNode; import org.apache.fop.datastructs.TreeException; +import org.apache.fop.datatypes.CountryType; import org.apache.fop.datatypes.EnumType; +import org.apache.fop.datatypes.LanguageType; import org.apache.fop.datatypes.Numeric; import org.apache.fop.datatypes.PropertyValue; import org.apache.fop.datatypes.PropertyValueList; @@ -606,6 +609,31 @@ public class FONode extends SyncedNode implements AreaListener { return EnumType.getEnumValue(wm); } + /** + * Gets the current locale. This is derived from the language + * and country properties in effect. Note that no account is + * taken of script at this stage. + *

N.B. The initial values of both language and + * country are taken from the default Locale + * returned bu the JVM. This may be problemattical in the case where a + * user sets a language but not a country, + * because the Locale returned by this method will use the + * default country. + * + * @return the locale + * @throws PropertyException + */ + public Locale getLocale() throws PropertyException { + Locale locale = null; + // Get the value of the language and country properties + PropertyValue pv = getPropertyValue(PropNames.LANGUAGE); + String language = + LanguageType.getISO639_1Language( + getPropertyValue(PropNames.LANGUAGE)); + String country = + CountryType.getCountry(getPropertyValue(PropNames.COUNTRY)); + return new Locale(language, country); + } /** * Clone the current font size. * @return a Numeric containing the current font size